Browse Source

Merge pull request #7480 in DESIGN/design from bugfix/10.0 to feature/10.0

* commit 'c106706ca023cf41319f4ab7c71188fc641276f2':
  CHART-22259 feat:插件重新加载或者切换env fvs模板重新加载
feature/10.0
superman 3 years ago
parent
commit
1e6938fcb7
  1. 23
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  2. 18
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

23
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java

@ -15,7 +15,6 @@ import com.fr.design.mainframe.JVirtualTemplate;
import com.fr.design.ui.util.UIUtil;
import com.fr.file.FILE;
import com.fr.file.FileNodeFILE;
import com.fr.file.StashedFILE;
import com.fr.general.ComparatorUtils;
import com.fr.invoke.ClassHelper;
import com.fr.log.FineLoggerFactory;
@ -25,7 +24,7 @@ import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.io.FilenameUtils;
import java.io.ByteArrayOutputStream;
import javax.swing.SwingWorker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -33,7 +32,6 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import javax.swing.SwingWorker;
/**
* 历史模板缓存
@ -360,7 +358,7 @@ public class HistoryTemplateListCache implements CallbackEvent {
int size = historyList.size();
for (int i = 0; i < size; i++) {
JTemplate<?, ?> template = historyList.get(i);
FILE file = templateToStashFile(template);
FILE file = template.templateToStashFile();
if (file != null) {
stashFILEMap.put(i, file);
}
@ -368,21 +366,6 @@ public class HistoryTemplateListCache implements CallbackEvent {
FineLoggerFactory.getLogger().info("Env Change Template Stashed.");
}
private FILE templateToStashFile(JTemplate<?, ?> template) {
FILE file = template.getEditingFILE();
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BaseBook target = template.getTarget();
if (target != null) {
target.export(outputStream);
return new StashedFILE(file, outputStream.toByteArray(), template.suffix());
}
// 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
private boolean checkStash() {
try {
@ -465,7 +448,7 @@ public class HistoryTemplateListCache implements CallbackEvent {
FILE file = template.getEditingFILE();
boolean needReload = context == null || needReloadTemplate(context, template);
if (needReload) {
FILE stashFile = templateToStashFile(template);
FILE stashFile = template.templateToStashFile();
if (stashFile != null) {
FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName());
template.refreshResource(stashFile);

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

@ -57,6 +57,7 @@ import com.fr.event.EventDispatcher;
import com.fr.file.FILE;
import com.fr.file.FILEChooserPane;
import com.fr.file.MemFILE;
import com.fr.file.StashedFILE;
import com.fr.form.ui.NoneWidget;
import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
@ -85,6 +86,7 @@ import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.undo.UndoManager;
import java.awt.BorderLayout;
import java.io.ByteArrayOutputStream;
import java.util.Set;
import java.util.concurrent.Callable;
@ -372,6 +374,22 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
PluginListenerRegistration.getInstance().stopListen(this.pluginListener);
}
public FILE templateToStashFile() {
FILE file = this.getEditingFILE();
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BaseBook target = this.getTarget();
if (target != null) {
target.export(outputStream);
return new StashedFILE(file, outputStream.toByteArray(), template.suffix());
}
// 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
/**
* 刷新内部资源

Loading…
Cancel
Save