Browse Source

REPORT-70481 远程设计切换校验机制优化

【问题原因】rt
【改动思路】详见开发文档——https://kms.fineres.com/pages/viewpage.action?pageId=412521906
【review建议】review的时候麻烦顺便给文档评审下,谢谢~
feature/x
Yvan 3 years ago
parent
commit
8ce102bfdf
  1. 10
      designer-base/src/main/java/com/fr/design/actions/file/ExitDesignerAction.java
  2. 7
      designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java
  3. 7
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  4. 12
      designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java
  5. 6
      designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java
  6. 38
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  7. 20
      designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java
  8. 37
      designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java
  9. 8
      designer-base/src/main/java/com/fr/file/StashedFILE.java

10
designer-base/src/main/java/com/fr/design/actions/file/ExitDesignerAction.java

@ -3,6 +3,7 @@
*/ */
package com.fr.design.actions.file; package com.fr.design.actions.file;
import com.fr.design.file.SaveSomeTemplatePane;
import com.fr.design.mainframe.TemplateSavingChecker; import com.fr.design.mainframe.TemplateSavingChecker;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -28,9 +29,14 @@ public class ExitDesignerAction extends UpdateAction {
* @param e 事件 * @param e 事件
*/ */
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// 检查是否有正在保存的模板
if (!TemplateSavingChecker.check()) { if (!TemplateSavingChecker.check()) {
return; return;
} }
DesignerContext.getDesignerFrame().exit(); // 提示用户保存模板
SaveSomeTemplatePane saveSomeTemplatePane = new SaveSomeTemplatePane(true);
if (saveSomeTemplatePane.showSavePane()) {
DesignerContext.getDesignerFrame().exit();
}
} }
} }

7
designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java

@ -9,6 +9,7 @@ import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.DialogActionListener; import com.fr.design.dialog.DialogActionListener;
import com.fr.design.editor.editor.IntegerEditor; import com.fr.design.editor.editor.IntegerEditor;
import com.fr.design.file.SaveSomeTemplatePane;
import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIColorButton; import com.fr.design.gui.ibutton.UIColorButton;
@ -900,7 +901,11 @@ public class PreferencePane extends BasicPane {
null null
); );
if (rv == JOptionPane.OK_OPTION) { if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart(); // 重启前需要保存下模板
SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(true, SwingUtilities.getWindowAncestor(this));
if (saveSomeTempaltePane.showSavePane()) {
RestartHelper.restart();
}
} }
} }

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

