Browse Source

REPORT-75308 FVS大屏模板支持同时打开多个

feature/x
kerry 2 years ago
parent
commit
463f8d9e61
  1. 8
      designer-base/src/main/java/com/fr/design/actions/file/CloseCurrentTemplateAction.java
  2. 4
      designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java
  3. 2
      designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java
  4. 43
      designer-base/src/main/java/com/fr/design/file/CloseOption.java
  5. 41
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  6. 346
      designer-base/src/main/java/com/fr/design/file/MultiTemplateTabMenuFactory.java
  7. 486
      designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java
  8. 6
      designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java
  9. 6
      designer-base/src/main/java/com/fr/design/file/NewTemplatePane.java
  10. 19
      designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java
  11. 253
      designer-base/src/main/java/com/fr/design/file/TemplateTabManager.java
  12. 114
      designer-base/src/main/java/com/fr/design/file/TemplateTabOperateProvider.java
  13. 332
      designer-base/src/main/java/com/fr/design/file/impl/AbstractTemplateTabOperate.java
  14. 31
      designer-base/src/main/java/com/fr/design/file/impl/DefaultTemplateTabOperate.java
  15. 109
      designer-base/src/main/java/com/fr/design/file/impl/EmptyTemplateTabOperator.java
  16. 29
      designer-base/src/main/java/com/fr/design/mainframe/CenterRegionContainerPane.java
  17. 8
      designer-base/src/main/java/com/fr/design/mainframe/DefaultToolKitConfig.java
  18. 8
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java
  19. 15
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java
  20. 21
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  21. 10
      designer-base/src/main/java/com/fr/design/mainframe/ToolKitConfigStrategy.java
  22. 4
      designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java
  23. 8
      designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java
  24. 8
      designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionsPanel.java
  25. 4
      designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java
  26. 8
      designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java
  27. 6
      designer-base/src/main/java/com/fr/start/BaseDesigner.java
  28. 4
      designer-base/src/main/java/com/fr/start/common/DesignerOpenEmptyPanel.java
  29. 4
      designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java
  30. 5
      designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java
  31. 4
      designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java
  32. 4
      designer-realize/src/main/java/com/fr/start/MainDesigner.java

8
designer-base/src/main/java/com/fr/design/actions/file/CloseCurrentTemplateAction.java

@ -3,7 +3,7 @@ package com.fr.design.actions.file;
import com.fr.design.actions.UpdateAction; import com.fr.design.actions.UpdateAction;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.KeySetUtils;
@ -28,9 +28,9 @@ public class CloseCurrentTemplateAction extends UpdateAction {
* @param e 事件 * @param e 事件
*/ */
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); TemplateTabManager.getInstance().setCloseCurrent(true);
MultiTemplateTabPane.getInstance().closeFormat(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); TemplateTabManager.getInstance().closeFormat(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); TemplateTabManager.getInstance().closeSpecifiedTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
} }
@Override @Override

4
designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java

@ -7,7 +7,7 @@ import com.fr.design.actions.UpdateAction;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.FileOperations; import com.fr.design.file.FileOperations;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
@ -88,7 +88,7 @@ public class RenameAction extends UpdateAction {
} }
new FileRenameDialog(node); new FileRenameDialog(node);
MultiTemplateTabPane.getInstance().repaint(); TemplateTabManager.getInstance().refresh();
DesignerFrameFileDealerPane.getInstance().stateChange(); DesignerFrameFileDealerPane.getInstance().stateChange();
} }

2
designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java

@ -68,7 +68,7 @@ public class SwitchExistEnv extends MenuDef {
EnvChangeEntrance.getInstance().chooseEnv(envName); EnvChangeEntrance.getInstance().chooseEnv(envName);
} else { } else {
SaveSomeTemplatePane saveSomeTemplatePane = new SaveSomeTemplatePane(true); SaveSomeTemplatePane saveSomeTemplatePane = new SaveSomeTemplatePane(true);
if (saveSomeTemplatePane.showSavePane()) { if (saveSomeTemplatePane.showSavePane(true)) {
// 用户模板保存后,才进行切换目录操作 // 用户模板保存后,才进行切换目录操作
EnvChangeEntrance.getInstance().switch2Env(envName); EnvChangeEntrance.getInstance().switch2Env(envName);
} }

43
designer-base/src/main/java/com/fr/design/file/CloseOption.java

@ -0,0 +1,43 @@
package com.fr.design.file;
import com.fr.design.i18n.Toolkit;
public enum CloseOption {
Left(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Left")) {
@Override
public boolean shouldClose(int tplIndex, int i) {
return i < tplIndex;
}
},
Right(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Right")) {
@Override
public boolean shouldClose(int tplIndex, int i) {
return i > tplIndex;
}
}, All(Toolkit.i18nText("Fine-Design_Close_All_templates")),
Others(Toolkit.i18nText("Fine-Design_Close_Other_templates")) {
@Override
public boolean shouldClose(int tplIndex, int i) {
return i != tplIndex;
}
};
private String optionName;
public String getOptionName() {
return this.optionName;
}
CloseOption(String optionName) {
this.optionName = optionName;
}
public boolean shouldClose(int tplIndex, int i) {
return true;
}
}

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

@ -75,7 +75,7 @@ public class HistoryTemplateListCache implements CallbackEvent {
historyList.remove(contains(selected)); historyList.remove(contains(selected));
selected.getEditingFILE().closeTemplate(); selected.getEditingFILE().closeTemplate();
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName())); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName()));
MultiTemplateTabPane.getInstance().refreshOpenedTemplate(historyList); TemplateTabManager.getInstance().refreshOpenedTemplate(historyList);
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
@ -134,10 +134,10 @@ public class HistoryTemplateListCache implements CallbackEvent {
if (contains(jt) == -1) { if (contains(jt) == -1) {
addHistory(); addHistory();
} }
MultiTemplateTabPane.getInstance().refreshOpenedTemplate(historyList); TemplateTabManager.getInstance().refreshOpenedTemplate(historyList);
//设置tab栏为当前选中的那一栏 //设置tab栏为当前选中的那一栏
if (editingTemplate != null) { if (editingTemplate != null) {
MultiTemplateTabPane.getInstance().setSelectedIndex(contains(jt)); TemplateTabManager.getInstance().resetSelectIndex(jt);
} }
} }
@ -268,13 +268,14 @@ public class HistoryTemplateListCache implements CallbackEvent {
boolean replaceWithJVirtualTemplate = overTemplate.getEditingFILE().exists() boolean replaceWithJVirtualTemplate = overTemplate.getEditingFILE().exists()
&& overTemplate.isALLSaved() && overTemplate.isALLSaved()
&& overTemplate != editingTemplate && overTemplate != editingTemplate
&& overTemplate.checkEnable(); && overTemplate.checkEnable()
&& overTemplate.supportCache();
if (replaceWithJVirtualTemplate) { if (replaceWithJVirtualTemplate) {
closeVirtualSelectedReport(overTemplate); closeVirtualSelectedReport(overTemplate);
historyList.set(i, new JVirtualTemplate(overTemplate.getEditingFILE())); historyList.set(i, new JVirtualTemplate(overTemplate.getEditingFILE()));
} }
} }
MultiTemplateTabPane.getInstance().refreshOpenedTemplate(historyList); TemplateTabManager.getInstance().refreshOpenedTemplate(historyList);
} }
@ -285,35 +286,27 @@ public class HistoryTemplateListCache implements CallbackEvent {
// path like reportlets/xx/xxx/xxx // path like reportlets/xx/xxx/xxx
String path = file.getPath() + suffix; String path = file.getPath() + suffix;
List list = new ArrayList();
ListIterator<JTemplate<?, ?>> iterator = historyList.listIterator(); for(JTemplate jTemplate : historyList){
list.add(jTemplate);
}
ListIterator<JTemplate<?, ?>> iterator = list.listIterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
JTemplate<?, ?> template = iterator.next(); JTemplate<?, ?> template = iterator.next();
String tPath = template.getPath(); String tPath = template.getPath();
if (isDir ? tPath.startsWith(path) : tPath.equals(path)) { if (isDir ? tPath.startsWith(path) : tPath.equals(path)) {
int size = getHistoryCount(); historyList.remove(template);
iterator.remove(); TemplateTabManager.getInstance().deleteOpenedTemplate(template);
int index = iterator.nextIndex();
if (size == index + 1 && index > 0) {
//如果删除的是后一个Tab,则定位到前一个
MultiTemplateTabPane.getInstance().setSelectedIndex(index - 1);
}
} }
} }
//如果打开过,则删除,实时刷新多tab面板
int openFileCount = getHistoryCount();
if (openFileCount == 0) {
DesignerContext.getDesignerFrame().addAndActivateJTemplate();
}
JTemplate selectedFile = MultiTemplateTabPane.getInstance().getSelectedFile(); JTemplate selectedFile = TemplateTabManager.getInstance().getSelectedFile();
if (!isCurrentEditingFile(selectedFile.getPath())) { if (!isCurrentEditingFile(selectedFile.getPath())) {
//如果此时面板上的实时刷新的selectedIndex得到的和历史的不一样 //如果此时面板上的实时刷新的selectedIndex得到的和历史的不一样
DesignerContext.getDesignerFrame().activateJTemplate(selectedFile); DesignerContext.getDesignerFrame().activateJTemplate(selectedFile);
} }
MultiTemplateTabPane.getInstance().repaint(); TemplateTabManager.getInstance().refresh();
} }
@ -474,7 +467,7 @@ public class HistoryTemplateListCache implements CallbackEvent {
int index = contains(this.editingTemplate); int index = contains(this.editingTemplate);
this.editingTemplate = jt; this.editingTemplate = jt;
historyList.set(index, jt); historyList.set(index, jt);
MultiTemplateTabPane.getInstance().refreshOpenedTemplate(historyList); TemplateTabManager.getInstance().refreshOpenedTemplate(historyList);
MultiTemplateTabPane.getInstance().setSelectedIndex(contains(jt)); TemplateTabManager.getInstance().resetSelectIndex(jt);
} }
} }

346
designer-base/src/main/java/com/fr/design/file/MultiTemplateTabMenuFactory.java

