Browse Source

Merge branch 'feature/x' of https://code.fineres.com/scm/design/design into feature/x

# Conflicts:
#	designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
feature/x
kerry 2 years ago
parent
commit
8e4be6f040
  1. 62
      designer-base/src/main/java/com/fr/design/javascript/JSContentWithDescriptionPane.java
  2. 113
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  3. 52
      designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java
  4. 50
      designer-base/src/main/java/com/fr/design/worker/save/type/SaveType.java
  5. 81
      designer-base/src/main/java/com/fr/design/worker/save/type/SaveTypeWorker.java
  6. 31
      designer-chart/src/main/java/com/fr/design/mainframe/ChartPropertyPane.java

62
designer-base/src/main/java/com/fr/design/javascript/JSContentWithDescriptionPane.java

@ -50,6 +50,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
@ -59,6 +60,7 @@ import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.SwingWorker;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TreeSelectionEvent;
@ -352,27 +354,51 @@ public class JSContentWithDescriptionPane extends JSContentPane implements KeyLi
private void doHelpDocumentSearch() {
Object value = interfaceNameList.getSelectedValue();
if (value != null) {
String url = CloudCenter.getInstance().acquireUrlByKind("af.doc_search", DOCUMENT_SEARCH_URL) + value.toString();
try {
String result = HttpToolbox.get(url);
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.optJSONArray("list");
if (jsonArray != null) {
DefaultListModel helpDOCModel = (DefaultListModel) helpDOCList.getModel();
helpDOCModel.clear();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject resultJSONObject = jsonArray.optJSONObject(i);
String docURL = resultJSONObject.optString("url");
String name = resultJSONObject.optString("title").trim();
HelpDocument helpDocument = new HelpDocument(docURL, name);
helpDOCModel.addElement(helpDocument);
new SwingWorker<List<HelpDocument>, Void>() {
@Override
protected List<HelpDocument> doInBackground() {
List<HelpDocument> helpDocuments = new ArrayList<>();
updateHelpDocuments(value, helpDocuments);
return helpDocuments;
}
@Override
protected void done() {
try {
List<HelpDocument> helpDocuments = get();
DefaultListModel helpDOCModel = (DefaultListModel) helpDOCList.getModel();
helpDOCModel.clear();
for (HelpDocument helpDocument : helpDocuments) {
helpDOCModel.addElement(helpDocument);
}
} catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
} catch (JSONException e) {
FineLoggerFactory.getLogger().debug(e.getMessage(), e);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}.execute();
}
}
private void updateHelpDocuments(Object value, List<HelpDocument> helpDocuments) {
String url = CloudCenter.getInstance().acquireUrlByKind("af.doc_search", DOCUMENT_SEARCH_URL) + value.toString();
try {
String result = HttpToolbox.get(url);
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.optJSONArray("list");
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject resultJSONObject = jsonArray.optJSONObject(i);
String docURL = resultJSONObject.optString("url");
String name = resultJSONObject.optString("title").trim();
HelpDocument helpDocument = new HelpDocument(docURL, name);
helpDocuments.add(helpDocument);
}
}
} catch (JSONException e) {
FineLoggerFactory.getLogger().debug(e.getMessage(), e);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}

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

@ -62,6 +62,8 @@ import com.fr.design.utils.DesignUtils;
import com.fr.design.worker.save.CallbackSaveWorker;
import com.fr.design.worker.save.EmptyCallBackSaveWorker;
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.DBManipulationPane;
import com.fr.event.EventDispatcher;
@ -1688,24 +1690,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
if (!editingFILE.exists()) {
return saveAs(showLoc);
}
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;
return getSaveCallBackSaveWorker();
}
/**
@ -1751,6 +1736,8 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
}
}
private CallbackSaveWorker saveAs(boolean showLoc) {
FILE editingFILE = this.getEditingFILE();
if (editingFILE == null) {
@ -1772,7 +1759,6 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
// 目标文件
editingFILE = fileChooser.getSelectedFILE();
}
FILE finalEditingFILE = editingFILE;
CallbackSaveWorker worker = new CallbackSaveWorker(new Callable<Boolean>() {
@Override
@ -1873,10 +1859,95 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
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
public void saveDirectly() {
CallbackSaveWorker worker = save();
worker.start(getRuntimeId());
new SaveTypeWorker(getSaveTypeCallable(), this) {
@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

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.EastRegionContainerPane;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.ui.util.UIUtil;
import com.fr.design.worker.WorkerManager;
import com.fr.design.worker.save.type.SaveTypeWorker;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
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;
/**
@ -34,6 +38,14 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
private boolean slowly;
public boolean isSlowly() {
return slowly;
}
public void setSlowly(boolean slowly) {
this.slowly = slowly;
}
public SaveWorker(Callable<Boolean> callable, JTemplate<?, ?> template) {
this.callable = callable;
this.template = template;
@ -47,10 +59,11 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
@Override
protected void done() {
try {
success = get();
success = get();
} catch (Exception e) {
processResult();
FineLoggerFactory.getLogger().error(e.getMessage(), e);
WorkerManager.getInstance().removeWorker(taskName);
SaveFailureHandler.getInstance().process(e);
return;
}
@ -62,6 +75,7 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
// 恢复界面
if (slowly && ComparatorUtils.equals(this.template.getName(), HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getName())) {
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().hideCover();
slowly = false;
}
DesignerFrameFileDealerPane.getInstance().stateChange();
WorkerManager.getInstance().removeWorker(taskName);
@ -69,21 +83,29 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
public void start(String taskName) {
this.taskName = taskName;
StopWatch stopWatch = StopWatch.createStarted();
this.template.setSaving(true);
this.execute();
// worker纳入管理
WorkerManager.getInstance().registerWorker(taskName, this);
try {
this.get(TIME_OUT, TimeUnit.MILLISECONDS);
} catch (TimeoutException timeoutException) {
slowly = true;
// 开始禁用
EastRegionContainerPane.getInstance().updateAllPropertyPane();
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover();
DesignerFrameFileDealerPane.getInstance().stateChange();
} catch (Exception exception) {
FineLoggerFactory.getLogger().error(exception.getMessage(), exception);
WorkerManager.getInstance().removeWorker(taskName);
}
SaveTypeWorker.SAVE_TYPE_POOL.execute(() -> {
while (true) {
if (stopWatch.getTime() > TIME_OUT || isDone()) {
if (!isDone()) {
slowly = true;
UIUtil.invokeLaterIfNeeded(() -> {
// 开始禁用
if (slowly) {
EastRegionContainerPane.getInstance().updateAllPropertyPane();
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover();
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.charttypes.ChartTypeManager;
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.designer.TargetComponent;
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.Icon;
import javax.swing.SwingWorker;
import java.awt.BorderLayout;
import java.awt.Component;
@ -95,16 +97,25 @@ public class ChartPropertyPane extends BaseChartPropertyPane {
* @param ePane 面板
*/
public void populateChartPropertyPane(ChartCollection collection, TargetComponent<?> ePane) {
String chartID = collection.getSelectedChartProvider(ChartProvider.class).getID();
updateChartEditPane(collection.getSelectedChartProvider(ChartProvider.class).getID());
setSupportCellData(true);
this.container.setEPane(ePane);
if (ChartTypeManager.getInstance().chartExit(chartID)) {
chartEditPane.populate(collection);
} else {
GUICoreUtils.setEnabled(chartEditPane, false);
}
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
GEOJSONHelper.getInstance();
return null;
}
@Override
protected void done() {
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