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 93f2824547..c1c11553f7 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -102,11 +102,7 @@ public class EnvChangeEntrance { return false; } - //REPORT-13810如果只是添加了工作目录,没有切换,这里ToolArea也是要显示新建的工作目录 - JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (template != null) { - template.refreshToolArea(); - } + WorkContext.switchTo(workspace, new WorkContextCallback() { @Override public void done() { @@ -119,6 +115,11 @@ public class EnvChangeEntrance { } } }); + //REPORT-13810如果只是添加了工作目录,没有切换,这里ToolArea也是要显示新建的工作目录 + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (template != null) { + template.refreshToolArea(); + } } catch (WorkspaceAuthException | RegistEditionException e) { // String title = Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed"); 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 3e466ed1f3..f88582e664 100644 --- a/designer-base/src/main/java/com/fr/start/BaseDesigner.java +++ b/designer-base/src/main/java/com/fr/start/BaseDesigner.java @@ -31,19 +31,18 @@ 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; + + private final String[] args; public BaseDesigner(String[] args) { - - init(args); + + this.args = args; + init(); } - - private void init(String[] args) { + + private void init() { //初始化 EventDispatcher.fire(ModuleEvent.MajorModuleStarting, Toolkit.i18nText("Fine-Design_Basic_Initializing")); // 初始化look and feel.这个在预加载之前执行是因为lookAndFeel里的东西,预加载时也要用到 @@ -52,18 +51,15 @@ public abstract class BaseDesigner extends ToolBarMenuDock { DesignerEnvManager.loadLogSetting(); createDesignerFrame(); } - - public void show(final String[] args) { + + public void show() { collectUserInformation(); - DesignerContext.getDesignerFrame().updateProgress(PERCENT_TEN); - showDesignerFrame(args, DesignerContext.getDesignerFrame(), false); - DesignerContext.getDesignerFrame().updateProgress(PERCENT_SIXTY); + showDesignerFrame(false); + DesignerContext.getDesignerFrame().setVisible(true); DesignerContext.getDesignerFrame().refreshEnv(); - DesignerContext.getDesignerFrame().updateProgress(PERCENT_NINTY); for (int i = 0; !TemplateTreePane.getInstance().getTemplateFileTree().isTemplateShowing() && i < LOAD_TREE_MAXNUM; i++) { TemplateTreePane.getInstance().getTemplateFileTree().refresh(); } - DesignerContext.getDesignerFrame().updateProgress(PERCENT_COMPLETE); } @@ -71,10 +67,9 @@ public abstract class BaseDesigner extends ToolBarMenuDock { new DesignerFrame(this); } - - - private void showDesignerFrame(String[] args, final DesignerFrame df, - boolean isException) { + + + private void showDesignerFrame(boolean isException) { try { FILE file = null; if (args != null && args.length > 0) { @@ -101,12 +96,13 @@ public abstract class BaseDesigner extends ToolBarMenuDock { file = FILEFactory.createFILE(FILEFactory.ENV_PREFIX + DesignerEnvManager.getEnvManager().getLastOpenFile()); } + DesignerFrame df = DesignerContext.getDesignerFrame(); isException = openFile(df, isException, file); df.fireDesignerOpened(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); if (!isException) { - showDesignerFrame(args, df, true); + showDesignerFrame(true); } else { System.exit(0); } @@ -137,19 +133,14 @@ public abstract class BaseDesigner extends ToolBarMenuDock { df.getSelectedJTemplate().requestGridFocus(); return isException; } - - - /** - * @param window - */ + private void enableFullScreenMode(Window window) { String className = "com.apple.eawt.FullScreenUtilities"; String methodName = "setWindowCanFullScreen"; try { Class clazz = Class.forName(className); - Method method = clazz.getMethod(methodName, new Class[]{ - Window.class, boolean.class}); + Method method = clazz.getMethod(methodName, Window.class, boolean.class); method.invoke(null, window, true); } catch (Throwable t) { FineLoggerFactory.getLogger().error("Full screen mode is not supported"); diff --git a/designer-realize/src/main/java/com/fr/start/DesignerInitial.java b/designer-realize/src/main/java/com/fr/start/DesignerInitial.java new file mode 100644 index 0000000000..ea1faa321d --- /dev/null +++ b/designer-realize/src/main/java/com/fr/start/DesignerInitial.java @@ -0,0 +1,24 @@ +package com.fr.start; + +/** + * Created by juhaoyu on 2019-06-14. + * 设计器上下文 + */ +public class DesignerInitial { + + private static volatile Designer designer; + + public synchronized static void init(String... args) { + + designer = new Designer(args); + } + + public synchronized static void show() { + + if (designer != null) { + designer.show(); + } + //启动画面结束 + SplashContext.getInstance().hide(); + } +} diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java new file mode 100644 index 0000000000..e9bea26922 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java @@ -0,0 +1,21 @@ +package com.fr.start.module; + +import com.fr.module.Activator; +import com.fr.start.DesignerInitial; + +/** + * Created by juhaoyu on 2019-06-14. + */ +public class DesignerInitActivator extends Activator { + + @Override + public void start() { + + DesignerInitial.init(upFindSingleton(StartupArgs.class).get()); + } + + @Override + public void stop() { + + } +} diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerShowActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerShowActivator.java new file mode 100644 index 0000000000..d1e0ab567d --- /dev/null +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerShowActivator.java @@ -0,0 +1,21 @@ +package com.fr.start.module; + +import com.fr.module.Activator; +import com.fr.start.DesignerInitial; + +/** + * Created by juhaoyu on 2019-06-14. + */ +public class DesignerShowActivator extends Activator { + + @Override + public void start() { + + DesignerInitial.show(); + } + + @Override + public void stop() { + + } +} 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 a816769794..97bdceda1b 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 @@ -2,20 +2,15 @@ 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; -import com.fr.log.FineLoggerFactory; import com.fr.module.Activator; import com.fr.record.analyzer.EnableMetrics; import com.fr.record.analyzer.Metrics; import com.fr.runtime.FineRuntime; -import com.fr.start.Designer; +import com.fr.start.DesignerInitial; 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.third.org.apache.commons.lang3.time.StopWatch; import com.fr.workspace.Workspace; import com.fr.workspace.WorkspaceEvent; @@ -27,115 +22,31 @@ import java.util.concurrent.Executors; */ @EnableMetrics 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 - startSub(EnvBasedModule.class); + getSub("parallel").start(); //designer模块启动好后,查看demo browserDemo(); - ExecutorService service = Executors.newFixedThreadPool(2); - service.submit(new Runnable() { - @Override - public void run() { - FineEmbedServer.start(); - } - }); - final StopWatch watch = new StopWatch(); - service.submit(new Runnable() { - - @Override - public void run() { - try { - - watch.start(); - designer.show(args); - } finally { - DesignerContext.getDesignerFrame().getProgressDialog().dispose(); - FineLoggerFactory.getLogger().info("Designer showed.Time used {} ms", watch.getTime()); - watch.stop(); - } - } - }); - service.shutdown(); - DesignerContext.getDesignerFrame().setVisible(true); - //启动画面结束 - SplashContext.getInstance().hide(); - - DesignerContext.getDesignerFrame().getProgressDialog().setVisible(true); + + startSub(DesignerShowActivator.class); 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(Integer.MIN_VALUE) { - - @Override - 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 current) { - getSub(EnvBasedModule.class).start(); - // 切换后的环境是本地环境才启动内置服务器 - 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(); - } - }); - } - - + + @Override public void stop() { - + } } diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java new file mode 100644 index 0000000000..09115eb506 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java @@ -0,0 +1,94 @@ +package com.fr.start.module; + +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.event.Event; +import com.fr.event.Listener; +import com.fr.module.Activator; +import com.fr.start.server.FineEmbedServer; +import com.fr.workspace.WorkContext; +import com.fr.workspace.Workspace; +import com.fr.workspace.WorkspaceEvent; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * Created by juhaoyu on 2019-06-14. + */ +public class DesignerWorkspaceActivator extends Activator { + + @Override + public void start() { + + registerEnvListener(); + startServer(WorkContext.getCurrent()); + } + + + /** + * 注册切换环境前后事件监听 + */ + private void registerEnvListener() { + + /*切换环境前,关闭所有相关模块,最后执行*/ + listenEvent(WorkspaceEvent.BeforeSwitch, new Listener(Integer.MIN_VALUE) { + + @Override + 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 current) { + + getSub(EnvBasedModule.class).start(); + startServer(current); + } + }); + /*切换环境前,存储一下打开的所有文件对象,要先于 关闭相关模块部分 被触发*/ + 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(); + } + }); + } + + private void startServer(Workspace current) { + + // 切换后的环境是本地环境才启动内置服务器 + if (current.isLocal()) { + ExecutorService service = Executors.newSingleThreadExecutor(); + service.submit(new Runnable() { + + @Override + public void run() { + + FineEmbedServer.start(); + } + }); + service.shutdown(); + } + } + + @Override + public void stop() { + + } +}