@ -0,0 +1,346 @@
package com.fr.design.file;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.imenu.UIScrollPopUpMenu;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.utils.TemplateUtils;
import com.fr.file.FILE;
import com.fr.general.IOUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.collections.CollectionUtils;
import com.fr.third.javax.annotation.Nonnull;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Carlson
* @version 11.0
* @description
**/
public class MultiTemplateTabMenuFactory {
private static final Icon CLOSE = IOUtils.readIcon("/com/fr/design/images/buttonicon/close_icon.png");
private static final Icon MOUSE_OVER_CLOSE = IOUtils.readIcon("/com/fr/design/images/buttonicon/mouseoverclose icon.png");
private static final Icon MOUSE_PRESS_CLOSE = IOUtils.readIcon("/com/fr/design/images/buttonicon/pressclose icon.png");
private static final int ITEM_SIZE = 25;
private UIScrollPopUpMenu menu = null;
private static MultiTemplateTabMenuFactory INSTANCE = new MultiTemplateTabMenuFactory();
private MultiTemplateTabMenuFactory() {
}
public static MultiTemplateTabMenuFactory getInstance() {
return INSTANCE;
}
/**
* tab上的下拉菜单
*/
public UIScrollPopUpMenu createMenu() {
menu = new UIScrollPopUpMenu();
menu.setBorder(BorderFactory.createEmptyBorder(-3, 3, 3, 0));
menu.add(initCloseOther());
menu.add(createEmptyRow());
menu.addSeparator();
menu.add(createEmptyRow());
menu.add(createCategory(Toolkit.i18nText("Fine-Design_Basic_Tab_Current_Category_Templates")));
Component[] items = createCurrentCategory();
for (Component item : items) {
menu.add(item);
}
items = createOtherCategory();
if (items.length > 0) {
menu.addSeparator();
menu.add(createEmptyRow());
menu.add(createCategory(Toolkit.i18nText("Fine-Design_Basic_Tab_Other_Category_Templates")));
for (Component item : items) {
menu.add(item);
}
}
Dimension dimension = menu.getPreferredSize();
dimension.width += ITEM_SIZE;
menu.setPreferredSize(dimension);
return menu;
}
/**
* 关闭其它按钮
*/
private UIMenuItem initCloseOther() {
UIMenuItem closeOther = new UIMenuItem(Toolkit.i18nText("Fine-Design_Basic_Tab_Close_Other_Templates_Of_Current_Category"));
closeOther.setHorizontalAlignment(SwingConstants.CENTER);
Dimension dimension = closeOther.getPreferredSize();
dimension.height = ITEM_SIZE;
closeOther.setPreferredSize(dimension);
closeOther.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TemplateTabManager.getInstance().closeOthers();
}
});
if (TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size() <= 1) {
closeOther.setEnabled(false);
}
return closeOther;
}
private void closeAndFreeLock(@Nonnull JTemplate<?, ?> template) {
FILE file = template.getEditingFILE();
// 只有是环境内的文件,才执行释放锁
if (file != null && file.isEnvFile()) {
// release lock
TemplateResourceManager.getResource().closeTemplate(file.getPath());
}
}
/**
* 美观用
*/
private JPanel createEmptyRow() {
return new JPanel() {
@Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.height = 1;
return d;
}
};
}
/**
* 模板分类item
*/
private UIButton createCategory(String categoryName) {
UIButton button = new UIButton(categoryName);
button.setBorderPainted(false);
button.setExtraPainted(false);
button.setPreferredSize(new Dimension(menu.getWidth(), ITEM_SIZE));
button.setOpaque(true);
button.setBackground(UIConstants.NORMAL_BACKGROUND);
button.setHorizontalAlignment(SwingConstants.LEFT);
button.setForeground(UIConstants.FLESH_BLUE);
return button;
}
/**
* 创建 当前分类模板 item数组
*/
private Component[] createCurrentCategory() {
return createListDownItem(TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates());
}
/**
* 创建 其它分类模板 item数组
*/
private Component[] createOtherCategory() {
List<JTemplate<?, ?>> openedTemplates = new ArrayList<>();
Map<String, List<JTemplate<?, ?>>> map = TemplateTabManager.getInstance().getAllOpenedTemplateMap();
for (Map.Entry<String, List<JTemplate<?, ?>>> entry : map.entrySet()) {
if (!StringUtils.equals(TemplateTabManager.getInstance().getCurrentOperator().getOperatorType(), entry.getKey())) {
openedTemplates.addAll(entry.getValue());
}
}
return createListDownItem(openedTemplates);
}
/**
* 根据template列表创建多个item
*/
private Component[] createListDownItem(List<JTemplate<?, ?>> openedTemplates) {
if (!CollectionUtils.isEmpty(openedTemplates)) {
Component[] templates = new Component[openedTemplates.size()];
for (int i = 0; i < openedTemplates.size(); i++) {
templates[i] = createListDownMenuItem(openedTemplates.get(i));
}
return templates;
}
return new Component[0];
}
/**
* 根据template对象创建item
*/
private Component createListDownMenuItem(JTemplate<?, ?> template) {
JPanel jPanel = new JPanel();
jPanel.setPreferredSize(new Dimension(menu.getWidth(), ITEM_SIZE));
jPanel.setLayout(new BorderLayout());
MenuItemButtonGroup menuItemButtonGroup = new MenuItemButtonGroup(template);
if (template == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()) {
menuItemButtonGroup.templateButton.setForeground(UIConstants.FLESH_BLUE);
}
jPanel.add(menuItemButtonGroup.iconButton, BorderLayout.WEST);
jPanel.add(menuItemButtonGroup.templateButton, BorderLayout.CENTER);
jPanel.add(menuItemButtonGroup.closeButton, BorderLayout.EAST);
return jPanel;
}
/**
* menu的item由模板图标模板名模板关闭按钮组成
*/
private class MenuItemButtonGroup {
private final UIButton iconButton;
private final UIButton templateButton;
private final UIButton closeButton;
public MenuItemButtonGroup(JTemplate<?, ?> template) {
iconButton = createIconButton(template);
templateButton = createTemplateButton(template);
closeButton = createCloseButton();
initListener(template);
}
/**
* item[0] 模板图标按钮初始化
*/
private UIButton createIconButton(JTemplate<?, ?> template) {
UIButton button = new UIButton(template.getIcon(), template.getIcon(), template.getIcon());
button.setPreferredSize(new Dimension(ITEM_SIZE, ITEM_SIZE));
button.setOpaque(true);
button.setBackground(UIConstants.NORMAL_BACKGROUND);
return button;
}
/**
* item[1] 切换模板按钮初始化
*/
private UIButton createTemplateButton(JTemplate<?, ?> template) {
UIButton button = new UIButton(TemplateUtils.createLockeTemplatedName(template, template.getTemplateName()));
button.setBorderPainted(false);
button.setExtraPainted(false);
button.setPreferredSize(new Dimension(menu.getWidth() - ITEM_SIZE * 2, ITEM_SIZE));
button.setOpaque(true);
button.setBackground(UIConstants.NORMAL_BACKGROUND);
button.setHorizontalAlignment(SwingConstants.LEFT);
return button;
}
/**
* item[2] 关闭模板图标按钮初始化
*/
private UIButton createCloseButton() {
UIButton button = new UIButton(CLOSE, MOUSE_OVER_CLOSE, MOUSE_PRESS_CLOSE);
button.setPreferredSize(new Dimension(ITEM_SIZE, ITEM_SIZE));
button.setOpaque(true);
button.setBackground(UIConstants.NORMAL_BACKGROUND);
button.setVisible(false);
return button;
}
private void initListener(JTemplate<?, ?> template) {
initIconButtonListener();
initTemplateButtonListener(template);
initCloseButtonListener(template);
}
/**
* item[0] 模板图标按钮鼠标事件
*/
private void initIconButtonListener() {
iconButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
fireMouseEnteredEvent();
}
@Override
public void mouseExited(MouseEvent e) {
fireMouseExitedEvent();
}
});
}
/**
* item[1] 切换模板按钮鼠标事件
*/
private void initTemplateButtonListener(JTemplate<?, ?> template) {
templateButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
menu.setVisible(false);
TemplateTabManager.getInstance().switchByJTemplate(template);
}
@Override
public void mouseEntered(MouseEvent e) {
fireMouseEnteredEvent();
}
@Override
public void mouseExited(MouseEvent e) {
fireMouseExitedEvent();
}
});
}
/**
* item[2] 关闭模板按钮鼠标事件
*/
private void initCloseButtonListener(JTemplate<?, ?> template) {
closeButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
menu.setVisible(false);
TemplateTabManager.getInstance().closeByJTemplate(template);
}
@Override
public void mouseEntered(MouseEvent e) {
fireMouseEnteredEvent();
}
@Override
public void mouseExited(MouseEvent e) {
fireMouseExitedEvent();
}
});
}
/**
* mouse移入item范围
*/
private void fireMouseEnteredEvent() {
iconButton.setBackground(UIConstants.HOVER_BLUE);
templateButton.setBackground(UIConstants.HOVER_BLUE);
closeButton.setBackground(UIConstants.HOVER_BLUE);
closeButton.setVisible(true);
}
/**
* mouse移出item范围
*/
private void fireMouseExitedEvent() {
iconButton.setBackground(UIConstants.NORMAL_BACKGROUND);
templateButton.setBackground(UIConstants.NORMAL_BACKGROUND);
closeButton.setBackground(UIConstants.NORMAL_BACKGROUND);
closeButton.setVisible(false);
}
}
}

486
designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java

