|
88 | 88 | import java.text.DecimalFormat; |
89 | 89 | import java.util.HashMap; |
90 | 90 | import java.util.Map; |
| 91 | +import java.util.concurrent.ExecutionException; |
| 92 | +import java.util.concurrent.FutureTask; |
| 93 | +import java.util.concurrent.RunnableFuture; |
| 94 | +import java.util.function.Supplier; |
91 | 95 |
|
92 | 96 | import static com.microsoft.azuretools.core.mvp.model.springcloud.SpringCloudIdHelper.getSubscriptionId; |
93 | 97 | import static com.microsoft.intellij.helpers.arm.DeploymentPropertyViewProvider.TYPE; |
@@ -151,13 +155,17 @@ public void run() { |
151 | 155 | @Override |
152 | 156 | public boolean showConfirmation(@NotNull String message, @NotNull String title, @NotNull String[] options, |
153 | 157 | String defaultOption) { |
154 | | - return Messages.showDialog(message, title, options, ArrayUtils.indexOf(options, defaultOption), null) == 0; |
| 158 | + return showConfirmation(null, message, title, options, defaultOption); |
155 | 159 | } |
156 | 160 |
|
157 | 161 | @Override |
158 | 162 | public boolean showConfirmation(@NotNull Component node, @NotNull String message, @NotNull String title, @NotNull String[] options, String defaultOption) { |
159 | | - return Messages.showDialog(node, message, title, options, ArrayUtils.indexOf(options, defaultOption), null) |
160 | | - == 0; |
| 163 | + return runFromDispatchThread(() -> 0 == Messages.showDialog(node, |
| 164 | + message, |
| 165 | + title, |
| 166 | + options, |
| 167 | + ArrayUtils.indexOf(options, defaultOption), |
| 168 | + null)); |
161 | 169 | } |
162 | 170 |
|
163 | 171 | @Override |
@@ -719,27 +727,41 @@ public static String readableFileSize(long size) { |
719 | 727 |
|
720 | 728 | @Override |
721 | 729 | public void showMessageDialog(Component component, String message, String title, Icon icon) { |
722 | | - Messages.showMessageDialog(component, message, title, icon); |
| 730 | + DefaultLoader.getIdeHelper().invokeLater(() -> Messages.showMessageDialog(component, message, title, icon)); |
723 | 731 | } |
724 | 732 |
|
725 | 733 | @Override |
726 | 734 | public int showConfirmDialog(Component component, String message, String title, String[] options, |
727 | 735 | String defaultOption, Icon icon) { |
728 | | - return Messages.showDialog(component, |
729 | | - message, |
730 | | - title, |
731 | | - options, |
732 | | - ArrayUtils.indexOf(options, defaultOption), |
733 | | - icon); |
| 736 | + return runFromDispatchThread(() -> Messages.showDialog(component, |
| 737 | + message, |
| 738 | + title, |
| 739 | + options, |
| 740 | + ArrayUtils.indexOf(options, defaultOption), |
| 741 | + icon)); |
734 | 742 | } |
735 | 743 |
|
736 | 744 | @Override |
737 | 745 | public boolean showYesNoDialog(Component component, String message, String title, Icon icon) { |
738 | | - return Messages.showYesNoDialog(component, message, title, icon) == Messages.YES; |
| 746 | + return runFromDispatchThread(() -> Messages.showYesNoDialog(component, message, title, icon) |
| 747 | + == Messages.YES); |
739 | 748 | } |
740 | 749 |
|
741 | 750 | @Override |
742 | 751 | public String showInputDialog(Component component, String message, String title, Icon icon) { |
743 | | - return Messages.showInputDialog(component, message, title, icon); |
| 752 | + return runFromDispatchThread(() -> Messages.showInputDialog(component, message, title, icon)); |
| 753 | + } |
| 754 | + |
| 755 | + private static <T> T runFromDispatchThread(Supplier<T> supplier) { |
| 756 | + if (ApplicationManager.getApplication().isDispatchThread()) { |
| 757 | + return supplier.get(); |
| 758 | + } |
| 759 | + RunnableFuture<T> runnableFuture = new FutureTask<>(() -> supplier.get()); |
| 760 | + ApplicationManager.getApplication().invokeLater(runnableFuture); |
| 761 | + try { |
| 762 | + return runnableFuture.get(); |
| 763 | + } catch (InterruptedException | ExecutionException e) { |
| 764 | + return null; |
| 765 | + } |
744 | 766 | } |
745 | 767 | } |
0 commit comments