Browse Source

Merge pull request #414 in DESIGN/design from ~YAOH.WU/design:feature/10.0 to feature/10.0

* commit '3752c38f176805e9c3c4defed6b3b5310b7a7a7a':
  REPORT-10689 远程设计新建删除和重命名
research/10.0
yaoh.wu 6 years ago
parent
commit
869fb69161
  1. 38
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 77
      designer-base/src/main/java/com/fr/design/file/FileOperations.java
  3. 291
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  4. 451
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListPane.java
  5. 225
      designer-base/src/main/java/com/fr/design/file/NodeAuthProcessor.java
  6. 340
      designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java
  7. 136
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java
  8. 670
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java
  9. 68
      designer-base/src/main/java/com/fr/design/menu/KeySetUtils.java
  10. 71
      designer-base/src/main/java/com/fr/file/FILE.java
  11. 831
      designer-base/src/main/java/com/fr/file/FILEChooserPane.java
  12. 6
      designer-base/src/main/java/com/fr/file/FILEFactory.java
  13. 65
      designer-base/src/main/java/com/fr/file/FileFILE.java
  14. 239
      designer-base/src/main/java/com/fr/file/FileNodeFILE.java
  15. 7
      designer-base/src/main/java/com/fr/file/MemFILE.java
  16. BIN
      designer-base/src/main/resources/com/fr/design/images/icon_NewFolderIcon_normal.png

38
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -41,9 +41,10 @@ import com.fr.stable.xml.XMLableReader;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.WorkContextCallback; import com.fr.workspace.WorkContextCallback;
import javax.swing.*; import javax.swing.SwingWorker;
import javax.swing.SwingWorker.StateValue; import javax.swing.SwingWorker.StateValue;
import java.awt.*; import java.awt.Color;
import java.awt.Rectangle;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
@ -57,6 +58,7 @@ import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -482,7 +484,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
public void setLastEastRegionContainerWidth(int eastRegionContainerWidth) { public void setLastEastRegionContainerWidth(int eastRegionContainerWidth) {
this.eastRegionContainerWidth = eastRegionContainerWidth; this.eastRegionContainerWidth = eastRegionContainerWidth;
} }
/** /**
* 返回默认环境 * 返回默认环境
*/ */
@ -544,7 +546,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
DesignerEnvManager.getEnvManager().setCurEnvName(envName); DesignerEnvManager.getEnvManager().setCurEnvName(envName);
DesignUtils.refreshDesignerFrame(); DesignUtils.refreshDesignerFrame();
if(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate() != null) { if (HistoryTemplateListPane.getInstance().getCurrentEditingTemplate() != null) {
HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea(); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea();
} }
DesignTableDataManager.fireDSChanged(new HashMap<String, String>()); DesignTableDataManager.fireDSChanged(new HashMap<String, String>());
@ -866,12 +868,38 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
public void replaceRecentOpenedFilePath(String oldPath, String newPath) { public void replaceRecentOpenedFilePath(String oldPath, String newPath) {
List<String> list = getRecentOpenedFilePathList(); List<String> list = getRecentOpenedFilePathList();
if (list.contains(oldPath)) { if (list.contains(oldPath)) {
int index = getRecentOpenedFilePathList().indexOf(oldPath); int index = list.indexOf(oldPath);
list.remove(oldPath);
list.add(index, newPath);
}
oldPath = oldPath.replaceAll("\\\\", "/");
if (list.contains(oldPath)) {
int index = list.indexOf(oldPath);
list.remove(oldPath); list.remove(oldPath);
list.add(index, newPath); list.add(index, newPath);
} }
} }
/**
* 替换近期打开的文件路径
*
* @param type 文件类型,文件夹true,文件false
* @param oldPath 旧的路径 使用反斜杠分割
* @param newPath 新的路径 使用反斜杠分割
*/
public void replaceRecentOpenedFilePath(boolean type, String oldPath, String newPath) {
List<String> list = getRecentOpenedFilePathList();
ListIterator<String> iterator = list.listIterator();
while (iterator.hasNext()) {
String s = iterator.next().replaceAll("/", "\\\\");
if (type ? s.contains(oldPath + "\\") : s.equals(oldPath)) {
s = s.replace(oldPath, newPath);
iterator.set(s);
}
}
}
private void checkRecentOpenedFileNum() { private void checkRecentOpenedFileNum() {
List<String> list = getRecentOpenedFilePathList(); List<String> list = getRecentOpenedFilePathList();
if (list == null) { if (list == null) {

77
designer-base/src/main/java/com/fr/design/file/FileOperations.java

@ -1,45 +1,88 @@
package com.fr.design.file; package com.fr.design.file;
import com.fr.file.FILE;
import com.fr.file.filetree.FileNode;
public interface FileOperations { public interface FileOperations {
/**
* 新建文件夹
*
* @param name 文件夹名称
* @return 是否成功
*/
boolean mkdir(String name);
/**
* 打开报表文件
*/
void openFile();
/**
* 打开文件夹
*/
void showInExplorer();
/**
* 刷新
*/
void refresh();
/** /**
*打开选中的报表文件 * 删除文件
*/ */
public void openSelectedReport(); void deleteFile();
/** /**
*打开文件夹 * 加上文件锁
*/ */
public void openContainerFolder(); void lockFile();
/** /**
*刷新 * 文件解锁
*/ */
public void refresh(); void unlockFile();
/**
* 选中的模板路径
*
* @return 选中的模板路径
*/
String getFilePath();
/** /**
*删除文件 * 选中的文件节点
*
* @return 文件节点
*/ */
public void deleteFile(); FileNode getFileNode();
/** /**
*加上文件锁 * 是否有完整权限
*
* @return 是否有完整权限
*/ */
public void lockFile(); boolean access();
/** /**
*文件解锁 * 重命名
*
* @param tplFile 旧文件
* @param to 新文件名
* @param from 旧文件名
* @return 是否成功
*/ */
public void unLockFile(); boolean rename(FILE tplFile, String from, String to);
public String getSelectedTemplatePath();
/** /**
*文件名是否存在 * 文件名是否存在
*
* @param newName 原名 * @param newName 原名
* @param oldName 新的文件名 * @param suffix 后缀名
* @param suffix 后缀名
* @return 是否存在 * @return 是否存在
*/ */
public boolean isNameAlreadyExist(String newName, String oldName, String suffix); boolean duplicated(String newName, String suffix);
} }

291
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java

@ -0,0 +1,291 @@
package com.fr.design.file;
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.design.DesignerEnvManager;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.module.DesignModuleFactory;
import com.fr.file.FILE;
import com.fr.file.FileNodeFILE;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
/**
* 历史模板缓存
*
* @see HistoryTemplateListPane
*/
public class HistoryTemplateListCache implements CallbackEvent {
//最大保存内存中面板数,为0时关闭优化内存
private static final int DEAD_LINE = DesignerEnvManager.getEnvManager().getCachingTemplateLimit();
private List<JTemplate<?, ?>> historyList;
private JTemplate<?, ?> editingTemplate;
private static volatile HistoryTemplateListCache THIS;
public static HistoryTemplateListCache getInstance() {
if (THIS == null) {
synchronized (HistoryTemplateListCache.class) {
if (THIS == null) {
THIS = new HistoryTemplateListCache();
}
}
}
return THIS;
}
private HistoryTemplateListCache() {
historyList = new ArrayList<>();
}
/**
* 关闭选择的文件
*
* @param selected 选择的
*/
public void closeSelectedReport(JTemplate<?, ?> selected) {
DesignModuleFactory.clearChartPropertyPane();
DesignTableDataManager.closeTemplate(selected);
if (contains(selected) == -1) {
return;
}
selected.fireJTemplateClosed();
selected.stopEditing();
try {
historyList.remove(contains(selected));
selected.getEditingFILE().closeTemplate();
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName()));
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 临时关闭选择的文件
*
* @param selected 选择的
*/
public void closeVirtualSelectedReport(JTemplate<?, ?> selected) {
DesignModuleFactory.clearChartPropertyPane();
DesignTableDataManager.closeTemplate(selected);
if (contains(selected) == -1) {
return;
}
selected.fireJTemplateClosed();
selected.stopEditing();
try {
selected.getEditingFILE().closeTemplate();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
public JTemplate<?, ?> getCurrentEditingTemplate() {
return this.editingTemplate;
}
public void setCurrentEditingTemplate(JTemplate<?, ?> jt) {
this.editingTemplate = jt;
//如果当前历史面板中没有
if (contains(jt) == -1) {
addHistory();
}
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList);
//设置tab栏为当前选中的那一栏
if (editingTemplate != null) {
MutilTempalteTabPane.getInstance().setSelectedIndex(contains(jt));
}
}
/**
* 添加历史记录
*/
public void addHistory() {
if (editingTemplate == null) {
return;
}
DesignerEnvManager.getEnvManager().addRecentOpenedFilePath(editingTemplate.getPath());
historyList.add(editingTemplate);
closeOverLineTemplate();
}
public List<JTemplate<?, ?>> getHistoryList() {
return historyList;
}
/**
* 清空历史记录
*/
public void removeAllHistory() {
historyList.clear();
this.editingTemplate = null;
}
public int getHistoryCount() {
return historyList.size();
}
public JTemplate<?, ?> get(int index) {
if (index > historyList.size() - 1 || index < 0) {
return null;
}
Collections.reverse(historyList);
JTemplate<?, ?> select = historyList.get(index);
Collections.reverse(historyList);
return select;
}
public JTemplate<?, ?> getTemplate(int index) {
return historyList.get(index);
}
/**
* 获取模板的index
*
* @param jt 模板
* @return 位置
*/
public int contains(JTemplate<?, ?> jt) {
for (int i = 0; i < historyList.size(); i++) {
if (ComparatorUtils.equals(historyList.get(i).getEditingFILE(), jt.getEditingFILE())) {
return i;
}
}
return -1;
}
/**
* 判断是否打开过该模板
*
* @param filename 文件名
* @return 文件位置
*/
public int contains(String filename) {
for (int i = 0; i < historyList.size(); i++) {
String historyPath = historyList.get(i).getPath().replaceAll("/", "\\\\");
//文件路径是全路径,历史路径是reportlets/模板名
if (filename.endsWith(historyPath)) {
return i;
}
}
return -1;
}
/**
* 是否是当前编辑的文件
*
* @param filename 文件名
* @return 是则返回TRUE
*/
public boolean isCurrentEditingFile(String filename) {
String editingFileName = editingTemplate.getPath();
return ComparatorUtils.equals(filename, editingFileName);
}
@Override
public void callback() {
getCurrentEditingTemplate().repaint();
}
/**
* 打开new模板的同时关闭old模板,优先关已保存的先打开的
*/
public void closeOverLineTemplate() {
int size = historyList.size();
int vCount = size - DEAD_LINE;
if (DEAD_LINE == 0 || vCount <= 0) {
return;
}
for (int i = 0; i < vCount; i++) {
JTemplate overTemplate = historyList.get(i);
if (overTemplate.getEditingFILE().exists() && overTemplate.isALLSaved() && overTemplate != editingTemplate) {
historyList.get(i).closeOverLineTemplate(i);
}
}
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList);
}
public void deleteFile(FileNodeFILE file) {
boolean isDir = file.isDirectory();
String suffix = isDir ? "\\" : StringUtils.EMPTY;
// path like reportlets/xx/xxx/xxx
String path = file.getPath().replaceAll("/", "\\\\") + suffix;
ListIterator<JTemplate<?, ?>> iterator = historyList.listIterator();
while (iterator.hasNext()) {
JTemplate<?, ?> template = iterator.next();
String tPath = template.getPath().replaceAll("/", "\\\\");
if (isDir ? tPath.startsWith(path) : tPath.equals(path)) {
iterator.remove();
int index = iterator.nextIndex();
int size = getHistoryCount();
if (size == index + 1 && index > 0) {
//如果删除的是后一个Tab,则定位到前一个
MutilTempalteTabPane.getInstance().setSelectedIndex(index - 1);
JTemplate selectedFile = MutilTempalteTabPane.getInstance().getSelectedFile();
if (!isCurrentEditingFile(selectedFile.getPath())) {
//如果此时面板上的实时刷新的selectedIndex得到的和历史的不一样
DesignerContext.getDesignerFrame().activateJTemplate(selectedFile);
}
}
}
}
//如果打开过,则删除,实时刷新多tab面板
int openFileCount = getHistoryCount();
if (openFileCount == 0) {
DesignerContext.getDesignerFrame().addAndActivateJTemplate();
}
MutilTempalteTabPane.getInstance().repaint();
}
public boolean rename(FILE tplFile, String from, String to) {
boolean isDir = tplFile.isDirectory();
JTemplate<?, ?> template;
template = this.getCurrentEditingTemplate();
if (template != null) {
String editingPath = template.getEditingFILE().getPath().replaceAll("/", "\\\\");
if (isDir ? editingPath.contains(from + "\\") : editingPath.equals(from)) {
FILE renameFile = template.getEditingFILE();
renameFile.setPath(editingPath.replace(from, to));
}
}
for (int i = 0; i < this.getHistoryCount(); i++) {
template = this.get(i);
String editingPath = template.getEditingFILE().getPath().replaceAll("/", "\\\\");
if (isDir ? editingPath.contains(from + "\\") : editingPath.equals(from)) {
FILE renameFile = template.getEditingFILE();
renameFile.setPath(editingPath.replace(from, to));
}
}
return true;
}
}

451
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListPane.java

@ -1,443 +1,16 @@
package com.fr.design.file; package com.fr.design.file;
import com.fr.base.FRContext; /**
import com.fr.base.chart.chartdata.CallbackEvent; * 历史模板缓存
import com.fr.design.DesignModelAdapter; *
import com.fr.design.DesignerEnvManager; * 为可能存在的插件做兼容处理
import com.fr.design.constants.UIConstants; *
import com.fr.design.data.DesignTableDataManager; * @see HistoryTemplateListCache
import com.fr.design.data.datapane.TableDataTreePane; * @deprecated use HistoryTemplateListCache instead
import com.fr.design.gui.icontainer.UIScrollPane; */
import com.fr.design.gui.ilable.UILabel; @Deprecated
import com.fr.design.gui.ilist.UIList; public class HistoryTemplateListPane {
import com.fr.design.mainframe.DesignerContext; public static HistoryTemplateListCache getInstance() {
import com.fr.design.mainframe.JTemplate; return HistoryTemplateListCache.getInstance();
import com.fr.design.module.DesignModuleFactory;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.Constants;
import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class HistoryTemplateListPane extends JPanel implements FileOperations, CallbackEvent {
//最大保存内存中面板数,为0时关闭优化内存
private static final int DEAD_LINE = DesignerEnvManager.getEnvManager().getCachingTemplateLimit();;
private static final int LIST_BORDER = 4;
private List<JTemplate<?, ?>> historyList;
private JTemplate<?, ?> editingTemplate;
private FileToolbarStateChangeListener toobarStateChangeListener;
private static volatile HistoryTemplateListPane THIS;
private UIList list;
public static final HistoryTemplateListPane getInstance() {
if (THIS == null) {
synchronized (HistoryTemplateListPane.class) {
if (THIS == null) {
THIS = new HistoryTemplateListPane();
}
}
}
return THIS;
}
private HistoryTemplateListPane() {
setLayout(new BorderLayout());
historyList = new ArrayList<JTemplate<?, ?>>();
list = new UIList(new HistoryListDataMode()) {
public int locationToIndex(Point location) {
int rowCount = getModel().getSize();
int height = getPreferredSize().height - 2 * LIST_BORDER;
int rowHeight = height / rowCount;
int index = (location.y - LIST_BORDER) / rowHeight;
if (location.y < LIST_BORDER || index > rowCount - 1) {
return -1;
} else {
return index;
}
}
};
ToolTipManager.sharedInstance().registerComponent(list);
list.setBackground(UIConstants.NORMAL_BACKGROUND);
list.setCellRenderer(new HistoryListCellRender());
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() < 2) {
return;
}
openSelectedReport();
}
});
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (toobarStateChangeListener != null) {
toobarStateChangeListener.stateChange();
}
}
});
list.setBorder(BorderFactory.createEmptyBorder(LIST_BORDER, LIST_BORDER, LIST_BORDER, LIST_BORDER));
UIScrollPane scrollPane = new UIScrollPane(list);
scrollPane.setBorder(null);
this.add(scrollPane, BorderLayout.CENTER);
}
/**
* 关闭选择的文件
*
* @param selected 选择的
*/
public void closeSelectedReport(JTemplate<?, ?> selected) {
DesignModuleFactory.clearChartPropertyPane();
DesignTableDataManager.closeTemplate(selected);
if (contains(selected) == -1) {
return;
}
selected.fireJTemplateClosed();
selected.stopEditing();
try {
historyList.remove(contains(selected));
selected.getEditingFILE().closeTemplate();
FineLoggerFactory.getLogger().info(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName()));
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
/**
* 临时关闭选择的文件
*
* @param selected 选择的
*/
public void closeVirtualSelectedReport(JTemplate<?, ?> selected) {
DesignModuleFactory.clearChartPropertyPane();
DesignTableDataManager.closeTemplate(selected);
if (contains(selected) == -1) {
return;
}
selected.fireJTemplateClosed();
selected.stopEditing();
try {
selected.getEditingFILE().closeTemplate();
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
/**
* 关闭选择的文件
*/
public void selectedReportToVirtual(int i) {
closeOverLineTemplate();
}
public JTemplate<?, ?> getCurrentEditingTemplate() {
return this.editingTemplate;
}
public void setCurrentEditingTemplate(JTemplate<?, ?> jt) {
this.editingTemplate = jt;
//如果当前历史面板中没有
if (contains(jt) == -1) {
addHistory();
}
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList);
//设置tab栏为当前选中的那一栏
if (editingTemplate != null) {
MutilTempalteTabPane.getInstance().setSelectedIndex(contains(jt));
}
}
/**
* 添加历史记录
*/
public void addHistory() {
if (editingTemplate == null) {
return;
}
DesignerEnvManager.getEnvManager().addRecentOpenedFilePath(editingTemplate.getPath());
((HistoryListDataMode) list.getModel()).add(editingTemplate);
}
public List<JTemplate<?, ?>> getHistoryList() {
return historyList;
}
/**
* 清空历史记录
*/
public void removeAllHistory() {
historyList.clear();
this.editingTemplate = null;
}
public int getHistoryCount() {
return list.getModel().getSize();
}
public UIList getList() {
return list;
}
public JTemplate<?, ?> get(int index) {
return (JTemplate<?, ?>) list.getModel().getElementAt(index);
}
public JTemplate<?, ?> getTemplate(int index) {
return historyList.get(index);
}
/**
* 获取模板的index
*
* @param jt 模板
* @return 位置
*/
public int contains(JTemplate<?, ?> jt) {
for (int i = 0; i < historyList.size(); i++) {
if (ComparatorUtils.equals(historyList.get(i).getEditingFILE(), jt.getEditingFILE())) {
return i;
}
}
return -1;
}
/**
* 判断是否打开过该模板
*
* @param filename 文件名
* @return 文件位置
*/
public int contains(String filename) {
for (int i = 0; i < historyList.size(); i++) {
String historyPath = historyList.get(i).getPath().replaceAll("/", "\\\\");
//文件路径是全路径,历史路径是reportlets/模板名
if (filename.endsWith(historyPath)) {
return i;
}
}
return -1;
}
/**
* 是否是当前编辑的文件
*
* @param filename 文件名
* @return 是则返回TRUE
*/
public boolean isCurrentEditingFile(String filename) {
String editingFileName = editingTemplate.getPath();
return ComparatorUtils.equals(filename, editingFileName);
}
@Override
public void callback() {
getCurrentEditingTemplate().repaint();
}
private class HistoryListCellRender extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, final boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
JTemplate<?, ?> jt = (JTemplate<?, ?>) value;
UILabel nameLabel = new UILabel(jt.getEditingFILE().getName());
final int nameWidth = nameLabel.getPreferredSize().width;
UILabel uiLabel = new UILabel() {
public void paint(Graphics g) {
GUIPaintUtils.fillPaint((Graphics2D) g, 18, 0, nameWidth + 2, getHeight(), true, Constants.NULL, isSelected ? UIConstants.FLESH_BLUE : UIConstants.NORMAL_BACKGROUND, UIConstants.ARC);
super.paint(g);
}
};
uiLabel.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
uiLabel.setIcon(jt.getIcon());
uiLabel.setText(jt.getEditingFILE().getName());
return uiLabel;
}
}
private class HistoryListDataMode extends AbstractListModel {
@Override
public int getSize() {
return historyList.size();
}
@Override
public JTemplate<?, ?> getElementAt(int index) {
if (index > getSize() - 1 || index < 0) {
return null;
}
Collections.reverse(historyList);
JTemplate<?, ?> select = historyList.get(index);
Collections.reverse(historyList);
return select;
}
public void remove(int index) {
boolean outofindex = index >= historyList.size() || index < 0;
if (historyList.isEmpty() || outofindex) {
return;
}
historyList.remove(index);
}
public void add(JTemplate<?, ?> jt) {
historyList.add(jt);
closeOverLineTemplate();
refresh();
}
}
/**
* 打开new模板的同时关闭old模板,优先关已保存的先打开的
*/
public void closeOverLineTemplate() {
int size = historyList.size();
int vCount = size - DEAD_LINE;
if (DEAD_LINE == 0 || vCount <= 0) {
return;
}
for (int i = 0; i < vCount; i++) {
JTemplate overTemplate = historyList.get(i);
if (overTemplate.getEditingFILE().exists() && overTemplate.isALLSaved() && overTemplate != editingTemplate) {
historyList.get(i).closeOverLineTemplate(i);
}
}
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList);
}
/**
* 刷新
*/
public void refresh() {
list.removeAll();
list.setModel(new HistoryListDataMode());
list.setSelectedIndex(list.getSelectedIndex());
}
/**
* 打开选择的文件
*/
public void openSelectedReport() {
DesignerContext.getDesignerFrame().addAndActivateJTemplate((JTemplate<?, ?>) list.getSelectedValue());
TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter());
refresh();
}
/**
* 打开文件所在文件夹
*/
public void openContainerFolder() {
FileNode fileNode = new FileNode(((JTemplate<?, ?>) list.getSelectedValue()).getEditingFILE().getPath(), false);
if (WorkContext.getCurrent().isLocal()) {
IOUtils.openWindowsFolder(StableUtils.pathJoin(WorkContext.getCurrent().getPath(), fileNode.getEnvPath()));
}
}
/**
* 删除文件
*/
public void deleteFile() {
// TODO Auto-generated method stub
}
/***
* 琐文件
*/
public void lockFile() {
// TODO Auto-generated method stub
}
/**
* 解锁
*/
public void unLockFile() {
// TODO Auto-generated method stub
}
/**
* 路径
*
* @return 路径
*/
public String getSelectedTemplatePath() {
if (list.getSelectedIndex() < 0 || list.getSelectedIndex() > list.getModel().getSize() - 1) {
return null;
}
;
String path = ((HistoryListDataMode) list.getModel()).getElementAt(list.getSelectedIndex()).getEditingFILE().getPath();
if (path.startsWith(ProjectConstants.REPORTLETS_NAME)) {
return path.substring(ProjectConstants.REPORTLETS_NAME.length());
}
return path;
}
public void setToobarStateChangeListener(FileToolbarStateChangeListener toobarStateChangeListener) {
this.toobarStateChangeListener = toobarStateChangeListener;
}
/**
* 文件是否存在
*
* @param newName 文件名
* @param oldName 原名
* @param suffix 后缀名
* @return 文件是否存在
*/
public boolean isNameAlreadyExist(String newName, String oldName, String suffix) {
boolean isNameAreadyExist = false;
for (int i = 0; i < getHistoryCount(); i++) {
JTemplate<?, ?> jt = ((HistoryListDataMode) list.getModel()).getElementAt(i);
if (ComparatorUtils.equals(jt.getEditingFILE().getName(), newName + suffix)) {
isNameAreadyExist = true;
break;
}
}
if (ComparatorUtils.equals(newName, oldName)) {
isNameAreadyExist = false;
}
return isNameAreadyExist;
} }
} }

