From ea95d395ec095a6ea54bbac03a96a405d8151a35 Mon Sep 17 00:00:00 2001 From: roger Date: Mon, 15 Aug 2022 19:01:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B1=BB=E3=80=81=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E7=9B=B8=E5=85=B3=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/actions/file/DelFileAction.java | 11 ++++ .../fr/design/actions/file/LocateAction.java | 8 +++ .../fr/design/actions/file/RenameAction.java | 16 +++++- .../DefaultTemplateTreeDefineProcessor.java | 51 +++++++++++++++---- .../fr/design/file/TemplateDirTreePane.java | 3 ++ .../gui/itree/filetree/TemplateDirTree.java | 3 +- .../gui/itree/filetree/TemplateFileTree.java | 11 +++- .../manager/clip/TemplateTreeClipboard.java | 3 ++ .../search/TemplateDirTreeSearchManager.java | 17 ++++++- .../search/TemplateTreeSearchManager.java | 17 ++++++- .../searcher/TemplateDirTreeSearcher.java | 35 ++++++++++++- .../search/searcher/TemplateTreeSearcher.java | 26 +++++++++- .../common/TemplateDirSearchCallBack.java | 6 +++ .../common/TemplateSearchCallBack.java | 6 +++ .../control/common/TemplateSearchResult.java | 3 ++ .../control/common/TemplateSearchTask.java | 3 ++ .../pane/TemplateDirSearchRemindPane.java | 3 ++ .../pane/TemplateDirTreeSearchPane.java | 3 ++ .../pane/TemplateSearchRemindPane.java | 16 ++++++ .../pane/TemplateTreeSearchToolbarPane.java | 3 ++ .../control/pre/TemplateDirPreSearchTask.java | 3 ++ .../pre/TemplatePreSearchCallBack.java | 9 ++++ .../control/pre/TemplatePreSearchTask.java | 4 ++ .../com/fr/design/utils/TemplateUtils.java | 34 +++++++++++++ 24 files changed, 276 insertions(+), 18 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/actions/file/DelFileAction.java b/designer-base/src/main/java/com/fr/design/actions/file/DelFileAction.java index 3431676977..896c518781 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/DelFileAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/DelFileAction.java @@ -6,10 +6,13 @@ import com.fr.design.file.FileOperations; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; +import com.fr.design.utils.TemplateUtils; +import javax.swing.JOptionPane; import java.awt.event.ActionEvent; import static javax.swing.JOptionPane.WARNING_MESSAGE; +import static javax.swing.JOptionPane.YES_NO_OPTION; /* * 删除指定文件 @@ -32,6 +35,14 @@ public class DelFileAction extends UpdateAction { WARNING_MESSAGE); return; } + if (TemplateUtils.checkSelectedTemplateIsEditing()) { + if (FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Template_Is_Editing"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + YES_NO_OPTION) != JOptionPane.YES_OPTION) { + return; + } + } selectedOperation.deleteFile(); DesignerFrameFileDealerPane.getInstance().stateChange(); DesignerContext.getDesignerFrame().setTitle(); diff --git a/designer-base/src/main/java/com/fr/design/actions/file/LocateAction.java b/designer-base/src/main/java/com/fr/design/actions/file/LocateAction.java index f079059e4f..8c5955bcdc 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/LocateAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/LocateAction.java @@ -19,6 +19,9 @@ import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; import java.io.File; +/** + * 模板定位功能 + */ public class LocateAction extends UpdateAction { public LocateAction() { @@ -32,6 +35,11 @@ public class LocateAction extends UpdateAction { gotoEditingTemplateLeaf(current.getEditingFILE().getPath()); } + /** + * 在左侧模板树定位到指定模板 + * + * @param locatedPath + */ public static void gotoEditingTemplateLeaf(String locatedPath) { if (locatedPath == null) { return; diff --git a/designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java b/designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java index 58e3cff686..2df047264d 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java @@ -16,6 +16,7 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; +import com.fr.design.utils.TemplateUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.event.Event; import com.fr.event.EventDispatcher; @@ -29,6 +30,7 @@ import com.fr.third.org.apache.commons.io.FilenameUtils; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JPanel; +import javax.swing.JOptionPane; import javax.swing.SwingConstants; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -47,8 +49,11 @@ import java.util.regex.Pattern; import static javax.swing.JOptionPane.DEFAULT_OPTION; import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.WARNING_MESSAGE; +import static javax.swing.JOptionPane.YES_NO_OPTION; - +/** + * 模板/目录重命名操作 + */ public class RenameAction extends UpdateAction { private FileOperations selectedOperation; @@ -235,6 +240,15 @@ public class RenameAction extends UpdateAction { private void confirmClose() { + if (TemplateUtils.checkSelectedTemplateIsEditing()) { + if (FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Template_Is_Editing"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + YES_NO_OPTION) == JOptionPane.NO_OPTION) { + return; + } + } + String userInput = nameField.getText().trim(); String path = FilenameUtils.standard(fnf.getPath()); 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 a01ca0c7aa..e998d358d9 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 @@ -18,6 +18,7 @@ import com.fr.design.mainframe.manager.clip.TemplateTreeClipboard; import com.fr.design.mainframe.manager.search.TemplateDirTreeSearchManager; import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; import com.fr.design.mainframe.manager.search.searcher.control.pane.TemplateDirTreeSearchPane; +import com.fr.design.utils.TemplateUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.file.FileNodeFILE; import com.fr.file.filetree.FileNode; @@ -49,6 +50,9 @@ import static javax.swing.JOptionPane.INFORMATION_MESSAGE; import static javax.swing.JOptionPane.WARNING_MESSAGE; import static javax.swing.JOptionPane.YES_NO_OPTION; +/** + * 默认的模板右键处理方式:包含重命名、复制、黏贴、删除、移动等功能 + */ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefineProcessor { private UIPopupMenu popupMenu; @@ -129,6 +133,9 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi return TemplateDirTreePane.getInstance().getTemplateDirTree(); } + /** + * 复制功能 + */ private class CopyAction extends UpdateAction { public CopyAction() { @@ -153,6 +160,9 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi } } + /** + * 黏贴功能 + */ private class PasteAction extends UpdateAction { public PasteAction() { @@ -207,14 +217,20 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi return false; } //确定目标目录并检查权限 - FileOperations selectedOperation = DesignerFrameFileDealerPane.getInstance().getSelectedOperation(); - if (getFileTree().getSelectionCount() != 0 && !selectedOperation.access()) { + if (getDirTree().getSelectionCount() != 0 && !TemplateDirTreePane.getInstance().selectedAccess()) { FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"), Toolkit.i18nText("Fine-Design_Basic_Alert"), WARNING_MESSAGE); return false; } + //检测之前复制的文件是否被打开 + if (TemplateUtils.checkTemplateIsEditing(treeNodeList.toArray(new ExpandMutableTreeNode[0]))) { + return FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Template_Is_Editing"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + YES_NO_OPTION) == JOptionPane.YES_OPTION; + } return true; } @@ -251,6 +267,9 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi } + /** + * 移动功能 + */ private class MoveAction extends UpdateAction { public MoveAction() { @@ -347,12 +366,8 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi } private void confirmClose() { - //获取目录数中所选中的文件,并判断是否有权限 - if (getFileTree().getSelectionCount() != 0 && !TemplateDirTreePane.getInstance().selectedAccess()) { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), - Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"), - Toolkit.i18nText("Fine-Design_Basic_Alert"), - WARNING_MESSAGE); + //获取目录树中所选中的文件,并判断是否有权限 + if (!checkBeforeMove()) { return; } boolean moveSuccess = doMove(); @@ -372,9 +387,27 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi } } + private boolean checkBeforeMove() { + if (getDirTree().getSelectionCount() != 0 && !TemplateDirTreePane.getInstance().selectedAccess()) { + FineJOptionPane.showMessageDialog(this, + Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + WARNING_MESSAGE); + return false; + } + if (TemplateUtils.checkSelectedTemplateIsEditing()) { + return FineJOptionPane.showConfirmDialog(this, + Toolkit.i18nText("Fine-Design_Basic_Template_Is_Editing"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + YES_NO_OPTION) == JOptionPane.YES_OPTION; + } + return true; + } + private boolean doMove() { FileNode fileNode = getDirTree().getSelectedFileNode(); - fileNode = fileNode == null ? (FileNode) getFileTree().getModel().getRoot() : fileNode; + ExpandMutableTreeNode rootTreeNode = (ExpandMutableTreeNode) getDirTree().getModel().getRoot(); + fileNode = fileNode == null ? (FileNode) rootTreeNode.getUserObject() : fileNode; boolean moveSuccess = true; try { //待移动的文件可以有多个 diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateDirTreePane.java b/designer-base/src/main/java/com/fr/design/file/TemplateDirTreePane.java index 58740393d1..08531b895c 100644 --- a/designer-base/src/main/java/com/fr/design/file/TemplateDirTreePane.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateDirTreePane.java @@ -17,6 +17,9 @@ import javax.swing.tree.TreePath; import java.awt.BorderLayout; import java.awt.Color; +/** + * 目录树面板 + */ public class TemplateDirTreePane extends JPanel { public static TemplateDirTreePane getInstance() { diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateDirTree.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateDirTree.java index 10388fa324..c4c5b7bf55 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateDirTree.java +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateDirTree.java @@ -3,7 +3,6 @@ package com.fr.design.gui.itree.filetree; import com.fr.base.FRContext; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.mainframe.manager.search.TemplateDirTreeSearchManager; -import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; import com.fr.file.filetree.FileNode; import java.util.Arrays; @@ -40,7 +39,7 @@ public class TemplateDirTree extends TemplateFileTree { return; } currentTreeMode.clear(); - allTreeNode = TemplateTreeSearchManager.getInstance().allFileNodes().entrySet().stream().collect( + allTreeNode = TemplateDirTreeSearchManager.getInstance().allFileNodes().entrySet().stream().collect( Collectors.toMap(Map.Entry::getKey, entry -> fileNodeArray2TreeNodeArray(new FileNode[]{entry.getValue()})[0])); root.removeAllChildren(); 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 e50a3145b6..d312beb919 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 @@ -261,6 +261,9 @@ public class TemplateFileTree extends EnvFileTree { return new FileNode[0]; } + /** + * 搜索时更新搜索结果 + */ @Override public void refresh4TreeSearch() { ExpandMutableTreeNode root = (ExpandMutableTreeNode) this.getModel().getRoot(); @@ -313,6 +316,12 @@ public class TemplateFileTree extends EnvFileTree { } } + /** + * 将搜索匹配到的模板添加到搜索结果树里面 + * + * @param root + * @param treeNode + */ protected void addToTreeModel(ExpandMutableTreeNode root, ExpandMutableTreeNode treeNode) { FileNode fileNode = (FileNode) treeNode.getUserObject(); @@ -357,7 +366,7 @@ public class TemplateFileTree extends EnvFileTree { return result; } - protected void removePending(ExpandMutableTreeNode treeNode) { + private void removePending(ExpandMutableTreeNode treeNode) { if (treeNode.getChildCount() >= 1 && ((ExpandMutableTreeNode) treeNode.getFirstChild()).getUserObject() == PENDING) { treeNode.remove(0); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/clip/TemplateTreeClipboard.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/clip/TemplateTreeClipboard.java index f950701f58..e8f822b9a8 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/clip/TemplateTreeClipboard.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/clip/TemplateTreeClipboard.java @@ -5,6 +5,9 @@ import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import java.util.ArrayList; import java.util.List; +/** + * 模板复制黏贴 + */ public class TemplateTreeClipboard { private List clip = new ArrayList<>(); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateDirTreeSearchManager.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateDirTreeSearchManager.java index dcf8a5cb1a..67e798f6fc 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateDirTreeSearchManager.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/TemplateDirTreeSearchManager.java @@ -140,7 +140,7 @@ public class TemplateDirTreeSearchManager { FineLoggerFactory.getLogger().info("out of template search"); lastSearchText = null; if (treeSearcher != null) { - treeSearcher.afterSearch(); + treeSearcher.exitSearch(); } if (rendererHelper != null) { rendererHelper.restore(getCurrentTemplateDirTree()); @@ -155,14 +155,25 @@ public class TemplateDirTreeSearchManager { return treeSearcher.getMatchSets().toArray(new FileNode[0]); } + /** + * 当前目录树中搜索的目录节点 + * @return + */ public Map allFileNodes() { return treeSearcher.getAllTemplates(); } + /** + * 搜索结果是否为空 + * @return + */ public boolean isMatchSetsEmpty() { return treeSearcher.isMatchSetsEmpty(); } + /** + * 恢复到模板树面板 + */ public void restoreTreePane() { setTreeSearchStatus(TreeSearchStatus.SEARCH_NOT_BEGIN); lastSearchText = null; @@ -184,6 +195,10 @@ public class TemplateDirTreeSearchManager { return repeat; } + /** + * 当前是否处于搜索模式 + * @return + */ public boolean isInSearchMode() { return getTreeSearchStatus() != TreeSearchStatus.NOT_IN_SEARCH_MODE; } 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 9ae3b8e239..5a25d17be0 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 @@ -170,7 +170,7 @@ public class TemplateTreeSearchManager { setTreeSearchStatus(TreeSearchStatus.NOT_IN_SEARCH_MODE); FineLoggerFactory.getLogger().info("out of template search"); if (treeSearcher != null) { - treeSearcher.afterSearch(); + treeSearcher.exitSearch(); } lastSearchText = null; if (rendererHelper != null) { @@ -200,18 +200,33 @@ public class TemplateTreeSearchManager { return treeSearcher.getMatchSets().toArray(new FileNode[0]); } + /** + * 当前模板树中的所有模板节点 + * @return + */ public Map allFileNodes() { return treeSearcher.getAllTemplates(); } + /** + * 是否处于搜索模式 + * @return + */ public boolean isInSearchMode() { return getTreeSearchStatus() != TreeSearchStatus.NOT_IN_SEARCH_MODE; } + /** + * 退出搜索模式 + */ public void outOfSearchMode() { restoreToolBarAndTreePane(); } + /** + * 搜索结果数是否处于更新状态 + * @return + */ public boolean isRefreshing() { return isRefreshing.get(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/TemplateDirTreeSearcher.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/TemplateDirTreeSearcher.java index 5c553c8a65..fa120e65ec 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/TemplateDirTreeSearcher.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/TemplateDirTreeSearcher.java @@ -23,7 +23,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; - +/** + * 目录搜索器 + */ public class TemplateDirTreeSearcher extends TemplateTreeSearcher { private ExecutorService executorService; @@ -60,6 +62,11 @@ public class TemplateDirTreeSearcher extends TemplateTreeSearcher { return this.calculatedSets.size(); } + /** + * 将模板添加到已经计算过的集合中,不管模板是不是匹配 + * + * @param templateNames + */ public synchronized void addToCalculatedSets(List templateNames) { for (String templateName : templateNames) { FileNode fileNode = allDirs.get(templateName); @@ -70,10 +77,20 @@ public class TemplateDirTreeSearcher extends TemplateTreeSearcher { } } + /** + * 将搜索匹配的目录添加到匹配的集合中 + * + * @param matchNodes + */ public synchronized void addToMatchSets(List matchNodes) { matchSets.addAll(matchNodes); } + /** + * 将目录添加到未计算的集合中 + * + * @param fileNodes + */ public void addToNotCalculatedSets(List fileNodes) { synchronized (lock) { Map chileMap = fileNodes.stream().collect(Collectors.toMap(FileNode::getEnvPath, treeNode -> treeNode)); @@ -117,6 +134,11 @@ public class TemplateDirTreeSearcher extends TemplateTreeSearcher { allDirs.putAll(fileNodeMap); } + /** + * 开始搜索 + * + * @param searchText + */ @Override public void startSearch(String searchText) { reset(); @@ -141,11 +163,17 @@ public class TemplateDirTreeSearcher extends TemplateTreeSearcher { } while (outLayerDirCount.get() != 0); } + /** + * 停止搜索 + */ @Override public void stopSearch() { } + /** + * 完成搜索 + */ @Override public void completeSearch() { @@ -157,7 +185,10 @@ public class TemplateDirTreeSearcher extends TemplateTreeSearcher { notCalculatedSets.addAll(allDirs.keySet()); } - public void afterSearch() { + /** + * 退出搜索时的处理 + */ + public void exitSearch() { allDirs.clear(); executorService.shutdownNow(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/TemplateTreeSearcher.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/TemplateTreeSearcher.java index fd02cfddc2..95597e2b2e 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/TemplateTreeSearcher.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/TemplateTreeSearcher.java @@ -68,10 +68,20 @@ public class TemplateTreeSearcher implements TreeSearcher { } } + /** + * 将搜索匹配的模板添加到匹配的集合中 + * + * @param matchNodes + */ public synchronized void addToMatchSets(List matchNodes) { matchSets.addAll(matchNodes); } + /** + * 将模板添加到未计算的集合中 + * + * @param fileNodes + */ public void addToNotCalculatedSets(List fileNodes) { synchronized (lock) { Map chileMap = fileNodes.stream().collect(Collectors.toMap(FileNode::getEnvPath, treeNode -> treeNode)); @@ -116,6 +126,11 @@ public class TemplateTreeSearcher implements TreeSearcher { allTemplates.putAll(fileNodeMap); } + /** + * 开始搜索 + * + * @param searchText + */ @Override public void startSearch(String searchText) { reset(); @@ -140,11 +155,17 @@ public class TemplateTreeSearcher implements TreeSearcher { } while (outLayerDirCount.get() != 0); } + /** + * 停止搜索 + */ @Override public void stopSearch() { } + /** + * 完成搜索 + */ @Override public void completeSearch() { @@ -156,7 +177,10 @@ public class TemplateTreeSearcher implements TreeSearcher { notCalculatedSets.addAll(allTemplates.keySet()); } - public void afterSearch() { + /** + * 退出搜索模式 + */ + public void exitSearch() { allTemplates.clear(); executorService.shutdownNow(); } 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 d163c9ec7b..65ac5a020c 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 @@ -8,6 +8,9 @@ import com.fr.design.search.control.TreeSearchResult; import javax.swing.SwingUtilities; +/** + * 目录树搜索回调处理 + */ public class TemplateDirSearchCallBack implements TreeSearchCallback { protected TemplateDirTreeSearcher treeSearcher; @@ -30,6 +33,9 @@ public class TemplateDirSearchCallBack implements TreeSearchCallback { } } + /** + * 更新目录树搜索结果 + */ protected void updateTemplateTree() { SwingUtilities.invokeLater(() -> { if (TemplateDirTreeSearchManager.getInstance().getTreeSearchStatus() != TreeSearchStatus.SEARCHING) { 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 89f9065859..925760f791 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 @@ -7,6 +7,9 @@ import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; import com.fr.design.mainframe.manager.search.searcher.TemplateTreeSearcher; import javax.swing.SwingUtilities; +/** + * 模板搜索回调处理 + */ public class TemplateSearchCallBack implements TreeSearchCallback { protected TemplateTreeSearcher treeSearcher; @@ -28,6 +31,9 @@ public class TemplateSearchCallBack implements TreeSearchCallback { updateTemplateTree(); } + /** + * 更新目录树搜索结果 + */ protected void updateTemplateTree() { int calculatedCount = treeSearcher.getCalculatedCount(); boolean allCalculated = calculatedCount == treeSearcher.getAllTemplateSize(); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchResult.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchResult.java index 512fc6d832..65014f133f 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchResult.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/common/TemplateSearchResult.java @@ -6,6 +6,9 @@ import com.fr.file.filetree.FileNode; import java.util.ArrayList; import java.util.List; +/** + * 模板搜索结果 + */ public class TemplateSearchResult implements TreeSearchResult { private boolean success; 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 42aacc41d2..a23775bbb4 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 @@ -9,6 +9,9 @@ import com.fr.log.FineLoggerFactory; import java.util.ArrayList; import java.util.Arrays; +/** + * 模板搜索任务(比较模板路径与搜索关键字是否匹配) + */ public class TemplateSearchTask implements TreeSearchTask { /** diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateDirSearchRemindPane.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateDirSearchRemindPane.java index a0474333bc..5c0dbc65a1 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateDirSearchRemindPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateDirSearchRemindPane.java @@ -23,6 +23,9 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.FlowLayout; +/** + * 目录树搜索提示面板:整合了目录树面板和搜索时的提示面板 + */ public class TemplateDirSearchRemindPane extends JPanel implements TreeSearchStatusChangeListener { private TemplateDirSearchRemindPane.RemindPane remindPane; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateDirTreeSearchPane.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateDirTreeSearchPane.java index 18af8a742d..b2c9e54f0c 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateDirTreeSearchPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateDirTreeSearchPane.java @@ -26,6 +26,9 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +/** + * 目录树搜索面板 + */ public class TemplateDirTreeSearchPane extends JPanel implements TreeSearchStatusChangeListener { /** diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java index c2d53c82b4..bdb6a32819 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java @@ -24,6 +24,9 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.FlowLayout; +/** + * 模板搜索提示面板:整合了模板树和提示面板 + */ public class TemplateSearchRemindPane extends JPanel implements TreeSearchStatusChangeListener { private TemplateSearchRemindPane.RemindPane remindPane; @@ -67,12 +70,25 @@ public class TemplateSearchRemindPane extends JPanel implements TreeSearchStatus private interface TreeSearchStatusChange { + /** + * 搜索未开始时 + */ void onNotBegin(); + /** + * 搜索中 + */ void onInSearching(); + /** + * 停止搜索 + */ void onStoppedSearching(); + /** + * 搜索结束 + * @param matchSetsEmpty + */ void onDoneSearching(boolean matchSetsEmpty); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java index 0ff8c05916..bb98561bf9 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java @@ -30,6 +30,9 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +/** + * 模板搜索工具栏 + */ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchStatusChangeListener { public static final String TOOLBAR_PANE = "toolbarPane"; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplateDirPreSearchTask.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplateDirPreSearchTask.java index 6ab7782431..b6d626e62a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplateDirPreSearchTask.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pre/TemplateDirPreSearchTask.java @@ -6,6 +6,9 @@ import com.fr.file.filetree.FileNode; import java.util.List; +/** + * 目录树搜索时的前置处理,跟模板搜索前置处理类似 + */ public class TemplateDirPreSearchTask extends TemplatePreSearchTask { public TemplateDirPreSearchTask(TreeSearchCallback callback, FileNode fileNode) { 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 e98b7f264b..83176f1007 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 @@ -5,6 +5,10 @@ import com.fr.design.mainframe.manager.search.searcher.control.common.TemplateSe import com.fr.design.search.control.TreeSearchResult; import com.fr.design.mainframe.manager.search.searcher.TemplateTreeSearcher; +/** + * 模板搜索前置回调处理 + * 主要是将最外层目录下的所有模板添加到未计算的集合中 + */ public class TemplatePreSearchCallBack extends TemplateSearchCallBack { public TemplatePreSearchCallBack(TemplateTreeSearcher treeSearcher) { @@ -18,6 +22,11 @@ public class TemplatePreSearchCallBack extends TemplateSearchCallBack { } } + /** + * 将结果添加到未计算的集合中 + * + * @param searchResult + */ @Override protected void addToTreeSearcher(TreeSearchResult searchResult) { TemplateSearchResult templateSearchResult = (TemplateSearchResult) 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 f50eea77c1..496eef5140 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 @@ -11,6 +11,10 @@ import com.fr.log.FineLoggerFactory; import java.util.ArrayList; import java.util.List; +/** + * 模板搜索前置任务 + * 主要是计算最外层目录下面所有的子节点,并记录到结果集中 + */ public class TemplatePreSearchTask implements TreeSearchTask { protected TreeSearchCallback callback; diff --git a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java index c4cb64db09..9fb1e632af 100644 --- a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java @@ -3,12 +3,14 @@ package com.fr.design.utils; import com.fr.base.extension.FileExtension; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.TemplateTreePane; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.design.worker.save.SaveFailureHandler; import com.fr.file.FILE; import com.fr.file.FILEChooserPane; +import com.fr.file.filetree.FileNode; import com.fr.file.filter.ChooseFileFilter; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; @@ -19,6 +21,8 @@ import com.fr.workspace.server.lock.TplOperator; import javax.swing.SwingWorker; import java.io.OutputStream; +import java.util.List; +import java.util.stream.Collectors; /** * @author hades @@ -134,4 +138,34 @@ public class TemplateUtils { } return name.substring(0, index) + Toolkit.i18nText("Fine_Design_Template_Has_Been_Locked") + name.substring(index); } + + /** + * 检测当前所选模板是否已经被打开 + * + * @return + */ + public static boolean checkSelectedTemplateIsEditing() { + return checkTemplateIsEditing(TemplateTreePane.getInstance().getTemplateFileTree().getSelectedTreeNodes()); + } + + /** + * 检测指定模板节点是否已经被打开 + * + * @param treeNodes + * @return + */ + public static boolean checkTemplateIsEditing(ExpandMutableTreeNode[] treeNodes) { + if (ArrayUtils.isEmpty(treeNodes)) { + return false; + } + List> jTemplates = HistoryTemplateListCache.getInstance().getHistoryList(); + List openedFile = jTemplates.stream().map(JTemplate::getPath).collect(Collectors.toList()); + for (ExpandMutableTreeNode treeNode : treeNodes) { + String templatePath = ((FileNode) (treeNode.getUserObject())).getEnvPath(); + if (openedFile.contains(templatePath)) { + return true; + } + } + return false; + } }