Browse Source

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

和 vito 讨论,这里的异步可以直接改成 invokeLater
省心省力, get
feature/x
Harrison 2 years ago
parent
commit
90d09befcc
  1. 29
      designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java

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

@ -9,7 +9,6 @@ import com.fr.design.selection.QuickEditor;
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.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.start.common.DesignerStartupPool;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
@ -20,7 +19,6 @@ 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.CompletableFuture;
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;
@ -84,20 +82,21 @@ public class ActionFactory {
public static void registerAsyncInitCellEditorClass(Class keyClazz, Class<? extends QuickEditor> editorClazz) { public static void registerAsyncInitCellEditorClass(Class keyClazz, Class<? extends QuickEditor> editorClazz) {
cellEditorClass.put(keyClazz, editorClazz); cellEditorClass.put(keyClazz, editorClazz);
CompletableFuture.runAsync(() -> { // 这里直接用 invokeLater 放到 UI 线程中去调用。
UIUtil.invokeAndWaitIfNeeded(new Runnable() { // 不阻塞主逻辑的启动
@Override UIUtil.invokeLaterIfNeeded(new Runnable() {
public void run() { @Override
try { public void run() {
QuickEditor quickEditor = editorClazz.newInstance();
cellEditorClass.remove(keyClazz); try {
cellEditor.put(keyClazz, quickEditor); QuickEditor quickEditor = editorClazz.newInstance();
} catch (Exception e) { cellEditorClass.remove(keyClazz);
FineLoggerFactory.getLogger().error(e.getMessage(), e); cellEditor.put(keyClazz, quickEditor);
} } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
}); }
}, DesignerStartupPool.designer()); });
} }
/** /**

Loading…
Cancel
Save