From 4418950c11964bca1176e13b6e2de882f8922220 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Tue, 4 Jun 2019 15:14:55 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-17527=20=E6=8E=A8=E9=80=81=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E8=AE=BE=E8=AE=A1=E8=A7=A6=E5=8F=91=E7=9A=84=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E9=A2=84=E8=A7=88=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/actions/file/WebPreviewUtils.java | 89 ++++++++++++------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/actions/file/WebPreviewUtils.java b/designer-base/src/main/java/com/fr/design/actions/file/WebPreviewUtils.java index de223e2ccc..f3bfe5622e 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/WebPreviewUtils.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/WebPreviewUtils.java @@ -1,7 +1,8 @@ package com.fr.design.actions.file; -import com.fr.base.vcs.DesignerMode; +import com.fr.design.base.mode.DesignModeContext; import com.fr.design.fun.PreviewProvider; +import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.design.utils.DesignUtils; @@ -10,41 +11,56 @@ import com.fr.file.FileNodeFILE; import com.fr.general.GeneralUtils; import com.fr.general.web.ParameterConstants; import com.fr.stable.project.ProjectConstants; +import com.fr.web.referrer.DesignSessionReferrer; -import javax.swing.JOptionPane; -import java.util.Collections; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import static javax.swing.JOptionPane.OK_CANCEL_OPTION; +import static javax.swing.JOptionPane.OK_OPTION; +import static javax.swing.JOptionPane.WARNING_MESSAGE; +import static javax.swing.JOptionPane.showConfirmDialog; + public final class WebPreviewUtils { public static void preview(JTemplate jt) { preview(jt, jt.getPreviewType()); } - @SuppressWarnings("unchecked") public static void preview(JTemplate jt, PreviewProvider provider) { String baseRoute = jt.route(); - if (provider == null) { - actionPerformed(jt, baseRoute, Collections.EMPTY_MAP, ParameterConstants.VIEWLET); - } else { - actionPerformed(jt, baseRoute, provider.parametersForPreview(), provider.getActionType()); + + String previewType = ParameterConstants.VIEWLET; + Map paraMap = new HashMap<>(getExtraPara()); + + if (provider != null) { + Map providerParaMap = provider.parametersForPreview(); + if (providerParaMap != null) { + paraMap.putAll(providerParaMap); + } + previewType = provider.getActionType(); } + actionPerformed(jt, baseRoute, paraMap, previewType); + } + + private static Map getExtraPara() { + Map extraPara = new HashMap<>(); + if (DesignModeContext.isVcsMode()) { + extraPara.put("mode", DesignModeContext.getMode().toString()); + + } + extraPara.putAll(new DesignSessionReferrer.Builder().referrerMap()); + + return extraPara; } private static void actionPerformed(JTemplate jt, String baseRoute, Map map, String actionType) { if (jt == null) { return; } - - if (map == null || map == Collections.EMPTY_MAP) { - map = new HashMap<>(); - } - if (DesignerMode.isVcsMode()) { - map.put("mode", DesignerMode.getMode().toString()); - } DesignerContext.getDesignerFrame().refreshToolbar(); - jt.stopEditing(); /* * alex:如果没有保存,先保存到Env @@ -54,17 +70,20 @@ public final class WebPreviewUtils { if (!jt.isSaved() && !jt.saveTemplate2Env()) { return; } - FILE currentTemplate = jt.getEditingFILE(); // carl:是否是保存在运行环境下的模板,不是就不能被预览 if (currentTemplate instanceof FileNodeFILE) { browseUrl(currentTemplate, baseRoute, map, actionType, jt); } else { // 说明模板没有保存在报表运行环境下面,提示用户 - int selVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Web_Preview_Message"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview_Tool_Tips"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); + 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 (JOptionPane.OK_OPTION == selVal) { + if (OK_OPTION == selVal) { if (!jt.saveAsTemplate2Env()) { return; } @@ -74,7 +93,10 @@ public final class WebPreviewUtils { } } - private static void browseUrl(FILE currentTemplate, String baseRoute, Map map, String actionType, JTemplate jt) { + private static void browseUrl(FILE currentTemplate, + String baseRoute, + Map map, + String actionType, JTemplate jt) { if (!(currentTemplate instanceof FileNodeFILE)) { return; } @@ -85,8 +107,8 @@ public final class WebPreviewUtils { path = path.substring(ProjectConstants.REPORTLETS_NAME.length() + 1); } - java.util.List parameterNameList = new java.util.ArrayList(); - java.util.List parameterValueList = new java.util.ArrayList(); + List parameterNameList = new ArrayList<>(); + List parameterValueList = new ArrayList<>(); parameterNameList.add(actionType); parameterValueList.add(path); @@ -96,14 +118,21 @@ public final class WebPreviewUtils { parameterValueList.add(GeneralUtils.objectToString(map.get(key))); } } - DesignUtils.visitEnvServerByParameters(baseRoute, parameterNameList.toArray(new String[parameterNameList.size()]), parameterValueList.toArray(new String[parameterValueList.size()])); + DesignUtils.visitEnvServerByParameters( + baseRoute, + parameterNameList.toArray(new String[0]), + parameterValueList.toArray(new String[0]) + ); } else { - int selVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Web_Preview_Message"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview_Tool_Tips"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); - if (JOptionPane.OK_OPTION == selVal) { - if (!jt.saveAsTemplate()) { - return; - } + 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) { + jt.saveAsTemplate(); } } }