diff --git a/build.gradle.kts b/build.gradle.kts index d8d725b..ac6ab61 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ intellij { version.set("2022.2.5") type.set("IC") // Target IDE Platform - plugins.set(listOf("com.intellij.java")) + plugins.set(listOf("com.intellij.java","org.jetbrains.plugins.terminal")) } dependencies{ diff --git a/src/main/java/com/example/pssupporter/MyToolWindowFactory.java b/src/main/java/com/example/pssupporter/MyToolWindowFactory.java index 1e04c40..cc58f7a 100644 --- a/src/main/java/com/example/pssupporter/MyToolWindowFactory.java +++ b/src/main/java/com/example/pssupporter/MyToolWindowFactory.java @@ -4,30 +4,22 @@ package com.example.pssupporter; -import com.example.pssupporter.ui.MyTestListPanel; -import com.example.pssupporter.ui.MyToolbarPanel; -import com.example.pssupporter.utils.ComponentManager; -import com.intellij.openapi.actionSystem.ActionGroup; -import com.intellij.openapi.actionSystem.ActionManager; +import com.example.pssupporter.ui.MyMainView; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowAnchor; import com.intellij.openapi.wm.ToolWindowFactory; -import com.intellij.ui.components.JBPanel; -import com.intellij.ui.components.JBScrollPane; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.openapi.wm.ex.ToolWindowManagerListener; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; +import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; -import javax.swing.*; -import java.awt.*; - public class MyToolWindowFactory implements ToolWindowFactory { - private ActionGroup getActionGroup(String actionGroupId) { - ActionManager actionManager = ActionManager.getInstance(); - return (ActionGroup) actionManager.getAction(actionGroupId); - } + private MyMainView myMainView; @Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { @@ -35,27 +27,30 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo ContentManager contentManager = toolWindow.getContentManager(); ContentFactory contentFactory = ContentFactory.getInstance(); - JBPanel myMainView = new JBPanel(new BorderLayout()); - - JBScrollPane scrollPane = new JBScrollPane(MyTestListPanel.getInstance()); - - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - - JBPanel myEditorPanel = new JBPanel(new GridLayout(1, 1)); - ActionGroup myActionGroup = getActionGroup("myActionGroup"); - MyToolbarPanel myToolbarPanel = new MyToolbarPanel(myActionGroup, myMainView); - - myMainView.add(myToolbarPanel, BorderLayout.NORTH); - myMainView.add(scrollPane, BorderLayout.WEST); - myMainView.add(myEditorPanel, BorderLayout.CENTER); - - ComponentManager.getInstance().addComponent("myTestListPanel", MyTestListPanel.getInstance()); - ComponentManager.getInstance().addComponent("myEditorPanel", myEditorPanel); + myMainView = new MyMainView(project, toolWindow.getAnchor().isHorizontal()); Content content = contentFactory.createContent(myMainView, "Supporter", false); contentManager.addContent(content); + setupToolWindowEventListener(project); + }); + } + + private void setupToolWindowEventListener(@NotNull Project project) { + MessageBusConnection connect = project.getMessageBus().connect(); + connect.subscribe(ToolWindowManagerListener.TOPIC, new ToolWindowManagerListener() { + @Override + public void stateChanged(@NotNull ToolWindowManager toolWindowManager, @NotNull ToolWindowManagerEventType changeType) { + ToolWindowManagerListener.super.stateChanged(toolWindowManager, changeType); + if (ToolWindowManagerEventType.SetSideToolAndAnchor.equals(changeType)) { + ToolWindow baekjoonSupporter = toolWindowManager.getToolWindow("BaekjoonSupporter"); + + if (baekjoonSupporter.getAnchor() != null) { + ToolWindowAnchor anchor = baekjoonSupporter.getAnchor(); + myMainView.setLayoutBasedOnOrientation(anchor.isHorizontal()); + } + } + } }); } } diff --git a/src/main/java/com/example/pssupporter/actions/MyAddTestAction.java b/src/main/java/com/example/pssupporter/actions/MyAddTestAction.java index 277be18..d9b4df8 100644 --- a/src/main/java/com/example/pssupporter/actions/MyAddTestAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyAddTestAction.java @@ -5,6 +5,7 @@ package com.example.pssupporter.actions; import com.example.pssupporter.ui.MyTestListPanel; +import com.example.pssupporter.utils.ComponentManager; import com.example.pssupporter.utils.thread.GlobalThreadStore; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; import com.intellij.openapi.actionSystem.AnAction; @@ -22,7 +23,7 @@ public void update(@NotNull AnActionEvent e) { @Override public void actionPerformed(@NotNull AnActionEvent e) { - MyTestListPanel myTestListPanel = MyTestListPanel.getInstance(); + MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); myTestListPanel.addTest(); } } diff --git a/src/main/java/com/example/pssupporter/actions/MyLoadTestDataAction.java b/src/main/java/com/example/pssupporter/actions/MyLoadTestDataAction.java index 2197935..658c619 100644 --- a/src/main/java/com/example/pssupporter/actions/MyLoadTestDataAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyLoadTestDataAction.java @@ -30,6 +30,7 @@ public void update(@NotNull AnActionEvent e) { @Override public void actionPerformed(@NotNull AnActionEvent e) { + MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); String selected = Messages.showInputDialog(e.getProject(), "Input Baekjoon number", "Load Test Data", null); if (!StringUtils.isBlank(selected)) { ComponentManager.getInstance().removeChildrenComponentsByName("myEditorPanel"); @@ -38,10 +39,10 @@ public void actionPerformed(@NotNull AnActionEvent e) { long number = Long.parseLong(selected); List examples = CrawlerProvider.getCrawler(Site.BAEKJOON_OJ).getExamples(number); - MyTestListPanel.getInstance().removeAllTests(); + myTestListPanel.removeAllTests(); for (TestData testData : examples) { - MyTestListPanel.getInstance().addTest(testData); + myTestListPanel.addTest(testData); } } catch (NumberFormatException ne) { diff --git a/src/main/java/com/example/pssupporter/actions/MyRemoveTestAction.java b/src/main/java/com/example/pssupporter/actions/MyRemoveTestAction.java index 700d036..b9d3b9f 100644 --- a/src/main/java/com/example/pssupporter/actions/MyRemoveTestAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyRemoveTestAction.java @@ -23,13 +23,13 @@ public void update(@NotNull AnActionEvent e) { @Override public void actionPerformed(@NotNull AnActionEvent e) { - MyTestListPanel instance = MyTestListPanel.getInstance(); - int selectedIndex = instance.getSelectedIndex(); + MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); + int selectedIndex = myTestListPanel.getSelectedIndex(); if (selectedIndex != -1) { ComponentManager.getInstance().removeChildrenComponentsByName("myEditorPanel"); - instance.removeTest(selectedIndex); - instance.repaint(); + myTestListPanel.removeTest(selectedIndex); + myTestListPanel.repaint(); } } } diff --git a/src/main/java/com/example/pssupporter/actions/MyRunAllTestsAction.java b/src/main/java/com/example/pssupporter/actions/MyRunAllTestsAction.java index 9987e4b..1fd5529 100644 --- a/src/main/java/com/example/pssupporter/actions/MyRunAllTestsAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyRunAllTestsAction.java @@ -30,16 +30,17 @@ public void update(@NotNull AnActionEvent e) { boolean isRunning = GlobalThreadStore.getInstance() .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(!isRunning); - - MyTestListPanel.getInstance().setEnabled(!isRunning); + MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); + myTestListPanel.setEnabled(!isRunning); } @Override public void actionPerformed(@NotNull AnActionEvent e) { ComponentManager.getInstance().removeChildrenComponentsByName("myEditorPanel"); - MyTestListPanel.getInstance().clearSelection(); + MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); + myTestListPanel.clearSelection(); - List myTestListItems = MyTestListPanel.getInstance().getMyTestListItems(); + List myTestListItems = myTestListPanel.getMyTestListItems(); IntellijUtils.getSelectedFile(Objects.requireNonNull(e.getProject())) .ifPresentOrElse(selectedFile -> { IntellijUtils.autoSaveFile(selectedFile); diff --git a/src/main/java/com/example/pssupporter/actions/MyRunTestAction.java b/src/main/java/com/example/pssupporter/actions/MyRunTestAction.java index a2dc6d2..dea69c6 100644 --- a/src/main/java/com/example/pssupporter/actions/MyRunTestAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyRunTestAction.java @@ -30,19 +30,21 @@ public void update(@NotNull AnActionEvent e) { .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(!isRunning); - MyTestListPanel.getInstance().setEnabled(!isRunning); + MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); + myTestListPanel.setEnabled(!isRunning); } @Override public void actionPerformed(@NotNull AnActionEvent e) { - int selectedIndex = MyTestListPanel.getInstance().getSelectedIndex(); + MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); + int selectedIndex = myTestListPanel.getSelectedIndex(); if (selectedIndex == -1) { return; } ComponentManager.getInstance().removeChildrenComponentsByName("myEditorPanel"); - MyTestListPanel.getInstance().clearSelection(); + myTestListPanel.clearSelection(); - MyTestListItem selectedItem = MyTestListPanel.getInstance().getMyTestListItem(selectedIndex); + MyTestListItem selectedItem = myTestListPanel.getMyTestListItem(selectedIndex); IntellijUtils.getSelectedFile(Objects.requireNonNull(e.getProject())) .ifPresentOrElse(selectedFile -> { IntellijUtils.autoSaveFile(selectedFile); diff --git a/src/main/java/com/example/pssupporter/actions/MyStopAllTestsAction.java b/src/main/java/com/example/pssupporter/actions/MyStopAllTestsAction.java index f8b23a2..cff40d8 100644 --- a/src/main/java/com/example/pssupporter/actions/MyStopAllTestsAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyStopAllTestsAction.java @@ -5,6 +5,7 @@ package com.example.pssupporter.actions; import com.example.pssupporter.ui.MyTestListPanel; +import com.example.pssupporter.utils.ComponentManager; import com.example.pssupporter.utils.thread.GlobalThreadStore; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; import com.intellij.openapi.actionSystem.AnAction; @@ -19,7 +20,8 @@ public void update(@NotNull AnActionEvent e) { .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(isRunning); - MyTestListPanel.getInstance().setEnabled(!isRunning); + MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); + myTestListPanel.setEnabled(!isRunning); } @Override diff --git a/src/main/java/com/example/pssupporter/ui/MyEditorPanel.java b/src/main/java/com/example/pssupporter/ui/MyEditorPanel.java index d9b8a25..060b67b 100644 --- a/src/main/java/com/example/pssupporter/ui/MyEditorPanel.java +++ b/src/main/java/com/example/pssupporter/ui/MyEditorPanel.java @@ -6,6 +6,10 @@ import com.example.pssupporter.vo.TestData; +import com.intellij.execution.filters.TextConsoleBuilderFactory; +import com.intellij.execution.ui.ConsoleView; +import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.openapi.project.Project; import com.intellij.ui.JBColor; import com.intellij.ui.components.JBPanel; import com.intellij.ui.components.JBScrollPane; @@ -18,20 +22,24 @@ public class MyEditorPanel extends JBPanel { private final JBTextArea myInputTextArea; private final JBTextArea myOutputTextArea; - private final JBTextArea myLogTextArea; + private final ConsoleView myLogConsoleView; + private final Project project; private final TestData myTestData; - public MyEditorPanel() { - this(new TestData()); + public MyEditorPanel(Project project) { + this(project, new TestData()); } - public MyEditorPanel(TestData myTestData) { + public MyEditorPanel(Project project, TestData myTestData) { this.myTestData = myTestData; this.setName("MyLogPanel"); - this.setLayout(new GridLayout(3, 1)); + this.setLayout(new BorderLayout()); this.setBorder(BorderFactory.createLineBorder(JBColor.DARK_GRAY)); + this.project = project; - myInputTextArea = new JBTextArea(10, 10); + JBPanel inputOutputPanel = new JBPanel(new GridLayout(1, 2)); + + myInputTextArea = new JBTextArea(); myInputTextArea.setText(myTestData.getInput()); JBScrollPane myInputTextScrollPane = new JBScrollPane(myInputTextArea); @@ -39,7 +47,7 @@ public MyEditorPanel(TestData myTestData) { myInputTextScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); myInputTextScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - myOutputTextArea = new JBTextArea(10, 10); + myOutputTextArea = new JBTextArea(); myOutputTextArea.setText(myTestData.getOutput()); JBScrollPane myOutputTextScrollPane = new JBScrollPane(myOutputTextArea); @@ -47,31 +55,39 @@ public MyEditorPanel(TestData myTestData) { myOutputTextScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); myOutputTextScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - myLogTextArea = new JBTextArea(); - myLogTextArea.setEditable(false); - myLogTextArea.setDragEnabled(true); + myLogConsoleView = createConsoleView(); setBorder(BorderFactory.createLineBorder(JBColor.LIGHT_GRAY)); - JBScrollPane myLogScrollPane = new JBScrollPane(myLogTextArea); + JBScrollPane myLogScrollPane = new JBScrollPane(myLogConsoleView.getComponent()); myLogScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(JBColor.DARK_GRAY), "Result")); myLogScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); myLogScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - this.add(myInputTextScrollPane); - this.add(myOutputTextScrollPane); - this.add(myLogScrollPane); + inputOutputPanel.add(myInputTextScrollPane); + inputOutputPanel.add(myOutputTextScrollPane); + + this.add(inputOutputPanel, BorderLayout.NORTH); + this.add(myLogScrollPane, BorderLayout.SOUTH); + // JSplitPane + JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, inputOutputPanel, myLogScrollPane); + splitPane.setDividerSize(1); + splitPane.setResizeWeight(0.3); + add(splitPane, BorderLayout.CENTER); } public TestData getTestData() { myTestData.setInput(myInputTextArea.getText()); myTestData.setOutput(myOutputTextArea.getText()); - myTestData.setResult(myLogTextArea.getText()); return myTestData; } public void setResult(String result) { - myTestData.setResult(result); - myLogTextArea.setText(result); + myLogConsoleView.clear(); + myLogConsoleView.print(result, ConsoleViewContentType.SYSTEM_OUTPUT); + } + + private ConsoleView createConsoleView() { + return TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); } } diff --git a/src/main/java/com/example/pssupporter/ui/MyMainView.java b/src/main/java/com/example/pssupporter/ui/MyMainView.java new file mode 100644 index 0000000..b16337e --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/MyMainView.java @@ -0,0 +1,110 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui; + +import com.example.pssupporter.utils.ComponentManager; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.project.Project; +import com.intellij.ui.components.JBPanel; +import com.intellij.ui.components.JBScrollPane; + +import javax.swing.*; +import java.awt.*; + +public class MyMainView extends JBPanel { + private Project myProject; + private boolean myHorizontal; + private JBPanel myTestPanel; + private MyTestListPanel myTestListPanel; + private JBScrollPane myTestListScrollPane; + private JBPanel myEditorPanel; + + + public MyMainView(Project project, boolean horizontal) { + super(new BorderLayout()); + this.myProject = project; + this.myHorizontal = horizontal; + + setupActionToolbarPanel(); + setupTestListPanel(); + setupEditorPanel(); + setupTestPanel(); + addComponentsToManager(); + } + + /** + * add component in component manager + */ + private void addComponentsToManager() { + ComponentManager.getInstance().addComponent("myTestListPanel", myTestListPanel); + ComponentManager.getInstance().addComponent("myEditorPanel", myEditorPanel); + } + + /** + * implements test panel that includes testList and editor panel. + */ + private void setupTestPanel() { + myTestPanel = new JBPanel(new BorderLayout()); + this.setLayoutBasedOnOrientation(this.myHorizontal, true); + this.add(myTestPanel, BorderLayout.CENTER); + } + + /** + * implements editor panel + */ + private void setupEditorPanel() { + myEditorPanel = new JBPanel(new GridLayout(1, 1)); + } + + /** + * implement test list panel + */ + private void setupTestListPanel() { + myTestListPanel = new MyTestListPanel(this.myProject); + myTestListScrollPane = new JBScrollPane(myTestListPanel); + myTestListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + myTestListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + } + + /** + * implement action panel + */ + private void setupActionToolbarPanel() { + ActionGroup myActionGroup = getActionGroup("myActionGroup"); + MyToolbarPanel myActionToolbarPanel = new MyToolbarPanel(myActionGroup, this); + + this.add(myActionToolbarPanel, BorderLayout.NORTH); + } + + private ActionGroup getActionGroup(String actionGroupId) { + com.intellij.openapi.actionSystem.ActionManager actionManager = com.intellij.openapi.actionSystem.ActionManager.getInstance(); + return (ActionGroup) actionManager.getAction(actionGroupId); + } + + public void setLayoutBasedOnOrientation(boolean horizontal) { + setLayoutBasedOnOrientation(horizontal, false); + } + + private void setLayoutBasedOnOrientation(boolean horizontal, boolean init) { + if (init || this.myHorizontal != horizontal) { + if (horizontal) { + setHorizontalLayout(); + } else { + setVerticalLayout(); + } + this.myHorizontal = horizontal; + } + } + + private void setHorizontalLayout() { + myTestPanel.add(myTestListScrollPane, BorderLayout.WEST); + myTestPanel.add(myEditorPanel, BorderLayout.CENTER); + } + + private void setVerticalLayout() { + myTestPanel.add(myTestListScrollPane, BorderLayout.NORTH); + myTestPanel.add(myEditorPanel, BorderLayout.CENTER); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/MyTestListPanel.java b/src/main/java/com/example/pssupporter/ui/MyTestListPanel.java index dbbb6cb..b13aa52 100644 --- a/src/main/java/com/example/pssupporter/ui/MyTestListPanel.java +++ b/src/main/java/com/example/pssupporter/ui/MyTestListPanel.java @@ -6,6 +6,7 @@ import com.example.pssupporter.utils.ComponentManager; import com.example.pssupporter.vo.TestData; +import com.intellij.openapi.project.Project; import com.intellij.ui.components.JBList; import com.intellij.ui.components.JBPanel; @@ -15,21 +16,18 @@ public class MyTestListPanel extends JBList { - private static final MyTestListPanel myTestListPanel = new MyTestListPanel(); private DefaultListModel myModel; + private Project myProject; - public static MyTestListPanel getInstance() { - return myTestListPanel; - } - - private MyTestListPanel() { + protected MyTestListPanel(Project project) { + this.myProject = project; myModel = new DefaultListModel<>(); setCellRenderer(new MyCellRenderer()); this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); addListSelectionListener((e) -> { - int selectedIndex = myTestListPanel.getSelectedIndex(); + int selectedIndex = this.getSelectedIndex(); if (selectedIndex == -1) { return; @@ -48,11 +46,11 @@ private MyTestListPanel() { } public void addTest() { - myModel.addElement(new MyTestListItem(new MyEditorPanel())); + myModel.addElement(new MyTestListItem(new MyEditorPanel(this.myProject))); } public void addTest(TestData testData) { - myModel.addElement(new MyTestListItem(new MyEditorPanel(testData))); + myModel.addElement(new MyTestListItem(new MyEditorPanel(this.myProject, testData))); } public void removeTest(int index) { diff --git a/src/main/java/com/example/pssupporter/utils/ComponentManager.java b/src/main/java/com/example/pssupporter/utils/ComponentManager.java index d51d24f..98d9add 100644 --- a/src/main/java/com/example/pssupporter/utils/ComponentManager.java +++ b/src/main/java/com/example/pssupporter/utils/ComponentManager.java @@ -31,15 +31,22 @@ public JComponent getComponent(String componentName) { .orElseThrow(() -> new IllegalArgumentException("Not exist component")); } + public T getComponent(String componentName, Class clazz) { + try { + return clazz.cast(Optional.ofNullable(ourComponentMap.get(componentName)) + .orElseThrow(() -> new IllegalArgumentException("Not exist component"))); + } catch (ClassCastException e) { + throw new IllegalArgumentException("Class Type Not Match"); + } + } + public void removeChildrenComponentsByName(String componentName) { JComponent component = getComponent(componentName); removeChildrenComponents(component); } public void removeChildrenComponents(@NotNull JComponent component) { - while (component.getComponentCount() != 0) { - component.remove(0); - } + component.removeAll(); component.repaint(); } } diff --git a/src/main/java/com/example/pssupporter/utils/thread/TestRunningThread.java b/src/main/java/com/example/pssupporter/utils/thread/TestRunningThread.java index 2f2f263..ffcb31b 100644 --- a/src/main/java/com/example/pssupporter/utils/thread/TestRunningThread.java +++ b/src/main/java/com/example/pssupporter/utils/thread/TestRunningThread.java @@ -5,7 +5,6 @@ package com.example.pssupporter.utils.thread; import com.example.pssupporter.ui.MyTestListItem; -import com.example.pssupporter.ui.MyTestListPanel; import com.example.pssupporter.utils.runner.CodeRunner; import com.example.pssupporter.utils.runner.dto.CodeRunnerDTO; import com.example.pssupporter.vo.TestData; @@ -28,7 +27,6 @@ public TestRunningThread(String myFilePath, CodeRunner myCodeRunner, MyTestListI public void run() { super.run(); myTestListItem.setStatus(TestStatus.RUNNING); - MyTestListPanel.getInstance().repaint(); String input = myTestData.getInput(); String output = myTestData.getOutput(); @@ -43,13 +41,11 @@ public void run() { } myTestListItem.getMyEditorPanel().setResult(result); - MyTestListPanel.getInstance().repaint(); } @Override public void interrupt() { myTestListItem.setStatus(TestStatus.STOP); - MyTestListPanel.getInstance().repaint(); super.interrupt(); } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 5d68a60..35ae3a6 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -42,12 +42,13 @@ Read more: https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html --> com.intellij.modules.platform com.intellij.modules.java + org.jetbrains.plugins.terminal + doNotActivateOnStart="true" anchor="bottom" icon="/icons/pluginIcon.svg" canCloseContents="false"/> diff --git a/src/test/java/com/example/pssupporter/utils/ComponentManagerTest.java b/src/test/java/com/example/pssupporter/utils/ComponentManagerTest.java index 92c2d57..1b8cc90 100644 --- a/src/test/java/com/example/pssupporter/utils/ComponentManagerTest.java +++ b/src/test/java/com/example/pssupporter/utils/ComponentManagerTest.java @@ -67,6 +67,12 @@ void overwriteWithTheSameName_Success() { @Nested @DisplayName("[GetComponent]") class GetComponentTest { + private class MockComponent1 extends JComponent{ + + } + private class MockComponent2 extends JComponent{ + + } @Test @DisplayName("Success : Get Component correctly") void getComponent_Success() { @@ -83,6 +89,28 @@ void getComponent_Success() { void throwErrorWhenNameDoesNotExist_Failure() { assertThrows(IllegalArgumentException.class, () -> ComponentManager.getInstance().getComponent("notExistName")); } + + @Test + @DisplayName("Success : Get Component correctly with class parameter") + void getComponentWithClazzParam_Success() { + MockComponent1 mockComponent = new MockComponent1(); + String name = "mockComponent"; + + ComponentManager.getInstance().addComponent(name, mockComponent); + MockComponent1 result = ComponentManager.getInstance().getComponent(name, MockComponent1.class); + assertEquals(mockComponent, result); + assertEquals(mockComponent.getClass(),result.getClass()); + } + + @Test + @DisplayName("Fail : Throw error when component's class does not match") + void throwErrorWhenClassDoesNotExist_Failure() { + MockComponent1 mockComponent = new MockComponent1(); + String name = "mockComponent"; + + ComponentManager.getInstance().addComponent(name, mockComponent); + assertThrows(IllegalArgumentException.class, () -> ComponentManager.getInstance().getComponent(name,MockComponent2.class)); + } } @Nested