Browse Source

Merge remote-tracking branch 'origin/release/11.0' into release/11.0

release/11.0
obo 2 years ago
parent
commit
280abc2dae
  1. 104
      designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java
  2. 8
      designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java
  3. 54
      designer-realize/src/main/java/com/fr/design/mainframe/SheetNameTabPane.java

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

@ -24,6 +24,8 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -44,7 +46,7 @@ public class TemplateUtils {
* @param openNewTemplate 是否需要在创建后打开模板 * @param openNewTemplate 是否需要在创建后打开模板
*/ */
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate) { public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate) {
createAndOpenTemplate(prefix, file, createByEditingTemplate, openNewTemplate, () -> {}); createAndOpenTemplate(prefix, file, createByEditingTemplate, openNewTemplate, null);
} }
/** /**
@ -66,15 +68,33 @@ public class TemplateUtils {
Runnable doAfterCreateTemplate; Runnable doAfterCreateTemplate;
//判断一下要保存的文件是否已打开 //判断一下要保存的文件是否已打开
int index = HistoryTemplateListCache.getInstance().contains(file); int index = HistoryTemplateListCache.getInstance().contains(file);
if (index == -1) { JTemplate template = null;
doAfterCreateTemplate = () -> {}; if (index != -1) {
} else { template = HistoryTemplateListCache.getInstance().getHistoryList().get(index);
JTemplate template = HistoryTemplateListCache.getInstance().getHistoryList().get(index);
doAfterCreateTemplate = () -> HistoryTemplateListCache.getInstance().closeSelectedReport(template);
} }
createAndOpenTemplate0(file, oldPath, createByEditingTemplate, openNewTemplate, doAfterCreateTemplate); createAndOpenTemplate0(file, oldPath, createByEditingTemplate, openNewTemplate, template);
} }
/**
* 创建新的模板文件并打开模板并在创建备份模板成功后执行doAfterCreate
*
* @param prefix 模板文件名称前缀
* @param file 模板文件
* @param createByEditingTemplate 是否根据 当前编辑模板 来创建新模板
* 为true时以CurrentEditingTemplate为准创建新模板
* 为false时以传入的File文件为准创建新模板此文件可以不是编辑状态
* @param openNewTemplate 是否需要在创建后打开模板
* @param template 备份成功后需要关闭的模板
*/
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate, @Nullable JTemplate<?, ?> template) {
String oldPath = file.getPath();
file = getSavedFile(prefix, file);
if (file == null) {
return;
}
createAndOpenTemplate0(file, oldPath, createByEditingTemplate, openNewTemplate, template);
}
/** /**
* 返回值可以为null, 为null表示没有点击保存按钮或者传递进来的文件file本身不满足格式要求 * 返回值可以为null, 为null表示没有点击保存按钮或者传递进来的文件file本身不满足格式要求
@ -111,31 +131,17 @@ public class TemplateUtils {
} }
/** /**
* 创建新的模板文件并打开模板并在创建备份模板成功后执行doAfterCreate * 生成备份模板
* *
* @param prefix 模板文件名称前缀 * @param file saveAs的模板文件
* @param file 模板文件
* @param createByEditingTemplate 是否根据 当前编辑模板 来创建新模板 * @param createByEditingTemplate 是否根据 当前编辑模板 来创建新模板
* 为true时以CurrentEditingTemplate为准创建新模板 * 为true时以CurrentEditingTemplate为准创建新模板
* 为false时以传入的File文件为准创建新模板此文件可以不是编辑状态 * 为false时以传入的File文件为准创建新模板此文件可以不是编辑状态
* @param openNewTemplate 是否需要在创建后打开模板 * @param oldPath 被saveAs的文件路径
* @param doAfterCreateTemplate 创建备份模板成功后调用
*/ */
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate, Runnable doAfterCreateTemplate) { private static CompletableFuture<Boolean> createTemplate(FILE file, String oldPath, boolean createByEditingTemplate) {
String oldPath = file.getPath(); return CompletableFuture.supplyAsync(() -> {
file = getSavedFile(prefix, file); try {
if (file == null) {
return;
}
createAndOpenTemplate0(file, oldPath, createByEditingTemplate, openNewTemplate, doAfterCreateTemplate);
}
private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, Runnable doAfterCreateTemplate) {
new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() throws Exception {
// 读取模板数据 // 读取模板数据
byte[] content = getTemplateData(createByEditingTemplate, oldPath); byte[] content = getTemplateData(createByEditingTemplate, oldPath);
OutputStream out = null; OutputStream out = null;
@ -144,7 +150,7 @@ public class TemplateUtils {
boolean saveAsLock = WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath()); boolean saveAsLock = WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath());
if (!saveAsLock) { if (!saveAsLock) {
// 加锁失败时,直接返回 // 加锁失败时,直接返回
return false; throw new RuntimeException("[RemoteDesign] back up template file failed");
} }
out = file.asOutputStream(); out = file.asOutputStream();
out.write(content); out.write(content);
@ -159,20 +165,43 @@ public class TemplateUtils {
} }
} }
return true; return true;
} catch (Exception e) {
SaveFailureHandler.getInstance().process(e);
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
} }
});
}
/**
* 打开saveAs的新模板并关闭指定的旧模板
*
* @param file 模板文件
* @param openNewTemplate 是否需要打开新模板
* @param template 需要关闭的模板
*/
private static void openNewTemplateAndCloseOldTemplate(FILE file, boolean openNewTemplate, @Nullable JTemplate<?, ?> template) {
new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() throws Exception {
if (JTemplate.isValid(template)) {
//给要关闭的模板解锁
WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(template.getPath());
return true;
}
return false;
}
@Override @Override
protected void done() { protected void done() {
try { try {
if (!get()) { if (get()) {
throw new Exception("[RemoteDesign] back up template file failed"); //模板释放锁成功后关闭该模板
HistoryTemplateListCache.getInstance().closeSelectedReport(template);
} }
// 创建备份成功后,关闭原模板
doAfterCreateTemplate.run();
if (openNewTemplate) { if (openNewTemplate) {
DesignerContext.getDesignerFrame().openTemplate(file); DesignerContext.getDesignerFrame().openTemplate(file);
} }
// 备份成功刷新下目录树 展示出来备份的模板 // 刷新下目录树
TemplateTreePane.getInstance().refresh(); TemplateTreePane.getInstance().refresh();
} catch (Exception e) { } catch (Exception e) {
SaveFailureHandler.getInstance().process(e); SaveFailureHandler.getInstance().process(e);
@ -182,6 +211,15 @@ public class TemplateUtils {
}.execute(); }.execute();
} }
private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, @Nullable JTemplate<?, ?> template) {
createTemplate(file, oldPath, createByEditingTemplate).thenApply((Function<Boolean, Void>) aBoolean -> {
if (aBoolean) {
openNewTemplateAndCloseOldTemplate(file, openNewTemplate, template);
}
return null;
});
}
/** /**
* 读取模板文件数据 * 读取模板文件数据
* *

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

@ -119,8 +119,8 @@ public class SaveFailureHandler implements ThrowableHandler {
new FileNodeFILE(new FileNode(template.getPath(), false)), new FileNodeFILE(new FileNode(template.getPath(), false)),
true, true,
true, true,
// 创建并打开备份模板后,关闭原模板,无需释放原模板锁(因为已经被超管手动清除了) //另存之后需要关闭的模板
() -> HistoryTemplateListCache.getInstance().closeSelectedReport(template)); template);
} }
} }
} }
@ -141,8 +141,8 @@ public class SaveFailureHandler implements ThrowableHandler {
new FileNodeFILE(new FileNode(template.getPath(), false)), new FileNodeFILE(new FileNode(template.getPath(), false)),
true, true,
true, true,
// 创建并打开备份模板后,关闭原模板,无需释放原模板锁(锁定信息不一致 = 此用户模板锁信息已被清除) //另存之后需要关闭的模板
() -> HistoryTemplateListCache.getInstance().closeSelectedReport(template)); template);
} }
} }
} }

54
designer-realize/src/main/java/com/fr/design/mainframe/SheetNameTabPane.java

@ -1,30 +1,7 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.Path2D;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import com.fr.base.BaseUtils; 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.theme.ReportTheme; import com.fr.base.theme.ReportTheme;
import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.TemplateTheme;
@ -44,7 +21,6 @@ import com.fr.design.roleAuthority.RolesAlreadyEditedPane;
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.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.main.impl.WorkBook; import com.fr.main.impl.WorkBook;
import com.fr.poly.PolyDesigner; import com.fr.poly.PolyDesigner;
@ -52,6 +28,34 @@ import com.fr.report.poly.PolyWorkSheet;
import com.fr.report.report.TemplateReport; import com.fr.report.report.TemplateReport;
import com.fr.report.worksheet.WorkSheet; import com.fr.report.worksheet.WorkSheet;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.GeneralPath;
import java.awt.geom.Path2D;
import java.util.ArrayList;
import java.util.List;
/** /**
* NameTabPane of sheets * NameTabPane of sheets
* *
@ -67,7 +71,7 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
private static final Icon WORK_SHEET_ICON = IconUtils.readIcon("/com/fr/design/standard/worksheet"); private static final Icon WORK_SHEET_ICON = IconUtils.readIcon("/com/fr/design/standard/worksheet");
private static final Icon POLY_SHEET_ICON = IconUtils.readIcon("/com/fr/design/standard/polysheet"); private static final Icon POLY_SHEET_ICON = IconUtils.readIcon("/com/fr/design/standard/polysheet");
private static final Icon LEFT_ICON = IconUtils.readIcon("/com/fr/design/standard/prepage/pre_page"); private static final Icon LEFT_ICON = IconUtils.readIcon("/com/fr/design/standard/prepage/pre_page");
private static final Icon RIGHT_ICON = IconUtils.readIcon("/com/fr/design/standard/nextpage"); private static final Icon RIGHT_ICON = IconUtils.readIcon("/com/fr/design/standard/nextpage/next_page");
private static final Icon DISABLED_LEFT_ICON = IconUtils.readIcon("/com/fr/design/standard/prepage/pre_page_disabled.svg"); private static final Icon DISABLED_LEFT_ICON = IconUtils.readIcon("/com/fr/design/standard/prepage/pre_page_disabled.svg");
private static final Icon DISABLED_RIGHT_ICON = IconUtils.readIcon("/com/fr/design/standard/nextpage/next_page_disabled.svg"); private static final Icon DISABLED_RIGHT_ICON = IconUtils.readIcon("/com/fr/design/standard/nextpage/next_page_disabled.svg");
private static final int NUM = 10; private static final int NUM = 10;

Loading…
Cancel
Save