From 1564fa8bc14ebaa8186faf29e9fa38e86aeadfc8 Mon Sep 17 00:00:00 2001 From: Hades Date: Tue, 11 Feb 2020 20:32:53 +0800 Subject: [PATCH 1/5] =?UTF-8?q?REPORT-17834=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/DesignerEnvManager.java | 15 +- .../java/com/fr/design/EnvChangeEntrance.java | 6 +- .../java/com/fr/design/RestartHelper.java | 4 +- .../com/fr/design/dialog/ErrorDialog.java | 94 +++ .../java/com/fr/design/dialog/TipDialog.java | 96 ++++ .../fr/design/mainframe/DesignerFrame.java | 5 +- .../java/com/fr/design/utils/DesignUtils.java | 101 +++- .../com/fr/design/utils/DesignerPort.java | 87 ++- .../main/java/com/fr/start/BaseDesigner.java | 6 +- .../com/fr/design/images/error/error.png | Bin 0 -> 2384 bytes .../com/fr/design/utils/DesignUtilsTest.java | 32 ++ .../start/CollectUserInformationDialog.java | 4 +- .../src/main/java/com/fr/start/Designer.java | 524 +---------------- .../java/com/fr/start/Designer4Debug.java | 2 +- .../java/com/fr/start/DesignerInitial.java | 4 +- .../com/fr/start/DesignerJavaRuntime.java | 71 +++ .../com/fr/start/DesignerProcessType.java | 18 + .../main/java/com/fr/start/MainDesigner.java | 537 ++++++++++++++++++ .../com/fr/start/module/DesignerStartup.java | 36 +- .../com.fr/design/mainframe/JFileTest.java | 3 +- 20 files changed, 1105 insertions(+), 540 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/dialog/ErrorDialog.java create mode 100644 designer-base/src/main/java/com/fr/design/dialog/TipDialog.java create mode 100644 designer-base/src/main/resources/com/fr/design/images/error/error.png create mode 100644 designer-base/src/test/java/com/fr/design/utils/DesignUtilsTest.java create mode 100644 designer-realize/src/main/java/com/fr/start/DesignerJavaRuntime.java create mode 100644 designer-realize/src/main/java/com/fr/start/DesignerProcessType.java create mode 100644 designer-realize/src/main/java/com/fr/start/MainDesigner.java diff --git a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index 6ebd349cbb..4e01d2d2dd 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -19,6 +19,7 @@ import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.update.push.DesignerPushUpdateConfigManager; import com.fr.design.style.color.ColorSelectConfigManager; import com.fr.design.utils.DesignUtils; +import com.fr.design.utils.DesignerPort; import com.fr.file.FILEFactory; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogFormatter; @@ -1545,7 +1546,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { readDesignerPushUpdateAttr(reader); } else if (name.equals(vcsConfigManager.XML_TAG)) { readVcsAttr(reader); - } else { + } else if (DesignerPort.XML_TAG.equals(name)) { + + } + else { readLayout(reader, name); } } @@ -1736,6 +1740,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { reader.readXMLObject(vcsConfigManager); } + public void readDesignerPort(XMLableReader reader) { + reader.readXMLObject(DesignerPort.getInstance()); + } + /** * Write XML.
* The method will be invoked when save data to XML file.
@@ -1761,6 +1769,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { writeOpenDebug(writer); writeDesignerPushUpdateAttr(writer); writeVcsAttr(writer); + writeDesignerPort(writer); writer.end(); } @@ -2010,6 +2019,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.vcsConfigManager.writeXML(writer); } + private void writeDesignerPort(XMLPrintWriter writer) { + DesignerPort.getInstance().writeXML(writer); + } + public VcsConfigManager getVcsConfigManager() { return vcsConfigManager; diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index c1c11553f7..ecdef3ed7e 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -16,6 +16,8 @@ import com.fr.env.EnvListPane; import com.fr.general.GeneralContext; import com.fr.license.exception.RegistEditionException; import com.fr.log.FineLoggerFactory; +import com.fr.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.AssistUtils; import com.fr.stable.EnvChangedListener; import com.fr.start.server.ServerTray; @@ -243,13 +245,13 @@ public class EnvChangeEntrance { @Override public void doOk() { if (!envListOkAction(envListPane, PopTipStrategy.NOW)) { - System.exit(0); + FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); } } @Override public void doCancel() { - System.exit(0); + FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); } }); envListDialog.setVisible(true); diff --git a/designer-base/src/main/java/com/fr/design/RestartHelper.java b/designer-base/src/main/java/com/fr/design/RestartHelper.java index cdb4fc532e..10bee060e7 100644 --- a/designer-base/src/main/java/com/fr/design/RestartHelper.java +++ b/designer-base/src/main/java/com/fr/design/RestartHelper.java @@ -5,6 +5,8 @@ import com.fr.design.os.impl.RestartAction; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralUtils; import com.fr.log.FineLoggerFactory; +import com.fr.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.ArrayUtils; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; @@ -152,7 +154,7 @@ public class RestartHelper { } finally { WorkContext.getCurrent().close(); frame.dispose(); - System.exit(0); + FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); } } diff --git a/designer-base/src/main/java/com/fr/design/dialog/ErrorDialog.java b/designer-base/src/main/java/com/fr/design/dialog/ErrorDialog.java new file mode 100644 index 0000000000..21042a57a9 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/dialog/ErrorDialog.java @@ -0,0 +1,94 @@ +package com.fr.design.dialog; + +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.FRFont; + +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/1/8 + */ +public abstract class ErrorDialog extends JDialog implements ActionListener { + + private UIButton okButton; + private UIButton restartButton; + + + public ErrorDialog(Frame parent, String message, String title, String detail) { + super(parent, true); + JPanel northPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + JPanel messagePane = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true); + UILabel boldFontLabel = new UILabel(message); + UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Send_Report_To_Us")); + Font font = FRFont.getInstance("Dialog", Font.BOLD, 20); + boldFontLabel.setFont(font); + messagePane.add(boldFontLabel); + messagePane.add(label); + northPane.add(messagePane); + + JTextArea area = new JTextArea(detail); + area.setPreferredSize(new Dimension(400, 100)); + area.setEnabled(true); + area.setEditable(false); + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + UILabel detailLabel = new UILabel(Toolkit.i18nText("Fine-Design_Problem_Detail_Message")); + centerPane.add(detailLabel, BorderLayout.NORTH); + centerPane.add(area, BorderLayout.CENTER); + + JPanel southPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + okButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Ok")); + okButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + okEvent(); + } + }); + buttonPane.add(okButton); + restartButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Restart")); + restartButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + restartEvent(); + } + }); + buttonPane.add(restartButton); + controlPane.add(buttonPane, BorderLayout.EAST); + southPane.add(controlPane); + + this.setTitle(title); + this.setResizable(false); + this.add(northPane, BorderLayout.NORTH); + this.add(centerPane, BorderLayout.CENTER); + this.add(southPane, BorderLayout.SOUTH); + this.setSize(new Dimension(600, 500)); + GUICoreUtils.centerWindow(this); + + } + + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + + protected abstract void okEvent(); + + protected abstract void restartEvent(); + +} diff --git a/designer-base/src/main/java/com/fr/design/dialog/TipDialog.java b/designer-base/src/main/java/com/fr/design/dialog/TipDialog.java new file mode 100644 index 0000000000..554d70a22b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/dialog/TipDialog.java @@ -0,0 +1,96 @@ +package com.fr.design.dialog; + +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.IOUtils; + +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/1/8 + */ +public class TipDialog extends JDialog implements ActionListener { + + private UIButton endButton; + private UIButton cancelButton; + + public TipDialog(Frame parent, String type) { + super(parent, true); + JPanel northPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + JPanel iconPane = new JPanel(); + UILabel iconLabel = new UILabel(); + iconLabel.setIcon(IOUtils.readIcon("com/fr/design/images/error/error.png")); + iconPane.add(iconLabel); + iconPane.setPreferredSize(new Dimension(100, 100)); + JPanel tipPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + UILabel tipLabel = new UILabel(Toolkit.i18nText("Fine-Design_Last_Designer_Process_Not_Exist")); + tipPane.add(tipLabel); + northPane.add(iconPane, BorderLayout.WEST); + northPane.add(tipPane, BorderLayout.CENTER); + + JTextArea area = new JTextArea(type); + area.setPreferredSize(new Dimension(400, 100)); + area.setEnabled(true); + area.setEditable(false); + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + centerPane.add(area); + + JPanel southPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + endButton = new UIButton(Toolkit.i18nText("Fine-Design_End_Occupied_Process")); + endButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + endEvent(); + } + }); + buttonPane.add(endButton); + cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")); + cancelButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + cancelEvent(); + } + }); + buttonPane.add(cancelButton); + controlPane.add(buttonPane, BorderLayout.EAST); + southPane.add(controlPane); + + this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Error_Tittle")); + this.setResizable(false); + this.add(northPane, BorderLayout.NORTH); + this.add(centerPane, BorderLayout.CENTER); + this.add(southPane, BorderLayout.SOUTH); + this.setSize(new Dimension(600, 500)); + GUICoreUtils.centerWindow(this); + + } + + protected void endEvent() { + // do nothing + } + + protected void cancelEvent() { + // do nothing + } + + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + +} 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 082775a62d..14a566c731 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 @@ -54,6 +54,8 @@ 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.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.OperatingSystem; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; @@ -1159,8 +1161,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta this.dispose(); this.ad.shutDown(); - - System.exit(0); + FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); } // harry:添加程序外拖拽文件进来打开的功能 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 8d32e6e0ed..93e3e0c1a7 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 @@ -13,6 +13,8 @@ import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; import com.fr.general.GeneralContext; import com.fr.log.FineLoggerFactory; +import com.fr.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.ArrayUtils; import com.fr.stable.CommonCodeUtils; import com.fr.stable.StableUtils; @@ -29,7 +31,9 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; @@ -38,15 +42,21 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.Locale; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; /** * Some util method of Designer */ public class DesignUtils { - private static int port = DesignerPort.MESSAGE_PORT; + private static int port = DesignerPort.getInstance().getMessagePort(); + + private static boolean started = false; private DesignUtils() { } @@ -61,15 +71,54 @@ public class DesignUtils { } /** - * 通过端口是否被占用判断设计器有没有启动 - * s + * 判断设计器有没有启动 * * @return 启动了返回true */ public static boolean isStarted() { - try (Socket socket = new Socket("localhost", port)) { + return started; + } + + + /** + * 判断设计器端口是否被其他程序占用 + * 尝试去通信,无回应就是其他程序占用端口,否则需要继续判断是否为设计器进程未关闭 + * @return + */ + public static boolean isPortOccupied() { + ExecutorService executor = null; + Future future = null; + try (Socket socket = new Socket("localhost", port); + BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8)); + PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8)))) { + writer.println("check"); + writer.flush(); + executor = Executors.newSingleThreadExecutor(); + future = executor.submit(new Callable() { + @Override + public String call() throws Exception { + String line; + while ((line = reader.readLine()) != null) { + if ("response".equals(line)) { + // 正常通信 上一次设计器进程未关闭 + started = true; + return line; + } + } + return StringUtils.EMPTY; + } + }); + future.get(2, TimeUnit.SECONDS); + return false; + } catch (TimeoutException e) { + future.cancel(true); return true; - } catch (Exception ignored) { + } catch (Exception ignore) { + + } finally { + if (executor != null) { + executor.shutdownNow(); + } } return false; } @@ -79,15 +128,12 @@ public class DesignUtils { * * @param lines 命令行 */ - public static void clientSend(String[] lines) { + public static void clientSend(String[] lines, Socket socket) { if (lines == null || lines.length == 0) { return; } - Socket socket = null; PrintWriter writer = null; try { - socket = new Socket("localhost", port); - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8))); for (int i = 0; i < lines.length; i++) { writer.println(lines[i]); @@ -96,19 +142,23 @@ public class DesignUtils { } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } finally { - try { - if (writer != null) { - writer.close(); - } - if (socket != null) { - socket.close(); - } - } catch (IOException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + if (writer != null) { + writer.close(); } } } + public static void clientSend(String[] lines) { + if (lines == null || lines.length == 0) { + return; + } + try (Socket socket = new Socket("localhost", port)) { + clientSend(lines, socket); + } catch (Exception ignore) { + + } + } + /** * 建立监听端口 * @@ -138,7 +188,12 @@ public class DesignUtils { if (line.startsWith("demo")) { DesignerEnvManager.getEnvManager().setCurrentEnv2Default(); ServerStarter.browserDemoURL(); - } else if (StringUtils.isNotEmpty(line)) { + } else if ("check".equals(line)) { + clientSend(new String[] {"response"}, socket); + } else if ("end".equals(line)) { + FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + } + else if (StringUtils.isNotEmpty(line)) { File f = new File(line); String path = f.getAbsolutePath(); @@ -165,6 +220,14 @@ public class DesignUtils { } + public static void responseToClient(Socket socket) { + try (OutputStream outputStream = socket.getOutputStream()) { + outputStream.write("reponse".getBytes(StandardCharsets.UTF_8)); + outputStream.flush(); + } catch (IOException ignore) { + } + } + /** * 弹出对话框,显示报错 * diff --git a/designer-base/src/main/java/com/fr/design/utils/DesignerPort.java b/designer-base/src/main/java/com/fr/design/utils/DesignerPort.java index 7c082800ed..46bdd52a83 100644 --- a/designer-base/src/main/java/com/fr/design/utils/DesignerPort.java +++ b/designer-base/src/main/java/com/fr/design/utils/DesignerPort.java @@ -1,26 +1,95 @@ package com.fr.design.utils; +import com.fr.design.i18n.Toolkit; +import com.fr.general.ComparatorUtils; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLReadable; +import com.fr.stable.xml.XMLWriter; +import com.fr.stable.xml.XMLableReader; + +import javax.swing.JOptionPane; + /** * 为的就是能替换 DesignPort.class 实现多开,因此避免编译器常量编译展开优化 */ -public class DesignerPort { +public class DesignerPort implements XMLReadable, XMLWriter { + + public static final String XML_TAG = "DesignerPort"; + private static final int MIN_PORT = 1024; + private static final int MAX_PORT = 65536; + + public static final DesignerPort INSTANCE = new DesignerPort(); + + public static DesignerPort getInstance() { + return INSTANCE; + } + private DesignerPort() { } /** - * 设计器端口,避免编译期常量优化展开 + * 设计器端口 */ - public static final int MESSAGE_PORT = getMessagePort(); + private int messagePort = 51462; + /** - * 设计器端口,避免编译期常量优化展开 + * 设计器端口,debug模式下 */ - public static final int DEBUG_MESSAGE_PORT = getDebugMessagePort(); + private int debugMessagePort = 51463; + + public int getMessagePort() { + return messagePort; + } - private static int getMessagePort() { - return 51462; + public int getDebugMessagePort() { + return debugMessagePort; } - private static int getDebugMessagePort() { - return 51463; + public void setMessagePort(int messagePort) { + this.messagePort = messagePort; } + + public void setDebugMessagePort(int debugMessagePort) { + this.debugMessagePort = debugMessagePort; + } + + @Override + public void readXML(XMLableReader reader) { + if (reader.isAttr()) { + this.setMessagePort(reader.getAttrAsInt("messagePort", 51462)); + this.setDebugMessagePort(reader.getAttrAsInt("debugMessagePort", 51463)); + } + } + + @Override + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(XML_TAG); + writer.attr("messagePort", this.messagePort); + writer.attr("debugMessagePort", this.debugMessagePort); + writer.end(); + } + + public int resetPort() { + String port = JOptionPane.showInputDialog(null, + Toolkit.i18nText("Fine-Design_Modify_Designer_Port_Tip"), + Toolkit.i18nText("Fine-Design_Modify_Designer_Port"), JOptionPane.INFORMATION_MESSAGE); + int value; + try { + value = Integer.parseInt(port); + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Modify_Designer_Port_Not_Number_Tip")); + value = resetPort(); + } + if (value < MIN_PORT || value > MAX_PORT) { + JOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Modify_Designer_Port_Out_Of_Range_Tip")); + value = resetPort(); + } + if (ComparatorUtils.equals("true", System.getProperty("debug"))) { + setDebugMessagePort(value); + } else { + setMessagePort(value); + } + return value; + } + } diff --git a/designer-base/src/main/java/com/fr/start/BaseDesigner.java b/designer-base/src/main/java/com/fr/start/BaseDesigner.java index 833faaef70..5c0e8d013f 100644 --- a/designer-base/src/main/java/com/fr/start/BaseDesigner.java +++ b/designer-base/src/main/java/com/fr/start/BaseDesigner.java @@ -24,6 +24,8 @@ import com.fr.file.FILEFactory; import com.fr.file.FileFILE; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; +import com.fr.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.OperatingSystem; import java.awt.*; @@ -47,8 +49,6 @@ public abstract class BaseDesigner extends ToolBarMenuDock { private void init() { prepare(); - // 初始化look and feel.这个在预加载之前执行是因为lookAndFeel里的东西,预加载时也要用到 - DesignUtils.initLookAndFeel(); // 初始化Log Handler DesignerEnvManager.loadLogSetting(); createDesignerFrame(); @@ -137,7 +137,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { if (!isException) { showDesignerFrame(true); } else { - System.exit(0); + FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); } } } diff --git a/designer-base/src/main/resources/com/fr/design/images/error/error.png b/designer-base/src/main/resources/com/fr/design/images/error/error.png new file mode 100644 index 0000000000000000000000000000000000000000..fd4a4650919e880ea79aa17239f226e5f8d1fb63 GIT binary patch literal 2384 zcmV-W39t5vP)Px;3Q0skRCodHolk63MI6Ux-d1TEYQeUF7-@GoxCajsBPbq-;=!9SLMbGA;$-3< z5=n^0vxdZjoIH8b1PWq^HxHuWLPCtegNOCNZo!z67HNev1-m=`zO#MXx697FH}B27 zeeJ$U+V_9vH=pm!y!YnK{Fbpi;vm61D43YA!HhG0lSI4B7{4sU<3Ekxs{CyuUK?@rT!8s1*Pya6Z{)7wB_P>rGi@1v*0wdx?IhdN@cz(PEjeJrt^k$=Q=#L zOtoW14Di$A)oR6II?AY17vOHG^xSG)e8Pn|Or_mZT9)Dgg3u70e>YIzpKY&Je@`)K zx79tEk^806j+J`j3nAFs!TniV=bU{zSny76tyXWRVVm<3D5j+(Lc|cyU?IKtgKsGrO#VdY1c_pC@J^kb zrIPbznvl{;i<+cMqXl-1*J>-a(zGVPKf8C2)c8#k70 z*k?rm34gWm3q3;Yv0+r^@knn$QitOoIeRjX(i# z6o%H=X`>GnK#o|`MiK8|w~`->$%Y6j_Q(md^s(SBE9(S}M!5_=ts9G~tpOM)>jFMqwwro!Oq$OJxYfGsWp*fj?mt7F#+Kms0AUz+R)O7zl^>F6Rvd^$3NPd9tA z!L)Xn)3yh%-sY%DE;Yc;n-&K!0JOm+)bmj-^rnx^6Tq zW3G;yh!AE&ui>xRr(~%X08>GG7}iBVKVZC&5%}mwP_k4DfO)t*4owk`(#x8;2$_Ko zh8mV?0sKkO84;l|KOfnWI-M)Kn(1vj6G6jLEkGtLUpIpKRU!xLJ%^D~Ha}4<0H*(E zAhe$IBRuW+=Hlr{b~CGAK>btGS!!6S1%U5`9)}kEz?ZD3CbfD|vmkI zwSHa__`Wfj5kbRJEdY5P@iUV4(gu9r=8TA-WT_MYE?@jiq`5SKkEfj|Pe;8LLB~=l z0Q~Kw2_9(~!NW_nx-br-lF?g4xgB~HFCTwm1>cM*IMFiP3x#EhV=z6df6w-Ylkl)M3E!Sq$@bZ)dTKT({ad-{=RXZQJ8 zoSz@RS%X8`&=9ExAQm_^4UH{7K@u=w66* z>wBWDMScnjMwdHm3eu1h!P0ZsgrucsC@zk-o6*Nx#3GKjED$qpf_%*Ikw!P2GyZnJ zF2NwKzc?_9EdVYaeR1zc)b?G%dOrr_9SoA>J=Q%Sm>`^&F4WnN)M2s7T^0v(jdgxy ztiWDR>PI?J4UlG#BWw6lrYXt&YLJjuLS{Otg6vswduA+VG``yu$(aB3Rd zztPqS{31 shortCuts = new ArrayList(); -// shortCuts.add(new NewWorkBookXAction()); - shortCuts.add(new NewWorkBookAction()); - shortCuts.add(new NewPolyReportAction()); - try { - if (DesignModuleFactory.getNewFormAction() != null) { - shortCuts.add((ShortCut) DesignModuleFactory.getNewFormAction().newInstance()); - } - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return shortCuts.toArray(new ShortCut[shortCuts.size()]); - } - - @Override - protected MenuDef createServerMenuDef(ToolBarMenuDockPlus plus) { - MenuDef menuDef = super.createServerMenuDef(plus); - - if (WorkContext.getCurrent() == null) { - return menuDef; - } - - if (!DesignerMode.isAuthorityEditing()) { - menuDef.addShortCut(SeparatorDef.DEFAULT); - - if (WorkContext.getCurrent().isRoot()) { - menuDef.addShortCut(new ServerConfigManagerAction(), new StyleListAction(), new WidgetManagerAction()); - if (ActionFactory.getChartPreStyleAction() != null) { - menuDef.addShortCut(ActionFactory.getChartPreStyleAction()); - } - if (ActionFactory.getChartEmptyDataStyleAction() != null) { - menuDef.addShortCut(ActionFactory.getChartEmptyDataStyleAction()); - } - if (ActionFactory.getChartMapEditorAction() != null) { - menuDef.addShortCut(ActionFactory.getChartMapEditorAction()); - } - } - - insertMenu(menuDef, MenuHandler.SERVER); - } - - return menuDef; - } - - - /** - * 创建设计器上几个比较大的图标:新建cpt,保存,前进,后退,运行。 - * - * @return 返回大图标对应的工具栏 - */ - @Override - public UILargeToolbar createLargeToolbar() { - UILargeToolbar largeToolbar = super.createLargeToolbar(); - largeToolbar.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 4)); - largeToolbar.add(generateEmptyGap(1)); - createRunButton(largeToolbar); - largeToolbar.add(run); - largeToolbar.add(generateEmptyGap(GAP)); - largeToolbar.addSeparator(new Dimension(2, 42)); - largeToolbar.setBorder(new MatteBorder(new Insets(0, 0, 1, 0), UIConstants.LINE_COLOR)); - return largeToolbar; - } - - private JPanel generateEmptyGap(final int width) { - JPanel panel = new JPanel() { + process.getPipe().listen(FineProcessEngineEvent.DESTROY, new Listener() { @Override - public Dimension getPreferredSize() { - Dimension dim = super.getPreferredSize(); - dim.width = width; - return dim; - } - }; - panel.setBackground(null); - panel.setOpaque(false); - return panel; - } - - /** - * 创建上面一排的工具栏按钮 - * - * @return 按钮 - */ - @Override - public UIButton[] createUp() { - if (upToolBar == null) { - createSaveButton(); - createUndoButton(); - createRedoButton(); - return upToolBar = new UIButton[]{saveButton, undo, redo}; - } - return upToolBar; - } - - - private void createSaveButton() { - saveButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/save.png")); - saveButton.setToolTipText(KeySetUtils.SAVE_TEMPLATE.getMenuKeySetName()); - saveButton.set4ToolbarButton(); - saveButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - jt.stopEditing(); - jt.saveTemplate(); - jt.requestFocus(); - } - }); - } - - - private void createUndoButton() { - undo = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/undo.png")); - undo.setToolTipText(KeySetUtils.UNDO.getMenuKeySetName()); - undo.set4ToolbarButton(); - undo.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTemplate jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); - if (jt != null) { - jt.undo(); - } + public void on(Event event, Null param) { + process.destroy(); } }); - } - - private void createRedoButton() { - redo = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/redo.png")); - redo.setToolTipText(KeySetUtils.REDO.getMenuKeySetName()); - redo.set4ToolbarButton(); - redo.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTemplate jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); - if (jt != null) { - jt.redo(); - } - } - }); - } - - private void createRunButton(UILargeToolbar largeToolbar) { - run = new UIPreviewButton(new UIButton(UIConstants.PAGE_BIG_ICON) { - @Override - public Dimension getPreferredSize() { - return new Dimension(34, 34); - } - }, new UIButton(UIConstants.PREVIEW_DOWN) { - @Override - public Dimension getPreferredSize() { - return new Dimension(34, 10); - } - } - ) { - @Override - protected void upButtonClickEvent() { - JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (jt == null) { - return; - } - WebPreviewUtils.preview(jt); - } - - @Override - protected void downButtonClickEvent() { - final JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (jt == null) { - return; - } - - UIPopupMenu menu = new UIPopupMenu(); - - UIMenuItem[] items = jt.createMenuItem4Preview(); - for (int i = 0; i < items.length; i++) { - menu.add(items[i]); - } - GUICoreUtils.showPopupMenu(menu, MutilTempalteTabPane.getInstance(), MutilTempalteTabPane.getInstance().getX() - PREVIEW_DOWN_X_GAP, MutilTempalteTabPane.getInstance().getY() - 1 + MutilTempalteTabPane.getInstance().getHeight()); - } - - @Override - public Dimension getPreferredSize() { - // TODO Auto-generated method stub - return new Dimension(34, 46); - } - }; - run.setExtraPainted(false); - run.set4Toolbar(); - run.getUpButton().setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview")); - run.getDownButton().setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Dropdown_More_Preview")); - } - - @Override - protected void refreshLargeToolbarState() { - JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (jt == null) { - return; - } - saveButton.setEnabled(!jt.isSaved() && !DesignModeContext.isVcsMode()); - MutilTempalteTabPane.getInstance().refreshOpenedTemplate(HistoryTemplateListCache.getInstance().getHistoryList()); - MutilTempalteTabPane.getInstance().repaint(); - if (DesignerEnvManager.getEnvManager().isSupportUndo()) { - undo.setEnabled(jt.canUndo()); - redo.setEnabled(jt.canRedo()); - } else { - undo.setEnabled(false); - redo.setEnabled(false); - } - - run.getUpButton().setIcon(jt.getPreviewLargeIcon()); - - } - - /** - * 生成工具栏 - * - * @param toolbarComponent 工具栏 - * @param plus 对象 - * @return 更新后的toolbar - */ - @Override - public JComponent resetToolBar(JComponent toolbarComponent, ToolBarMenuDockPlus plus) { - //如果是处于权限编辑状态 - if (DesignerMode.isAuthorityEditing()) { - if (plus instanceof JWorkBook && plus.toolbars4Target() == null) { - //聚合块编辑 - return super.polyToolBar(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Privilege_Poly_Block_Edit")); - } else { - return plus.toolBar4Authority(); - } - } - - if (plus.toolbarPanes4Form().length == 0) { - return super.resetToolBar(toolbarComponent, plus); - } else { - JPanel toolbarPane; - toolbarPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, TOOLBARPANEVGAP)); - Dimension dim = new Dimension(); - dim.height = plus.getToolBarHeight(); - toolbarPane.setPreferredSize(dim); - toolbarPane.setFocusable(true); - JPanel[] paneArray = plus.toolbarPanes4Form(); - for (int i = 0; i < paneArray.length; i++) { - toolbarPane.add(paneArray[i]); - } - return toolbarPane; - } - } - - /** - * 生成报表设计和表单设计的编辑区域 - * - * @return 返回编辑区域 - */ - @Override - public JTemplate createNewTemplate() { - return new JWorkBook(); } - - /** - * 创建论坛登录面板, chart那边不需要 - * - * @return 面板组件 - */ - @Override - public Component createBBSLoginPane() { - if (userInfoPane == null) { - userInfoPane = UserInfoPane.getInstance(); - } - return userInfoPane; - } - - /** - * 创建alphafine打开面板 - * - * @return 面板组件 - */ - @Override - public Component createAlphaFinePane() { - return AlphaFinePane.getAlphaFinePane(); - } - - /** - * 收集用户信息吗 - */ - @Override - protected void collectUserInformation() { - //定制的就不弹出来了 - if (!ComparatorUtils.equals(ProductConstants.APP_NAME, ProductConstants.DEFAULT_APP_NAME)) { - return; - } - - DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); - final String key = envManager.getActivationKey(); - //本地验证通过 - if (ActiveKeyGenerator.localVerify(key)) { - onLineVerify(envManager, key); - UserInfoLabel.showBBSDialog(); - return; - } - - if (StableUtils.checkDesignerActive(readOldKey())) { - //只要有老的key, 就不弹窗, 下次启动的时候, 在线验证下就行. - String newKey = ActiveKeyGenerator.generateActiveKey(); - envManager.setActivationKey(newKey); - UserInfoLabel.showBBSDialog(); - return; - } - - CollectUserInformationDialog activeDialog = new CollectUserInformationDialog( - DesignerContext.getDesignerFrame()); - activeDialog.setVisible(true); - } - - private void onLineVerify(DesignerEnvManager envManager, final String key) { - int status = envManager.getActiveKeyStatus(); - //没有联网验证过 - if (status != 0) { - ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() - .setNameFormat("net-verify-thread-%s").build(); - ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( - 1, 1, - 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue(1), - namedThreadFactory); - threadPoolExecutor.execute(new Runnable() { - @Override - public void run() { - ActiveKeyGenerator.onLineVerify(key); - } - }); - } - } - - private File getOldEnvFile(String folderName) { - String userHome = System.getProperty("user.home"); - if (userHome == null) { - userHome = System.getProperty("userHome"); - } - String filePath = StableUtils.pathJoin(userHome, folderName, ProductConstants.APP_NAME + "Env.xml"); - return new File(filePath); - } - - private String getOldActiveKeyFromFile(File envFile) { - if (!envFile.exists()) { - return StringUtils.EMPTY; - } - - DesignerEnvManager temp = new DesignerEnvManager(); - try { - XMLTools.readFileXML(temp, envFile); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return temp.getActivationKey(); - } - - //默认只从7.0和711的设计器里读取key - private String readOldKey() { - File file71 = getOldEnvFile(OLD_ENV_FOLDER_71); - if (!file71.exists()) { - File file70 = getOldEnvFile(OLD_ENV_FOLDER_70); - return getOldActiveKeyFromFile(file70); - } - - return getOldActiveKeyFromFile(file71); - } - - /** - * 设计器退出时, 做的一些操作. - */ - @Override - public void shutDown() { - InformationCollector collector = InformationCollector.getInstance(); - collector.collectStopTime(); - collector.saveXMLFile(); - } - } diff --git a/designer-realize/src/main/java/com/fr/start/Designer4Debug.java b/designer-realize/src/main/java/com/fr/start/Designer4Debug.java index 0786fee6f8..6704b9c8cc 100644 --- a/designer-realize/src/main/java/com/fr/start/Designer4Debug.java +++ b/designer-realize/src/main/java/com/fr/start/Designer4Debug.java @@ -6,6 +6,6 @@ package com.fr.start; public class Designer4Debug { public static void main(String... args) { - org.swingexplorer.Launcher.main(new String[]{"com.fr.start.Designer"}); + org.swingexplorer.Launcher.main(new String[]{"com.fr.start.MainDesigner"}); } } diff --git a/designer-realize/src/main/java/com/fr/start/DesignerInitial.java b/designer-realize/src/main/java/com/fr/start/DesignerInitial.java index e6b9e4f464..856208f400 100644 --- a/designer-realize/src/main/java/com/fr/start/DesignerInitial.java +++ b/designer-realize/src/main/java/com/fr/start/DesignerInitial.java @@ -14,13 +14,13 @@ import com.fr.event.Null; */ public class DesignerInitial { - private static volatile Designer designer; + private static volatile MainDesigner designer; public static void init(final String... args) { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { - designer = new Designer(args); + designer = new MainDesigner(args); } }); } diff --git a/designer-realize/src/main/java/com/fr/start/DesignerJavaRuntime.java b/designer-realize/src/main/java/com/fr/start/DesignerJavaRuntime.java new file mode 100644 index 0000000000..351bf1e44f --- /dev/null +++ b/designer-realize/src/main/java/com/fr/start/DesignerJavaRuntime.java @@ -0,0 +1,71 @@ +package com.fr.start; + +import com.fr.general.ComparatorUtils; +import com.fr.process.engine.core.AbstractJavaRuntime; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.os.OperatingSystem; + +/** + * 设计器Java运行环境 + * + * @author hades + * @version 10.0 + * Created by hades on 2019/9/22 + */ +public class DesignerJavaRuntime extends AbstractJavaRuntime { + + private static final String DOT = "."; + private static final String INSTALL4J = ".install4j"; + private static final String JAVA_EXEC = "java"; + private static final String WIN_JRE_BIN = StableUtils.pathJoin("jre", "bin"); + private static final String MAC_JRE_BIN = StableUtils.pathJoin("jre.bundle", "Contents", "Home", "jre", "bin"); + private static final String[] DEBUG_OPTIONS = new String[]{"-Dfile.encoding=UTF-8", "-Xmx2048m"}; + + private static final DesignerJavaRuntime INSTANCE = new DesignerJavaRuntime(); + + public static DesignerJavaRuntime getInstance() { + return INSTANCE; + } + + @Override + public String getJavaExec() { + String installHome = StableUtils.getInstallHome(); + if (!isInstallVersion()) { + return JAVA_EXEC; + } + if (OperatingSystem.isWindows()) { + return StableUtils.pathJoin(installHome, WIN_JRE_BIN, JAVA_EXEC); + } + if (OperatingSystem.isMacos()) { + + return StableUtils.pathJoin(installHome, INSTALL4J, MAC_JRE_BIN, JAVA_EXEC); + } + if (OperatingSystem.isUnix()) { + return StableUtils.pathJoin(installHome, WIN_JRE_BIN, JAVA_EXEC); + + } + return StringUtils.EMPTY; + } + + private boolean isInstallVersion() { + return !ComparatorUtils.equals(StableUtils.getInstallHome(), DOT); + } + + + /** + * 非安装版本需要添加下内存参数 + * 工程中可根据需要修改 + * + * @return 参数 + */ + @Override + public String[] getJvmOptions() { + if (isInstallVersion()) { + return super.getJvmOptions(); + } else { + return DEBUG_OPTIONS; + } + + } +} diff --git a/designer-realize/src/main/java/com/fr/start/DesignerProcessType.java b/designer-realize/src/main/java/com/fr/start/DesignerProcessType.java new file mode 100644 index 0000000000..6a530125cd --- /dev/null +++ b/designer-realize/src/main/java/com/fr/start/DesignerProcessType.java @@ -0,0 +1,18 @@ +package com.fr.start; + +import com.fr.process.FineProcessType; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/1/14 + */ +public enum DesignerProcessType implements FineProcessType { + + INSTANCE; + + @Override + public String obtain() { + return "designer"; + } +} diff --git a/designer-realize/src/main/java/com/fr/start/MainDesigner.java b/designer-realize/src/main/java/com/fr/start/MainDesigner.java new file mode 100644 index 0000000000..56aa763899 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/start/MainDesigner.java @@ -0,0 +1,537 @@ +package com.fr.start; + +import com.fr.base.BaseUtils; +import com.fr.base.vcs.DesignerMode; +import com.fr.design.DesignerEnvManager; +import com.fr.design.RestartHelper; +import com.fr.design.actions.core.ActionFactory; +import com.fr.design.actions.file.WebPreviewUtils; +import com.fr.design.actions.file.newReport.NewPolyReportAction; +import com.fr.design.actions.file.newReport.NewWorkBookAction; +import com.fr.design.actions.server.ServerConfigManagerAction; +import com.fr.design.actions.server.StyleListAction; +import com.fr.design.actions.server.WidgetManagerAction; +import com.fr.design.base.mode.DesignModeContext; +import com.fr.design.constants.UIConstants; +import com.fr.design.dialog.ErrorDialog; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.fun.MenuHandler; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.UIPreviewButton; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.gui.itoolbar.UILargeToolbar; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.ActiveKeyGenerator; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.InformationCollector; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.mainframe.alphafine.component.AlphaFinePane; +import com.fr.design.mainframe.bbs.UserInfoLabel; +import com.fr.design.mainframe.bbs.UserInfoPane; +import com.fr.design.mainframe.messagecollect.StartErrorMessageCollector; +import com.fr.design.mainframe.messagecollect.entity.DesignerErrorMessage; +import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.menu.MenuDef; +import com.fr.design.menu.SeparatorDef; +import com.fr.design.menu.ShortCut; +import com.fr.design.module.DesignModuleFactory; +import com.fr.design.utils.concurrent.ThreadFactoryBuilder; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.ComparatorUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.module.Module; +import com.fr.module.ModuleContext; +import com.fr.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; +import com.fr.runtime.FineRuntime; +import com.fr.stable.ProductConstants; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.lifecycle.ErrorType; +import com.fr.stable.lifecycle.LifecycleFatalError; +import com.fr.stable.xml.XMLTools; +import com.fr.start.module.StartupArgs; +import com.fr.start.server.ServerTray; +import com.fr.third.org.apache.commons.lang3.time.StopWatch; +import com.fr.workspace.WorkContext; + +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.border.MatteBorder; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.ArrayList; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class MainDesigner extends BaseDesigner { + + private static final int TOOLBARPANEVGAP = -4; + private static final int PREVIEW_DOWN_X_GAP = 92; + private static final int GAP = 7; + private static final String OLD_ENV_FOLDER_71 = ".FineReport71"; + private static final String OLD_ENV_FOLDER_70 = ".FineReport70"; + + private UserInfoPane userInfoPane; + private UIButton saveButton; + private UIButton undo; + private UIButton redo; + private UIButton[] upToolBar; + private UIPreviewButton run; + + public MainDesigner(String[] args) { + super(args); + } + + /** + * 设计器启动的Main方法 + * + * @param args 参数 + */ + public static void main(String[] args) { + + StopWatch watch = new StopWatch(); + watch.start(); + //启动运行时 + FineRuntime.start(); + Module designerRoot = ModuleContext.parseRoot("designer-startup.xml"); + //传递启动参数 + designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args)); + try { + designerRoot.start(); + } catch (LifecycleFatalError fatal) { + SplashContext.getInstance().hide(); + if (ErrorType.FINEDB.equals(fatal.getErrorType())) { + StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.FINEDB_PROBLEM.getId(), + DesignerErrorMessage.FINEDB_PROBLEM.getMessage(), + fatal.getMessage()); + JOptionPane.showMessageDialog(null, fatal.getMessage(), Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.ERROR_MESSAGE); + } + FineLoggerFactory.getLogger().error(fatal.getMessage(), fatal); + StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.UNEXCEPTED_START_FAILED.getId(), + DesignerErrorMessage.UNEXCEPTED_START_FAILED.getMessage(), + fatal.getMessage()); + ErrorDialog dialog = new ErrorDialog(null, Toolkit.i18nText("Fine-Design_Error_Start_Apology_Message"), + Toolkit.i18nText("Fine-Design_Error_Start_Report"), + fatal.getMessage()) { + @Override + protected void okEvent() { + dispose(); + FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + } + + @Override + protected void restartEvent() { + dispose(); + RestartHelper.restart(); + } + }; + dialog.setVisible(true); + } + + if (WorkContext.getCurrent().isLocal()) { + //初始化一下serverTray + ServerTray.init(); + } + FineLoggerFactory.getLogger().info("Designer started.Time used {} ms", watch.getTime()); + watch.stop(); + } + + /** + * 创建新建文件的快捷方式数组。 + * + * @return 返回快捷方式的数组 + */ + @Override + public ShortCut[] createNewFileShortCuts() { + ArrayList shortCuts = new ArrayList(); +// shortCuts.add(new NewWorkBookXAction()); + shortCuts.add(new NewWorkBookAction()); + shortCuts.add(new NewPolyReportAction()); + try { + if (DesignModuleFactory.getNewFormAction() != null) { + shortCuts.add((ShortCut) DesignModuleFactory.getNewFormAction().newInstance()); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return shortCuts.toArray(new ShortCut[shortCuts.size()]); + } + + @Override + protected MenuDef createServerMenuDef(ToolBarMenuDockPlus plus) { + MenuDef menuDef = super.createServerMenuDef(plus); + + if (WorkContext.getCurrent() == null) { + return menuDef; + } + + if (!DesignerMode.isAuthorityEditing()) { + menuDef.addShortCut(SeparatorDef.DEFAULT); + + if (WorkContext.getCurrent().isRoot()) { + menuDef.addShortCut(new ServerConfigManagerAction(), new StyleListAction(), new WidgetManagerAction()); + if (ActionFactory.getChartPreStyleAction() != null) { + menuDef.addShortCut(ActionFactory.getChartPreStyleAction()); + } + if (ActionFactory.getChartEmptyDataStyleAction() != null) { + menuDef.addShortCut(ActionFactory.getChartEmptyDataStyleAction()); + } + if (ActionFactory.getChartMapEditorAction() != null) { + menuDef.addShortCut(ActionFactory.getChartMapEditorAction()); + } + } + + insertMenu(menuDef, MenuHandler.SERVER); + } + + return menuDef; + } + + + /** + * 创建设计器上几个比较大的图标:新建cpt,保存,前进,后退,运行。 + * + * @return 返回大图标对应的工具栏 + */ + @Override + public UILargeToolbar createLargeToolbar() { + UILargeToolbar largeToolbar = super.createLargeToolbar(); + largeToolbar.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 4)); + largeToolbar.add(generateEmptyGap(1)); + createRunButton(largeToolbar); + largeToolbar.add(run); + largeToolbar.add(generateEmptyGap(GAP)); + largeToolbar.addSeparator(new Dimension(2, 42)); + largeToolbar.setBorder(new MatteBorder(new Insets(0, 0, 1, 0), UIConstants.LINE_COLOR)); + return largeToolbar; + } + + private JPanel generateEmptyGap(final int width) { + JPanel panel = new JPanel() { + @Override + public Dimension getPreferredSize() { + Dimension dim = super.getPreferredSize(); + dim.width = width; + return dim; + } + }; + panel.setBackground(null); + panel.setOpaque(false); + return panel; + } + + /** + * 创建上面一排的工具栏按钮 + * + * @return 按钮 + */ + @Override + public UIButton[] createUp() { + if (upToolBar == null) { + createSaveButton(); + createUndoButton(); + createRedoButton(); + return upToolBar = new UIButton[]{saveButton, undo, redo}; + } + return upToolBar; + } + + + private void createSaveButton() { + saveButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/save.png")); + saveButton.setToolTipText(KeySetUtils.SAVE_TEMPLATE.getMenuKeySetName()); + saveButton.set4ToolbarButton(); + saveButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + jt.stopEditing(); + jt.saveTemplate(); + jt.requestFocus(); + } + }); + } + + + private void createUndoButton() { + undo = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/undo.png")); + undo.setToolTipText(KeySetUtils.UNDO.getMenuKeySetName()); + undo.set4ToolbarButton(); + undo.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTemplate jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (jt != null) { + jt.undo(); + } + } + }); + } + + private void createRedoButton() { + redo = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/redo.png")); + redo.setToolTipText(KeySetUtils.REDO.getMenuKeySetName()); + redo.set4ToolbarButton(); + redo.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTemplate jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (jt != null) { + jt.redo(); + } + } + }); + } + + private void createRunButton(UILargeToolbar largeToolbar) { + run = new UIPreviewButton(new UIButton(UIConstants.PAGE_BIG_ICON) { + @Override + public Dimension getPreferredSize() { + return new Dimension(34, 34); + } + }, new UIButton(UIConstants.PREVIEW_DOWN) { + @Override + public Dimension getPreferredSize() { + return new Dimension(34, 10); + } + } + ) { + @Override + protected void upButtonClickEvent() { + JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (jt == null) { + return; + } + WebPreviewUtils.preview(jt); + } + + @Override + protected void downButtonClickEvent() { + final JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (jt == null) { + return; + } + + UIPopupMenu menu = new UIPopupMenu(); + + UIMenuItem[] items = jt.createMenuItem4Preview(); + for (int i = 0; i < items.length; i++) { + menu.add(items[i]); + } + GUICoreUtils.showPopupMenu(menu, MutilTempalteTabPane.getInstance(), MutilTempalteTabPane.getInstance().getX() - PREVIEW_DOWN_X_GAP, MutilTempalteTabPane.getInstance().getY() - 1 + MutilTempalteTabPane.getInstance().getHeight()); + } + + @Override + public Dimension getPreferredSize() { + // TODO Auto-generated method stub + return new Dimension(34, 46); + } + }; + run.setExtraPainted(false); + run.set4Toolbar(); + run.getUpButton().setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview")); + run.getDownButton().setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Dropdown_More_Preview")); + } + + @Override + protected void refreshLargeToolbarState() { + JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (jt == null) { + return; + } + saveButton.setEnabled(!jt.isSaved() && !DesignModeContext.isVcsMode()); + MutilTempalteTabPane.getInstance().refreshOpenedTemplate(HistoryTemplateListCache.getInstance().getHistoryList()); + MutilTempalteTabPane.getInstance().repaint(); + if (DesignerEnvManager.getEnvManager().isSupportUndo()) { + undo.setEnabled(jt.canUndo()); + redo.setEnabled(jt.canRedo()); + } else { + undo.setEnabled(false); + redo.setEnabled(false); + } + + run.getUpButton().setIcon(jt.getPreviewLargeIcon()); + + } + + /** + * 生成工具栏 + * + * @param toolbarComponent 工具栏 + * @param plus 对象 + * @return 更新后的toolbar + */ + @Override + public JComponent resetToolBar(JComponent toolbarComponent, ToolBarMenuDockPlus plus) { + //如果是处于权限编辑状态 + if (DesignerMode.isAuthorityEditing()) { + if (plus instanceof JWorkBook && plus.toolbars4Target() == null) { + //聚合块编辑 + return super.polyToolBar(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Privilege_Poly_Block_Edit")); + } else { + return plus.toolBar4Authority(); + } + } + + if (plus.toolbarPanes4Form().length == 0) { + return super.resetToolBar(toolbarComponent, plus); + } else { + JPanel toolbarPane; + toolbarPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, TOOLBARPANEVGAP)); + Dimension dim = new Dimension(); + dim.height = plus.getToolBarHeight(); + toolbarPane.setPreferredSize(dim); + toolbarPane.setFocusable(true); + JPanel[] paneArray = plus.toolbarPanes4Form(); + for (int i = 0; i < paneArray.length; i++) { + toolbarPane.add(paneArray[i]); + } + return toolbarPane; + } + } + + + /** + * 生成报表设计和表单设计的编辑区域 + * + * @return 返回编辑区域 + */ + @Override + public JTemplate createNewTemplate() { + return new JWorkBook(); + } + + /** + * 创建论坛登录面板, chart那边不需要 + * + * @return 面板组件 + */ + @Override + public Component createBBSLoginPane() { + if (userInfoPane == null) { + userInfoPane = UserInfoPane.getInstance(); + } + return userInfoPane; + } + + /** + * 创建alphafine打开面板 + * + * @return 面板组件 + */ + @Override + public Component createAlphaFinePane() { + return AlphaFinePane.getAlphaFinePane(); + } + + /** + * 收集用户信息吗 + */ + @Override + protected void collectUserInformation() { + //定制的就不弹出来了 + if (!ComparatorUtils.equals(ProductConstants.APP_NAME, ProductConstants.DEFAULT_APP_NAME)) { + return; + } + + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + final String key = envManager.getActivationKey(); + //本地验证通过 + if (ActiveKeyGenerator.localVerify(key)) { + onLineVerify(envManager, key); + UserInfoLabel.showBBSDialog(); + return; + } + + if (StableUtils.checkDesignerActive(readOldKey())) { + //只要有老的key, 就不弹窗, 下次启动的时候, 在线验证下就行. + String newKey = ActiveKeyGenerator.generateActiveKey(); + envManager.setActivationKey(newKey); + UserInfoLabel.showBBSDialog(); + return; + } + + CollectUserInformationDialog activeDialog = new CollectUserInformationDialog( + DesignerContext.getDesignerFrame()); + activeDialog.setVisible(true); + } + + private void onLineVerify(DesignerEnvManager envManager, final String key) { + int status = envManager.getActiveKeyStatus(); + //没有联网验证过 + if (status != 0) { + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() + .setNameFormat("net-verify-thread-%s").build(); + ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( + 1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(1), + namedThreadFactory); + threadPoolExecutor.execute(new Runnable() { + @Override + public void run() { + ActiveKeyGenerator.onLineVerify(key); + } + }); + } + } + + private File getOldEnvFile(String folderName) { + String userHome = System.getProperty("user.home"); + if (userHome == null) { + userHome = System.getProperty("userHome"); + } + String filePath = StableUtils.pathJoin(userHome, folderName, ProductConstants.APP_NAME + "Env.xml"); + return new File(filePath); + } + + private String getOldActiveKeyFromFile(File envFile) { + if (!envFile.exists()) { + return StringUtils.EMPTY; + } + + DesignerEnvManager temp = new DesignerEnvManager(); + try { + XMLTools.readFileXML(temp, envFile); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return temp.getActivationKey(); + } + + //默认只从7.0和711的设计器里读取key + private String readOldKey() { + File file71 = getOldEnvFile(OLD_ENV_FOLDER_71); + if (!file71.exists()) { + File file70 = getOldEnvFile(OLD_ENV_FOLDER_70); + return getOldActiveKeyFromFile(file70); + } + + return getOldActiveKeyFromFile(file71); + } + + /** + * 设计器退出时, 做的一些操作. + */ + @Override + public void shutDown() { + InformationCollector collector = InformationCollector.getInstance(); + collector.collectStopTime(); + collector.saveXMLFile(); + } + +} 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 1d781d31ec..5f8ad4ed55 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 @@ -3,20 +3,27 @@ package com.fr.start.module; import com.fr.concurrent.NamedThreadFactory; import com.fr.design.DesignerEnvManager; +import com.fr.design.RestartHelper; +import com.fr.design.dialog.TipDialog; import com.fr.design.fun.OemProcessor; import com.fr.design.fun.impl.GlobalListenerProviderManager; +import com.fr.design.mainframe.messagecollect.StartErrorMessageCollector; import com.fr.design.mainframe.messagecollect.StartupMessageCollector; +import com.fr.design.mainframe.messagecollect.entity.DesignerErrorMessage; import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.DesignUtils; import com.fr.design.utils.DesignerPort; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.module.Activator; +import com.fr.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.record.analyzer.EnableMetrics; import com.fr.record.analyzer.Metrics; import com.fr.stable.BuildContext; import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; +import com.fr.start.DesignerProcessType; import com.fr.start.OemHandler; import com.fr.start.ServerStarter; import com.fr.start.SplashContext; @@ -26,6 +33,8 @@ import com.fr.start.server.FineEmbedServer; import com.fr.value.NotNullLazyValue; import org.jetbrains.annotations.NotNull; +import javax.swing.JFrame; +import javax.swing.JOptionPane; import java.io.File; import java.util.concurrent.ExecutorService; @@ -48,12 +57,35 @@ public class DesignerStartup extends Activator { BuildContext.setBuildFilePath("/com/fr/stable/build.properties"); // 检查是否是-Ddebug = true 启动 并切换对应的端口以及环境配置文件 checkDebugStart(); + // 初始化look and feel + DesignUtils.initLookAndFeel(); + if (DesignUtils.isPortOccupied()) { + StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.PORT_OCCUPIED.getId(), + DesignerErrorMessage.PORT_OCCUPIED.getMessage()); + DesignerPort.getInstance().resetPort(); + } if (DesignUtils.isStarted()) { // 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了 final String[] args = startupArgsValue.getValue().get(); DesignUtils.clientSend(args); FineLoggerFactory.getLogger().info("The Designer Has Been Started"); - System.exit(0); + if (args.length == 0) { + TipDialog dialog = new TipDialog(null, DesignerProcessType.INSTANCE.obtain()) { + @Override + protected void endEvent() { + dispose(); + DesignUtils.clientSend(new String[]{"end"}); + RestartHelper.restart(); + } + + @Override + protected void cancelEvent() { + dispose(); + } + }; + dialog.setVisible(true); + } + FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); return; } // 快快显示启动画面 @@ -137,7 +169,7 @@ public class DesignerStartup extends Activator { */ private void setDebugEnv() { - DesignUtils.setPort(DesignerPort.DEBUG_MESSAGE_PORT); + DesignUtils.setPort(DesignerPort.getInstance().getDebugMessagePort()); DesignerEnvManager.setEnvFile(new File(StableUtils.pathJoin( ProductConstants.getEnvHome(), ProductConstants.APP_NAME + "Env_debug.xml" diff --git a/designer-realize/src/test/java/com.fr/design/mainframe/JFileTest.java b/designer-realize/src/test/java/com.fr/design/mainframe/JFileTest.java index 3b5bd1a14e..1fe29fa5dc 100644 --- a/designer-realize/src/test/java/com.fr/design/mainframe/JFileTest.java +++ b/designer-realize/src/test/java/com.fr/design/mainframe/JFileTest.java @@ -19,6 +19,7 @@ import com.fr.report.worksheet.WorkSheet; import com.fr.restriction.Restrictions; import com.fr.stable.module.Module; import com.fr.start.Designer; +import com.fr.start.MainDesigner; import junit.framework.TestCase; import org.junit.Assert; @@ -33,7 +34,7 @@ public class JFileTest extends TestCase { Restrictions.register(ReportRestrictionScene.CELL_COUNT, new CellCountRestriction()); ModuleContext.startModule(Module.PAGE_MODULE); ModuleContext.startModule(Module.VIEW_MODULE); - Designer designer = new Designer(new String[0]); + MainDesigner designer = new MainDesigner(new String[0]); } public void testJWorkBookSetPicture() { From 14dbf5d7be51969c8949f012870370f00a8bb841 Mon Sep 17 00:00:00 2001 From: Hades Date: Tue, 11 Feb 2020 20:36:59 +0800 Subject: [PATCH 2/5] fix --- .../src/main/java/com/fr/design/DesignerEnvManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index 4e01d2d2dd..cb8634c002 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -1547,7 +1547,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } else if (name.equals(vcsConfigManager.XML_TAG)) { readVcsAttr(reader); } else if (DesignerPort.XML_TAG.equals(name)) { - + readDesignerPort(reader); } else { readLayout(reader, name); From e3d99c5f77b44a1d588bc9e85287de46370fd12c Mon Sep 17 00:00:00 2001 From: Hades Date: Tue, 11 Feb 2020 20:40:04 +0800 Subject: [PATCH 3/5] fix --- .../src/main/java/com/fr/design/dialog/TipDialog.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/dialog/TipDialog.java b/designer-base/src/main/java/com/fr/design/dialog/TipDialog.java index 554d70a22b..14997f8687 100644 --- a/designer-base/src/main/java/com/fr/design/dialog/TipDialog.java +++ b/designer-base/src/main/java/com/fr/design/dialog/TipDialog.java @@ -22,7 +22,7 @@ import java.awt.event.ActionListener; * @version 10.0 * Created by hades on 2020/1/8 */ -public class TipDialog extends JDialog implements ActionListener { +public abstract class TipDialog extends JDialog implements ActionListener { private UIButton endButton; private UIButton cancelButton; @@ -80,13 +80,9 @@ public class TipDialog extends JDialog implements ActionListener { } - protected void endEvent() { - // do nothing - } + protected abstract void endEvent(); - protected void cancelEvent() { - // do nothing - } + protected abstract void cancelEvent(); @Override public void actionPerformed(ActionEvent e) { From dc7f760caceeccdbe3d5241bf08820f489a68906 Mon Sep 17 00:00:00 2001 From: Hades Date: Tue, 11 Feb 2020 20:54:16 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=BC=8F=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StartErrorMessageCollector.java | 43 +++++++++++++++++++ .../entity/DesignerErrorMessage.java | 37 ++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java create mode 100644 designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/DesignerErrorMessage.java diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java new file mode 100644 index 0000000000..0b6a6b0e4c --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java @@ -0,0 +1,43 @@ +package com.fr.design.mainframe.messagecollect; + +import com.fr.config.MarketConfig; +import com.fr.design.DesignerEnvManager; +import com.fr.design.mainframe.errorinfo.ErrorInfo; +import com.fr.stable.StringUtils; + +/** + * + * @author hades + * @version 10.0 + * Created by hades on 2020/1/8 + */ +public class StartErrorMessageCollector { + + private static final StartErrorMessageCollector INSTANCE = new StartErrorMessageCollector(); + + private String uuid; + private String activeKey; + + + public static StartErrorMessageCollector getInstance() { + return INSTANCE; + } + + private StartErrorMessageCollector() { + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + this.uuid = envManager.getUUID(); + this.activeKey = envManager.getActivationKey(); + } + + public void record(String id, String msg, String detail) { + ErrorInfo errorInfo = new ErrorInfo(StringUtils.EMPTY, uuid, activeKey); + errorInfo.setLogid(id); + errorInfo.setLog(msg); + errorInfo.setStackTrace(detail); + errorInfo.saveAsJSON(); + } + + public void record(String id, String msg) { + record(id, msg, StringUtils.EMPTY); + } +} diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/DesignerErrorMessage.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/DesignerErrorMessage.java new file mode 100644 index 0000000000..d2047336ec --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/DesignerErrorMessage.java @@ -0,0 +1,37 @@ +package com.fr.design.mainframe.messagecollect.entity; + +import com.fr.design.i18n.Toolkit; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/1/8 + */ +public enum DesignerErrorMessage { + + DESIGNER_PROCESS_OCCUPIED("11300201", Toolkit.i18nText("Fine-Design_Error_Process_Occupied_Message")), + PORT_OCCUPIED("11300202", Toolkit.i18nText("Fine-Design_Error_Port_Occupied_Message")), + FINEDB_PROBLEM("11300203", Toolkit.i18nText("Fine-Design_Error_Finedb_Problem_Message")), + DESIGNER_OUT_OF_MEMORY("11300204", Toolkit.i18nText("Fine-Design_Error_Out_Of_Memory_Message")), + REMOTE_DESIGN_NO_RESPONSE("11300205", Toolkit.i18nText("Fine-Design_Error_Remote_No_Response_Message")), + UNEXCEPTED_START_FAILED("11300200", Toolkit.i18nText("Fine-Design_Error_UnExcepted_Start_Failed")), + UNEXCEPTED_FALL_BACK("11300400 ", Toolkit.i18nText("Fine-Design_Error_UnExcepted_Fall_Back")); + + + + private String id; + private String message; + + public String getId() { + return id; + } + + public String getMessage() { + return message; + } + + DesignerErrorMessage(String id, String message) { + this.id = id; + this.message = message; + } +} From 5f6e4f48edc6ffccc596b2b77b0572f0159ba82e Mon Sep 17 00:00:00 2001 From: Hades Date: Thu, 13 Feb 2020 16:23:47 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 8 ++--- .../java/com/fr/design/RestartHelper.java | 5 ++-- .../fr/design/mainframe/DesignerFrame.java | 5 ++-- .../java/com/fr/design/utils/DesignUtils.java | 6 ++-- .../main/java/com/fr/exit/DesignerExiter.java | 30 +++++++++++++++++++ .../main/java/com/fr/start/BaseDesigner.java | 6 ++-- .../start/CollectUserInformationDialog.java | 8 ++--- .../main/java/com/fr/start/MainDesigner.java | 3 +- .../com/fr/start/module/DesignerStartup.java | 5 ++-- 9 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/exit/DesignerExiter.java diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index ecdef3ed7e..cfb488694f 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -13,11 +13,10 @@ import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.design.utils.DesignUtils; import com.fr.env.EnvListPane; +import com.fr.exit.DesignerExiter; import com.fr.general.GeneralContext; import com.fr.license.exception.RegistEditionException; import com.fr.log.FineLoggerFactory; -import com.fr.process.engine.core.FineProcessContext; -import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.AssistUtils; import com.fr.stable.EnvChangedListener; import com.fr.start.server.ServerTray; @@ -245,14 +244,13 @@ public class EnvChangeEntrance { @Override public void doOk() { if (!envListOkAction(envListPane, PopTipStrategy.NOW)) { - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + DesignerExiter.getInstance().execute(); } } @Override public void doCancel() { - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); - } + DesignerExiter.getInstance().execute(); } }); envListDialog.setVisible(true); } diff --git a/designer-base/src/main/java/com/fr/design/RestartHelper.java b/designer-base/src/main/java/com/fr/design/RestartHelper.java index 10bee060e7..596257d70c 100644 --- a/designer-base/src/main/java/com/fr/design/RestartHelper.java +++ b/designer-base/src/main/java/com/fr/design/RestartHelper.java @@ -2,11 +2,10 @@ package com.fr.design; import com.fr.design.mainframe.DesignerContext; import com.fr.design.os.impl.RestartAction; +import com.fr.exit.DesignerExiter; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralUtils; import com.fr.log.FineLoggerFactory; -import com.fr.process.engine.core.FineProcessContext; -import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.ArrayUtils; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; @@ -154,7 +153,7 @@ public class RestartHelper { } finally { WorkContext.getCurrent().close(); frame.dispose(); - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + DesignerExiter.getInstance().execute(); } } 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 14a566c731..718a9f50c0 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 @@ -43,6 +43,7 @@ import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.event.EventDispatcher; import com.fr.exception.DecryptTemplateException; +import com.fr.exit.DesignerExiter; import com.fr.file.FILE; import com.fr.file.FILEFactory; import com.fr.file.FileFILE; @@ -54,8 +55,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.process.engine.core.FineProcessContext; -import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.OperatingSystem; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; @@ -1161,7 +1160,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta this.dispose(); this.ad.shutDown(); - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + DesignerExiter.getInstance().execute(); } // harry:添加程序外拖拽文件进来打开的功能 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 93e3e0c1a7..d8f5d01161 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 @@ -8,13 +8,12 @@ import com.fr.design.ExtraDesignClassManager; import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.gui.UILookAndFeel; import com.fr.design.mainframe.DesignerContext; +import com.fr.exit.DesignerExiter; import com.fr.file.FileFILE; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; import com.fr.general.GeneralContext; import com.fr.log.FineLoggerFactory; -import com.fr.process.engine.core.FineProcessContext; -import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.ArrayUtils; import com.fr.stable.CommonCodeUtils; import com.fr.stable.StableUtils; @@ -191,8 +190,7 @@ public class DesignUtils { } else if ("check".equals(line)) { clientSend(new String[] {"response"}, socket); } else if ("end".equals(line)) { - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); - } + DesignerExiter.getInstance().execute(); } else if (StringUtils.isNotEmpty(line)) { File f = new File(line); String path = f.getAbsolutePath(); diff --git a/designer-base/src/main/java/com/fr/exit/DesignerExiter.java b/designer-base/src/main/java/com/fr/exit/DesignerExiter.java new file mode 100644 index 0000000000..8264d8db91 --- /dev/null +++ b/designer-base/src/main/java/com/fr/exit/DesignerExiter.java @@ -0,0 +1,30 @@ +package com.fr.exit; + +import com.fr.process.engine.core.FineProcessContext; +import com.fr.process.engine.core.FineProcessEngineEvent; +import com.fr.stable.StableUtils; + + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/2/12 + */ +public class DesignerExiter { + + public static final DesignerExiter INSTANCE = new DesignerExiter(); + + private static final String DOT = "."; + + public static DesignerExiter getInstance() { + return INSTANCE; + } + + public void execute() { + if (FineProcessContext.getParentPipe() == null && DOT.equals(StableUtils.getInstallHome())) { + System.exit(0); + } else { + FineProcessContext.getParentPipe().fire(FineProcessEngineEvent.DESTROY); + } + } +} diff --git a/designer-base/src/main/java/com/fr/start/BaseDesigner.java b/designer-base/src/main/java/com/fr/start/BaseDesigner.java index 5c0e8d013f..a36c29822f 100644 --- a/designer-base/src/main/java/com/fr/start/BaseDesigner.java +++ b/designer-base/src/main/java/com/fr/start/BaseDesigner.java @@ -14,18 +14,16 @@ import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrame; import com.fr.design.mainframe.toolbar.ToolBarMenuDock; import com.fr.design.ui.util.UIUtil; -import com.fr.design.utils.DesignUtils; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; import com.fr.event.Null; +import com.fr.exit.DesignerExiter; import com.fr.file.FILE; import com.fr.file.FILEFactory; import com.fr.file.FileFILE; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; -import com.fr.process.engine.core.FineProcessContext; -import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.stable.OperatingSystem; import java.awt.*; @@ -137,7 +135,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { if (!isException) { showDesignerFrame(true); } else { - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + DesignerExiter.getInstance().execute(); } } } diff --git a/designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java b/designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java index 0bfbbceabb..f6a2f8500f 100644 --- a/designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java +++ b/designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java @@ -11,13 +11,9 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.locale.impl.UserInfoMark; import com.fr.design.mainframe.ActiveKeyGenerator; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.CloudCenter; -import com.fr.general.ComparatorUtils; -import com.fr.general.GeneralContext; +import com.fr.exit.DesignerExiter; import com.fr.general.locale.LocaleCenter; import com.fr.general.locale.LocaleMark; -import com.fr.process.engine.core.FineProcessContext; -import com.fr.process.engine.core.FineProcessEngineEvent; import javax.swing.*; import javax.swing.border.TitledBorder; @@ -157,7 +153,7 @@ public class CollectUserInformationDialog extends UIDialog { exitButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + DesignerExiter.getInstance().execute(); } }); // set default pane. diff --git a/designer-realize/src/main/java/com/fr/start/MainDesigner.java b/designer-realize/src/main/java/com/fr/start/MainDesigner.java index 56aa763899..ec32a64699 100644 --- a/designer-realize/src/main/java/com/fr/start/MainDesigner.java +++ b/designer-realize/src/main/java/com/fr/start/MainDesigner.java @@ -42,6 +42,7 @@ import com.fr.design.menu.ShortCut; import com.fr.design.module.DesignModuleFactory; import com.fr.design.utils.concurrent.ThreadFactoryBuilder; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.exit.DesignerExiter; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.module.Module; @@ -130,7 +131,7 @@ public class MainDesigner extends BaseDesigner { @Override protected void okEvent() { dispose(); - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + DesignerExiter.getInstance().execute(); } @Override 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 5f8ad4ed55..0adb4a6e28 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 @@ -13,11 +13,10 @@ import com.fr.design.mainframe.messagecollect.entity.DesignerErrorMessage; import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.DesignUtils; import com.fr.design.utils.DesignerPort; +import com.fr.exit.DesignerExiter; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.module.Activator; -import com.fr.process.engine.core.FineProcessContext; -import com.fr.process.engine.core.FineProcessEngineEvent; import com.fr.record.analyzer.EnableMetrics; import com.fr.record.analyzer.Metrics; import com.fr.stable.BuildContext; @@ -85,7 +84,7 @@ public class DesignerStartup extends Activator { }; dialog.setVisible(true); } - FineProcessContext.getChildPipe().fire(FineProcessEngineEvent.DESTROY); + DesignerExiter.getInstance().execute(); return; } // 快快显示启动画面