Browse Source

REPORT-55243:联动修改因为报表引擎属性中标识引擎的数据类型的改变所需要修改的代码,将其中关于cpt和cptx兼容的流程部分放入一个工具类中(放在CptCompileUtil中不合适)

research/11.0
fly.li 3 years ago
parent
commit
f4b6071fb9
  1. 6
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  2. 88
      designer-base/src/main/java/com/fr/nx/app/designer/utils/CptAndCptxCompatibilityUtil.java
  3. 71
      designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java
  4. 7
      designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java
  5. 9
      designer-realize/src/main/java/com/fr/design/report/LayerReportEnginePane.java

6
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.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.main.impl.WorkBook; 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.app.designer.utils.CptCompileUtil;
import com.fr.nx.cptx.entry.metadata.CptxMetadata; import com.fr.nx.cptx.entry.metadata.CptxMetadata;
import com.fr.nx.cptx.utils.CptxFileUtils; import com.fr.nx.cptx.utils.CptxFileUtils;
@ -1470,7 +1471,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
* 设置新引擎后有不支持的功能时设计器中模板的标题需要加上兼容模式或者不支持分页引擎来提示用户 * 设置新引擎后有不支持的功能时设计器中模板的标题需要加上兼容模式或者不支持分页引擎来提示用户
* */ * */
private String compatibilityTip() { private String compatibilityTip() {
if (!CptCompileUtil.isNewEngine(this.getTarget(), getEditingFILE().getPath())){ if (!CptAndCptxCompatibilityUtil.enableNewEngine(this.getTarget(), getEditingFILE().getPath())){
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
String path = this.getEditingFILE().getPath(); String path = this.getEditingFILE().getPath();
@ -1686,8 +1687,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
* 2.在这三种情况下1.cptx文件另存为cpt文件 2.cptx另存为cptx文件 3.设置了新引擎的cpt文件另存为cpt文件 * 2.在这三种情况下1.cptx文件另存为cpt文件 2.cptx另存为cptx文件 3.设置了新引擎的cpt文件另存为cpt文件
* 因为文件的编译目录改变了需要重新预编译因此设置jTemplate的保存状态为false * 因为文件的编译目录改变了需要重新预编译因此设置jTemplate的保存状态为false
* */ * */
boolean hasChanged = CptCompileUtil.hasChanged(oldName, this); if (CptAndCptxCompatibilityUtil.needRecompile(oldName, this)){
if (hasChanged){
this.saved = false; this.saved = false;
} }
result = this.saveRealFile(); result = this.saveRealFile();

88
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);
}
}

71
designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java

@ -1,12 +1,10 @@
package com.fr.nx.app.designer.utils; package com.fr.nx.app.designer.utils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE; import com.fr.file.FILE;
import com.fr.file.FileNodeFILE; import com.fr.file.FileNodeFILE;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.main.TemplateWorkBook;
import com.fr.main.impl.WorkBook; import com.fr.main.impl.WorkBook;
import com.fr.nx.app.designer.cptx.io.DesignReadWritableProvider; import com.fr.nx.app.designer.cptx.io.DesignReadWritableProvider;
import com.fr.nx.app.designer.monitor.DesignerMetricRecorder; import com.fr.nx.app.designer.monitor.DesignerMetricRecorder;
@ -44,8 +42,9 @@ public class CptCompileUtil {
* 如果是cpt并且引擎设置正确执行预编译如果是cptx文件也执行预编译在JStreamWork中保存和另存为流程都进行了重新编译 * 如果是cpt并且引擎设置正确执行预编译如果是cptx文件也执行预编译在JStreamWork中保存和另存为流程都进行了重新编译
* 但是由于之前的DefaultTemplateResource.saveTemplate的原因导致JStreamWork::saveFile()不能执行--cptx的保存不能进行预编译 * 但是由于之前的DefaultTemplateResource.saveTemplate的原因导致JStreamWork::saveFile()不能执行--cptx的保存不能进行预编译
* 应该是流程的误改动这里改回来保存时仍然执行预编译 * 应该是流程的误改动这里改回来保存时仍然执行预编译
* 预编译本不应该受引擎模式的影响但是cpt文件在设置为新引擎后是需要进行编译的
* */ * */
if (!isNewEngine(workbook, path)){ if (!CptAndCptxCompatibilityUtil.enableNewEngine(workbook, path)){
return; return;
} }
TransformResultInfo resultInfo = compile0(workbook, file); TransformResultInfo resultInfo = compile0(workbook, file);
@ -140,70 +139,6 @@ public class CptCompileUtil {
|| ComparatorUtils.equals(TransformResult.UNSUPPORT, result); || 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){ private static void unSupportLog(TransformResultInfo transformResultInfo){
TransformResult result = transformResultInfo.getResult(); TransformResult result = transformResultInfo.getResult();
//这里只打印模板转换不支持的信息,没有打印模板转换失败的信息 //这里只打印模板转换不支持的信息,没有打印模板转换失败的信息
@ -211,6 +146,4 @@ public class CptCompileUtil {
FineLoggerFactory.getLogger().error(transformResultInfo.getTransformLog()); FineLoggerFactory.getLogger().error(transformResultInfo.getTransformLog());
} }
} }
} }

