From 0f33a0fee9c109d257420e0090aa7a0d7e5b643d Mon Sep 17 00:00:00 2001 From: Harrison Date: Wed, 16 Nov 2022 18:36:44 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-83197=E3=80=90=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E3=80=91=E5=90=AF=E5=8A=A8=E9=A1=B5=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E5=B0=86=E5=BC=82=E6=AD=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=94=BE=E5=88=B0=20UIUtil=20=E4=B8=AD=E5=8E=BB?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E3=80=82=E9=81=BF=E5=85=8D=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/actions/core/ActionFactory.java | 36 ++++++++----------- .../fr/startup/ui/StartupLoadingPanel.java | 29 +++++++-------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java b/designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java index 5b1aaf6f52..e4b8b9ed62 100644 --- a/designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java +++ b/designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java @@ -6,12 +6,10 @@ import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.mainframe.JTemplate; import com.fr.design.menu.MenuKeySet; import com.fr.design.selection.QuickEditor; +import com.fr.design.ui.util.UIUtil; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import com.fr.start.common.DesignerStartupPool; -import com.fr.third.guava.util.concurrent.FutureCallback; -import com.fr.third.guava.util.concurrent.Futures; -import com.fr.third.guava.util.concurrent.ListenableFutureTask; import javax.swing.Action; import javax.swing.KeyStroke; @@ -22,7 +20,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArraySet; @@ -86,23 +84,19 @@ public class ActionFactory { public static void registerAsyncInitCellEditorClass(Class keyClazz, Class editorClazz) { cellEditorClass.put(keyClazz, editorClazz); - Callable callable = new Callable() { - @Override - public QuickEditor call() throws Exception { - return editorClazz.newInstance(); - } - }; - ListenableFutureTask future = ListenableFutureTask.create(callable); - Futures.addCallback(future, new FutureCallback() { - @Override - public void onSuccess(QuickEditor quickEditor) { - cellEditorClass.remove(keyClazz); - cellEditor.put(keyClazz, quickEditor); - } - - @Override - public void onFailure(Throwable throwable) { - } + CompletableFuture.runAsync(() -> { + UIUtil.invokeAndWaitIfNeeded(new Runnable() { + @Override + public void run() { + try { + QuickEditor quickEditor = editorClazz.newInstance(); + cellEditorClass.remove(keyClazz); + cellEditor.put(keyClazz, quickEditor); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + }); }, DesignerStartupPool.designer()); } diff --git a/designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java b/designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java index fa44903dc9..59f86fc467 100644 --- a/designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java +++ b/designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java @@ -4,7 +4,7 @@ import com.fr.concurrent.FineExecutors; import com.fr.concurrent.NamedThreadFactory; import com.fr.design.gui.iprogressbar.ProgressDialog; import com.fr.design.i18n.Toolkit; -import com.fr.design.mainframe.DesignerContext; +import com.fr.design.ui.util.UIUtil; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; @@ -68,19 +68,20 @@ public class StartupLoadingPanel { scheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { - if (isComplete()) { - scheduler.shutdown(); - progressDialog.dispose(); - resetListeners(); - return; - } - if (!progressDialog.isVisible()) { - progressDialog = new ProgressDialog(DesignerContext.getDesignerFrame()); - progressDialog.setVisible(true); - String moduleId = getModuleId(); - progressDialog.updateLoadingText(moduleId); - } - progressDialog.setProgressValue(incrementProgress()); + UIUtil.invokeAndWaitIfNeeded(() -> { + if (isComplete()) { + scheduler.shutdown(); + progressDialog.dispose(); + resetListeners(); + return; + } + if (!progressDialog.isVisible()) { + progressDialog.setVisible(true); + String moduleId = getModuleId(); + progressDialog.updateLoadingText(moduleId); + } + progressDialog.setProgressValue(incrementProgress()); + }); } }, 0, STEP_HEARTBEAT, TimeUnit.MILLISECONDS);