|
|
|
/*
|
|
|
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved.
|
|
|
|
*/
|
|
|
|
package com.fr.start;
|
|
|
|
|
|
|
|
import com.fr.common.report.ReportState;
|
|
|
|
import com.fr.design.DesignerEnvManager;
|
|
|
|
import com.fr.design.ExtraDesignClassManager;
|
|
|
|
import com.fr.design.constants.DesignerLaunchStatus;
|
|
|
|
import com.fr.design.file.HistoryTemplateListPane;
|
|
|
|
import com.fr.design.file.MutilTempalteTabPane;
|
|
|
|
import com.fr.design.file.TemplateTreePane;
|
|
|
|
import com.fr.design.fun.DesignerStartOpenFileProcessor;
|
|
|
|
import com.fr.design.fun.impl.DesignerStartWithEmptyFile;
|
|
|
|
import com.fr.design.mainframe.DesignerContext;
|
|
|
|
import com.fr.design.mainframe.DesignerFrame;
|
|
|
|
import com.fr.design.mainframe.JTemplate;
|
|
|
|
import com.fr.design.mainframe.toolbar.ToolBarMenuDock;
|
|
|
|
import com.fr.design.monitor.DesignerLifecycleMonitorContext;
|
|
|
|
import com.fr.design.ui.util.UIUtil;
|
|
|
|
import com.fr.design.versioncheck.VersionCheckUtils;
|
|
|
|
import com.fr.event.Event;
|
|
|
|
import com.fr.event.EventDispatcher;
|
|
|
|
import com.fr.event.Listener;
|
|
|
|
import com.fr.event.Null;
|
|
|
|
import com.fr.exit.DesignerExiter;
|
|
|
|
import com.fr.file.FILE;
|
|
|
|
import com.fr.file.FILEFactory;
|
|
|
|
import com.fr.log.FineLoggerFactory;
|
|
|
|
import com.fr.process.ProcessEventPipe;
|
|
|
|
import com.fr.process.engine.core.CarryMessageEvent;
|
|
|
|
import com.fr.process.engine.core.FineProcessContext;
|
|
|
|
import com.fr.stable.OperatingSystem;
|
|
|
|
import com.fr.start.common.DesignerStartupContext;
|
|
|
|
import com.fr.start.common.DesignerStartupUtil;
|
|
|
|
import com.fr.start.event.LazyStartupEvent;
|
|
|
|
import com.fr.workspace.base.WorkspaceStatus;
|
|
|
|
|
|
|
|
import java.awt.Window;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main class of Report Designer.
|
|
|
|
*/
|
|
|
|
public abstract class BaseDesigner extends ToolBarMenuDock {
|
|
|
|
|
|
|
|
private static final int LOAD_TREE_MAXNUM = 10;
|
|
|
|
|
|
|
|
private final String[] args;
|
|
|
|
|
|
|
|
public BaseDesigner(String[] args) {
|
|
|
|
|
|
|
|
this.args = args;
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
prepare();
|
|
|
|
// 初始化Log Handler
|
|
|
|
DesignerEnvManager.loadLogSetting();
|
|
|
|
createDesignerFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 准备一些订阅
|
|
|
|
*/
|
|
|
|
private void prepare() {
|
|
|
|
EventDispatcher.listen(DesignerLaunchStatus.DESIGNER_INIT_COMPLETE, new Listener<Null>() {
|
|
|
|
@Override
|
|
|
|
public void on(Event event, Null param) {
|
|
|
|
EventDispatcher.stopListen(this);
|
|
|
|
UIUtil.invokeLaterIfNeeded(() -> {
|
|
|
|
|
|
|
|
// 打开上次的文件
|
|
|
|
showDesignerFrame(false);
|
|
|
|
DesignerLaunchStatus.setStatus(DesignerLaunchStatus.OPEN_LAST_FILE_COMPLETE);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, new Listener<Null>() {
|
|
|
|
@Override
|
|
|
|
public void on(Event event, Null param) {
|
|
|
|
DesignerLifecycleMonitorContext.getMonitor().afterStart();
|
|
|
|
EventDispatcher.stopListen(this);
|
|
|
|
// 启动完成 停止监听
|
|
|
|
ProcessEventPipe eventPipe = FineProcessContext.getParentPipe();
|
|
|
|
if (eventPipe != null) {
|
|
|
|
eventPipe.fire(new CarryMessageEvent(ReportState.STOP.getValue()));
|
|
|
|
}
|
|
|
|
EventDispatcher.fire(WorkspaceStatus.Prepared);
|
|
|
|
EventDispatcher.asyncFire(LazyStartupEvent.INSTANCE);
|
|
|
|
collectUserInformation();
|
|
|
|
checkVersion();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkVersion() {
|
|
|
|
try {
|
|
|
|
VersionCheckUtils.showVersionCheckDialog(DesignerEnvManager.getEnvManager().getCurEnvName());
|
|
|
|
} catch (Exception e) {
|
|
|
|
FineLoggerFactory.getLogger().warn("Check Service Failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void show() {
|
|
|
|
UIUtil.invokeLaterIfNeeded(this::refreshTemplateTree);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refreshTemplateTree() {
|
|
|
|
//TODO: 2019-06-14 这里有啥作用?
|
|
|
|
DesignerContext.getDesignerFrame().refreshEnv();
|
|
|
|
for (int i = 0; !TemplateTreePane.getInstance().getTemplateFileTree().isTemplateShowing() && i < LOAD_TREE_MAXNUM; i++) {
|
|
|
|
TemplateTreePane.getInstance().getTemplateFileTree().refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createDesignerFrame() {
|
|
|
|
new DesignerFrame(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showDesignerFrame(boolean isException) {
|
|
|
|
try {
|
|
|
|
FILE file = null;
|
|
|
|
if (args != null && args.length > 0) {
|
|
|
|
file = DesignerStartupUtil.convertArgs2FILE(args);
|
|
|
|
} else {
|
|
|
|
file = FILEFactory.createFILE(FILEFactory.ENV_PREFIX + DesignerEnvManager.getEnvManager().getLastOpenFile());
|
|
|
|
}
|
|
|
|
DesignerFrame df = DesignerContext.getDesignerFrame();
|
|
|
|
isException = openFile(df, isException, file);
|
|
|
|
df.fireDesignerOpened();
|
|
|
|
FineLoggerFactory.getLogger().debug("show designer cost {} ms", DesignerStartupContext.getRecorder().getTime());
|
|
|
|
} catch (Exception e) {
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
|
|
|
if (!isException) {
|
|
|
|
showDesignerFrame(true);
|
|
|
|
} else {
|
|
|
|
DesignerExiter.getInstance().exit(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean openFile(final DesignerFrame df, boolean isException, FILE file) {
|
|
|
|
|
|
|
|
AtomicBoolean isExWrapper = new AtomicBoolean(isException);
|
|
|
|
openTemplate(df, isExWrapper, file);
|
|
|
|
|
|
|
|
if (OperatingSystem.isMacOS()) {
|
|
|
|
enableFullScreenMode(df);
|
|
|
|
}
|
|
|
|
|
|
|
|
JTemplate<?, ?> selectedJTemplate = df.getSelectedJTemplate();
|
|
|
|
if (selectedJTemplate != null) {
|
|
|
|
selectedJTemplate.requestGridFocus();
|
|
|
|
}
|
|
|
|
return isExWrapper.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openTemplate(DesignerFrame df, AtomicBoolean isException, FILE file) {
|
|
|
|
|
|
|
|
// 如果是起始页启动中
|
|
|
|
if (openTemplateOnStartup(df, isException, file)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
openTemplate0(df, isException, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openTemplate0(DesignerFrame df, AtomicBoolean isException, FILE file) {
|
|
|
|
|
|
|
|
file = getExtraFILE(isException, file);
|
|
|
|
|
|
|
|
if (file != null && file.exists() && !isException.get()) {
|
|
|
|
df.openTemplate(file);
|
|
|
|
} else {
|
|
|
|
df.addAndActivateJTemplate();
|
|
|
|
// 如果没有模板,则需要确认一下
|
|
|
|
MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private FILE getExtraFILE(AtomicBoolean isException, FILE file) {
|
|
|
|
|
|
|
|
//启动时打开指定文件的接口
|
|
|
|
DesignerStartOpenFileProcessor processor = ExtraDesignClassManager.getInstance().getSingle(DesignerStartOpenFileProcessor.XML_TAG);
|
|
|
|
// 如果插件没有,且又开启了启动时打开空文件,则使用启动时打开空文件
|
|
|
|
if (processor == null && DesignerEnvManager.getEnvManager().isStartWithEmptyFile()) {
|
|
|
|
processor = DesignerStartWithEmptyFile.getInstance();
|
|
|
|
}
|
|
|
|
if (processor != null) {
|
|
|
|
FILE f = processor.fileToShow();
|
|
|
|
if (f != null) {
|
|
|
|
file = f;//避免null
|
|
|
|
} else {
|
|
|
|
isException.set(true);//此时有文件nullpointer异常,执行打开空文件
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean openTemplateOnStartup(DesignerFrame df, AtomicBoolean isException, FILE file) {
|
|
|
|
|
|
|
|
boolean onStartup = DesignerStartupContext.getInstance().isSupport();
|
|
|
|
if (onStartup) {
|
|
|
|
DesignerStartupContext context = DesignerStartupContext.getInstance();
|
|
|
|
if (context.isCreateNew()) {
|
|
|
|
return createNewTemplate(df);
|
|
|
|
}
|
|
|
|
if (isOpenTemplate(isException, file, context)) {
|
|
|
|
return openTemplate(df, file);
|
|
|
|
}
|
|
|
|
if (context.isOpenEmpty()) {
|
|
|
|
return openEmpty(df);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isOpenTemplate(AtomicBoolean isException, FILE file, DesignerStartupContext context) {
|
|
|
|
|
|
|
|
return context.isOpenLastFile() && file != null && file.exists() && !isException.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean openEmpty(DesignerFrame df) {
|
|
|
|
df.showEmptyJTemplate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean openTemplate(DesignerFrame df, FILE file) {
|
|
|
|
df.openTemplate(file);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean createNewTemplate(DesignerFrame df) {
|
|
|
|
df.addAndActivateJTemplate();
|
|
|
|
// 如果没有模板,则需要确认一下
|
|
|
|
MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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, Window.class, boolean.class);
|
|
|
|
method.invoke(null, window, true);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
FineLoggerFactory.getLogger().error("Full screen mode is not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 收集用户信息码
|
|
|
|
protected void collectUserInformation() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|