@ -1,38 +1,28 @@
package com.fr.design.file; package com.fr.design.file;
import com.fr.base.BaseUtils;
import com.fr.base.GraphHelper; import com.fr.base.GraphHelper;
import com.fr.base.svg.IconUtils; import com.fr.base.svg.IconUtils;
import com.fr.base.vcs.DesignerMode; import com.fr.base.vcs.DesignerMode;
import com.fr.design.actions.UpdateAction; import com.fr.design.actions.UpdateAction;
import com.fr.design.actions.file.LocateAction; import com.fr.design.actions.file.LocateAction;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.gui.imenu.UIPopupMenu;
import com.fr.design.gui.imenu.UIScrollPopUpMenu; import com.fr.design.gui.imenu.UIScrollPopUpMenu;
import com.fr.design.i18n.DesignSizeI18nManager; import com.fr.design.i18n.DesignSizeI18nManager;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.TemplateSavingChecker; import com.fr.design.mainframe.TemplateSavingChecker;
import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager;
import com.fr.design.utils.DesignUtils; import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.TemplateUtils; import com.fr.design.utils.TemplateUtils;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.design.worker.WorkerManager;
import com.fr.design.worker.save.CallbackSaveWorker;
import com.fr.file.FILE; import com.fr.file.FILE;
import com.fr.file.FileNodeFILE;
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.stable.Constants; import com.fr.stable.Constants;
import com.fr.third.javax.annotation.Nonnull; import com.fr.third.javax.annotation.Nonnull;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.lock.TplOperator;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ButtonModel; import javax.swing.ButtonModel;
@ -41,7 +31,6 @@ import javax.swing.ImageIcon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JSeparator; import javax.swing.JSeparator;
import javax.swing.MenuElement; import javax.swing.MenuElement;
@ -69,12 +58,6 @@ import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import java.util.List;
import static com.fr.design.dialog.FineJOptionPane.showConfirmDialog;
import static javax.swing.JOptionPane.OK_CANCEL_OPTION;
import static javax.swing.JOptionPane.OK_OPTION;
import static javax.swing.JOptionPane.WARNING_MESSAGE;
/** /**
* 改个名字一个拼写 n 个错误 * 改个名字一个拼写 n 个错误
@ -114,10 +97,6 @@ public class MultiTemplateTabPane extends JComponent {
private static MultiTemplateTabPane THIS; private static MultiTemplateTabPane THIS;
//用于存放工作簿
private java.util.List<JTemplate<?, ?>> openedTemplate;
//选中的Tab项
private int selectedIndex = 0;
// //
private int mouseOveredIndex = -1; private int mouseOveredIndex = -1;
@ -136,16 +115,11 @@ public class MultiTemplateTabPane extends JComponent {
//记录关闭按钮的状态 //记录关闭按钮的状态
private int closeIconIndex = -1; private int closeIconIndex = -1;
private boolean isCloseCurrent = false;
private Icon clodeMode = CLOSE; private Icon clodeMode = CLOSE;
private Icon listDownMode = LIST_DOWN; private Icon listDownMode = LIST_DOWN;
private boolean isShowList = false; private boolean isShowList = false;
//自动新建的模板B若没有进行任何编辑,切换到其他
//
// 模板时,模板B会自动关闭
private JTemplate<?, ?> temTemplate = null;
public static MultiTemplateTabPane getInstance() { public static MultiTemplateTabPane getInstance() {
if (THIS == null) { if (THIS == null) {
@ -165,8 +139,6 @@ public class MultiTemplateTabPane extends JComponent {
this.setBorder(null); this.setBorder(null);
this.setForeground(new Color(58, 56, 58)); this.setForeground(new Color(58, 56, 58));
this.setFont(DesignUtils.getDefaultGUIFont().applySize(12)); this.setFont(DesignUtils.getDefaultGUIFont().applySize(12));
openedTemplate = HistoryTemplateListCache.getInstance().getHistoryList();
selectedIndex = openedTemplate.size() - 1;
AWTEventListener awt = new AWTEventListener() { AWTEventListener awt = new AWTEventListener() {
@Override @Override
public void eventDispatched(AWTEvent event) { public void eventDispatched(AWTEvent event) {
@ -206,45 +178,13 @@ public class MultiTemplateTabPane extends JComponent {
//根据当前i18n语言环境,动态调整popupMenu的宽度 //根据当前i18n语言环境,动态调整popupMenu的宽度
menu.setPreferredSize(new Dimension((int) DesignSizeI18nManager.getInstance(). menu.setPreferredSize(new Dimension((int) DesignSizeI18nManager.getInstance().
i18nDimension("com.fr.design.file.MultiTemplateTabPane.popUpMenu").getWidth(), height)); i18nDimension("com.fr.design.file.MultiTemplateTabPane.popUpMenu").getWidth(), height));
GUICoreUtils.showPopupMenu(menu, MultiTemplateTabPane.getInstance(), e.getX(), MultiTemplateTabPane.getInstance().getY() - 1 + MultiTemplateTabPane.getInstance().getHeight()); GUICoreUtils.showPopupMenu(menu, MultiTemplateTabPane.this, e.getX(), MultiTemplateTabPane.this.getY() - 1 + MultiTemplateTabPane.this.getHeight());
} }
} }
} }
}); });
} }
enum CloseOption {
Left(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Left")) {
@Override
boolean shouldClose(int tplIndex, int i) {
return i < tplIndex;
}
},
Right(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Right")) {
@Override
boolean shouldClose(int tplIndex, int i) {
return i > tplIndex;
}
},
All(Toolkit.i18nText("Fine-Design_Close_All_templates")),
Others(Toolkit.i18nText("Fine-Design_Close_Other_templates")) {
@Override
boolean shouldClose(int tplIndex, int i) {
return i != tplIndex;
}
};
String optionName;
CloseOption(String optionName) {
this.optionName = optionName;
}
boolean shouldClose(int tplIndex, int i) {
return true;
}
}
private static class CloseMenuItemJSeparator extends JSeparator { private static class CloseMenuItemJSeparator extends JSeparator {
@Override @Override
@ -272,41 +212,10 @@ public class MultiTemplateTabPane extends JComponent {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
//处于搜索模式时,先退出搜索模式,再定位 //DefaultTemplateTabOperate.getInstance().locateTemplateInTree(this.tplIndex);
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) { TemplateTabManager.getInstance().getCurrentOperator().locateTemplateInTree(this.tplIndex);
TemplateTreeSearchManager.getInstance().outOfSearchMode();
TemplateTreePane.getInstance().refreshDockingView();
}
JTemplate<?, ?> template = openedTemplate.get(this.tplIndex);
locateTemplate(template);
} }
private void locateTemplate(JTemplate<?, ?> template) {
FILE currentTemplate = template.getEditingFILE();
//模板不属于当前环境,跟预览一样先提示保存,再定位模板
//如果是拖拽进来的模板单单用exist不能判断,这边参考预览的判断逻辑(browserTemplate),补充一下
if (!currentTemplate.exists() || !(currentTemplate instanceof FileNodeFILE)) {
int selVal = showConfirmDialog(
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Web_Preview_Message"),
Toolkit.i18nText("Fine-Design_Basic_Preview_Tool_Tips"),
OK_CANCEL_OPTION,
WARNING_MESSAGE
);
if (OK_OPTION == selVal) {
CallbackSaveWorker worker = template.saveAs();
worker.start(template.getRuntimeId());
worker.addSuccessCallback(new Runnable() {
@Override
public void run() {
gotoEditingTemplateLeaf(template.getPath());
}
});
}
} else {
gotoEditingTemplateLeaf(template.getPath());
}
}
} }
private class RightMenuCloseAction extends UpdateAction { private class RightMenuCloseAction extends UpdateAction {
@ -316,80 +225,15 @@ public class MultiTemplateTabPane extends JComponent {
public RightMenuCloseAction(CloseOption option, int tplIndex) { public RightMenuCloseAction(CloseOption option, int tplIndex) {
this.option = option; this.option = option;
this.setName(option.optionName); this.setName(option.getOptionName());
this.tplIndex = tplIndex; this.tplIndex = tplIndex;
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false); TemplateTabManager.getInstance().getCurrentOperator().closeAction(option, this.tplIndex);
if (saveSomeTempaltePane.showSavePane()) { MultiTemplateTabPane.this.repaint();
JTemplate<?, ?>[] templates = new JTemplate<?, ?>[openedTemplate.size()];
for (int i = 0; i < openedTemplate.size(); i++) {
templates[i] = openedTemplate.get(i);
}
JTemplate<?, ?> currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
closeTemplate(templates, currentTemplate);
if (option == CloseOption.All) {
DesignerContext.getDesignerFrame().addAndActivateJTemplate();
} else {
DesignerContext.getDesignerFrame().activateJTemplate(currentTemplate);
}
MultiTemplateTabPane.getInstance().repaint();
}
}
private void closeTemplate(JTemplate<?, ?>[] templates, JTemplate<?, ?> currentTemplate) {
for (int i = 0; i < templates.length; i++) {
if (option.shouldClose(tplIndex, i)) {
JTemplate<?, ?> jTemplate = templates[i];
if (jTemplate == currentTemplate) {
currentTemplate = option == CloseOption.All ? null : templates[tplIndex];
}
//判断关闭的模板是不是格式刷的被参照的模板
openedTemplate.remove(jTemplate);
if (jTemplate != currentTemplate) {
MultiTemplateTabPane.getInstance().closeFormat(jTemplate);
HistoryTemplateListCache.getInstance().closeSelectedReport(jTemplate);
closeAndFreeLock(jTemplate);
}
}
}
}
private void closeAndFreeLock(@Nonnull JTemplate<?, ?> template) {
FILE file = template.getEditingFILE();
// 只有是环境内的文件,才执行释放锁
if (file != null && file.isEnvFile()) {
// release lock
WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath());
}
}
}
public JTemplate getSelectedFile() {
if (openedTemplate.size() == selectedIndex) {
selectedIndex = Math.max(--selectedIndex, 0);
}
return openedTemplate.get(selectedIndex);
}
/**
* 关闭掉当前已打开文件列表中指定的文件
*
* @param file 指定的文件
*/
public void closeFileTemplate(FILE file) {
for (JTemplate<?, ?> temp : openedTemplate) {
if (ComparatorUtils.equals(file, temp.getEditingFILE())) {
closeSpecifiedTemplate(temp);
break;
}
} }
} }
@ -409,7 +253,9 @@ public class MultiTemplateTabPane extends JComponent {
closeOther.addActionListener(new ActionListener() { closeOther.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (openedTemplate.size() == 1) { //int tabSize = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size();
int tabSize = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size();
if (tabSize == 1) {
return; return;
} }
if (!TemplateSavingChecker.check()) { if (!TemplateSavingChecker.check()) {
@ -418,29 +264,28 @@ public class MultiTemplateTabPane extends JComponent {
SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false); SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false);
//点击关闭其他模板,并且点击确定保存 //点击关闭其他模板,并且点击确定保存
if (saveSomeTempaltePane.showSavePane()) { if (saveSomeTempaltePane.showSavePane()) {
JTemplate<?, ?>[] panes = new JTemplate<?, ?>[openedTemplate.size()]; JTemplate<?, ?>[] panes = new JTemplate<?, ?>[tabSize];
for (int i = 0; i < openedTemplate.size(); i++) { for (int i = 0; i < tabSize; i++) {
panes[i] = openedTemplate.get(i); panes[i] = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().get(i);
} }
for (int i = 0; i < panes.length; i++) { for (int i = 0; i < panes.length; i++) {
if (i != selectedIndex) { if (i != TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex()) {
JTemplate<?, ?> jTemplate = panes[i]; JTemplate<?, ?> jTemplate = panes[i];
//判断关闭的模板是不是格式刷的被参照的模板 //判断关闭的模板是不是格式刷的被参照的模板
openedTemplate.remove(jTemplate); TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().remove(jTemplate);
closeFormat(jTemplate); TemplateTabManager.getInstance().closeFormat(jTemplate);
HistoryTemplateListCache.getInstance().closeSelectedReport(jTemplate); HistoryTemplateListCache.getInstance().closeSelectedReport(jTemplate);
closeAndFreeLock(jTemplate); closeAndFreeLock(jTemplate);
} }
} }
JTemplate<?, ?> currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); JTemplate<?, ?> currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
HistoryTemplateListCache.getInstance().removeAllHistory(); TemplateTabManager.getInstance().resetSelectIndex(currentTemplate);
DesignerContext.getDesignerFrame().activateJTemplate(currentTemplate);
THIS.repaint(); THIS.repaint();
} }
//如果取消保存了,则不关闭其他模板 //如果取消保存了,则不关闭其他模板
} }
}); });
if (openedTemplate.size() == 1) { if (TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size() == 1) {
closeOther.setEnabled(false); closeOther.setEnabled(false);
} }
return closeOther; return closeOther;
@ -448,21 +293,22 @@ public class MultiTemplateTabPane extends JComponent {
private UIMenuItem[] createListDownTemplate() { private UIMenuItem[] createListDownTemplate() {
UIMenuItem[] templates = new UIMenuItem[openedTemplate.size()]; int templateTabCount = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size();
for (int i = 0; i < openedTemplate.size(); i++) { UIMenuItem[] templates = new UIMenuItem[templateTabCount];
for (int i = 0; i < templateTabCount; i++) {
final int index = i; final int index = i;
final JTemplate tem = openedTemplate.get(i); final JTemplate tem = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().get(i);
templates[i] = new UIMenuItem(tempalteShowName(tem), tem.getIcon()); templates[i] = new UIMenuItem(tempalteShowName(tem), tem.getIcon());
templates[i].setUI(new UIListDownItemUI()); templates[i].setUI(new UIListDownItemUI());
setListDownItemPreferredSize(templates[i]); setListDownItemPreferredSize(templates[i]);
if (i == selectedIndex) { if (i == TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex()) {
//画选中的高亮 //画选中的高亮
templates[i].setBackground(UIConstants.SHADOW_CENTER); templates[i].setBackground(UIConstants.SHADOW_CENTER);
} }
templates[i].addActionListener(new ActionListener() { templates[i].addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
selectedIndex = index; TemplateTabManager.getInstance().getCurrentOperator().setSelectIndex(index);
tem.activeNewJTemplate(); tem.activeNewJTemplate();
} }
}); });
@ -478,68 +324,13 @@ public class MultiTemplateTabPane extends JComponent {
private String tempalteShowName(JTemplate<?, ?> template) { private String tempalteShowName(JTemplate<?, ?> template) {
String name = TemplateUtils.createLockeTemplatedName(template, template.getTemplateName()); return TemplateTabManager.getInstance().getTemplateShowName(template);
if (!template.isSaved() && !name.endsWith(" *")) {
name += " *";
}
return name;
}
/**
* 刷新打开模板
*
* @param history 模板
*/
public void refreshOpenedTemplate(List<JTemplate<?, ?>> history) {
openedTemplate = history;
}
public void setTemTemplate(JTemplate<?, ?> auotCreate) {
temTemplate = auotCreate;
} }
private void showListDown() { private void showListDown() {
UIScrollPopUpMenu menu = MultiTemplateTabMenuFactory.getInstance().createMenu();
UIScrollPopUpMenu menu = new UIScrollPopUpMenu(); GUICoreUtils.showPopupMenu(menu, MultiTemplateTabPane.this, MultiTemplateTabPane.this.getWidth() - menu.getPreferredSize().width, getY() - 1 + getHeight());
menu.setBorder(BorderFactory.createEmptyBorder(-3, 3, 3, 0));
menu.add(initCloseOther());
JSeparator separator = new JSeparator() {
@Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.height = 1;
return d;
}
};
menu.add(new JPanel() {
@Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.height = 1;
return d;
}
});
separator.setForeground(UIConstants.LINE_COLOR);
menu.add(separator);
menu.add(new JPanel() {
@Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.height = 1;
return d;
}
});
UIMenuItem[] items = createListDownTemplate();
for (int i = 0; i < items.length; i++) {
menu.add(items[i]);
}
GUICoreUtils.showPopupMenu(menu, MultiTemplateTabPane.getInstance(), MultiTemplateTabPane.getInstance().getWidth() - menu.getPreferredSize().width, getY() - 1 + getHeight());
}
public void setSelectedIndex(int index) {
selectedIndex = index;
} }
@ -566,15 +357,18 @@ public class MultiTemplateTabPane extends JComponent {
paintDefaultBackground(g2d); paintDefaultBackground(g2d);
//最多能画的个数 //最多能画的个数
int maxTemplateNum = (int) (maxWidth) / MINWIDTH; int maxTemplateNum = (int) (maxWidth) / MINWIDTH;
int templateTabCount = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size();
int currentSelectedIndex = TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex();
//计算开始画的最小模板index和最大模板index //计算开始画的最小模板index和最大模板index
calMinAndMaxIndex(maxTemplateNum); calMinAndMaxIndex(maxTemplateNum);
calculateRealAverageWidth(maxWidth, maxTemplateNum); calculateRealAverageWidth(maxWidth, maxTemplateNum);
int maxStringlength = calculateStringMaxLength(); int maxStringlength = calculateStringMaxLength();
if (selectedIndex >= openedTemplate.size()) { if ( currentSelectedIndex >= templateTabCount) {
selectedIndex = openedTemplate.size() - 1; TemplateTabManager.getInstance().getCurrentOperator().setSelectIndex(
templateTabCount - 1);
} }
if (selectedIndex < 0) { if (TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex() < 0) {
selectedIndex = 0; TemplateTabManager.getInstance().getCurrentOperator().setSelectIndex(0);
} }
double templateStartX = 0; double templateStartX = 0;
startX = new int[maxPaintIndex - minPaintIndex + 1]; startX = new int[maxPaintIndex - minPaintIndex + 1];
@ -582,7 +376,7 @@ public class MultiTemplateTabPane extends JComponent {
//从可以开始展示在tab面板上的tab开始画 //从可以开始展示在tab面板上的tab开始画
for (int i = minPaintIndex; i <= maxPaintIndex; i++) { for (int i = minPaintIndex; i <= maxPaintIndex; i++) {
JTemplate template = openedTemplate.get(i); JTemplate template = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().get(i);
Icon icon = template.getIcon(); Icon icon = template.getIcon();
String name = tempalteShowName(template); String name = tempalteShowName(template);
//如果tab名字的长度大于最大能显示的英文字符长度,则进行省略号处理 //如果tab名字的长度大于最大能显示的英文字符长度,则进行省略号处理
@ -599,7 +393,7 @@ public class MultiTemplateTabPane extends JComponent {
} else { } else {
selectedIcon = CLOSE; selectedIcon = CLOSE;
} }
if (i == selectedIndex) { if (i == TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex()) {
if (template.isSaving()) { if (template.isSaving()) {
selectedIcon = WHITE_SAVING_CLOSE_ICON; selectedIcon = WHITE_SAVING_CLOSE_ICON;
} }
@ -608,7 +402,7 @@ public class MultiTemplateTabPane extends JComponent {
if (template.isSaving()) { if (template.isSaving()) {
selectedIcon = GREY_SAVING_CLOSE_ICON; selectedIcon = GREY_SAVING_CLOSE_ICON;
} }
boolean isLeft = i < selectedIndex; boolean isLeft = i < TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex();
startX[i - minPaintIndex] = paintUnSelectedTab(g2d, icon, templateStartX, name, selectedIcon, isLeft, mouseOveredIndex, i); startX[i - minPaintIndex] = paintUnSelectedTab(g2d, icon, templateStartX, name, selectedIcon, isLeft, mouseOveredIndex, i);
} }
templateStartX += realWidth; templateStartX += realWidth;
@ -684,38 +478,39 @@ public class MultiTemplateTabPane extends JComponent {
} }
private void calMinAndMaxIndex(int maxTemplateNum) { private void calMinAndMaxIndex(int maxTemplateNum) {
int templateTabCount = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size();
//如果个数大于最多能容纳的个数,则多余的进行处理 //如果个数大于最多能容纳的个数,则多余的进行处理
if (openedTemplate.size() > maxTemplateNum) { if (templateTabCount > maxTemplateNum) {
//所点击列表中的标签页处在标签页栏最后一个标签页之后,则标签页栏左移至所点击标签页出现 //所点击列表中的标签页处在标签页栏最后一个标签页之后,则标签页栏左移至所点击标签页出现
if (selectedIndex >= maxPaintIndex) { if (TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex() >= maxPaintIndex) {
minPaintIndex = selectedIndex - maxTemplateNum + 1; minPaintIndex = TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex() - maxTemplateNum + 1;
maxPaintIndex = selectedIndex; maxPaintIndex = TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex();
if (minPaintIndex <= 0) { if (minPaintIndex <= 0) {
minPaintIndex = 0; minPaintIndex = 0;
maxPaintIndex = maxTemplateNum - 1; maxPaintIndex = maxTemplateNum - 1;
} }
} else if (selectedIndex <= minPaintIndex) { } else if (TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex() <= minPaintIndex) {
//所点击列表中的标签页处在标签页栏第一个标签页之前,则标签页栏右移至所点击标签页出现 //所点击列表中的标签页处在标签页栏第一个标签页之前,则标签页栏右移至所点击标签页出现
minPaintIndex = selectedIndex; minPaintIndex = TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex();
maxPaintIndex = minPaintIndex + maxTemplateNum - 1; maxPaintIndex = minPaintIndex + maxTemplateNum - 1;
if (maxPaintIndex > openedTemplate.size() - 1) { if (maxPaintIndex > templateTabCount- 1) {
maxPaintIndex = openedTemplate.size() - 1; maxPaintIndex = templateTabCount - 1;
} }
} else { } else {
if (selectedIndex >= openedTemplate.size() - 1) { if (TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex() >= templateTabCount - 1) {
selectedIndex = openedTemplate.size() - 1; TemplateTabManager.getInstance().getCurrentOperator().setSelectIndex(templateTabCount - 1);
maxPaintIndex = selectedIndex; maxPaintIndex = TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex();
minPaintIndex = selectedIndex - maxTemplateNum + 1; minPaintIndex = TemplateTabManager.getInstance().getCurrentOperator().getSelectIndex() - maxTemplateNum + 1;
} else { } else {
maxPaintIndex = minPaintIndex + maxTemplateNum - 1; maxPaintIndex = minPaintIndex + maxTemplateNum - 1;
if (maxPaintIndex > openedTemplate.size() - 1) { if (maxPaintIndex > templateTabCount - 1) {
maxPaintIndex = openedTemplate.size() - 1; maxPaintIndex = templateTabCount - 1;
} }
} }
} }
} else { } else {
minPaintIndex = 0; minPaintIndex = 0;
maxPaintIndex = openedTemplate.size() - 1; maxPaintIndex = templateTabCount - 1;
} }
} }
@ -723,7 +518,7 @@ public class MultiTemplateTabPane extends JComponent {
//个数小于最多能容纳的个数的情况下,看看宽度每个要画多少 //个数小于最多能容纳的个数的情况下,看看宽度每个要画多少
private void calculateRealAverageWidth(double maxwidth, int templateNum) { private void calculateRealAverageWidth(double maxwidth, int templateNum) {
int num = openedTemplate.size() > templateNum ? templateNum : openedTemplate.size(); int num = TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size() > templateNum ? templateNum : TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().size();
realWidth = (int) (maxwidth / (num)); realWidth = (int) (maxwidth / (num));
if (realWidth > MAXWIDTH) { if (realWidth > MAXWIDTH) {
realWidth = MAXWIDTH; realWidth = MAXWIDTH;
@ -888,50 +683,6 @@ public class MultiTemplateTabPane extends JComponent {
} }
public void setIsCloseCurrent(boolean isCloseCurrent) {
this.isCloseCurrent = isCloseCurrent;
}
/**
* 关闭模板
*
* @param specifiedTemplate 模板
*/
public void closeSpecifiedTemplate(JTemplate<?, ?> specifiedTemplate) {
if (specifiedTemplate == null) {
return;
}
if (!specifiedTemplate.isALLSaved() && !DesignerMode.isVcsMode()) {
specifiedTemplate.stopEditing();
int returnVal = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Would_You_Like_To_Save") + " \"" + specifiedTemplate.getEditingFILE() + "\" ?",
Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (returnVal == JOptionPane.YES_OPTION) {
CallbackSaveWorker worker = specifiedTemplate.save();
worker.addSuccessCallback(new Runnable() {
@Override
public void run() {
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName()));
closeTpl(specifiedTemplate);
}
});
worker.start(specifiedTemplate.getRuntimeId());
} else if (returnVal == JOptionPane.NO_OPTION) {
closeTpl(specifiedTemplate);
}
} else {
closeTpl(specifiedTemplate);
}
}
private void closeTpl(@Nonnull JTemplate<?, ?> specifiedTemplate) {
HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate);
closeAndFreeLock(specifiedTemplate);
activePrevTemplateAfterClose();
}
private void closeAndFreeLock(@Nonnull JTemplate<?, ?> template) { private void closeAndFreeLock(@Nonnull JTemplate<?, ?> template) {
FILE file = template.getEditingFILE(); FILE file = template.getEditingFILE();
// 只有是环境内的文件,才执行释放锁 // 只有是环境内的文件,才执行释放锁
@ -941,70 +692,6 @@ public class MultiTemplateTabPane extends JComponent {
} }
} }
/**
* 后台关闭当前编辑模板
*/
public void closeCurrentTpl() {
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
this.setIsCloseCurrent(true);
this.closeFormat(jTemplate);
this.closeSpecifiedTemplate(jTemplate);
}
/**
* 关闭模板
*
* @param closedTemplate 模板
*/
public void closeFormat(JTemplate closedTemplate) {
//表单不需要处理
if (!closedTemplate.isJWorkBook()) {
return;
}
if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_NULL) {
return;
}
//是被参照的模板被关闭,则重置格式刷
closedTemplate.doConditionCancelFormat();
}
/**
* 关闭掉一个模板之后激活新的待显示模板
*/
public void activePrevTemplateAfterClose() {
if (openedTemplate.isEmpty()) {
//新建并激活模板
DesignerContext.getDesignerFrame().addAndActivateJTemplate();
selectedIndex = 0;
//此时刚自动新建的模板在HistoryTemplateListCache的editingTemplate
temTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
} else {
// 如果关闭的模板是当前选中的模板,则重新激活当前 selectIndex 的模板;
// selectIndex 没有变化,但是对应的模板已经变成了前一张模板
if (closeIconIndex == selectedIndex || isCloseCurrent) {
// 如果当前关闭的模板在最右侧,那么预览上一个,防止数组越界
if (selectedIndex >= maxPaintIndex) {
// selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true
selectedIndex--;
}
isCloseCurrent = false;
}
// 如果关闭的模板不是当前选中的模板,那么重新获取一下当前模板的 index,激活该 index
else {
JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
selectedIndex = HistoryTemplateListCache.getInstance().contains(template);
}
if (selectedIndex < openedTemplate.size()) {
//如果是已后台关闭的模板,则重新打开文件
openedTemplate.get(selectedIndex).activeOldJTemplate();
}
}
}
private boolean isOverCloseIcon(int evtX) { private boolean isOverCloseIcon(int evtX) {
boolean isOverCloseIcon = false; boolean isOverCloseIcon = false;
@ -1036,29 +723,6 @@ public class MultiTemplateTabPane extends JComponent {
return -1; return -1;
} }
/**
* 处理自动新建的模板 在切换时的处理
*/
public void doWithtemTemplate() {
//temtemplate保存的一定是手动新建的没有编辑或是编辑了没有保存的模板
//没有保存,说明有编辑;已经保存在磁盘里的文件,说明有过处理,并且已经保存,此时切换都不将其自动关闭
if (temTemplate == null || temTemplate == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()) {
return;
}
if (!temTemplate.isSaved() || !temTemplate.getEditingFILE().isMemFile()) {
temTemplate = null;
}
//自动新建的模板B若没有进行任何编辑(新建模板没有进行任何编辑时saved都是true):还没有存盘
if (temTemplate != null && temTemplate.getEditingFILE().isMemFile() && temTemplate.isSaved()) {
HistoryTemplateListCache.getInstance().closeSelectedReport(temTemplate);
temTemplate = null;
setSelectedIndex(HistoryTemplateListCache.getInstance().contains(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()));
}
}
private class UIListDownItemUI extends BasicMenuItemUI { private class UIListDownItemUI extends BasicMenuItemUI {
@Override @Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
@ -1161,44 +825,13 @@ public class MultiTemplateTabPane extends JComponent {
closeIconIndex = getTemplateIndex(evtX); closeIconIndex = getTemplateIndex(evtX);
clodeMode = MOUSE_PRESS_CLOSE; clodeMode = MOUSE_PRESS_CLOSE;
//关闭close图标所在的模板{ //关闭close图标所在的模板{
JTemplate<?, ?> template = openedTemplate.get(closeIconIndex); TemplateTabManager.getInstance().getCurrentOperator().closeByIndex(closeIconIndex);
if (template.isOpening()) {
WorkerManager.getInstance().cancelWorker(template.getPath());
} else if (template.isSaving()) {
boolean completed = WorkerManager.getInstance().isCompleted(template.getTarget().getTemplateID());
if (!completed) {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Close_Template_Tip", template.getEditingFILE().getName()));
return;
}
}
//参考CloseCurrentTemplateAction,在closeFormat与closeSpecifiedTemplate之前要先设定isCloseCurrent,这样关闭之后才会自动切换tab
if (checkCurrentClose(template)) {
setIsCloseCurrent(true);
}
closeFormat(template);
closeSpecifiedTemplate(template);
DesignerContext.getDesignerFrame().getContentFrame().repaint();
isShowList = false; isShowList = false;
} else { } else {
//没有点击关闭和ListDown按钮,则切换到点击的模板处 //没有点击关闭和ListDown按钮,则切换到点击的模板处
closeIconIndex = -1; closeIconIndex = -1;
clodeMode = CLOSE; clodeMode = CLOSE;
int tempSelectedIndex = selectedIndex; TemplateTabManager.getInstance().getCurrentOperator().switchTpl(getTemplateIndex(evtX));
if (selectedIndex != getTemplateIndex(evtX) && getTemplateIndex(evtX) != -1) {
openedTemplate.get(selectedIndex).stopEditing();
selectedIndex = getTemplateIndex(evtX);
//如果在权限编辑情况下,不允许切换到表单类型的工作簿
if (DesignerMode.isAuthorityEditing() && !openedTemplate.get(selectedIndex).isJWorkBook()) {
DesignerContext.getDesignerFrame().addAndActivateJTemplate(openedTemplate.get(tempSelectedIndex));
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Form_Authority_Edited_Cannot_Be_Supported")
+ "!", Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.WARNING_MESSAGE);
MultiTemplateTabPane.this.repaint();
return;
}
JTemplate evtXTemplate = openedTemplate.get(getTemplateIndex(evtX));
evtXTemplate.activeNewJTemplate();
}
isShowList = false; isShowList = false;
} }
MultiTemplateTabPane.this.repaint(); MultiTemplateTabPane.this.repaint();
@ -1209,11 +842,6 @@ public class MultiTemplateTabPane extends JComponent {
} }
private boolean checkCurrentClose(JTemplate template) {
JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
return JTemplate.isValid(currentTemplate) && ComparatorUtils.equals(template.getPath(), currentTemplate.getPath());
}
private class MultiTemplateTabMouseMotionListener implements MouseMotionListener { private class MultiTemplateTabMouseMotionListener implements MouseMotionListener {
/** /**
* 鼠标拖拽 * 鼠标拖拽
@ -1237,7 +865,7 @@ public class MultiTemplateTabPane extends JComponent {
//看是否需要显示toolTip //看是否需要显示toolTip
if (mouseOveredIndex != -1 && isNeedToolTips[mouseOveredIndex - minPaintIndex]) { if (mouseOveredIndex != -1 && isNeedToolTips[mouseOveredIndex - minPaintIndex]) {
setToolTipText(openedTemplate.get(mouseOveredIndex).getEditingFILE().getName()); setToolTipText(TemplateTabManager.getInstance().getCurrentOperator().getOpenedJTemplates().get(mouseOveredIndex).getEditingFILE().getName());
} else { } else {
setToolTipText(null); setToolTipText(null);
} }

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

@ -1,5 +1,7 @@
package com.fr.design.file; package com.fr.design.file;
import com.fr.design.file.impl.DefaultTemplateTabOperate;
/** /**
* @author shine * @author shine
* @version 10.0 * @version 10.0
@ -14,11 +16,11 @@ public class MutilTempalteTabPane {
} }
public void setIsCloseCurrent(boolean b) { public void setIsCloseCurrent(boolean b) {
MultiTemplateTabPane.getInstance().setIsCloseCurrent(b); TemplateTabManager.getInstance().setCloseCurrent(b);
} }
public void activePrevTemplateAfterClose() { public void activePrevTemplateAfterClose() {
MultiTemplateTabPane.getInstance().activePrevTemplateAfterClose(); DefaultTemplateTabOperate.getInstance().activePrevTemplateAfterClose(true);
} }
} }

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

@ -81,11 +81,15 @@ public abstract class NewTemplatePane extends JComponent implements MouseListene
} }
if (isOverNewIcon(evtX) && newWorkBookIconMode != GRAY_NEW_CPT) { if (isOverNewIcon(evtX) && newWorkBookIconMode != GRAY_NEW_CPT) {
newWorkBookIconMode = getMousePressNew(); newWorkBookIconMode = getMousePressNew();
DesignerContext.getDesignerFrame().addAndActivateJTemplate(); createNewTemplate();
} }
this.repaint(); this.repaint();
} }
protected void createNewTemplate() {
DesignerContext.getDesignerFrame().addAndActivateJTemplate();
}
/** /**
*鼠标松开 *鼠标松开
* @param e 事件 * @param e 事件

19
designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java

@ -3,8 +3,8 @@ package com.fr.design.file;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.event.StateChangeListener; import com.fr.design.event.StateChangeListener;
import com.fr.design.file.impl.DefaultTemplateTabOperate;
import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
@ -19,10 +19,10 @@ import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**
* Author : daisy * Author : daisy
@ -152,7 +152,16 @@ public class SaveSomeTemplatePane extends BasicPane {
public boolean showSavePane() { public boolean showSavePane() {
populate(); return showSavePane(false);
}
public boolean showSavePane(boolean switchEnv) {
return switchEnv ?
showSavePane(DefaultTemplateTabOperate.getInstance().getOpenedJTemplates()) :
showSavePane(HistoryTemplateListPane.getInstance().getHistoryList());
}
public boolean showSavePane(List<JTemplate<?, ?>> jTemplates) {
populate(jTemplates);
//如果有未保存的文件 ,则跳出保存对话框,选择要存储的项目 //如果有未保存的文件 ,则跳出保存对话框,选择要存储的项目
if (!unSavedTemplate.isEmpty()) { if (!unSavedTemplate.isEmpty()) {
dialog.setVisible(true); dialog.setVisible(true);
@ -162,8 +171,8 @@ public class SaveSomeTemplatePane extends BasicPane {
return isAllSaved; return isAllSaved;
} }
public void populate() {
java.util.List<JTemplate<?, ?>> opendedTemplate = HistoryTemplateListPane.getInstance().getHistoryList(); private void populate(java.util.List<JTemplate<?, ?>> opendedTemplate) {
JTemplate<?, ?> currentTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); JTemplate<?, ?> currentTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate();
for (int i = 0; i < opendedTemplate.size(); i++) { for (int i = 0; i < opendedTemplate.size(); i++) {
if (isneedToAdd(opendedTemplate.get(i), currentTemplate)) { if (isneedToAdd(opendedTemplate.get(i), currentTemplate)) {

253
designer-base/src/main/java/com/fr/design/file/TemplateTabManager.java

@ -0,0 +1,253 @@
package com.fr.design.file;
import com.finebi.cbb.utils.CompareUtils;
import com.fr.design.file.impl.DefaultTemplateTabOperate;
import com.fr.design.file.impl.EmptyTemplateTabOperator;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TemplateTabManager {
private static class HOLDER {
private static final TemplateTabManager singleton = new TemplateTabManager();
}
public static TemplateTabManager getInstance() {
return HOLDER.singleton;
}
private TemplateTabManager() {
list.add(DefaultTemplateTabOperate.getInstance());
}
private List<TemplateTabOperateProvider> list = new ArrayList<>();
public void register(TemplateTabOperateProvider templateTabOperateProvider) {
this.list.add(templateTabOperateProvider);
}
public void remove(TemplateTabOperateProvider templateTabOperateProvider) {
this.list.remove(templateTabOperateProvider);
}
private boolean isCloseCurrent = false;
//自动新建的模板B若没有进行任何编辑,切换到其他
// 模板时,模板B会自动关闭
private JTemplate<?, ?> temTemplate = null;
public boolean isCloseCurrent() {
return isCloseCurrent;
}
public void setCloseCurrent(boolean closeCurrent) {
isCloseCurrent = closeCurrent;
}
public void setTemTemplate(JTemplate<?, ?> temTemplate) {
this.temTemplate = temTemplate;
}
public void refresh() {
getCurrentOperator().refresh();
}
/**
* 从模板树删除文件
*/
public void deleteOpenedTemplate(JTemplate<?, ?> template) {
TemplateTabOperateProvider provider = getOperatorByTemplate(template);
provider.deleteOpenedTemplate(template);
this.refresh();
}
public JTemplate getSelectedFile() {
return getCurrentOperator().getSelectedFile();
}
/**
* 关闭掉当前文件列表中指定的文件
*
* @param file 指定的文件
*/
public void closeFileTemplate(FILE file) {
for (TemplateTabOperateProvider provider : list) {
provider.closeFileTemplate(file);
}
}
/**
* 关闭指定模板
*
* @param specifiedTemplate
*/
public void closeSpecifiedTemplate(JTemplate<?, ?> specifiedTemplate) {
getCurrentOperator().closeSpecifiedTemplate(specifiedTemplate);
}
/**
* 刷新打开模板
*
* @param tempalteLsit
*/
public void refreshOpenedTemplate(List<JTemplate<?, ?>> tempalteLsit) {
for (TemplateTabOperateProvider provider : list) {
provider.refreshOpenedTemplate(tempalteLsit);
}
}
/**
* 处理自动新建的模板 在切换时的处理
*/
public void doWithtemTemplate() {
//temtemplate保存的一定是手动新建的没有编辑或是编辑了没有保存的模板
//没有保存,说明有编辑;已经保存在磁盘里的文件,说明有过处理,并且已经保存,此时切换都不将其自动关闭
if (temTemplate == null || temTemplate == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()) {
return;
}
if (!temTemplate.isSaved() || !temTemplate.getEditingFILE().isMemFile()) {
temTemplate = null;
}
//自动新建的模板B若没有进行任何编辑(新建模板没有进行任何编辑时saved都是true):还没有存盘
if (temTemplate != null && temTemplate.getEditingFILE().isMemFile() && temTemplate.isSaved()) {
HistoryTemplateListCache.getInstance().closeSelectedReport(temTemplate);
temTemplate = null;
resetSelectIndex(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate());
}
}
public void resetSelectIndex(JTemplate jTemplate) {
getCurrentOperator().resetSelectIndex(jTemplate);
}
public void activeNewTemplate() {
//先看其他模式中是否有已打开的模板,有的话切换过去
for (TemplateTabOperateProvider templateTabOperateProvider : list) {
if (templateTabOperateProvider.getOpenedJTemplates().size() != 0) {
templateTabOperateProvider.getSelectedFile().activeNewJTemplate();
refresh();
return;
}
}
//都没有的话,新建并激活模板
DesignerContext.getDesignerFrame().addAndActivateJTemplate();
//此时刚自动新建的模板在HistoryTemplateListCache的editingTemplate
TemplateTabManager.getInstance().setTemTemplate(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate());
refresh();
}
/**
* 后台关闭当前编辑模板
*/
public void closeCurrentTpl() {
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
this.setCloseCurrent(true);
this.closeFormat(jTemplate);
this.closeSpecifiedTemplate(jTemplate);
}
/**
* 关闭指定索引值模板
*
* @param index
*/
public void closeByIndex(int index) {
getCurrentOperator().closeByIndex(index);
}
/**
* 关闭指定索引值模板
*
* @param jTemplate
*/
public void closeByJTemplate(JTemplate jTemplate) {
TemplateTabOperateProvider operator = getOperatorByOperatorType(jTemplate.getTemplateTabOperatorType());
operator.closeByIndex(operator.getJTemplateIndex(jTemplate));
}
/**
* 切换到指定tab栏的指定索引值模板
*
* @param jTemplate
*/
public void switchByJTemplate(JTemplate jTemplate) {
TemplateTabOperateProvider operator = getOperatorByOperatorType(jTemplate.getTemplateTabOperatorType());
operator.switchTpl(operator.getJTemplateIndex(jTemplate));
}
/**
* 获取所有打开的模板map
*
* @return
*/
public Map<String, List<JTemplate<?, ?>>> getAllOpenedTemplateMap() {
Map<String, List<JTemplate<?, ?>>> resultMap = new HashMap<>();
for (TemplateTabOperateProvider provider : list) {
resultMap.put(provider.getOperatorType(), provider.getOpenedJTemplates());
}
return resultMap;
}
public void closeOthers() {
TemplateTabOperateProvider currentOperator = getCurrentOperator();
currentOperator.closeAction(CloseOption.Others,
currentOperator.getJTemplateIndex(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()));
}
public String getTemplateShowName(JTemplate temTemplate){
return getCurrentOperator().getTemplateShowName(temTemplate);
}
/**
* 关闭模板
*
* @param closedTemplate 模板
*/
public void closeFormat(JTemplate closedTemplate) {
//表单不需要处理
if (!closedTemplate.isJWorkBook()) {
return;
}
if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_NULL) {
return;
}
//是被参照的模板被关闭,则重置格式刷
closedTemplate.doConditionCancelFormat();
}
public TemplateTabOperateProvider getCurrentOperator() {
return getOperatorByTemplate(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate());
}
private TemplateTabOperateProvider getOperatorByTemplate(JTemplate jTemplate) {
return getOperatorByOperatorType(jTemplate.getTemplateTabOperatorType());
}
private TemplateTabOperateProvider getOperatorByOperatorType(String type) {
for (TemplateTabOperateProvider provider : list) {
if (CompareUtils.isEqual(provider.getOperatorType(), type)) {
return provider;
}
}
return EmptyTemplateTabOperator.getInstance();
}
}

114
designer-base/src/main/java/com/fr/design/file/TemplateTabOperateProvider.java

@ -0,0 +1,114 @@
package com.fr.design.file;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE;
import java.util.List;
public interface TemplateTabOperateProvider {
/**
* 找到模板树中的位置
*/
void locateTemplateInTree(int tplIndex);
/**
* 右键一系列关闭操作
*
* @param option closeType
* @param index
*/
void closeAction(CloseOption option, int index);
/**
* 切换模板
*
* @param templateIndex 模板索引值
*/
void switchTpl(int templateIndex);
/**
* 获取打开模板的基本信息
*
* @return
*/
List<JTemplate<?, ?>> getOpenedJTemplates();
void closeByIndex(int index);
/**
* 关闭指定模板
*
* @param specifiedTemplate
*/
void closeSpecifiedTemplate(JTemplate<?, ?> specifiedTemplate);
/**
* 删除已打开的模板
*/
void deleteOpenedTemplate(JTemplate<?, ?> template);
/**
* 获取选中模板
* @return
*/
JTemplate getSelectedFile();
/**
* 刷新ui
*/
void refresh();
/**
* 重置下选中的Index
* @param jTemplate
*/
void resetSelectIndex(JTemplate jTemplate);
/**
* 刷新下打开的模板list
* @param list
*/
void refreshOpenedTemplate(List<JTemplate<?, ?>> list);
/**
* 关闭指定节点
* @param file
*/
void closeFileTemplate(FILE file);
/**
* 获取操作类型标识
* @return
*/
String getOperatorType();
/**
* 获取当前选中模板的index
* @return
*/
int getSelectIndex();
/**
* 设置当前选中模板的index
* @return
*/
void setSelectIndex(int index);
/**
* 获取指定模板在operator中的索引值
* @param jTemplate
* @return
*/
int getJTemplateIndex(JTemplate jTemplate);
/**
* 获取template在tab中显示的名称
* @param jTemplate
* @return
*/
String getTemplateShowName(JTemplate jTemplate);
}

332
designer-base/src/main/java/com/fr/design/file/impl/AbstractTemplateTabOperate.java

@ -0,0 +1,332 @@
package com.fr.design.file.impl;
import com.finebi.cbb.utils.CompareUtils;
import com.fr.base.vcs.DesignerMode;
import com.fr.design.actions.file.LocateAction;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.CloseOption;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.SaveSomeTemplatePane;
import com.fr.design.file.TemplateTabManager;
import com.fr.design.file.TemplateTabOperateProvider;
import com.fr.design.file.TemplateTreePane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager;
import com.fr.design.utils.TemplateUtils;
import com.fr.design.worker.WorkerManager;
import com.fr.design.worker.save.CallbackSaveWorker;
import com.fr.file.FILE;
import com.fr.file.FileNodeFILE;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.third.javax.annotation.Nonnull;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.lock.TplOperator;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import static com.fr.design.dialog.FineJOptionPane.showConfirmDialog;
import static javax.swing.JOptionPane.*;
public abstract class AbstractTemplateTabOperate implements TemplateTabOperateProvider {
//用于存放工作簿
protected java.util.List<JTemplate<?, ?>> openedTemplate = new ArrayList<>();
//选中的Tab项
protected int selectedIndex = -1;
public AbstractTemplateTabOperate() {
}
@Override
public void locateTemplateInTree(int tplIndex) {
//处于搜索模式时,先退出搜索模式,再定位
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
TemplateTreePane.getInstance().refreshDockingView();
}
JTemplate<?, ?> template = openedTemplate.get(tplIndex);
locateTemplate(template);
}
private void locateTemplate(JTemplate<?, ?> template) {
FILE currentTemplate = template.getEditingFILE();
//模板不属于当前环境,跟预览一样先提示保存,再定位模板
//如果是拖拽进来的模板单单用exist不能判断,这边参考预览的判断逻辑(browserTemplate),补充一下
if ((!currentTemplate.exists() || !(currentTemplate instanceof FileNodeFILE)) && template.canBeSaved()) {
int selVal = showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Web_Preview_Message"), Toolkit.i18nText("Fine-Design_Basic_Preview_Tool_Tips"), OK_CANCEL_OPTION, WARNING_MESSAGE);
if (OK_OPTION == selVal) {
CallbackSaveWorker worker = template.saveAs();
worker.start(template.getRuntimeId());
worker.addSuccessCallback(new Runnable() {
@Override
public void run() {
LocateAction.gotoEditingTemplateLeaf(template.getPath());
}
});
}
} else {
LocateAction.gotoEditingTemplateLeaf(template.getPath());
}
}
@Override
public void closeAction(CloseOption option, int index) {
SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(true);
if (saveSomeTempaltePane.showSavePane(this.openedTemplate)) {
JTemplate<?, ?>[] templates = new JTemplate<?, ?>[openedTemplate.size()];
for (int i = 0; i < openedTemplate.size(); i++) {
templates[i] = openedTemplate.get(i);
}
JTemplate<?, ?> currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
closeTemplate(templates, currentTemplate, option, index);
if (openedTemplate.isEmpty()) {
TemplateTabManager.getInstance().activeNewTemplate();
selectedIndex = 0;
} else {
DesignerContext.getDesignerFrame().activateJTemplate(currentTemplate);
}
}
}
public void closeByIndex(int index) {
//关闭close图标所在的模板{
JTemplate<?, ?> template = openedTemplate.get(index);
if (template.isOpening()) {
WorkerManager.getInstance().cancelWorker(template.getPath());
} else if (template.isSaving()) {
boolean completed = WorkerManager.getInstance().isCompleted(template.getTarget().getTemplateID());
if (!completed) {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Close_Template_Tip", template.getEditingFILE().getName()));
return;
}
}
//参考CloseCurrentTemplateAction,在closeFormat与closeSpecifiedTemplate之前要先设定isCloseCurrent,这样关闭之后才会自动切换tab
if (checkCurrentClose(template)) {
TemplateTabManager.getInstance().setCloseCurrent(true);
}
TemplateTabManager.getInstance().closeFormat(template);
closeSpecifiedTemplate(template);
DesignerContext.getDesignerFrame().getContentFrame().repaint();
}
private boolean checkCurrentClose(JTemplate template) {
JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
return JTemplate.isValid(currentTemplate) && ComparatorUtils.equals(template.getPath(), currentTemplate.getPath());
}
private void closeTemplate(JTemplate<?, ?>[] templates, JTemplate<?, ?> currentTemplate, CloseOption option, int tplIndex) {
for (int i = 0; i < templates.length; i++) {
if (option.shouldClose(tplIndex, i)) {
JTemplate<?, ?> jTemplate = templates[i];
if (jTemplate == currentTemplate) {
currentTemplate = option == CloseOption.All ? null : templates[tplIndex];
}
//判断关闭的模板是不是格式刷的被参照的模板
openedTemplate.remove(jTemplate);
if (jTemplate != currentTemplate) {
TemplateTabManager.getInstance().closeFormat(jTemplate);
HistoryTemplateListCache.getInstance().closeSelectedReport(jTemplate);
closeAndFreeLock(jTemplate);
}
}
}
}
private void closeAndFreeLock(@Nonnull JTemplate<?, ?> template) {
FILE file = template.getEditingFILE();
// 只有是环境内的文件,才执行释放锁
if (file != null && file.isEnvFile()) {
// release lock
WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath());
}
}
@Override
public void switchTpl(int templateIndex) {
int tempSelectedIndex = selectedIndex;
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if ((selectedIndex != templateIndex || !this.accept(jTemplate.getTemplateTabOperatorType()))
&& templateIndex != -1) {
openedTemplate.get(selectedIndex).stopEditing();
selectedIndex = templateIndex;
//如果在权限编辑情况下,不允许切换到表单类型的工作簿
if (DesignerMode.isAuthorityEditing() && !openedTemplate.get(selectedIndex).isJWorkBook()) {
DesignerContext.getDesignerFrame().addAndActivateJTemplate(openedTemplate.get(tempSelectedIndex));
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Form_Authority_Edited_Cannot_Be_Supported") + "!", Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.WARNING_MESSAGE);
return;
}
JTemplate evtXTemplate = openedTemplate.get(templateIndex);
evtXTemplate.activeNewJTemplate();
}
}
@Override
public void deleteOpenedTemplate(JTemplate<?, ?> template) {
if (!openedTemplate.contains(template)) {
return;
}
openedTemplate.remove(template);
if (openedTemplate.size() == 0) {
TemplateTabManager.getInstance().activeNewTemplate();
return;
}
if (openedTemplate.size() == selectedIndex) {
//如果删除的是后一个Tab,则定位到前一个
this.selectedIndex--;
}
}
@Override
public JTemplate getSelectedFile() {
if (openedTemplate.size() == selectedIndex) {
selectedIndex = Math.max(--selectedIndex, 0);
}
return openedTemplate.get(selectedIndex);
}
/**
* 关闭掉当前已打开文件列表中指定的文件
*
* @param file 指定的文件
*/
public void closeFileTemplate(FILE file) {
for (JTemplate<?, ?> temp : openedTemplate) {
if (ComparatorUtils.equals(file, temp.getEditingFILE())) {
closeSpecifiedTemplate(temp);
break;
}
}
}
/**
* 关闭模板
*
* @param specifiedTemplate 模板
*/
public void closeSpecifiedTemplate(JTemplate<?, ?> specifiedTemplate) {
if (specifiedTemplate == null && !openedTemplate.contains(specifiedTemplate)) {
return;
}
if (!specifiedTemplate.isALLSaved() && !DesignerMode.isVcsMode()) {
specifiedTemplate.stopEditing();
int returnVal = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Would_You_Like_To_Save") + " \"" + specifiedTemplate.getEditingFILE() + "\" ?", Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (returnVal == JOptionPane.YES_OPTION) {
CallbackSaveWorker worker = specifiedTemplate.save();
worker.addSuccessCallback(new Runnable() {
@Override
public void run() {
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName()));
closeTpl(specifiedTemplate);
}
});
worker.start(specifiedTemplate.getRuntimeId());
} else if (returnVal == JOptionPane.NO_OPTION) {
closeTpl(specifiedTemplate);
}
} else {
closeTpl(specifiedTemplate);
}
}
private void closeTpl(@Nonnull JTemplate<?, ?> specifiedTemplate) {
HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate);
closeAndFreeLock(specifiedTemplate);
activePrevTemplateAfterClose(specifiedTemplate == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate());
}
/**
* 关闭掉一个模板之后激活新的待显示模板
*/
public void activePrevTemplateAfterClose(boolean isCurrentSelectedTpl) {
if (openedTemplate.isEmpty()) {
TemplateTabManager.getInstance().activeNewTemplate();
selectedIndex = 0;
} else {
// 如果关闭的模板是当前选中的模板,则重新激活当前 selectIndex 的模板;
// selectIndex 没有变化,但是对应的模板已经变成了前一张模板
if (isCurrentSelectedTpl || TemplateTabManager.getInstance().isCloseCurrent()) {
// 如果当前关闭的模板在最右侧,那么预览上一个,防止数组越界
if (selectedIndex >= openedTemplate.size()) {
// selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true
selectedIndex--;
}
TemplateTabManager.getInstance().setCloseCurrent(false);
}
// 如果关闭的模板不是当前选中的模板,那么重新获取一下当前模板的 index,激活该 index
else {
JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
selectedIndex = this.openedTemplate.indexOf(template);
}
if (selectedIndex < openedTemplate.size()) {
//如果是已后台关闭的模板,则重新打开文件
openedTemplate.get(selectedIndex).activeOldJTemplate();
}
}
TemplateTabManager.getInstance().refresh();
}
@Override
public void resetSelectIndex(JTemplate jTemplate) {
this.selectedIndex = openedTemplate.indexOf(jTemplate);
TemplateTabManager.getInstance().refresh();
}
public void refreshOpenedTemplate(List<JTemplate<?, ?>> list) {
List<JTemplate<?, ?>> result = new ArrayList<>();
for (JTemplate jTemplate : list) {
if (this.accept(jTemplate.getTemplateTabOperatorType())) {
result.add(jTemplate);
}
}
this.openedTemplate = result;
TemplateTabManager.getInstance().refresh();
}
public List<JTemplate<?, ?>> getOpenedJTemplates() {
return this.openedTemplate;
}
@Override
public void setSelectIndex(int index) {
this.selectedIndex = index;
}
@Override
public int getSelectIndex() {
return this.selectedIndex;
}
@Override
public int getJTemplateIndex(JTemplate jTemplate) {
return this.openedTemplate.indexOf(jTemplate);
}
public boolean accept(String type) {
return CompareUtils.isEqual(getOperatorType(), type);
}
@Override
public String getTemplateShowName(JTemplate template) {
String name = TemplateUtils.createLockeTemplatedName(template, template.getTemplateName());
if (!template.isSaved() && !name.endsWith(" *")) {
name += " *";
}
return name;
}
}

