Browse Source

REPORT-83197【设计器】启动页性能优化

1、DesignerEnvManager 异步加载
2、插件更新功能优化, 改成异步
3、启动页启动时样式变化
4、设计器异步面板加载
feature/x
Harrison 2 years ago
parent
commit
0fbd8b0c6b
  1. 292
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 40
      designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java
  3. 7
      designer-base/src/main/java/com/fr/design/env/LocalDesignerWorkspaceInfo.java
  4. 3
      designer-base/src/main/java/com/fr/start/BaseDesigner.java
  5. 21
      designer-base/src/main/java/com/fr/start/common/DesignerStartupPool.java
  6. 113
      designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java
  7. 87
      designer-base/src/main/java/com/fr/startup/ui/StartupPageWindow.java
  8. 30
      designer-realize/src/main/java/com/fr/start/MainDesigner.java
  9. 39
      designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java
  10. 2
      designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java
  11. 54
      designer-realize/src/main/java/com/fr/start/module/optimized/DesignerStartupPageActivator.java
  12. 20
      designer-realize/src/main/java/com/fr/start/preload/PreLoadService.java

292
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -5,6 +5,7 @@ package com.fr.design;
import com.fr.base.BaseXMLUtils; import com.fr.base.BaseXMLUtils;
import com.fr.base.Utils; import com.fr.base.Utils;
import com.fr.collections.api.Callback;
import com.fr.design.actions.help.alphafine.AlphaFineConfigManager; import com.fr.design.actions.help.alphafine.AlphaFineConfigManager;
import com.fr.design.carton.SwitchForSwingChecker; import com.fr.design.carton.SwitchForSwingChecker;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
@ -21,8 +22,8 @@ import com.fr.design.locale.impl.ProductImproveMark;
import com.fr.design.login.DesignerLoginType; import com.fr.design.login.DesignerLoginType;
import com.fr.design.login.config.DesignerLoginConfigManager; import com.fr.design.login.config.DesignerLoginConfigManager;
import com.fr.design.mainframe.ComponentReuseNotifyUtil; import com.fr.design.mainframe.ComponentReuseNotifyUtil;
import com.fr.design.mainframe.simple.SimpleDesignerConfig;
import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo; import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo;
import com.fr.design.mainframe.simple.SimpleDesignerConfig;
import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.mainframe.vcs.VcsConfigManager;
import com.fr.design.notification.SnapChatConfig; import com.fr.design.notification.SnapChatConfig;
import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.os.impl.SupportOSImpl;
@ -41,6 +42,12 @@ import com.fr.general.SupportLocale;
import com.fr.general.locale.LocaleCenter; import com.fr.general.locale.LocaleCenter;
import com.fr.general.locale.LocaleMark; import com.fr.general.locale.LocaleMark;
import com.fr.general.xml.GeneralXMLTools; import com.fr.general.xml.GeneralXMLTools;
import com.fr.general.xml.async.AsyncXmlElement;
import com.fr.general.xml.async.AsyncXmlReadable;
import com.fr.general.xml.async.SimpleXmlElement;
import com.fr.general.xml.async.XmlElement;
import com.fr.general.xml.async.XmlException;
import com.fr.general.xml.async.XmlInitialFactory;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.log.LogHandler; import com.fr.log.LogHandler;
import com.fr.stable.CommonUtils; import com.fr.stable.CommonUtils;
@ -58,8 +65,10 @@ import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLWriter; import com.fr.stable.xml.XMLWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.start.common.DesignerStartupConfig; import com.fr.start.common.DesignerStartupConfig;
import com.fr.start.common.DesignerStartupPool;
import com.fr.third.apache.logging.log4j.core.appender.FileAppender; import com.fr.third.apache.logging.log4j.core.appender.FileAppender;
import com.fr.third.apache.logging.log4j.core.layout.PatternLayout; import com.fr.third.apache.logging.log4j.core.layout.PatternLayout;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.third.org.apache.commons.io.FilenameUtils;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.WorkContextCallback; import com.fr.workspace.WorkContextCallback;
@ -90,8 +99,8 @@ import java.util.Map.Entry;
/** /**
* The manager of Designer GUI. * The manager of Designer GUI.
*/ */
public class DesignerEnvManager implements XMLReadable, XMLWriter { public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReadable {
private static final int MAX_SHOW_NUM = 10; private static final int MAX_SHOW_NUM = 10;
private static final String VERSION_80 = "80"; private static final String VERSION_80 = "80";
private static final String VERSION_90 = "90"; private static final String VERSION_90 = "90";
@ -104,21 +113,26 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
* 指定默认工作空间 * 指定默认工作空间
*/ */
public static final String DEFAULT_WORKSPACE_PATH = "fr.designer.workspace.default"; public static final String DEFAULT_WORKSPACE_PATH = "fr.designer.workspace.default";
public static final String LAST_EAST_REGION_LAYOUT = "LastEastRegionLayout";
public static final String LAST_WEST_REGION_LAYOUT = "LastWestRegionLayout";
private static DesignerEnvManager designerEnvManager; // gui. private static DesignerEnvManager designerEnvManager; // gui.
private String activationKey = null; private String activationKey = null;
private String logLocation = null; private String logLocation = null;
private Rectangle windowBounds = null; // window bounds. private Rectangle windowBounds = null; // window bounds.
private String DialogCurrentDirectory = null; private String DialogCurrentDirectory = null;
private String CurrentDirectoryPrefix = null; private String CurrentDirectoryPrefix = null;
private Map<String, List<String>> recentOpenedFileListMap = new HashMap<>(); private Map<String, List<String>> recentOpenedFileListMap = new HashMap<>();
private List<String> tempRecentOpenedFilePathList = new ArrayList<String>(); private List<String> tempRecentOpenedFilePathList = new ArrayList<String>();
private XmlElement<Map<String, List<String>>> recentOpenedMapping = SimpleXmlElement.of(recentOpenedFileListMap);
private boolean showPaintToolBar = true; private boolean showPaintToolBar = true;
private int maxNumberOrPreviewRow = 200; private int maxNumberOrPreviewRow = 200;
// name和Env的键值对
private Map<String, DesignerWorkspaceInfo> nameEnvMap = new ListMap<>(); private XmlElement<EnvConfiguration> envConfig = SimpleXmlElement.of(new EnvConfiguration());
// marks: 当前报表服务器名字
private String curEnvName = null;
private boolean showProjectPane = true; private boolean showProjectPane = true;
private boolean showDataPane = true; private boolean showDataPane = true;
//p:这是当前选择的数据库连接的名字,这个在新建数据源的时候用到. //p:这是当前选择的数据库连接的名字,这个在新建数据源的时候用到.
@ -181,7 +195,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
/** /**
* alphafine * alphafine
*/ */
private AlphaFineConfigManager alphaFineConfigManager = AlphaFineConfigManager.getInstance(); private XmlElement<AlphaFineConfigManager> alphaFineConfigManager;
/** /**
* 阅后即焚的配置项 * 阅后即焚的配置项
@ -230,7 +244,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
private boolean propertiesUsable; private boolean propertiesUsable;
private SimpleDesignerConfig fvsDesignerConfig = SimpleDesignerConfig.getInstance("FvsDesignerConfig"); private XmlElement<SimpleDesignerConfig> fvsDesignerConfig = SimpleXmlElement.of(SimpleDesignerConfig.getInstance("FvsDesignerConfig"));
/** /**
* DesignerEnvManager. * DesignerEnvManager.
@ -245,12 +259,18 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
//REPORT-15332有一个国际化调用比较早,需要在这边就设置好locale,由于后台GeneralContext默认是China //REPORT-15332有一个国际化调用比较早,需要在这边就设置好locale,由于后台GeneralContext默认是China
GeneralContext.setLocale(designerEnvManager.getLanguage()); GeneralContext.setLocale(designerEnvManager.getLanguage());
try { try {
XMLTools.readFileXML(designerEnvManager, designerEnvManager.getDesignerEnvFile()); designerEnvManager.initElements(designerEnvManager.getDesignerEnvFile());
} catch (FileNotFoundException e) { } catch (Exception retryEx) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().debug("try async init DesignerEnvManager failed", retryEx);
XmlHandler.Self.handle(e);
} catch (Exception e) { try {
FineLoggerFactory.getLogger().error(e.getMessage(), e); XMLTools.readFileXML(designerEnvManager, designerEnvManager.getDesignerEnvFile());
} catch (FileNotFoundException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
XmlHandler.Self.handle(e);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
} }
// james:如果没有env定义,要设置一个默认的 // james:如果没有env定义,要设置一个默认的
@ -273,7 +293,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
public static void checkNameEnvMap() { public static void checkNameEnvMap() {
if (designerEnvManager == null || designerEnvManager.nameEnvMap.size() > 0) {
if (designerEnvManager == null || designerEnvManager.getNameEnvMap().size() > 0) {
return; return;
} }
String installHome = StableUtils.getInstallHome(); String installHome = StableUtils.getInstallHome();
@ -443,8 +464,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
// 清空前一个版本中的工作目录和最近打开 // 清空前一个版本中的工作目录和最近打开
nameEnvMap = new ListMap<String, DesignerWorkspaceInfo>(); getEnvConfig().setNameEnvMap(new ListMap<>());
curEnvName = null; getEnvConfig().setCurEnvName(null);
designerEnvManager.saveXMLFile(); designerEnvManager.saveXMLFile();
} }
@ -606,7 +627,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
String installHome = StableUtils.getInstallHome(); String installHome = StableUtils.getInstallHome();
String defaultenvPath = getDefaultenvPath(installHome); String defaultenvPath = getDefaultenvPath(installHome);
defaultenvPath = new File(defaultenvPath).getPath(); defaultenvPath = new File(defaultenvPath).getPath();
Iterator<Entry<String, DesignerWorkspaceInfo>> entryIt = nameEnvMap.entrySet().iterator(); Iterator<Entry<String, DesignerWorkspaceInfo>> entryIt = getNameEnvMap().entrySet().iterator();
while (entryIt.hasNext()) { while (entryIt.hasNext()) {
Entry<String, DesignerWorkspaceInfo> entry = entryIt.next(); Entry<String, DesignerWorkspaceInfo> entry = entryIt.next();
DesignerWorkspaceInfo env = entry.getValue(); DesignerWorkspaceInfo env = entry.getValue();
@ -627,8 +648,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
String installHome = StableUtils.getInstallHome(); String installHome = StableUtils.getInstallHome();
String defaultenvPath = getDefaultenvPath(installHome); String defaultenvPath = getDefaultenvPath(installHome);
defaultenvPath = new File(defaultenvPath).getPath(); defaultenvPath = new File(defaultenvPath).getPath();
if (nameEnvMap.size() >= 0) { if (getNameEnvMap().size() >= 0) {
Iterator<Entry<String, DesignerWorkspaceInfo>> entryIt = nameEnvMap.entrySet().iterator(); Iterator<Entry<String, DesignerWorkspaceInfo>> entryIt = getNameEnvMap().entrySet().iterator();
while (entryIt.hasNext()) { while (entryIt.hasNext()) {
Entry<String, DesignerWorkspaceInfo> entry = entryIt.next(); Entry<String, DesignerWorkspaceInfo> entry = entryIt.next();
DesignerWorkspaceInfo env = entry.getValue(); DesignerWorkspaceInfo env = entry.getValue();
@ -1019,21 +1040,21 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
public SimpleDesignerConfig getFvsDesignerConfig() { public SimpleDesignerConfig getFvsDesignerConfig() {
return fvsDesignerConfig; return fvsDesignerConfig.getValue();
} }
/** /**
* 返回环境名称迭代器 * 返回环境名称迭代器
*/ */
public Iterator<String> getEnvNameIterator() { public Iterator<String> getEnvNameIterator() {
return this.nameEnvMap.keySet().iterator(); return this.getNameEnvMap().keySet().iterator();
} }
/** /**
* 根据名称返回环境 * 根据名称返回环境
*/ */
public DesignerWorkspaceInfo getWorkspaceInfo(String name) { public DesignerWorkspaceInfo getWorkspaceInfo(String name) {
return this.nameEnvMap.get(name); return this.getNameEnvMap().get(name);
} }
/** /**
@ -1044,7 +1065,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
*/ */
public void putEnv(String name, DesignerWorkspaceInfo info) { public void putEnv(String name, DesignerWorkspaceInfo info) {
this.nameEnvMap.put(name, info); this.getNameEnvMap().put(name, info);
} }
/** /**
@ -1053,14 +1074,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
* @param name 环境的名字 * @param name 环境的名字
*/ */
public void removeEnv(String name) { public void removeEnv(String name) {
this.nameEnvMap.remove(name); this.getNameEnvMap().remove(name);
} }
/** /**
* 清除全部环境 * 清除全部环境
*/ */
public void clearAllEnv() { public void clearAllEnv() {
this.nameEnvMap.clear(); this.getNameEnvMap().clear();
} }
/** /**
@ -1082,14 +1103,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
* 返回当前环境的名称. * 返回当前环境的名称.
*/ */
public String getCurEnvName() { public String getCurEnvName() {
return this.curEnvName; return getEnvConfig().getCurEnvName();
} }
/** /**
* 设置当前环境的名称 * 设置当前环境的名称
*/ */
public void setCurEnvName(String envName) { public void setCurEnvName(String envName) {
this.curEnvName = envName; getEnvConfig().setCurEnvName(envName);
} }
/** /**
@ -1146,12 +1167,12 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
if (StringUtils.isEmpty(envName)) { if (StringUtils.isEmpty(envName)) {
return tempRecentOpenedFilePathList; return tempRecentOpenedFilePathList;
} else { } else {
if (!recentOpenedFileListMap.containsKey(envName)) { if (!recentOpenedMapping.getValue().containsKey(envName)) {
recentOpenedFileListMap.put(envName, tempRecentOpenedFilePathList); recentOpenedMapping.getValue().put(envName, tempRecentOpenedFilePathList);
} }
} }
return recentOpenedFileListMap.get(envName); return recentOpenedMapping.getValue().get(envName);
} }
/** /**
@ -1755,11 +1776,11 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
public AlphaFineConfigManager getAlphaFineConfigManager() { public AlphaFineConfigManager getAlphaFineConfigManager() {
return alphaFineConfigManager; return alphaFineConfigManager.getValue();
} }
public void setAlphaFineConfigManager(AlphaFineConfigManager alphaFineConfigManager) { public void setAlphaFineConfigManager(AlphaFineConfigManager alphaFineConfigManager) {
this.alphaFineConfigManager = alphaFineConfigManager; this.alphaFineConfigManager.setValue(alphaFineConfigManager);
} }
public boolean isImageCompress() { public boolean isImageCompress() {
@ -1801,7 +1822,99 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
public void setLayoutTemplateStyle(int layoutTemplateStyle) { public void setLayoutTemplateStyle(int layoutTemplateStyle) {
this.layoutTemplateStyle = layoutTemplateStyle; this.layoutTemplateStyle = layoutTemplateStyle;
} }
@Override
public void initElements(File xmlFile) throws XmlException {
try {
backupOldXmlFile();
XmlInitialFactory xmlInitialFactory = XmlInitialFactory.create(xmlFile);
xmlInitialFactory
.init("XMLVersion", DesignerEnvManager.this::readXMLVersion)
.init("Attributes", DesignerEnvManager.this::readAttributes)
.init("ReportPaneAttributions", DesignerEnvManager.this::readReportPaneAttributions)
.init("RecentOpenedFilePath", (e) -> {
this.recentOpenedMapping = AsyncXmlElement.of(DesignerStartupPool.common(), () -> {
DesignerEnvManager.this.readRecentOpenFileList0(e);
return recentOpenedFileListMap;
}).callback(new Callback<Map<String, List<String>>>() {
@Override
public void exec(Map<String, List<String>> stringListMap) {
checkRecentOpenedFileNum();
}
});
})
.init("EnvConfigMap", (e) -> {
final EnvConfiguration previousConfig = this.envConfig.getValue();
this.envConfig = AsyncXmlElement.of(DesignerStartupPool.common(), () -> {
DesignerEnvManager.this.readEnvConfigMap(e, previousConfig);
return previousConfig;
});
})
.init("LogLocation", DesignerEnvManager.this::readLogLocation)
.init("Language", DesignerEnvManager.this::readLanguage)
.init("JettyServerPort", DesignerEnvManager.this::readJettyPort)
.init("PLengthUnit", DesignerEnvManager.this::readPageLengthUnit)
.init("RLengthUnit", DesignerEnvManager.this::readReportLengthUnit)
.init("LastOpenFilePath", DesignerEnvManager.this::readLastOpenFile)
.init("EncryptionKey", DesignerEnvManager.this::readEncrytionKey)
.init("jdkHome", (e) -> this.jdkHome = e.getElementValue())
.init("lastBBSTime", DesignerEnvManager.this::readLastBBSTime)
.init("lastBBSNewsTime", DesignerEnvManager.this::readLastBBSNewsTime)
.init("ActivationKey", DesignerEnvManager.this::readActiveKey)
.init("status", DesignerEnvManager.this::readActiveStatus)
.init(CAS_PARAS, DesignerEnvManager.this::readHttpsParas)
.init("AlphaFineConfigManager", (e) -> {
this.alphaFineConfigManager = AsyncXmlElement.of(DesignerStartupPool.common(), () -> {
AlphaFineConfigManager config = AlphaFineConfigManager.getInstance();
e.readXMLObject(config);
return config;
});
})
.init("RecentColors", DesignerEnvManager.this::readRecentColor)
.init("OpenDebug", DesignerEnvManager.this::readOpenDebug)
.init(ComponentReuseNotificationInfo.XML_TAG, DesignerEnvManager.this::readComponentReuseNotificationInfo)
.init(DesignerPushUpdateConfigManager.XML_TAG, DesignerEnvManager.this::readDesignerPushUpdateAttr)
.init(VcsConfigManager.XML_TAG, DesignerEnvManager.this::readVcsAttr)
.init(DesignerPort.XML_TAG, DesignerEnvManager.this::readDesignerPort)
.init(SnapChatConfig.XML_TAG, DesignerEnvManager.this::readSnapChatConfig)
.init(DesignerLoginConfigManager.XML_TAG, DesignerEnvManager.this::readDesignerLoginAttr)
.init(fvsDesignerConfig.getValue().getName(), (e) -> {
SimpleDesignerConfig config = this.fvsDesignerConfig.getValue();
this.fvsDesignerConfig = AsyncXmlElement.of(() -> {
e.readXMLObject(config);
return config;
});
})
.init(SwitchForSwingChecker.XML_TAG, DesignerEnvManager.this::readSwitchForSwingCheckerAttr)
.init(LAST_WEST_REGION_LAYOUT, DesignerEnvManager.this::readLastWestRegionLayout)
.init(LAST_EAST_REGION_LAYOUT, DesignerEnvManager.this::readLastEastRegionLayout);
} catch (Exception e) {
throw new XmlException(e);
}
}
/**
* 备份老的 xml 文件, 防止第一次修改存在问题
* 但是只备份一次其他都走老逻辑
*/
private void backupOldXmlFile() {
try {
File oldFile = getEnvFile();
String newFilePath = ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "Env_backup.xml";
File newFile = new File(newFilePath);
if (newFile.exists()) {
return;
}
if (oldFile.exists()) {
FileUtils.copyFile(oldFile, newFile);
}
} catch (Exception ignored) {
}
}
/** /**
* Read XML.<br> * Read XML.<br>
* The method will be invoked when read data from XML file.<br> * The method will be invoked when read data from XML file.<br>
@ -1865,7 +1978,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
readComponentReuseNotificationInfo(reader); readComponentReuseNotificationInfo(reader);
} else if (name.equals(DesignerPushUpdateConfigManager.XML_TAG)) { } else if (name.equals(DesignerPushUpdateConfigManager.XML_TAG)) {
readDesignerPushUpdateAttr(reader); readDesignerPushUpdateAttr(reader);
} else if (name.equals(vcsConfigManager.XML_TAG)) { } else if (name.equals(VcsConfigManager.XML_TAG)) {
readVcsAttr(reader); readVcsAttr(reader);
} else if (DesignerPort.XML_TAG.equals(name)) { } else if (DesignerPort.XML_TAG.equals(name)) {
readDesignerPort(reader); readDesignerPort(reader);
@ -1873,7 +1986,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
readSnapChatConfig(reader); readSnapChatConfig(reader);
} else if (name.equals(DesignerLoginConfigManager.XML_TAG)) { } else if (name.equals(DesignerLoginConfigManager.XML_TAG)) {
readDesignerLoginAttr(reader); readDesignerLoginAttr(reader);
} else if (name.equals(fvsDesignerConfig.getName())) { } else if (name.equals(fvsDesignerConfig.getValue().getName())) {
readFvsDesignerConfig(reader); readFvsDesignerConfig(reader);
} else if (name.equals(SwitchForSwingChecker.XML_TAG)) { } else if (name.equals(SwitchForSwingChecker.XML_TAG)) {
readSwitchForSwingCheckerAttr(reader); readSwitchForSwingCheckerAttr(reader);
@ -1893,7 +2006,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
private void readAlphaFineAttr(XMLableReader reader) { private void readAlphaFineAttr(XMLableReader reader) {
reader.readXMLObject(this.alphaFineConfigManager = AlphaFineConfigManager.getInstance());
AlphaFineConfigManager config = AlphaFineConfigManager.getInstance();
reader.readXMLObject(config);
this.alphaFineConfigManager = SimpleXmlElement.of(config);
} }
private void readEnvDetectorConfig(XMLableReader reader) { private void readEnvDetectorConfig(XMLableReader reader) {
@ -1918,9 +2034,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
private void readLayout(XMLableReader reader, String name) { private void readLayout(XMLableReader reader, String name) {
if ("LastEastRegionLayout".equals(name)) { if (LAST_EAST_REGION_LAYOUT.equals(name)) {
this.readLastEastRegionLayout(reader); this.readLastEastRegionLayout(reader);
} else if ("LastWestRegionLayout".equals(name)) { } else if (LAST_WEST_REGION_LAYOUT.equals(name)) {
this.readLastWestRegionLayout(reader); this.readLastWestRegionLayout(reader);
} }
} }
@ -2015,6 +2131,40 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
this.setPaginationLineColor(new Color(Integer.parseInt(tmpVal))); this.setPaginationLineColor(new Color(Integer.parseInt(tmpVal)));
} }
} }
private void readEnvConfigMap(XMLableReader reader, EnvConfiguration envConfigs) {
String currentEnv = reader.getAttrAsString("currentEnv", StringUtils.EMPTY);
envConfigs.setCurEnvName(currentEnv);
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
if (reader.isAttr()) {
envConfigs.getNameEnvMap().clear();
} else if (reader.isChildNode()) {
String tagName = reader.getTagName();
if ("EnvConfigElement".equals(tagName)) {
final String name = reader.getAttrAsString("name", StringUtils.EMPTY);
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if (DesignerWorkspaceType.Local.toString().equals(tagName)) {
LocalDesignerWorkspaceInfo envConfig = (LocalDesignerWorkspaceInfo) GeneralXMLTools.readXMLable(reader);
envConfigs.getNameEnvMap().put(name, envConfig);
} else if (DesignerWorkspaceType.Remote.toString().equals(tagName)) {
RemoteDesignerWorkspaceInfo envConfig = (RemoteDesignerWorkspaceInfo) GeneralXMLTools.readXMLable(reader);
envConfigs.getNameEnvMap().put(name, envConfig);
}
}
}
});
}
}
}
});
}
private void readEnvConfigMap(XMLableReader reader) { private void readEnvConfigMap(XMLableReader reader) {
String currentEnv = reader.getAttrAsString("currentEnv", StringUtils.EMPTY); String currentEnv = reader.getAttrAsString("currentEnv", StringUtils.EMPTY);
@ -2048,8 +2198,15 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
}); });
} }
private void readRecentOpenFileList(XMLableReader reader) { private void readRecentOpenFileList(XMLableReader reader) {
readRecentOpenFileList0(reader);
checkRecentOpenedFileNum();
}
private void readRecentOpenFileList0(XMLableReader reader) {
reader.readXMLObject(new XMLReadable() { reader.readXMLObject(new XMLReadable() {
@Override @Override
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {
@ -2081,7 +2238,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
} }
}); });
checkRecentOpenedFileNum();
} }
private void readDesignerPushUpdateAttr(XMLableReader reader) { private void readDesignerPushUpdateAttr(XMLableReader reader) {
@ -2151,7 +2307,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
private void writeAlphaFineAttr(XMLPrintWriter writer) { private void writeAlphaFineAttr(XMLPrintWriter writer) {
if (this.alphaFineConfigManager != null) { if (this.alphaFineConfigManager != null) {
this.alphaFineConfigManager.writeXML(writer); this.alphaFineConfigManager.getValue().writeXML(writer);
} }
} }
@ -2228,10 +2384,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
writer.end(); writer.end();
writer.startTAG("EnvConfigMap"); writer.startTAG("EnvConfigMap");
if (this.curEnvName != null) { if (this.getCurEnvName() != null) {
writer.attr("currentEnv", this.curEnvName); writer.attr("currentEnv", this.getCurEnvName());
} }
for (Entry<String, DesignerWorkspaceInfo> entry : nameEnvMap.entrySet()) { for (Entry<String, DesignerWorkspaceInfo> entry : getNameEnvMap().entrySet()) {
writer.startTAG("EnvConfigElement").attr("name", entry.getKey()); writer.startTAG("EnvConfigElement").attr("name", entry.getKey());
DesignerWorkspaceInfo envConfig = entry.getValue(); DesignerWorkspaceInfo envConfig = entry.getValue();
GeneralXMLTools.writeXMLable(writer, envConfig, envConfig.getType().toString()); GeneralXMLTools.writeXMLable(writer, envConfig, envConfig.getType().toString());
@ -2440,11 +2596,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
private void readFvsDesignerConfig(XMLableReader reader) { private void readFvsDesignerConfig(XMLableReader reader) {
reader.readXMLObject(fvsDesignerConfig);
SimpleDesignerConfig config = fvsDesignerConfig.getValue();
reader.readXMLObject(config);
fvsDesignerConfig = SimpleXmlElement.of(config);
} }
private void writeFvsDesignerConfig(XMLPrintWriter writer) { private void writeFvsDesignerConfig(XMLPrintWriter writer) {
this.fvsDesignerConfig.writeXML(writer); this.fvsDesignerConfig.getValue().writeXML(writer);
} }
private void writeSwitchForSwingChecker(XMLPrintWriter writer) { private void writeSwitchForSwingChecker(XMLPrintWriter writer) {
@ -2479,4 +2638,39 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
public SnapChatConfig getSnapChatConfig() { public SnapChatConfig getSnapChatConfig() {
return snapChatConfig; return snapChatConfig;
} }
private EnvConfiguration getEnvConfig() {
return envConfig.getValue();
}
private Map<String, DesignerWorkspaceInfo> getNameEnvMap() {
return getEnvConfig().getNameEnvMap();
}
private static class EnvConfiguration {
// name和Env的键值对
private Map<String, DesignerWorkspaceInfo> nameEnvMap = new ListMap<>();
// marks: 当前报表服务器名字
private String curEnvName = null;
public Map<String, DesignerWorkspaceInfo> getNameEnvMap() {
return nameEnvMap;
}
public void setNameEnvMap(Map<String, DesignerWorkspaceInfo> nameEnvMap) {
this.nameEnvMap = nameEnvMap;
}
public String getCurEnvName() {
return curEnvName;
}
public void setCurEnvName(String curEnvName) {
this.curEnvName = curEnvName;
}
}
} }

40
designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java

@ -8,6 +8,11 @@ import com.fr.design.menu.MenuKeySet;
import com.fr.design.selection.QuickEditor; import com.fr.design.selection.QuickEditor;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.start.common.DesignerStartupPool;
import com.fr.third.checkerframework.checker.nullness.qual.Nullable;
import com.fr.third.guava.util.concurrent.FutureCallback;
import com.fr.third.guava.util.concurrent.Futures;
import com.fr.third.guava.util.concurrent.ListenableFutureTask;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
@ -18,6 +23,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
@ -32,6 +38,7 @@ public class ActionFactory {
private static Set<Class<?>> actionClasses = new CopyOnWriteArraySet<>(); private static Set<Class<?>> actionClasses = new CopyOnWriteArraySet<>();
private static Set<Class<?>> floatActionClasses = new CopyOnWriteArraySet<>(); private static Set<Class<?>> floatActionClasses = new CopyOnWriteArraySet<>();
private static Class chartCollectionClass = null; private static Class chartCollectionClass = null;
/** /**
* 无需每次实例化的悬浮元素编辑器 * 无需每次实例化的悬浮元素编辑器
*/ */
@ -57,7 +64,6 @@ public class ActionFactory {
private ActionFactory() { private ActionFactory() {
} }
/** /**
* 元素编辑器释放模板对象 * 元素编辑器释放模板对象
*/ */
@ -69,7 +75,37 @@ public class ActionFactory {
entry.getValue().release(); entry.getValue().release();
} }
} }
/**
* 注册异步加载的单元格编辑器
* 首先放到 classMap 当初始化成功后则移除并放到 cellEditor
* 如果已经存在则覆盖
*
* @param keyClazz 作为 key 的类
* @param editorClazz 作为 编辑器 的类
*/
public static void registerAsyncInitCellEditorClass(Class keyClazz, Class<? extends QuickEditor> editorClazz) {
cellEditorClass.put(keyClazz, editorClazz);
Callable<QuickEditor> callable = new Callable<QuickEditor>() {
@Override
public QuickEditor call() throws Exception {
return editorClazz.newInstance();
}
};
ListenableFutureTask<QuickEditor> future = ListenableFutureTask.create(callable);
Futures.addCallback(future, new FutureCallback<QuickEditor>() {
@Override
public void onSuccess(@Nullable QuickEditor quickEditor) {
cellEditorClass.remove(keyClazz);
cellEditor.put(keyClazz, quickEditor);
}
@Override
public void onFailure(Throwable throwable) {
}
}, DesignerStartupPool.designer());
}
/** /**
* 注册无需每次实例化的单元格元素编辑器 * 注册无需每次实例化的单元格元素编辑器

7
designer-base/src/main/java/com/fr/design/env/LocalDesignerWorkspaceInfo.java vendored

@ -1,6 +1,7 @@
package com.fr.design.env; package com.fr.design.env;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.stable.CommonUtils;
import com.fr.stable.CoreConstants; import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -98,6 +99,12 @@ public class LocalDesignerWorkspaceInfo implements DesignerWorkspaceInfo {
@Override @Override
public boolean checkValid(){ public boolean checkValid(){
// 如果当前是 debug 模式,就不检测这个逻辑
if (CommonUtils.isDebug()) {
return true;
}
File file = new File(this.path); File file = new File(this.path);
//判断不是文件夹/路径不在WEB-INF下/代码启动三种情况 //判断不是文件夹/路径不在WEB-INF下/代码启动三种情况
if(!file.isDirectory() || !ComparatorUtils.equals(file.getName(), "WEB-INF") || this.path.startsWith(".")) { if(!file.isDirectory() || !ComparatorUtils.equals(file.getName(), "WEB-INF") || this.path.startsWith(".")) {

3
designer-base/src/main/java/com/fr/start/BaseDesigner.java

@ -39,6 +39,7 @@ import org.jetbrains.annotations.Nullable;
import java.awt.Window; import java.awt.Window;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
/** /**
@ -136,7 +137,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
DesignerFrame df = DesignerContext.getDesignerFrame(); DesignerFrame df = DesignerContext.getDesignerFrame();
isException = openFile(df, isException, file); isException = openFile(df, isException, file);
df.fireDesignerOpened(); df.fireDesignerOpened();
FineLoggerFactory.getLogger().debug("show designer cost {} ms", DesignerStartupContext.getRecorder().getTime()); FineLoggerFactory.getLogger().info("Designer showed.Time used {} ms", DesignerStartupContext.getRecorder().getTime(TimeUnit.MILLISECONDS));
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
if (!isException) { if (!isException) {

21
designer-base/src/main/java/com/fr/start/common/DesignerStartupPool.java

@ -4,17 +4,36 @@ import com.fr.concurrent.FineExecutors;
import com.fr.concurrent.NamedThreadFactory; import com.fr.concurrent.NamedThreadFactory;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/** /**
* created by Harrison on 2022/07/03 * created by Harrison on 2022/07/03
**/ **/
public class DesignerStartupPool { public class DesignerStartupPool {
private static final Executor COMMON_EXECUTOR = FineExecutors.newCachedThreadPool(new NamedThreadFactory("startup-common")); private static final int MAX_THREAD_COUNT = Runtime.getRuntime().availableProcessors() * 2;
private static final Executor COMMON_EXECUTOR = FineExecutors.newThreadPoolExecutor(MAX_THREAD_COUNT, MAX_THREAD_COUNT, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("startup-common"));
private static final Executor DESIGNER_EXECUTOR = FineExecutors.newThreadPoolExecutor(MAX_THREAD_COUNT, MAX_THREAD_COUNT, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("startup-designer"));
/**
*
* @return 启动通用线程池
*/
public static Executor common() { public static Executor common() {
return COMMON_EXECUTOR; return COMMON_EXECUTOR;
} }
/**
*
* @return 启动设计器线程池
*/
public static Executor designer() {
return DESIGNER_EXECUTOR;
}
} }

113
designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java

@ -0,0 +1,113 @@
package com.fr.startup.ui;
import com.fr.concurrent.FineExecutors;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.gui.iprogressbar.ProgressDialog;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.fr.module.ModuleEvent;
import java.awt.Frame;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* created by Harrison on 2022/11/08
**/
public class StartupLoadingPanel {
/**
* 每次更新的步伐
*/
private static final int STEP = 1;
/**
* 40ms更新进度
*/
private static final int STEP_HEARTBEAT = 40;
private final Listener<String> MODULE_LISTENER = new Listener<String>() {
@Override
public void on(Event event, String param) {
moduleId = param;
}
};
private ProgressDialog progressDialog;
private String moduleId;
private int progress;
public StartupLoadingPanel(Frame frame) {
this.progressDialog = new ProgressDialog(frame);
this.moduleId = Toolkit.i18nText("Fine-Design_Basic_Initializing");
initListeners();
}
/**
* 隐藏
*/
public void hide() {
this.progress = progressDialog.getProgressMaximum();
}
/**
* 展示
*/
public void show() {
final ScheduledExecutorService scheduler = FineExecutors.newScheduledThreadPool(1,
new NamedThreadFactory("StartupLoadingPanel"));
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
if (isComplete()) {
scheduler.shutdown();
progressDialog.dispose();
resetListeners();
return;
}
if (!progressDialog.isVisible()) {
progressDialog = new ProgressDialog(DesignerContext.getDesignerFrame());
progressDialog.setVisible(true);
String moduleId = getModuleId();
progressDialog.updateLoadingText(moduleId);
}
progressDialog.setProgressValue(incrementProgress());
}
}, 0, STEP_HEARTBEAT, TimeUnit.MILLISECONDS);
}
private void initListeners() {
EventDispatcher.listen(ModuleEvent.MajorModuleStarting, MODULE_LISTENER);
}
private void resetListeners() {
EventDispatcher.stopListen(MODULE_LISTENER);
}
private boolean isComplete() {
return this.progress >= progressDialog.getProgressMaximum();
}
private String getModuleId() {
return this.moduleId;
}
private int incrementProgress() {
if (progress != progressDialog.getProgressMaximum()) {
progress += STEP;
}
return progress;
}
}

87
designer-base/src/main/java/com/fr/startup/ui/StartupPageWindow.java

@ -2,7 +2,6 @@ package com.fr.startup.ui;
import com.fr.base.svg.IconUtils; import com.fr.base.svg.IconUtils;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.components.loading.LoadingPane;
import com.fr.design.dialog.UIExpandDialog; import com.fr.design.dialog.UIExpandDialog;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
@ -25,7 +24,6 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JSeparator; import javax.swing.JSeparator;
import javax.swing.ScrollPaneConstants; import javax.swing.ScrollPaneConstants;
@ -34,7 +32,6 @@ import javax.swing.SwingWorker;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.Font; import java.awt.Font;
@ -84,41 +81,42 @@ public class StartupPageWindow extends JFrame {
private JPanel body; private JPanel body;
private LoadingPane loadingPane = new LoadingPane(); private StartupLoadingPanel loadingPanel;
private JLayeredPane layeredPane = new JLayeredPane() {
@Override
public void doLayout() {
for (Component comp : getComponents()) {
comp.setBounds(0, 0, getWidth(), getHeight());
}
}
};
public StartupPageWindow(StartupPageModel pageModel) { public StartupPageWindow(StartupPageModel pageModel) {
patchUIAction(pageModel); patchUIAction(pageModel);
setLayout(new BorderLayout()); setLayout(new BorderLayout());
initCenter(pageModel);
loadingPanel = new StartupLoadingPanel(this);
// Workspace-detail
setSize(SCREEN_SIZE);
setDefaultTitle();
addDefaultListeners();
repaint();
validate();
revalidate();
setFullScreen();
}
private void initCenter(StartupPageModel pageModel) {
this.body = FRGUIPaneFactory.createBorderLayout_S_Pane(); this.body = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.body.setBackground(new Color(0, 0, 0, 0)); this.body.setBackground(new Color(0, 0, 0, 0));
// Header JPanel headerPanel = createHeader();
UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Startup_Page_Select_Workspace"));
Font font = label.getFont();
Font titleFont = font.deriveFont(font.getStyle(), TITLE_FONT_SIZE);
label.setFont(titleFont);
JPanel headerPanel = new JPanel();
LayoutManager centerFlowLayout = FRGUIPaneFactory.createCenterFlowLayout();
headerPanel.setLayout(centerFlowLayout);
headerPanel.add(label);
headerPanel.setBackground(new Color(0, 0, 0, 0));
this.body.add(headerPanel, BorderLayout.NORTH); this.body.add(headerPanel, BorderLayout.NORTH);
// Workspace-description // Workspace-description
this.workspacePanel = generateWorkspacePanel(pageModel); this.workspacePanel = generateWorkspacePanel(pageModel);
this.body.add(workspacePanel, BorderLayout.CENTER); this.body.add(workspacePanel, BorderLayout.CENTER);
workspacePanel.setSelectWorkspaceRunnable(new Runnable() { workspacePanel.setSelectWorkspaceRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -144,25 +142,24 @@ public class StartupPageWindow extends JFrame {
this.contentPane.setLayout(getCenterLayout(body)); this.contentPane.setLayout(getCenterLayout(body));
this.contentPane.add(this.body, BorderLayout.CENTER); this.contentPane.add(this.body, BorderLayout.CENTER);
this.contentPane.setPreferredSize(this.body.getPreferredSize()); this.contentPane.setPreferredSize(this.body.getPreferredSize());
this.layeredPane.setName("layered-pane");
this.layeredPane.add(this.contentPane, CONTENT_LAYER);
this.layeredPane.add(this.loadingPane, TRANSPARENT_LAYER);
this.layeredPane.moveToFront(this.contentPane);
add(this.layeredPane, BorderLayout.CENTER);
// Workspace-detail add(this.contentPane, BorderLayout.CENTER);
setSize(SCREEN_SIZE); }
setDefaultTitle();
addDefaultListeners(); @NotNull
private static JPanel createHeader() {
repaint();
validate();
revalidate();
setFullScreen(); // Header
UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Startup_Page_Select_Workspace"));
Font font = label.getFont();
Font titleFont = font.deriveFont(font.getStyle(), TITLE_FONT_SIZE);
label.setFont(titleFont);
JPanel headerPanel = new JPanel();
LayoutManager centerFlowLayout = FRGUIPaneFactory.createCenterFlowLayout();
headerPanel.setLayout(centerFlowLayout);
headerPanel.add(label);
headerPanel.setBackground(new Color(0, 0, 0, 0));
return headerPanel;
} }
private void setFullScreen() { private void setFullScreen() {
@ -214,9 +211,8 @@ public class StartupPageWindow extends JFrame {
} }
private void enterWorkspace(Runnable action) { private void enterWorkspace(Runnable action) {
loadingPane.start(); loadingPanel.show();
layeredPane.moveToFront(loadingPane);
SwingWorker<Void, Void> task = new SwingWorker<Void, Void>() { SwingWorker<Void, Void> task = new SwingWorker<Void, Void>() {
@Override @Override
protected Void doInBackground() throws Exception { protected Void doInBackground() throws Exception {
@ -245,9 +241,8 @@ public class StartupPageWindow extends JFrame {
.setVisible(true); .setVisible(true);
}); });
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
layeredPane.moveToFront(contentPane);
} finally { } finally {
loadingPane.stop(); loadingPanel.hide();
} }
} }
}; };

30
designer-realize/src/main/java/com/fr/start/MainDesigner.java

@ -72,17 +72,15 @@ import com.fr.start.common.SplashCommon;
import com.fr.start.module.StartupArgs; import com.fr.start.module.StartupArgs;
import com.fr.start.preload.PreLoadService; import com.fr.start.preload.PreLoadService;
import com.fr.start.server.ServerTray; import com.fr.start.server.ServerTray;
import com.fr.third.org.apache.commons.lang3.time.StopWatch;
import com.fr.van.chart.map.server.ChartMapEditorAction; import com.fr.van.chart.map.server.ChartMapEditorAction;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import javax.swing.JPanel;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.border.MatteBorder; import javax.swing.border.MatteBorder;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -119,11 +117,11 @@ public class MainDesigner extends BaseDesigner {
* @param args 参数 * @param args 参数
*/ */
public static void main(String[] args) { public static void main(String[] args) {
StopWatch watch = new StopWatch();
watch.start();
DesignerStartupContext.getRecorder().start(); DesignerStartupContext.getRecorder().start();
showSplash();
DesignerEnvManager.getEnvManager();
startPreload0(); startPreload0();
DesignerLifecycleMonitorContext.getMonitor().beforeStart(); DesignerLifecycleMonitorContext.getMonitor().beforeStart();
@ -143,7 +141,7 @@ public class MainDesigner extends BaseDesigner {
}); });
Module designerRoot = ModuleContext.parseRoot("designer-startup.xml"); Module designerRoot = ModuleContext.parseRoot("designer-startup.xml");
FineLoggerFactory.getLogger().debug("designer-startup prepared cost {} ms", DesignerStartupContext.getRecorder().getTime(TimeUnit.MILLISECONDS)); FineLoggerFactory.getLogger().debug("Designer prepared.Time used {} ms", DesignerStartupContext.getRecorder().getTime(TimeUnit.MILLISECONDS));
//传递启动参数 //传递启动参数
designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args)); designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args));
try { try {
@ -156,8 +154,7 @@ public class MainDesigner extends BaseDesigner {
//初始化一下serverTray //初始化一下serverTray
ServerTray.init(); ServerTray.init();
} }
FineLoggerFactory.getLogger().info("Designer started.Time used {} ms", watch.getTime()); FineLoggerFactory.getLogger().info("Designer started.Time used {} ms", DesignerStartupContext.getRecorder().getTime(TimeUnit.MILLISECONDS));
watch.stop();
SwitchForSwingChecker.initThreadMonitoring(); SwitchForSwingChecker.initThreadMonitoring();
} }
@ -168,7 +165,9 @@ public class MainDesigner extends BaseDesigner {
private static void startPreload1() { private static void startPreload1() {
CompletableFuture<Void> initLookAndFeel = CompletableFuture.runAsync(DesignUtils::initLookAndFeel); CompletableFuture<Void> initLookAndFeel = CompletableFuture.runAsync(DesignUtils::initLookAndFeel);
PreLoadService.getInstance().addFuture(initLookAndFeel); PreLoadService.getInstance().addUIFuture(initLookAndFeel);
showSplash();
} }
/** /**
@ -189,17 +188,12 @@ public class MainDesigner extends BaseDesigner {
action.run(); action.run();
} }
}); });
Runnable fontLoad = () -> {
Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
};
PreLoadService.getInstance().addRunnable(fontLoad);
} }
private static void showSplash() { private static void showSplash() {
// 快快显示启动画面 // 快快显示启动画面
UIUtil.invokeAndWaitIfNeeded(new Runnable() { UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override @Override
public void run() { public void run() {
SplashContext.getInstance().registerSplash(createSplash()); SplashContext.getInstance().registerSplash(createSplash());

39
designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

@ -146,13 +146,14 @@ import com.fr.start.common.DesignerStartupPool;
import com.fr.task.Once; import com.fr.task.Once;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.xml.ReportXMLUtils; import com.fr.xml.ReportXMLUtils;
import javax.swing.SwingWorker;
import java.awt.Image; import java.awt.Image;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import javax.swing.SwingWorker;
/** /**
* Created by juhaoyu on 2018/1/31. * Created by juhaoyu on 2018/1/31.
@ -191,7 +192,9 @@ public class DesignerActivator extends Activator implements Prepare {
}, DesignerStartupPool.common()); }, DesignerStartupPool.common());
CompletableFuture<Void> mainDesignerPrepare = CompletableFuture.runAsync(this::designerModuleStart, DesignerStartupPool.common()); CompletableFuture<Void> mainDesignerPrepare = CompletableFuture.runAsync(this::designerModuleStart, DesignerStartupPool.common());
CompletableFuture<Void> extendDesignerPrepare = CompletableFuture.runAsync(this::designerExtendStart, DesignerStartupPool.common());
CompletableFuture<Void> otherFeaturesPrepare = CompletableFuture.runAsync(() -> { CompletableFuture<Void> otherFeaturesPrepare = CompletableFuture.runAsync(() -> {
startBBSLoginAuthServer(); startBBSLoginAuthServer();
migrateBBSInfoFromFineDB(); migrateBBSInfoFromFineDB();
@ -207,7 +210,7 @@ public class DesignerActivator extends Activator implements Prepare {
storePassport(); storePassport();
AlphaFineHelper.switchConfig4Locale(); AlphaFineHelper.switchConfig4Locale();
RecoverManager.register(new RecoverForDesigner()); RecoverManager.register(new RecoverForDesigner());
}); }, DesignerStartupPool.common());
CompletableFuture<Void> resourcePrepare = CompletableFuture.runAsync(() -> { CompletableFuture<Void> resourcePrepare = CompletableFuture.runAsync(() -> {
pushUpdateTask.run(); pushUpdateTask.run();
@ -218,7 +221,7 @@ public class DesignerActivator extends Activator implements Prepare {
}, DesignerStartupPool.common()); }, DesignerStartupPool.common());
CompletableFuture CompletableFuture
.allOf(mainDesignerPrepare, themeConfigPrepare, otherFeaturesPrepare, resourcePrepare) .allOf(mainDesignerPrepare, extendDesignerPrepare, themeConfigPrepare, otherFeaturesPrepare, resourcePrepare)
.join(); .join();
} }
@ -272,8 +275,12 @@ public class DesignerActivator extends Activator implements Prepare {
designerRegister(); designerRegister();
InformationCollector.getInstance().collectStartTime(); }
private void designerExtendStart() {
SharableManager.start(); SharableManager.start();
InformationCollector.getInstance().collectStartTime();
GuideRegister.register(); GuideRegister.register();
} }
@ -413,16 +420,16 @@ public class DesignerActivator extends Activator implements Prepare {
*/ */
private static void registerCellEditor() { private static void registerCellEditor() {
ActionFactory.registerCellEditor(String.class, new CellStringQuickEditor()); ActionFactory.registerAsyncInitCellEditorClass(String.class, CellStringQuickEditor.class);
ActionFactory.registerCellEditor(Number.class, new CellStringQuickEditor()); ActionFactory.registerAsyncInitCellEditorClass(Number.class, CellStringQuickEditor.class);
ActionFactory.registerCellEditor(BaseFormula.class, new CellFormulaQuickEditor()); ActionFactory.registerAsyncInitCellEditorClass(BaseFormula.class, CellFormulaQuickEditor.class);
ActionFactory.registerCellEditor(SubReport.class, new CellSubReportEditor()); ActionFactory.registerAsyncInitCellEditorClass(SubReport.class, CellSubReportEditor.class);
ActionFactory.registerCellEditor(RichText.class, new CellRichTextEditor()); ActionFactory.registerAsyncInitCellEditorClass(RichText.class, CellRichTextEditor.class);
ActionFactory.registerCellEditor(DSColumn.class, new CellDSColumnEditor()); ActionFactory.registerAsyncInitCellEditorClass(DSColumn.class, CellDSColumnEditor.class);
ActionFactory.registerCellEditor(Image.class, new CellImageQuickEditor()); ActionFactory.registerAsyncInitCellEditorClass(Image.class, CellImageQuickEditor.class);
ActionFactory.registerCellEditor(BiasTextPainter.class, new CellBiasTextPainterEditor()); ActionFactory.registerAsyncInitCellEditorClass(BiasTextPainter.class, CellBiasTextPainterEditor.class);
ActionFactory.registerCellEditor(BufferedImage.class, new CellImageQuickEditor()); ActionFactory.registerAsyncInitCellEditorClass(BufferedImage.class, CellImageQuickEditor.class);
ActionFactory.registerCellEditor(CellImagePainter.class, new CellImageQuickEditor()); ActionFactory.registerAsyncInitCellEditorClass(CellImagePainter.class, CellImageQuickEditor.class);
Set<ElementUIProvider> providers = ExtraDesignClassManager.getInstance().getArray(ElementUIProvider.MARK_STRING); Set<ElementUIProvider> providers = ExtraDesignClassManager.getInstance().getArray(ElementUIProvider.MARK_STRING);
for (ElementUIProvider provider : providers) { for (ElementUIProvider provider : providers) {
@ -430,7 +437,7 @@ public class DesignerActivator extends Activator implements Prepare {
if (provider.quickEditor() == null) { if (provider.quickEditor() == null) {
continue; continue;
} }
ActionFactory.registerCellEditor(provider.targetObjectClass(), provider.quickEditor().newInstance()); ActionFactory.registerAsyncInitCellEditorClass(provider.targetObjectClass(), provider.quickEditor());
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }

2
designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

@ -67,7 +67,7 @@ public class DesignerStartup extends Activator {
registerDaoSelector(); registerDaoSelector();
Stopwatch beforeWatch = Stopwatch.createStarted(); Stopwatch beforeWatch = Stopwatch.createStarted();
PreLoadService.getInstance().waitForAll(); PreLoadService.getInstance().waitForCommon();
FineLoggerFactory.getLogger().debug( "DesignerStartup cost {} ms to wait load", beforeWatch.elapsed(TimeUnit.MILLISECONDS)); FineLoggerFactory.getLogger().debug( "DesignerStartup cost {} ms to wait load", beforeWatch.elapsed(TimeUnit.MILLISECONDS));
if (DesignUtils.isStarted()) { if (DesignUtils.isStarted()) {

54
designer-realize/src/main/java/com/fr/start/module/optimized/DesignerStartupPageActivator.java

@ -5,9 +5,11 @@ import com.fr.design.mainframe.DesignerContext;
import com.fr.design.ui.util.UIUtil; import com.fr.design.ui.util.UIUtil;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.module.Activator; import com.fr.module.Activator;
import com.fr.module.engine.base.ActivatorContext;
import com.fr.start.SplashContext; import com.fr.start.SplashContext;
import com.fr.start.common.DesignerStartupContext; import com.fr.start.common.DesignerStartupContext;
import com.fr.start.module.StartupArgs; import com.fr.start.module.StartupArgs;
import com.fr.start.preload.PreLoadService;
import com.fr.start.util.DesignerStartupPageUtil; import com.fr.start.util.DesignerStartupPageUtil;
import com.fr.startup.metric.DesignerMetrics; import com.fr.startup.metric.DesignerMetrics;
import com.fr.startup.metric.DesignerStartupModel; import com.fr.startup.metric.DesignerStartupModel;
@ -18,6 +20,7 @@ import com.fr.third.org.apache.commons.lang3.time.StopWatch;
import com.fr.value.NotNullLazyValue; import com.fr.value.NotNullLazyValue;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -37,6 +40,13 @@ public class DesignerStartupPageActivator extends Activator {
} }
}; };
/**
* 上下文
*/
private final ActivatorContext activatorContext = new ActivatorContext();
private final CountDownLatch LATCH = new CountDownLatch(1);
@Override @Override
public void start() { public void start() {
@ -64,14 +74,25 @@ public class DesignerStartupPageActivator extends Activator {
// 即时暂停 // 即时暂停
suspendRecorder(context); suspendRecorder(context);
addMutable(ActivatorContext.KEY, activatorContext);
PreLoadService.getInstance().waitForUI();
UIUtil.invokeLaterIfNeeded(() -> { UIUtil.invokeLaterIfNeeded(() -> {
StartupPageModel model = StartupPageModel.create(); StartupPageModel model = StartupPageModel.create();
context.setStartupPageModel(model); context.setStartupPageModel(model);
StopWatch suspendWatch = new StopWatch();
final Runnable recordSuspend = () -> {
long suspendTime = suspendWatch.getTime(TimeUnit.MILLISECONDS);
activatorContext.setSuspendTime(suspendTime);
};
// selectAndOpenLast // selectAndOpenLast
model.setOpenLastTemplateRunnable(() -> { model.setOpenLastTemplateRunnable(() -> {
recordSuspend.run();
context.setOpenLastFile(true); context.setOpenLastFile(true);
handleModel(model); handleModel(model);
launchAfterWarmup(); launchAfterWarmup();
@ -79,6 +100,7 @@ public class DesignerStartupPageActivator extends Activator {
// selectAndOpenEmpty // selectAndOpenEmpty
model.setOpenEmptyTemplateRunnable(() -> { model.setOpenEmptyTemplateRunnable(() -> {
recordSuspend.run();
context.setOpenEmpty(true); context.setOpenEmpty(true);
handleModel(model); handleModel(model);
launchAfterWarmup(); launchAfterWarmup();
@ -86,6 +108,7 @@ public class DesignerStartupPageActivator extends Activator {
// selectAndCreateNew // selectAndCreateNew
model.setCreateNewTemplateRunnable(() -> { model.setCreateNewTemplateRunnable(() -> {
recordSuspend.run();
context.setCreateNew(true); context.setCreateNew(true);
handleModel(model); handleModel(model);
launchAfterWarmup(); launchAfterWarmup();
@ -94,8 +117,11 @@ public class DesignerStartupPageActivator extends Activator {
StartupPageWindow window = new StartupPageWindow(model); StartupPageWindow window = new StartupPageWindow(model);
window.setVisible(true); window.setVisible(true);
context.setOnWaiting(true); context.setOnWaiting(true);
suspendWatch.start();
}); });
waitSubTask();
} }
private void suspendRecorder(DesignerStartupContext context) { private void suspendRecorder(DesignerStartupContext context) {
@ -136,9 +162,9 @@ public class DesignerStartupPageActivator extends Activator {
DesignerStartupContext.getInstance().setOnStartup(false); DesignerStartupContext.getInstance().setOnStartup(false);
recordStartupEnd(stopWatch); recordStartupEnd(stopWatch);
}); });
markComplete();
} }
FineLoggerFactory.getLogger().debug("designer-startup-page started cost {} ms", DesignerStartupContext.getRecorder().getTime(TimeUnit.MILLISECONDS));
} }
private void recordStartupEnd(StopWatch stopWatch) { private void recordStartupEnd(StopWatch stopWatch) {
@ -150,6 +176,28 @@ public class DesignerStartupPageActivator extends Activator {
model.fill(); model.fill();
} }
/**
* 阻塞住当前的方法
* 只有 UI 交互开始执行的时候才会停止阻塞
*/
private void waitSubTask() {
try {
LATCH.await();
} catch (InterruptedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
private void markComplete() {
try {
LATCH.countDown();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@Override @Override
public void stop() { public void stop() {

20
designer-realize/src/main/java/com/fr/start/preload/PreLoadService.java

@ -11,7 +11,9 @@ import java.util.concurrent.CompletableFuture;
**/ **/
public class PreLoadService { public class PreLoadService {
private List<CompletableFuture<?>> futures = new ArrayList<>(); private List<CompletableFuture<?>> commonFutures = new ArrayList<>();
private List<CompletableFuture<?>> uIFutures = new ArrayList<>();
public static PreLoadService getInstance() { public static PreLoadService getInstance() {
return PreLoadServiceHolder.INSTANCE; return PreLoadServiceHolder.INSTANCE;
@ -21,16 +23,24 @@ public class PreLoadService {
private static final PreLoadService INSTANCE = new PreLoadService(); private static final PreLoadService INSTANCE = new PreLoadService();
} }
public void addUIFuture(CompletableFuture<?> future) {
uIFutures.add(future);
}
public void addFuture(CompletableFuture<?> future) { public void addFuture(CompletableFuture<?> future) {
futures.add(future); commonFutures.add(future);
} }
public void addRunnable(Runnable runnable) { public void addRunnable(Runnable runnable) {
futures.add(CompletableFuture.runAsync(runnable, DesignerStartupPool.common())); commonFutures.add(CompletableFuture.runAsync(runnable, DesignerStartupPool.common()));
}
public void waitForCommon() {
CompletableFuture.allOf(commonFutures.toArray(new CompletableFuture[0])).join();
} }
public void waitForAll() { public void waitForUI() {
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); CompletableFuture.allOf(uIFutures.toArray(new CompletableFuture[0])).join();
} }
} }

Loading…
Cancel
Save