帆软报表设计器源代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

163 lines
6.2 KiB

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;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager;
import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils;
import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.event.ActionEvent;
import java.io.File;
/**
* 模板定位功能
*/
public class LocateAction extends UpdateAction {
public LocateAction() {
this.setName(Toolkit.i18nText("Fine-Design_Basic_Locate"));
this.setSmallIcon("/com/fr/design/standard/locate/locate");
}
@Override
public void actionPerformed(ActionEvent e) {
JTemplate<?, ?> current = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
gotoEditingTemplateLeaf(current.getEditingFILE().getPath(), false);
}
/**
* 在左侧模板树定位到指定模板
*
* @param locatedPath
*/
public static void gotoEditingTemplateLeaf(String locatedPath) {
gotoEditingTemplateLeaf(locatedPath, true);
}
private static void gotoEditingTemplateLeaf(String locatedPath, boolean needRefreshMode) {
if (locatedPath == null) {
return;
}
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
}
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 = getTemplateFileTree().getSelectionPath();
if (selectedTreePath != null) {
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);
// 取出当前的childTreeNode,并append到searchingPath后面
ExpandMutableTreeNode childTreeNode = (ExpandMutableTreeNode) node;
if (selectFilePath(childTreeNode, ProjectConstants.REPORTLETS_NAME, currentPath, m_model)) {
break;
}
if (!node.isLeaf()) {
for (int j = 0; j < node.getChildCount(); j++) {
recursiveSelectPath(node.getChildAt(j), currentPath, m_model);
}
}
}
}
/*
* 在currentTreeNode下找寻filePath
*
* prefix + currentTreeNode.getName() = currentTreeNode所对应的Path
*
* 返回currentTreeNode下是否找到了filePath
*/
private static boolean selectFilePath(ExpandMutableTreeNode currentTreeNode, String prefix, String filePath, DefaultTreeModel model) {
Object userObj = currentTreeNode.getUserObject();
if (!(userObj instanceof FileNode)) {
return false;
}
FileNode fileNode = (FileNode) userObj;
String nodePath = fileNode.getName();
String currentTreePath = StableUtils.pathJoin(prefix, nodePath);
boolean result = false;
// 如果equals,说明找到了,不必再找下去了
if (ComparatorUtils.equals(new File(currentTreePath), new File(filePath))) {
getTemplateFileTree().setSelectionPath(new TreePath(model.getPathToRoot(currentTreeNode)));
result = true;
}
// 如果当前路径是currentFilePath的ParentFile,则expandTreeNode,并继续往下找
else if (isParentFile(currentTreePath, filePath)) {
loadPendingChildTreeNode(currentTreeNode);
prefix = currentTreePath + CoreConstants.SEPARATOR;
for (int i = 0, len = currentTreeNode.getChildCount(); i < len; i++) {
ExpandMutableTreeNode childTreeNode = (ExpandMutableTreeNode) currentTreeNode.getChildAt(i);
if (selectFilePath(childTreeNode, prefix, filePath, model)) {
result = true;
}
}
}
return result;
}
protected static void loadPendingChildTreeNode(ExpandMutableTreeNode currentTreeNode) {
if (currentTreeNode.isLeaf()) {
return;
}
// 判断第一个孩子节点.UserObject是不是PENDING,如果是PENDING的话,需要重新加载这个TreeNode
ExpandMutableTreeNode flag = (ExpandMutableTreeNode) currentTreeNode.getFirstChild();
if (flag == null || !flag.getUserObject().toString().equals(RefreshableJTree.PENDING.toString())) {
return;
}
// 删除所有的节点.
currentTreeNode.removeAllChildren();
ExpandMutableTreeNode[] children = getTemplateFileTree().loadChildTreeNodes(currentTreeNode);
for (ExpandMutableTreeNode c : children) {
currentTreeNode.add(c);
}
}
private static boolean isParentFile(String var0, String var1) {
File var2 = new File(var0);
File var3 = new File(var1);
while (!ComparatorUtils.equals(var2, var3)) {
var3 = var3.getParentFile();
if (var3 == null) {
return false;
}
}
return true;
}
}