From f4b6071fb94a019ca69bae260a8007eb0803b2bc Mon Sep 17 00:00:00 2001 From: "fly.li" Date: Sun, 12 Sep 2021 23:04:02 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-55243:=E8=81=94=E5=8A=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=9B=A0=E4=B8=BA=E6=8A=A5=E8=A1=A8=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=B8=AD=E6=A0=87=E8=AF=86=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=B9?= =?UTF-8?q?=E5=8F=98=E6=89=80=E9=9C=80=E8=A6=81=E4=BF=AE=E6=94=B9=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=B0=86=E5=85=B6=E4=B8=AD=E5=85=B3?= =?UTF-8?q?=E4=BA=8Ecpt=E5=92=8Ccptx=E5=85=BC=E5=AE=B9=E7=9A=84=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E9=83=A8=E5=88=86=E6=94=BE=E5=85=A5=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=E4=B8=AD=EF=BC=88=E6=94=BE=E5=9C=A8?= =?UTF-8?q?CptCompileUtil=E4=B8=AD=E4=B8=8D=E5=90=88=E9=80=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JTemplate.java | 6 +- .../utils/CptAndCptxCompatibilityUtil.java | 88 +++++++++++++++++++ .../nx/app/designer/utils/CptCompileUtil.java | 71 +-------------- .../com/fr/design/mainframe/JWorkBook.java | 7 +- .../design/report/LayerReportEnginePane.java | 9 +- 5 files changed, 100 insertions(+), 81 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/nx/app/designer/utils/CptAndCptxCompatibilityUtil.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index efeaa6b046..4b7c6abc87 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -70,6 +70,7 @@ import com.fr.general.IOUtils; import com.fr.locale.InterProviderFactory; import com.fr.log.FineLoggerFactory; import com.fr.main.impl.WorkBook; +import com.fr.nx.app.designer.utils.CptAndCptxCompatibilityUtil; import com.fr.nx.app.designer.utils.CptCompileUtil; import com.fr.nx.cptx.entry.metadata.CptxMetadata; import com.fr.nx.cptx.utils.CptxFileUtils; @@ -1470,7 +1471,7 @@ public abstract class JTemplate> * 设置新引擎后,有不支持的功能时,设计器中模板的标题需要加上“兼容模式”或者“不支持分页引擎”来提示用户 * */ private String compatibilityTip() { - if (!CptCompileUtil.isNewEngine(this.getTarget(), getEditingFILE().getPath())){ + if (!CptAndCptxCompatibilityUtil.enableNewEngine(this.getTarget(), getEditingFILE().getPath())){ return StringUtils.EMPTY; } String path = this.getEditingFILE().getPath(); @@ -1686,8 +1687,7 @@ public abstract class JTemplate> * 2.在这三种情况下:1.cptx文件另存为cpt文件 2.cptx另存为cptx文件 3.设置了新引擎的cpt文件另存为cpt文件, * 因为文件的编译目录改变了,需要重新预编译,因此设置jTemplate的保存状态为false * */ - boolean hasChanged = CptCompileUtil.hasChanged(oldName, this); - if (hasChanged){ + if (CptAndCptxCompatibilityUtil.needRecompile(oldName, this)){ this.saved = false; } result = this.saveRealFile(); diff --git a/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptAndCptxCompatibilityUtil.java b/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptAndCptxCompatibilityUtil.java new file mode 100644 index 0000000000..c390579d77 --- /dev/null +++ b/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptAndCptxCompatibilityUtil.java @@ -0,0 +1,88 @@ +package com.fr.nx.app.designer.utils; + +import com.fr.base.extension.FileExtension; +import com.fr.design.mainframe.JTemplate; +import com.fr.file.FILE; +import com.fr.main.TemplateWorkBook; +import com.fr.report.report.Report; +import com.fr.report.stable.LayerReportAttr; +import com.fr.report.worksheet.WorkSheet; + +/** + * @author fly.li + * @version 10.0 + * Created on 2021/09/12 + */ +public class CptAndCptxCompatibilityUtil { + + /** + * 判断是否需要重新编译 + **/ + public static boolean needRecompile(String oldName, JTemplate jTemplate){ + FILE editingFILE = jTemplate.getEditingFILE(); + String path = editingFILE.getPath(); + //只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性 + boolean isCptxConvertToCpt = oldName.endsWith(".cptx") && path.endsWith(".cpt"); + if (isCptxConvertToCpt && !changeFrEngineAttr(jTemplate)){ + isCptxConvertToCpt = false; + } + return (isCptxConvertToCpt || isSaveAs(jTemplate, oldName, path)); + } + + /** + * 判断是不是cptx模板或者开启了的新引擎的cpt模板的另存为操作 + **/ + private static boolean isSaveAs(JTemplate jTemplate, String oldName, String newName){ + return enableNewEngine(jTemplate.getTarget(), newName) && ((FileExtension.CPTX.matchExtension(oldName) && FileExtension.CPTX.matchExtension(newName)) || (FileExtension.CPT.matchExtension(oldName) && FileExtension.CPT.matchExtension(newName))); + } + + /** + * cptx另存为cpt需要修改报表引擎属性 + **/ + private static boolean changeFrEngineAttr(JTemplate jTemplate){ + WorkSheet workSheet = gainWorkSheet(jTemplate.getTarget()); + if (workSheet == null){ + return false; + }else { + LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); + if (layerReportAttr == null){ + layerReportAttr = new LayerReportAttr(); + workSheet.setLayerReportAttr(layerReportAttr); + } + layerReportAttr.setClientPaging(true); + layerReportAttr.setEngineState(0); + return true; + } + } + + /** + * 是否启用了新引擎的判断 + * cptx自动走新引擎(非兼容模式),cpt需要进行设置 + * */ + public static boolean enableNewEngine(Object workBook, String fileName){ + WorkSheet workSheet = gainWorkSheet(workBook); + LayerReportAttr layerReportAttr = gainLayerReportAttr(workSheet); + return enableNewEngine(layerReportAttr, fileName); + } + + private static LayerReportAttr gainLayerReportAttr(WorkSheet workSheet){ + if (workSheet != null){ + LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); + return layerReportAttr; + } else { + return null; + } + } + + private static WorkSheet gainWorkSheet(Object workBook){ + if (workBook == null || !(workBook instanceof TemplateWorkBook)){ + return null; + } + Report report = ((TemplateWorkBook) workBook).getReport(0); + return report instanceof WorkSheet ? (WorkSheet)report : null; + } + + private static boolean enableNewEngine(LayerReportAttr layerReportAttr, String fileName){ + return (layerReportAttr!= null && layerReportAttr.isClientPaging() && layerReportAttr.getEngineState() == 0) || FileExtension.CPTX.matchExtension(fileName); + } +} diff --git a/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java b/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java index 7067789a45..57f114aba1 100644 --- a/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java +++ b/designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java @@ -1,12 +1,10 @@ package com.fr.nx.app.designer.utils; -import com.fr.base.extension.FileExtension; import com.fr.design.mainframe.JTemplate; import com.fr.file.FILE; import com.fr.file.FileNodeFILE; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; -import com.fr.main.TemplateWorkBook; import com.fr.main.impl.WorkBook; import com.fr.nx.app.designer.cptx.io.DesignReadWritableProvider; import com.fr.nx.app.designer.monitor.DesignerMetricRecorder; @@ -44,8 +42,9 @@ public class CptCompileUtil { * 如果是cpt并且引擎设置正确,执行预编译,如果是cptx文件也执行预编译。在JStreamWork中,保存和另存为流程都进行了重新编译。 * 但是由于之前的DefaultTemplateResource.saveTemplate的原因导致JStreamWork::saveFile()不能执行--cptx的保存不能进行预编译, * 应该是流程的误改动,这里改回来,保存时仍然执行预编译。 + * 预编译本不应该受引擎模式的影响,但是cpt文件在设置为新引擎后是需要进行编译的 * */ - if (!isNewEngine(workbook, path)){ + if (!CptAndCptxCompatibilityUtil.enableNewEngine(workbook, path)){ return; } TransformResultInfo resultInfo = compile0(workbook, file); @@ -140,70 +139,6 @@ public class CptCompileUtil { || ComparatorUtils.equals(TransformResult.UNSUPPORT, result); } - /* - * 该另存为流程会改变文件内容,现在作为兼容的流程,以后可以随时删除该流程 - * */ - public static boolean hasChanged(String oldName, JTemplate jTemplate){ - FILE editingFILE = jTemplate.getEditingFILE(); - String path = editingFILE.getPath(); - //只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性 - boolean isChange = oldName.endsWith(".cptx") && path.endsWith(".cpt"); - if (isChange && !changeFrEngineAttr(jTemplate)){ - isChange = false; - } - //合并JStreamWork中另存为流程,cptx的另存为也需要重新预编译 - return (isChange || isSaveAs(jTemplate, oldName, path)); - } - - //cptx和设置了新引擎的cpt的另存也需要进行预编译 - private static boolean isSaveAs(JTemplate jTemplate, String oldName, String newName){ - return isNewEngine(jTemplate.getTarget(), newName) && ((FileExtension.CPTX.matchExtension(oldName) && FileExtension.CPTX.matchExtension(newName)) || (FileExtension.CPT.matchExtension(oldName) && FileExtension.CPT.matchExtension(newName))); - } - - private static boolean changeFrEngineAttr(JTemplate jTemplate){ - WorkSheet workSheet = gainWorkSheet(jTemplate); - if (workSheet == null){ - return false; - }else { - LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); - if (layerReportAttr == null){ - layerReportAttr = new LayerReportAttr(); - workSheet.setLayerReportAttr(layerReportAttr); - } - layerReportAttr.setClientPaging(true); - layerReportAttr.setNewEngine(true); - return true; - } - } - - - public static boolean isNewEngine(Object workBook, String fileName){ - WorkSheet workSheet = gainWorkSheet(workBook); - LayerReportAttr layerReportAttr = gainLayerReportAttr(workSheet); - return isNewEngine(layerReportAttr, fileName); - } - - private static LayerReportAttr gainLayerReportAttr(WorkSheet workSheet){ - if (workSheet != null){ - LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr(); - return layerReportAttr; - } else { - return null; - } - } - - private static WorkSheet gainWorkSheet(Object workBook){ - if (workBook == null || !(workBook instanceof TemplateWorkBook)){ - return null; - } - Report report = ((TemplateWorkBook) workBook).getReport(0); - return report instanceof WorkSheet ? (WorkSheet)report : null; - } - - private static boolean isNewEngine(LayerReportAttr layerReportAttr, String fileName){ - return (layerReportAttr!= null && layerReportAttr.isClientPaging() && layerReportAttr.isNewEngine()) || FileExtension.CPTX.matchExtension(fileName); - } - private static void unSupportLog(TransformResultInfo transformResultInfo){ TransformResult result = transformResultInfo.getResult(); //这里只打印模板转换不支持的信息,没有打印模板转换失败的信息 @@ -211,6 +146,4 @@ public class CptCompileUtil { FineLoggerFactory.getLogger().error(transformResultInfo.getTransformLog()); } } - - } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java b/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java index ba4348fb6c..67fd5f1e2d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java @@ -90,6 +90,7 @@ import com.fr.main.impl.WorkBookAdapter; import com.fr.main.impl.WorkBookX; import com.fr.main.parameter.ReportParameterAttr; import com.fr.nx.app.designer.menu.CalculateAttrAction; +import com.fr.nx.app.designer.utils.CptAndCptxCompatibilityUtil; import com.fr.nx.app.designer.utils.CptCompileUtil; import com.fr.poly.PolyDesigner; import com.fr.poly.creator.BlockCreator; @@ -719,7 +720,7 @@ public class JWorkBook extends JTemplate { } protected void addShortCut(MenuDef exportMenuDef, MenuDef excelExportMenuDef) { - if (CptCompileUtil.isNewEngine(this.getTarget(), getEditingFILE().getPath())){ + if (CptAndCptxCompatibilityUtil.enableNewEngine(this.getTarget(), getEditingFILE().getPath())){ exportMenuDef.addShortCut(excelExportMenuDef, new PDFExportAction(this), new WordExportAction(this), new SVGExportAction(this), new CSVExportAction(this), new TextExportAction(this)); }else { @@ -749,7 +750,7 @@ public class JWorkBook extends JTemplate { */ @Override public ShortCut[] shortcut4TemplateMenu() { - boolean isNewEngine = CptCompileUtil.isNewEngine(this.getTarget(), getEditingFILE().getPath()); + boolean enableNewEngine = CptAndCptxCompatibilityUtil.enableNewEngine(this.getTarget(), getEditingFILE().getPath()); ShortCut[] commonShortCut = ArrayUtils.addAll(new ShortCut[]{ new ReportWebAttrAction(this), new ReportExportAttrAction(this), @@ -760,7 +761,7 @@ public class JWorkBook extends JTemplate { new ReportWatermarkAction(this), new NameSeparator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Utils_Current_Sheet")), }, this.reportComposite.getEditingReportComponent().shortcut4TemplateMenu()); - if (isNewEngine){ + if (enableNewEngine){ return ArraysUtil.insert(commonShortCut, new CalculateAttrAction(this), 5); }else { return commonShortCut; diff --git a/designer-realize/src/main/java/com/fr/design/report/LayerReportEnginePane.java b/designer-realize/src/main/java/com/fr/design/report/LayerReportEnginePane.java index e744579d44..f64c6ad600 100644 --- a/designer-realize/src/main/java/com/fr/design/report/LayerReportEnginePane.java +++ b/designer-realize/src/main/java/com/fr/design/report/LayerReportEnginePane.java @@ -11,17 +11,14 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; -import com.fr.locale.InterProviderFactory; import com.fr.report.core.ReportUtils; import com.fr.report.stable.LayerReportAttr; import com.fr.report.worksheet.WorkSheet; - import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; -import java.awt.CardLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; @@ -165,8 +162,8 @@ public class LayerReportEnginePane extends BasicBeanPane { isPageQueryBox.setSelected(false); countPerPageEditor.setEnabled(false); } - radioButtons.get(0).setSelected(ob.isNewEngine()); - radioButtons.get(1).setSelected(!ob.isNewEngine()); + radioButtons.get(0).setSelected(ob.getEngineState() == 0 ? true : false); + radioButtons.get(1).setSelected(ob.getEngineState() == 1 ? true : false); } @Override @@ -179,7 +176,7 @@ public class LayerReportEnginePane extends BasicBeanPane { attr.setShowDataNumber(isShowDataNumber.isSelected()); for (int i = 0; i < radioButtons.size(); i++){ if (radioButtons.get(i).isSelected()){ - attr.setNewEngine((i == 0)); + attr.setEngineState(i); } } return attr;