From 3ca46492cc50c38fb4a04a86ed491292014f8acf Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 6 Apr 2015 15:45:07 +0200 Subject: [PATCH] testRunner: make action to navigate from statistics panel to test tree available for all runners --- .../sm/runner/SMTRunnerTreeStructure.java | 17 ++--------- .../runner/ui/statistics/StatisticsPanel.java | 7 ++++- .../testframework/TestTreeViewStructure.java | 30 +++++++++++++++++++ .../actions/SelectInTreeAction.java | 4 +-- .../testframework}/actions/TestContext.java | 22 +++++++------- plugins/junit/src/META-INF/plugin.xml | 5 ---- .../execution/junit2/ui/StatisticsPanel.java | 2 +- .../junit2/ui/model/JUnitRunningModel.java | 4 --- .../junit2/ui/model/TestTreeStructure.java | 19 +++--------- .../testng/model/TestTreeStructure.java | 19 ++---------- resources/src/idea/RichPlatformActions.xml | 2 ++ 11 files changed, 63 insertions(+), 68 deletions(-) create mode 100644 platform/testRunner/src/com/intellij/execution/testframework/TestTreeViewStructure.java rename {plugins/junit/src/com/intellij/execution/junit2/ui => platform/testRunner/src/com/intellij/execution/testframework}/actions/SelectInTreeAction.java (90%) rename {plugins/junit/src/com/intellij/execution/junit2/ui => platform/testRunner/src/com/intellij/execution/testframework}/actions/TestContext.java (59%) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerTreeStructure.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerTreeStructure.java index 7d15140c8de5..76988236b1cf 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerTreeStructure.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerTreeStructure.java @@ -16,8 +16,7 @@ package com.intellij.execution.testframework.sm.runner; import com.intellij.execution.testframework.AbstractTestProxy; -import com.intellij.execution.testframework.Filter; -import com.intellij.ide.util.treeView.AbstractTreeStructure; +import com.intellij.execution.testframework.TestTreeViewStructure; import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; @@ -27,16 +26,14 @@ import java.util.List; /** * @author: Roman Chernyatchik */ -public class SMTRunnerTreeStructure extends AbstractTreeStructure +public class SMTRunnerTreeStructure extends TestTreeViewStructure { private final Object myRootNode; - private Filter myTestNodesFilter; private final Project myProject; public SMTRunnerTreeStructure(final Project project, final Object rootNode) { myProject = project; myRootNode = rootNode; - myTestNodesFilter = Filter.NO_FILTER; } @Override @@ -58,14 +55,10 @@ public class SMTRunnerTreeStructure extends AbstractTreeStructure (NodeDescriptor)parentDesc); } - public Filter getFilter() { - return myTestNodesFilter; - } - @Override public Object[] getChildElements(final Object element) { final List results = - ((SMTestProxy)element).getChildren(myTestNodesFilter); + ((SMTestProxy)element).getChildren(getFilter()); return results.toArray(new AbstractTestProxy[results.size()]); } @@ -80,8 +73,4 @@ public class SMTRunnerTreeStructure extends AbstractTreeStructure public Object getRootElement() { return myRootNode; } - - public void setFilter(final Filter nodesFilter) { - myTestNodesFilter = nodesFilter; - } } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsPanel.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsPanel.java index 55de358b5e89..564a26ce29e8 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsPanel.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/statistics/StatisticsPanel.java @@ -17,6 +17,7 @@ package com.intellij.execution.testframework.sm.runner.ui.statistics; import com.intellij.execution.testframework.TestFrameworkRunningModel; import com.intellij.execution.testframework.TestsUIUtil; +import com.intellij.execution.testframework.actions.TestContext; import com.intellij.execution.testframework.sm.SMRunnerUtil; import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter; import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsListener; @@ -163,7 +164,11 @@ public class StatisticsPanel implements DataProvider { if (SM_TEST_RUNNER_STATISTICS.is(dataId)) { return this; } - return TestsUIUtil.getData(getSelectedItem(), dataId, myFrameworkRunningModel); + final SMTestProxy selectedItem = getSelectedItem(); + if (TestContext.DATA_KEY.is(dataId)) { + return new TestContext(myFrameworkRunningModel, selectedItem); + } + return TestsUIUtil.getData(selectedItem, dataId, myFrameworkRunningModel); } /** diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestTreeViewStructure.java b/platform/testRunner/src/com/intellij/execution/testframework/TestTreeViewStructure.java new file mode 100644 index 000000000000..dbb7084b196e --- /dev/null +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestTreeViewStructure.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.testframework; + +import com.intellij.ide.util.treeView.AbstractTreeStructure; + +public abstract class TestTreeViewStructure extends AbstractTreeStructure { + private Filter myTestNodesFilter = Filter.NO_FILTER; + + public Filter getFilter() { + return myTestNodesFilter; + } + + public void setFilter(final Filter nodesFilter) { + myTestNodesFilter = nodesFilter; + } +} diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/actions/SelectInTreeAction.java b/platform/testRunner/src/com/intellij/execution/testframework/actions/SelectInTreeAction.java similarity index 90% rename from plugins/junit/src/com/intellij/execution/junit2/ui/actions/SelectInTreeAction.java rename to platform/testRunner/src/com/intellij/execution/testframework/actions/SelectInTreeAction.java index 5004ebe04bee..41e0f779dd61 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/actions/SelectInTreeAction.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/actions/SelectInTreeAction.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.intellij.execution.junit2.ui.actions; +package com.intellij.execution.testframework.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -24,7 +24,7 @@ public class SelectInTreeAction extends AnAction { final TestContext context = TestContext.from(e); if (!shouldBeEnabled(context)) return; - context.getModel().selectTest(context.getSelection()); + context.getModel().getTreeBuilder().select(context.getSelection()); } public void update(final AnActionEvent e) { diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/actions/TestContext.java b/platform/testRunner/src/com/intellij/execution/testframework/actions/TestContext.java similarity index 59% rename from plugins/junit/src/com/intellij/execution/junit2/ui/actions/TestContext.java rename to platform/testRunner/src/com/intellij/execution/testframework/actions/TestContext.java index bcbfe725d668..eb90db709617 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/actions/TestContext.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/actions/TestContext.java @@ -14,30 +14,31 @@ * limitations under the License. */ -package com.intellij.execution.junit2.ui.actions; +package com.intellij.execution.testframework.actions; -import com.intellij.execution.junit2.TestProxy; -import com.intellij.execution.junit2.ui.model.JUnitRunningModel; +import com.intellij.execution.testframework.AbstractTestProxy; +import com.intellij.execution.testframework.TestFrameworkRunningModel; +import com.intellij.execution.testframework.TestTreeViewStructure; +import com.intellij.ide.util.treeView.AbstractTreeStructure; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataKey; public class TestContext { public static final DataKey DATA_KEY = DataKey.create("JUNIT_CONTEXT"); - @Deprecated public static final String TEST_CONTEXT = DATA_KEY.getName(); - private final JUnitRunningModel myModel; - private final TestProxy mySelection; + private final TestFrameworkRunningModel myModel; + private final AbstractTestProxy mySelection; - public TestContext(final JUnitRunningModel model, final TestProxy selection) { + public TestContext(final TestFrameworkRunningModel model, final AbstractTestProxy selection) { myModel = model; mySelection = selection; } - public JUnitRunningModel getModel() { + public TestFrameworkRunningModel getModel() { return myModel; } - public TestProxy getSelection() { + public AbstractTestProxy getSelection() { return mySelection; } @@ -46,7 +47,8 @@ public class TestContext { } public boolean treeContainsSelection() { - return getModel().hasInTree(getSelection()); + final AbstractTreeStructure structure = getModel().getTreeBuilder().getTreeStructure(); + return structure instanceof TestTreeViewStructure && ((TestTreeViewStructure)structure).getFilter().shouldAccept(getSelection()); } public static TestContext from(final AnActionEvent event) { diff --git a/plugins/junit/src/META-INF/plugin.xml b/plugins/junit/src/META-INF/plugin.xml index 6f69d152919f..3aa3954d5691 100644 --- a/plugins/junit/src/META-INF/plugin.xml +++ b/plugins/junit/src/META-INF/plugin.xml @@ -63,11 +63,6 @@ - - - - - diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java index d19e488f4210..ca732c129b1b 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java @@ -18,7 +18,7 @@ package com.intellij.execution.junit2.ui; import com.intellij.execution.junit2.TestProxy; import com.intellij.execution.junit2.events.TestEvent; -import com.intellij.execution.junit2.ui.actions.TestContext; +import com.intellij.execution.testframework.actions.TestContext; import com.intellij.execution.junit2.ui.model.JUnitAdapter; import com.intellij.execution.junit2.ui.model.JUnitRunningModel; import com.intellij.execution.testframework.TestsUIUtil; diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitRunningModel.java b/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitRunningModel.java index 0e4ba2f9082a..5e1049c7c856 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitRunningModel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitRunningModel.java @@ -176,10 +176,6 @@ public class JUnitRunningModel implements TestFrameworkRunningModel { return TreeUtil.getPath((TreeNode) myTreeView.getModel().getRoot(), node); } - public boolean hasInTree(final AbstractTestProxy test) { - return getStructure().getFilter().shouldAccept(test); - } - public JUnitConfiguration getConfiguration() { return myProperties.getConfiguration(); } diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/model/TestTreeStructure.java b/plugins/junit/src/com/intellij/execution/junit2/ui/model/TestTreeStructure.java index aabe03db3050..1980f852f82f 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/model/TestTreeStructure.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/model/TestTreeStructure.java @@ -16,29 +16,18 @@ package com.intellij.execution.junit2.ui.model; -import com.intellij.execution.testframework.Filter; import com.intellij.execution.junit2.TestProxy; -import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties; -import com.intellij.ide.util.treeView.AbstractTreeStructure; +import com.intellij.execution.testframework.AbstractTestProxy; +import com.intellij.execution.testframework.TestTreeViewStructure; import com.intellij.ide.util.treeView.NodeDescriptor; import org.jetbrains.annotations.NotNull; -class TestTreeStructure extends AbstractTreeStructure { +class TestTreeStructure extends TestTreeViewStructure { private final TestProxy myRootTest; private final JUnitConsoleProperties myProperties; private SpecialNode mySpecialNode; - public void setFilter(final Filter filter) { - myFilter = filter; - } - - public Filter getFilter() { - return myFilter; - } - - private Filter myFilter = Filter.NO_FILTER; - public TestTreeStructure(final TestProxy rootTest, final JUnitConsoleProperties properties) { myRootTest = rootTest; myProperties = properties; @@ -51,7 +40,7 @@ class TestTreeStructure extends AbstractTreeStructure { } public Object[] getChildElements(final Object element) { - final AbstractTestProxy[] children = ((TestProxy)element).selectChildren(myFilter); + final AbstractTestProxy[] children = ((TestProxy)element).selectChildren(getFilter()); if (element == myRootTest) { if (children.length == 0 && myRootTest.getState().isPassed()) { mySpecialNode.setVisible(true); diff --git a/plugins/testng/src/com/theoryinpractice/testng/model/TestTreeStructure.java b/plugins/testng/src/com/theoryinpractice/testng/model/TestTreeStructure.java index ce3aabb9b980..54ec2a9502d8 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/model/TestTreeStructure.java +++ b/plugins/testng/src/com/theoryinpractice/testng/model/TestTreeStructure.java @@ -15,35 +15,22 @@ */ package com.theoryinpractice.testng.model; -import com.intellij.execution.testframework.Filter; import com.intellij.execution.testframework.AbstractTestProxy; -import com.intellij.ide.util.treeView.AbstractTreeStructure; +import com.intellij.execution.testframework.TestTreeViewStructure; import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import java.util.List; -public class TestTreeStructure extends AbstractTreeStructure +public class TestTreeStructure extends TestTreeViewStructure { private final Object root; - private Filter filter; private final Project project; public TestTreeStructure(Project project, Object root) { this.project = project; this.root = root; - filter = Filter.NO_FILTER; - } - - public void setFilter(Filter filter) - { - this.filter = filter; - } - - public Filter getFilter() - { - return filter; } @Override @@ -55,7 +42,7 @@ public class TestTreeStructure extends AbstractTreeStructure @Override public Object[] getChildElements(Object obj) { - List results = ((TestProxy)obj).getResults(filter); + List results = ((TestProxy)obj).getResults(getFilter()); return results.toArray(new AbstractTestProxy[results.size()]); } diff --git a/resources/src/idea/RichPlatformActions.xml b/resources/src/idea/RichPlatformActions.xml index 17591405eaff..ab2573813a96 100644 --- a/resources/src/idea/RichPlatformActions.xml +++ b/resources/src/idea/RichPlatformActions.xml @@ -346,6 +346,8 @@ +