225
designer-base/src/main/java/com/fr/design/file/NodeAuthProcessor.java

@ -0,0 +1,225 @@
package com.fr.design.file;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.file.FILE;
import com.fr.file.FileNodeFILE;
import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.report.DesignAuthority;
import com.fr.stable.CoreConstants;
import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.authority.AuthorityOperator;
import java.util.ArrayList;
public class NodeAuthProcessor {
public static NodeAuthProcessor getInstance() {
return NodeAuthProcessor.HOLDER.singleton;
}
private static class HOLDER {
private static NodeAuthProcessor singleton = new NodeAuthProcessor();
}
/**
* 远程设计拥有全部权限的文件夹路径
*/
private ArrayList<String> authPaths = new ArrayList<>();
private NodeAuthProcessor() {
}
public void refresh() {
authPaths.clear();
if (!WorkContext.getCurrent().isLocal()) {
try {
String username = WorkContext.getConnector().currentUser();
// 远程设计获取全部设计成员的权限列表
DesignAuthority[] authorities = WorkContext.getCurrent().get(AuthorityOperator.class).getAuthorities();
DesignAuthority authority = null;
if (authorities != null) {
for (DesignAuthority designAuthority : authorities) {
if (ComparatorUtils.equals(designAuthority.getUsername(), username)) {
authority = designAuthority;
}
}
}
if (authority != null) {
for (DesignAuthority.Item item : authority.getItems()) {
if (item.getType()) {
authPaths.add(item.getPath());
}
}
}
} catch (Exception exception) {
FineLoggerFactory.getLogger().error(exception.getMessage(), exception);
}
}
}
public void clear() {
authPaths.clear();
}
/**
* 生成带权限信息的文件节点供另存对话框使用
*
* @param fileNodes file nodes
* @return 带权限信息的文件节点
*/
public FILE[] parser2FILEArray(FileNode[] fileNodes, String envPath) {
boolean isLocal = WorkContext.getCurrent().isLocal();
boolean isRoot = WorkContext.getCurrent().isRoot();
FILE[] res = new FILE[fileNodes.length];
for (int i = 0; i < res.length; i++) {
FileNode fn = fileNodes[i];
if (fn.isDirectory()) {
if (isLocal || isRoot) {
res[i] = new FileNodeFILE(fileNodes[i], envPath);
} else {
boolean hasFullAuthority = isContained(fn);
res[i] = new FileNodeFILE(fileNodes[i], envPath, hasFullAuthority);
}
} else {
res[i] = new FileNodeFILE(fileNodes[i], envPath);
}
}
return res;
}
/**
* 生成带权限信息的文件节点供另存对话框使用
*
* @param fileNode file nodes
* @return 带权限信息的文件节点
*/
public FILE fixFILENodeAuth(FileNode fileNode) {
boolean isLocal = WorkContext.getCurrent().isLocal();
boolean isRoot = WorkContext.getCurrent().isRoot();
if (fileNode.isDirectory()) {
if (isLocal || isRoot) {
return new FileNodeFILE(fileNode);
} else {
boolean hasFullAuthority = isContained(fileNode);
return new FileNodeFILE(fileNode, hasFullAuthority);
}
} else {
return new FileNodeFILE(fileNode);
}
}
/**
* 生成带权限信息的文件节点供另存对话框使用
*
* @param fileNode file nodes
* @return 带权限信息的文件节点
*/
public boolean fixFileNodeAuth(FileNode fileNode) {
boolean isLocal = WorkContext.getCurrent().isLocal();
boolean isRoot = WorkContext.getCurrent().isRoot();
if (fileNode.isDirectory()) {
if (isLocal || isRoot) {
return true;
} else {
return isContained(fileNode);
}
} else {
return true;
}
}
/**
* 生成带权限信息的目录树节点
* 提供给目录树使用
*
* @param fileNodes file nodes
* @return 带权限信息的目录树节点
*/
public ExpandMutableTreeNode[] parser2TreeNodeArray(FileNode[] fileNodes) {
boolean isLocal = WorkContext.getCurrent().isLocal();
boolean isRoot = WorkContext.getCurrent().isRoot();
ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[fileNodes.length];
for (int i = 0; i < res.length; i++) {
FileNode fn = fileNodes[i];
res[i] = new ExpandMutableTreeNode(fn);
if (fn.isDirectory()) {
res[i].add(new ExpandMutableTreeNode());
if (isLocal || isRoot) {
res[i].setFullAuthority(true);
} else {
boolean hasFullAuthority = isContained(fn);
res[i].setFullAuthority(hasFullAuthority);
}
}
}
return res;
}
public void fixTreeNodeAuth(ExpandMutableTreeNode treeNode) {
if (treeNode == null) {
return;
}
Object object = treeNode.getUserObject();
if (object instanceof FileNode) {
boolean isLocal = WorkContext.getCurrent().isLocal();
boolean isRoot = WorkContext.getCurrent().isRoot();
if (((FileNode) object).isDirectory()) {
if (isLocal || isRoot) {
treeNode.setFullAuthority(true);
} else {
boolean hasFullAuthority = isContained((FileNode) object);
treeNode.setFullAuthority(hasFullAuthority);
}
}
}
}
private boolean isContained(FileNode fileNode) {
for (String auPath : authPaths) {
if (isContained(auPath, fileNode)) {
return true;
}
}
return false;
}
private boolean isContained(String auPath, FileNode fileNode) {
auPath = ProjectConstants.REPORTLETS_NAME + CoreConstants.SEPARATOR + auPath;
String fileName = fileNode.getEnvPath();
String[] auPaths = auPath.split(CoreConstants.SEPARATOR);
String[] nodePaths = fileName.split(CoreConstants.SEPARATOR);
// 待判断目录是有权限目录或者有权限目录的子目录,全部权限
if (auPaths.length <= nodePaths.length) {
for (int i = 0; i < auPaths.length; i++) {
if (!auPaths[i].equals(nodePaths[i])) {
return false;
}
}
return fileNode.isDirectory();
}
// 其他情况半权限
else {
return false;
}
}
}

