Browse Source
* commit '3752c38f176805e9c3c4defed6b3b5310b7a7a7a': REPORT-10689 远程设计新建删除和重命名research/10.0
yaoh.wu
6 years ago
16 changed files with 2057 additions and 1458 deletions
@ -1,45 +1,88 @@
|
||||
package com.fr.design.file; |
||||
|
||||
|
||||
import com.fr.file.FILE; |
||||
import com.fr.file.filetree.FileNode; |
||||
|
||||
public interface FileOperations { |
||||
|
||||
/** |
||||
* 新建文件夹 |
||||
* |
||||
* @param name 文件夹名称 |
||||
* @return 是否成功 |
||||
*/ |
||||
boolean mkdir(String name); |
||||
|
||||
/** |
||||
*打开选中的报表文件 |
||||
* 打开报表文件 |
||||
*/ |
||||
public void openSelectedReport(); |
||||
void openFile(); |
||||
|
||||
/** |
||||
* 打开文件夹 |
||||
*/ |
||||
public void openContainerFolder(); |
||||
void showInExplorer(); |
||||
|
||||
/** |
||||
* 刷新 |
||||
*/ |
||||
public void refresh(); |
||||
void refresh(); |
||||
|
||||
/** |
||||
* 删除文件 |
||||
*/ |
||||
public void deleteFile(); |
||||
void deleteFile(); |
||||
|
||||
/** |
||||
* 加上文件锁 |
||||
*/ |
||||
public void lockFile(); |
||||
void lockFile(); |
||||
|
||||
/** |
||||
* 文件解锁 |
||||
*/ |
||||
public void unLockFile(); |
||||
void unlockFile(); |
||||
|
||||
/** |
||||
* 选中的模板路径 |
||||
* |
||||
* @return 选中的模板路径 |
||||
*/ |
||||
String getFilePath(); |
||||
|
||||
|
||||
/** |
||||
* 选中的文件节点 |
||||
* |
||||
* @return 文件节点 |
||||
*/ |
||||
FileNode getFileNode(); |
||||
|
||||
/** |
||||
* 是否有完整权限 |
||||
* |
||||
* @return 是否有完整权限 |
||||
*/ |
||||
boolean access(); |
||||
|
||||
/** |
||||
* 重命名 |
||||
* |
||||
* @param tplFile 旧文件 |
||||
* @param to 新文件名 |
||||
* @param from 旧文件名 |
||||
* @return 是否成功 |
||||
*/ |
||||
boolean rename(FILE tplFile, String from, String to); |
||||
|
||||
public String getSelectedTemplatePath(); |
||||
|
||||
/** |
||||
* 文件名是否存在 |
||||
* |
||||
* @param newName 原名 |
||||
* @param oldName 新的文件名 |
||||
* @param suffix 后缀名 |
||||
* @return 是否存在 |
||||
*/ |
||||
public boolean isNameAlreadyExist(String newName, String oldName, String suffix); |
||||
boolean duplicated(String newName, String suffix); |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -1,443 +1,16 @@
|
||||
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; |
||||
import com.fr.design.data.datapane.TableDataTreePane; |
||||
import com.fr.design.gui.icontainer.UIScrollPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ilist.UIList; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
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 文件位置 |
||||
* @see HistoryTemplateListCache |
||||
* @deprecated use HistoryTemplateListCache instead |
||||
*/ |
||||
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; |
||||
@Deprecated |
||||
public class HistoryTemplateListPane { |
||||
public static HistoryTemplateListCache getInstance() { |
||||
return HistoryTemplateListCache.getInstance(); |
||||
} |
||||
} |
||||
|
@ -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; |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -1,93 +1,106 @@
|
||||
package com.fr.file; |
||||
|
||||
import javax.swing.Icon; |
||||
import java.io.InputStream; |
||||
import java.io.OutputStream; |
||||
|
||||
public interface FILE { |
||||
|
||||
/** |
||||
* 后缀 |
||||
* @return 后缀 |
||||
* 前缀 |
||||
* |
||||
* @return 前缀 |
||||
*/ |
||||
public String prefix(); |
||||
String prefix(); |
||||
|
||||
/** |
||||
* 是否是目录 |
||||
* |
||||
* @return 是则返回true |
||||
*/ |
||||
public boolean isDirectory(); |
||||
boolean isDirectory(); |
||||
|
||||
// Name
|
||||
public String getName(); |
||||
String getName(); |
||||
|
||||
// Icon
|
||||
public Icon getIcon(); |
||||
Icon getIcon(); |
||||
|
||||
// 当前目录的Path
|
||||
public String getPath(); |
||||
String getPath(); |
||||
|
||||
public void setPath(String path); |
||||
void setPath(String path); |
||||
|
||||
// 取当前目录的上级目录
|
||||
public FILE getParent(); |
||||
FILE getParent(); |
||||
|
||||
/** |
||||
* 列出当前目录下所有的文件及文件夹 |
||||
* |
||||
* @return 文件 |
||||
*/ |
||||
public FILE[] listFiles(); |
||||
FILE[] listFiles(); |
||||
|
||||
/** |
||||
* 新建一个目录 |
||||
* |
||||
* @param name 名字 |
||||
* @return 新建目录 |
||||
*/ |
||||
public boolean createFolder(String name); |
||||
boolean createFolder(String name); |
||||
|
||||
/** |
||||
* 新建文件 |
||||
* |
||||
* @return 是否新建成功 |
||||
* @throws Exception 异常 |
||||
*/ |
||||
public boolean mkfile() throws Exception; |
||||
boolean mkfile() throws Exception; |
||||
|
||||
/** |
||||
* 是否存在 |
||||
* |
||||
* @return 是否存在 |
||||
*/ |
||||
public boolean exists(); |
||||
boolean exists(); |
||||
|
||||
/** |
||||
* 关闭文件 |
||||
* |
||||
* @throws Exception 异常 |
||||
*/ |
||||
public void closeTemplate() throws Exception; |
||||
void closeTemplate() throws Exception; |
||||
|
||||
/** |
||||
* 作为输入流 |
||||
* |
||||
* @return 输入流 |
||||
* @throws Exception 异常 |
||||
*/ |
||||
public java.io.InputStream asInputStream() throws Exception; |
||||
InputStream asInputStream() throws Exception; |
||||
|
||||
/** |
||||
* 作为输出流 |
||||
* |
||||
* @return 输出流 |
||||
* @throws Exception 异常 |
||||
*/ |
||||
public java.io.OutputStream asOutputStream() throws Exception; |
||||
OutputStream asOutputStream() throws Exception; |
||||
|
||||
public String getEnvFullName(); |
||||
String getEnvFullName(); |
||||
|
||||
|
||||
/** |
||||
* 是否是内存文件 |
||||
* |
||||
* @return 是则返回true |
||||
*/ |
||||
public boolean isMemFile(); |
||||
boolean isMemFile(); |
||||
|
||||
/** |
||||
* 是否是环境文件 |
||||
* |
||||
* @return 是则返回true |
||||
*/ |
||||
public boolean isEnvFile(); |
||||
boolean isEnvFile(); |
||||
} |
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 288 B |
Loading…
Reference in new issue