31
designer-base/src/main/java/com/fr/design/file/impl/DefaultTemplateTabOperate.java

@ -0,0 +1,31 @@
package com.fr.design.file.impl;
import com.fr.design.file.MultiTemplateTabPane;
public class DefaultTemplateTabOperate extends AbstractTemplateTabOperate {
public static final String OPERATOR_TYPE = "DEFAULT_TEMPLATE_TAB_OPERATOR";
private static class HOLDER {
private static final DefaultTemplateTabOperate singleton = new DefaultTemplateTabOperate();
}
private DefaultTemplateTabOperate() {
super();
}
public static DefaultTemplateTabOperate getInstance() {
return HOLDER.singleton;
}
@Override
public void refresh() {
MultiTemplateTabPane.getInstance().repaint();
}
@Override
public String getOperatorType() {
return OPERATOR_TYPE;
}
}

109
designer-base/src/main/java/com/fr/design/file/impl/EmptyTemplateTabOperator.java

@ -0,0 +1,109 @@
package com.fr.design.file.impl;
import com.fr.design.file.CloseOption;
import com.fr.design.file.TemplateTabOperateProvider;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE;
import com.fr.stable.StringUtils;
import java.util.ArrayList;
import java.util.List;
public class EmptyTemplateTabOperator implements TemplateTabOperateProvider {
private static class HOLDER {
private static final EmptyTemplateTabOperator singleton = new EmptyTemplateTabOperator();
}
private EmptyTemplateTabOperator() {
}
public static EmptyTemplateTabOperator getInstance() {
return HOLDER.singleton;
}
@Override
public void locateTemplateInTree(int tplIndex) {
}
@Override
public void closeAction(CloseOption option, int index) {
}
@Override
public void closeByIndex(int index) {
}
@Override
public void switchTpl(int templateIndex) {
}
@Override
public List<JTemplate<?, ?>> getOpenedJTemplates() {
return new ArrayList<>();
}
@Override
public void closeSpecifiedTemplate(JTemplate<?, ?> specifiedTemplate) {
}
@Override
public void deleteOpenedTemplate(JTemplate<?, ?> template) {
}
@Override
public JTemplate getSelectedFile() {
return null;
}
@Override
public void refresh() {
}
@Override
public void resetSelectIndex(JTemplate jTemplate) {
}
@Override
public void refreshOpenedTemplate(List<JTemplate<?, ?>> list) {
}
@Override
public void closeFileTemplate(FILE file) {
}
@Override
public String getOperatorType() {
return StringUtils.EMPTY;
}
@Override
public int getSelectIndex() {
return 0;
}
@Override
public void setSelectIndex(int index) {
}
@Override
public int getJTemplateIndex(JTemplate jTemplate) {
return 0;
}
@Override
public String getTemplateShowName(JTemplate jTemplate) {
return StringUtils.EMPTY;
}
}