@ -353,7 +353,7 @@ public class HistoryTemplateListCache implements CallbackEvent {
int size = historyList.size(); int size = historyList.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
JTemplate<?, ?> template = historyList.get(i); JTemplate<?, ?> template = historyList.get(i);
FILE file = template.templateToStashFile(); FILE file = template.templateToStashFile4Envchange();
if (file != null) { if (file != null) {
stashFILEMap.put(i, file); stashFILEMap.put(i, file);
} }
@ -382,7 +382,8 @@ public class HistoryTemplateListCache implements CallbackEvent {
} }
FineLoggerFactory.getLogger().info("{} is being reloaded", stashedFile.getName()); FineLoggerFactory.getLogger().info("{} is being reloaded", stashedFile.getName());
JTemplate<?, ?> template = historyList.get(i); JTemplate<?, ?> template = historyList.get(i);
template.refreshResource(stashedFile); // 切换环境后,刷新资源并且将暂存的FILE替换到template中
template.refreshResourceAndEditingFILE(stashedFile);
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
@ -430,7 +431,7 @@ public class HistoryTemplateListCache implements CallbackEvent {
FILE file = template.getEditingFILE(); FILE file = template.getEditingFILE();
boolean needReload = context == null || needReloadTemplate(context, template); boolean needReload = context == null || needReloadTemplate(context, template);
if (needReload) { if (needReload) {
FILE stashFile = template.templateToStashFile(); FILE stashFile = template.templateToStashFile4Other();
if (stashFile != null) { if (stashFile != null) {
FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName()); FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName());
template.refreshResource(stashFile); template.refreshResource(stashFile);

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

@ -17,7 +17,6 @@ import com.fr.design.mainframe.JTemplate;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.ProductConstants;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
@ -43,9 +42,18 @@ public class SaveSomeTemplatePane extends BasicPane {
private boolean isJudgeCurrentEditingTemplate = true; private boolean isJudgeCurrentEditingTemplate = true;
public SaveSomeTemplatePane(boolean isNeedTojudgeCurrent) { public SaveSomeTemplatePane(boolean isNeedTojudgeCurrent) {
this(isNeedTojudgeCurrent, DesignerContext.getDesignerFrame());
}
/**
* 支持自定义设置 dialog的父窗口
* @param isNeedTojudgeCurrent
* @param parent
*/
public SaveSomeTemplatePane(boolean isNeedTojudgeCurrent, Window parent) {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
if (this.dialog == null) { if (this.dialog == null) {
this.dialog = this.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { this.dialog = this.showSmallWindow(parent, new DialogActionAdapter() {
@Override @Override
public void doOk() { public void doOk() {
for (int i = 0; i < templateCheckBoxes.length; i++) { for (int i = 0; i < templateCheckBoxes.length; i++) {

6
designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java

@ -99,7 +99,11 @@ public class LockInfoDialog extends JDialog {
return; return;
} }
final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, TemplateTreePane.getInstance().getFilePath()); final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, TemplateTreePane.getInstance().getFilePath());
TemplateUtils.createAndOpenTemplate(Toolkit.i18nText("Fine_Design_Template_Lock_Copy"), new FileNodeFILE(new FileNode(selectedFilePath, false)), true); TemplateUtils.createAndOpenTemplate(
Toolkit.i18nText("Fine_Design_Template_Lock_Copy"),
new FileNodeFILE(new FileNode(selectedFilePath, false)),
false,
true);
} }
}); });
cancelButton.addActionListener(new ActionListener() { cancelButton.addActionListener(new ActionListener() {

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

@ -442,14 +442,35 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
stopListenThemeConfig(); stopListenThemeConfig();
} }
public FILE templateToStashFile() { /**
* 用于 切换工作目录 时的模板资源暂存
* @return
*/
public FILE templateToStashFile4Envchange() {
return templateToStashFile(true);
}
/**
* 用于 其它情况 的模板资源暂存
* 例如 插件插件安装/启用
* @return
*/
public FILE templateToStashFile4Other() {
return templateToStashFile(false);
}
private FILE templateToStashFile(boolean envChange) {
FILE file = this.getEditingFILE(); FILE file = this.getEditingFILE();
try { try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BaseBook target = this.getTarget(); BaseBook target = this.getTarget();
if (target != null) { if (target != null) {
target.export(outputStream); target.export(outputStream);
return new StashedFILE(file, outputStream.toByteArray(), template.suffix()); return envChange && file.isEnvFile() && !isSaved()?
// 切换工作目录时,未保存的环境文件转化为与环境无关的内存文件,再创建暂存文件
new StashedFILE(new MemFILE(file.getName()), outputStream.toByteArray(), template.suffix()) :
// 其它情况下,直接创建暂存文件
new StashedFILE(file, outputStream.toByteArray(), template.suffix());
} }
// 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理 // 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理
} catch (Exception e) { } catch (Exception e) {
@ -492,6 +513,17 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
} }
/**
* 刷新 模板资源 EditingFILE
* 仅在切换工作目录reload模板时使用
* @param file
*/
public void refreshResourceAndEditingFILE(FILE file) {
this.editingFILE = file instanceof StashedFILE ? ((StashedFILE) file).getInsideFILE() : file;
refreshResource(file);
}
private void setTargetByFile(FILE file) { private void setTargetByFile(FILE file) {
T newTemplate = JTemplateFactory.asIOFile(file, this.suffix()); T newTemplate = JTemplateFactory.asIOFile(file, this.suffix());
if (newTemplate != null) { if (newTemplate != null) {
@ -1921,4 +1953,4 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode(); DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode();
} }
} }

20
designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java

@ -27,7 +27,16 @@ import java.io.OutputStream;
*/ */
public class TemplateUtils { public class TemplateUtils {
public static void createAndOpenTemplate(String prefix, FILE file, boolean needOpen) { /**
* 创建新的模板文件并打开模板
* @param prefix 模板文件名称前缀
* @param file 模板文件
* @param createByEditingTemplate 是否根据 当前编辑模板 来创建新模板
* 为true时以CurrentEditingTemplate为准创建新模板
* 为false时以传入的File文件为准创建新模板此文件可以不是编辑状态
* @param openNewTemplate 是否需要在创建后打开模板
*/
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate) {
String fileName = file.getName(); String fileName = file.getName();
String oldPath = file.getPath(); String oldPath = file.getPath();
int indexOfLastDot = fileName.lastIndexOf(CoreConstants.DOT); int indexOfLastDot = fileName.lastIndexOf(CoreConstants.DOT);
@ -49,19 +58,18 @@ public class TemplateUtils {
if (isOk(result)) { if (isOk(result)) {
file = fileChooserPane.getSelectedFILE(); file = fileChooserPane.getSelectedFILE();
_createAndOpenTemplate(file, oldPath, needOpen); _createAndOpenTemplate(file, oldPath, createByEditingTemplate, openNewTemplate);
} }
} }
private static void _createAndOpenTemplate(FILE file, String oldPath, boolean needOpen){ private static void _createAndOpenTemplate(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate){
new SwingWorker<Void, Void>() { new SwingWorker<Void, Void>() {
@Override @Override
protected Void doInBackground() throws Exception { protected Void doInBackground() throws Exception {
byte[] content = new byte[0]; byte[] content = new byte[0];
if (!needOpen) { if (createByEditingTemplate) {
// 从当前编辑模板中生成备份文件 // 从当前编辑模板中生成备份文件
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
content = template.exportData(); content = template.exportData();
@ -95,7 +103,7 @@ public class TemplateUtils {
protected void done() { protected void done() {
try { try {
get(); get();
if (needOpen) { if (openNewTemplate) {
DesignerContext.getDesignerFrame().openTemplate(file); DesignerContext.getDesignerFrame().openTemplate(file);
} }
// 备份成功刷新下目录树 展示出来备份的模板 // 备份成功刷新下目录树 展示出来备份的模板

37
designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java

@ -22,6 +22,7 @@ import javax.swing.JOptionPane;
* @version 11.0 * @version 11.0
* Created by hades on 2021/12/7 * Created by hades on 2021/12/7
*/ */
@SuppressWarnings("all")
public class SaveFailureHandler implements ThrowableHandler { public class SaveFailureHandler implements ThrowableHandler {
private static final SaveFailureHandler INSTANCE = new SaveFailureHandler(); private static final SaveFailureHandler INSTANCE = new SaveFailureHandler();
@ -70,7 +71,7 @@ public class SaveFailureHandler implements ThrowableHandler {
@Override @Override
public boolean process(Throwable e) { public boolean process(Throwable e) {
if (e.getCause() instanceof UnLockedException || e instanceof UnLockedException) { if (e.getCause() instanceof UnLockedException || e instanceof UnLockedException) {
processByBack(Toolkit.i18nText("Fine_Design_Template_Has_Been_UnLocked")); processUnLocked(Toolkit.i18nText("Fine_Design_Template_Has_Been_UnLocked"));
return true; return true;
} }
return false; return false;
@ -81,7 +82,7 @@ public class SaveFailureHandler implements ThrowableHandler {
@Override @Override
public boolean process(Throwable e) { public boolean process(Throwable e) {
if (e.getCause() instanceof InconsistentLockException || e instanceof InconsistentLockException) { if (e.getCause() instanceof InconsistentLockException || e instanceof InconsistentLockException) {
processByBack(Toolkit.i18nText("Fine_Design_Template_Save_Failed_By_Lock_Inconsistency")); processInconsistentLock(Toolkit.i18nText("Fine_Design_Template_Save_Failed_By_Lock_Inconsistency"));
return true; return true;
} }
return false; return false;
@ -102,7 +103,7 @@ public class SaveFailureHandler implements ThrowableHandler {
}; };
protected void processByBack(String tip) { protected void processUnLocked(String tip) {
int option = FineJOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), int option = FineJOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(),
tip, tip,
Toolkit.i18nText("Fine-Design_Basic_Alert"), Toolkit.i18nText("Fine-Design_Basic_Alert"),
@ -113,10 +114,36 @@ public class SaveFailureHandler implements ThrowableHandler {
if (option == JOptionPane.YES_OPTION) { if (option == JOptionPane.YES_OPTION) {
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (template != null) { if (template != null) {
TemplateUtils.createAndOpenTemplate(Toolkit.i18nText("Fine_Design_Template_Backup"), new FileNodeFILE(new FileNode(template.getPath(), false)), false); TemplateUtils.createAndOpenTemplate(
Toolkit.i18nText("Fine_Design_Template_Backup"),
new FileNodeFILE(new FileNode(template.getPath(), false)),
true,
false);
}
}
}
protected void processInconsistentLock(String tip) {
int option = FineJOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(),
tip,
Toolkit.i18nText("Fine-Design_Basic_Alert"),
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE,
IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png"),
new Object[] {Toolkit.i18nText("Fine_Design_Template_SaveAs_Backup"), Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")}, null);
if (option == JOptionPane.YES_OPTION) {
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (template != null) {
TemplateUtils.createAndOpenTemplate(
Toolkit.i18nText("Fine_Design_Template_Backup"),
new FileNodeFILE(new FileNode(template.getPath(), false)),
true,
true);
// 创建并打开备份模板后,关闭原模板
HistoryTemplateListCache.getInstance().closeSelectedReport(template);
} }
} }
} }
} }
} }

8
designer-base/src/main/java/com/fr/file/StashedFILE.java

@ -87,6 +87,14 @@ public class StashedFILE extends AbstractFILE {
return false; return false;
} }
/**
* 获取内部FILE对象
* @return
*/
public FILE getInsideFILE() {
return file;
}
@Override @Override
public String toString() { public String toString() {
return FILEFactory.MEM_PREFIX + getName(); return FILEFactory.MEM_PREFIX + getName();

Loading…
Cancel
Save