ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / smRunner / src / com / intellij / execution / testframework / sm / runner / ui / SMTRunnerNotificationsHandler.java
blob6d76efed1d8c5981fadd15b1d6ecf1ab48c62af4
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.execution.testframework.sm.runner.ui;
18 import com.intellij.execution.testframework.TestConsoleProperties;
19 import com.intellij.execution.testframework.sm.SMTestsRunnerBundle;
20 import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter;
21 import com.intellij.execution.testframework.sm.runner.SMTestProxy;
22 import com.intellij.execution.testframework.sm.runner.states.TestStateInfo;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.ui.MessageType;
25 import com.intellij.openapi.util.Comparing;
26 import com.intellij.openapi.wm.ToolWindowId;
27 import com.intellij.openapi.wm.ToolWindowManager;
28 import org.jetbrains.annotations.NotNull;
30 import javax.swing.*;
32 /**
33 * @author Roman Chernyatchik
35 public class SMTRunnerNotificationsHandler extends SMTRunnerEventsAdapter {
36 private final TestConsoleProperties myConsoleProperties;
37 //private boolean myFirstDefectWasFound;
39 public SMTRunnerNotificationsHandler(@NotNull final TestConsoleProperties consoleProperties) {
40 myConsoleProperties = consoleProperties;
43 public void onTestingStarted(@NotNull SMTestProxy testsRoot) {
44 //myFirstDefectWasFound = false;
47 public void onTestingFinished(@NotNull SMTestProxy testsRoot) {
48 final String msg;
49 final MessageType type;
51 final TestStateInfo.Magnitude magnitude = testsRoot.getMagnitudeInfo();
52 //noinspection EnumSwitchStatementWhichMissesCases
53 switch (magnitude) {
54 case SKIPPED_INDEX:
55 case IGNORED_INDEX:
56 msg = SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.skipped");
57 type = MessageType.WARNING;
58 break;
60 case NOT_RUN_INDEX:
61 msg = SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.not.run");
62 type = MessageType.WARNING;
63 break;
65 case FAILED_INDEX:
66 case ERROR_INDEX:
67 msg = SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.failed");
68 type = MessageType.ERROR;
69 break;
70 case COMPLETE_INDEX:
71 if (testsRoot.getChildren().size() == 0) {
72 msg = SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.no.tests.were.found");
73 type = MessageType.ERROR;
74 break;
76 // else same as: PASSED_INDEX
77 case PASSED_INDEX:
78 msg = SMTestsRunnerBundle.message("sm.test.runner.notifications.tests.passed");
79 type = MessageType.INFO;
80 break;
82 default:
83 msg = null;
84 type = null;
87 if (msg != null) {
88 notify(msg, type);
92 public void onTestFailed(@NotNull SMTestProxy test) {
93 // TODO : if user doesn't close this balloon then user will not see 'tests failed' balloon
94 //if (!myFirstDefectWasFound) {
95 // // notify about defect on the fly
96 // if (test.isDefect()) {
97 // final TestStateInfo.Magnitude magnitude = test.getMagnitudeInfo();
98 // //noinspection EnumSwitchStatementWhichMissesCases
99 // switch (magnitude) {
100 // case FAILED_INDEX:
101 // case ERROR_INDEX:
102 // myFirstDefectWasFound = true;
103 // notify("Tests will fail", MessageType.WARNING);
104 // break;
105 // default:
106 // // Do nothing
107 // }
108 // }
112 private void notify(final String msg, final MessageType type) {
113 SwingUtilities.invokeLater(new Runnable() {
114 public void run() {
115 final Project project = myConsoleProperties.getProject();
116 if ( project.isDisposed()) {
117 return;
120 if (myConsoleProperties == null) {
121 return;
123 final String testRunDebugId = myConsoleProperties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN;
124 final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
125 if (!Comparing.strEqual(toolWindowManager.getActiveToolWindowId(), testRunDebugId)) {
126 toolWindowManager.notifyByBalloon(testRunDebugId, type, msg, null, null);