From a92ed2f8402453ee7b2ea374d89f657a1b0cb0d6 Mon Sep 17 00:00:00 2001 From: zack Date: Wed, 22 Aug 2018 10:30:27 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-10384=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=90=AF=E5=8A=A8=E5=81=87=E6=AD=BB=E9=97=AE?= =?UTF-8?q?=E9=A2=98,=E5=86=85=E7=BD=AE=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E6=8F=90=E5=89=8D=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/iprogressbar/ProgressDialog.java | 3 + .../fr/design/mainframe/DesignerFrame.java | 30 +++++++ .../main/java/com/fr/start/BaseDesigner.java | 12 ++- .../main/java/com/fr/start/ServerStarter.java | 31 +++++-- .../server/FineEmbedServerActivator.java | 2 + .../start/server/FineEmbedServerMonitor.java | 89 +++++++++++++++++++ .../com/fr/start/module/DesignerStartup.java | 9 +- 7 files changed, 163 insertions(+), 13 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/start/server/FineEmbedServerMonitor.java diff --git a/designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java b/designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java index 2247fe453..049b868c4 100644 --- a/designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java +++ b/designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java @@ -77,4 +77,7 @@ public class ProgressDialog extends UIDialog { centerDialog.dispose(); super.dispose(); } + public void updateLoadingText(String text) { + this.text.setText(text); + } } 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 78f546f4d..971834e89 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 @@ -1153,4 +1153,34 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta return progressDialog; } + public void showProgressDialog() { + + progressDialog.setVisible(true); + + } + + /** + * 隐藏进度框 + */ + public void hideProgressDialog() { + + progressDialog.setVisible(false); + } + + /** + * 更新进度框进度 + * @param progress + */ + public void updateProgress(int progress) { + + progressDialog.setProgressValue(progress); + } + + /** + * 释放进度框 + */ + public void disposeProgressDialog() { + + progressDialog.dispose(); + } } 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 932a1ebb8..3e466ed1f 100644 --- a/designer-base/src/main/java/com/fr/start/BaseDesigner.java +++ b/designer-base/src/main/java/com/fr/start/BaseDesigner.java @@ -31,6 +31,10 @@ import java.lang.reflect.Method; * The main class of Report Designer. */ public abstract class BaseDesigner extends ToolBarMenuDock { + private static final int PERCENT_TEN = 10; + private static final int PERCENT_SIXTY = 60; + private static final int PERCENT_NINTY= 90; + private static final int PERCENT_COMPLETE= 100; private static final int LOAD_TREE_MAXNUM = 10; @@ -51,15 +55,15 @@ public abstract class BaseDesigner extends ToolBarMenuDock { public void show(final String[] args) { collectUserInformation(); - DesignerContext.getDesignerFrame().getProgressDialog().setProgressValue(10); + DesignerContext.getDesignerFrame().updateProgress(PERCENT_TEN); showDesignerFrame(args, DesignerContext.getDesignerFrame(), false); - DesignerContext.getDesignerFrame().getProgressDialog().setProgressValue(60); + DesignerContext.getDesignerFrame().updateProgress(PERCENT_SIXTY); DesignerContext.getDesignerFrame().refreshEnv(); - DesignerContext.getDesignerFrame().getProgressDialog().setProgressValue(90); + DesignerContext.getDesignerFrame().updateProgress(PERCENT_NINTY); for (int i = 0; !TemplateTreePane.getInstance().getTemplateFileTree().isTemplateShowing() && i < LOAD_TREE_MAXNUM; i++) { TemplateTreePane.getInstance().getTemplateFileTree().refresh(); } - DesignerContext.getDesignerFrame().getProgressDialog().setProgressValue(100); + DesignerContext.getDesignerFrame().updateProgress(PERCENT_COMPLETE); } diff --git a/designer-base/src/main/java/com/fr/start/ServerStarter.java b/designer-base/src/main/java/com/fr/start/ServerStarter.java index b916bd679..5ea007cd8 100644 --- a/designer-base/src/main/java/com/fr/start/ServerStarter.java +++ b/designer-base/src/main/java/com/fr/start/ServerStarter.java @@ -5,20 +5,21 @@ import com.fr.base.ServerConfig; import com.fr.design.DesignerEnvManager; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; - import com.fr.log.FineLoggerFactory; import com.fr.stable.OperatingSystem; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.start.server.FineEmbedServer; +import com.fr.start.server.FineEmbedServerMonitor; import com.fr.workspace.WorkContext; - -import javax.swing.*; -import java.awt.*; +import javax.swing.JOptionPane; +import java.awt.Desktop; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class ServerStarter { @@ -57,10 +58,24 @@ public class ServerStarter { * * @param url 指定路径 */ - public static void browserURLWithLocalEnv(String url) { - - FineEmbedServer.start(); - browser(url); + public static void browserURLWithLocalEnv(final String url) { + + if(!FineEmbedServerMonitor.getInstance().isComplete()){ + FineEmbedServerMonitor.getInstance().monitor(); + ExecutorService service = Executors.newSingleThreadExecutor(); + service.submit(new Runnable() { + + @Override + public void run() { + FineEmbedServer.start(); + browser(url); + } + }); + service.shutdown(); + }else{ + FineEmbedServer.start(); + browser(url); + } } private static void browser(String uri) { diff --git a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java index 176db579a..15196000e 100644 --- a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java +++ b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java @@ -30,9 +30,11 @@ public class FineEmbedServerActivator extends Activator { public synchronized void start() { try { + FineEmbedServerMonitor.getInstance().reset(); //初始化tomcat initTomcat(); tomcat.start(); + FineEmbedServerMonitor.getInstance().setComplete(); } catch (LifecycleException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } diff --git a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerMonitor.java b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerMonitor.java new file mode 100644 index 000000000..08ecd3536 --- /dev/null +++ b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerMonitor.java @@ -0,0 +1,89 @@ +package com.fr.start.server; + +import com.fr.design.mainframe.DesignerContext; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.event.Null; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * 内置服务器启动监视器 + * Created by zack on 2018/8/21. + */ +public class FineEmbedServerMonitor { + private int progress; + private static final int COMPLETE = 100;//启动完成 + private static final int STEP = 5;//随便设置一个假的进度条 + private static final int STEP_HEARTBEAT = 2000;//2秒更新进度 + private static volatile FineEmbedServerMonitor monitor; + + private FineEmbedServerMonitor() { + } + + static { + EventDispatcher.listen(EmbedServerEvent.AfterStop, new Listener() { + @Override + public void on(Event event, Null aNull) { + DesignerContext.getDesignerFrame().disposeProgressDialog(); + } + }); + } + + public static FineEmbedServerMonitor getInstance() { + if (monitor == null) { + synchronized (FineEmbedServerMonitor.class) { + if (monitor == null) { + monitor = new FineEmbedServerMonitor(); + } + } + } + return monitor; + } + + public int getProgress() { + if (progress == COMPLETE) { + return progress; + } else { + progress += STEP; + return progress; + } + } + + public void setComplete() { + this.progress = COMPLETE; + } + + public void reset() { + this.progress = 0; + } + + public boolean isComplete() { + return this.progress == COMPLETE; + } + + public void monitor() { + ExecutorService service = Executors.newSingleThreadExecutor(); + service.submit(new Runnable() { + + @Override + public void run() { + while (!isComplete()) { + if (!DesignerContext.getDesignerFrame().getProgressDialog().isVisible()) { + DesignerContext.getDesignerFrame().showProgressDialog(); + DesignerContext.getDesignerFrame().getProgressDialog().updateLoadingText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Loading_Embed_Server")); + } + DesignerContext.getDesignerFrame().updateProgress(getProgress()); + try { + Thread.sleep(STEP_HEARTBEAT); + } catch (InterruptedException ignore) { + } + } + DesignerContext.getDesignerFrame().disposeProgressDialog(); + } + }); + service.shutdown(); + } +} 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 aac6112ee..7c63552cd 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 @@ -10,6 +10,7 @@ import com.fr.record.analyzer.Metrics; import com.fr.start.Designer; import com.fr.start.ServerStarter; import com.fr.start.SplashContext; +import com.fr.start.server.FineEmbedServer; import com.fr.startup.activators.BasicActivator; import com.fr.workspace.Workspace; import com.fr.workspace.WorkspaceEvent; @@ -39,7 +40,13 @@ public class DesignerStartup extends Activator { startSub(EnvBasedModule.class); //designer模块启动好后,查看demo browserDemo(); - ExecutorService service = Executors.newSingleThreadExecutor(); + ExecutorService service = Executors.newFixedThreadPool(2); + service.submit(new Runnable() { + @Override + public void run() { + FineEmbedServer.start(); + } + }); service.submit(new Runnable() { @Override