Browse Source

REPORT-9314 【10.0一轮回归】模板目录无法显示excel文件也无法打开,9.0可以

后面有过滤的
master
ju 7 years ago
parent
commit
bf17d9f018
  1. 87
      designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java

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

@ -20,36 +20,40 @@ import java.util.List;
* 显示Env下的reportlets目录下面的所有cpt文件 * 显示Env下的reportlets目录下面的所有cpt文件
*/ */
public class TemplateFileTree extends EnvFileTree { public class TemplateFileTree extends EnvFileTree {
public TemplateFileTree() { public TemplateFileTree() {
super(ProjectConstants.REPORTLETS_NAME, null, null); super(ProjectConstants.REPORTLETS_NAME, null, null);
} }
/* /*
* 选中reportPath * 选中reportPath
*/ */
public void setSelectedTemplatePath(String templatePath) { public void setSelectedTemplatePath(String templatePath) {
this.selectPath(templatePath); this.selectPath(templatePath);
} }
/** /**
* 返回选中的Template的路径 * 返回选中的Template的路径
*/ */
public String getSelectedTemplatePath() { public String getSelectedTemplatePath() {
FileNode fn = this.getSelectedFileNode(); FileNode fn = this.getSelectedFileNode();
if (fn != null && !fn.isDirectory()) { if (fn != null && !fn.isDirectory()) {
String envPath = fn.getEnvPath(); String envPath = fn.getEnvPath();
if (envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { if (envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
return envPath.substring(ProjectConstants.REPORTLETS_NAME.length()); return envPath.substring(ProjectConstants.REPORTLETS_NAME.length());
} }
} }
return null; return null;
} }
public String[] getSelectedTemplatePaths() { public String[] getSelectedTemplatePaths() {
TreePath[] selectedTreePaths = this.getSelectionPaths(); TreePath[] selectedTreePaths = this.getSelectionPaths();
if (ArrayUtils.isEmpty(selectedTreePaths)) { if (ArrayUtils.isEmpty(selectedTreePaths)) {
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
@ -68,13 +72,13 @@ public class TemplateFileTree extends EnvFileTree {
} }
} }
} }
return selectedPathList.toArray(new String[0]); return selectedPathList.toArray(new String[0]);
} }
public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) { public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) {
int max = getRowCount(); int max = getRowCount();
if (prefix == null) { if (prefix == null) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@ -89,9 +93,9 @@ public class TemplateFileTree extends EnvFileTree {
do { do {
TreePath path = getPathForRow(row); TreePath path = getPathForRow(row);
String text = convertValueToText( String text = convertValueToText(
path.getLastPathComponent(), isRowSelected(row), path.getLastPathComponent(), isRowSelected(row),
isExpanded(row), true, row, false); isExpanded(row), true, row, false);
if (text.toUpperCase().startsWith(prefix)) { if (text.toUpperCase().startsWith(prefix)) {
return path; return path;
} }
@ -99,24 +103,23 @@ public class TemplateFileTree extends EnvFileTree {
} while (row != startingRow); } while (row != startingRow);
return null; return null;
} }
public FileNode[] listFile(String path) throws Exception { public FileNode[] listFile(String path) throws Exception {
return FRContext.getFileNodes().list(
path, return FRContext.getFileNodes().list(path);
new FileExtension[]{FileExtension.CPT, FileExtension.FRM, FileExtension.CPTX, FileExtension.FRMX});
} }
/* /*
* 改变Env后,根据构造函数时设置的RootPaths,重新加载 * 改变Env后,根据构造函数时设置的RootPaths,重新加载
*/ */
public void refreshEnv() { public void refreshEnv() {
DefaultTreeModel defaultTreeModel = (DefaultTreeModel) this.getModel(); DefaultTreeModel defaultTreeModel = (DefaultTreeModel) this.getModel();
ExpandMutableTreeNode rootTreeNode = (ExpandMutableTreeNode) defaultTreeModel.getRoot(); ExpandMutableTreeNode rootTreeNode = (ExpandMutableTreeNode) defaultTreeModel.getRoot();
rootTreeNode.removeAllChildren(); rootTreeNode.removeAllChildren();
FileNode[] fns; FileNode[] fns;
// 如果rootPaths是null的话列出所有文件 // 如果rootPaths是null的话列出所有文件
if (subPathes == null) { if (subPathes == null) {
fns = listFileNodes(this.treeRootPath); fns = listFileNodes(this.treeRootPath);
@ -127,26 +130,28 @@ public class TemplateFileTree extends EnvFileTree {
fns[i] = new FileNode(StableUtils.pathJoin(this.treeRootPath, subPathes[i]), true); fns[i] = new FileNode(StableUtils.pathJoin(this.treeRootPath, subPathes[i]), true);
} }
} }
ExpandMutableTreeNode[] subTreeNodes = fileNodeArray2TreeNodeArray(fns); ExpandMutableTreeNode[] subTreeNodes = fileNodeArray2TreeNodeArray(fns);
for (ExpandMutableTreeNode node : subTreeNodes) { for (ExpandMutableTreeNode node : subTreeNodes) {
rootTreeNode.add(node); rootTreeNode.add(node);
} }
defaultTreeModel.reload(rootTreeNode); defaultTreeModel.reload(rootTreeNode);
} }
protected ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) { protected ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) {
FileNode[] fn_array = listFileNodes(treeNode); FileNode[] fn_array = listFileNodes(treeNode);
return fileNodeArray2TreeNodeArray(fn_array); return fileNodeArray2TreeNodeArray(fn_array);
} }
/* /*
* 把FileNode[]转成ExpandMutableTreeNode[] * 把FileNode[]转成ExpandMutableTreeNode[]
*/ */
private ExpandMutableTreeNode[] fileNodeArray2TreeNodeArray(FileNode[] fileNodes) { private ExpandMutableTreeNode[] fileNodeArray2TreeNodeArray(FileNode[] fileNodes) {
ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[fileNodes.length]; ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[fileNodes.length];
for (int i = 0; i < res.length; i++) { for (int i = 0; i < res.length; i++) {
FileNode fn = fileNodes[i]; FileNode fn = fileNodes[i];
@ -155,12 +160,13 @@ public class TemplateFileTree extends EnvFileTree {
res[i].add(new ExpandMutableTreeNode()); res[i].add(new ExpandMutableTreeNode());
} }
} }
return res; return res;
} }
private FileNode[] listFileNodes(String filePath) { private FileNode[] listFileNodes(String filePath) {
FileNode[] fileNodes = null; FileNode[] fileNodes = null;
try { try {
fileNodes = listFile(filePath); fileNodes = listFile(filePath);
@ -178,31 +184,32 @@ public class TemplateFileTree extends EnvFileTree {
list.add(fileNode); list.add(fileNode);
} }
} }
fileNodes = list.toArray(new FileNode[list.size()]); fileNodes = list.toArray(new FileNode[list.size()]);
} }
Arrays.sort(fileNodes, new FileNodeComparator()); Arrays.sort(fileNodes, new FileNodeComparator());
return fileNodes; return fileNodes;
} }
/* /*
* 求当前TreeNode下所有的FileNode. * 求当前TreeNode下所有的FileNode.
*/ */
private FileNode[] listFileNodes(ExpandMutableTreeNode currentTreeNode) { private FileNode[] listFileNodes(ExpandMutableTreeNode currentTreeNode) {
if (currentTreeNode == null) { if (currentTreeNode == null) {
return new FileNode[0]; return new FileNode[0];
} }
Object object = currentTreeNode.getUserObject(); Object object = currentTreeNode.getUserObject();
if (object instanceof FileNode) { if (object instanceof FileNode) {
return this.listFileNodes(((FileNode) object).getEnvPath()); return this.listFileNodes(((FileNode) object).getEnvPath());
} }
return new FileNode[0]; return new FileNode[0];
} }
} }
Loading…
Cancel
Save