29
designer-base/src/main/java/com/fr/design/mainframe/CenterRegionContainerPane.java

@ -230,12 +230,11 @@ public class CenterRegionContainerPane extends JPanel {
// 颜色,字体那些按钮的工具栏 // 颜色,字体那些按钮的工具栏
toolbarPane.add(toolbarComponent = ad.resetToolBar(toolbarComponent, plus), BorderLayout.CENTER); toolbarPane.add(toolbarComponent = ad.resetToolBar(toolbarComponent, plus), BorderLayout.CENTER);
if (strategy.hasToolBarPane(plus)) { JPanel customNorthPane = strategy.customNorthPane(toolbarPane,plus);
this.add(toolbarPane, BorderLayout.NORTH); if (!isExist(customNorthPane)){
} else { this.removeNorth();
this.remove(toolbarPane); this.add(customNorthPane, BorderLayout.NORTH);
} }
if (strategy.hasTemplateTabPane(plus)) { if (strategy.hasTemplateTabPane(plus)) {
eastCenterPane.add(templateTabPane, BorderLayout.CENTER); eastCenterPane.add(templateTabPane, BorderLayout.CENTER);
} else { } else {
@ -250,6 +249,26 @@ public class CenterRegionContainerPane extends JPanel {
resetByDesignMode(); resetByDesignMode();
} }
private void removeNorth(){
Component[] components = this.getComponents();
for(Component c : components){
if (c!= centerTemplateCardPane){
this.remove(c);
}
}
}
private boolean isExist(JPanel customNorthPane) {
Component[] components = this.getComponents();
for (Component component : components) {
if (component == customNorthPane) {
return true;
}
}
return false;
}
private void resetByDesignMode() { private void resetByDesignMode() {
if (DesignModeContext.isDuchampMode()) { if (DesignModeContext.isDuchampMode()) {
eastPane.remove(largeToolbar); eastPane.remove(largeToolbar);

8
designer-base/src/main/java/com/fr/design/mainframe/DefaultToolKitConfig.java

@ -3,6 +3,9 @@ package com.fr.design.mainframe;
import com.fr.design.base.mode.DesignModeContext; import com.fr.design.base.mode.DesignModeContext;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import javax.swing.JPanel;
public class DefaultToolKitConfig implements ToolKitConfigStrategy { public class DefaultToolKitConfig implements ToolKitConfigStrategy {
@Override @Override
public boolean hasTemplateTabPane(ToolBarMenuDockPlus plus) { public boolean hasTemplateTabPane(ToolBarMenuDockPlus plus) {
@ -18,4 +21,9 @@ public class DefaultToolKitConfig implements ToolKitConfigStrategy {
public boolean hasToolBarPane(ToolBarMenuDockPlus plus) { public boolean hasToolBarPane(ToolBarMenuDockPlus plus) {
return plus.hasToolBarPane(); return plus.hasToolBarPane();
} }
@Override
public JPanel customNorthPane(JPanel toolBarPane, ToolBarMenuDockPlus plus) {
return toolBarPane;
}
} }

8
designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java

@ -19,11 +19,7 @@ import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.event.DesignerOpenedListener; import com.fr.design.event.DesignerOpenedListener;
import com.fr.design.event.TargetModifiedEvent; import com.fr.design.event.TargetModifiedEvent;
import com.fr.design.event.TargetModifiedListener; import com.fr.design.event.TargetModifiedListener;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.*;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MultiTemplateTabPane;
import com.fr.design.file.SaveSomeTemplatePane;
import com.fr.design.file.TemplateTreePane;
import com.fr.design.fun.OemProcessor; import com.fr.design.fun.OemProcessor;
import com.fr.design.fun.impl.AbstractTemplateTreeShortCutProvider; import com.fr.design.fun.impl.AbstractTemplateTreeShortCutProvider;
import com.fr.design.gui.iprogressbar.ProgressDialog; import com.fr.design.gui.iprogressbar.ProgressDialog;
@ -1110,7 +1106,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
// 新的form不往前兼容 // 新的form不往前兼容
if (inValidDesigner(jt)) { if (inValidDesigner(jt)) {
this.addAndActivateJTemplate(); this.addAndActivateJTemplate();
MultiTemplateTabPane.getInstance().setTemTemplate( TemplateTabManager.getInstance().setTemTemplate(
HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); HistoryTemplateListCache.getInstance().getCurrentEditingTemplate());
} else { } else {
this.addAndActivateJTemplate(jt); this.addAndActivateJTemplate(jt);

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

@ -17,12 +17,7 @@ import com.fr.design.data.datapane.TableDataTreePane;
import com.fr.design.data.datapane.management.search.TableDataTreeSearchManager; import com.fr.design.data.datapane.management.search.TableDataTreeSearchManager;
import com.fr.design.data.tabledata.ResponseDataSourceChange; import com.fr.design.data.tabledata.ResponseDataSourceChange;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.FileOperations; import com.fr.design.file.*;
import com.fr.design.file.FileToolbarStateChangeListener;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MultiTemplateTabPane;
import com.fr.design.file.TemplateTreePane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.imenu.UIMenuHighLight; import com.fr.design.gui.imenu.UIMenuHighLight;
@ -275,7 +270,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter());
HistoryTemplateListPane.getInstance().setCurrentEditingTemplate(jt); HistoryTemplateListPane.getInstance().setCurrentEditingTemplate(jt);
//处理自动新建的模板 //处理自动新建的模板
MultiTemplateTabPane.getInstance().doWithtemTemplate(); TemplateTabManager.getInstance().doWithtemTemplate();
if (DesignerMode.isAuthorityEditing()) { if (DesignerMode.isAuthorityEditing()) {
RolesAlreadyEditedPane.getInstance().refreshDockingView(); RolesAlreadyEditedPane.getInstance().refreshDockingView();
} }
@ -547,10 +542,10 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
for (JTemplate jTemplate : HistoryTemplateListCache.getInstance().getHistoryList()) { for (JTemplate jTemplate : HistoryTemplateListCache.getInstance().getHistoryList()) {
if (ComparatorUtils.equals(jTemplate.getEditingFILE().getPath(), path)) { if (ComparatorUtils.equals(jTemplate.getEditingFILE().getPath(), path)) {
if (isCurrentEditing) { if (isCurrentEditing) {
MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); TemplateTabManager.getInstance().setCloseCurrent(true);
} }
MultiTemplateTabPane.getInstance().closeFormat(jTemplate); TemplateTabManager.getInstance().closeFormat(jTemplate);
MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(jTemplate); TemplateTabManager.getInstance().closeSpecifiedTemplate(jTemplate);
return; return;
} }
} }

21
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -30,9 +30,8 @@ import com.fr.design.designer.DesignerProxy;
import com.fr.design.designer.TargetComponent; import com.fr.design.designer.TargetComponent;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.dialog.InformationWarnPane; import com.fr.design.dialog.InformationWarnPane;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.*;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.impl.DefaultTemplateTabOperate;
import com.fr.design.file.TemplateResourceManager;
import com.fr.design.fun.DesignerFrameUpButtonProvider; import com.fr.design.fun.DesignerFrameUpButtonProvider;
import com.fr.design.fun.MenuHandler; import com.fr.design.fun.MenuHandler;
import com.fr.design.fun.PreviewProvider; import com.fr.design.fun.PreviewProvider;
@ -615,7 +614,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
* @return 是则返回true * @return 是则返回true
*/ */
public boolean isALLSaved() { public boolean isALLSaved() {
return this.saved && this.authoritySaved; return this.saved && this.authoritySaved && this.canBeSaved();
} }
@ -1979,7 +1978,11 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
public void setDesignerUIMode() { public void setDesignerUIMode() {
DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode(); DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode();
} }
public String getTemplateTabOperatorType(){
return DefaultTemplateTabOperate.OPERATOR_TYPE;
}
/** /**
* 判断当前的模板是否是有效的模板 * 判断当前的模板是否是有效的模板
* *
@ -1989,4 +1992,12 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
public static boolean isValid(JTemplate jt) { public static boolean isValid(JTemplate jt) {
return jt != null && jt != JNullTemplate.NULL; return jt != null && jt != JNullTemplate.NULL;
} }
public boolean canBeSaved(){
return true;
}
public boolean supportCache(){
return true;
}
} }

10
designer-base/src/main/java/com/fr/design/mainframe/ToolKitConfigStrategy.java

@ -2,6 +2,9 @@ package com.fr.design.mainframe;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import javax.swing.JPanel;
public interface ToolKitConfigStrategy { public interface ToolKitConfigStrategy {
/** /**
@ -24,4 +27,11 @@ public interface ToolKitConfigStrategy {
* @return * @return
*/ */
boolean hasToolBarPane(ToolBarMenuDockPlus plus); boolean hasToolBarPane(ToolBarMenuDockPlus plus);
/**
* 定制工具栏
* @param toolBarPane
* @param plus
* @return
*/
JPanel customNorthPane(JPanel toolBarPane, ToolBarMenuDockPlus plus);
} }

4
designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java

@ -416,9 +416,7 @@ public abstract class ToolBarMenuDock {
menuDef.addShortCut(new OpenRecentReportMenuDef()); menuDef.addShortCut(new OpenRecentReportMenuDef());
if (!DesignModeContext.isDuchampMode()) { addCloseCurrentTemplateAction(menuDef);
addCloseCurrentTemplateAction(menuDef);
}
scs = plus.shortcut4FileMenu(); scs = plus.shortcut4FileMenu();
if (!ArrayUtils.isEmpty(scs)) { if (!ArrayUtils.isEmpty(scs)) {

8
designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java

@ -1,7 +1,7 @@
package com.fr.design.mainframe.vcs.ui; package com.fr.design.mainframe.vcs.ui;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.mainframe.DesignerFrameFileDealerPane;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
@ -57,9 +57,9 @@ public class FileVersionCellEditor extends AbstractCellEditor implements TableCe
jt.stopEditing(); jt.stopEditing();
//只有模板路径一致时关闭当前模板 //只有模板路径一致时关闭当前模板
if (ComparatorUtils.equals(fileOfVersion, jt.getPath())) { if (ComparatorUtils.equals(fileOfVersion, jt.getPath())) {
MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); TemplateTabManager.getInstance().setCloseCurrent(true);
MultiTemplateTabPane.getInstance().closeFormat(jt); TemplateTabManager.getInstance().closeFormat(jt);
MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(jt); TemplateTabManager.getInstance().closeSpecifiedTemplate(jt);
} }
//再打开cache中的模板 //再打开cache中的模板

8
designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionsPanel.java

@ -5,7 +5,7 @@ import com.fr.design.base.mode.DesignModeContext;
import com.fr.design.base.mode.DesignerMode; import com.fr.design.base.mode.DesignerMode;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
@ -115,9 +115,9 @@ public class FileVersionsPanel extends BasicPane {
// 关闭当前打开的版本 // 关闭当前打开的版本
JTemplate<?, ?> jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); JTemplate<?, ?> jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); TemplateTabManager.getInstance().setCloseCurrent(true);
MultiTemplateTabPane.getInstance().closeFormat(jt); TemplateTabManager.getInstance().closeFormat(jt);
MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(jt); TemplateTabManager.getInstance().closeSpecifiedTemplate(jt);
updateDesignerFrame(true); updateDesignerFrame(true);

4
designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java

@ -3,7 +3,7 @@ package com.fr.design.worker.open;
import com.fr.base.chart.exception.ChartNotFoundException; import com.fr.base.chart.exception.ChartNotFoundException;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.file.TemplateTreePane; import com.fr.design.file.TemplateTreePane;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.lock.LockInfoDialog; import com.fr.design.lock.LockInfoDialog;
@ -87,7 +87,7 @@ public class OpenWorker<T> extends SwingWorker<T, Void> {
UIManager.getIcon("OptionPane.errorIcon")); UIManager.getIcon("OptionPane.errorIcon"));
} }
if (cause.getCause() instanceof TplLockedException) { if (cause.getCause() instanceof TplLockedException) {
MultiTemplateTabPane.getInstance().closeCurrentTpl(); TemplateTabManager.getInstance().closeCurrentTpl();
TemplateTreePane.getInstance().getFileNode().setLock(UUID.randomUUID().toString()); TemplateTreePane.getInstance().getFileNode().setLock(UUID.randomUUID().toString());
LockInfoDialog.show(null); LockInfoDialog.show(null);
} }

8
designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java

@ -2,7 +2,7 @@ package com.fr.nx.app.designer.toolbar;
import com.fr.base.extension.FileExtension; import com.fr.base.extension.FileExtension;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE; import com.fr.file.FILE;
@ -103,9 +103,9 @@ public enum TemplateTransformer {
DesignerContext.getDesignerFrame().openTemplate(file); DesignerContext.getDesignerFrame().openTemplate(file);
return; return;
} }
MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); TemplateTabManager.getInstance().setCloseCurrent(true);
MultiTemplateTabPane.getInstance().closeFormat(jt); TemplateTabManager.getInstance().closeFormat(jt);
MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(jt); TemplateTabManager.getInstance().closeSpecifiedTemplate(jt);
DesignerContext.getDesignerFrame().openTemplate(file); DesignerContext.getDesignerFrame().openTemplate(file);
} }

6
designer-base/src/main/java/com/fr/start/BaseDesigner.java

@ -8,7 +8,7 @@ import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.constants.DesignerLaunchStatus; import com.fr.design.constants.DesignerLaunchStatus;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.file.TemplateTreePane; import com.fr.design.file.TemplateTreePane;
import com.fr.design.fun.DesignerStartOpenFileProcessor; import com.fr.design.fun.DesignerStartOpenFileProcessor;
import com.fr.design.fun.impl.DesignerStartWithEmptyFile; import com.fr.design.fun.impl.DesignerStartWithEmptyFile;
@ -193,7 +193,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
} else { } else {
df.addAndActivateJTemplate(); df.addAndActivateJTemplate();
// 如果没有模板,则需要确认一下 // 如果没有模板,则需要确认一下
MultiTemplateTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); TemplateTabManager.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
} }
} }
@ -253,7 +253,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
private boolean createNewTemplate(DesignerFrame df) { private boolean createNewTemplate(DesignerFrame df) {
df.addAndActivateJTemplate(); df.addAndActivateJTemplate();
// 如果没有模板,则需要确认一下 // 如果没有模板,则需要确认一下
MultiTemplateTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); TemplateTabManager.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
return true; return true;
} }

