From f170ea04ac0e648c931f45b6bee184c9cd694c2e Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Wed, 2 Jan 2019 17:03:11 +0800 Subject: [PATCH 1/6] =?UTF-8?q?REPORT-14022=20=E3=80=90=E9=9A=BE=E8=BF=98?= =?UTF-8?q?=E5=8E=9F=E3=80=91=E6=9C=80=E6=96=B0=E7=9A=8429=E5=8F=B7release?= =?UTF-8?q?=EF=BC=8C=E8=8E=AB=E5=90=8D=E5=85=B6=E5=A6=99=E7=9A=84=E5=8D=A1?= =?UTF-8?q?=E4=BD=8F=E5=BE=88=E4=B9=85=EF=BC=8C=E5=90=8E=E5=8F=B0=E7=99=BE?= =?UTF-8?q?=E5=88=86=E7=99=BE=E7=9A=84cpu=E5=8D=A0=E7=94=A8=20=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E9=80=81=EF=BC=8C=E5=8E=BB=E9=87=8D=EF=BC=9B?= =?UTF-8?q?=E6=AF=8F=E6=AC=A1query=20200=E6=9D=A1=EF=BC=8C=E6=94=BE?= =?UTF-8?q?=E5=85=A5=E5=86=85=E5=AD=98=EF=BC=8C=E5=8F=91=E9=80=81=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=86=8D=E8=BF=9B=E8=A1=8C=E6=96=B0=E7=9A=84=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=20=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=94=B9=E5=88=B0final?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/InformationCollector.java | 186 ++++++++++-------- 1 file changed, 104 insertions(+), 82 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java b/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java index 61b583c615..49ad7d6a37 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java @@ -89,11 +89,15 @@ public class InformationCollector implements XMLReadable, XMLWriter { private static final String ATTR_TEXT = "text"; private static final String ATTR_SOURCE = "source"; private static final String ATTR_TIME = "time"; + private static final String ATTR_TIMES = "times"; private static final String ATTR_TITLE = "title"; private static final String ATTR_USER_NAME = "username"; private static final String ATTR_UUID = "uuid"; + private static final String ATTR_ITEMS = "items"; private static final String ATTR_FUNCTION_ARRAY = "functionArray"; private static final int MAX_EACH_REQUEST_RECORD_COUNT = 200; + private static final int PAGE_SIZE = 200; + private long totalCount = -1; private static InformationCollector collector; @@ -214,26 +218,14 @@ public class InformationCollector implements XMLReadable, XMLWriter { if (currentTime - lastTime <= DELTA) { return; } - JSONArray content = getFunctionsContent(currentTime, lastTime); - boolean success = false; FineLoggerFactory.getLogger().info("Start sent function records to the cloud center..."); - String url = CloudCenter.getInstance().acquireUrlByKind(TABLE_FUNCTION_RECORD); - try { - for(int i=0;i 0){ - success = sendFunctionRecord(url, functionArray); - } - } - //服务器返回true, 说明已经获取成功, 更新最后一次发送时间 - if (success) { - this.lastTime = dateToString(); - FineLoggerFactory.getLogger().info("Function records successfully sent to the cloud center."); - } - }catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + queryAndSendOnePageFunctionContent(currentTime, lastTime, 0); + long page = (totalCount/PAGE_SIZE) + 1; + for(int i=1; i focusPoints = MetricRegistry.getMetric().find(FocusPoint.class,condition); + //第一次查询获取总记录数 + if(page == 0){ + totalCount = focusPoints.getTotalCount(); + } + sendThisPageFunctionContent(focusPoints); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + + private void sendThisPageFunctionContent(DataList focusPoints) { + String url = CloudCenter.getInstance().acquireUrlByKind(TABLE_FUNCTION_RECORD); + try { + JSONObject jsonObject = dealWithSendFunctionContent(focusPoints); + sendFunctionRecord(url, jsonObject); + } catch (JSONException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + + private JSONObject dealWithSendFunctionContent(DataList focusPoints) throws JSONException { + JSONObject jsonObject = new JSONObject(); + Map map = new HashMap<>(); + if(!focusPoints.isEmpty()){ + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + String bbsUserName = MarketConfig.getInstance().getBbsUsername(); + String uuid = envManager.getUUID(); + jsonObject.put(ATTR_UUID, uuid); + jsonObject.put(ATTR_USER_NAME, bbsUserName); + for(FocusPoint focusPoint : focusPoints.getList()) { + FunctionRecord functionRecord = getOneRecord(focusPoint); + if (map.containsKey(focusPoint.getId())) { + functionRecord.setTimes(functionRecord.getTimes() + 1); + map.put(focusPoint.getId(), functionRecord); + } else { + map.put(focusPoint.getId(), functionRecord); + } + } + jsonObject.put(ATTR_ITEMS, mapToJSONArray(map)); + } + return jsonObject; + } + + private JSONArray mapToJSONArray(Map map) throws JSONException { + JSONArray jsonArray = new JSONArray(); + for(String keys : map.keySet()){ + FunctionRecord functionRecord = (FunctionRecord)map.get(keys); + JSONObject jo = new JSONObject(); + jo.put(ATTR_ID, functionRecord.getId()); + jo.put(ATTR_TEXT, functionRecord.getText()); + jo.put(ATTR_SOURCE, functionRecord.getSource()); + jo.put(ATTR_TIME, functionRecord.getTime()); + jo.put(ATTR_TITLE, functionRecord.getTitle()); + jo.put(ATTR_TIMES, functionRecord.getTimes()); + jsonArray.put(jo); + } + return jsonArray; + } + + private void sendFunctionRecord(String url, JSONObject record) { boolean success = false; try { HashMap para = new HashMap<>(); @@ -260,12 +320,28 @@ public class InformationCollector implements XMLReadable, XMLWriter { para.put("content", record); String res = HttpToolbox.post(url, para); success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); + if (success) { + this.lastTime = dateToString(); + } else { + FineLoggerFactory.getLogger().error("Error occured when sent function records to the cloud center."); + } } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } - return success; } + private FunctionRecord getOneRecord(FocusPoint focusPoint) { + FunctionRecord functionRecord = new FunctionRecord(); + functionRecord.setId(focusPoint.getId() == null?StringUtils.EMPTY : focusPoint.getId()); + functionRecord.setText(focusPoint.getText() == null?StringUtils.EMPTY : focusPoint.getText()); + functionRecord.setSource(focusPoint.getSource()); + functionRecord.setTime(focusPoint.getTime().getTime()); + functionRecord.setTitle(focusPoint.getTitle() == null?StringUtils.EMPTY : focusPoint.getTitle()); + functionRecord.setUsername(MarketConfig.getInstance().getBbsUsername() == null?StringUtils.EMPTY : MarketConfig.getInstance().getBbsUsername()); + functionRecord.setUuid(DesignerEnvManager.getEnvManager().getUUID() == null?StringUtils.EMPTY : DesignerEnvManager.getEnvManager().getUUID()); + return functionRecord; + } + /** * 收集开始使用时间,发送信息 */ @@ -426,69 +502,6 @@ public class InformationCollector implements XMLReadable, XMLWriter { }); } - public JSONArray getFunctionsContent(long current, long last) { - //记录当前条数,达到200条合并成一个请求 - int count = 0; - JSONArray functionArray = new JSONArray(); - QueryCondition condition = QueryFactory.create() - .addRestriction(RestrictionFactory.lte(COLUMN_TIME, current)) - .addRestriction(RestrictionFactory.gte(COLUMN_TIME, last)); - try { - DataList focusPoints = MetricRegistry.getMetric().find(FocusPoint.class,condition); - TreeSet focusPointsList = new TreeSet<>(); - if(!focusPoints.isEmpty()){ - for(int i=0;i< focusPoints.getList().size();i++){ - FocusPoint focusPoint = focusPoints.getList().get(i); - if(focusPoint != null){ - if((++count <= MAX_EACH_REQUEST_RECORD_COUNT)){ - focusPointsList.add(getOneRecord(focusPoint)); - } else { - count = 0; - functionArray.put(setToJSONArray(focusPointsList)); - focusPointsList.add(getOneRecord(focusPoint)); - } - if(i == (focusPoints.getList().size() -1)){ - functionArray.put(setToJSONArray(focusPointsList)); - } - } - } - } - - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return functionArray; - } - - private FunctionRecord getOneRecord(FocusPoint focusPoint) { - FunctionRecord functionRecord = new FunctionRecord(); - functionRecord.setId(focusPoint.getId() == null?StringUtils.EMPTY : focusPoint.getId()); - functionRecord.setText(focusPoint.getText() == null?StringUtils.EMPTY : focusPoint.getText()); - functionRecord.setSource(focusPoint.getSource()); - functionRecord.setTime(focusPoint.getTime().getTime()); - functionRecord.setTitle(focusPoint.getTitle() == null?StringUtils.EMPTY : focusPoint.getTitle()); - functionRecord.setUsername(MarketConfig.getInstance().getBbsUsername() == null?StringUtils.EMPTY : MarketConfig.getInstance().getBbsUsername()); - functionRecord.setUuid(DesignerEnvManager.getEnvManager().getUUID() == null?StringUtils.EMPTY : DesignerEnvManager.getEnvManager().getUUID()); - return functionRecord; - } - - private JSONArray setToJSONArray(Set set) throws JSONException { - JSONArray jsonArray = new JSONArray(); - for(Iterator iter = set.iterator(); iter.hasNext(); ) { - FunctionRecord functionRecord = (FunctionRecord)iter.next(); - com.fr.json.JSONObject record = new com.fr.json.JSONObject(); - record.put(ATTR_ID, functionRecord.getId()); - record.put(ATTR_TEXT, functionRecord.getText()); - record.put(ATTR_SOURCE, functionRecord.getSource()); - record.put(ATTR_TIME, functionRecord.getTime()); - record.put(ATTR_TITLE, functionRecord.getTitle()); - record.put(ATTR_USER_NAME, functionRecord.getUsername()); - record.put(ATTR_UUID, functionRecord.getUuid()); - jsonArray.put(record); - } - return jsonArray; - } - private class StartStopTime implements XMLReadable, XMLWriter { private String startDate; @@ -533,6 +546,7 @@ public class InformationCollector implements XMLReadable, XMLWriter { private String text; private int source; private long time; + private int times = 1; private String title; private String username; private String uuid; @@ -548,6 +562,14 @@ public class InformationCollector implements XMLReadable, XMLWriter { this.id = id; } + public int getTimes() { + return times; + } + + public void setTimes(int times) { + this.times = times; + } + public String getText() { return text; } From 3e57d8a624c3b97970b1b55a6cf71cd3416e9b55 Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Wed, 2 Jan 2019 18:35:50 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=AC=A1=E6=95=B0bugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/mainframe/InformationCollector.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java b/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java index 49ad7d6a37..b71144774d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java @@ -285,7 +285,8 @@ public class InformationCollector implements XMLReadable, XMLWriter { for(FocusPoint focusPoint : focusPoints.getList()) { FunctionRecord functionRecord = getOneRecord(focusPoint); if (map.containsKey(focusPoint.getId())) { - functionRecord.setTimes(functionRecord.getTimes() + 1); + int times = ((FunctionRecord)map.get(focusPoint.getId())).getTimes() + 1; + functionRecord.setTimes(times); map.put(focusPoint.getId(), functionRecord); } else { map.put(focusPoint.getId(), functionRecord); From eeff85a4b294c40c4a6d78fb87a2c03149464604 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 2 Jan 2019 19:02:18 +0800 Subject: [PATCH 3/6] =?UTF-8?q?REPORT-14020=20=E5=8F=AF=E4=BB=A5=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=89=93=E5=BC=80=E8=AE=BE=E8=AE=A1=E5=99=A8=20?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E7=9A=84=E4=BB=A3=E7=A0=81=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E8=AF=AF=E4=BC=A0=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/utils/DesignUtils.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java b/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java index 77173cebb5..240176eef7 100644 --- a/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java @@ -65,12 +65,12 @@ public class DesignUtils { * @return 启动了返回true */ public static boolean isStarted() { -// try { -// new Socket("localhost", port); -// return true; -// } catch (Exception exp) { -// -// } + try { + new Socket("localhost", port); + return true; + } catch (Exception exp) { + + } return false; } From 4db0d2b9967f795732728a16e1f945d9be6e59c7 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Wed, 23 Jan 2019 17:35:11 +0800 Subject: [PATCH 4/6] =?UTF-8?q?REPORT-13202=20=E5=8C=85=E5=90=AB=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=8E=A7=E4=BB=B6=E7=9A=84=E6=A8=A1=E6=9D=BF=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E7=8E=AF=E5=A2=83=E5=90=8E=E5=AD=98=E5=82=A8=E5=87=BA?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/DesignModelAdapter.java | 2 +- .../design/file/HistoryTemplateListCache.java | 78 +++++++++++++ .../design/mainframe/AbstractAppProvider.java | 10 +- .../fr/design/mainframe/DesignerFrame.java | 68 ++++------- .../fr/design/mainframe/JTemplateFactory.java | 63 +++++++++++ .../main/java/com/fr/file/StashedFILE.java | 106 ++++++++++++++++++ .../mainframe/app/DesignerAppActivator.java | 6 +- .../com/fr/start/module/DesignerStartup.java | 61 ++++++---- 8 files changed, 319 insertions(+), 75 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/JTemplateFactory.java create mode 100644 designer-base/src/main/java/com/fr/file/StashedFILE.java diff --git a/designer-base/src/main/java/com/fr/design/DesignModelAdapter.java b/designer-base/src/main/java/com/fr/design/DesignModelAdapter.java index 4ebc64103d..84fd684ae8 100644 --- a/designer-base/src/main/java/com/fr/design/DesignModelAdapter.java +++ b/designer-base/src/main/java/com/fr/design/DesignModelAdapter.java @@ -134,7 +134,7 @@ public abstract class DesignModelAdapter stashFILEMap; + + /** + * 切换环境前将正在编辑的模板暂存起来,并且在新环境中重新读取一遍,暂存的不是模板文件的内容而是模板对象的内容 + *

+ * 防止新环境加载到的同名 Class 和模板对象中的 Class 不一致,在新环境存储失败 + * + * @see HistoryTemplateListCache#load() + */ + public void stash() { + FineLoggerFactory.getLogger().info("Env Change Template Stashing..."); + if (stashFILEMap == null) { + stashFILEMap = new HashMap(); + } else { + stashFILEMap.clear(); + } + int size = historyList.size(); + for (int i = 0; i < size; i++) { + JTemplate template = historyList.get(i); + FILE file = template.getEditingFILE(); + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + BaseBook target = template.getTarget(); + if (target != null) { + target.export(outputStream); + stashFILEMap.put(i, new StashedFILE(file, outputStream.toByteArray())); + } + // 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理 + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + FineLoggerFactory.getLogger().info("Env Change Template Stashed."); + } + + /** + * 切换环境前将正在编辑的模板暂存起来后,在新环境重新读取一遍 + *

+ * 防止新环境加载到的同名 Class 和模板对象中的 Class 不一致,在新环境存储失败 + * + * @see HistoryTemplateListCache#stash() + */ + public void load() { + FineLoggerFactory.getLogger().info("Env Change Template Loading..."); + if (stashFILEMap != null && stashFILEMap.size() != 0) { + int size = historyList.size(); + for (int i = 0; i < size; i++) { + try { + FILE stashedFile = stashFILEMap.get(i); + // 可能有模板 stash 失败的情况,在 load 的时候不更新它 + // 或者这个模板是被模板内存优化功能处理过的,不用处理 + if (stashedFile == null) { + continue; + } + JTemplate template = JTemplateFactory.createJTemplate(stashedFile); + if (template != null) { + historyList.set(i, template); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + stashFILEMap.clear(); + MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList); + MutilTempalteTabPane.getInstance().repaint(); + } + FineLoggerFactory.getLogger().info("Env Change Template Loaded."); + } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/AbstractAppProvider.java b/designer-base/src/main/java/com/fr/design/mainframe/AbstractAppProvider.java index 95a9696355..cc859ce178 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/AbstractAppProvider.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/AbstractAppProvider.java @@ -8,7 +8,7 @@ import com.fr.stable.fun.mark.API; * Created by Administrator on 2016/3/17/0017. */ @API(level = App.CURRENT_LEVEL) -public abstract class AbstractAppProvider extends AbstractProvider implements App{ +public abstract class AbstractAppProvider extends AbstractProvider implements App { public int currentAPILevel() { return CURRENT_LEVEL; @@ -21,12 +21,12 @@ public abstract class AbstractAppProvider extends AbstractProv @Override public void process() { - DesignerFrame.registApp(this); + JTemplateFactory.register(this); } - + @Override public void undo() { - - DesignerFrame.removeApp(this); + + JTemplateFactory.remove(this); } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java index 7ab92165bb..e148a10407 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java @@ -52,7 +52,6 @@ import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.manage.PluginFilter; import com.fr.plugin.observer.PluginEvent; import com.fr.plugin.observer.PluginEventListener; -import com.fr.stable.CoreConstants; import com.fr.stable.OperatingSystem; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; @@ -115,11 +114,9 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta private static final int MENU_HEIGHT = 26; - private static final Integer SECOND_LAYER = new Integer(100); + private static final Integer SECOND_LAYER = 100; - private static final Integer TOP_LAYER = new Integer((200)); - - private static java.util.List> appList = new java.util.ArrayList>(); + private static final Integer TOP_LAYER = 200; private List designerOpenedListenerList = new ArrayList<>(); @@ -326,7 +323,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta this.progressDialog = new ProgressDialog(this); } - public void closeAuthorityEditing(){ + public void closeAuthorityEditing() { DesignModeContext.switchTo(com.fr.design.base.mode.DesignerMode.NORMAL); WestRegionContainerPane.getInstance().replaceDownPane( TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter())); @@ -342,19 +339,22 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta * 注册app. * * @param app 注册app. + * @deprecated use {@link JTemplateFactory#register(App)} instead */ + @Deprecated public static void registApp(App app) { - - if (app != null) { - appList.add(app); - } + JTemplateFactory.register(app); } + /** + * 移除app + * + * @param app app + * @deprecated use {@link JTemplateFactory#remove(App)} instead + */ + @Deprecated public static void removeApp(App app) { - - if (app != null) { - appList.remove(app); - } + JTemplateFactory.remove(app); } /** @@ -1013,39 +1013,17 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta */ private void openFile(FILE tplFile) { - String fileName = tplFile.getName(); - int indexOfLastDot = fileName.lastIndexOf(CoreConstants.DOT); - if (indexOfLastDot < 0) { + JTemplate jt = JTemplateFactory.createJTemplate(tplFile); + if (jt == null) { return; } - String fileExtention = fileName.substring(indexOfLastDot + 1); - for (int i = 0, len = appList.size(); i < len; i++) { - App app = appList.get(i); - String[] defaultAppExtentions = app.defaultExtensions(); - boolean opened = false; - for (int j = 0; j < defaultAppExtentions.length; j++) { - if (defaultAppExtentions[j].equalsIgnoreCase(fileExtention)) { - // 不要catch - JTemplate jt = app.openTemplate(tplFile); - - if (jt == null) { - return; - } - // 新的form不往前兼容 - if (inValidDesigner(jt)) { - this.addAndActivateJTemplate(); - MutilTempalteTabPane.getInstance().setTemTemplate( - HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); - } else { - activeTemplate(jt); - } - opened = true; - break; - } - } - if (opened) { - break; - } + // 新的form不往前兼容 + if (inValidDesigner(jt)) { + this.addAndActivateJTemplate(); + MutilTempalteTabPane.getInstance().setTemTemplate( + HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + } else { + activeTemplate(jt); } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplateFactory.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplateFactory.java new file mode 100644 index 0000000000..c6a6f4a0de --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplateFactory.java @@ -0,0 +1,63 @@ +package com.fr.design.mainframe; + +import com.fr.file.FILE; +import com.fr.stable.CoreConstants; +import com.fr.third.javax.annotation.Nonnull; +import com.fr.third.javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public final class JTemplateFactory { + private static final List> ALL_APP = new ArrayList>(); + + private JTemplateFactory() { + } + + /** + * 生成设计器编辑模板对象 + * + * @param file 包含了模板名称,类型以及内容的文件 + * @return 设计器编辑的模板对象 + */ + @Nullable + public static JTemplate createJTemplate(@Nonnull FILE file) { + + String fileName = file.getName(); + int indexOfLastDot = fileName.lastIndexOf(CoreConstants.DOT); + if (indexOfLastDot < 0) { + return null; + } + String fileExtension = fileName.substring(indexOfLastDot + 1); + for (App app : ALL_APP) { + String[] defaultAppExtensions = app.defaultExtensions(); + for (String defaultAppExtension : defaultAppExtensions) { + if (defaultAppExtension.equalsIgnoreCase(fileExtension)) { + JTemplate jt = app.openTemplate(file); + if (jt != null) { + return jt; + } + } + } + } + return null; + } + + + /** + * 注册app. + * + * @param app 注册app. + */ + public static void register(App app) { + if (app != null) { + ALL_APP.add(app); + } + } + + public static void remove(App app) { + if (app != null) { + ALL_APP.remove(app); + } + } +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/file/StashedFILE.java b/designer-base/src/main/java/com/fr/file/StashedFILE.java new file mode 100644 index 0000000000..cacb1e9a90 --- /dev/null +++ b/designer-base/src/main/java/com/fr/file/StashedFILE.java @@ -0,0 +1,106 @@ +package com.fr.file; + +import javax.swing.Icon; +import javax.transaction.NotSupportedException; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * 切换环境用于暂存的文件类型 + */ +public class StashedFILE implements FILE { + + private FILE file; + private byte[] content; + + public StashedFILE(FILE file, byte[] content) { + this.file = file; + this.content = content; + } + + @Override + public String prefix() { + return file.prefix(); + } + + @Override + public boolean isDirectory() { + return file.isDirectory(); + } + + @Override + public String getName() { + return file.getName(); + } + + @Override + public Icon getIcon() { + return file.getIcon(); + } + + @Override + public String getPath() { + return file.getPath(); + } + + @Override + public void setPath(String path) { + throw new UnsupportedOperationException(); + } + + @Override + public FILE getParent() { + throw new UnsupportedOperationException(); + } + + @Override + public FILE[] listFiles() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean createFolder(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean mkfile() throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public boolean exists() { + return false; + } + + @Override + public void closeTemplate() throws Exception { + // do nothing + } + + @Override + public InputStream asInputStream() throws Exception { + return new ByteArrayInputStream(content); + } + + @Override + public OutputStream asOutputStream() throws Exception { + throw new NotSupportedException(); + } + + @Override + public String getEnvFullName() { + return file.getEnvFullName(); + } + + @Override + public boolean isMemFile() { + return true; + } + + @Override + public boolean isEnvFile() { + return false; + } +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/app/DesignerAppActivator.java b/designer-realize/src/main/java/com/fr/design/mainframe/app/DesignerAppActivator.java index f91b0d9a10..b13cdca853 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/app/DesignerAppActivator.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/app/DesignerAppActivator.java @@ -1,7 +1,7 @@ package com.fr.design.mainframe.app; import com.fr.design.mainframe.App; -import com.fr.design.mainframe.DesignerFrame; +import com.fr.design.mainframe.JTemplateFactory; import com.fr.module.Activator; import com.fr.module.extension.Prepare; @@ -17,7 +17,7 @@ public class DesignerAppActivator extends Activator implements Prepare { List appList = rightCollectMutable(App.KEY); for (App app : appList) { - DesignerFrame.registApp(app); + JTemplateFactory.register(app); } } @@ -26,7 +26,7 @@ public class DesignerAppActivator extends Activator implements Prepare { List appList = rightCollectMutable(App.KEY); for (App app : appList) { - DesignerFrame.removeApp(app); + JTemplateFactory.remove(app); } } diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java b/designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java index 701a6936c1..4a3db7b2cc 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java +++ b/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,64 @@ 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() { + /*切换环境前,关闭所有相关模块,最后执行*/ + listenEvent(WorkspaceEvent.BeforeSwitch, new Listener(Integer.MIN_VALUE) { @Override - public void on(Event event, Workspace param) { - + public void on(Event event, Workspace current) { getSub(EnvBasedModule.class).stop(); } }); + /*切换环境后,重新启动所有相关模块,最先执行*/ listenEvent(WorkspaceEvent.AfterSwitch, new Listener(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(Integer.MAX_VALUE) { + @Override + public void on(Event event, Workspace workspace) { + HistoryTemplateListCache.getInstance().stash(); + } + }); + + /*切换环境后,装载一下打开的所有文件对象,优先级低于默认优先级,要后于 启动相关模块部分 被触发*/ + listenEvent(WorkspaceEvent.AfterSwitch, new Listener(Integer.MIN_VALUE) { + @Override + public void on(Event event, Workspace workspace) { + HistoryTemplateListCache.getInstance().load(); } }); } From 003c234bce787ca340ec7bce362970ebff07ccef Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Thu, 24 Jan 2019 17:18:53 +0800 Subject: [PATCH 5/6] =?UTF-8?q?REPORT-14515=20=E7=8E=AF=E5=A2=83=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=90=8E=E6=A8=A1=E6=9D=BF=E5=8F=A6=E5=AD=98=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E6=B2=A1=E6=9C=89=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/file/HistoryTemplateListCache.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index e162fee3e6..f790eca94f 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -372,6 +372,12 @@ public class HistoryTemplateListCache implements CallbackEvent { JTemplate template = JTemplateFactory.createJTemplate(stashedFile); if (template != null) { historyList.set(i, template); + // 替换当前正在编辑的模板,使用添加并激活的方式,以便使用统一的入口来处理监听事件 + if (isCurrentEditingFile(template.getPath())) { + DesignerContext.getDesignerFrame().addAndActivateJTemplate(template); + setCurrentEditingTemplate(template); + FineLoggerFactory.getLogger().info("Env Change Current Editing Template."); + } } } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); From 553bb2a605b0cd9b71f241ebd0bf374ef765ef0c Mon Sep 17 00:00:00 2001 From: Hades Date: Fri, 25 Jan 2019 11:23:28 +0800 Subject: [PATCH 6/6] =?UTF-8?q?MOBILE-19684=20=E5=90=8C=E6=97=B6=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E9=A1=B6=E9=83=A8=E5=8F=82=E6=95=B0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=92=8C=E5=AF=BC=E8=88=AA=E5=8F=82=E6=95=B0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E8=AE=BE=E8=AE=A1=E5=99=A8=E6=98=BE=E7=A4=BA=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/designer/mobile/ParaMobileDefinePane.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ParaMobileDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ParaMobileDefinePane.java index 7e0f3b940a..b924b5c55a 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ParaMobileDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ParaMobileDefinePane.java @@ -21,7 +21,6 @@ import com.fr.form.ui.container.WParameterLayout; import com.fr.form.ui.container.WSortLayout; import com.fr.general.ComparatorUtils; import com.fr.general.SiteCenter; -import com.fr.json.JSONException; import com.fr.log.FineLoggerFactory; import com.fr.report.ExtraReportClassManager; import com.fr.report.fun.MobileParamStyleProvider; @@ -109,9 +108,9 @@ public class ParaMobileDefinePane extends MobileWidgetDefinePane { Item[] items = new Item[pluginCreators.size() + 1]; MobileParamStyleProvider provider = new DefaultMobileParamStyle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Default")); items[0] = new Item(provider.descriptor(), provider); - for (int i = 0; i < pluginCreators.size(); i++) { - provider = pluginCreators.iterator().next(); - items[i + 1] = new Item(provider.descriptor(), provider); + int i = 1; + for (MobileParamStyleProvider mobileParamStyleProvider : pluginCreators) { + items[i++] = new Item(mobileParamStyleProvider.descriptor(), mobileParamStyleProvider); } return items; } @@ -161,6 +160,7 @@ public class ParaMobileDefinePane extends MobileWidgetDefinePane { private UIComboBox getParamLocationComboBox() { items = getItems(); + UIComboBox paramLocationComoBox = new UIComboBox(items); paramLocationComoBox.addItemListener(new ItemListener() { @Override @@ -218,7 +218,7 @@ public class ParaMobileDefinePane extends MobileWidgetDefinePane { break; } } - } catch (JSONException e) { + } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } paramLocationComboBox.setSelectedIndex(index);