Browse Source

REPORT-78748 搜索结果很多时,设计器界面处于卡死的状态

release/11.0
roger 2 years ago
parent
commit
fa207040f2
  1. 27
      designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java
  2. 19
      designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java
  3. 1
      designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java
  4. 7
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java
  5. 19
      designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateTreeSearchManager.java
  6. 6
      designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateDirSearchCallBack.java
  7. 6
      designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchCallBack.java
  8. 3
      designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchTask.java
  9. 4
      designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchCallBack.java
  10. 2
      designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplatePreSearchTask.java

27
designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java

@ -329,21 +329,20 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
WARNING_MESSAGE);
return;
}
// 筛选可以移动的文件
ArrayList<ExpandMutableTreeNode> moveNodes = new ArrayList<>();
ArrayList<ExpandMutableTreeNode> 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();

19
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<ExpandMutableTreeNode> dNodes, ArrayList<ExpandMutableTreeNode> 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) {

1
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) {

7
designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java

@ -35,6 +35,8 @@ public class TemplateFileTree extends EnvFileTree {
protected Map<String, ExpandMutableTreeNode> allTreeNode = new ConcurrentHashMap<>();
protected Map<String, ExpandMutableTreeNode> calculateNode = new ConcurrentHashMap<>();
protected Map<String, List<String>> 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);
}
}
/**

19
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<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
treeSearcher.startSearch(searchText);
return null;
}
}.execute();
}
/**
@ -203,7 +212,13 @@ public class TemplateTreeSearchManager {
}
public void deleteMatchedNode(Set<FileNode> fileNodes) {
treeSearcher.getMatchSets().removeAll(fileNodes);
Set<FileNode> 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);
}
/**

6
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();
}

6
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();
}

3
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();
}
/**

4
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);
}
/**

2
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);
}

Loading…
Cancel
Save