4
designer-base/src/main/java/com/fr/start/common/DesignerOpenEmptyPanel.java

@ -3,7 +3,7 @@ package com.fr.start.common;
import com.fr.base.svg.IconUtils; import com.fr.base.svg.IconUtils;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.DesignSizeI18nManager; import com.fr.design.i18n.DesignSizeI18nManager;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
@ -59,7 +59,7 @@ public class DesignerOpenEmptyPanel extends JPanel {
HistoryTemplateListCache.getInstance().setCurrentEditingTemplate(null); HistoryTemplateListCache.getInstance().setCurrentEditingTemplate(null);
df.addAndActivateJTemplate(); df.addAndActivateJTemplate();
// 如果没有模板,则需要确认一下 // 如果没有模板,则需要确认一下
MultiTemplateTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); TemplateTabManager.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
} }
}); });
createButton.setBorder(new EmptyBorder(0, 10, 0, 10)); createButton.setBorder(new EmptyBorder(0, 10, 0, 10));

4
designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java

@ -1,7 +1,7 @@
package com.fr.design.fit.common; package com.fr.design.fit.common;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.fit.NewJForm; import com.fr.design.fit.NewJForm;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
@ -86,7 +86,7 @@ public class TemplateTool {
JTemplate oldJTemplate = jTemplateList.get(i); JTemplate oldJTemplate = jTemplateList.get(i);
if (oldJTemplate != null && ComparatorUtils.equals(oldJTemplate.getEditingFILE(), newJTemplate.getEditingFILE())) { if (oldJTemplate != null && ComparatorUtils.equals(oldJTemplate.getEditingFILE(), newJTemplate.getEditingFILE())) {
jTemplateList.set(i, newJTemplate); jTemplateList.set(i, newJTemplate);
MultiTemplateTabPane.getInstance().refreshOpenedTemplate(jTemplateList); TemplateTabManager.getInstance().refreshOpenedTemplate(jTemplateList);
return; return;
} }
} }

