Browse Source

DEC-472 新模块划分与启动、关闭框架

修改设计器启动时到新Module形式
master
ju 7 years ago
parent
commit
a1e10bd799
  1. 23
      designer/src/com/fr/start/Designer.java
  2. 86
      designer/src/com/fr/start/Designer4BI.java
  3. 14
      designer/src/com/fr/start/ReportSplashPane.java
  4. 65
      designer/src/com/fr/start/module/DesignerEnvActivator.java
  5. 101
      designer/src/com/fr/start/module/DesignerStartup.java
  6. 55
      designer/src/com/fr/start/module/PreStartActivator.java
  7. 38
      designer/src/com/fr/start/module/StartFinishActivator.java
  8. 21
      designer/src/com/fr/start/module/StartupArgs.java
  9. 6
      designer/src/com/fr/start/module/module-designer-env.xml
  10. 10
      designer/src/com/fr/start/module/startup-designer.xml
  11. 175
      designer_base/src/com/fr/start/BaseDesigner.java

23
designer/src/com/fr/start/Designer.java

@ -40,18 +40,17 @@ import com.fr.design.utils.concurrent.ThreadFactoryBuilder;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.module.Module;
import com.fr.module.ModuleStartup;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLTools;
import com.fr.start.module.StartupArgs;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.*;
import javax.swing.border.MatteBorder;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
@ -83,7 +82,11 @@ public class Designer extends BaseDesigner {
* @param args 参数
*/
public static void main(String[] args) {
new Designer(args);
Module designerRoot = ModuleStartup.parse("/com/fr/start/module/startup-designer.xml");
//传递启动参数
designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args));
designerRoot.start();
}
public Designer(String[] args) {
@ -375,12 +378,6 @@ public class Designer extends BaseDesigner {
return AlphaFinePane.getAlphaFinePane();
}
@Override
protected SplashPane createSplashPane() {
return new ReportSplashPane();
}
/**
* 收集用户信息吗
*/

86
designer/src/com/fr/start/Designer4BI.java

@ -1,86 +0,0 @@
package com.fr.start;
import java.util.ArrayList;
import java.util.List;
import com.fr.base.FRContext;
import com.fr.design.actions.file.newReport.NewWorkBookAction;
import com.fr.design.actions.report.ReportFooterAction;
import com.fr.design.actions.report.ReportHeaderAction;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.menu.MenuDef;
import com.fr.design.menu.ShortCut;
import com.fr.general.ComparatorUtils;
import com.fr.stable.Constants;
/**
* Created with IntelliJ IDEA.
* User: richie
* Date: 12/17/13
* Time: 12:54 PM
* 这是英文版的GridBI设计器启动类
*/
public class Designer4BI extends Designer {
/**
* 启动BI的设计器
*
* @param args 参数
*
*/
public static void main(String[] args) {
new Designer4BI(args);
}
public Designer4BI(String[] args) {
super(args);
}
protected void initLanguage() {
//这两句的位置不能随便调换,因为会影响语言切换的问题
FRContext.setLanguage(Constants.LANGUAGE_ENGLISH);
}
protected SplashPane createSplashPane() {
return new BISplashPane();
}
@Override
/**
* 创建新建文件的快捷方式数组
* @return 返回快捷方式的数组
*/
public ShortCut[] createNewFileShortCuts() {
ArrayList<ShortCut> shortCuts = new ArrayList<ShortCut>();
shortCuts.add(new NewWorkBookAction());
return shortCuts.toArray(new ShortCut[shortCuts.size()]);
}
/**
* 获取模板-菜单选项
*
* @param plus 当前的工作对象
*
* @return 菜单栏对象数组
*
*/
public MenuDef[] createTemplateShortCuts(ToolBarMenuDockPlus plus) {
MenuDef[] menuDefs = plus.menus4Target();
for (MenuDef m : menuDefs) {
List<ShortCut> shortCuts = new ArrayList<ShortCut>();
for (int i = 0, count = m.getShortCutCount(); i < count; i++) {
ShortCut shortCut = m.getShortCut(i);
if (!ComparatorUtils.equals(shortCut.getClass(), ReportHeaderAction.class)
&& !ComparatorUtils.equals(shortCut.getClass(), ReportFooterAction.class)) {
shortCuts.add(shortCut);
}
}
m.clearShortCuts();
for (int i = 0, len = shortCuts.size(); i < len; i ++) {
m.addShortCut(shortCuts.get(i));
}
}
return menuDefs;
}
}

14
designer/src/com/fr/start/ReportSplashPane.java

@ -51,6 +51,8 @@ public class ReportSplashPane extends SplashPane {
private int loadingIndex = 0;
private String[] loading = new String[]{"..", "....", "......"};
private java.util.Timer timer = new java.util.Timer();
private ModuleListener listener;
private static float uiScale(float f) {
return f * JBUI_INIT_SCALE;
@ -74,8 +76,8 @@ public class ReportSplashPane extends SplashPane {
ReportSplashPane.this.repaint();
}
}, 0, 300);
ModuleListener moduleListener = new ModuleAdapter() {
listener = new ModuleAdapter() {
@Override
public void onStartBefore(String moduleName, String moduleI18nName) {
moduleID = moduleI18nName;
@ -84,9 +86,13 @@ public class ReportSplashPane extends SplashPane {
ReportSplashPane.this.repaint();
}
};
ModuleContext.registerModuleListener(moduleListener);
}
public ModuleListener getModuleListener() {
return listener;
}
protected void paintComponent(Graphics g) {
Icon icon = IconLoader.getIcon(StableUtils.pathJoin(OEM_PATH, getImageName()));
icon.paintIcon(null, g, 0, 0);

65
designer/src/com/fr/start/module/DesignerEnvActivator.java

@ -0,0 +1,65 @@
package com.fr.start.module;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.TemplatePane;
import com.fr.design.module.DesignerModule;
import com.fr.env.SignIn;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.general.ModuleContext;
import com.fr.module.Activator;
import com.fr.stable.module.ModuleListener;
import com.fr.start.StartServer;
/**
* Created by juhaoyu on 2018/1/8.
* 设计器启动时的环境相关模块activator
*/
public class DesignerEnvActivator extends Activator {
@Override
public void start() {
String[] args = getModule().findSingleton(StartupArgs.class).get();
if (args != null) {
for (String arg : args) {
if (ComparatorUtils.equals(arg, "demo")) {
DesignerEnvManager.getEnvManager().setCurrentEnv2Default();
StartServer.browserDemoURL();
break;
}
}
}
//设置好环境即可,具体跟环境有关的模块会自动调用
switch2LastEnv();
//启动core部分
getSub("core").start();
//启动其他模块
//todo 也切换到新Module
ModuleContext.registerModuleListener(getModule().findSingleton(ModuleListener.class));
ModuleContext.startModule(DesignerModule.class.getName());
switch2LastEnv();
}
private void switch2LastEnv() {
try {
String current = DesignerEnvManager.getEnvManager().getCurEnvName();
SignIn.signIn(DesignerEnvManager.getEnvManager().getEnv(current));
if (!FRContext.getCurrentEnv().testServerConnectionWithOutShowMessagePane()) {
throw new Exception(Inter.getLocText("Datasource-Connection_failed"));
}
} catch (Exception e) {
TemplatePane.getInstance().dealEvnExceptionWhenStartDesigner();
}
}
@Override
public void stop() {
//清空模块
}
}

101
designer/src/com/fr/start/module/DesignerStartup.java

@ -0,0 +1,101 @@
package com.fr.start.module;
import com.fr.design.DesignerEnvManager;
import com.fr.design.utils.DesignUtils;
import com.fr.general.ComparatorUtils;
import com.fr.module.Activator;
import com.fr.stable.ProductConstants;
import com.fr.stable.module.ModuleListener;
import com.fr.start.Designer;
import com.fr.start.ReportSplashPane;
import com.fr.start.SplashWindow;
import com.fr.startup.activators.BasicActivator;
import java.io.File;
/**
* Created by juhaoyu on 2018/1/8.
*/
public class DesignerStartup extends Activator {
private static final int MESSAGE_PORT = 51462;
private static final int DEBUG_PORT = 51463;
@Override
public void start() {
startSub(PreStartActivator.class);
if (checkMultiStart()) {
return;
}
//启动基础部分
startSub(BasicActivator.class);
//启动画面
SplashWindow splashWindow = createSplashWindow();
//启动env
startSub(DesignerEnvActivator.class);
//启动设计器界面
startDesigner();
//启动画面结束
splashWindow.setVisible(false);
splashWindow.dispose();
startSub(StartFinishActivator.class);
}
private SplashWindow createSplashWindow() {
ReportSplashPane reportSplashPane = new ReportSplashPane();
SplashWindow splashWindow = new SplashWindow(reportSplashPane);
getModule().setSingleton(ModuleListener.class, reportSplashPane.getModuleListener());
return splashWindow;
}
private void startDesigner() {
new Designer(getModule().getSingleton(StartupArgs.class).get());
}
private boolean checkMultiStart() {
if (isDebug()) {
setDebugEnv();
} else {
DesignUtils.setPort(getStartPort());
}
// 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了
if (DesignUtils.isStarted()) {
DesignUtils.clientSend(getModule().findSingleton(StartupArgs.class).get());
return true;
}
return false;
}
private int getStartPort() {
return MESSAGE_PORT;
}
//在VM options里加入-Ddebug=true激活
private boolean isDebug() {
return ComparatorUtils.equals("true", System.getProperty("debug"));
}
//端口改一下,环境配置文件改一下。便于启动两个设计器,进行对比调试
private void setDebugEnv() {
DesignUtils.setPort(DEBUG_PORT);
DesignerEnvManager.setEnvFile(new File(ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "Env_debug.xml"));
}
@Override
public void stop() {
}
}

55
designer/src/com/fr/start/module/PreStartActivator.java

@ -0,0 +1,55 @@
package com.fr.start.module;
import com.fr.base.ConfigManagerCreatorProxy;
import com.fr.base.ConfigManagerFactory;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.module.DesignModule;
import com.fr.general.GeneralContext;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.module.Activator;
import com.fr.plugin.conversion.PluginConversionModule;
import com.fr.stable.BuildContext;
/**
* Created by juhaoyu on 2018/1/8.
*/
public class PreStartActivator extends Activator {
@Override
public void start() {
RestartHelper.deleteRecordFilesWhenStart();
ConfigManagerFactory.registerConfigManagerProxy(new ConfigManagerCreatorProxy());
BuildContext.setBuildFilePath(buildPropertiesPath());
SiteCenter.getInstance();
//标记一下是设计器启动
PluginConversionModule.getInstance().markDesignerStart();
initLanguage();
// 在 initLanguage 之后加载设计器国际化文件,确保是正确的语言环境
Inter.loadLocaleFile(GeneralContext.getLocale(), DesignModule.LOCALE_FILE_PATH);
}
private void initLanguage() {
//这两句的位置不能随便调换,因为会影响语言切换的问题
FRContext.setLanguage(DesignerEnvManager.getEnvManager(false).getLanguage());
DesignerEnvManager.checkNameEnvMap();
}
/**
* build得路径
*/
private String buildPropertiesPath() {
return "/com/fr/stable/build.properties";
}
@Override
public void stop() {
}
}

38
designer/src/com/fr/start/module/StartFinishActivator.java

@ -0,0 +1,38 @@
package com.fr.start.module;
import com.fr.design.fun.impl.GlobalListenerProviderManager;
import com.fr.design.utils.DesignUtils;
import com.fr.general.ModuleContext;
import com.fr.module.Activator;
/**
* Created by juhaoyu on 2018/1/8.
*/
public class StartFinishActivator extends Activator {
private static final int MESSAGE_PORT = 51462;
@Override
public void start() {
DesignUtils.creatListeningServer(getStartPort(), startFileSuffix());
ModuleContext.clearModuleListener();
GlobalListenerProviderManager.getInstance().init();
}
private int getStartPort() {
return MESSAGE_PORT;
}
private String[] startFileSuffix() {
return new String[]{".cpt", ".xls", ".xlsx", ".frm", ".form", ".cht", ".chart"};
}
@Override
public void stop() {
}
}

21
designer/src/com/fr/start/module/StartupArgs.java

@ -0,0 +1,21 @@
package com.fr.start.module;
/**
* Created by juhaoyu on 2018/1/8.
* 封装启动参数
*/
public class StartupArgs {
private final String[] args;
public StartupArgs(String[] args) {
this.args = args;
}
public String[] get() {
return args;
}
}

6
designer/src/com/fr/start/module/module-designer-env.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--设计器环境模块-->
<designer-env activator="com.fr.start.module.DesignerEnvActivator" invoke-children-strategy="custom">
<core ref="/com/fr/startup/config/module-core.xml"/>
<!--todo 现在存在的这些个模块-->
</designer-env>

10
designer/src/com/fr/start/module/startup-designer.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<startup-designer activator="com.fr.start.module.DesignerStartup" invoke-children-strategy="custom">
<!--启动前的准备工作-->
<pre-start activator="com.fr.start.module.PreStartActivator"/>
<basic ref="/com/fr/startup/config/module-basic.xml"/>
<!--环境相关模块-->
<designer-env ref="/com/fr/start/module/module-designer-env.xml"/>
<!--启动完成后的清理工作-->
<start-finish activator="com.fr.start.module.StartFinishActivator"/>
</startup-designer>

175
designer_base/src/com/fr/start/BaseDesigner.java

@ -3,13 +3,9 @@
*/
package com.fr.start;
import com.fr.base.ConfigManagerCreatorProxy;
import com.fr.base.ConfigManagerFactory;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.RestartHelper;
import com.fr.design.extra.WebViewDlgHelper;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MutilTempalteTabPane;
import com.fr.design.file.TemplateTreePane;
@ -18,7 +14,6 @@ import com.fr.design.fun.impl.GlobalListenerProviderManager;
import com.fr.design.mainframe.DesignerFrame;
import com.fr.design.mainframe.TemplatePane;
import com.fr.design.mainframe.toolbar.ToolBarMenuDock;
import com.fr.design.module.DesignModule;
import com.fr.design.utils.DesignUtils;
import com.fr.env.SignIn;
import com.fr.file.FILE;
@ -26,25 +21,11 @@ import com.fr.file.FILEFactory;
import com.fr.file.FileFILE;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.GeneralContext;
import com.fr.general.Inter;
import com.fr.general.ModuleContext;
import com.fr.general.SiteCenter;
import com.fr.plugin.PluginCollector;
import com.fr.plugin.conversion.PluginConversionModule;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.PluginStartup;
import com.fr.register.Register;
import com.fr.stable.ArrayUtils;
import com.fr.stable.BuildContext;
import com.fr.stable.OperatingSystem;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
@ -56,180 +37,34 @@ import java.lang.reflect.Method;
public abstract class BaseDesigner extends ToolBarMenuDock {
private static final int LOAD_TREE_MAXNUM = 10;
private static final int MESSAGEPORT = 51462;
private Timer timer;
public BaseDesigner(String[] args) {
init(args);
}
private void init(String[] args) {
RestartHelper.deleteRecordFilesWhenStart();
ConfigManagerFactory.registerConfigManagerProxy(new ConfigManagerCreatorProxy());
//启动core
BuildContext.setBuildFilePath(buildPropertiesPath());
if (isDebug()) {
setDebugEnv();
} else {
DesignUtils.setPort(getStartPort());
}
// 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了
if (DesignUtils.isStarted()) {
DesignUtils.clientSend(args);
return;
}
Register.load();
//标记一下是设计器启动
PluginConversionModule.getInstance().markDesignerStart();
SiteCenter.getInstance();
//下面这两句的位置不能随便调换,因为会影响语言切换的问题
initLanguage();
// 在 initLanguage 之后加载设计器国际化文件,确保是正确的语言环境
Inter.loadLocaleFile(GeneralContext.getLocale(), DesignModule.LOCALE_FILE_PATH);
SplashWindow splashWindow = new SplashWindow(createSplashPane());
if (args != null) {
for (String arg : args) {
if (ComparatorUtils.equals(arg, "demo")) {
DesignerEnvManager.getEnvManager().setCurrentEnv2Default();
StartServer.browserDemoURL();
break;
}
}
}
initLookAndFeel(args, splashWindow);
}
private void initLookAndFeel(String[] args, SplashWindow splashWindow) {
// 初始化look and feel.这个在预加载之前执行是因为lookAndFeel里的东西,预加载时也要用到
DesignUtils.initLookAndFeel();
DesignUtils.creatListeningServer(getStartPort(), startFileSuffix());
// 初始化Log Handler
DesignerEnvManager.loadLogSetting();
DesignerFrame df = createDesignerFrame();
// 默认加载工作目录,用于读取License
switch2LastEnv();
initDefaultFont();
// 必须先初始化Env再去startModule, 不然会导致lic读取不到
ModuleContext.startModule(module2Start());
// 再次加载工作目录,用于读取工作目录下的各种插件
switch2LastEnv();
ModuleContext.clearModuleListener();
collectUserInformation();
showDesignerFrame(args, df, false);
for (int i = 0; !TemplateTreePane.getInstance().getTemplateFileTree().isTemplateShowing() && i < LOAD_TREE_MAXNUM; i++) {
TemplateTreePane.getInstance().getTemplateFileTree().refresh();
}
splashWindow.setVisible(false);
splashWindow.dispose();
bindGlobalListener();
showErrorPluginsMessage();
}
private void bindGlobalListener() {
GlobalListenerProviderManager.getInstance().init();
}
private void showErrorPluginsMessage() {
if (timer == null) {
timer = new Timer(5000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String[] plugins = PluginCollector.getCollector().getErrorPlugins();
if (ArrayUtils.isNotEmpty(plugins)) {
String text = StableUtils.join(plugins, ",") + ": " + Inter.getLocText("FR-Designer_Plugin_Should_Update_Please_Contact_Developer");
int r = JOptionPane.showConfirmDialog(null, text, Inter.getLocText("FR-Designer_Plugin_Should_Update_Title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (r == JOptionPane.OK_OPTION) {
WebViewDlgHelper.createPluginDialog();
}
}
timer.stop();
}
});
timer.start();
}
}
protected String[] startFileSuffix() {
return new String[]{".cpt", ".xls", ".xlsx", ".frm", ".form", ".cht", ".chart"};
}
protected DesignerFrame createDesignerFrame() {
private DesignerFrame createDesignerFrame() {
return new DesignerFrame(this);
}
protected int getStartPort() {
return MESSAGEPORT;
}
protected void initLanguage() {
//这两句的位置不能随便调换,因为会影响语言切换的问题
FRContext.setLanguage(DesignerEnvManager.getEnvManager(false).getLanguage());
DesignerEnvManager.checkNameEnvMap();
}
protected void initDefaultFont() {
}
/**
* build得路径
*
* @return build得路径
*/
public String buildPropertiesPath() {
return "/com/fr/stable/build.properties";
}
protected SplashPane createSplashPane() {
return new SplashPane();
}
//在VM options里加入-Ddebug=true激活
private boolean isDebug() {
return ComparatorUtils.equals("true", System.getProperty("debug"));
}
private static final int DEBUG_PORT = 51463;
//端口改一下,环境配置文件改一下。便于启动两个设计器,进行对比调试
private void setDebugEnv() {
DesignUtils.setPort(DEBUG_PORT);
DesignerEnvManager.setEnvFile(new File(ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "Env_debug.xml"));
}
private void switch2LastEnv() {
try {
String current = DesignerEnvManager.getEnvManager().getCurEnvName();
SignIn.signIn(DesignerEnvManager.getEnvManager().getEnv(current));
if (!FRContext.getCurrentEnv().testServerConnectionWithOutShowMessagePane()) {
throw new Exception(Inter.getLocText("Datasource-Connection_failed"));
}
} catch (Exception e) {
TemplatePane.getInstance().dealEvnExceptionWhenStartDesigner();
}
}
private void showDesignerFrame(String[] args, final DesignerFrame df,
boolean isException) {

Loading…
Cancel
Save