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 262da62117..2971f38e22 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 @@ -37,11 +37,17 @@ import com.fr.workspace.base.UserInfo; import com.fr.workspace.server.repository.vcs.VcsRepository; import org.jetbrains.annotations.Nullable; -import javax.swing.*; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; +import javax.swing.ToolTipManager; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Desktop; +import java.awt.Dimension; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; @@ -53,8 +59,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; import java.util.Objects; -import java.util.Observable; -import java.util.Observer; import java.util.Set; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -88,12 +92,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { ToolTipManager.sharedInstance().registerComponent(reportletsTree); - FileLockStateObservable.getInstance().addObserver(new Observer() { - @Override - public void update(Observable o, Object arg) { - TemplateTreePane.this.refresh(); - } - }); + FileLockStateObservable.getInstance().addObserver((o, arg) -> TemplateTreePane.this.refresh()); /* * Tree.MouseAdapter @@ -102,6 +101,9 @@ public class TemplateTreePane extends JPanel implements FileOperations { @Override public void mousePressed(MouseEvent evt) { + if (isDirectorySelection()) { + return; + } if (evt.getClickCount() == 2) { DesignCacheManager.processByCacheTableData(() -> openFile()); } @@ -157,6 +159,16 @@ public class TemplateTreePane extends JPanel implements FileOperations { }); } + /** + * 选中的是否目录 + * + * @return 是否目录 + */ + private boolean isDirectorySelection() { + FileNode fileNode = reportletsTree.getSelectedFileNode(); + return fileNode != null && fileNode.isDirectory(); + } + public TemplateFileTree getTemplateFileTree() { return this.reportletsTree; } @@ -256,7 +268,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { } @Nullable - private JTemplate getOpenedTemplate(String path) { + private JTemplate getOpenedTemplate(String path) { for (JTemplate template : HistoryTemplateListCache.getInstance().getHistoryList()) { if (ComparatorUtils.equals(template.getEditingFILE().getPath(), path)) { return template; @@ -380,7 +392,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { TreePath[] paths = reportletsTree.getSelectionPaths(); if (paths == null) { reportletsTree.refresh(); - } else { + } else { for (TreePath path : Objects.requireNonNull(reportletsTree.getSelectionPaths())) { reportletsTree.refreshParent(path); } @@ -389,7 +401,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { } private void deleteNodes(Collection nodes) { - new SwingWorker(){ + new SwingWorker() { @Override protected Boolean doInBackground() throws Exception { boolean success = true; @@ -415,6 +427,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { } return success; } + @Override protected void done() { try { @@ -518,6 +531,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { } return false; } + public void setToolbarStateChangeListener(FileToolbarStateChangeListener listener) { this.toolBarStateChangeListener = listener; } @@ -526,8 +540,8 @@ public class TemplateTreePane extends JPanel implements FileOperations { /** * 仅支持在拥有完整权限的文件夹下进行新建和重命名操作,那么是可以看到改文件夹下所有文件的。 * - * @param newName 原名 - * @param suffix 后缀名 + * @param newName 原名 + * @param suffix 后缀名 * @param baseOnSelf 检验目录时,是基于自身目录的子节点还是基于父目录的子节点进行校验 * @return 是否有重名的 */