340
designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java

@ -7,18 +7,18 @@ import com.fr.base.FRContext;
import com.fr.base.io.FileAssistUtilsOperator; import com.fr.base.io.FileAssistUtilsOperator;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.gui.itree.filetree.TemplateFileTree;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate; import com.fr.file.FILE;
import com.fr.file.FileNodeFILE; import com.fr.file.FileNodeFILE;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.file.filetree.IOFileNodeFilter; import com.fr.file.filetree.IOFileNodeFilter;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.CoreConstants; import com.fr.stable.CoreConstants;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
@ -26,7 +26,10 @@ import com.fr.workspace.WorkContext;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.ToolTipManager; import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Desktop; import java.awt.Desktop;
import java.awt.Dimension; import java.awt.Dimension;
@ -37,6 +40,11 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import static javax.swing.JOptionPane.YES_NO_OPTION;
public class TemplateTreePane extends JPanel implements FileOperations { public class TemplateTreePane extends JPanel implements FileOperations {
@ -49,7 +57,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
} }
private TemplateFileTree reportletsTree; private TemplateFileTree reportletsTree;
private FileToolbarStateChangeListener toobarStateChangeListener; private FileToolbarStateChangeListener toolBarStateChangeListener;
private TemplateTreePane() { private TemplateTreePane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
@ -71,14 +79,14 @@ public class TemplateTreePane extends JPanel implements FileOperations {
@Override @Override
public void mousePressed(MouseEvent evt) { public void mousePressed(MouseEvent evt) {
if (evt.getClickCount() == 2) { if (evt.getClickCount() == 2) {
openSelectedReport(); openFile();
} }
} }
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
if (toobarStateChangeListener != null) { if (toolBarStateChangeListener != null) {
toobarStateChangeListener.stateChange(); toolBarStateChangeListener.stateChange();
} }
} }
}; };
@ -89,24 +97,24 @@ public class TemplateTreePane extends JPanel implements FileOperations {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getKeyCode() == KeyEvent.VK_ENTER) {
openSelectedReport(); openFile();
} }
} }
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getKeyCode() == KeyEvent.VK_ENTER) {
openSelectedReport(); openFile();
} }
if (toobarStateChangeListener != null) { if (toolBarStateChangeListener != null) {
toobarStateChangeListener.stateChange(); toolBarStateChangeListener.stateChange();
} }
} }
@Override @Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getKeyCode() == KeyEvent.VK_ENTER) {
openSelectedReport(); openFile();
} }
} }
}); });
@ -116,6 +124,49 @@ public class TemplateTreePane extends JPanel implements FileOperations {
return this.reportletsTree; return this.reportletsTree;
} }
/**
* 选中的路径数
*
* @return 选中的路径数
*/
public int countSelectedPath() {
TreePath[] treePaths = reportletsTree.getSelectionPaths();
if (treePaths == null) {
return 0;
}
return treePaths.length;
}
/**
* 选中的文件夹个数
*
* @return 选中的文件夹个数
*/
public int countSelectedFolder() {
if (reportletsTree.getSelectedFolderPaths() == null) {
return 0;
}
return reportletsTree.getSelectedFolderPaths().length;
}
/**
* 选中的文件个数
*
* @return 选中的文件
*/
public int countSelectedFile() {
if (reportletsTree.getSelectionPaths() == null) {
return 0;
}
return reportletsTree.getSelectedTemplatePaths().length;
}
/** /**
* 刷新 * 刷新
*/ */
@ -125,11 +176,16 @@ public class TemplateTreePane extends JPanel implements FileOperations {
} }
@Override
public boolean mkdir(String path) {
return WorkContext.getWorkResource().createDirectory(path);
}
/** /**
* 打开选中的报表文件 * 打开选中的报表文件
*/ */
@Override @Override
public void openSelectedReport() { public void openFile() {
String reportPath = reportletsTree.getSelectedTemplatePath(); String reportPath = reportletsTree.getSelectedTemplatePath();
final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath); final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath);
DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(selectedFilePath, false))); DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(selectedFilePath, false)));
@ -139,7 +195,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
* 打开文件夹 * 打开文件夹
*/ */
@Override @Override
public void openContainerFolder() { public void showInExplorer() {
FileNode fn = TemplateTreePane.this.reportletsTree.getSelectedFileNode(); FileNode fn = TemplateTreePane.this.reportletsTree.getSelectedFileNode();
String filePath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), fn.getEnvPath()); String filePath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), fn.getEnvPath());
filePath = filePath.substring(0, filePath.lastIndexOf(CoreConstants.SEPARATOR)); filePath = filePath.substring(0, filePath.lastIndexOf(CoreConstants.SEPARATOR));
@ -156,134 +212,232 @@ public class TemplateTreePane extends JPanel implements FileOperations {
@Override @Override
public void refresh() { public void refresh() {
reportletsTree.refresh(); reportletsTree.refresh();
FineLoggerFactory.getLogger().info(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Template_File_Tree_Refresh_Successfully") + "!"); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_File_Tree_Refresh_Successfully") + "!");
} }
/** /**
* 删除文件 * 删除文件
* 文件夹和文件均可删除
* <p>
* 当文件被锁时不能删除
* 当文件夹中包含被锁文件时不能删除
*/ */
@Override @Override
public void deleteFile() { public void deleteFile() {
String[] reportPaths = reportletsTree.getSelectedTemplatePaths();
if (reportPaths.length == 0) {
return; String tipContent =
countSelectedFolder() > 0
? Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_Folder")
: Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_File");
ExpandMutableTreeNode[] treeNodes = reportletsTree.getSelectedTreeNodes();
// 筛选可以删除的文件
ArrayList<ExpandMutableTreeNode> deletableNodes = new ArrayList<>();
ArrayList<ExpandMutableTreeNode> lockedNodes = new ArrayList<>();
for (ExpandMutableTreeNode treeNode : treeNodes) {
checkFreeOrLock(treeNode, deletableNodes, lockedNodes);
}
boolean success = false;
if (lockedNodes.isEmpty()) {
if (JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(),
tipContent,
UIManager.getString("OptionPane.titleText"),
YES_NO_OPTION)
== JOptionPane.OK_OPTION) {
// 删除所有选中的即可
success = deleteNodes(Arrays.asList(treeNodes));
}
} else {
if (JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_Unlock_File"),
UIManager.getString("OptionPane.titleText"),
YES_NO_OPTION)
== JOptionPane.YES_OPTION) {
// 删除其他
success = deleteNodes(deletableNodes);
}
} }
if (JOptionPane.showConfirmDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Confirm_Delete_File")) != JOptionPane.OK_OPTION) {
return; if (!success) {
JOptionPane.showConfirmDialog(null,
Toolkit.i18nText("Fine-Design_Basic_Delete_Failure"),
UIManager.getString("OptionPane.titleText"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE);
} }
for (String reportPath : reportPaths) {
FileNodeFILE nodeFile = new FileNodeFILE(new FileNode(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath), false));
if (nodeFile.isLocked()) { reportletsTree.refresh();
if (JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_FileLocked_Undeleted"), }
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.YES_OPTION) {
refreshDockingView(); private boolean deleteNodes(Collection<ExpandMutableTreeNode> nodes) {
boolean success = true;
for (ExpandMutableTreeNode treeNode : nodes) {
Object node = treeNode.getUserObject();
if (node instanceof FileNode) {
FileNodeFILE nodeFILE = new FileNodeFILE((FileNode) node);
if (nodeFILE.exists()) {
FileAssistUtilsOperator fileAssistUtils = WorkContext.getCurrent().get(FileAssistUtilsOperator.class);
success = fileAssistUtils.moveToTrash(nodeFILE.getPath()) && success;
HistoryTemplateListCache.getInstance().deleteFile(nodeFILE);
} }
break;
} }
if (nodeFile.exists()) { }
String path = StableUtils.pathJoin(nodeFile.getEnvPath(), nodeFile.getPath()); return success;
FileAssistUtilsOperator fileAssistUtils = WorkContext.getCurrent().get(FileAssistUtilsOperator.class); }
fileAssistUtils.moveToTrash(nodeFile.getPath());
deleteHistory(path.replaceAll("/", "\\\\")); private boolean checkFreeOrLock(ExpandMutableTreeNode node, ArrayList<ExpandMutableTreeNode> dNodes, ArrayList<ExpandMutableTreeNode> lNodes) {
// 自己没锁
boolean selfEmptyLock = false;
Object userObj = node.getUserObject();
if (userObj instanceof FileNode) {
String lock = ((FileNode) userObj).getLock();
selfEmptyLock = lock == null || ((FileNode) userObj).getUserID().equals(lock);
}
if (node.isLeaf()) {
if (selfEmptyLock) {
dNodes.add(node);
} else {
lNodes.add(node);
}
return selfEmptyLock;
}
ExpandMutableTreeNode[] children = reportletsTree.loadChildTreeNodes(node);
boolean childrenEmptyLock = true;
for (ExpandMutableTreeNode child : children) {
boolean childEmptyLock = checkFreeOrLock(child, dNodes, lNodes);
if (childEmptyLock) {
dNodes.add(child);
} else { } else {
JOptionPane.showMessageDialog(this, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Warning_Template_Do_Not_Exsit"), ProductConstants.PRODUCT_NAME, lNodes.add(child);
JOptionPane.INFORMATION_MESSAGE);
} }
childrenEmptyLock = childrenEmptyLock && childEmptyLock;
} }
reportletsTree.refresh();
boolean emptyLock = childrenEmptyLock && selfEmptyLock;
if (emptyLock) {
dNodes.add(node);
} else {
lNodes.add(node);
}
return emptyLock;
} }
@Override @Override
public void lockFile() { public void lockFile() {
throw new UnsupportedOperationException("unsupport now"); throw new UnsupportedOperationException("unsupport now");
} }
@Override @Override
public void unLockFile() { public void unlockFile() {
throw new UnsupportedOperationException("unsupport now"); throw new UnsupportedOperationException("unsupport now");
} }
private void deleteHistory(String fileName) {
int index = HistoryTemplateListPane.getInstance().contains(fileName); @Override
int size = HistoryTemplateListPane.getInstance().getHistoryCount(); public String getFilePath() {
if (index == -1) { return reportletsTree.getSelectedTemplatePath();
return; }
@Override
public boolean access() {
TreePath[] selectedTreePaths = reportletsTree.getSelectionPaths();
if (selectedTreePaths == null || selectedTreePaths.length != 1) {
return false;
} }
//如果打开过,则删除,实时刷新多tab面板 // 选中的是文件夹
HistoryTemplateListPane.getInstance().getHistoryList().remove(index); TreePath treePath = selectedTreePaths[0];
int openfileCount = HistoryTemplateListPane.getInstance().getHistoryCount(); ExpandMutableTreeNode currentTreeNode = (ExpandMutableTreeNode) treePath.getLastPathComponent();
if (openfileCount == 0) {
DesignerContext.getDesignerFrame().addAndActivateJTemplate(); ExpandMutableTreeNode parentTreeNode = (ExpandMutableTreeNode) currentTreeNode.getParent();
return parentTreeNode != null && parentTreeNode.hasFullAuthority();
}
@Override
public boolean rename(FILE tplFile, String from, String to) {
// 多人协作时判断是否有锁定的文件
ExpandMutableTreeNode[] treeNodes = reportletsTree.getSelectedTreeNodes();
// 筛选可以重命名的文件
ArrayList<ExpandMutableTreeNode> unlockedNodes = new ArrayList<>();
ArrayList<ExpandMutableTreeNode> lockedNodes = new ArrayList<>();
for (ExpandMutableTreeNode treeNode : treeNodes) {
checkFreeOrLock(treeNode, unlockedNodes, lockedNodes);
} }
MutilTempalteTabPane.getInstance().repaint();
if (size == index + 1 && index != 0) { if (!lockedNodes.isEmpty()) {
//如果删除的是最后一个Tab,则定位到前一个 JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(),
MutilTempalteTabPane.getInstance().setSelectedIndex(index - 1); Toolkit.i18nText("Fine-Design_Basic_Warn_Rename_Lock_File"),
UIManager.getString("OptionPane.titleText"),
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
return true;
} }
JTemplate selectedfile = MutilTempalteTabPane.getInstance().getSelectedFile();
if (!HistoryTemplateListPane.getInstance().isCurrentEditingFile(selectedfile.getPath())) { try {
//如果此时面板上的实时刷新的selectedIndex得到的和历史的不一样 // com.fr.io.utils.ResourceIOUtils 接收的是WEB-INF下的路径
DesignerContext.getDesignerFrame().activateJTemplate(selectedfile); return WorkContext.getWorkResource().rename(from, to);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
} }
MutilTempalteTabPane.getInstance().repaint();
} }
@Override @Override
public String getSelectedTemplatePath() { public FileNode getFileNode() {
return reportletsTree.getSelectedTemplatePath(); return reportletsTree.getSelectedFileNode();
} }
public void setToobarStateChangeListener(FileToolbarStateChangeListener toobarStateChangeListener) { public void setToolbarStateChangeListener(FileToolbarStateChangeListener listener) {
this.toobarStateChangeListener = toobarStateChangeListener; this.toolBarStateChangeListener = listener;
} }
/** /**
* 文件名是否存在 * 仅支持在拥有完整权限的文件夹下进行新建和重命名操作那么是可以看到改文件夹下所有文件的
* *
* @param newName 原名 * @param newName 原名
* @param oldName 新的文件名
* @param suffix 后缀名 * @param suffix 后缀名
* @return 是否存在 * @return 是否有重名的
*/ */
@Override @Override
public boolean isNameAlreadyExist(String newName, String oldName, String suffix) { public boolean duplicated(String newName, String suffix) {
boolean isNameAlreadyExist = false;
TemplateFileTree tt = reportletsTree;
DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot();
ArrayList<String> al = new ArrayList<String>();
findFiles(gen, al); // 选中的节点
TreePath treePath = reportletsTree.getSelectionPath();
for (int i = 0; i < al.size(); i++) { if (treePath == null) {
if (ComparatorUtils.equals(al.get(i), newName + suffix)) { return false;
isNameAlreadyExist = true;
break;
}
} }
DefaultMutableTreeNode currentTreeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
TreeNode parentTreeNode = currentTreeNode.getParent();
if (ComparatorUtils.equals(newName, oldName)) { Enumeration children = parentTreeNode.children();
isNameAlreadyExist = false;
}
return isNameAlreadyExist; while (children.hasMoreElements()) {
} DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();
Object object = childNode.getUserObject();
if (object instanceof FileNode) {
private void findFiles(DefaultMutableTreeNode node, ArrayList<String> al) { if (ComparatorUtils.equals(((FileNode) object).getName(), newName + suffix)) {
String[] str = new String[node.getChildCount()]; return true;
for (int j = 0; j < node.getChildCount(); j++) {
DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(j);
if (childNode.getChildCount() > 0) {
findFiles(childNode, al);
} else {
str[j] = node.getChildAt(j).toString();
if (str[j].contains(".")) {
al.add(str[j]);
} }
} else {
return false;
} }
} }
return false;
} }
} }

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

