auto test: simplify ToggleAutoTestAction creation (no need in ExecutionEnvironment)

This commit is contained in:
Sergey Simonchik
2015-02-09 01:55:28 +03:00
parent eff2915b26
commit f6763a4980
4 changed files with 33 additions and 13 deletions
@@ -102,7 +102,7 @@ public class ToolbarPanel extends JPanel implements OccurenceNavigator, Disposab
properties, TestConsoleProperties.OPEN_FAILURE_LINE)).setAsSecondary(true);
actionGroup.addAction(new ShowStatisticsAction(properties)).setAsSecondary(true);
actionGroup.addAction(new AdjustAutotestDelayActionGroup(environment)).setAsSecondary(true);
actionGroup.addAction(new AdjustAutotestDelayActionGroup(environment.getProject(), parent)).setAsSecondary(true);
for (ToggleModelActionProvider actionProvider : Extensions.getExtensions(ToggleModelActionProvider.EP_NAME)) {
final ToggleModelAction toggleModelAction = actionProvider.createToggleModelAction(properties);
@@ -15,30 +15,42 @@
*/
package com.intellij.execution.testframework.autotest;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author Dennis.Ushakov
*/
public class AdjustAutotestDelayActionGroup extends ActionGroup {
public static final int MAX_DELAY = 10;
private final ExecutionEnvironment myEnvironment;
private final Project myProject;
private final DataContext myDataContext;
public AdjustAutotestDelayActionGroup(ExecutionEnvironment environment) {
public AdjustAutotestDelayActionGroup(@NotNull Project project, @NotNull JComponent parent) {
super("Set AutoTest Delay", true);
myEnvironment = environment;
myProject = project;
myDataContext = DataManager.getInstance().getDataContext(parent);
}
@Override
public void update(AnActionEvent e) {
e.getPresentation().setVisible(Boolean.TRUE == myEnvironment.getUserData(AutoTestManager.AUTOTESTABLE));
RunContentDescriptor descriptor = LangDataKeys.RUN_CONTENT_DESCRIPTOR.getData(myDataContext);
boolean visible = false;
if (descriptor != null) {
for (AnAction action : descriptor.getRestartActions()) {
if (action instanceof ToggleAutoTestAction) {
visible = true;
break;
}
}
}
e.getPresentation().setVisible(visible);
}
@NotNull
@@ -46,7 +58,7 @@ public class AdjustAutotestDelayActionGroup extends ActionGroup {
public AnAction[] getChildren(@Nullable AnActionEvent e) {
final AnAction[] actions = new AnAction[MAX_DELAY];
for (int i = 0; i < MAX_DELAY; i++) {
actions[i] = new SetAutoTestDelayAction(myEnvironment.getProject(), i + 1);
actions[i] = new SetAutoTestDelayAction(myProject, i + 1);
}
return actions;
}
@@ -47,7 +47,6 @@ import javax.swing.*;
* @author yole
*/
public class AutoTestManager {
static final Key<Boolean> AUTOTESTABLE = Key.create("auto.test.manager.supported");
private static final String AUTO_TEST_MANAGER_DELAY = "auto.test.manager.delay";
private static final Key<ProcessListener> ON_TERMINATION_RESTARTER_KEY = Key.create("auto.test.manager.on.termination.restarter");
private static final Key<ExecutionEnvironment> EXECUTION_ENVIRONMENT_KEY = Key.create("auto.test.manager.execution.environment");
@@ -13,10 +13,19 @@ import com.intellij.openapi.project.Project;
* @author yole
*/
public class ToggleAutoTestAction extends ToggleAction {
/**
* @deprecated use default constructor instead
* @param environment
* To be removed in IDEA 16
*/
@Deprecated
public ToggleAutoTestAction(ExecutionEnvironment environment) {
this();
}
public ToggleAutoTestAction() {
super("Toggle auto-test", "Toggle automatic rerun of tests on code changes",
AllIcons.Actions.SwapPanels);
environment.putUserData(AutoTestManager.AUTOTESTABLE, true);
}
@Override