Browse Source
* commit '051bf9c362c9f1de654787a536d8bfd929640751': (42 commits) REPORT-91074 解决冲突 REPORT-91074 解决冲突 改下类名 fix:代码规范 fix:代码规范修改 REPORT-83195 卡顿点优化-回退一下开发者模式部分代码,设计有点问题 fix:代码修改 REPORT-93901 打开js高级编辑界面设计器卡死需重启 & REPORT-83195 卡顿点优化 卡顿/卡死问题修改 REPORT-93901 打开js高级编辑界面设计器卡死需重启 & REPORT-83195 卡顿点优化 卡顿/卡死问题修改 REPORT-93901 打开js高级编辑界面设计器卡死需重启 & REPORT-83195 卡顿点优化 卡顿/卡死问题修改 REPORT-83195 卡顿点优化-根据插件提示修改了一下代码规范 REPORT-83195 卡顿点优化-根据插件提示修改了一下代码规范 fix:代码规范 REPORT-83195 卡顿点优化-根据插件提示修改了一下代码规范 fix:处理代码兼容 fix:修改代码规范 fix:修改代码规范 REPORT-83195 卡顿点优化-开发者模式 fix:修改代码规范 REPORT-83195 卡顿点优化-单元格初次添加图表卡死 ...release/11.0
superman
2 years ago
48 changed files with 2156 additions and 645 deletions
@ -0,0 +1,68 @@
|
||||
package com.fr.design.file; |
||||
|
||||
import com.fr.design.i18n.Toolkit; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @since 11.0 |
||||
* created on 2023-04-14 |
||||
**/ |
||||
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; |
||||
} |
||||
|
||||
/** |
||||
* 判断指定索引模板是否应该被关闭 |
||||
* @param tplIndex |
||||
* @param i |
||||
* @return |
||||
*/ |
||||
public boolean shouldClose(int tplIndex, int i) { |
||||
return true; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,351 @@
|
||||
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 |
||||
* @since 11.0 |
||||
* created on 2023-04-14 |
||||
**/ |
||||
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() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 返回右侧下拉菜单的工厂类 |
||||
* @return |
||||
*/ |
||||
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); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,291 @@
|
||||
package com.fr.design.file; |
||||
|
||||
import com.finebi.cbb.utils.CompareUtils; |
||||
import com.fr.design.file.impl.DefaultTemplateTabOperate; |
||||
import com.fr.design.file.impl.EmptyTemplateTabOperate; |
||||
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; |
||||
|
||||
/** |
||||
* 模板tab的操作统一管理类 |
||||
* @author kerry |
||||
* @since 11.0 |
||||
* created on 2023-04-14 |
||||
**/ |
||||
public class TemplateTabManager { |
||||
private static class Holder { |
||||
private static final TemplateTabManager SINGLETON = new TemplateTabManager(); |
||||
} |
||||
|
||||
/** |
||||
* 返回TemplateTabManager单例对象 |
||||
* @return |
||||
*/ |
||||
public static TemplateTabManager getInstance() { |
||||
return Holder.SINGLETON; |
||||
} |
||||
|
||||
private TemplateTabManager() { |
||||
list.add(DefaultTemplateTabOperate.getInstance()); |
||||
} |
||||
|
||||
private List<TemplateTabOperateProvider> list = new ArrayList<>(); |
||||
|
||||
/** |
||||
* 支持注册新的Operator |
||||
* @param templateTabOperateProvider |
||||
*/ |
||||
public void register(TemplateTabOperateProvider templateTabOperateProvider) { |
||||
this.list.add(templateTabOperateProvider); |
||||
} |
||||
|
||||
/** |
||||
* 移除operator |
||||
* @param templateTabOperateProvider |
||||
*/ |
||||
public void remove(TemplateTabOperateProvider templateTabOperateProvider) { |
||||
this.list.remove(templateTabOperateProvider); |
||||
} |
||||
|
||||
private boolean closeCurrent = false; |
||||
//自动新建的模板B若没有进行任何编辑,切换到其他
|
||||
|
||||
// 模板时,模板B会自动关闭
|
||||
private JTemplate<?, ?> temTemplate = null; |
||||
|
||||
|
||||
public boolean isCloseCurrent() { |
||||
return closeCurrent; |
||||
} |
||||
|
||||
public void setCloseCurrent(boolean closeCurrent) { |
||||
this.closeCurrent = closeCurrent; |
||||
} |
||||
|
||||
public void setTemTemplate(JTemplate<?, ?> temTemplate) { |
||||
this.temTemplate = temTemplate; |
||||
} |
||||
|
||||
/** |
||||
* 刷新tab栏 |
||||
*/ |
||||
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()); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 重置选中index |
||||
* @param jTemplate |
||||
*/ |
||||
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 activePrevTemplateAfterClose(){ |
||||
getCurrentOperator().activePrevTemplateAfterClose(); |
||||
} |
||||
|
||||
/** |
||||
* 关闭其他 |
||||
*/ |
||||
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 EmptyTemplateTabOperate.getInstance(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,129 @@
|
||||
package com.fr.design.file; |
||||
|
||||
|
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.file.FILE; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 模板tab的操作接口 |
||||
* @author kerry |
||||
* @since 11.0 |
||||
* created on 2023-04-14 |
||||
**/ |
||||
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(); |
||||
|
||||
|
||||
/** |
||||
* 根据指定索引关闭模板 |
||||
* @param index |
||||
*/ |
||||
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); |
||||
|
||||
|
||||
/** |
||||
* 留作兼容,在关闭模板后激活前一个模板 |
||||
*/ |
||||
void activePrevTemplateAfterClose(); |
||||
} |
@ -0,0 +1,364 @@
|
||||
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.JOptionPane; |
||||
import java.util.ArrayList; |
||||
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; |
||||
|
||||
/** |
||||
* 模板tab的操作抽象类 |
||||
* @author kerry |
||||
* @since 11.0 |
||||
* created on 2023-04-14 |
||||
**/ |
||||
public abstract class AbstractTemplateTabOperate implements TemplateTabOperateProvider { |
||||
private static final String UNSAVED_SUFFIX = " *"; |
||||
//用于存放工作簿
|
||||
private java.util.List<JTemplate<?, ?>> openedTemplate = new ArrayList<>(); |
||||
//选中的Tab项
|
||||
private 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),补充一下
|
||||
boolean needSave = (!currentTemplate.exists() || !(currentTemplate instanceof FileNodeFILE)) && template.canBeSaved(); |
||||
if (needSave) { |
||||
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); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据指定索引值关闭模板 |
||||
* @param index |
||||
*/ |
||||
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(); |
||||
boolean shouldSwitch = (selectedIndex != templateIndex || !this.accept(jTemplate.getTemplateTabOperatorType())) |
||||
&& templateIndex != -1; |
||||
if (shouldSwitch) { |
||||
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"), WARNING_MESSAGE); |
||||
return; |
||||
} |
||||
JTemplate evtTemplate = openedTemplate.get(templateIndex); |
||||
evtTemplate.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()); |
||||
} |
||||
|
||||
/** |
||||
* 关闭掉一个模板之后激活新的待显示模板 |
||||
*/ |
||||
@Override |
||||
public void activePrevTemplateAfterClose(){ |
||||
activePrevTemplateAfterClose(TemplateTabManager.getInstance().isCloseCurrent()); |
||||
} |
||||
|
||||
/** |
||||
* 关闭掉一个模板之后激活新的待显示模板 |
||||
*/ |
||||
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(); |
||||
} |
||||
|
||||
/** |
||||
* 刷新已打开的模板 |
||||
* @param list |
||||
*/ |
||||
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); |
||||
} |
||||
|
||||
/** |
||||
* 是否支持指定操作类型 |
||||
* @param type |
||||
* @return |
||||
*/ |
||||
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(UNSAVED_SUFFIX)) { |
||||
name += UNSAVED_SUFFIX; |
||||
} |
||||
return name; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fr.design.file.impl; |
||||
|
||||
import com.fr.design.file.MultiTemplateTabPane; |
||||
|
||||
/** |
||||
* 默认的模板tab的操作类 |
||||
* @author kerry |
||||
* @since 11.0 |
||||
* created on 2023-04-14 |
||||
**/ |
||||
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(); |
||||
} |
||||
|
||||
/** |
||||
* 返回DefaultTemplateTabOperate 单例 |
||||
* @return |
||||
*/ |
||||
public static DefaultTemplateTabOperate getInstance() { |
||||
return Holder.SINGLETON; |
||||
} |
||||
|
||||
@Override |
||||
public void refresh() { |
||||
MultiTemplateTabPane.getInstance().repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public String getOperatorType() { |
||||
return OPERATOR_TYPE; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,124 @@
|
||||
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; |
||||
|
||||
/** |
||||
* 空的模板tab的操作类 |
||||
* @author kerry |
||||
* @since 11.0 |
||||
* created on 2023-04-14 |
||||
**/ |
||||
public class EmptyTemplateTabOperate implements TemplateTabOperateProvider { |
||||
private static class Holder { |
||||
private static final EmptyTemplateTabOperate SINGLETON = new EmptyTemplateTabOperate(); |
||||
} |
||||
|
||||
|
||||
private EmptyTemplateTabOperate() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 返回空的模板taboperator单例 |
||||
* @return |
||||
*/ |
||||
public static EmptyTemplateTabOperate 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; |
||||
} |
||||
|
||||
@Override |
||||
public void activePrevTemplateAfterClose() { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
package com.fr.design.worker.save.type; |
||||
|
||||
/** |
||||
* 保存的类别 |
||||
* |
||||
* @author John.Ying |
||||
* @since 11.0 |
||||
* Created on 2023/4/14 |
||||
*/ |
||||
public class SaveType { |
||||
|
||||
private TypeEnum type; |
||||
//保存时间是否慢(是否展示了保存中的UI界面)
|
||||
private boolean slowly; |
||||
|
||||
public TypeEnum getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(TypeEnum saveType) { |
||||
this.type = saveType; |
||||
} |
||||
|
||||
public boolean isSlowly() { |
||||
return slowly; |
||||
} |
||||
|
||||
public void setSlowly(boolean slowly) { |
||||
this.slowly = slowly; |
||||
} |
||||
|
||||
/** |
||||
* 保存类型:save or saveAs or empty |
||||
*/ |
||||
public enum TypeEnum { |
||||
/** |
||||
* 保存 |
||||
*/ |
||||
SAVE, |
||||
/** |
||||
* 另存 |
||||
*/ |
||||
SAVE_AS, |
||||
/** |
||||
* 空保存 |
||||
*/ |
||||
EMPTY; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,81 @@
|
||||
package com.fr.design.worker.save.type; |
||||
|
||||
|
||||
import com.fr.concurrent.FineExecutors; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrameFileDealerPane; |
||||
import com.fr.design.mainframe.EastRegionContainerPane; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.ui.util.UIUtil; |
||||
import com.fr.third.org.apache.commons.lang3.time.StopWatch; |
||||
|
||||
import javax.swing.SwingWorker; |
||||
import java.util.concurrent.Callable; |
||||
import java.util.concurrent.ExecutorService; |
||||
|
||||
/** |
||||
* 判断保存类别时执行的worker |
||||
* |
||||
* @author John.Ying |
||||
* @since 11.0 |
||||
* Created on 2023/4/14 |
||||
*/ |
||||
public class SaveTypeWorker extends SwingWorker<SaveType, Void> { |
||||
|
||||
public static final ExecutorService SAVE_TYPE_POOL = FineExecutors.newSingleThreadExecutor(); |
||||
|
||||
private final Callable<SaveType.TypeEnum> callable; |
||||
|
||||
private static final int TIME_OUT = 400; |
||||
|
||||
private final JTemplate<?, ?> template; |
||||
|
||||
private final SaveType saveType; |
||||
|
||||
|
||||
|
||||
public SaveTypeWorker(Callable<SaveType.TypeEnum> callable, JTemplate<?, ?> template) { |
||||
this.callable = callable; |
||||
this.template = template; |
||||
this.saveType = new SaveType(); |
||||
} |
||||
|
||||
@Override |
||||
protected SaveType doInBackground() throws Exception { |
||||
this.saveType.setType(callable.call()); |
||||
return this.saveType; |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 启动saveTypeWorker |
||||
*/ |
||||
public void start() { |
||||
StopWatch stopWatch = StopWatch.createStarted(); |
||||
this.template.setSaving(true); |
||||
this.execute(); |
||||
SAVE_TYPE_POOL.execute(() -> { |
||||
while (true) { |
||||
//大于最大等待时间或者worker已经完成该线程都要结束循环
|
||||
if (stopWatch.getTime() > TIME_OUT || isDone()) { |
||||
//如果是大于最大等待时间结束的,就需要进行等待中界面的覆盖
|
||||
if (!isDone()) { |
||||
saveType.setSlowly(true); |
||||
UIUtil.invokeLaterIfNeeded(() -> { |
||||
// 开始禁用
|
||||
EastRegionContainerPane.getInstance().updateAllPropertyPane(); |
||||
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover(); |
||||
DesignerFrameFileDealerPane.getInstance().stateChange(); |
||||
}); |
||||
} |
||||
stopWatch.stop(); |
||||
break; |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue