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 8c5955bcdc..db308181dc 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 @@ -3,6 +3,7 @@ package com.fr.design.actions.file; import com.fr.design.actions.UpdateAction; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.TemplateTreePane; +import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.gui.itree.refreshabletree.RefreshableJTree; import com.fr.design.i18n.Toolkit; @@ -32,7 +33,7 @@ public class LocateAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { JTemplate current = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - gotoEditingTemplateLeaf(current.getEditingFILE().getPath()); + gotoEditingTemplateLeaf(current.getEditingFILE().getPath(), false); } /** @@ -41,20 +42,34 @@ public class LocateAction extends UpdateAction { * @param locatedPath */ public static void gotoEditingTemplateLeaf(String locatedPath) { + gotoEditingTemplateLeaf(locatedPath, true); + } + + private static void gotoEditingTemplateLeaf(String locatedPath, boolean needRefreshMode) { if (locatedPath == null) { return; } - DefaultTreeModel model = (DefaultTreeModel) TemplateTreePane.getInstance().getTemplateFileTree().getModel(); + DefaultTreeModel model = (DefaultTreeModel) getTemplateFileTree().getModel(); ExpandMutableTreeNode treeNode = (ExpandMutableTreeNode) model.getRoot(); + if (needRefreshMode) { + treeNode.removeAllChildren(); + ExpandMutableTreeNode[] childTreeNodes = getTemplateFileTree().loadChildTreeNodes(treeNode); + treeNode.addChildTreeNodes(childTreeNodes); + model.reload(treeNode); + } recursiveSelectPath(treeNode, locatedPath, model); - TreePath selectedTreePath = TemplateTreePane.getInstance().getTemplateFileTree().getSelectionPath(); + TreePath selectedTreePath = getTemplateFileTree().getSelectionPath(); if (selectedTreePath != null) { - TemplateTreePane.getInstance().getTemplateFileTree().scrollPathToVisible(selectedTreePath); + getTemplateFileTree().scrollPathToVisible(selectedTreePath); } } + private static TemplateFileTree getTemplateFileTree() { + return TemplateTreePane.getInstance().getTemplateFileTree(); + } + private static void recursiveSelectPath(TreeNode treeNode, String currentPath, DefaultTreeModel m_model) { for (int i = 0, len = treeNode.getChildCount(); i < len; i++) { TreeNode node = treeNode.getChildAt(i); @@ -90,7 +105,7 @@ public class LocateAction extends UpdateAction { // 如果equals,说明找到了,不必再找下去了 if (ComparatorUtils.equals(new File(currentTreePath), new File(filePath))) { - TemplateTreePane.getInstance().getTemplateFileTree().setSelectionPath(new TreePath(model.getPathToRoot(currentTreeNode))); + getTemplateFileTree().setSelectionPath(new TreePath(model.getPathToRoot(currentTreeNode))); result = true; } // 如果当前路径是currentFilePath的ParentFile,则expandTreeNode,并继续往下找 @@ -122,7 +137,7 @@ public class LocateAction extends UpdateAction { // 删除所有的节点. currentTreeNode.removeAllChildren(); - ExpandMutableTreeNode[] children = TemplateTreePane.getInstance().getTemplateFileTree().loadChildTreeNodes(currentTreeNode); + ExpandMutableTreeNode[] children = getTemplateFileTree().loadChildTreeNodes(currentTreeNode); for (ExpandMutableTreeNode c : children) { currentTreeNode.add(c); } diff --git a/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java b/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java index aabb6ef751..480edea346 100644 --- a/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java +++ b/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java @@ -68,6 +68,11 @@ import java.awt.geom.Path2D; import java.awt.geom.RoundRectangle2D; import java.util.List; +import static com.fr.design.dialog.FineJOptionPane.showConfirmDialog; +import static javax.swing.JOptionPane.OK_CANCEL_OPTION; +import static javax.swing.JOptionPane.OK_OPTION; +import static javax.swing.JOptionPane.WARNING_MESSAGE; + /** * Author : daisy * Date: 13-8-5 @@ -265,7 +270,33 @@ public class MutilTempalteTabPane extends JComponent { TemplateTreePane.getInstance().refreshDockingView(); } JTemplate template = openedTemplate.get(this.tplIndex); - super.gotoEditingTemplateLeaf(template.getPath()); + locateTemplate(template); + } + + private void locateTemplate(JTemplate template) { + FILE currentTemplate = template.getEditingFILE(); + //模板不属于当前环境,跟预览一样先提示保存,再定位模板 + if (!currentTemplate.exists()) { + int selVal = showConfirmDialog( + DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Web_Preview_Message"), + Toolkit.i18nText("Fine-Design_Basic_Preview_Tool_Tips"), + OK_CANCEL_OPTION, + WARNING_MESSAGE + ); + if (OK_OPTION == selVal) { + CallbackSaveWorker worker = template.saveAs(); + worker.start(template.getRuntimeId()); + worker.addSuccessCallback(new Runnable() { + @Override + public void run() { + gotoEditingTemplateLeaf(template.getPath()); + } + }); + } + } else { + gotoEditingTemplateLeaf(template.getPath()); + } } } 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 c2a2a9c600..e6bfff633c 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 @@ -476,6 +476,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt @Override public void actionPerformed(ActionEvent e) { TemplateTreePane.getInstance().refreshDockingView(); + refreshDockingView(); } }