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
.model
;
19 import com
.intellij
.execution
.junit2
.TestEvent
;
20 import com
.intellij
.execution
.junit2
.TestProxy
;
21 import com
.intellij
.execution
.junit2
.ui
.properties
.JUnitConsoleProperties
;
22 import com
.intellij
.execution
.testframework
.AbstractTestProxy
;
23 import com
.intellij
.execution
.testframework
.TestTreeView
;
24 import com
.intellij
.execution
.testframework
.ui
.AbstractTestTreeBuilder
;
25 import com
.intellij
.ide
.util
.treeView
.IndexComparator
;
26 import com
.intellij
.ide
.util
.treeView
.NodeDescriptor
;
27 import com
.intellij
.openapi
.diagnostic
.Logger
;
28 import com
.intellij
.openapi
.progress
.ProgressIndicator
;
29 import com
.intellij
.openapi
.progress
.util
.StatusBarProgress
;
30 import org
.jetbrains
.annotations
.NotNull
;
31 import org
.jetbrains
.annotations
.Nullable
;
34 import javax
.swing
.tree
.DefaultMutableTreeNode
;
35 import javax
.swing
.tree
.DefaultTreeModel
;
36 import java
.util
.Collection
;
37 import java
.util
.HashSet
;
38 import java
.util
.List
;
40 public class TestTreeBuilder
extends AbstractTestTreeBuilder
{
41 private static final Logger LOG
= Logger
.getInstance("#com.intellij.execution.junit2.ui.model.TestTreeBuilder");
43 private JUnitRunningModel myModel
;
44 private final JUnitAdapter myListener
= new JUnitAdapter(){
45 private final Collection
<TestProxy
> myNodesToUpdate
= new HashSet
<TestProxy
>();
46 public void onEventsDispatched(final List
<TestEvent
> events
) {
47 for (final TestEvent event
: events
) {
48 final TestProxy testSubtree
= (TestProxy
)event
.getTestSubtree();
49 if (testSubtree
!= null) myNodesToUpdate
.add(testSubtree
);
54 public void doDispose() {
56 myNodesToUpdate
.clear();
59 private void updateTree() {
60 TestProxy parentToUpdate
= null;
61 for (final TestProxy test
: myNodesToUpdate
) {
62 parentToUpdate
= test
.getCommonAncestor(parentToUpdate
);
63 if (parentToUpdate
.getParent() == null) break;
65 final DefaultMutableTreeNode node
= getNodeForElement(parentToUpdate
);
68 myNodesToUpdate
.clear();
73 public TestTreeBuilder(final TestTreeView tree
, final JUnitRunningModel model
, final JUnitConsoleProperties properties
) {
74 this(tree
, new TestTreeStructure(model
.getRoot(), properties
), model
);
77 private TestTreeBuilder(final JTree tree
, final TestTreeStructure treeStructure
, final JUnitRunningModel model
) {
78 treeStructure
.setSpecialNode(new SpecialNode(this, model
));
80 myModel
.addListener(myListener
);
81 init(tree
, new DefaultTreeModel(new DefaultMutableTreeNode(treeStructure
.createDescriptor(model
.getRoot(), null))), treeStructure
, IndexComparator
.INSTANCE
);
85 protected boolean isSmartExpand() {
89 protected boolean isAlwaysShowPlus(final NodeDescriptor nodeDescriptor
) {
93 protected boolean isAutoExpandNode(final NodeDescriptor nodeDescriptor
) {
94 return nodeDescriptor
.getElement() == myModel
.getRoot();
98 public DefaultMutableTreeNode
ensureTestVisible(final TestProxy test
) {
99 DefaultMutableTreeNode node
= getNodeForElement(test
);
101 if (node
.getParent() != null) {
102 expandNodeChildren((DefaultMutableTreeNode
) node
.getParent());
103 node
= getNodeForElement(test
);
107 final AbstractTestProxy
[] parents
= test
.getPathFromRoot();
109 for (final AbstractTestProxy parent
: parents
) {
110 buildNodeForElement(parent
);
111 node
= getNodeForElement(parent
);
113 expandNodeChildren(node
);
120 protected ProgressIndicator
createProgressIndicator() {
121 return new StatusBarProgress();