From 8ba66293908d0ee0d4fc30315068c28e13ebfbf9 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Mon, 10 Sep 2018 17:49:40 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-10896=20=E5=A4=9A=E4=BA=BA=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/DesignerEnvManager.java | 32 +++----- .../design/file/HistoryTemplateListCache.java | 10 ++- .../com/fr/design/file/TemplateTreePane.java | 82 ++++++++++++------- .../DesignerFrameFileDealerPane.java | 29 ++++--- .../mainframe/socketio/DesignerSocketIO.java | 13 ++- 5 files changed, 93 insertions(+), 73 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index 16d00156b..d054ab959 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -26,6 +26,7 @@ import com.fr.general.xml.GeneralXMLTools; import com.fr.log.FineLoggerFactory; import com.fr.stable.CommonUtils; import com.fr.stable.Constants; +import com.fr.stable.CoreConstants; import com.fr.stable.EnvChangedListener; import com.fr.stable.ListMap; import com.fr.stable.ProductConstants; @@ -38,6 +39,7 @@ import com.fr.stable.xml.XMLReadable; import com.fr.stable.xml.XMLTools; import com.fr.stable.xml.XMLWriter; import com.fr.stable.xml.XMLableReader; +import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContextCallback; @@ -850,10 +852,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { * @param filePath 文件路径 */ public void addRecentOpenedFilePath(String filePath) { + filePath = FilenameUtils.standard(filePath); // 先删除. - if (getRecentOpenedFilePathList().contains(filePath)) { - getRecentOpenedFilePathList().remove(filePath); - } + getRecentOpenedFilePathList().remove(filePath); getRecentOpenedFilePathList().add(0, filePath); checkRecentOpenedFileNum(); @@ -862,8 +863,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { /** * 替换近期打开的文件路径 * - * @param oldPath 旧的路径 - * @param newPath 新的路径 + * @param oldPath path 使用 unix 分隔符 + * @param newPath path 使用 unix 分隔符 */ public void replaceRecentOpenedFilePath(String oldPath, String newPath) { List list = getRecentOpenedFilePathList(); @@ -872,28 +873,22 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { list.remove(oldPath); list.add(index, newPath); } - oldPath = oldPath.replaceAll("\\\\", "/"); - if (list.contains(oldPath)) { - int index = list.indexOf(oldPath); - list.remove(oldPath); - list.add(index, newPath); - } } /** * 替换近期打开的文件路径 * * @param type 文件类型,文件夹true,文件false - * @param oldPath 旧的路径 使用反斜杠分割 - * @param newPath 新的路径 使用反斜杠分割 + * @param oldPath path 使用 unix 分隔符 + * @param newPath path 使用 unix 分隔符 */ public void replaceRecentOpenedFilePath(boolean type, String oldPath, String newPath) { List list = getRecentOpenedFilePathList(); ListIterator iterator = list.listIterator(); while (iterator.hasNext()) { - String s = iterator.next().replaceAll("/", "\\\\"); - if (type ? s.contains(oldPath + "\\") : s.equals(oldPath)) { + String s = FilenameUtils.standard(iterator.next()); + if (type ? s.contains(oldPath + CoreConstants.SEPARATOR) : s.equals(oldPath)) { s = s.replace(oldPath, newPath); iterator.set(s); } @@ -916,9 +911,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { * @param filePath 文件路径 */ public void removeRecentOpenedFilePath(String filePath) { - if (getRecentOpenedFilePathList().contains(filePath)) { - getRecentOpenedFilePathList().remove(filePath); - } + filePath = FilenameUtils.standard(filePath); + getRecentOpenedFilePathList().remove(filePath); } @@ -1637,7 +1631,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { if (reader.isChildNode()) { String n = reader.getTagName(); if ("Path".equals(n)) { - String path = reader.getElementValue(); + String path = FilenameUtils.standard(reader.getElementValue()); if (StringUtils.isNotEmpty(path)) { recentOpenedFileList.add(path); } diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 13fd85955..70fbde3f1 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -11,7 +11,9 @@ import com.fr.file.FILE; import com.fr.file.FileNodeFILE; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; +import com.fr.stable.CoreConstants; import com.fr.stable.StringUtils; +import com.fr.third.org.apache.commons.io.FilenameUtils; import java.util.ArrayList; import java.util.Collections; @@ -270,8 +272,8 @@ public class HistoryTemplateListCache implements CallbackEvent { template = this.getCurrentEditingTemplate(); if (template != null) { - String editingPath = template.getEditingFILE().getPath().replaceAll("/", "\\\\"); - if (isDir ? editingPath.contains(from + "\\") : editingPath.equals(from)) { + String editingPath = FilenameUtils.standard(template.getEditingFILE().getPath()); + if (isDir ? editingPath.contains(from + CoreConstants.SEPARATOR) : editingPath.equals(from)) { FILE renameFile = template.getEditingFILE(); renameFile.setPath(editingPath.replace(from, to)); } @@ -279,8 +281,8 @@ public class HistoryTemplateListCache implements CallbackEvent { for (int i = 0; i < this.getHistoryCount(); i++) { template = this.get(i); - String editingPath = template.getEditingFILE().getPath().replaceAll("/", "\\\\"); - if (isDir ? editingPath.contains(from + "\\") : editingPath.equals(from)) { + String editingPath = FilenameUtils.standard(template.getEditingFILE().getPath()); + if (isDir ? editingPath.contains(from + CoreConstants.SEPARATOR) : editingPath.equals(from)) { FILE renameFile = template.getEditingFILE(); renameFile.setPath(editingPath.replace(from, to)); } diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java index 3344d69f2..2a8b543d7 100644 --- a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java @@ -5,6 +5,8 @@ package com.fr.design.file; import com.fr.base.FRContext; import com.fr.base.io.FileAssistUtilsOperator; +import com.fr.design.DesignerEnvManager; +import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; @@ -20,8 +22,10 @@ import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; import com.fr.workspace.WorkContext; +import com.fr.workspace.connect.WorkspaceConnection; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -186,6 +190,26 @@ public class TemplateTreePane extends JPanel implements FileOperations { */ @Override public void openFile() { + // 判断是否是远程设计的锁定文件 + if (!WorkContext.getCurrent().isLocal()) { + FileNode node = reportletsTree.getSelectedFileNode(); + if (node == null) { + return; + } + + String envName = DesignerEnvManager.getEnvManager().getCurEnvName(); + DesignerWorkspaceInfo info = DesignerEnvManager.getEnvManager().getWorkspaceInfo(envName); + + String username = null; + if (info != null) { + WorkspaceConnection connection = info.getConnection(); + username = connection == null ? StringUtils.EMPTY : connection.getUserName(); + } + String lock = node.getLock(); + if (lock != null && !lock.equals(username)) { + return; + } + } String reportPath = reportletsTree.getSelectedTemplatePath(); final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath); DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(selectedFilePath, false))); @@ -226,11 +250,6 @@ public class TemplateTreePane extends JPanel implements FileOperations { public void deleteFile() { - String tipContent = - countSelectedFolder() > 0 - ? Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_Folder") - : Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_File"); - ExpandMutableTreeNode[] treeNodes = reportletsTree.getSelectedTreeNodes(); // 筛选可以删除的文件 ArrayList deletableNodes = new ArrayList<>(); @@ -238,40 +257,49 @@ public class TemplateTreePane extends JPanel implements FileOperations { for (ExpandMutableTreeNode treeNode : treeNodes) { checkFreeOrLock(treeNode, deletableNodes, lockedNodes); } - - boolean success = false; - if (lockedNodes.isEmpty()) { + String tipContent = + countSelectedFolder() > 0 + ? Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_Folder") + : Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_File"); + if (JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), tipContent, UIManager.getString("OptionPane.titleText"), YES_NO_OPTION) - == JOptionPane.OK_OPTION) { + == JOptionPane.YES_OPTION) { // 删除所有选中的即可 - success = deleteNodes(Arrays.asList(treeNodes)); + if (!deleteNodes(Arrays.asList(treeNodes))) { + JOptionPane.showConfirmDialog(null, + Toolkit.i18nText("Fine-Design_Basic_Delete_Failure"), + UIManager.getString("OptionPane.titleText"), + JOptionPane.DEFAULT_OPTION, + JOptionPane.ERROR_MESSAGE); + } } - } else { + String tipContent = + countSelectedFolder() > 0 + ? Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_Unlock_File_And_Folder") + : Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_Unlock_File"); + if (JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), - Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_Unlock_File"), + tipContent, UIManager.getString("OptionPane.titleText"), YES_NO_OPTION) == JOptionPane.YES_OPTION) { // 删除其他 - success = deleteNodes(deletableNodes); + if (!deleteNodes(deletableNodes)) { + JOptionPane.showConfirmDialog(null, + Toolkit.i18nText("Fine-Design_Basic_Delete_Failure"), + UIManager.getString("OptionPane.titleText"), + JOptionPane.DEFAULT_OPTION, + JOptionPane.ERROR_MESSAGE); + } } } - - if (!success) { - JOptionPane.showConfirmDialog(null, - Toolkit.i18nText("Fine-Design_Basic_Delete_Failure"), - UIManager.getString("OptionPane.titleText"), - JOptionPane.DEFAULT_OPTION, - JOptionPane.ERROR_MESSAGE); - } - reportletsTree.refresh(); } @@ -314,15 +342,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { boolean childrenEmptyLock = true; for (ExpandMutableTreeNode child : children) { - - boolean childEmptyLock = checkFreeOrLock(child, dNodes, lNodes); - if (childEmptyLock) { - dNodes.add(child); - } else { - lNodes.add(child); - } - - childrenEmptyLock = childrenEmptyLock && childEmptyLock; + childrenEmptyLock = checkFreeOrLock(child, dNodes, lNodes) && childrenEmptyLock; } boolean emptyLock = childrenEmptyLock && selfEmptyLock; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java index 83e30eecf..5e1c6b2a4 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java @@ -36,6 +36,7 @@ import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.CoreConstants; import com.fr.stable.StringUtils; +import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.workspace.WorkContext; import javax.swing.BorderFactory; @@ -394,8 +395,8 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt fnf = new FileNodeFILE(node); String oldName = fnf.getName(); - String suffix = fnf.isDirectory() ? "" : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length()); - oldName = oldName.replaceAll(suffix, ""); + String suffix = fnf.isDirectory() ? StringUtils.EMPTY : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length()); + oldName = oldName.replaceAll(suffix, StringUtils.EMPTY); this.setLayout(new BorderLayout()); this.setModal(true); @@ -509,11 +510,11 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt String userInput = nameField.getText().trim(); - String path = fnf.getPath(); + String path = FilenameUtils.standard(fnf.getPath()); String oldName = fnf.getName(); - String suffix = fnf.isDirectory() ? "" : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length()); - oldName = oldName.replaceAll(suffix, ""); + String suffix = fnf.isDirectory() ? StringUtils.EMPTY : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length()); + oldName = oldName.replaceAll(suffix, StringUtils.EMPTY); // 输入为空或者没有修改 if (ComparatorUtils.equals(userInput, oldName)) { @@ -521,18 +522,16 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt return; } - String oldPath = path.replaceAll(CoreConstants.SEPARATOR, "\\\\"); - - String parentPath = fnf.getParent().getPath().replaceAll(CoreConstants.SEPARATOR, "\\\\"); + String parentPath = FilenameUtils.standard(fnf.getParent().getPath()); // 简单执行old new 替换是不可行的,例如 /abc/abc/abc/abc/ - String newPath = parentPath + "\\" + userInput + suffix; + String newPath = parentPath + CoreConstants.SEPARATOR + userInput + suffix; - HistoryTemplateListCache.getInstance().rename(fnf, oldPath, newPath); - DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(fnf.isDirectory(), oldPath, newPath); + HistoryTemplateListCache.getInstance().rename(fnf, path, newPath); + DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(fnf.isDirectory(), path, newPath); //模版重命名 - boolean success = selectedOperation.rename(fnf, oldPath, newPath); + boolean success = selectedOperation.rename(fnf, path, newPath); selectedOperation.refresh(); DesignerContext.getDesignerFrame().setTitle(); this.dispose(); @@ -552,8 +551,8 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt String userInput = nameField.getText().trim(); String oldName = fnf.getName(); - String suffix = fnf.isDirectory() ? "" : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length()); - oldName = oldName.replaceAll(suffix, ""); + String suffix = fnf.isDirectory() ? StringUtils.EMPTY : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length()); + oldName = oldName.replaceAll(suffix, StringUtils.EMPTY); if (StringUtils.isEmpty(userInput)) { confirmButton.setEnabled(false); @@ -714,7 +713,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt //新建文件夹 boolean success = selectedOperation.mkdir( - selectedOperation.getFileNode().getParent() + CoreConstants.SEPARATOR + userInput + FilenameUtils.standard(selectedOperation.getFileNode().getParent() + CoreConstants.SEPARATOR + userInput) ); selectedOperation.refresh(); this.dispose(); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java b/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java index e9b12e7b1..4f5c6e371 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java @@ -2,8 +2,9 @@ package com.fr.design.mainframe.socketio; import com.fr.config.RemoteConfigEvent; import com.fr.decision.webservice.utils.DecisionServiceConstants; +import com.fr.design.EnvChangeEntrance; +import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.TemplatePane; import com.fr.design.mainframe.loghandler.DesignerLogHandler; import com.fr.event.EventDispatcher; import com.fr.log.FineLoggerFactory; @@ -84,9 +85,13 @@ public class DesignerSocketIO { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remote_Disconnected"), - null, 0, UIManager.getIcon("OptionPane.errorIcon")); - TemplatePane.getInstance().editItems(); + JOptionPane.showMessageDialog( + DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Remote_Disconnected"), + UIManager.getString("OptionPane.messageDialogTitle"), + JOptionPane.ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon")); + EnvChangeEntrance.getInstance().chooseEnv(); } }); } catch (Exception e) {