You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
4.4 KiB
108 lines
4.4 KiB
7 years ago
|
package com.fr.design.actions.file;
|
||
|
|
||
7 years ago
|
import com.fr.base.extension.FileExtension;
|
||
7 years ago
|
import com.fr.design.fun.PreviewProvider;
|
||
7 years ago
|
import com.fr.design.mainframe.DesignerContext;
|
||
|
import com.fr.design.mainframe.JTemplate;
|
||
|
import com.fr.design.utils.DesignUtils;
|
||
|
import com.fr.file.FILE;
|
||
|
import com.fr.file.FileNodeFILE;
|
||
|
import com.fr.general.GeneralUtils;
|
||
|
import com.fr.general.Inter;
|
||
|
import com.fr.general.web.ParameterConstants;
|
||
|
import com.fr.stable.project.ProjectConstants;
|
||
7 years ago
|
import com.fr.stable.web.AbstractWebletCreator;
|
||
7 years ago
|
|
||
7 years ago
|
import javax.swing.JOptionPane;
|
||
7 years ago
|
import java.util.Collections;
|
||
7 years ago
|
import java.util.Map;
|
||
|
|
||
|
public final class WebPreviewUtils {
|
||
|
|
||
7 years ago
|
public static void preview(JTemplate<?, ?> jt) {
|
||
7 years ago
|
preview(jt, jt.getPreviewType());
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
@SuppressWarnings("unchecked")
|
||
|
public static void preview(JTemplate<?, ?> jt, PreviewProvider provider) {
|
||
|
String baseRoute = jt.route();
|
||
|
actionPerformed(jt, baseRoute, provider == null ? Collections.EMPTY_MAP : provider.parametersForPreview(), ParameterConstants.VIEWLET);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
private static void actionPerformed(JTemplate<?, ?> jt, String baseRoute, Map<String, Object> map, String actionType) {
|
||
7 years ago
|
if (jt == null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
DesignerContext.getDesignerFrame().refreshToolbar();
|
||
|
|
||
|
jt.stopEditing();
|
||
|
/*
|
||
7 years ago
|
* alex:如果没有保存,先保存到Env
|
||
|
*
|
||
|
* 如果保存失败,不执行下面的WebPreview
|
||
|
*/
|
||
7 years ago
|
if (!jt.isSaved() && !jt.saveTemplate2Env()) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
FILE currentTemplate = jt.getEditingFILE();
|
||
|
// carl:是否是保存在运行环境下的模板,不是就不能被预览
|
||
|
if (currentTemplate instanceof FileNodeFILE) {
|
||
7 years ago
|
browseUrl(currentTemplate, baseRoute, map, actionType, jt);
|
||
7 years ago
|
} else {
|
||
|
// 说明模板没有保存在报表运行环境下面,提示用户
|
||
|
int selVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Web_Preview_Message"),
|
||
|
Inter.getLocText("Preview_ToolTips"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
|
||
|
|
||
|
if (JOptionPane.OK_OPTION == selVal) {
|
||
|
if (!jt.saveAsTemplate2Env()) {
|
||
|
return;
|
||
|
}
|
||
|
currentTemplate = jt.getEditingFILE();
|
||
7 years ago
|
browseUrl(currentTemplate, baseRoute, map, actionType, jt);
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
private static void browseUrl(FILE currentTemplate, String baseRoute, Map<String, Object> map, String actionType, JTemplate<?, ?> jt) {
|
||
7 years ago
|
if (!(currentTemplate instanceof FileNodeFILE)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (currentTemplate.exists()) {
|
||
|
String path = currentTemplate.getPath();
|
||
|
if (path.startsWith(ProjectConstants.REPORTLETS_NAME)) {
|
||
|
path = path.substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
|
||
|
|
||
|
java.util.List<String> parameterNameList = new java.util.ArrayList<String>();
|
||
|
java.util.List<String> parameterValueList = new java.util.ArrayList<String>();
|
||
|
|
||
7 years ago
|
// 暂时屏蔽cptx直接访问
|
||
|
if (path.endsWith(FileExtension.CPTX.getSuffix())) {
|
||
|
path = path.substring(0, path.length() - 1);
|
||
|
parameterNameList.add(AbstractWebletCreator.FORMAT);
|
||
|
parameterValueList.add(AbstractWebletCreator.X);
|
||
|
}
|
||
|
|
||
7 years ago
|
parameterNameList.add(actionType);
|
||
|
parameterValueList.add(path);
|
||
|
if (map != null) {
|
||
|
for (String key : map.keySet()) {
|
||
|
parameterNameList.add(key);
|
||
|
parameterValueList.add(GeneralUtils.objectToString(map.get(key)));
|
||
|
}
|
||
|
}
|
||
7 years ago
|
DesignUtils.visitEnvServerByParameters(baseRoute, parameterNameList.toArray(new String[parameterNameList.size()]), parameterValueList.toArray(new String[parameterValueList.size()]));
|
||
7 years ago
|
}
|
||
|
} else {
|
||
|
int selVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Web_Preview_Message"),
|
||
|
Inter.getLocText("Preview_ToolTips"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
|
||
|
if (JOptionPane.OK_OPTION == selVal) {
|
||
|
if (!jt.saveAsTemplate()) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
}
|