diff --git a/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java b/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java index aa75d7f092..821d36551e 100644 --- a/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java +++ b/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java @@ -329,21 +329,20 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi WARNING_MESSAGE); return; } + // 筛选可以移动的文件 + ArrayList moveNodes = new ArrayList<>(); + ArrayList lockedNodes = new ArrayList<>(); + for (ExpandMutableTreeNode treeNode : getFileTree().getSelectedTreeNodes()) { + FileOperationHelper.getInstance().checkFreeOrLock(treeNode, moveNodes, lockedNodes); + } - ExpandMutableTreeNode[] selectedTreeNodes = getFileTree().getSelectedTreeNodes(); - for (ExpandMutableTreeNode treeNode : selectedTreeNodes) { - if (treeNode.getUserObject() instanceof FileNode) { - FileNode node = (FileNode) treeNode.getUserObject(); - String lock = node.getLock(); - if (lock != null && !lock.equals(node.getUserID())) { - // 提醒被锁定模板无法移动 - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), - Toolkit.i18nText("Fine-Design_Basic_Unable_Move_Locked_File"), - Toolkit.i18nText("Fine-Design_Basic_Alert"), - WARNING_MESSAGE); - return; - } - } + if (!lockedNodes.isEmpty()) { + // 提醒被锁定模板无法移动 + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Unable_Move_Locked_File"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + WARNING_MESSAGE); + return; } new TemplateMoveDialog(); diff --git a/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java b/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java index 8c2eb9ac8d..72d8df899e 100644 --- a/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java +++ b/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java @@ -40,10 +40,10 @@ public class FileOperationHelper { HistoryTemplateListCache.getInstance().deleteFile(nodeFILE); FineLoggerFactory.getLogger().info("template {} move to {} success.", sourceFileNode.getEnvPath(), targetDir); } else { - //删除失败,将复制过去的文件删掉 - TemplateResourceManager.getResource().delete(new FileNodeFILE(targetPath)); + //删除源文件失败,将复制过去的文件删掉 + TemplateResourceManager.getResource().delete(new FileNodeFILE(new FileNode(targetPath, sourceFileNode.isDirectory()))); FineLoggerFactory.getLogger().error("template {} move to {} failed.", sourceFileNode.getEnvPath(), targetDir); - targetPath = StringUtils.EMPTY; + throw new ResourceIOException(String.format("template %s move to %s failed", sourceFileNode.getEnvPath(), targetDir)); } } return targetPath; @@ -79,13 +79,16 @@ public class FileOperationHelper { public boolean checkFreeOrLock(ExpandMutableTreeNode node, ArrayList dNodes, ArrayList lNodes) { // 自己没锁 boolean selfEmptyLock = false; + boolean isDir = false; Object userObj = node.getUserObject(); if (userObj instanceof FileNode) { - String lock = ((FileNode) userObj).getLock(); - selfEmptyLock = lock == null || ((FileNode) userObj).getUserID().equals(lock); + FileNode fileNode = (FileNode) userObj; + String lock = fileNode.getLock(); + selfEmptyLock = lock == null || fileNode.getUserID().equals(lock); + isDir = fileNode.isDirectory(); } - if (node.isLeaf()) { + if (!isDir) { if (selfEmptyLock) { dNodes.add(node); } else { @@ -130,7 +133,9 @@ public class FileOperationHelper { FileNode[] fileNodes = TemplateTreePane.getInstance().getTemplateFileTree().listFile(sourceDir); if (ArrayUtils.isEmpty(fileNodes)) { //空目录:相当于新建一个目录 - DesignerFrameFileDealerPane.getInstance().getSelectedOperation().mkdir(targetDir); + if (!DesignerFrameFileDealerPane.getInstance().getSelectedOperation().mkdir(targetDir)) { + throw new ResourceIOException(String.format("copy dir failed: from %s to %s.", sourceDir, targetDir)); + } return; } for (FileNode fileNode : fileNodes) { 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 381f201726..18abbb7e28 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 @@ -393,6 +393,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { if (TemplateTreeSearchManager.getInstance().isInSearchMode()) { TemplateTreeSearchManager.getInstance().deleteMatchedNode(deletedPaths); TemplateTreeSearchManager.getInstance().updateTemplateTree(); + TemplateTreeSearchManager.getInstance().setRefreshing(false); } else { TreePath[] paths = reportletsTree.getSelectionPaths(); if (paths == null) { diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java index 609e99e862..0a0d6c5d33 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java @@ -35,6 +35,8 @@ public class TemplateFileTree extends EnvFileTree { protected Map allTreeNode = new ConcurrentHashMap<>(); protected Map calculateNode = new ConcurrentHashMap<>(); protected Map> currentTreeMode = new ConcurrentHashMap<>(); + private static final int MAX_NODE_EXPAND_NUM = 50; + private static final int MAX_MATCHED_NODE_NUM = 500; public TemplateFileTree() { super(ProjectConstants.REPORTLETS_NAME, null, null); @@ -272,7 +274,10 @@ public class TemplateFileTree extends EnvFileTree { refreshTreeNode4TreeSearch(root); sortTreeNode(root); ((DefaultTreeModel) this.getModel()).reload(root); - root.expandCurrentTreeNode(this); + if (currentTreeMode.keySet().size() < MAX_NODE_EXPAND_NUM || TemplateTreeSearchManager.getInstance().matchesNode().length < MAX_MATCHED_NODE_NUM) { + //要展开的节点比较多的话,全部展开会有性能问题 + root.expandCurrentTreeNode(this); + } } /** diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateTreeSearchManager.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateTreeSearchManager.java index c9b875c562..2695c24436 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateTreeSearchManager.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateTreeSearchManager.java @@ -12,7 +12,9 @@ import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -129,7 +131,14 @@ public class TemplateTreeSearchManager { setTreeSearchStatus(TreeSearchStatus.SEARCHING); rendererHelper.replaceTreeRenderer(getCurrentTemplateTree(), searchText); FineLoggerFactory.getLogger().debug("start template search for search text: {}", searchText); - treeSearcher.startSearch(searchText); + new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + treeSearcher.startSearch(searchText); + return null; + } + }.execute(); } /** @@ -203,7 +212,13 @@ public class TemplateTreeSearchManager { } public void deleteMatchedNode(Set fileNodes) { - treeSearcher.getMatchSets().removeAll(fileNodes); + Set deleteNode = new HashSet<>(); + for (FileNode matchedNode : treeSearcher.getMatchSets()) { + if (fileNodes.stream().anyMatch(fileNode -> fileNode.getEnvPath().equals(matchedNode.getEnvPath()))) { + deleteNode.add(matchedNode); + } + } + treeSearcher.getMatchSets().removeAll(deleteNode); } /** diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateDirSearchCallBack.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateDirSearchCallBack.java index 65ac5a020c..37853c9375 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateDirSearchCallBack.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateDirSearchCallBack.java @@ -24,10 +24,8 @@ public class TemplateDirSearchCallBack implements TreeSearchCallback { if (TemplateDirTreeSearchManager.getInstance().getTreeSearchStatus() != TreeSearchStatus.SEARCHING) { return; } - if (treeSearchResult.isSuccess()) { - // 添加结果 - addToTreeSearcher(treeSearchResult); - } + // 添加结果 + addToTreeSearcher(treeSearchResult); if (treeSearcher.getCalculatedCount() == treeSearcher.getAllDirSize()) { updateTemplateTree(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchCallBack.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchCallBack.java index 925760f791..5905ea9a34 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchCallBack.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchCallBack.java @@ -24,10 +24,8 @@ public class TemplateSearchCallBack implements TreeSearchCallback { if (TemplateTreeSearchManager.getInstance().getTreeSearchStatus() != TreeSearchStatus.SEARCHING) { return; } - if (treeSearchResult.isSuccess()) { - // 添加结果 - addToTreeSearcher(treeSearchResult); - } + // 添加结果 + addToTreeSearcher(treeSearchResult); updateTemplateTree(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchTask.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchTask.java index a23775bbb4..b1cc743748 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchTask.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchTask.java @@ -63,7 +63,8 @@ public class TemplateSearchTask implements TreeSearchTask { * @param fileNode */ private TreeSearchResult dealWithErrorTemplateWrapper(FileNode fileNode) { - return new TemplateSearchResult.Builder().buildSuccess(false).build(); + return new TemplateSearchResult.Builder().buildSuccess(false) + .buildAddToCalculated(Arrays.asList(fileNode.getEnvPath())).build(); } /** diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchCallBack.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchCallBack.java index 83176f1007..fd2c6853ba 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchCallBack.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchCallBack.java @@ -17,9 +17,7 @@ public class TemplatePreSearchCallBack extends TemplateSearchCallBack { @Override public void done(TreeSearchResult searchResult) { - if (searchResult.isSuccess()) { - addToTreeSearcher(searchResult); - } + addToTreeSearcher(searchResult); } /** diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchTask.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchTask.java index 496eef5140..5eed450622 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchTask.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchTask.java @@ -37,7 +37,7 @@ public class TemplatePreSearchTask implements TreeSearchTask { FineLoggerFactory.getLogger().info("[Template Search] calculate {} child nodes success. total child node num is: {}", fileNode.getEnvPath(), allChildNode.size()); } catch (Exception e) { FineLoggerFactory.getLogger().error("[Template Search] calculate {} child nodes failed", fileNode.getEnvPath()); - result = new TemplateSearchResult.Builder().buildSuccess(false).build(); + result = new TemplateSearchResult.Builder().buildAddToNotCalculated(new ArrayList<>()).buildSuccess(false).build(); } callback.done(result); }