Browse Source

Merge branch 'release/10.0' of http://cloud.finedevelop.com:2015/scm/~hades/design into release/10.0

bugfix/10.0
Hades 6 years ago
parent
commit
4ec4c73c51
  1. 79
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  2. 13
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  3. 2
      designer-base/src/main/resources/com/fr/design/insert/formula/variable/cn/servletURL.txt
  4. 2
      designer-base/src/main/resources/com/fr/design/insert/formula/variable/en/servletURL.txt
  5. 4
      designer-form/src/main/java/com/fr/design/designer/creator/ErrorCreator.java
  6. 4
      designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java
  7. 29
      designer-form/src/test/java/com/fr/form/ui/WidgetNameCopyTest.java
  8. 82
      designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java
  9. 60
      designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

79
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java

@ -1,6 +1,8 @@
package com.fr.design.file;
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.base.io.BaseBook;
import com.fr.base.io.IOFile;
import com.fr.design.DesignerEnvManager;
import com.fr.design.base.mode.DesignModeContext;
import com.fr.design.data.DesignTableDataManager;
@ -18,10 +20,14 @@ import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.io.FilenameUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
/**
* 历史模板缓存
@ -305,4 +311,77 @@ public class HistoryTemplateListCache implements CallbackEvent {
}
return true;
}
/**
* 切换环境时暂存打开的模板内容key 是在历史中的indexvalue 是模板xml 内容byte[]
*/
private Map<Integer, byte[]> bytesMap;
/**
* 切换环境前将正在编辑的模板暂存起来并且在新环境中重新读取一遍暂存的不是模板文件的内容而是模板对象的内容
* <p>
* 防止新环境加载到的同名 Class 和模板对象中的 Class 不一致在新环境存储失败
*
* @see HistoryTemplateListCache#load()
*/
public void stash() {
FineLoggerFactory.getLogger().info("Env Change Template Stashing...");
if (bytesMap == null) {
bytesMap = new HashMap<Integer, byte[]>();
} else {
bytesMap.clear();
}
int size = historyList.size();
for (int i = 0; i < size; i++) {
JTemplate<?, ?> template = historyList.get(i);
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BaseBook target = template.getTarget();
if (target != null) {
target.export(outputStream);
bytesMap.put(i, outputStream.toByteArray());
}
// 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
FineLoggerFactory.getLogger().info("Env Change Template Stashed.");
}
/**
* 切换环境前将正在编辑的模板暂存起来后在新环境重新读取一遍
* <p>
* 防止新环境加载到的同名 Class 和模板对象中的 Class 不一致在新环境存储失败
*
* @see HistoryTemplateListCache#stash()
*/
public void load() {
FineLoggerFactory.getLogger().info("Env Change Template Loading...");
if (bytesMap != null && bytesMap.size() != 0) {
int size = historyList.size();
for (int i = 0; i < size; i++) {
try {
byte[] bytes = bytesMap.get(i);
// 可能有模板 stash 失败的情况,在 load 的时候不更新它
if (bytes == null) {
continue;
}
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
BaseBook target = historyList.get(i).getTarget();
if (target != null) {
// todo readStream 这个行为应该上升到 BaseBook 上
((IOFile) target).readStream(inputStream);
}
// 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
bytesMap.clear();
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList);
MutilTempalteTabPane.getInstance().repaint();
}
FineLoggerFactory.getLogger().info("Env Change Template Loaded.");
}
}

13
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -522,19 +522,6 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
if (editingFILE == null) {
return false;
}
// //检查一下连接是否成功
// try {
// if (FRContext.getCommonOperator() != null && !FRContext.getCommonOperator().testServerConnectionWithOutShowMessagePane()) {
// //连接不成功,提示
// JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
// com.fr.design.i18n.Toolkit.i18nText(new String[]{"server_disconnected", "template_unsaved"}, new String[]{",", "!"})
// , com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Error"), JOptionPane.ERROR_MESSAGE);
// return false;
// }
// } catch (Exception e) {
// FineLoggerFactory.getLogger().error(e.getMessage(), e);
// }
// 检查一下editingFILE是不是已存在的文件,如果不存在则用saveAs
if (!editingFILE.exists()) {

2
designer-base/src/main/resources/com/fr/design/insert/formula/variable/cn/servletURL.txt

@ -1 +1 @@
假如访问:http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,servletURL指的是:/WebReport/ReportServer
假如访问的是http://localhost:8075/webroot/decision/view/report?viewlet=workbook1.cpt,servletURL指的是:/webroot/decision/view/report

2
designer-base/src/main/resources/com/fr/design/insert/formula/variable/en/servletURL.txt

@ -1 +1 @@
http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,servletURL is /WebReport/ReportServer
http://localhost:8075/webroot/decision/view/report?viewlet=workbook1.cpt,servletURL is /webroot/decision/view/report

4
designer-form/src/main/java/com/fr/design/designer/creator/ErrorCreator.java

@ -1,7 +1,7 @@
package com.fr.design.designer.creator;
import com.fr.form.ui.ErrorMarker;
import com.fr.form.ui.Widget;
import com.fr.form.ui.WidgetErrorMarker;
import com.fr.stable.StringUtils;
import java.awt.*;
@ -18,7 +18,7 @@ public class ErrorCreator extends NullCreator {
@Override
protected String showText() {
ErrorMarker marker = (ErrorMarker)toData();
WidgetErrorMarker marker = (WidgetErrorMarker)toData();
String text = marker.getWidgetValue().getDisplayValue();
if (StringUtils.isEmpty(text)) {
return super.showText();

4
designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java

@ -26,7 +26,6 @@ import com.fr.form.ui.ComboCheckBox;
import com.fr.form.ui.DateEditor;
import com.fr.form.ui.EditorHolder;
import com.fr.form.ui.ElementCaseEditor;
import com.fr.form.ui.ErrorMarker;
import com.fr.form.ui.FileEditor;
import com.fr.form.ui.FreeButton;
import com.fr.form.ui.IframeEditor;
@ -42,6 +41,7 @@ import com.fr.form.ui.TextEditor;
import com.fr.form.ui.TreeComboBoxEditor;
import com.fr.form.ui.TreeEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.WidgetErrorMarker;
import com.fr.form.ui.container.WAbsoluteBodyLayout;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WBorderLayout;
@ -160,7 +160,7 @@ public class XCreatorUtils {
objectMap.put(NameWidget.class, XNameWidget.class);
objectMap.put(CardSwitchButton.class, XCardSwitchButton.class);
objectMap.put(CardAddButton.class, XCardAddButton.class);
objectMap.put(ErrorMarker.class, ErrorCreator.class);
objectMap.put(WidgetErrorMarker.class, ErrorCreator.class);
}
private static void reInitExtra() {

29
designer-form/src/test/java/com/fr/form/ui/WidgetNameCopyTest.java

@ -0,0 +1,29 @@
package com.fr.form.ui;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.form.main.Form;
import com.fr.general.ComparatorUtils;
import junit.framework.TestCase;
import java.awt.Dimension;
/**
* @author kerry
* @date 2018/7/27
*/
public class WidgetNameCopyTest extends TestCase {
public void testWidgetNameCopy() throws Exception {
Widget button = new FreeButton();
Form form = new Form();
button.setWidgetName("button0");
XCreator xCreator = XCreatorUtils.createXCreator(button, new Dimension(100, 100));
XCreator copyXcreator1 = FormSelectionUtils.copyXcreator(form, xCreator);
XCreator copyXcreator2 = FormSelectionUtils.copyXcreator(form, xCreator);
copyXcreator1.toData().setWidgetName("button_test");
assertTrue(!ComparatorUtils.equals(copyXcreator2.toData().getWidgetName(), copyXcreator1.toData().getWidgetName()));
}
}

82
designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java

@ -3,15 +3,16 @@ package com.fr.design.mainframe.errorinfo;
import com.fr.base.FRContext;
import com.fr.design.mainframe.SiteCenterToken;
import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils;
import com.fr.general.CommonIOUtils;
import com.fr.general.GeneralContext;
import com.fr.general.IOUtils;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONException;
import com.fr.general.http.HttpResponseType;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject;
import com.fr.license.function.VT4FR;
import com.fr.log.FineLoggerFactory;
import com.fr.log.LogHandler;
import com.fr.stable.ArrayUtils;
import com.fr.stable.EnvChangedListener;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
@ -93,9 +94,7 @@ public class ErrorInfoUploader {
try {
String downloadURL = CloudCenter.getInstance().acquireUrlByKind("solution.download", "http://cloud.fanruan.com/api/solution");
downloadURL = String.format("%s?token=%s", downloadURL, SiteCenterToken.generateToken());
HttpClient hc = new HttpClient(downloadURL);
hc.asGet();
InputStream in = hc.getResponseStream();
InputStream in = HttpToolbox.post(downloadURL, new HashMap<String, Object>(), HttpResponseType.STREAM);
StableUtils.makesureFileExist(localCacheZip);
FileOutputStream out = new FileOutputStream(localCacheZip);
IOUtils.copyBinaryTo(in, out);
@ -114,15 +113,11 @@ public class ErrorInfoUploader {
// 判断本地文件大小.
String checkURL = CloudCenter.getInstance().acquireUrlByKind("solution.check", "http://cloud.fanruan.com/api/solution/cache/check");
checkURL = String.format("%s?token=%s", checkURL, SiteCenterToken.generateToken());
HttpClient client = new HttpClient(checkURL);
client.asGet();
if (client.isServerAlive()) {
try {
JSONObject res = new JSONObject(client.getResponseText());
// 简单粗暴, 直接判断文件大小.
return res.optLong("version") != localCacheZip.length();
} catch (JSONException ignore) {
}
try {
JSONObject res = new JSONObject(HttpToolbox.get(checkURL));
// 简单粗暴, 直接判断文件大小.
return res.optLong("version") != localCacheZip.length();
} catch (Exception ignore) {
}
return false;
}
@ -140,27 +135,29 @@ public class ErrorInfoUploader {
}
File[] files = folder.listFiles();
if (files.length > MAX_ERROR_SIZE) {
StableUtils.deleteFile(folder);
if (ArrayUtils.getLength(files) > MAX_ERROR_SIZE) {
CommonIOUtils.deleteFile(folder);
return;
}
try {
for (File file : files) {
String filePath = file.getPath();
String suffix = filePath.substring(filePath.lastIndexOf("."));
if (suffix.endsWith(SUFFIX)) {
Thread.sleep(1000L);
String content = IOUtils.inputStream2String(new FileInputStream(file));
if (content.length() > MAX_ERROR_SIZE) {
file.delete();
continue;
}
String url = CloudCenter.getInstance().acquireUrlByKind("design.error");
if (sendErroInfo(url, content)) {
file.delete();
if (ArrayUtils.isNotEmpty(files)) {
for (File file : files) {
String filePath = file.getPath();
String suffix = filePath.substring(filePath.lastIndexOf("."));
if (suffix.endsWith(SUFFIX)) {
Thread.sleep(1000L);
String content = IOUtils.inputStream2String(new FileInputStream(file));
if (content.length() > MAX_ERROR_SIZE) {
CommonIOUtils.deleteFile(file);
continue;
}
String url = CloudCenter.getInstance().acquireUrlByKind("design.error");
if (sendErrorInfo(url, content)) {
CommonIOUtils.deleteFile(file);
}
}
}
}
@ -169,25 +166,18 @@ public class ErrorInfoUploader {
}
}
private boolean sendErroInfo(String url, String content) {
HashMap<String, String> para = new HashMap<>();
private boolean sendErrorInfo(String url, String content) {
HashMap<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", content);
HttpClient httpClient = new HttpClient(url, para, true);
httpClient.asGet();
if (!httpClient.isServerAlive()) {
return false;
}
String res = httpClient.getResponseText();
boolean success;
try {
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (Exception ex) {
success = true;
String responseText = HttpToolbox.post(url, para);
return "success".equals(new JSONObject(responseText).get("status"));
} catch (Exception ignore) {
}
return success;
return false;
}

60
designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

@ -1,6 +1,7 @@
package com.fr.start.module;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.mainframe.DesignerContext;
import com.fr.event.Event;
import com.fr.event.Listener;
@ -28,13 +29,13 @@ public class DesignerStartup extends Activator {
@Override
@Metrics
public void start() {
startSub(PreStartActivator.class);
//启动基础部分
startSub(BasicActivator.class);
final String[] args = getModule().upFindSingleton(StartupArgs.class).get();
final Designer designer = new Designer(args);
startSub(DesignerWorkspaceProvider.class);
registerEnvListener();
//启动env
@ -49,7 +50,7 @@ public class DesignerStartup extends Activator {
}
});
service.submit(new Runnable() {
@Override
public void run() {
try {
@ -63,46 +64,65 @@ public class DesignerStartup extends Activator {
DesignerContext.getDesignerFrame().setVisible(true);
//启动画面结束
SplashContext.getInstance().hide();
DesignerContext.getDesignerFrame().getProgressDialog().setVisible(true);
startSub(StartFinishActivator.class);
FineRuntime.startFinish();
}
private void browserDemo() {
if (getModule().leftFindSingleton(StartupArgs.class) != null && getModule().leftFindSingleton(StartupArgs.class).isDemo()) {
ServerStarter.browserDemoURL();
}
}
/**
* 切换环境时重新启动所有相关模块
* 注册切换环境前后事件监听
*/
private void registerEnvListener() {
/*切换环境前,关闭所有相关模块*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>() {
@Override
public void on(Event event, Workspace param) {
public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).stop();
}
});
/*切换环境后,重新启动所有相关模块*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override
public void on(Event event, Workspace param) {
public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).start();
ExecutorService service = Executors.newSingleThreadExecutor();
service.submit(new Runnable() {
@Override
public void run() {
FineEmbedServer.start();
}
});
service.shutdown();
// 切换后的环境是本地环境才启动内置服务器
if (current.isLocal()) {
ExecutorService service = Executors.newSingleThreadExecutor();
service.submit(new Runnable() {
@Override
public void run() {
FineEmbedServer.start();
}
});
service.shutdown();
}
}
});
/*切换环境前,存储一下打开的所有文件对象,优先级高于默认优先级,要先于 关闭相关模块部分 被触发*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override
public void on(Event event, Workspace workspace) {
HistoryTemplateListCache.getInstance().stash();
}
});
/*切换环境后,装载一下打开的所有文件对象,优先级低于默认优先级,要后于 启动相关模块部分 被触发*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MIN_VALUE) {
@Override
public void on(Event event, Workspace workspace) {
HistoryTemplateListCache.getInstance().load();
}
});
}

Loading…
Cancel
Save