fixed [IDEADEV-41319] test runner: do not show green balloon and green progress bar...
[fedora-idea.git] / platform / testRunner / src / com / intellij / execution / testframework / TestTreeView.java
blob71e5f47f693eef240aff3805e5c691fb7ca23610
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.
18 * User: anna
19 * Date: 25-May-2007
21 package com.intellij.execution.testframework;
23 import com.intellij.openapi.Disposable;
24 import com.intellij.openapi.actionSystem.ActionPlaces;
25 import com.intellij.openapi.actionSystem.DataProvider;
26 import com.intellij.openapi.actionSystem.IdeActions;
27 import com.intellij.openapi.util.Disposer;
28 import com.intellij.ui.PopupHandler;
29 import com.intellij.ui.TreeSpeedSearch;
30 import com.intellij.ui.TreeToolTipHandler;
31 import com.intellij.ui.treeStructure.Tree;
32 import com.intellij.util.EditSourceOnDoubleClickHandler;
33 import com.intellij.util.containers.Convertor;
34 import com.intellij.util.ui.tree.TreeUtil;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
38 import javax.swing.plaf.TreeUI;
39 import javax.swing.tree.*;
41 public abstract class TestTreeView extends Tree implements DataProvider {
42 private TestFrameworkRunningModel myModel;
44 protected abstract TreeCellRenderer getRenderer(TestConsoleProperties properties);
46 public abstract AbstractTestProxy getSelectedTest(@NotNull TreePath selectionPath);
48 @Nullable
49 public AbstractTestProxy getSelectedTest() {
50 final TreePath selectionPath = getSelectionPath();
51 return selectionPath != null ? getSelectedTest(selectionPath) : null;
54 public void attachToModel(final TestFrameworkRunningModel model) {
55 setModel(new DefaultTreeModel(new DefaultMutableTreeNode(model.getRoot())));
56 getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
57 myModel = model;
58 Disposer.register(myModel, new Disposable() {
59 public void dispose() {
60 setModel(null);
61 myModel = null;
63 });
64 installHandlers();
65 setCellRenderer(getRenderer(myModel.getProperties()));
68 public void setUI(final TreeUI ui) {
69 super.setUI(ui);
70 final int fontHeight = getFontMetrics(getFont()).getHeight();
71 final int iconHeight = PoolOfTestIcons.PASSED_ICON.getIconHeight();
72 setRowHeight(Math.max(fontHeight, iconHeight) + 2);
73 setLargeModel(true);
76 public Object getData(final String dataId) {
77 final TreePath selectionPath = getSelectionPath();
78 if (selectionPath == null) return null;
79 final AbstractTestProxy testProxy = getSelectedTest(selectionPath);
80 if (testProxy == null) return null;
81 return TestsUIUtil.getData(testProxy, dataId, myModel);
84 protected void installHandlers() {
85 EditSourceOnDoubleClickHandler.install(this);
86 new TreeSpeedSearch(this, new Convertor<TreePath, String>() {
87 public String convert(final TreePath path) {
88 final AbstractTestProxy testProxy = getSelectedTest(path);
89 if (testProxy == null) return null;
90 return testProxy.getName();
92 });
93 TreeToolTipHandler.install(this);
94 TreeUtil.installActions(this);
95 PopupHandler.installPopupHandler(this, IdeActions.GROUP_TESTTREE_POPUP, ActionPlaces.TESTTREE_VIEW_POPUP);