7
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.impl.WorkBookX;
import com.fr.main.parameter.ReportParameterAttr; import com.fr.main.parameter.ReportParameterAttr;
import com.fr.nx.app.designer.menu.CalculateAttrAction; 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.nx.app.designer.utils.CptCompileUtil;
import com.fr.poly.PolyDesigner; import com.fr.poly.PolyDesigner;
import com.fr.poly.creator.BlockCreator; import com.fr.poly.creator.BlockCreator;
@ -719,7 +720,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
} }
protected void addShortCut(MenuDef exportMenuDef, MenuDef excelExportMenuDef) { 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), exportMenuDef.addShortCut(excelExportMenuDef, new PDFExportAction(this), new WordExportAction(this), new SVGExportAction(this),
new CSVExportAction(this), new TextExportAction(this)); new CSVExportAction(this), new TextExportAction(this));
}else { }else {
@ -749,7 +750,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
*/ */
@Override @Override
public ShortCut[] shortcut4TemplateMenu() { 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[]{ ShortCut[] commonShortCut = ArrayUtils.addAll(new ShortCut[]{
new ReportWebAttrAction(this), new ReportWebAttrAction(this),
new ReportExportAttrAction(this), new ReportExportAttrAction(this),
@ -760,7 +761,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
new ReportWatermarkAction(this), new ReportWatermarkAction(this),
new NameSeparator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Utils_Current_Sheet")), new NameSeparator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Utils_Current_Sheet")),
}, this.reportComposite.getEditingReportComponent().shortcut4TemplateMenu()); }, this.reportComposite.getEditingReportComponent().shortcut4TemplateMenu());
if (isNewEngine){ if (enableNewEngine){
return ArraysUtil.insert(commonShortCut, new CalculateAttrAction(this), 5); return ArraysUtil.insert(commonShortCut, new CalculateAttrAction(this), 5);
}else { }else {
return commonShortCut; return commonShortCut;

9
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.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.locale.InterProviderFactory;
import com.fr.report.core.ReportUtils; import com.fr.report.core.ReportUtils;
import com.fr.report.stable.LayerReportAttr; import com.fr.report.stable.LayerReportAttr;
import com.fr.report.worksheet.WorkSheet; import com.fr.report.worksheet.WorkSheet;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JRadioButton; import javax.swing.JRadioButton;
import java.awt.CardLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -165,8 +162,8 @@ public class LayerReportEnginePane extends BasicBeanPane<LayerReportAttr> {
isPageQueryBox.setSelected(false); isPageQueryBox.setSelected(false);
countPerPageEditor.setEnabled(false); countPerPageEditor.setEnabled(false);
} }
radioButtons.get(0).setSelected(ob.isNewEngine()); radioButtons.get(0).setSelected(ob.getEngineState() == 0 ? true : false);
radioButtons.get(1).setSelected(!ob.isNewEngine()); radioButtons.get(1).setSelected(ob.getEngineState() == 1 ? true : false);
} }
@Override @Override
@ -179,7 +176,7 @@ public class LayerReportEnginePane extends BasicBeanPane<LayerReportAttr> {
attr.setShowDataNumber(isShowDataNumber.isSelected()); attr.setShowDataNumber(isShowDataNumber.isSelected());
for (int i = 0; i < radioButtons.size(); i++){ for (int i = 0; i < radioButtons.size(); i++){
if (radioButtons.get(i).isSelected()){ if (radioButtons.get(i).isSelected()){
attr.setNewEngine((i == 0)); attr.setEngineState(i);
} }
} }
return attr; return attr;

Loading…
Cancel
Save