Permalink
Browse files

Issue #32. Change ToolWindow icon relatively to the TestRunner state

  • Loading branch information...
1 parent df14618 commit e19030e6cc891cf988d21f57c1734006a5c0e3ee @athieriot athieriot committed Jun 15, 2011
@@ -22,6 +22,7 @@
package org.infinitest.intellij.idea.facet;
import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.wm.ToolWindowManager;
import org.infinitest.intellij.idea.IdeaCompilationNotifier;
import org.infinitest.intellij.idea.IdeaModuleSettings;
import org.infinitest.intellij.idea.IdeaSourceNavigator;
@@ -117,7 +118,8 @@ public InfinitestLauncher createLauncher()
InfinitestLauncherImpl launcher = new InfinitestLauncherImpl(new IdeaModuleSettings(module),
new IdeaToolWindowRegistry(module.getProject()), new IdeaCompilationNotifier(
module.getProject()), new IdeaSourceNavigator(module.getProject()),
- FileEditorManager.getInstance(module.getProject()));
+ FileEditorManager.getInstance(module.getProject()),
+ ToolWindowManager.getInstance(module.getProject()));
if (isScmUpdateEnabled())
{
@@ -31,12 +31,20 @@
public class IdeaWindowHelper
{
+ public static final String WAITING_ICON_PATH = "/infinitest-waiting.png";
+
+ public static final String RUNNING_ICON_PATH = "/infinitest.png";
+
+ public static final String SUCCESS_ICON_PATH = "/infinitest-success.png";
+
+ public static final String FAILURE_ICON_PATH = "/infinitest-failure.png";
+
@SuppressWarnings({ "deprecation" })
public void addPanelToWindow(JPanel rootPanel, ToolWindow window)
{
ContentFactory contentFactory = PeerFactory.getInstance().getContentFactory();
Content content = contentFactory.createContent(rootPanel, "Infinitest", false);
window.getContentManager().addContent(content);
- window.setIcon(IconLoader.getIcon("/infinitest.png"));
+ window.setIcon(IconLoader.getIcon(WAITING_ICON_PATH));
}
}
@@ -44,4 +44,24 @@ public void testRunCompleted()
}
}
}
+
+ public void testRunSucceed()
+ {
+ // nothing to do here
+ }
+
+ public void testRunFailed()
+ {
+ // nothing to do here
+ }
+
+ public void testRunStarted()
+ {
+ // nothing to do here
+ }
+
+ public void testRunWaiting()
+ {
+ // nothing to do here
+ }
}
@@ -28,6 +28,7 @@
import javax.swing.JPanel;
import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.wm.ToolWindowManager;
import org.apache.log4j.Logger;
import org.infinitest.InfinitestCoreBuilder;
import org.infinitest.intellij.CompilationNotifier;
@@ -52,10 +53,11 @@
private IdeaCompilationListener testControl;
private final GreenHookListener greenHookListener;
private final FileEditorListener fileEditorListener;
+ private final ToolWindowListener toolWindowListener;
public InfinitestLauncherImpl(ModuleSettings moduleSettings, ToolWindowRegistry toolWindowRegistry,
CompilationNotifier compilationNotifier, SourceNavigator navigator,
- FileEditorManager fileEditorManager)
+ FileEditorManager fileEditorManager, ToolWindowManager toolWindowManager)
{
this.moduleSettings = moduleSettings;
this.toolWindowRegistry = toolWindowRegistry;
@@ -64,6 +66,7 @@ public InfinitestLauncherImpl(ModuleSettings moduleSettings, ToolWindowRegistry
this.greenHookListener = new GreenHookListener();
this.infinitestBuilder = createInfinitestBuilder();
this.fileEditorListener = new FileEditorListener(fileEditorManager);
+ this.toolWindowListener = new ToolWindowListener(toolWindowManager, toolWindowId());
}
public void launchInfinitest()
@@ -77,6 +80,7 @@ public void launchInfinitest()
addScmGreenHookListener();
addResultClickListener();
addFileEditorListener();
+ addToolWindowListener();
}
private void addResultClickListener()
@@ -135,4 +139,9 @@ private void addFileEditorListener()
{
infinitestBuilder.addPresenterListener(fileEditorListener);
}
+
+ private void addToolWindowListener()
+ {
+ infinitestBuilder.addPresenterListener(toolWindowListener);
+ }
}
@@ -89,6 +89,7 @@ private void indicateWaitingForChanges()
view.setProgressBarColor(BLACK);
view.setMaximumProgress(1);
view.setProgress(1);
+ onWait();
}
public void coreStatusChanged(CoreStatus oldStatus, final CoreStatus newStatus)
@@ -120,6 +121,7 @@ private void updateView(CoreStatus status)
{
case RUNNING:
view.setProgressBarColor(UNKNOWN_COLOR);
+ onRun();
break;
case FAILING:
view.setProgressBarColor(FAILING_COLOR);
@@ -159,10 +161,7 @@ public void reloading()
public void testRunComplete()
{
- for (PresenterListener presenterListener : presenterListeners)
- {
- presenterListener.testRunCompleted();
- }
+ onComplete();
}
public void failureListChanged(Collection<TestEvent> failuresAdded, Collection<TestEvent> failuresRemoved)
@@ -193,4 +192,42 @@ public void addPresenterListener(PresenterListener listener)
this.presenterListeners.add(listener);
}
}
+
+ /*private*/ void onComplete()
+ {
+ for (PresenterListener presenterListener : presenterListeners)
+ {
+ presenterListener.testRunCompleted();
+
+ if(isSuccess())
+ {
+ presenterListener.testRunSucceed();
+ }
+ else
+ {
+ presenterListener.testRunFailed();
+ }
+ }
+ }
+
+ /*private*/ boolean isSuccess()
+ {
+ return !resultCollector.hasFailures();
+ }
+
+ /*private*/ void onRun()
+ {
+ for (PresenterListener presenterListener : presenterListeners)
+ {
+ presenterListener.testRunStarted();
+ }
+ }
+
+ /*private*/ void onWait()
+ {
+ for (PresenterListener presenterListener : presenterListeners)
+ {
+ presenterListener.testRunWaiting();
+ }
+ }
}
@@ -24,4 +24,12 @@
public interface PresenterListener extends java.util.EventListener
{
void testRunCompleted();
+
+ void testRunSucceed();
+
+ void testRunFailed();
+
+ void testRunStarted();
+
+ void testRunWaiting();
}
@@ -0,0 +1,78 @@
+/*
+ * This file is part of Infinitest.
+ *
+ * Copyright (C) 2010
+ * "Ben Rady" <benrady@gmail.com>,
+ * "Rod Coffin" <rfciii@gmail.com>,
+ * "Ryan Breidenbach" <ryan.breidenbach@gmail.com>, et al.
+ *
+ * Infinitest is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Infinitest is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Infinitest. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.infinitest.intellij.plugin.launcher;
+
+import com.intellij.openapi.util.IconLoader;
+import com.intellij.openapi.wm.ToolWindow;
+import com.intellij.openapi.wm.ToolWindowManager;
+import org.infinitest.intellij.idea.window.IdeaWindowHelper;
+
+import javax.swing.Icon;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: aurelien
+ * Date: 09/06/11
+ * Time: 21:26
+ */
+public class ToolWindowListener implements PresenterListener
+{
+ ToolWindowManager toolWindowManager;
+ String toolWindowId;
+
+ public ToolWindowListener(ToolWindowManager toolWindowManager, String toolWindowId)
+ {
+ this.toolWindowManager = toolWindowManager;
+ this.toolWindowId = toolWindowId;
+ }
+
+ public void testRunCompleted()
+ {
+ // nothing to do here
+ }
+
+ public void testRunSucceed()
+ {
+ editToolWindowIcon(IconLoader.getIcon(IdeaWindowHelper.SUCCESS_ICON_PATH));
+ }
+
+ public void testRunFailed()
+ {
+ editToolWindowIcon(IconLoader.getIcon(IdeaWindowHelper.FAILURE_ICON_PATH));
+ }
+
+ public void testRunStarted()
+ {
+ editToolWindowIcon(IconLoader.getIcon(IdeaWindowHelper.RUNNING_ICON_PATH));
+ }
+
+ public void testRunWaiting()
+ {
+ editToolWindowIcon(IconLoader.getIcon(IdeaWindowHelper.WAITING_ICON_PATH));
+ }
+
+ private void editToolWindowIcon(Icon icon)
+ {
+ ToolWindow toolWindow = toolWindowManager.getToolWindow(toolWindowId);
+ toolWindow.setIcon(icon);
+ }
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -28,6 +28,7 @@
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.wm.ToolWindowManager;
import org.infinitest.intellij.plugin.launcher.InfinitestLauncher;
import org.infinitest.intellij.plugin.launcher.InfinitestLauncherImpl;
import org.junit.Before;
@@ -49,9 +50,10 @@ public void shouldNameToolWindowAfterModule()
{
ToolWindowRegistry registry = mock(ToolWindowRegistry.class);
FileEditorManager fileEditorManagerMock = mock(FileEditorManager.class);
+ ToolWindowManager toolWindowManagerMock = mock(ToolWindowManager.class);
InfinitestLauncher launcher = new InfinitestLauncherImpl(moduleSettings, registry,
- new FakeCompilationNotifier(), new FakeSourceNavigator(), fileEditorManagerMock);
+ new FakeCompilationNotifier(), new FakeSourceNavigator(), fileEditorManagerMock, toolWindowManagerMock);
launcher.launchInfinitest();
verify(registry).registerToolWindow(Matchers.any(JPanel.class), eq("Infinitest_foo"));
@@ -1,98 +0,0 @@
-/*
- * This file is part of Infinitest.
- *
- * Copyright (C) 2010
- * "Ben Rady" <benrady@gmail.com>,
- * "Rod Coffin" <rfciii@gmail.com>,
- * "Ryan Breidenbach" <ryan.breidenbach@gmail.com>, et al.
- *
- * Infinitest is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Infinitest is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Infinitest. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.infinitest.intellij.plugin;
-
-import org.infinitest.InfinitestCore;
-import org.infinitest.ResultCollector;
-import org.infinitest.TestControl;
-import org.infinitest.intellij.FakeInfinitestAnnotator;
-import org.infinitest.intellij.plugin.launcher.InfinitestPresenter;
-import org.infinitest.intellij.plugin.launcher.PresenterListener;
-import org.infinitest.intellij.plugin.swingui.InfinitestView;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.mockito.Mockito.*;
-
-public class WhenTestRunCompleted
-{
-
- private InfinitestView mockView;
- private InfinitestPresenter presenter;
- private InfinitestCore mockCore;
- private PresenterListener mockPresenterListener;
- private PresenterListener mockPresenterListenerBis;
-
- @Before
- public void inContext()
- {
- mockView = mock(InfinitestView.class);
- mockCore = mock(InfinitestCore.class);
- mockPresenterListener = mock(PresenterListener.class);
- mockPresenterListenerBis = mock(PresenterListener.class);
-
- TestControl mockTestControl = mock(TestControl.class);
-
- presenter = new InfinitestPresenter(new ResultCollector(mockCore), mockCore, mockView, mockTestControl,
- new FakeInfinitestAnnotator());
- }
-
- @Test
- public void shouldNotCallPresenterListener()
- {
- presenter.testRunComplete();
-
- verify(mockPresenterListener, never()).testRunCompleted();
- }
-
- @Test
- public void shouldDoNothingWhenNull()
- {
- presenter.addPresenterListener(null);
-
- presenter.testRunComplete();
-
- verify(mockPresenterListener, never()).testRunCompleted();
- }
-
- @Test
- public void shouldCallPresenterListener()
- {
- presenter.addPresenterListener(mockPresenterListener);
-
- presenter.testRunComplete();
-
- verify(mockPresenterListener).testRunCompleted();
- }
-
- @Test
- public void shouldCallTwoPresenterListener()
- {
- presenter.addPresenterListener(mockPresenterListener);
- presenter.addPresenterListener(mockPresenterListenerBis);
-
- presenter.testRunComplete();
-
- verify(mockPresenterListener).testRunCompleted();
- verify(mockPresenterListenerBis).testRunCompleted();
- }
-}
Oops, something went wrong.

0 comments on commit e19030e

Please sign in to comment.