@ -2,17 +2,13 @@ package com.fr.design.gui.itree.filetree;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.base.extension.FileExtension; import com.fr.base.extension.FileExtension;
import com.fr.design.file.NodeAuthProcessor;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.report.DesignAuthority;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.authority.AuthorityOperator;
import javax.swing.text.Position; import javax.swing.text.Position;
import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeModel;
@ -26,12 +22,6 @@ import java.util.List;
*/ */
public class TemplateFileTree extends EnvFileTree { public class TemplateFileTree extends EnvFileTree {
/**
* 远程设计拥有全部权限的文件夹路径
*/
private ArrayList<String> paths = new ArrayList<>();
public TemplateFileTree() { public TemplateFileTree() {
super(ProjectConstants.REPORTLETS_NAME, null, null); super(ProjectConstants.REPORTLETS_NAME, null, null);
} }
@ -79,10 +69,32 @@ public class TemplateFileTree extends EnvFileTree {
} }
} }
return selectedPathList.toArray(new String[0]);
}
public String[] getSelectedFolderPaths() {
TreePath[] selectedTreePaths = this.getSelectionPaths();
if (ArrayUtils.isEmpty(selectedTreePaths)) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
List<String> selectedPathList = new ArrayList<String>();
for (TreePath treepath : selectedTreePaths) {
ExpandMutableTreeNode currentTreeNode = (ExpandMutableTreeNode) treepath.getLastPathComponent();
Object userObject = currentTreeNode.getUserObject();
if (userObject instanceof FileNode) {
FileNode fn = (FileNode) userObject;
if (fn.isDirectory()) {
String envPath = fn.getEnvPath();
if (envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
selectedPathList.add(envPath.substring(ProjectConstants.REPORTLETS_NAME.length()));
}
}
}
}
return selectedPathList.toArray(new String[0]); return selectedPathList.toArray(new String[0]);
} }
@Override @Override
public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) { public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) {
@ -122,37 +134,11 @@ public class TemplateFileTree extends EnvFileTree {
*/ */
@Override @Override
public void refreshEnv() { public void refreshEnv() {
paths.clear(); NodeAuthProcessor.getInstance().refresh();
if (!WorkContext.getCurrent().isLocal()) {
try {
String username = WorkContext.getConnector().currentUser();
// 远程设计获取全部设计成员的权限列表
DesignAuthority[] authorities = WorkContext.getCurrent().get(AuthorityOperator.class).getAuthorities();
DesignAuthority authority = null;
if (authorities != null) {
for (DesignAuthority designAuthority : authorities) {
if (ComparatorUtils.equals(designAuthority.getUsername(), username)) {
authority = designAuthority;
}
}
}
if (authority != null) {
for (DesignAuthority.Item item : authority.getItems()) {
if (item.getType()) {
paths.add(item.getPath());
}
}
}
} catch (Exception exception) {
FineLoggerFactory.getLogger().error(exception.getMessage(), exception);
}
}
DefaultTreeModel defaultTreeModel = (DefaultTreeModel) this.getModel(); DefaultTreeModel defaultTreeModel = (DefaultTreeModel) this.getModel();
ExpandMutableTreeNode rootTreeNode = (ExpandMutableTreeNode) defaultTreeModel.getRoot(); ExpandMutableTreeNode rootTreeNode = (ExpandMutableTreeNode) defaultTreeModel.getRoot();
NodeAuthProcessor.getInstance().fixTreeNodeAuth(rootTreeNode);
rootTreeNode.removeAllChildren(); rootTreeNode.removeAllChildren();
FileNode[] fns; FileNode[] fns;
@ -178,64 +164,34 @@ public class TemplateFileTree extends EnvFileTree {
} }
@Override @Override
protected ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) { public ExpandMutableTreeNode[] loadChildTreeNodes(ExpandMutableTreeNode treeNode) {
FileNode[] fnArray = listFileNodes(treeNode); FileNode[] fnArray = listFileNodes(treeNode);
return fileNodeArray2TreeNodeArray(fnArray); return fileNodeArray2TreeNodeArray(fnArray);
} }
/*
* 把FileNode[]转成ExpandMutableTreeNode[] public ExpandMutableTreeNode[] getSelectedTreeNodes() {
*/ TreePath[] paths = this.getSelectionPaths();
private ExpandMutableTreeNode[] fileNodeArray2TreeNodeArray(FileNode[] fileNodes) {
boolean isLocal = WorkContext.getCurrent().isLocal(); if (paths == null) {
boolean isRoot = WorkContext.getCurrent().isRoot(); return new ExpandMutableTreeNode[0];
ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[fileNodes.length];
for (int i = 0; i < res.length; i++) {
FileNode fn = fileNodes[i];
res[i] = new ExpandMutableTreeNode(fn);
if (fn.isDirectory()) {
res[i].add(new ExpandMutableTreeNode());
if (isLocal || isRoot) {
res[i].setFullAuthority(true);
} else {
boolean hasFullAuthority = isContained(fn);
res[i].setFullAuthority(hasFullAuthority);
}
}
} }
return res;
}
private boolean isContained(FileNode fileNode) { ArrayList<ExpandMutableTreeNode> res = new ArrayList<>();
for (String auPath : paths) { for (TreePath path : paths) {
if (isContained(auPath, fileNode)) { res.add((ExpandMutableTreeNode) path.getLastPathComponent());
return true;
}
} }
return false; return res.toArray(new ExpandMutableTreeNode[res.size()]);
} }
private boolean isContained(String auPath, FileNode fileNode) { /*
auPath = ProjectConstants.REPORTLETS_NAME + CoreConstants.SEPARATOR + auPath; * 把FileNode[]转成ExpandMutableTreeNode[]
String fileName = fileNode.getEnvPath(); */
String[] auPaths = auPath.split(CoreConstants.SEPARATOR); private ExpandMutableTreeNode[] fileNodeArray2TreeNodeArray(FileNode[] fileNodes) {
String[] nodePaths = fileName.split(CoreConstants.SEPARATOR); return NodeAuthProcessor.getInstance().parser2TreeNodeArray(fileNodes);
// 待判断目录是有权限目录或者有权限目录的子目录,全部权限
if (auPaths.length <= nodePaths.length) {
for (int i = 0; i < auPaths.length; i++) {
if (!auPaths[i].equals(nodePaths[i])) {
return false;
}
}
return fileNode.isDirectory();
}
// 其他情况半权限
else {
return false;
}
} }
@ -270,7 +226,7 @@ public class TemplateFileTree extends EnvFileTree {
* 求当前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];
} }
@ -278,12 +234,10 @@ public class TemplateFileTree extends EnvFileTree {
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];
} }
} }

670
designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java

