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.
17 package com
.intellij
.execution
.junit2
.ui
;
19 import com
.intellij
.execution
.ExecutionBundle
;
20 import com
.intellij
.execution
.configurations
.ConfigurationPerRunnerSettings
;
21 import com
.intellij
.execution
.configurations
.RunnerSettings
;
22 import com
.intellij
.execution
.junit2
.TestProxy
;
23 import com
.intellij
.execution
.junit2
.ui
.actions
.JUnitToolbarPanel
;
24 import com
.intellij
.execution
.junit2
.ui
.model
.JUnitAdapter
;
25 import com
.intellij
.execution
.junit2
.ui
.model
.JUnitRunningModel
;
26 import com
.intellij
.execution
.junit2
.ui
.properties
.JUnitConsoleProperties
;
27 import com
.intellij
.execution
.process
.ProcessAdapter
;
28 import com
.intellij
.execution
.process
.ProcessEvent
;
29 import com
.intellij
.execution
.process
.ProcessHandler
;
30 import com
.intellij
.execution
.testframework
.PoolOfTestIcons
;
31 import com
.intellij
.execution
.testframework
.Printer
;
32 import com
.intellij
.execution
.testframework
.TestTreeView
;
33 import com
.intellij
.execution
.testframework
.ToolbarPanel
;
34 import com
.intellij
.execution
.testframework
.ui
.TestResultsPanel
;
35 import com
.intellij
.execution
.testframework
.ui
.TestStatusLine
;
36 import com
.intellij
.execution
.testframework
.ui
.TestsOutputConsolePrinter
;
37 import com
.intellij
.openapi
.Disposable
;
38 import com
.intellij
.openapi
.actionSystem
.AnAction
;
39 import com
.intellij
.openapi
.application
.ApplicationManager
;
40 import com
.intellij
.openapi
.application
.ModalityState
;
41 import com
.intellij
.ui
.SimpleColoredComponent
;
42 import com
.intellij
.ui
.SimpleTextAttributes
;
43 import com
.intellij
.ui
.treeStructure
.Tree
;
44 import com
.intellij
.util
.Alarm
;
45 import org
.jetbrains
.annotations
.NonNls
;
48 import javax
.swing
.tree
.DefaultMutableTreeNode
;
49 import javax
.swing
.tree
.DefaultTreeModel
;
50 import javax
.swing
.tree
.TreeCellRenderer
;
52 import java
.beans
.PropertyChangeEvent
;
53 import java
.beans
.PropertyChangeListener
;
55 class ConsolePanel
extends TestResultsPanel
implements Disposable
{
56 @NonNls private static final String PROPORTION_PROPERTY
= "test_tree_console_proprtion";
57 private static final float DEFAULT_PROPORTION
= 0.2f
;
59 private JUnitStatusLine myStatusLine
;
60 private StatisticsPanel myStatisticsPanel
;
61 private TestTreeView myTreeView
;
62 private TestsOutputConsolePrinter myPrinter
;
63 private StartingProgress myStartingProgress
;
65 public ConsolePanel(final JComponent console
,
66 final TestsOutputConsolePrinter printer
,
67 final JUnitConsoleProperties properties
,
68 final RunnerSettings runnerSettings
,
69 final ConfigurationPerRunnerSettings configurationSettings
, AnAction
[] consoleActions
) {
70 super(console
, consoleActions
, properties
, runnerSettings
, configurationSettings
, PROPORTION_PROPERTY
, DEFAULT_PROPORTION
);
74 public void initUI() {
76 myStartingProgress
= new StartingProgress(myTreeView
);
79 protected JComponent
createStatisticsPanel() {
80 myStatisticsPanel
= new StatisticsPanel();
81 return myStatisticsPanel
;
84 protected ToolbarPanel
createToolbarPanel() {
85 return new JUnitToolbarPanel(myProperties
, myRunnerSettings
, myConfigurationSettings
, this);
88 protected TestStatusLine
createStatusLine() {
89 myStatusLine
= new JUnitStatusLine();
93 protected JComponent
createTestTreeView() {
94 myTreeView
= new JUnitTestTreeView();
98 public void onProcessStarted(final ProcessHandler process
) {
99 myStatusLine
.onProcessStarted(process
);
100 if (myStartingProgress
== null) return;
101 myStartingProgress
.start(process
);
104 public void setModel(final JUnitRunningModel model
) {
105 stopStartingProgress();
106 final TestTreeView treeView
= model
.getTreeView();
107 treeView
.setLargeModel(true);
108 setLeftComponent(treeView
);
109 myToolbarPanel
.setModel(model
);
110 myStatusLine
.setModel(model
);
112 model
.addListener(new JUnitAdapter() {
114 public void onTestSelected(final TestProxy test
) {
115 if (myPrinter
!= null) myPrinter
.updateOnTestSelected(test
);
118 myStatisticsPanel
.attachTo(model
);
121 private void stopStartingProgress() {
122 if (myStartingProgress
!= null) myStartingProgress
.doStop();
123 myStartingProgress
= null;
126 public TestTreeView
getTreeView() {
130 public Printer
getPrinter() {
134 public void dispose() {
135 stopStartingProgress();
139 public void attachToModel(final JUnitRunningModel model
) {
140 getTreeView().attachToModel(model
);
143 private static class StartingProgress
implements Runnable
{
144 private final Alarm myAlarm
= new Alarm();
145 private final Tree myTree
;
146 private final DefaultTreeModel myModel
;
147 private final DefaultMutableTreeNode myRootNode
= new DefaultMutableTreeNode();
148 private boolean myStarted
= false;
149 private boolean myStopped
= false;
150 private final SimpleColoredComponent myStartingLabel
;
151 private ProcessHandler myProcess
;
152 private long myStartedAt
= System
.currentTimeMillis();
153 private final ProcessAdapter myProcessListener
= new ProcessAdapter() {
154 public void processTerminated(ProcessEvent event
) {
155 ApplicationManager
.getApplication().invokeLater(new Runnable() {
163 public StartingProgress(final Tree tree
) {
165 myModel
= new DefaultTreeModel(myRootNode
);
166 myTree
.setModel(myModel
);
167 myStartingLabel
= new SimpleColoredComponent();
169 //myStartingLabel.setBackground(UIManager.getColor("Tree.background"));
170 myTree
.setCellRenderer(new TreeCellRenderer() {
171 public Component
getTreeCellRendererComponent(final JTree tree
, final Object value
,
172 final boolean selected
, final boolean expanded
,
173 final boolean leaf
, final int row
, final boolean hasFocus
) {
174 myStartingLabel
.clear();
175 myStartingLabel
.setIcon(PoolOfTestIcons
.LOADING_ICON
);
176 myStartingLabel
.append(getProgressText(), SimpleTextAttributes
.REGULAR_ATTRIBUTES
);
177 if (!myStarted
) postRepaint();
178 return myStartingLabel
;
181 myTree
.addPropertyChangeListener(JTree
.TREE_MODEL_PROPERTY
, new PropertyChangeListener() {
182 public void propertyChange(final PropertyChangeEvent evt
) {
183 myTree
.removePropertyChangeListener(JTree
.TREE_MODEL_PROPERTY
, this);
189 private void doStop() {
191 myModel
.nodeChanged(myRootNode
);
192 myAlarm
.cancelAllRequests();
193 if (myProcess
!= null) myProcess
.removeProcessListener(myProcessListener
);
198 myModel
.nodeChanged(myRootNode
);
202 private void postRepaint() {
203 if (myStopped
) return;
205 myAlarm
.cancelAllRequests();
206 myAlarm
.addRequest(this, 300, ModalityState
.NON_MODAL
);
209 public void start(final ProcessHandler process
) {
210 if (process
.isProcessTerminated()) return;
212 myStartedAt
= System
.currentTimeMillis();
213 process
.addProcessListener(myProcessListener
);
216 private String
getProgressText() {
217 if (myStopped
) return ExecutionBundle
.message("test.not.started.progress.text");
218 final long millis
= System
.currentTimeMillis() - myStartedAt
;
219 final String phaseName
= myProcess
== null ? ExecutionBundle
.message("starting.jvm.progress.text") : ExecutionBundle
.message("instantiating.tests.progress.text");
220 return phaseName
+ Formatters
.printMinSec(millis
);