From 1482a1dc91492420bbd1a7a0d57f42bf9ecad226 Mon Sep 17 00:00:00 2001 From: "Anton.Makeev" Date: Tue, 9 Feb 2010 12:41:28 +0300 Subject: [PATCH] Maven+Ant: refactored 'before run' dialog --- .../impl/BaseExecuteBeforeRunDialog.java | 104 ++--- .../src/messages/ExecutionBundle.properties | 3 +- .../explorer/AntExecuteBeforeRunDialog.java | 63 +++ .../lang/ant/config/explorer/AntExplorer.java | 10 +- .../BuildFilePropertiesPanel.java | 2 +- .../actions/MavenExecuteBeforeRunDialog.java | 63 +++ .../actions/SelectBeforeRunTaskDialog.java | 373 ------------------ .../actions/ToggleBeforeRunTaskAction.java | 4 +- .../src/main/resources/TasksBundle.properties | 3 +- .../src/messages/AntBundle.properties | 2 +- 10 files changed, 191 insertions(+), 436 deletions(-) rename plugins/ant/src/com/intellij/lang/ant/config/explorer/ExecuteOnRunDialog.java => platform/lang-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java (79%) create mode 100644 plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExecuteBeforeRunDialog.java create mode 100644 plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/MavenExecuteBeforeRunDialog.java delete mode 100644 plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/SelectBeforeRunTaskDialog.java diff --git a/plugins/ant/src/com/intellij/lang/ant/config/explorer/ExecuteOnRunDialog.java b/platform/lang-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java similarity index 79% rename from plugins/ant/src/com/intellij/lang/ant/config/explorer/ExecuteOnRunDialog.java rename to platform/lang-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java index 61fb4309d4c0..374b626198cb 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/explorer/ExecuteOnRunDialog.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -13,23 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.lang.ant.config.explorer; +package com.intellij.execution.impl; +import com.intellij.execution.BeforeRunTask; +import com.intellij.execution.ExecutionBundle; import com.intellij.execution.RunManager; import com.intellij.execution.RunManagerEx; import com.intellij.execution.configurations.ConfigurationFactory; import com.intellij.execution.configurations.ConfigurationType; import com.intellij.execution.configurations.RunConfiguration; -import com.intellij.execution.impl.RunManagerImpl; -import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl; -import com.intellij.lang.ant.AntBundle; -import com.intellij.lang.ant.config.AntBuildFile; -import com.intellij.lang.ant.config.AntBuildTarget; -import com.intellij.lang.ant.config.impl.AntBeforeRunTask; -import com.intellij.lang.ant.config.impl.AntBeforeRunTaskProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.util.Key; import com.intellij.ui.TreeSpeedSearch; import com.intellij.ui.TreeToolTipHandler; import com.intellij.ui.treeStructure.Tree; @@ -51,21 +46,21 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.Set; -public final class ExecuteOnRunDialog extends DialogWrapper { + +public abstract class BaseExecuteBeforeRunDialog extends DialogWrapper { private final Project myProject; - private final AntBuildTarget myTarget; - private final AntBuildFile myFile; private DefaultMutableTreeNode myRoot; - public ExecuteOnRunDialog(final Project project, final AntBuildTarget target, final AntBuildFile file) { + public BaseExecuteBeforeRunDialog(final Project project) { super(project, true); myProject = project; - myTarget = target; - myFile = file; - setTitle(AntBundle.message("execute.target.before.run.debug.dialog.title")); - init(); } + @Override + protected void init() { + super.init(); + setTitle(ExecutionBundle.message("execute.before.run.debug.dialog.title", getTargetDisplayString())); + } protected JComponent createCenterPanel() { JPanel panel = new JPanel(new BorderLayout()); @@ -183,16 +178,14 @@ public final class ExecuteOnRunDialog extends DialogWrapper { final RunManagerEx runManager = RunManagerEx.getInstanceEx(myProject); for (ConfigurationFactory factory : type.getConfigurationFactories()) { final RunnerAndConfigurationSettingsImpl settings = ((RunManagerImpl)runManager).getConfigurationTemplate(factory); - final AntBeforeRunTask task = runManager.getBeforeRunTask(settings.getConfiguration(), AntBeforeRunTaskProvider.ID); - if (task != null && task.isRunningTarget(myTarget)) { - return true; - } + if (isConfigurationAssigned(settings.getConfiguration())) return true; } return false; } + private boolean isConfigurationAssigned(RunConfiguration configuration) { - final AntBeforeRunTask task = RunManagerEx.getInstanceEx(myProject).getBeforeRunTask(configuration, AntBeforeRunTaskProvider.ID); - return task != null && task.isRunningTarget(myTarget); + final T task = RunManagerEx.getInstanceEx(myProject).getBeforeRunTask(configuration, getTaskID()); + return task != null && isRunning(task); } protected void doOKAction() { @@ -201,43 +194,50 @@ public final class ExecuteOnRunDialog extends DialogWrapper { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)nodes.nextElement(); final Descriptor descriptor = (Descriptor)node.getUserObject(); final boolean isChecked = descriptor.isChecked(); - final String targetName; - final String antfileUrl; - if (isChecked) { - final VirtualFile vFile = myTarget.getModel().getBuildFile().getVirtualFile(); - targetName = vFile != null? myTarget.getName() : null; - antfileUrl = vFile != null? vFile.getUrl() : null; - } - else { - targetName = null; - antfileUrl = null; - } + if (descriptor instanceof ConfigurationTypeDescriptor) { - final ConfigurationTypeDescriptor configurationTypeDescriptor = (ConfigurationTypeDescriptor)descriptor; - for (ConfigurationFactory factory : configurationTypeDescriptor.getConfigurationType().getConfigurationFactories()) { - final RunnerAndConfigurationSettingsImpl settings = runManager.getConfigurationTemplate(factory); - final AntBeforeRunTask task = runManager.getBeforeRunTask(settings.getConfiguration(), AntBeforeRunTaskProvider.ID); - if (task != null && (isChecked || task.isRunningTarget(myTarget))) { - task.setEnabled(isChecked); - task.setAntFileUrl(antfileUrl); - task.setTargetName(targetName); - } + ConfigurationTypeDescriptor typeDesc = (ConfigurationTypeDescriptor)descriptor; + for (ConfigurationFactory factory : typeDesc.getConfigurationType().getConfigurationFactories()) { + RunnerAndConfigurationSettingsImpl settings = runManager.getConfigurationTemplate(factory); + update(settings.getConfiguration(), isChecked, runManager); } } else if (descriptor instanceof ConfigurationDescriptor) { - final ConfigurationDescriptor configurationDescriptor = (ConfigurationDescriptor)descriptor; - final AntBeforeRunTask task = runManager.getBeforeRunTask(configurationDescriptor.getConfiguration(), AntBeforeRunTaskProvider.ID); - if (task != null && (isChecked || task.isRunningTarget(myTarget))) { - task.setEnabled(isChecked); - task.setAntFileUrl(antfileUrl); - task.setTargetName(targetName); - } + ConfigurationDescriptor configDesc = (ConfigurationDescriptor)descriptor; + update(configDesc.getConfiguration(), isChecked, runManager); } } close(OK_EXIT_CODE); } + protected abstract String getTargetDisplayString(); + + protected abstract Key getTaskID(); + + protected abstract boolean isRunning(T task); + + private void update(RunConfiguration config, boolean enabled, RunManagerImpl runManager) { + T task = runManager.getBeforeRunTask(config, getTaskID()); + if (task == null) return; + + if (enabled) { + task.setEnabled(true); + update(task); + } + else { + if (isRunning(task)) { + task.setEnabled(false); + clear(task); + } + // do not change the task otherwise + } + } + + protected abstract void update(T task); + + protected abstract void clear(T task); + private static class Descriptor { private boolean myChecked; @@ -356,4 +356,4 @@ public final class ExecuteOnRunDialog extends DialogWrapper { } } -} +} \ No newline at end of file diff --git a/platform/platform-resources-en/src/messages/ExecutionBundle.properties b/platform/platform-resources-en/src/messages/ExecutionBundle.properties index 842f194c4bc4..004a34265cee 100644 --- a/platform/platform-resources-en/src/messages/ExecutionBundle.properties +++ b/platform/platform-resources-en/src/messages/ExecutionBundle.properties @@ -284,4 +284,5 @@ up.the.stack.trace=Up the stack trace configuration.action.chooser.title=Choose configuration type to run env.vars.checkbox.title=&Include parent environment variables -before.launch.compile.step=Make \ No newline at end of file +before.launch.compile.step=Make +execute.before.run.debug.dialog.title=Execute {0} Before Run/Debug diff --git a/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExecuteBeforeRunDialog.java b/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExecuteBeforeRunDialog.java new file mode 100644 index 000000000000..0dcf15125701 --- /dev/null +++ b/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExecuteBeforeRunDialog.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2009 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.lang.ant.config.explorer; + +import com.intellij.execution.impl.BaseExecuteBeforeRunDialog; +import com.intellij.lang.ant.AntBundle; +import com.intellij.lang.ant.config.AntBuildTarget; +import com.intellij.lang.ant.config.impl.AntBeforeRunTask; +import com.intellij.lang.ant.config.impl.AntBeforeRunTaskProvider; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.vfs.VirtualFile; + +public final class AntExecuteBeforeRunDialog extends BaseExecuteBeforeRunDialog { + private final AntBuildTarget myTarget; + + public AntExecuteBeforeRunDialog(final Project project, final AntBuildTarget target) { + super(project); + myTarget = target; + init(); + } + + @Override + protected String getTargetDisplayString() { + return AntBundle.message("ant.target"); + } + + @Override + protected Key getTaskID() { + return AntBeforeRunTaskProvider.ID; + } + + @Override + protected boolean isRunning(AntBeforeRunTask task) { + return task.isRunningTarget(myTarget); + } + + @Override + protected void update(AntBeforeRunTask task) { + VirtualFile f = myTarget.getModel().getBuildFile().getVirtualFile(); + task.setAntFileUrl(f != null ? f.getUrl() : null); + task.setTargetName(f != null ? myTarget.getName() : null); + } + + @Override + protected void clear(AntBeforeRunTask task) { + task.setAntFileUrl(null); + task.setTargetName(null); + } +} diff --git a/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.java b/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.java index d10db02ed7f6..cbce55dcd503 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.java @@ -385,7 +385,7 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider { executeOnGroup.add(new ExecuteOnEventAction(target, ExecuteBeforeCompilationEvent.getInstance())); executeOnGroup.add(new ExecuteOnEventAction(target, ExecuteAfterCompilationEvent.getInstance())); executeOnGroup.addSeparator(); - executeOnGroup.add(new ExecuteBeforeRunAction(target, getCurrentBuildFile())); + executeOnGroup.add(new ExecuteBeforeRunAction(target)); group.add(executeOnGroup); group.add(new AssignShortcutAction(target.getActionId())); } @@ -612,22 +612,20 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider { private final class ExecuteBeforeRunAction extends AnAction { private final AntBuildTarget myTarget; - private final AntBuildFile myBuildFile; - public ExecuteBeforeRunAction(final AntBuildTarget target, final AntBuildFile buildFile) { + public ExecuteBeforeRunAction(final AntBuildTarget target) { super(AntBundle.message("executes.before.run.debug.acton.name")); myTarget = target; - myBuildFile = buildFile; } public void actionPerformed(AnActionEvent e) { - final ExecuteOnRunDialog dialog = new ExecuteOnRunDialog(myProject, myTarget, myBuildFile); + final AntExecuteBeforeRunDialog dialog = new AntExecuteBeforeRunDialog(myProject, myTarget); dialog.show(); myBuilder.refresh(); } public void update(AnActionEvent e) { - e.getPresentation().setEnabled(myBuildFile.exists()); + e.getPresentation().setEnabled(myTarget.getModel().getBuildFile().exists()); } } diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/BuildFilePropertiesPanel.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/BuildFilePropertiesPanel.java index d52041a8355d..955ffc1c6cf7 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/BuildFilePropertiesPanel.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/configuration/BuildFilePropertiesPanel.java @@ -288,7 +288,7 @@ public class BuildFilePropertiesPanel { } }; private static final ColumnInfo NAME_COLUMN = new ColumnInfo( - AntBundle.message("edit.ant.properties.target.column.name")) { + AntBundle.message("ant.target")) { public String valueOf(TargetFilter targetFilter) { return targetFilter.getTargetName(); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/MavenExecuteBeforeRunDialog.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/MavenExecuteBeforeRunDialog.java new file mode 100644 index 000000000000..8f63bac2479e --- /dev/null +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/MavenExecuteBeforeRunDialog.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2009 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 org.jetbrains.idea.maven.tasks.actions; + +import com.intellij.execution.impl.BaseExecuteBeforeRunDialog; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; +import org.jetbrains.idea.maven.project.MavenProject; +import org.jetbrains.idea.maven.tasks.MavenBeforeRunTask; +import org.jetbrains.idea.maven.tasks.MavenBeforeRunTasksProvider; +import org.jetbrains.idea.maven.tasks.TasksBundle; + +public class MavenExecuteBeforeRunDialog extends BaseExecuteBeforeRunDialog { + private final MavenProject myMavenProject; + private final String myGoal; + + public MavenExecuteBeforeRunDialog(Project project, MavenProject mavenProject, String goal) { + super(project); + myMavenProject = mavenProject; + myGoal = goal; + init(); + } + + @Override + protected String getTargetDisplayString() { + return TasksBundle.message("maven.tasks.goal"); + } + + @Override + protected Key getTaskID() { + return MavenBeforeRunTasksProvider.TASK_ID; + } + + @Override + protected boolean isRunning(MavenBeforeRunTask task) { + return task.isFor(myMavenProject, myGoal); + } + + @Override + protected void update(MavenBeforeRunTask task) { + task.setProjectPath(myMavenProject.getPath()); + task.setGoal(myGoal); + } + + @Override + protected void clear(MavenBeforeRunTask task) { + task.setProjectPath(null); + task.setGoal(null); + } +} diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/SelectBeforeRunTaskDialog.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/SelectBeforeRunTaskDialog.java deleted file mode 100644 index bb75f2e724ce..000000000000 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/SelectBeforeRunTaskDialog.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright 2000-2009 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 org.jetbrains.idea.maven.tasks.actions; - -import com.intellij.execution.RunManagerEx; -import com.intellij.execution.configurations.ConfigurationFactory; -import com.intellij.execution.configurations.ConfigurationType; -import com.intellij.execution.configurations.RunConfiguration; -import com.intellij.execution.impl.RunManagerImpl; -import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.ui.treeStructure.Tree; -import com.intellij.util.StringSetSpinAllocator; -import com.intellij.util.ui.UIUtil; -import com.intellij.util.ui.tree.TreeUtil; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.idea.maven.project.MavenProject; -import org.jetbrains.idea.maven.tasks.MavenBeforeRunTask; -import org.jetbrains.idea.maven.tasks.MavenBeforeRunTasksProvider; -import org.jetbrains.idea.maven.tasks.MavenTasksManager; -import org.jetbrains.idea.maven.tasks.TasksBundle; - -import javax.swing.*; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeCellRenderer; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import java.awt.*; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Set; - -public class SelectBeforeRunTaskDialog extends DialogWrapper { - private final RunManagerEx myRunManager; - private final MavenTasksManager myTasksManager; - - private final MavenProject myMavenProject; - private final String myGoal; - - private DefaultMutableTreeNode myRoot; - - public SelectBeforeRunTaskDialog(Project project, MavenProject mavenProject, String goal) { - super(project, true); - myRunManager = RunManagerEx.getInstanceEx(project); - myTasksManager = MavenTasksManager.getInstance(project); - myMavenProject = mavenProject; - myGoal = goal; - - setTitle(TasksBundle.message("maven.tasks.before.run.action")); - init(); - } - - protected JComponent createCenterPanel() { - JPanel panel = new JPanel(new BorderLayout()); - - myRoot = buildNodes(); - final Tree tree = new Tree(myRoot); - - final MyTreeCellRenderer cellRenderer = new MyTreeCellRenderer(); - - tree.setCellRenderer(cellRenderer); - tree.setRootVisible(false); - tree.setShowsRootHandles(true); - tree.setLineStyleAngled(); -// TreeToolTipHandler.install(tree); - TreeUtil.installActions(tree); -// new TreeSpeedSearch(tree); - - tree.addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - int row = tree.getRowForLocation(e.getX(), e.getY()); - if (row >= 0) { - Rectangle rowBounds = tree.getRowBounds(row); - cellRenderer.setBounds(rowBounds); - Rectangle checkBounds = cellRenderer.myCheckbox.getBounds(); - - checkBounds.setLocation(rowBounds.getLocation()); - if (checkBounds.contains(e.getPoint())) { - toggleNode(tree, (DefaultMutableTreeNode)tree.getPathForRow(row).getLastPathComponent()); - e.consume(); - tree.setSelectionRow(row); - } - } - } - }); - - tree.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_SPACE) { - TreePath treePath = tree.getLeadSelectionPath(); - DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath.getLastPathComponent(); - toggleNode(tree, node); - e.consume(); - } - } - }); - - expandChecked(tree); - - JScrollPane scrollPane = new JScrollPane(tree); - scrollPane.setPreferredSize(new Dimension(400, 400)); - panel.add(scrollPane, BorderLayout.CENTER); - return panel; - } - - private static void expandChecked(Tree tree) { - TreeNode root = (TreeNode)tree.getModel().getRoot(); - Enumeration factories = root.children(); - ArrayList toExpand = new ArrayList(); - while (factories.hasMoreElements()) { - DefaultMutableTreeNode factoryNode = (DefaultMutableTreeNode)factories.nextElement(); - Enumeration configurations = factoryNode.children(); - while (configurations.hasMoreElements()) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode)configurations.nextElement(); - ConfigurationDescriptor config = (ConfigurationDescriptor)node.getUserObject(); - if (config.isChecked()) { - toExpand.add(factoryNode.getPath()); - break; - } - } - } - for (TreeNode[] treeNodes : toExpand) { - tree.expandPath(new TreePath(treeNodes)); - } - } - - private static void toggleNode(JTree tree, DefaultMutableTreeNode node) { - Descriptor descriptor = (Descriptor)node.getUserObject(); - descriptor.setChecked(!descriptor.isChecked()); - tree.repaint(); - } - - private DefaultMutableTreeNode buildNodes() { - DefaultMutableTreeNode root = new DefaultMutableTreeNode(new Descriptor()); - ConfigurationType[] configurationFactories = myRunManager.getConfigurationFactories(); - - for (final ConfigurationType type : configurationFactories) { - final Icon icon = type.getIcon(); - DefaultMutableTreeNode typeNode = - new DefaultMutableTreeNode(new ConfigurationTypeDescriptor(type, icon, isAssigned(type, null))); - root.add(typeNode); - final Set addedNames = StringSetSpinAllocator.alloc(); - try { - RunConfiguration[] configurations = myRunManager.getConfigurations(type); - for (final RunConfiguration configuration : configurations) { - final String configurationName = configuration.getName(); - if (addedNames.contains(configurationName)) { - // add only the first configuration if more than one has the same name - continue; - } - addedNames.add(configurationName); - typeNode.add(new DefaultMutableTreeNode( - new ConfigurationDescriptor(type, configuration, configurationName, isAssigned(type, configuration)))); - } - } - finally { - StringSetSpinAllocator.dispose(addedNames); - } - } - - return root; - } - - private boolean isAssigned(ConfigurationType type, RunConfiguration configuration) { - if (configuration == null) { - for (ConfigurationFactory each : type.getConfigurationFactories()) { - RunnerAndConfigurationSettingsImpl settings = ((RunManagerImpl)myRunManager).getConfigurationTemplate(each); - if (doIsAssigned(settings.getConfiguration())) return true; - } - return false; - } - - return doIsAssigned(configuration); - } - - private boolean doIsAssigned(RunConfiguration configuration) { - MavenBeforeRunTask task = myRunManager.getBeforeRunTask(configuration, MavenBeforeRunTasksProvider.TASK_ID); - return task != null && task.isEnabled() && task.isFor(myMavenProject, myGoal); - } - - private void assign(ConfigurationType type, RunConfiguration configuration) { - if (configuration == null) { - for (ConfigurationFactory each : type.getConfigurationFactories()) { - RunnerAndConfigurationSettingsImpl settings = ((RunManagerImpl)myRunManager).getConfigurationTemplate(each); - doAssign(settings.getConfiguration()); - } - } else { - doAssign(configuration); - } - myTasksManager.fireTasksChanged(); - } - - private void doAssign(RunConfiguration configuration) { - MavenBeforeRunTask task = myRunManager.getBeforeRunTask(configuration, MavenBeforeRunTasksProvider.TASK_ID); - if (task != null) { - task.setProjectPath(myMavenProject.getPath()); - task.setGoal(myGoal); - task.setEnabled(true); - } - } - - private void clearAll() { - for (MavenBeforeRunTask each : myRunManager.getBeforeRunTasks(MavenBeforeRunTasksProvider.TASK_ID, false)) { - each.setEnabled(false); - } - myTasksManager.fireTasksChanged(); - } - - protected void doOKAction() { - clearAll(); - - Enumeration nodes = myRoot.depthFirstEnumeration(); - while (nodes.hasMoreElements()) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode)nodes.nextElement(); - Descriptor descriptor = (Descriptor)node.getUserObject(); - if (!descriptor.isChecked()) continue; - if (descriptor instanceof DescriptorBase) { - DescriptorBase descriptorBase = (DescriptorBase)descriptor; - assign(descriptorBase.getConfigurationType(), descriptorBase.getConfiguration()); - } - } - - close(OK_EXIT_CODE); - } - - private static class Descriptor { - private boolean myChecked; - - public final boolean isChecked() { - return myChecked; - } - - public final void setChecked(boolean checked) { - myChecked = checked; - } - } - - private static abstract class DescriptorBase extends Descriptor { - private final ConfigurationType myConfigurationType; - private final RunConfiguration myConfiguration; - - public DescriptorBase(ConfigurationType type, RunConfiguration configuration, boolean isChecked) { - myConfigurationType = type; - myConfiguration = configuration; - setChecked(isChecked); - } - - public ConfigurationType getConfigurationType() { - return myConfigurationType; - } - - @Nullable - public abstract String getName(); - - public RunConfiguration getConfiguration() { - return myConfiguration; - } - } - - private static final class ConfigurationTypeDescriptor extends DescriptorBase { - private final Icon myIcon; - - public ConfigurationTypeDescriptor(ConfigurationType type, Icon icon, boolean isChecked) { - super(type, null, isChecked); - myIcon = icon; - } - - public Icon getIcon() { - return myIcon; - } - - @Nullable - public String getName() { - return null; - } - } - - private static final class ConfigurationDescriptor extends DescriptorBase { - private final String myName; - - public ConfigurationDescriptor(ConfigurationType type, RunConfiguration configuration, String name, boolean isChecked) { - super(type, configuration, isChecked); - myName = name; - } - - public String getName() { - return myName; - } - } - - private static final class MyTreeCellRenderer extends JPanel implements TreeCellRenderer { - private final JLabel myLabel; - public final JCheckBox myCheckbox; - - public MyTreeCellRenderer() { - super(new BorderLayout()); - myCheckbox = new JCheckBox(); - myLabel = new JLabel(); - add(myCheckbox, BorderLayout.WEST); - add(myLabel, BorderLayout.CENTER); - } - - public Component getTreeCellRendererComponent(JTree tree, - Object value, - boolean selected, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; - Descriptor descriptor = (Descriptor)node.getUserObject(); - - myCheckbox.setSelected(descriptor.isChecked()); - - myCheckbox.setBackground(UIUtil.getTreeTextBackground()); - setBackground(selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground()); - Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground(); - setForeground(foreground); - myCheckbox.setForeground(foreground); - myLabel.setForeground(foreground); - myCheckbox.setEnabled(true); - - if (descriptor instanceof ConfigurationTypeDescriptor) { - ConfigurationTypeDescriptor configurationTypeDescriptor = (ConfigurationTypeDescriptor)descriptor; - myLabel.setFont(tree.getFont()); - myLabel.setText(configurationTypeDescriptor.getConfigurationType().getDisplayName()); - myLabel.setIcon(configurationTypeDescriptor.getIcon()); - } - else if (descriptor instanceof ConfigurationDescriptor) { - ConfigurationDescriptor configurationTypeDescriptor = (ConfigurationDescriptor)descriptor; - myLabel.setFont(tree.getFont()); - myLabel.setText(configurationTypeDescriptor.getName()); - myLabel.setIcon(null); - - if (((ConfigurationTypeDescriptor)((DefaultMutableTreeNode)node.getParent()).getUserObject()).isChecked()) { - Color foregrnd = tree.getForeground(); - Color backgrnd = tree.getBackground(); - if (foregrnd == null) foregrnd = Color.black; - if (backgrnd == null) backgrnd = Color.white; - - int red = (foregrnd.getRed() + backgrnd.getRed()) / 2; - int green = (foregrnd.getGreen() + backgrnd.getGreen()) / 2; - int blue = (foregrnd.getBlue() + backgrnd.getBlue()) / 2; - Color halftone = new Color(red, green, blue); - setForeground(halftone); - myCheckbox.setForeground(halftone); - myLabel.setForeground(halftone); - myCheckbox.setEnabled(false); - } - } - - return this; - } - } -} diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/ToggleBeforeRunTaskAction.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/ToggleBeforeRunTaskAction.java index 66a3c95cb5ee..15b3d05665f5 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/ToggleBeforeRunTaskAction.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/ToggleBeforeRunTaskAction.java @@ -21,6 +21,7 @@ import com.intellij.openapi.util.Pair; import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.tasks.MavenBeforeRunTask; import org.jetbrains.idea.maven.tasks.MavenBeforeRunTasksProvider; +import org.jetbrains.idea.maven.tasks.MavenTasksManager; import org.jetbrains.idea.maven.utils.MavenDataKeys; import org.jetbrains.idea.maven.utils.actions.MavenToggleAction; import org.jetbrains.idea.maven.utils.actions.MavenActionUtil; @@ -45,7 +46,8 @@ public class ToggleBeforeRunTaskAction extends MavenToggleAction { @Override public void setSelected(final AnActionEvent e, boolean state) { Pair desc = getTaskDesc(e); - new SelectBeforeRunTaskDialog(MavenActionUtil.getProject(e), desc.first, desc.second).show(); + new MavenExecuteBeforeRunDialog(MavenActionUtil.getProject(e), desc.first, desc.second).show(); + MavenTasksManager.getInstance(MavenActionUtil.getProject(e)).fireTasksChanged(); } protected Pair getTaskDesc(AnActionEvent e) { diff --git a/plugins/maven/src/main/resources/TasksBundle.properties b/plugins/maven/src/main/resources/TasksBundle.properties index a4d496f21cfb..2ea08b335794 100644 --- a/plugins/maven/src/main/resources/TasksBundle.properties +++ b/plugins/maven/src/main/resources/TasksBundle.properties @@ -1,6 +1,7 @@ +maven.tasks.goal=Maven Goal + maven.tasks.before.run.empty=Run Maven Goal maven.tasks.before.run=Run Maven Goal ''{0}'' -maven.tasks.before.run.action=Execute Goal Before Run/Debug maven.tasks.goal.before.compile=Before Make maven.tasks.goal.after.compile=After Make maven.tasks.goal.before.run=Before Run diff --git a/resources-en/src/messages/AntBundle.properties b/resources-en/src/messages/AntBundle.properties index d0fd2afb829c..5161fc06f2e7 100644 --- a/resources-en/src/messages/AntBundle.properties +++ b/resources-en/src/messages/AntBundle.properties @@ -8,6 +8,7 @@ ant.create.target.intention.description=Create target ''{0}'' ant.role.ant.target=Ant target ant.role.ant.property=Ant property ant.role.ant.task=Ant task +ant.target=Target cannot.add.build.files.from.excluded.directories.error.message=Cannot add build files from excluded directories\n{0} cannot.add.build.file.dialog.title=Cannot Add Build File build.file.properties.action.name=Properties @@ -129,7 +130,6 @@ build.file.properties.dialog.title=Build File Properties edit.ant.properties.name.column.name=Name edit.ant.properties.value.column.name=Value edit.ant.properties.tab.display.name=Properties -edit.ant.properties.target.column.name=Target edit.ant.properties.description.column.name=Description edit.ant.properties.filters.tab.display.name=Filters edit.ant.properties.execution.tab.display.name=Execution