@ -1,7 +1,6 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.base.vcs.DesignerMode; import com.fr.base.vcs.DesignerMode;
import com.fr.design.DesignModelAdapter; import com.fr.design.DesignModelAdapter;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
@ -13,6 +12,7 @@ import com.fr.design.data.datapane.TableDataTreePane;
import com.fr.design.data.tabledata.ResponseDataSourceChange; import com.fr.design.data.tabledata.ResponseDataSourceChange;
import com.fr.design.file.FileOperations; import com.fr.design.file.FileOperations;
import com.fr.design.file.FileToolbarStateChangeListener; import com.fr.design.file.FileToolbarStateChangeListener;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MutilTempalteTabPane; import com.fr.design.file.MutilTempalteTabPane;
import com.fr.design.file.TemplateTreePane; import com.fr.design.file.TemplateTreePane;
@ -21,66 +21,66 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.imenu.UIMenuHighLight; import com.fr.design.gui.imenu.UIMenuHighLight;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.KeySetUtils;
import com.fr.design.menu.ShortCut; import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef; import com.fr.design.menu.ToolBarDef;
import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.file.FILE;
import com.fr.file.FileNodeFILE; import com.fr.file.FileNodeFILE;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.io.utils.ResourceIOUtils; import com.fr.log.FineLoggerFactory;
import com.fr.stable.CoreConstants; import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.CardLayout; import java.awt.CardLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GridLayout; import java.awt.FlowLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static javax.swing.JOptionPane.WARNING_MESSAGE;
public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarStateChangeListener, ResponseDataSourceChange { public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarStateChangeListener, ResponseDataSourceChange {
private static final String FILE = "file"; private static final String FILE = "file";
private static volatile DesignerFrameFileDealerPane THIS; private static volatile DesignerFrameFileDealerPane THIS;
private CardLayout card; private List<FileToolbarStateChangeListener> otherToolbarStateChangeListeners = new ArrayList<>();
private JPanel cardPane;
private java.util.List<FileToolbarStateChangeListener> otherToobarStateChangeListeners = new ArrayList<>();
private FileOperations selectedOperation; private FileOperations selectedOperation;
private UIToolbar toolBar; private UIToolbar toolBar;
private OpenReportAction openReportAction = new OpenReportAction(); private NewFolderAction newFolderAction = new NewFolderAction();
private RefreshTreeAction refreshTreeAction = new RefreshTreeAction(); private RefreshTreeAction refreshTreeAction = new RefreshTreeAction();
private OpenFolderAction openFolderAction = new OpenFolderAction(); private ShowInExplorerAction showInExplorerAction = new ShowInExplorerAction();
private RenameAction renameAction = new RenameAction(); private RenameAction renameAction = new RenameAction();
@ -91,11 +91,10 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
* 刷新 * 刷新
*/ */
public void refresh() { public void refresh() {
selectedOperation.refresh(); selectedOperation.refresh();
} }
public static final DesignerFrameFileDealerPane getInstance() { public static DesignerFrameFileDealerPane getInstance() {
if (THIS == null) { if (THIS == null) {
synchronized (DesignerFrameFileDealerPane.class) { synchronized (DesignerFrameFileDealerPane.class) {
@ -121,13 +120,14 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
tooBarPane.add(new UIMenuHighLight(), BorderLayout.SOUTH); tooBarPane.add(new UIMenuHighLight(), BorderLayout.SOUTH);
add(tooBarPane, BorderLayout.NORTH); add(tooBarPane, BorderLayout.NORTH);
cardPane = new JPanel(card = new CardLayout()); CardLayout card;
JPanel cardPane = new JPanel(card = new CardLayout());
cardPane.add(TemplateTreePane.getInstance(), FILE); cardPane.add(TemplateTreePane.getInstance(), FILE);
selectedOperation = TemplateTreePane.getInstance(); selectedOperation = TemplateTreePane.getInstance();
card.show(cardPane, FILE); card.show(cardPane, FILE);
TemplateTreePane.getInstance().setToobarStateChangeListener(this); TemplateTreePane.getInstance().setToolbarStateChangeListener(this);
add(cardPane, BorderLayout.CENTER); add(cardPane, BorderLayout.CENTER);
stateChange(); stateChange();
@ -136,7 +136,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
public final void setCurrentEditingTemplate(JTemplate<?, ?> jt) { public final void setCurrentEditingTemplate(JTemplate<?, ?> jt) {
DesignModelAdapter.setCurrentModelAdapter(jt == null ? null : jt.getModel()); DesignModelAdapter.setCurrentModelAdapter(jt.getModel());
fireDSChanged(); fireDSChanged();
TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter());
HistoryTemplateListPane.getInstance().setCurrentEditingTemplate(jt); HistoryTemplateListPane.getInstance().setCurrentEditingTemplate(jt);
@ -152,7 +152,9 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
jt.requestFocus(); jt.requestFocus();
jt.revert(); jt.revert();
FRContext.getLogger().info("\"" + jt.getEditingFILE().getName() + "\"" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_LOG_Has_Been_Openned") + "!"); FineLoggerFactory.getLogger().info(
"\"" + jt.getEditingFILE().getName() + "\""
+ Toolkit.i18nText("Fine-Design_Basic_LOG_Has_Been_Openned") + "!");
} }
/** /**
@ -161,27 +163,26 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
public void refreshDockingView() { public void refreshDockingView() {
ToolBarDef toolbarDef = new ToolBarDef(); ToolBarDef toolbarDef = new ToolBarDef();
toolbarDef.addShortCut(openReportAction, refreshTreeAction); toolbarDef.addShortCut(newFolderAction, refreshTreeAction);
if (WorkContext.getCurrent().isLocal()) { if (WorkContext.getCurrent().isLocal()) {
toolbarDef.addShortCut(openFolderAction, renameAction); toolbarDef.addShortCut(showInExplorerAction);
} }
toolbarDef.addShortCut(delFileAction); toolbarDef.addShortCut(renameAction, delFileAction);
Set<ShortCut> extraShortCuts = ExtraDesignClassManager.getInstance().getExtraShortCuts(); Set<ShortCut> extraShortCuts = ExtraDesignClassManager.getInstance().getExtraShortCuts();
for (ShortCut shortCut : extraShortCuts) { for (ShortCut shortCut : extraShortCuts) {
toolbarDef.addShortCut(shortCut); toolbarDef.addShortCut(shortCut);
} }
toolbarDef.updateToolBar(toolBar); toolbarDef.updateToolBar(toolBar);
refreshActions(); resetActionStatus();
refresh(); refresh();
} }
private void refreshActions() { private void resetActionStatus() {
openReportAction.setEnabled(false); newFolderAction.setEnabled(false);
refreshTreeAction.setEnabled(true); refreshTreeAction.setEnabled(true);
openFolderAction.setEnabled(false); showInExplorerAction.setEnabled(false);
renameAction.setEnabled(false); renameAction.setEnabled(false);
delFileAction.setEnabled(false); delFileAction.setEnabled(false);
this.repaint(); this.repaint();
@ -206,28 +207,53 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
} }
public void addToolbarStateChangeListener(FileToolbarStateChangeListener listener) {
this.otherToolbarStateChangeListeners.add(listener);
}
public void removeToolbarStateChangeListener(FileToolbarStateChangeListener listener) {
this.otherToolbarStateChangeListeners.remove(listener);
}
private void otherStateChange() {
for (FileToolbarStateChangeListener listener : otherToolbarStateChangeListeners) {
listener.stateChange();
}
}
/* /*
* Open Report Action * 新建文件夹
*/ */
private class OpenReportAction extends UpdateAction { private class NewFolderAction extends UpdateAction {
public OpenReportAction() { public NewFolderAction() {
this.setName(KeySetUtils.OPEN_TEMPLATE.getMenuKeySetName()); this.setName(KeySetUtils.NEW_FOLDER.getMenuKeySetName());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/buttonicon/open.png")); this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/icon_NewFolderIcon_normal.png"));
} }
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
selectedOperation.openSelectedReport(); if (!selectedOperation.access()) {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
WARNING_MESSAGE);
return;
}
new MkdirDialog();
} }
} }
private class OpenFolderAction extends UpdateAction { /**
* 在系统资源管理器中打开
*/
private class ShowInExplorerAction extends UpdateAction {
public OpenFolderAction() { public ShowInExplorerAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Show_In_Containing_Folder")); this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Show_In_Containing_Folder"));
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/view_folder.png")); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/view_folder.png"));
@ -236,7 +262,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
selectedOperation.openContainerFolder(); selectedOperation.showInExplorer();
} }
} }
@ -247,7 +273,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
public RefreshTreeAction() { public RefreshTreeAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Refresh")); this.setName(Toolkit.i18nText("Fine-Design_Basic_Refresh"));
this.setSmallIcon(UIConstants.REFRESH_ICON); this.setSmallIcon(UIConstants.REFRESH_ICON);
} }
@ -260,20 +286,6 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
} }
} }
public void addToobarStateChangeListener(FileToolbarStateChangeListener toobarStateChangeListener) {
this.otherToobarStateChangeListeners.add(toobarStateChangeListener);
}
public void removeToobarStateChangeListener(FileToolbarStateChangeListener toobarStateChangeListener) {
this.otherToobarStateChangeListeners.remove(toobarStateChangeListener);
}
private void otherStateChange() {
for (FileToolbarStateChangeListener toobarStateChangeListener : otherToobarStateChangeListeners) {
toobarStateChangeListener.stateChange();
}
}
/* /*
* 重命名文件 * 重命名文件
*/ */
@ -281,14 +293,22 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
public RenameAction() { public RenameAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Rename")); this.setName(Toolkit.i18nText("Fine-Design_Basic_Rename"));
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/data/source/rename.png")); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/data/source/rename.png"));
} }
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
if (!selectedOperation.access()) {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
WARNING_MESSAGE);
return;
}
new RenameDialog(); FileNode node = selectedOperation.getFileNode();
new FileRenameDialog(node);
MutilTempalteTabPane.getInstance().repaint(); MutilTempalteTabPane.getInstance().repaint();
} }
@ -301,13 +321,21 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
public DelFileAction() { public DelFileAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove")); this.setName(Toolkit.i18nText("Fine-Design_Basic_Remove"));
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/data/source/delete.png")); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/data/source/delete.png"));
} }
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
if (!selectedOperation.access()) {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
WARNING_MESSAGE);
return;
}
selectedOperation.deleteFile(); selectedOperation.deleteFile();
} }
} }
@ -318,295 +346,411 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
@Override @Override
public void stateChange() { public void stateChange() {
if (selectedOperation.getSelectedTemplatePath() != null) { int selectedPathNum = TemplateTreePane.getInstance().countSelectedPath();
openReportAction.setEnabled(true);
renameAction.setEnabled(true); // 新建文件夹,重命名操作,在explorer中打开三个操作在选中单个文件夹或者文件时可用,其他情况不可用
delFileAction.setEnabled(true); boolean singleSelected = selectedPathNum == 1;
} else { newFolderAction.setEnabled(singleSelected);
openReportAction.setEnabled(false); renameAction.setEnabled(singleSelected);
renameAction.setEnabled(false); showInExplorerAction.setEnabled(singleSelected);
delFileAction.setEnabled(false);
}
openFolderAction.setEnabled(containsFolderNums() + seletedTemplateNums() != 0);
// 删除操作在至少选中一个时可用
boolean selected = selectedPathNum > 0;
delFileAction.setEnabled(selected);
// 刷新操作始终可用
refreshTreeAction.setEnabled(true); refreshTreeAction.setEnabled(true);
if (containsFolderNums() > 0 && (containsFolderNums() + seletedTemplateNums() > 1)) {
refreshActions();
} else if (containsFolderNums() == 0 && seletedTemplateNums() > 1) {
openReportAction.setEnabled(false);
refreshTreeAction.setEnabled(true);
openFolderAction.setEnabled(false);
renameAction.setEnabled(false);
delFileAction.setEnabled(true);
}
// 其他状态
otherStateChange(); otherStateChange();
} }
/** public FileOperations getSelectedOperation() {
* 是否包含文件夹 return selectedOperation;
*
* @return
*/
private int containsFolderNums() {
TemplateFileTree fileTree = TemplateTreePane.getInstance().getTemplateFileTree();
if (fileTree.getSelectionPaths() == null) {
return 0;
}
//选择的包含文件和文件夹的数目
if (fileTree.getSelectionPaths().length == 0) {
return 0;
}
//所有的num减去模板的num,得到文件夹的num
return fileTree.getSelectionPaths().length - fileTree.getSelectedTemplatePaths().length;
} }
/** /**
* 是否选择了多个模板 * 重命名对话框
* * 支持快捷键EnterESC
* @return
*/ */
private int seletedTemplateNums() { private class FileRenameDialog extends JDialog {
TemplateFileTree fileTree = TemplateTreePane.getInstance().getTemplateFileTree(); private UITextField nameField;
if (fileTree.getSelectionPaths() == null) {
return 0;
}
return fileTree.getSelectedTemplatePaths().length; private UILabel warnLabel;
}
private UIButton confirmButton;
// js: 重命名对话框,模仿Eclipse的重命名,支持快捷键F2,Enter,ESC /**
private class RenameDialog { * 操作的节点
*/
private FileNodeFILE fnf;
private UITextField jt;
private String userInput; private FileRenameDialog(FileNode node) {
if (node == null) {
return;
}
fnf = new FileNodeFILE(node);
private String oldName; String oldName = fnf.getName();
String suffix = fnf.isDirectory() ? "" : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length());
oldName = oldName.replaceAll(suffix, "");
private UILabel hintsLabel; this.setLayout(new BorderLayout());
this.setModal(true);
private UIButton confirmButton; // 输入框前提示
UILabel newNameLabel = new UILabel(Toolkit.i18nText(
fnf.isDirectory() ?
"Fine-Design_Basic_Enter_New_Folder_Name" : "Fine-Design_Basic_Enter_New_File_Name")
);
newNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
newNameLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
newNameLabel.setPreferredSize(new Dimension(118, 15));
private JDialog jd; // 重命名输入框
nameField = new UITextField(oldName);
nameField.getDocument().addDocumentListener(new DocumentListener() {
private String suffix; public void changedUpdate(DocumentEvent e) {
validInput();
}
public RenameDialog() { public void insertUpdate(DocumentEvent e) {
validInput();
}
final String reportPath = selectedOperation.getSelectedTemplatePath(); public void removeUpdate(DocumentEvent e) {
if (reportPath == null) { validInput();
return; }
} });
nameField.selectAll();
nameField.setPreferredSize(new Dimension(180, 20));
final FileNodeFILE nodeFile = new FileNodeFILE(new FileNode(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath), false)); JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 5));
final String path = nodeFile.getPath(); topPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 0, 15));
oldName = nodeFile.getName(); topPanel.add(newNameLabel);
suffix = oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length()); topPanel.add(nameField);
oldName = oldName.replaceAll(suffix, "");
jd = new JDialog(); // 增加enter以及esc快捷键的支持
jd.setLayout(new GridLayout(2, 2)); nameField.addKeyListener(new KeyAdapter() {
jd.setModal(true); @Override
UILabel newNameLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Enter_New_File_Name")); public void keyPressed(KeyEvent e) {
newNameLabel.setMinimumSize(new Dimension(150, 27)); if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
newNameLabel.setHorizontalAlignment(SwingConstants.RIGHT); dispose();
jt = new UITextField(oldName); } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
jt.getDocument().addDocumentListener(getdoDocumentListener()); if (confirmButton.isEnabled()) {
jt.selectAll(); confirmClose();
jt.setPreferredSize(new Dimension(150, 20)); }
}
JPanel newNamePanel = new JPanel(); }
newNamePanel.setLayout(new BoxLayout(newNamePanel, BoxLayout.X_AXIS)); });
newNamePanel.add(Box.createHorizontalGlue()); // 重名提示
newNamePanel.add(newNameLabel); warnLabel = new UILabel();
newNamePanel.add(Box.createHorizontalStrut(5)); warnLabel.setPreferredSize(new Dimension(300, 30));
jd.add(newNamePanel); warnLabel.setHorizontalAlignment(SwingConstants.LEFT);
warnLabel.setForeground(Color.RED);
JPanel jtPanel = new JPanel(); warnLabel.setVisible(false);
jtPanel.setLayout(new BoxLayout(jtPanel, BoxLayout.Y_AXIS));
JPanel containJt = new JPanel(new BorderLayout()); JPanel midPanel = new JPanel(new BorderLayout());
containJt.add(jt, BorderLayout.WEST); midPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15));
containJt.setMaximumSize(new Dimension(200, 20)); midPanel.add(warnLabel, BorderLayout.WEST);
jtPanel.add(Box.createVerticalGlue());
jtPanel.add(containJt); // 确认按钮
jtPanel.add(Box.createVerticalGlue()); confirmButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Confirm"));
jd.add(jtPanel); confirmButton.setPreferredSize(new Dimension(60, 25));
addUITextFieldListener(nodeFile, path);
hintsLabel = new UILabel();
hintsLabel.setBounds(20, 50, 250, 30);
hintsLabel.setMaximumSize(new Dimension(200, 30));
hintsLabel.setHorizontalAlignment(SwingConstants.RIGHT);
hintsLabel.setForeground(Color.RED);
hintsLabel.setVisible(false);
confirmButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Confirm"));
confirmButton.setPreferredSize(new Dimension(80, 25));
confirmButton.setMinimumSize(new Dimension(80, 25));
confirmButton.setMaximumSize(new Dimension(80, 25));
confirmButton.addActionListener(new ActionListener() { confirmButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
confirmClose();
confirmClose(nodeFile, path);
} }
}); });
UIButton cancelButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel")); // 取消按钮
cancelButton.setPreferredSize(new Dimension(80, 25)); UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel"));
cancelButton.setMinimumSize(new Dimension(80, 25)); cancelButton.setPreferredSize(new Dimension(60, 25));
cancelButton.setMaximumSize(new Dimension(80, 25));
cancelButton.addActionListener(new ActionListener() { cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
dispose();
jd.dispose();
} }
}); });
JPanel hintsPanel = new JPanel(); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
hintsPanel.setLayout(new BorderLayout()); bottomPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15));
hintsPanel.add(hintsLabel, BorderLayout.EAST); bottomPanel.add(confirmButton);
jd.add(hintsLabel); bottomPanel.add(cancelButton);
JPanel btPanel = new JPanel(new BorderLayout()); this.add(
btPanel.setLayout(new BoxLayout(btPanel, BoxLayout.X_AXIS)); TableLayoutHelper.createTableLayoutPane(
btPanel.add(Box.createHorizontalGlue()); new Component[][]{
btPanel.add(confirmButton); new Component[]{topPanel},
btPanel.add(Box.createHorizontalStrut(5)); new Component[]{midPanel},
btPanel.add(cancelButton); new Component[]{bottomPanel}
btPanel.add(Box.createHorizontalStrut(20)); },
jd.add(btPanel); new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL},
new double[]{TableLayout.FILL}
jd.setSize(380, 200); ),
jd.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Rename")); BorderLayout.CENTER);
jd.setResizable(false);
jd.setAlwaysOnTop(true);
jd.setIconImage(BaseUtils.readImage("/com/fr/base/images/oem/logo.png")); this.setSize(340, 180);
jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Rename"));
GUICoreUtils.centerWindow(jd); this.setResizable(false);
jd.setVisible(true); this.setAlwaysOnTop(true);
this.setIconImage(BaseUtils.readImage("/com/fr/base/images/oem/logo.png"));
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
GUICoreUtils.centerWindow(this);
this.setVisible(true);
} }
public void confirmClose(FileNodeFILE nodeFile, String path) { private void confirmClose() {
String userInput = nameField.getText().trim();
String path = fnf.getPath();
String oldName = fnf.getName();
String suffix = fnf.isDirectory() ? "" : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length());
oldName = oldName.replaceAll(suffix, "");
// 输入为空或者没有修改
if (ComparatorUtils.equals(userInput, oldName)) {
this.dispose();
return;
}
String oldPath = path.replaceAll(CoreConstants.SEPARATOR, "\\\\");
String parentPath = fnf.getParent().getPath().replaceAll(CoreConstants.SEPARATOR, "\\\\");
userInput = userInput == null ? oldName : userInput; // 简单执行old new 替换是不可行的,例如 /abc/abc/abc/abc/
String oldPath = path.replaceAll("/", "\\\\"); String newPath = parentPath + "\\" + userInput + suffix;
String newPath = path.replace(nodeFile.getName(), userInput + suffix);
renameTemplateInMemory(nodeFile, userInput + suffix, oldName + suffix); HistoryTemplateListCache.getInstance().rename(fnf, oldPath, newPath);
DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(oldPath, newPath.replaceAll("/", "\\\\")); DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(fnf.isDirectory(), oldPath, newPath);
//模版重命名 //模版重命名
ResourceIOUtils.renameTo(path, newPath); boolean success = selectedOperation.rename(fnf, oldPath, newPath);
selectedOperation.refresh(); selectedOperation.refresh();
DesignerContext.getDesignerFrame().setTitle(); DesignerContext.getDesignerFrame().setTitle();
jd.dispose(); this.dispose();
if (!success) {
JOptionPane.showConfirmDialog(null,
Toolkit.i18nText("Fine-Design_Basic_Rename_Failure"),
UIManager.getString("OptionPane.titleText"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE);
}
} }
private void renameTemplateInMemory(FILE tplFile, String newName, String oldName) {
JTemplate<?, ?> dPane = getSpecialTemplateByFILE(tplFile); private void validInput() {
if (dPane == null) {
String userInput = nameField.getText().trim();
String oldName = fnf.getName();
String suffix = fnf.isDirectory() ? "" : oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length());
oldName = oldName.replaceAll(suffix, "");
if (StringUtils.isEmpty(userInput)) {
confirmButton.setEnabled(false);
}
if (ComparatorUtils.equals(userInput, oldName)) {
warnLabel.setVisible(false);
confirmButton.setEnabled(true);
return; return;
} }
FILE renameFile = dPane.getEditingFILE();
renameFile.setPath(renameFile.getPath().replace(oldName, newName)); if (selectedOperation.duplicated(userInput, suffix)) {
nameField.selectAll();
// 如果文件名已存在,则灰掉确认按钮
warnLabel.setText(
Toolkit.i18nText(fnf.isDirectory() ?
"Fine-Design_Basic_Folder_Name_Duplicate" :
"Fine-Design_Basic_Template_File_Name_Duplicate",
userInput));
warnLabel.setVisible(true);
confirmButton.setEnabled(false);
} else {
warnLabel.setVisible(false);
confirmButton.setEnabled(true);
}
} }
}
// 增加enter以及esc快捷键的支持
public void addUITextFieldListener(final FileNodeFILE nodeFile, final String path) {
jt.addKeyListener(new KeyAdapter() { /**
* 新建文件夹对话框
* 支持快捷键EnterESC
*/
private class MkdirDialog extends JDialog {
public void keyPressed(KeyEvent e) { private UITextField nameField;
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { private UILabel warnLabel;
jd.dispose();
} private UIButton confirmButton;
private MkdirDialog() {
this.setLayout(new BorderLayout());
this.setModal(true);
// 输入框前提示
UILabel newNameLabel = new UILabel(Toolkit.i18nText(
"Fine-Design_Basic_Enter_New_Folder_Name")
);
newNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
newNameLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
newNameLabel.setPreferredSize(new Dimension(118, 15));
// 文件名输入框
nameField = new UITextField();
nameField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
validInput();
}
public void insertUpdate(DocumentEvent e) {
validInput();
}
public void removeUpdate(DocumentEvent e) {
validInput();
} }
}); });
nameField.selectAll();
nameField.setPreferredSize(new Dimension(180, 20));
jt.addKeyListener(new KeyAdapter() { JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 5));
topPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 0, 15));
topPanel.add(newNameLabel);
topPanel.add(nameField);
// 增加enter以及esc快捷键的支持
nameField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) { dispose();
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (confirmButton.isEnabled()) { if (confirmButton.isEnabled()) {
confirmClose(nodeFile, path); confirmClose();
} }
} }
} }
}); });
// 重名提示
warnLabel = new UILabel();
warnLabel.setPreferredSize(new Dimension(300, 30));
warnLabel.setHorizontalAlignment(SwingConstants.LEFT);
warnLabel.setForeground(Color.RED);
warnLabel.setVisible(false);
JPanel midPanel = new JPanel(new BorderLayout());
midPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15));
midPanel.add(warnLabel, BorderLayout.WEST);
// 确认按钮
confirmButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Confirm"));
confirmButton.setPreferredSize(new Dimension(60, 25));
confirmButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
confirmClose();
}
});
} // 取消按钮
UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel"));
cancelButton.setPreferredSize(new Dimension(60, 25));
// UITextField的输入监听 cancelButton.addActionListener(new ActionListener() {
public DocumentListener getdoDocumentListener() {
DocumentListener dl = new DocumentListener() { public void actionPerformed(ActionEvent e) {
dispose();
}
});
public void changedUpdate(DocumentEvent e) { JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
bottomPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15));
bottomPanel.add(confirmButton);
bottomPanel.add(cancelButton);
this.add(
TableLayoutHelper.createTableLayoutPane(
new Component[][]{
new Component[]{topPanel},
new Component[]{midPanel},
new Component[]{bottomPanel}
},
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL},
new double[]{TableLayout.FILL}
),
BorderLayout.CENTER);
this.setSize(340, 180);
this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Mkdir"));
this.setResizable(false);
this.setAlwaysOnTop(true);
this.setIconImage(BaseUtils.readImage("/com/fr/base/images/oem/logo.png"));
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
GUICoreUtils.centerWindow(this);
this.setVisible(true);
}
isNameAlreadyExist(); private void confirmClose() {
} String userInput = nameField.getText().trim();
public void insertUpdate(DocumentEvent e) { if (StringUtils.isEmpty(userInput)) {
return;
}
isNameAlreadyExist(); //新建文件夹
} boolean success = selectedOperation.mkdir(
selectedOperation.getFileNode().getParent() + CoreConstants.SEPARATOR + userInput
);
selectedOperation.refresh();
this.dispose();
if (!success) {
JOptionPane.showConfirmDialog(null,
Toolkit.i18nText("Fine-Design_Basic_Make_Failure"),
UIManager.getString("OptionPane.titleText"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE);
}
}
public void removeUpdate(DocumentEvent e) {
isNameAlreadyExist(); private void validInput() {
} String userInput = nameField.getText().trim();
};
return dl;
}
private void isNameAlreadyExist() { if (StringUtils.isEmpty(userInput)) {
confirmButton.setEnabled(false);
}
userInput = jt.getText().trim(); if (selectedOperation.duplicated(userInput, StringUtils.EMPTY)) {
if (selectedOperation.isNameAlreadyExist(userInput, oldName, suffix)) { nameField.selectAll();
jt.selectAll();
// 如果文件名已存在,则灰掉确认按钮 // 如果文件名已存在,则灰掉确认按钮
hintsLabel.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Template_File_Name_Duplicate", userInput)); warnLabel.setText(
hintsLabel.setVisible(true); Toolkit.i18nText(
"Fine-Design_Basic_Folder_Name_Duplicate",
userInput));
warnLabel.setVisible(true);
confirmButton.setEnabled(false); confirmButton.setEnabled(false);
} else { } else {
hintsLabel.setVisible(false); warnLabel.setVisible(false);
confirmButton.setEnabled(true); confirmButton.setEnabled(true);
} }
} }
} }
/**
* @param tplFile
* @return 内存中的template重命名一下
*/
private JTemplate<?, ?> getSpecialTemplateByFILE(FILE tplFile) {
HistoryTemplateListPane historyHandle = HistoryTemplateListPane.getInstance();
if (ComparatorUtils.equals(historyHandle.getCurrentEditingTemplate().getEditingFILE(), tplFile)) {
return historyHandle.getCurrentEditingTemplate();
}
for (int i = 0; i < historyHandle.getHistoryCount(); i++) {
if (ComparatorUtils.equals(historyHandle.get(i).getEditingFILE(), tplFile)) {
return historyHandle.get(i);
}
}
return null;
}
public FileOperations getSelectedOperation() {
return selectedOperation;
}
} }