5
designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java

@ -1,7 +1,8 @@
package com.fr.design.preview; package com.fr.design.preview;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.file.TemplateTreePane;
import com.fr.design.fun.impl.AbstractPreviewProvider; import com.fr.design.fun.impl.AbstractPreviewProvider;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.JForm;
@ -66,7 +67,7 @@ public class DeveloperPreview extends AbstractPreviewProvider {
} }
private void onPreview(JTemplate<?, ?> jt) { private void onPreview(JTemplate<?, ?> jt) {
MultiTemplateTabPane.getInstance().closeCurrentTpl(); TemplateTabManager.getInstance().closeCurrentTpl();
jt.generateForBiddenTemplate(); jt.generateForBiddenTemplate();
} }

4
designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java

@ -39,7 +39,7 @@ import com.fr.design.designer.TargetComponent;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTabManager;
import com.fr.design.fun.PreviewProvider; import com.fr.design.fun.PreviewProvider;
import com.fr.design.fun.PropertyItemPaneProvider; import com.fr.design.fun.PropertyItemPaneProvider;
import com.fr.design.fun.ReportSupportedFileUIProvider; import com.fr.design.fun.ReportSupportedFileUIProvider;
@ -1175,7 +1175,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
public boolean saveShareFile() { public boolean saveShareFile() {
FILE newFile = createNewEmptyFile(); FILE newFile = createNewEmptyFile();
//如果文件已经打开, 那么就覆盖关闭掉他 //如果文件已经打开, 那么就覆盖关闭掉他
MultiTemplateTabPane.getInstance().closeFileTemplate(newFile); TemplateTabManager.getInstance().closeFileTemplate(newFile);
final WorkBook tpl = this.getTarget(); final WorkBook tpl = this.getTarget();
// 弹出输入参数 // 弹出输入参数
java.util.Map<String, Object> parameterMap = inputParameters(tpl); java.util.Map<String, Object> parameterMap = inputParameters(tpl);

4
designer-realize/src/main/java/com/fr/start/MainDesigner.java

@ -17,6 +17,7 @@ import com.fr.design.deeplink.DeepLinkManager;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.MultiTemplateTabPane;
import com.fr.design.file.TemplateTabManager;
import com.fr.design.fun.MenuHandler; import com.fr.design.fun.MenuHandler;
import com.fr.design.fun.OemProcessor; import com.fr.design.fun.OemProcessor;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
@ -409,8 +410,7 @@ public class MainDesigner extends BaseDesigner {
return; return;
} }
saveButton.setEnabled(!jt.isSaved() && !DesignModeContext.isVcsMode() && jt.checkEnable()); saveButton.setEnabled(!jt.isSaved() && !DesignModeContext.isVcsMode() && jt.checkEnable());
MultiTemplateTabPane.getInstance().refreshOpenedTemplate(HistoryTemplateListCache.getInstance().getHistoryList()); TemplateTabManager.getInstance().refreshOpenedTemplate(HistoryTemplateListCache.getInstance().getHistoryList());
MultiTemplateTabPane.getInstance().repaint();
if (DesignerEnvManager.getEnvManager().isSupportUndo()) { if (DesignerEnvManager.getEnvManager().isSupportUndo()) {
undo.setEnabled(jt.canUndo()); undo.setEnabled(jt.canUndo());
redo.setEnabled(jt.canRedo()); redo.setEnabled(jt.canRedo());

Loading…
Cancel
Save