From c4651f8a3c9b60d4b07033d5df5259f6b9afe60a Mon Sep 17 00:00:00 2001 From: MrCoder Date: Mon, 23 Dec 2024 16:54:44 +1100 Subject: [PATCH] refactor(jetbrains): specify action update thread for DocumentationAction - Override getActionUpdateThread method to return ActionUpdateThread.EDT - This ensures the action is updated on the Event Dispatch Thread --- .../plugins/jetbrains/actions/DemoAction.java | 6 +++ .../actions/DocumentationAction.java | 6 +++ src/org/intellij/sequencer/SequencePanel.java | 42 ++++++++++++++++++- .../intellij/sequencer/SequencePlugin2.java | 17 +++++--- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/com/zenuml/sequence/plugins/jetbrains/actions/DemoAction.java b/src/com/zenuml/sequence/plugins/jetbrains/actions/DemoAction.java index 138aa775..fa56694c 100755 --- a/src/com/zenuml/sequence/plugins/jetbrains/actions/DemoAction.java +++ b/src/com/zenuml/sequence/plugins/jetbrains/actions/DemoAction.java @@ -2,6 +2,7 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.zenuml.license.CheckLicense; import org.jetbrains.annotations.NotNull; @@ -19,6 +20,11 @@ public DemoAction() { super(TITLE); } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { final boolean isLicensed = CheckLicense.isLicensed(); final String message = "Sample Plugin with License Support.\nLicense successfully obtained: " + (isLicensed? "yes" : "no"); diff --git a/src/com/zenuml/sequence/plugins/jetbrains/actions/DocumentationAction.java b/src/com/zenuml/sequence/plugins/jetbrains/actions/DocumentationAction.java index 8a8ecab4..713bc6d3 100644 --- a/src/com/zenuml/sequence/plugins/jetbrains/actions/DocumentationAction.java +++ b/src/com/zenuml/sequence/plugins/jetbrains/actions/DocumentationAction.java @@ -3,6 +3,7 @@ import com.intellij.ide.BrowserUtil; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import org.jetbrains.annotations.NotNull; public class DocumentationAction extends AnAction { @@ -13,6 +14,11 @@ public DocumentationAction() { super(TITLE); } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { BrowserUtil.browse("https://zenuml.atlassian.net/wiki/spaces/ZEN/pages/233373697/Documentations"); } diff --git a/src/org/intellij/sequencer/SequencePanel.java b/src/org/intellij/sequencer/SequencePanel.java index f07daf4b..9685b784 100644 --- a/src/org/intellij/sequencer/SequencePanel.java +++ b/src/org/intellij/sequencer/SequencePanel.java @@ -16,6 +16,7 @@ import org.intellij.sequencer.generator.filters.SingleClassFilter; import org.intellij.sequencer.generator.filters.SingleMethodFilter; import org.intellij.sequencer.ui.MyButtonlessScrollBarUI; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.filechooser.FileFilter; @@ -170,6 +171,11 @@ public CloseAction() { super("Close", "Close sequence", SequencePluginIcons.CLOSE_ICON); } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent event) { _plugin.closeSequence(SequencePanel.this); } @@ -180,6 +186,11 @@ public ReGenerateAction() { super("ReGenerate", "Regenerate diagram", SequencePluginIcons.REFRESH_ICON); } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent anActionEvent) { generate(); @@ -191,6 +202,11 @@ public ExportAction() { super("Export", "Export image to file", SequencePluginIcons.EXPORT_ICON); } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); @@ -222,6 +238,12 @@ private class ExportTextAction extends AnAction { public ExportTextAction() { super("ExportTextFile", "Export call stack as text file", SequencePluginIcons.EXPORT_TEXT_ICON); } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + @Override public void actionPerformed(AnActionEvent event) { JFileChooser fileChooser = new JFileChooser(); @@ -258,6 +280,11 @@ public GotoSourceAction(ScreenObject screenObject) { _screenObject = screenObject; } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent anActionEvent) { gotoSourceCode(_screenObject); } @@ -271,6 +298,11 @@ public RemoveClassAction(ObjectInfo objectInfo) { _objectInfo = objectInfo; } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent anActionEvent) { _sequenceParams.getMethodFilter().addFilter(new SingleClassFilter(_objectInfo.getFullName())); generate(); @@ -285,6 +317,11 @@ public RemoveMethodAction(MethodInfo methodInfo) { _methodInfo = methodInfo; } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent anActionEvent) { _sequenceParams.getMethodFilter().addFilter(new SingleMethodFilter( _methodInfo.getObjectInfo().getFullName(), @@ -292,7 +329,6 @@ public void actionPerformed(AnActionEvent anActionEvent) { _methodInfo.getArgTypes() )); generate(); - } } @@ -307,6 +343,10 @@ public ExpendInterfaceAction(String face, String impl) { } @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent anActionEvent) { _sequenceParams.getInterfaceImplFilter().put( face, diff --git a/src/org/intellij/sequencer/SequencePlugin2.java b/src/org/intellij/sequencer/SequencePlugin2.java index ad2dc886..c06a09ba 100644 --- a/src/org/intellij/sequencer/SequencePlugin2.java +++ b/src/org/intellij/sequencer/SequencePlugin2.java @@ -10,7 +10,6 @@ import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.ToolWindow; @@ -31,16 +30,12 @@ import org.intellij.sequencer.generator.filters.MethodFilter; import org.intellij.sequencer.ui.ButtonTabComponent; import org.intellij.sequencer.util.PsiUtil; +import org.jetbrains.annotations.NotNull; import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; public class SequencePlugin2 implements ProjectComponent { @@ -366,6 +361,11 @@ private class LockUnlockAction extends AnAction { _isLock = isLock; } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent anActionEvent) { _jTabbedPane.setIconAt(_index, _isLock? DISABLED_ICON: S_ICON); } @@ -379,6 +379,11 @@ private class CloseAction extends AnAction { _index = index; } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + public void actionPerformed(AnActionEvent anActionEvent) { closeSequenceAtIndex(_index); }