68
designer-base/src/main/java/com/fr/design/menu/KeySetUtils.java

@ -5,7 +5,7 @@
package com.fr.design.menu; package com.fr.design.menu;
import javax.swing.*; import javax.swing.KeyStroke;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
@ -20,6 +20,23 @@ import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_M
public class KeySetUtils { public class KeySetUtils {
public static final MenuKeySet NEW_FOLDER = new MenuKeySet() {
@Override
public char getMnemonic() {
return 'I';
}
@Override
public String getMenuName() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_New_Folder");
}
@Override
public KeyStroke getKeyStroke() {
return KeyStroke.getKeyStroke(KeyEvent.VK_I, DEFAULT_MODIFIER);
}
};
public static final MenuKeySet OPEN_TEMPLATE = new MenuKeySet() { public static final MenuKeySet OPEN_TEMPLATE = new MenuKeySet() {
@Override @Override
@ -547,7 +564,9 @@ public class KeySetUtils {
public static final MenuKeySet REPORT_WATERMARK = new MenuKeySet() { public static final MenuKeySet REPORT_WATERMARK = new MenuKeySet() {
@Override @Override
public char getMnemonic() { return 'M'; } public char getMnemonic() {
return 'M';
}
@Override @Override
public String getMenuName() { public String getMenuName() {
@ -974,14 +993,6 @@ public class KeySetUtils {
}; };
public static final MenuKeySet INSERT_FLOAT = new MenuKeySet() { public static final MenuKeySet INSERT_FLOAT = new MenuKeySet() {
@Override @Override
public char getMnemonic() { public char getMnemonic() {
@ -1000,41 +1011,4 @@ public class KeySetUtils {
}; };
} }

71
designer-base/src/main/java/com/fr/file/FILE.java

@ -1,93 +1,106 @@
package com.fr.file; package com.fr.file;
import javax.swing.Icon; import javax.swing.Icon;
import java.io.InputStream;
import java.io.OutputStream;
public interface FILE { public interface FILE {
/** /**
* 后缀 * 前缀
* @return 后缀 *
* @return 前缀
*/ */
public String prefix(); String prefix();
/** /**
* 是否是目录 * 是否是目录
*
* @return 是则返回true * @return 是则返回true
*/ */
public boolean isDirectory(); boolean isDirectory();
// Name // Name
public String getName(); String getName();
// Icon // Icon
public Icon getIcon(); Icon getIcon();
// 当前目录的Path // 当前目录的Path
public String getPath(); String getPath();
public void setPath(String path); void setPath(String path);
// 取当前目录的上级目录 // 取当前目录的上级目录
public FILE getParent(); FILE getParent();
/** /**
* 列出当前目录下所有的文件及文件夹 * 列出当前目录下所有的文件及文件夹
*
* @return 文件 * @return 文件
*/ */
public FILE[] listFiles(); FILE[] listFiles();
/** /**
* 新建一个目录 * 新建一个目录
*
* @param name 名字 * @param name 名字
* @return 新建目录 * @return 新建目录
*/ */
public boolean createFolder(String name); boolean createFolder(String name);
/** /**
* 新建文件 * 新建文件
*
* @return 是否新建成功 * @return 是否新建成功
* @throws Exception 异常 * @throws Exception 异常
*/ */
public boolean mkfile() throws Exception; boolean mkfile() throws Exception;
/** /**
* 是否存在 * 是否存在
*
* @return 是否存在 * @return 是否存在
*/ */
public boolean exists(); boolean exists();
/** /**
* 关闭文件 * 关闭文件
*
* @throws Exception 异常 * @throws Exception 异常
*/ */
public void closeTemplate() throws Exception; void closeTemplate() throws Exception;
/** /**
* 作为输入流 * 作为输入流
*
* @return 输入流 * @return 输入流
* @throws Exception 异常 * @throws Exception 异常
*/ */
public java.io.InputStream asInputStream() throws Exception; InputStream asInputStream() throws Exception;
/** /**
* 作为输出流 * 作为输出流
*
* @return 输出流 * @return 输出流
* @throws Exception 异常 * @throws Exception 异常
*/ */
public java.io.OutputStream asOutputStream() throws Exception; OutputStream asOutputStream() throws Exception;
public String getEnvFullName(); String getEnvFullName();
/** /**
* 是否是内存文件 * 是否是内存文件
*
* @return 是则返回true * @return 是则返回true
*/ */
public boolean isMemFile(); boolean isMemFile();
/** /**
* 是否是环境文件 * 是否是环境文件
*
* @return 是则返回true * @return 是则返回true
*/ */
public boolean isEnvFile(); boolean isEnvFile();
} }

831
designer-base/src/main/java/com/fr/file/FILEChooserPane.java

File diff suppressed because it is too large Load Diff

6
designer-base/src/main/java/com/fr/file/FILEFactory.java

@ -1,6 +1,7 @@
package com.fr.file; package com.fr.file;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.file.NodeAuthProcessor;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
@ -19,7 +20,7 @@ public class FILEFactory {
* 也有可能就是一个普通的路径d:/foo/bar * 也有可能就是一个普通的路径d:/foo/bar
*/ */
public static FILE createFILE(String path) { public static FILE createFILE(String path) {
String envPath = WorkContext.getCurrent().getPath().replaceAll("/", "\\\\"); String envPath = WorkContext.getCurrent().getPath().replaceAll("/", "\\\\");
if (path == null) { if (path == null) {
return null; return null;
@ -45,7 +46,8 @@ public class FILEFactory {
} else if (path.startsWith(MEM_PREFIX)) { } else if (path.startsWith(MEM_PREFIX)) {
return new MemFILE(path.substring(MEM_PREFIX.length())); return new MemFILE(path.substring(MEM_PREFIX.length()));
} else if (path.startsWith(ENV_PREFIX)) { } else if (path.startsWith(ENV_PREFIX)) {
return new FileNodeFILE(new FileNode(path.substring(ENV_PREFIX.length()), true)); return NodeAuthProcessor.getInstance().
fixFILENodeAuth(new FileNode(path.substring(ENV_PREFIX.length()), true));
} else if (path.startsWith(WEBREPORT_PREFIX)) { } else if (path.startsWith(WEBREPORT_PREFIX)) {
return new FileNodeFILE(new FileNode(path.substring(WEBREPORT_PREFIX.length()), true), return new FileNodeFILE(new FileNode(path.substring(WEBREPORT_PREFIX.length()), true),
FRContext.getCommonOperator().getWebRootPath()); FRContext.getCommonOperator().getWebRootPath());

65
designer-base/src/main/java/com/fr/file/FileFILE.java

@ -4,11 +4,11 @@ import com.fr.base.io.XMLEncryptUtils;
import com.fr.design.gui.itree.filetree.FileComparator; import com.fr.design.gui.itree.filetree.FileComparator;
import com.fr.design.gui.itree.filetree.FileTreeIcon; import com.fr.design.gui.itree.filetree.FileTreeIcon;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.web.session.SessionLocalManager;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.web.session.SessionLocalManager;
import javax.swing.*; import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView; import javax.swing.filechooser.FileSystemView;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -16,6 +16,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FileFILE implements FILE { public class FileFILE implements FILE {
@ -30,9 +32,9 @@ public class FileFILE implements FILE {
} }
/** /**
* *
* *
* @return * @return
*/ */
public String prefix() { public String prefix() {
return FILEFactory.FILE_PREFIX; return FILEFactory.FILE_PREFIX;
@ -44,7 +46,7 @@ public class FileFILE implements FILE {
* @returns 是则返回true * @returns 是则返回true
*/ */
public boolean isDirectory() { public boolean isDirectory() {
return file == null ? false : file.isDirectory(); return file != null && file.isDirectory();
} }
@Override @Override
@ -118,22 +120,22 @@ public class FileFILE implements FILE {
return new FILE[]{this}; return new FILE[]{this};
} }
File[] file_array = file.listFiles(); File[] fileArray = file.listFiles();
if (file_array == null) { if (fileArray == null) {
return new FILE[0]; return new FILE[0];
} }
java.util.Arrays.sort(file_array, new FileComparator()); Arrays.sort(fileArray, new FileComparator());
java.util.List<FILE> res_list = new ArrayList<FILE>(file_array.length); List<FILE> resList = new ArrayList<FILE>(fileArray.length);
for (int i = 0; i < file_array.length; i++) { for (int i = 0; i < fileArray.length; i++) {
// 因为有一些系统文件,比如虚拟内存等,会在listFiles的时候出现,但却not exists // 因为有一些系统文件,比如虚拟内存等,会在listFiles的时候出现,但却not exists
if (file_array[i].exists()) { if (fileArray[i].exists()) {
res_list.add(new FileFILE(file_array[i])); resList.add(new FileFILE(fileArray[i]));
} }
} }
return res_list.toArray(new FILE[res_list.size()]); return resList.toArray(new FILE[resList.size()]);
} }
/** /**
@ -147,9 +149,7 @@ public class FileFILE implements FILE {
return false; return false;
} }
File new_file = new File(StableUtils.pathJoin(new String[]{ File new_file = new File(StableUtils.pathJoin(file.getAbsolutePath(), name));
file.getAbsolutePath(), name
}));
if (new_file.exists()) { if (new_file.exists()) {
return false; return false;
@ -164,7 +164,7 @@ public class FileFILE implements FILE {
* @return 是否存在 * @return 是否存在
*/ */
public boolean exists() { public boolean exists() {
return file == null ? false : file.exists(); return file != null && file.exists();
} }
/** /**
@ -192,13 +192,12 @@ public class FileFILE implements FILE {
* 作为输出流 * 作为输出流
* *
* @return 输出流 * @return 输出流
* @throws Exception 异常
*/ */
public OutputStream asOutputStream() throws Exception { public OutputStream asOutputStream() {
if (file == null || !file.exists()) { if (file == null || !file.exists()) {
return null; return null;
} }
java.io.OutputStream out = null; OutputStream out;
try { try {
out = new FileOutputStream(file); out = new FileOutputStream(file);
} catch (Exception e) { } catch (Exception e) {
@ -209,10 +208,8 @@ public class FileFILE implements FILE {
/** /**
* 关闭文件 * 关闭文件
*
* @throws Exception 异常
*/ */
public void closeTemplate() throws Exception { public void closeTemplate() {
} }
@Override @Override
@ -225,10 +222,10 @@ public class FileFILE implements FILE {
} }
/** /**
* 返回hash码 * 返回hash码
* *
* @return 返回hash码 * @return 返回hash码
*/ */
public int hashCode() { public int hashCode() {
int hash = 7; int hash = 7;
hash = 97 * hash + (this.file != null ? this.file.hashCode() : 0); hash = 97 * hash + (this.file != null ? this.file.hashCode() : 0);
@ -251,17 +248,19 @@ public class FileFILE implements FILE {
} }
/** /**
* 是否是内存文件 * 是否是内存文件
* @return 是则返回true *
*/ * @return 是则返回true
*/
public boolean isMemFile() { public boolean isMemFile() {
return false; return false;
} }
/** /**
* 是否是环境文件 * 是否是环境文件
* @return 是则返回true *
*/ * @return 是则返回true
*/
public boolean isEnvFile() { public boolean isEnvFile() {
return false; return false;
} }

239
designer-base/src/main/java/com/fr/file/FileNodeFILE.java

@ -3,32 +3,39 @@ package com.fr.file;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.base.io.XMLEncryptUtils; import com.fr.base.io.XMLEncryptUtils;
import com.fr.design.file.NodeAuthProcessor;
import com.fr.design.gui.itree.filetree.FileNodeComparator; import com.fr.design.gui.itree.filetree.FileNodeComparator;
import com.fr.design.gui.itree.filetree.FileTreeIcon; import com.fr.design.gui.itree.filetree.FileTreeIcon;
import com.fr.design.i18n.Toolkit;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.workspace.resource.WorkResourceOutputStream;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.CoreConstants; import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.resource.WorkResourceOutputStream;
import javax.swing.*; import javax.swing.Icon;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays;
public class FileNodeFILE implements FILE { public class FileNodeFILE implements FILE {
private FileNode node; private FileNode node;
// carl:记录下FILE对应的运行环境,每次创建都设置下当前的运行环境 //记录下FILE对应的运行环境,每次创建都设置下当前的运行环境
private String envPath; private String envPath;
/**
* 是否有全部权限
*/
private boolean hasFullAuth = true;
public FileNodeFILE(FileNodeFILE parent, String name, boolean isDir) { public FileNodeFILE(FileNodeFILE parent, String name, boolean isDir) {
FileNode fn = parent.node; FileNode fn = parent.node;
String parentDir; String parentDir;
if (fn.isDirectory()) { if (fn.isDirectory()) {
@ -36,156 +43,187 @@ public class FileNodeFILE implements FILE {
} else { } else {
parentDir = fn.getParent(); parentDir = fn.getParent();
} }
this.node = new FileNode(StableUtils.pathJoin(parentDir, name), isDir); this.node = new FileNode(StableUtils.pathJoin(parentDir, name), isDir);
this.envPath = WorkContext.getCurrent().getPath(); this.envPath = WorkContext.getCurrent().getPath();
this.hasFullAuth = NodeAuthProcessor.getInstance().fixFileNodeAuth(node);
} }
public FileNodeFILE(FileNode node) { public FileNodeFILE(FileNode node) {
this.node = node; this.node = node;
this.envPath = WorkContext.getCurrent().getPath(); this.envPath = WorkContext.getCurrent().getPath();
this.hasFullAuth = NodeAuthProcessor.getInstance().fixFileNodeAuth(node);
}
public FileNodeFILE(FileNode node, boolean hasFullAuth) {
this(node);
this.hasFullAuth = hasFullAuth;
} }
public FileNodeFILE(String envPath) { public FileNodeFILE(String envPath) {
this.node = null; this.node = null;
this.envPath = envPath; this.envPath = envPath;
} }
public FileNodeFILE(FileNode node, String envPath) { public FileNodeFILE(FileNode node, String envPath) {
this.node = node; this.node = node;
this.envPath = envPath; this.envPath = envPath;
this.hasFullAuth = NodeAuthProcessor.getInstance().fixFileNodeAuth(node);
}
public FileNodeFILE(FileNode node, String envPath, boolean hasFullAuth) {
this(node, envPath);
this.hasFullAuth = hasFullAuth;
}
/**
* @return 是否有完整权限
*/
public boolean hasFullAuth() {
return hasFullAuth;
} }
/** /**
* prefix 后缀 *
* *
* @return 返回后缀 * @return
*/ */
@Override
public String prefix() { public String prefix() {
if (ComparatorUtils.equals(getEnvPath(), FRContext.getCommonOperator().getWebRootPath())) { if (ComparatorUtils.equals(getEnvPath(), FRContext.getCommonOperator().getWebRootPath())) {
return FILEFactory.WEBREPORT_PREFIX; return FILEFactory.WEBREPORT_PREFIX;
} }
return FILEFactory.ENV_PREFIX; return FILEFactory.ENV_PREFIX;
} }
/** /**
* @return * @return
*/ */
public String getEnvPath() { public String getEnvPath() {
return this.envPath; return this.envPath;
} }
/** /**
* 是否是目录 * 是否是目录
* *
* @return 是则返回true * @return 是则返回true
*/ */
@Override
public boolean isDirectory() { public boolean isDirectory() {
return ComparatorUtils.equals(node, null) ? true : node.isDirectory(); return ComparatorUtils.equals(node, null) || node.isDirectory();
} }
/** /**
* @return * @return
*/ */
@Override
public String getName() { public String getName() {
if (node == null) { if (node == null) {
return null; return null;
} }
if (ComparatorUtils.equals(node.getEnvPath(), ProjectConstants.REPORTLETS_NAME)) { if (ComparatorUtils.equals(node.getEnvPath(), ProjectConstants.REPORTLETS_NAME)) {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Report_Runtime_Env"); return Toolkit.i18nText("Fine-Design_Basic_Utils_Report_Runtime_Env");
} else { } else {
return node.getName(); return node.getName();
} }
} }
/** /**
* @return * @return
*/ */
@Override
public Icon getIcon() { public Icon getIcon() {
if (node == null) { if (node == null) {
return null; return null;
} }
if (ComparatorUtils.equals(node.getEnvPath(), ProjectConstants.REPORTLETS_NAME)) { if (ComparatorUtils.equals(node.getEnvPath(), ProjectConstants.REPORTLETS_NAME)) {
return BaseUtils.readIcon("/com/fr/base/images/oem/logo.png"); return BaseUtils.readIcon("/com/fr/base/images/oem/logo.png");
} else { } else {
if (!hasFullAuth) {
return FileTreeIcon.getFolderHalfImageIcon();
}
return FileTreeIcon.getIcon(node); return FileTreeIcon.getIcon(node);
} }
} }
/** /**
* @return * @return
*/ */
@Override
public String getPath() { public String getPath() {
if (node == null) { if (node == null) {
return ""; return "";
} }
return node.getEnvPath(); return node.getEnvPath();
} }
/** /**
* @param path * @param path
*/ */
@Override
public void setPath(String path) { public void setPath(String path) {
node.setEnvPath(path); node.setEnvPath(path);
} }
/** /**
* @return * @return
*/ */
@Override
public FILE getParent() { public FILE getParent() {
if (node == null) { if (node == null) {
return null; return null;
} }
return new FileNodeFILE(new FileNode(node.getParent(), true)); return new FileNodeFILE(new FileNode(node.getParent(), true));
} }
/** /**
* 文件 * 文件
* *
* @return 文件组 * @return 文件组
*/ */
@Override
public FILE[] listFiles() { public FILE[] listFiles() {
if (ComparatorUtils.equals(node, null)) { if (ComparatorUtils.equals(node, null)) {
node = new FileNode(CoreConstants.SEPARATOR, true); node = new FileNode(CoreConstants.SEPARATOR, true);
//return new FILE[0];
} }
if (!node.isDirectory()) { if (!node.isDirectory()) {
return new FILE[]{this}; return new FILE[]{this};
} }
try { try {
FileNode[] node_array; FileNode[] nodeArray;
node_array = listFile(node.getEnvPath()); nodeArray = listFile(node.getEnvPath());
java.util.Arrays.sort(node_array, new FileNodeComparator()); Arrays.sort(nodeArray, new FileNodeComparator());
FILE[] res_array = new FILE[node_array.length]; return fileNodeArray2FILEArray(nodeArray, envPath);
for (int i = 0; i < node_array.length; i++) {
res_array[i] = new FileNodeFILE(node_array[i], envPath);
}
return res_array;
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
return new FILE[0]; return new FILE[0];
} }
} }
private FILE[] fileNodeArray2FILEArray(FileNode[] nodeArray, String envPath) {
return NodeAuthProcessor.getInstance().parser2FILEArray(nodeArray, envPath);
}
/** /**
* 根目录文件地址 * 根目录文件地址
* *
@ -193,7 +231,7 @@ public class FileNodeFILE implements FILE {
* @return 返回文件节点 * @return 返回文件节点
*/ */
private FileNode[] listFile(String rootFilePath) { private FileNode[] listFile(String rootFilePath) {
try { try {
if (ComparatorUtils.equals(envPath, FRContext.getCommonOperator().getWebRootPath())) { if (ComparatorUtils.equals(envPath, FRContext.getCommonOperator().getWebRootPath())) {
return FRContext.getFileNodes().listWebRootFile(rootFilePath); return FRContext.getFileNodes().listWebRootFile(rootFilePath);
@ -205,19 +243,20 @@ public class FileNodeFILE implements FILE {
} }
return new FileNode[0]; return new FileNode[0];
} }
/** /**
* 创建文件夹 * 创建文件夹
* *
* @param name 文件夹名字 * @param name 文件夹名字
* @return 创建成功返回true * @return 创建成功返回true
*/ */
@Override
public boolean createFolder(String name) { public boolean createFolder(String name) {
if (ComparatorUtils.equals(node, null) || !node.isDirectory()) { if (ComparatorUtils.equals(node, null) || !node.isDirectory()) {
return false; return false;
} }
try { try {
return WorkContext.getWorkResource().createDirectory(StableUtils.pathJoin(node.getEnvPath(), name)); return WorkContext.getWorkResource().createDirectory(StableUtils.pathJoin(node.getEnvPath(), name));
} catch (Exception e) { } catch (Exception e) {
@ -225,18 +264,18 @@ public class FileNodeFILE implements FILE {
return false; return false;
} }
} }
/** /**
* 是否锁住 * 是否锁住
* *
* @return 文件被锁返回true * @return 文件被锁返回true
*/ */
public boolean isLocked() { public boolean isLocked() {
if (node == null) { if (node == null) {
return false; return false;
} }
try { try {
return FRContext.getCommonOperator().fileLocked(node.getEnvPath()); return FRContext.getCommonOperator().fileLocked(node.getEnvPath());
} catch (Exception e) { } catch (Exception e) {
@ -244,14 +283,15 @@ public class FileNodeFILE implements FILE {
return false; return false;
} }
} }
/** /**
* 是否存在 * 是否存在
* *
* @return 文件存在返回 true * @return 文件存在返回 true
*/ */
@Override
public boolean exists() { public boolean exists() {
if (node == null) { if (node == null) {
return false; return false;
} }
@ -259,7 +299,7 @@ public class FileNodeFILE implements FILE {
if (!isCurrentEnv()) { if (!isCurrentEnv()) {
return false; return false;
} }
try { try {
return WorkContext.getWorkResource().exist(node.getEnvPath()); return WorkContext.getWorkResource().exist(node.getEnvPath());
} catch (Exception e) { } catch (Exception e) {
@ -267,28 +307,29 @@ public class FileNodeFILE implements FILE {
return false; return false;
} }
} }
/** /**
* 是否是当前环境 * 是否是当前环境
* *
* @return 是报表当前环境返回true * @return 是报表当前环境返回true
*/ */
public boolean isCurrentEnv() { public boolean isCurrentEnv() {
return ComparatorUtils.equals(WorkContext.getCurrent().getPath(), envPath); return ComparatorUtils.equals(WorkContext.getCurrent().getPath(), envPath);
} }
/** /**
* 创建文件 * 创建文件
* *
* @return 成功返回true * @return 成功返回true
*/ */
@Override
public boolean mkfile() { public boolean mkfile() {
if (node == null) { if (node == null) {
return false; return false;
} }
try { try {
return WorkContext.getWorkResource().createFile(node.getEnvPath()); return WorkContext.getWorkResource().createFile(node.getEnvPath());
} catch (Exception e) { } catch (Exception e) {
@ -296,43 +337,45 @@ public class FileNodeFILE implements FILE {
return false; return false;
} }
} }
/** /**
* 作为输入流 * 作为输入流
* *
* @return 输入流 * @return 输入流
* @throws Exception * @throws Exception
*/ */
@Override
public InputStream asInputStream() throws Exception { public InputStream asInputStream() throws Exception {
if (node == null) { if (node == null) {
return null; return null;
} }
String envPath = node.getEnvPath(); String envPath = node.getEnvPath();
// envPath必须以reportlets开头 // envPath必须以reportlets开头
if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
return null; return null;
} }
InputStream in = new ByteArrayInputStream(WorkContext.getWorkResource().readFully(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)))); InputStream in = new ByteArrayInputStream(WorkContext.getWorkResource().readFully(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1))));
return envPath.endsWith(".cpt") || envPath.endsWith(".frm") return envPath.endsWith(".cpt") || envPath.endsWith(".frm")
? XMLEncryptUtils.decodeInputStream(in) : in; ? XMLEncryptUtils.decodeInputStream(in) : in;
} }
/** /**
* 作为输出流 * 作为输出流
* *
* @return 返回输出流 * @return 返回输出流
* @throws Exception * @throws Exception
*/ */
@Override
public OutputStream asOutputStream() throws Exception { public OutputStream asOutputStream() throws Exception {
if (ComparatorUtils.equals(node, null)) { if (ComparatorUtils.equals(node, null)) {
return null; return null;
} }
String envPath = node.getEnvPath(); String envPath = node.getEnvPath();
// envPath必须以reportlets开头 // envPath必须以reportlets开头
if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
@ -340,58 +383,62 @@ public class FileNodeFILE implements FILE {
} }
return new WorkResourceOutputStream(envPath); return new WorkResourceOutputStream(envPath);
} }
/** /**
* 关闭模板 * 关闭模板
* *
* @throws Exception * @throws Exception
*/ */
@Override
public void closeTemplate() throws Exception { public void closeTemplate() throws Exception {
if (node == null) { if (node == null) {
return; return;
} }
String envPath = node.getEnvPath(); String envPath = node.getEnvPath();
// envPath必须以reportlets开头 // envPath必须以reportlets开头
if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
return; return;
} }
FRContext.getCommonOperator().unlockTemplate( FRContext.getCommonOperator().unlockTemplate(
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)); envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1));
} }
/** /**
* 得到环境的全名 * 得到环境的全名
* *
* @return * @return
*/ */
@Override
public String getEnvFullName() { public String getEnvFullName() {
return this.node.getEnvPath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1); return this.node.getEnvPath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
} }
/** /**
* 是否是内存文件 * 是否是内存文件
* *
* @return 是则返回true * @return 是则返回true
*/ */
@Override
public boolean isMemFile() { public boolean isMemFile() {
return false; return false;
} }
/** /**
* 是否是环境文件 * 是否是环境文件
* *
* @return 是则返回true * @return 是则返回true
*/ */
@Override
public boolean isEnvFile() { public boolean isEnvFile() {
return true; return true;
} }
/** /**
* 是佛相同 * 是佛相同
* *
@ -399,34 +446,34 @@ public class FileNodeFILE implements FILE {
* @return * @return
*/ */
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof FileNodeFILE)) { if (!(obj instanceof FileNodeFILE)) {
return false; return false;
} }
return ComparatorUtils.equals(this.envPath, ((FileNodeFILE) obj).envPath) && ComparatorUtils.equals(this.node, ((FileNodeFILE) obj).node); return ComparatorUtils.equals(this.envPath, ((FileNodeFILE) obj).envPath) && ComparatorUtils.equals(this.node, ((FileNodeFILE) obj).node);
} }
/** /**
* 返回hash码 * 返回hash码
* *
* @return 返回hash码 * @return 返回hash码
*/ */
public int hashCode() { public int hashCode() {
int hash = 5; int hash = 5;
hash = 61 * hash + (this.node != null ? this.node.hashCode() : 0); hash = 61 * hash + (this.node != null ? this.node.hashCode() : 0);
hash = 61 * hash + (this.envPath != null ? this.envPath.hashCode() : 0); hash = 61 * hash + (this.envPath != null ? this.envPath.hashCode() : 0);
return hash; return hash;
} }
/** /**
* 作为字符串返回 * 作为字符串返回
* *
* @return String 字符串 * @return String 字符串
*/ */
public String toString() { public String toString() {
return prefix() + (this.node != null ? this.node.getEnvPath() : ""); return prefix() + (this.node != null ? this.node.getEnvPath() : "");
} }
} }

7
designer-base/src/main/java/com/fr/file/MemFILE.java

@ -1,10 +1,9 @@
package com.fr.file; package com.fr.file;
import javax.swing.Icon;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import javax.swing.Icon;
public class MemFILE implements FILE { public class MemFILE implements FILE {
private String name; private String name;
@ -103,9 +102,9 @@ public class MemFILE implements FILE {
} }
/** /**
* *
* *
* @return * @return
*/ */
public String prefix() { public String prefix() {
return FILEFactory.MEM_PREFIX; return FILEFactory.MEM_PREFIX;

BIN
designer-base/src/main/resources/com/fr/design/images/icon_NewFolderIcon_normal.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

Loading…
Cancel
Save