Browse Source

Pull request #11971: REPORT-83195 卡顿点优化

Merge in DESIGN/design from ~JOHN.YING/design:feature/x to feature/x

* commit '5155311b6e203d96432a8db4019fd75b05b6bd9b':
  REPORT-83195 卡顿点优化-回退一下开发者模式部分代码,设计有点问题
  REPORT-83195 卡顿点优化-根据插件提示修改了一下代码规范
  REPORT-83195 卡顿点优化-根据插件提示修改了一下代码规范
  REPORT-83195 卡顿点优化-根据插件提示修改了一下代码规范
  REPORT-83195 卡顿点优化-开发者模式
  REPORT-83195 卡顿点优化-单元格初次添加图表卡死
  REPORT-83195 卡顿点优化-保存逻辑优化
feature/x
John.Ying-应志浩 2 years ago
parent
commit
4e88c05b6d
  1. 115
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  2. 52
      designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java
  3. 50
      designer-base/src/main/java/com/fr/design/worker/save/type/SaveType.java
  4. 81
      designer-base/src/main/java/com/fr/design/worker/save/type/SaveTypeWorker.java
  5. 31
      designer-chart/src/main/java/com/fr/design/mainframe/ChartPropertyPane.java

115
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -61,6 +61,8 @@ import com.fr.design.utils.DesignUtils;
import com.fr.design.worker.save.CallbackSaveWorker; import com.fr.design.worker.save.CallbackSaveWorker;
import com.fr.design.worker.save.EmptyCallBackSaveWorker; import com.fr.design.worker.save.EmptyCallBackSaveWorker;
import com.fr.design.worker.save.SaveFailureHandler; import com.fr.design.worker.save.SaveFailureHandler;
import com.fr.design.worker.save.type.SaveType;
import com.fr.design.worker.save.type.SaveTypeWorker;
import com.fr.design.write.submit.DBManipulationInWidgetEventPane; import com.fr.design.write.submit.DBManipulationInWidgetEventPane;
import com.fr.design.write.submit.DBManipulationPane; import com.fr.design.write.submit.DBManipulationPane;
import com.fr.event.EventDispatcher; import com.fr.event.EventDispatcher;
@ -1687,24 +1689,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
if (!editingFILE.exists()) { if (!editingFILE.exists()) {
return saveAs(showLoc); return saveAs(showLoc);
} }
return getSaveCallBackSaveWorker();
CallbackSaveWorker worker = new CallbackSaveWorker(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return saveRealFileByWorker();
}
}, this);
worker.addSuccessCallback(new Runnable() {
@Override
public void run() {
callBackForSave();
//在保存后的回调中执行预编译流程
CptCompileUtil.compile(JTemplate.this);
}
});
return worker;
} }
/** /**
@ -1750,6 +1735,8 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
} }
} }
private CallbackSaveWorker saveAs(boolean showLoc) { private CallbackSaveWorker saveAs(boolean showLoc) {
FILE editingFILE = this.getEditingFILE(); FILE editingFILE = this.getEditingFILE();
if (editingFILE == null) { if (editingFILE == null) {
@ -1771,7 +1758,6 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
// 目标文件 // 目标文件
editingFILE = fileChooser.getSelectedFILE(); editingFILE = fileChooser.getSelectedFILE();
} }
FILE finalEditingFILE = editingFILE; FILE finalEditingFILE = editingFILE;
CallbackSaveWorker worker = new CallbackSaveWorker(new Callable<Boolean>() { CallbackSaveWorker worker = new CallbackSaveWorker(new Callable<Boolean>() {
@Override @Override
@ -1872,10 +1858,95 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
return saveAs(true); return saveAs(true);
} }
/**
* 获取保存用到的saveWorker
*/
private CallbackSaveWorker getSaveCallBackSaveWorker() {
CallbackSaveWorker worker = new CallbackSaveWorker(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return saveRealFileByWorker();
}
}, this);
worker.addSuccessCallback(new Runnable() {
@Override
public void run() {
callBackForSave();
//在保存后的回调中执行预编译流程
CptCompileUtil.compile(JTemplate.this);
}
});
return worker;
}
/**
* 获取保存的类别执行的callable
*/
private Callable<SaveType.TypeEnum> getSaveTypeCallable() {
return () -> {
fireJTemplateSaveBefore();
FILE editingFILE = getEditingFILE();
// carl:editingFILE没有,当然不存了,虽然不会有这种情况
if (editingFILE == null) {
return SaveType.TypeEnum.EMPTY;
}
// 检查一下editingFILE是不是已存在的文件,如果不存在则用saveAs
if (!editingFILE.exists()) {
return SaveType.TypeEnum.SAVE_AS;
}
return SaveType.TypeEnum.SAVE;
};
}
/**
* 根据保存类型获取对应的saveWorker
*
* @param saveType 保存类型
*/
private CallbackSaveWorker getSaveTypeWorker(SaveType saveType) {
CallbackSaveWorker callbackSaveWorker;
switch (saveType.getType()) {
case EMPTY:
callbackSaveWorker = new EmptyCallBackSaveWorker();
break;
case SAVE:
callbackSaveWorker = getSaveCallBackSaveWorker();
break;
default:
callbackSaveWorker = saveAs(true);
}
return callbackSaveWorker;
}
@Override @Override
public void saveDirectly() { public void saveDirectly() {
CallbackSaveWorker worker = save(); new SaveTypeWorker(getSaveTypeCallable(), this) {
worker.start(getRuntimeId()); @Override
protected void done() {
try {
SaveType saveType = get();
CallbackSaveWorker callbackSaveWorker = getSaveTypeWorker(saveType);
//告诉一下后面执行的saveWorker,当前判断文件是否存在的操作是否已经进行了开始转圈的那个等待动画,避免重复
callbackSaveWorker.setSlowly(saveType.isSlowly());
callbackSaveWorker.start(getRuntimeId());
//如果是空也就是不保存,需要恢复一下界面(如果saveTypeWorker里进行了操作的话)
if (callbackSaveWorker instanceof EmptyCallBackSaveWorker) {
setSaving(false);
if (saveType.isSlowly()) {
if (ComparatorUtils.equals(getName(), HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getName())) {
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().hideCover();
}
}
DesignerFrameFileDealerPane.getInstance().stateChange();
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}.start();
} }
@Override @Override
@ -1979,7 +2050,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
public void setDesignerUIMode() { public void setDesignerUIMode() {
DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode(); DesignerUIModeConfig.getInstance().setAbsoluteMeasureUIMode();
} }
/** /**
* 判断当前的模板是否是有效的模板 * 判断当前的模板是否是有效的模板
* *

52
designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java

@ -5,12 +5,16 @@ import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.mainframe.DesignerFrameFileDealerPane;
import com.fr.design.mainframe.EastRegionContainerPane; import com.fr.design.mainframe.EastRegionContainerPane;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.ui.util.UIUtil;
import com.fr.design.worker.WorkerManager; import com.fr.design.worker.WorkerManager;
import com.fr.design.worker.save.type.SaveTypeWorker;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import com.fr.third.org.apache.commons.lang3.time.StopWatch;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
/** /**
@ -34,6 +38,14 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
private boolean slowly; private boolean slowly;
public boolean isSlowly() {
return slowly;
}
public void setSlowly(boolean slowly) {
this.slowly = slowly;
}
public SaveWorker(Callable<Boolean> callable, JTemplate<?, ?> template) { public SaveWorker(Callable<Boolean> callable, JTemplate<?, ?> template) {
this.callable = callable; this.callable = callable;
this.template = template; this.template = template;
@ -47,10 +59,11 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
@Override @Override
protected void done() { protected void done() {
try { try {
success = get(); success = get();
} catch (Exception e) { } catch (Exception e) {
processResult(); processResult();
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
WorkerManager.getInstance().removeWorker(taskName);
SaveFailureHandler.getInstance().process(e); SaveFailureHandler.getInstance().process(e);
return; return;
} }
@ -62,6 +75,7 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
// 恢复界面 // 恢复界面
if (slowly && ComparatorUtils.equals(this.template.getName(), HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getName())) { if (slowly && ComparatorUtils.equals(this.template.getName(), HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getName())) {
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().hideCover(); DesignerContext.getDesignerFrame().getCenterTemplateCardPane().hideCover();
slowly = false;
} }
DesignerFrameFileDealerPane.getInstance().stateChange(); DesignerFrameFileDealerPane.getInstance().stateChange();
WorkerManager.getInstance().removeWorker(taskName); WorkerManager.getInstance().removeWorker(taskName);
@ -69,21 +83,29 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
public void start(String taskName) { public void start(String taskName) {
this.taskName = taskName; this.taskName = taskName;
StopWatch stopWatch = StopWatch.createStarted();
this.template.setSaving(true); this.template.setSaving(true);
this.execute(); this.execute();
// worker纳入管理 // worker纳入管理
WorkerManager.getInstance().registerWorker(taskName, this); WorkerManager.getInstance().registerWorker(taskName, this);
try { SaveTypeWorker.SAVE_TYPE_POOL.execute(() -> {
this.get(TIME_OUT, TimeUnit.MILLISECONDS); while (true) {
} catch (TimeoutException timeoutException) { if (stopWatch.getTime() > TIME_OUT || isDone()) {
slowly = true; if (!isDone()) {
// 开始禁用 slowly = true;
EastRegionContainerPane.getInstance().updateAllPropertyPane(); UIUtil.invokeLaterIfNeeded(() -> {
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover(); // 开始禁用
DesignerFrameFileDealerPane.getInstance().stateChange(); if (slowly) {
} catch (Exception exception) { EastRegionContainerPane.getInstance().updateAllPropertyPane();
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover();
WorkerManager.getInstance().removeWorker(taskName); DesignerFrameFileDealerPane.getInstance().stateChange();
} }
});
}
stopWatch.stop();
break;
}
}
});
} }
} }

50
designer-base/src/main/java/com/fr/design/worker/save/type/SaveType.java

@ -0,0 +1,50 @@
package com.fr.design.worker.save.type;
/**
* 保存的类别
*
* @author John.Ying
* @since 11.0
* Created on 2023/4/14
*/
public class SaveType {
private TypeEnum type;
//保存时间是否慢(是否展示了保存中的UI界面)
private boolean slowly;
public TypeEnum getType() {
return type;
}
public void setType(TypeEnum saveType) {
this.type = saveType;
}
public boolean isSlowly() {
return slowly;
}
public void setSlowly(boolean slowly) {
this.slowly = slowly;
}
/**
* 保存类型save or saveAs or empty
*/
public enum TypeEnum {
/**
* 保存
*/
SAVE,
/**
* 另存
*/
SAVE_AS,
/**
* 空保存
*/
EMPTY;
}
}

81
designer-base/src/main/java/com/fr/design/worker/save/type/SaveTypeWorker.java

@ -0,0 +1,81 @@
package com.fr.design.worker.save.type;
import com.fr.concurrent.FineExecutors;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrameFileDealerPane;
import com.fr.design.mainframe.EastRegionContainerPane;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.ui.util.UIUtil;
import com.fr.third.org.apache.commons.lang3.time.StopWatch;
import javax.swing.SwingWorker;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
/**
* 判断保存类别时执行的worker
*
* @author John.Ying
* @since 11.0
* Created on 2023/4/14
*/
public class SaveTypeWorker extends SwingWorker<SaveType, Void> {
public static final ExecutorService SAVE_TYPE_POOL = FineExecutors.newSingleThreadExecutor();
private final Callable<SaveType.TypeEnum> callable;
private static final int TIME_OUT = 400;
private final JTemplate<?, ?> template;
private final SaveType saveType;
public SaveTypeWorker(Callable<SaveType.TypeEnum> callable, JTemplate<?, ?> template) {
this.callable = callable;
this.template = template;
this.saveType = new SaveType();
}
@Override
protected SaveType doInBackground() throws Exception {
this.saveType.setType(callable.call());
return this.saveType;
}
@Override
protected void done() {
}
/**
* 启动saveTypeWorker
*/
public void start() {
StopWatch stopWatch = StopWatch.createStarted();
this.template.setSaving(true);
this.execute();
SAVE_TYPE_POOL.execute(() -> {
while (true) {
//大于最大等待时间或者worker已经完成该线程都要结束循环
if (stopWatch.getTime() > TIME_OUT || isDone()) {
//如果是大于最大等待时间结束的,就需要进行等待中界面的覆盖
if (!isDone()) {
saveType.setSlowly(true);
UIUtil.invokeLaterIfNeeded(() -> {
// 开始禁用
EastRegionContainerPane.getInstance().updateAllPropertyPane();
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover();
DesignerFrameFileDealerPane.getInstance().stateChange();
});
}
stopWatch.stop();
break;
}
}
});
}
}

31
designer-chart/src/main/java/com/fr/design/mainframe/ChartPropertyPane.java

@ -9,6 +9,7 @@ import com.fr.base.chart.BaseChartCollection;
import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.charttypes.ChartTypeManager; import com.fr.chart.charttypes.ChartTypeManager;
import com.fr.chartx.attr.ChartProvider; import com.fr.chartx.attr.ChartProvider;
import com.fr.decision.webservice.v10.map.geojson.helper.GEOJSONHelper;
import com.fr.design.ChartTypeInterfaceManager; import com.fr.design.ChartTypeInterfaceManager;
import com.fr.design.designer.TargetComponent; import com.fr.design.designer.TargetComponent;
import com.fr.design.gui.chart.BaseChartPropertyPane; import com.fr.design.gui.chart.BaseChartPropertyPane;
@ -19,6 +20,7 @@ import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.SwingWorker;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
@ -95,16 +97,25 @@ public class ChartPropertyPane extends BaseChartPropertyPane {
* @param ePane 面板 * @param ePane 面板
*/ */
public void populateChartPropertyPane(ChartCollection collection, TargetComponent<?> ePane) { public void populateChartPropertyPane(ChartCollection collection, TargetComponent<?> ePane) {
String chartID = collection.getSelectedChartProvider(ChartProvider.class).getID(); new SwingWorker<Void, Void>() {
updateChartEditPane(collection.getSelectedChartProvider(ChartProvider.class).getID()); @Override
setSupportCellData(true); protected Void doInBackground() throws Exception {
this.container.setEPane(ePane); GEOJSONHelper.getInstance();
return null;
if (ChartTypeManager.getInstance().chartExit(chartID)) { }
chartEditPane.populate(collection); @Override
} else { protected void done() {
GUICoreUtils.setEnabled(chartEditPane, false); String chartID = collection.getSelectedChartProvider(ChartProvider.class).getID();
} updateChartEditPane(collection.getSelectedChartProvider(ChartProvider.class).getID());
setSupportCellData(true);
container.setEPane(ePane);
if (ChartTypeManager.getInstance().chartExit(chartID)) {
chartEditPane.populate(collection);
} else {
GUICoreUtils.setEnabled(chartEditPane, false);
}
}
}.execute();
} }
/** /**

Loading…
Cancel
Save