From fd9ead508c5842a65ac57374ad8323dbf5afb505 Mon Sep 17 00:00:00 2001 From: Michael Golubev Date: Mon, 27 Oct 2014 17:32:49 +0100 Subject: [PATCH] IDEA-131963 - Redesign application servers view actions --- .../impl/src/META-INF/RemoteServers.xml | 14 +- .../runtime/ui/ServersToolWindowContent.java | 29 +--- .../impl/runtime/ui/tree/DeploymentNode.java | 16 +- .../impl/runtime/ui/tree/ServerNode.java | 19 +-- .../impl/runtime/ui/tree/ServersTreeNode.java | 20 +++ .../runtime/ui/tree/ServersTreeStructure.java | 152 +++++++++--------- .../tree/actions/ChooseDeploymentAction.java | 39 +++++ .../ChooseDeploymentWithDebugAction.java | 39 +++++ .../ui/tree/actions/DebugServerAction.java | 19 --- .../runtime/ui/tree/actions/DeployAction.java | 63 +++----- .../ui/tree/actions/DeployAllAction.java | 27 ---- .../tree/actions/DeployWithDebugAction.java | 46 ++++++ .../ui/tree/actions/DeploymentActionBase.java | 52 ------ .../tree/actions/DeploymentConfigAction.java | 40 +++++ .../tree/actions/EditConfigurationAction.java | 42 ----- .../actions/EditConfigurationActionBase.java | 26 +++ .../actions/RemoteServerConfigAction.java | 35 ++++ .../actions/RemoteServerConnectAction.java | 42 +++++ .../actions/RemoteServerDisconnectAction.java | 46 ++++++ .../ui/tree/actions/RunServerAction.java | 20 --- .../ui/tree/actions/RunServerActionBase.java | 31 ---- .../ui/tree/actions/ServerActionBase.java | 46 ------ .../ui/tree/actions/ServersTreeAction.java | 91 +++++++++++ .../tree/actions/ServersTreeActionBase.java | 44 ----- .../tree/actions/SingleServerActionBase.java | 49 ------ .../ui/tree/actions/StopServerAction.java | 26 --- .../ui/tree/actions/UndeployAction.java | 21 ++- 27 files changed, 560 insertions(+), 534 deletions(-) create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeNode.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ChooseDeploymentAction.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ChooseDeploymentWithDebugAction.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DebugServerAction.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployAllAction.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployWithDebugAction.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeploymentActionBase.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeploymentConfigAction.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/EditConfigurationAction.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/EditConfigurationActionBase.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerConfigAction.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerConnectAction.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerDisconnectAction.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RunServerAction.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RunServerActionBase.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServerActionBase.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServersTreeAction.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServersTreeActionBase.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/SingleServerActionBase.java delete mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/StopServerAction.java diff --git a/platform/remote-servers/impl/src/META-INF/RemoteServers.xml b/platform/remote-servers/impl/src/META-INF/RemoteServers.xml index 0ce5eae571a9..eae970f46594 100644 --- a/platform/remote-servers/impl/src/META-INF/RemoteServers.xml +++ b/platform/remote-servers/impl/src/META-INF/RemoteServers.xml @@ -38,14 +38,16 @@ - - - - - - + + + + + + + + \ No newline at end of file diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java index 8a46887be6cf..2d3fb8cc1b86 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowContent.java @@ -6,18 +6,16 @@ import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.ide.util.treeView.NodeRenderer; import com.intellij.ide.util.treeView.TreeVisitor; -import com.intellij.openapi.application.ModalityState; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; import com.intellij.remoteServer.configuration.RemoteServer; import com.intellij.remoteServer.impl.runtime.log.LoggingHandlerImpl; -import com.intellij.remoteServer.impl.runtime.ui.tree.DeploymentNode; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServerNode; +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; import com.intellij.remoteServer.impl.runtime.ui.tree.TreeBuilderBase; import com.intellij.remoteServer.runtime.ConnectionStatus; import com.intellij.remoteServer.runtime.ServerConnection; @@ -108,13 +106,10 @@ public class ServersToolWindowContent extends JPanel implements Disposable { new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent event) { - Set nodes = getSelectedRemoteServerNodes(); - if (nodes.size() == 1) { - RemoteServer server = nodes.iterator().next().getValue(); - ServerConnectionManager.getInstance().getOrCreateConnection(server); - return true; - } - return false; + AnAction connectAction = ActionManager.getInstance().getAction("RemoteServers.ConnectServer"); + AnActionEvent actionEvent = AnActionEvent.createFromInputEvent(connectAction, event, ActionPlaces.UNKNOWN); + connectAction.actionPerformed(actionEvent); + return true; } }.installOn(myTree); } @@ -265,18 +260,6 @@ public class ServersToolWindowContent extends JPanel implements Disposable { return this; } - public Set getSelectedServerNodes() { - return myBuilder.getSelectedElements(ServerNode.class); - } - - public Set getSelectedDeploymentNodes() { - return myBuilder.getSelectedElements(DeploymentNode.class); - } - - public Set getSelectedRemoteServerNodes() { - return myBuilder.getSelectedElements(ServersTreeStructure.RemoteServerNode.class); - } - @Override public void dispose() { } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/DeploymentNode.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/DeploymentNode.java index d859d61b7f3e..b147ee72df6c 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/DeploymentNode.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/DeploymentNode.java @@ -5,18 +5,24 @@ import org.jetbrains.annotations.NotNull; /** * @author nik */ -public interface DeploymentNode { +public interface DeploymentNode extends ServersTreeNode { + @NotNull ServerNode getServerNode(); - boolean isRedeployActionEnabled(); - void redeploy(); + boolean isDeployActionVisible(); + + boolean isDeployActionEnabled(); + + void deploy(); boolean isUndeployActionEnabled(); + void undeploy(); - boolean isEditConfigurationActionEnabled(); - void editConfiguration(); + boolean isDebugActionVisible(); + + void deployWithDebug(); boolean isDeployed(); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServerNode.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServerNode.java index d17a730002fb..d3d160cff2e3 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServerNode.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServerNode.java @@ -1,26 +1,9 @@ package com.intellij.remoteServer.impl.runtime.ui.tree; -import com.intellij.execution.Executor; -import com.intellij.openapi.actionSystem.AnActionEvent; -import org.jetbrains.annotations.NotNull; - /** * @author nik */ -public interface ServerNode { - boolean isConnected(); - boolean isStopActionEnabled(); - void stopServer(); +public interface ServerNode extends ServersTreeNode { - boolean isStartActionEnabled(@NotNull Executor executor); - void startServer(@NotNull Executor executor); - - boolean isDeployActionEnabled(); - void deploy(AnActionEvent e); - - boolean isDeployAllActionEnabled(); - void deployAll(); - - void editConfiguration(); } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeNode.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeNode.java new file mode 100644 index 000000000000..84cd735aaba6 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeNode.java @@ -0,0 +1,20 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree; + +public interface ServersTreeNode { + +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeStructure.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeStructure.java index 7a2a053779d5..5f1969ecbea3 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeStructure.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/ServersTreeStructure.java @@ -3,6 +3,7 @@ package com.intellij.remoteServer.impl.runtime.ui.tree; import com.intellij.execution.Executor; import com.intellij.execution.ProgramRunnerUtil; import com.intellij.execution.RunnerAndConfigurationSettings; +import com.intellij.execution.executors.DefaultDebugExecutor; import com.intellij.execution.executors.DefaultRunExecutor; import com.intellij.execution.impl.RunDialog; import com.intellij.execution.runners.ExecutionEnvironment; @@ -18,13 +19,16 @@ import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.remoteServer.ServerType; import com.intellij.remoteServer.configuration.RemoteServer; import com.intellij.remoteServer.configuration.RemoteServersManager; import com.intellij.remoteServer.configuration.ServerConfiguration; import com.intellij.remoteServer.configuration.deployment.DeploymentConfigurationManager; import com.intellij.remoteServer.impl.configuration.SingleRemoteServerConfigurable; +import com.intellij.remoteServer.impl.configuration.deployment.DeployToServerRunConfiguration; import com.intellij.remoteServer.impl.runtime.deployment.DeploymentTaskImpl; import com.intellij.remoteServer.impl.runtime.log.DeploymentLogManagerImpl; import com.intellij.remoteServer.impl.runtime.log.LoggingHandlerImpl; @@ -38,6 +42,7 @@ import com.intellij.remoteServer.runtime.deployment.DeploymentStatus; import com.intellij.remoteServer.runtime.deployment.DeploymentTask; import com.intellij.ui.LayeredIcon; import com.intellij.ui.awt.RelativePoint; +import com.intellij.util.containers.ContainerUtil; import icons.RemoteServersIcons; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -160,50 +165,65 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { return ServerConnectionManager.getInstance().getConnection(getValue()); } - @Override public boolean isConnected() { ServerConnection connection = getConnection(); return connection != null && connection.getStatus() == ConnectionStatus.CONNECTED; } - @Override - public boolean isDeployActionEnabled() { - return true; + public void deploy(AnActionEvent e) { + doDeploy(e, DefaultRunExecutor.getRunExecutorInstance(), "Deploy Configuration", true); } - @Override - public void deploy(AnActionEvent e) { - final ServerType serverType = getValue().getType(); + public void deployWithDebug(AnActionEvent e) { + doDeploy(e, DefaultDebugExecutor.getDebugExecutorInstance(), "Deploy and Debug Configuration", false); + } + + public void doDeploy(AnActionEvent e, final Executor executor, String popupTitle, boolean canCreate) { + final RemoteServer server = getValue(); + final ServerType serverType = server.getType(); final DeploymentConfigurationManager configurationManager = DeploymentConfigurationManager.getInstance(doGetProject()); - List list = new ArrayList(configurationManager.getDeploymentConfigurations(serverType)); - list.add(null); - ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep("Deploy Configuration", list) { - @Override - public Icon getIconFor(RunnerAndConfigurationSettings value) { - return value != null ? serverType.getIcon() : null; - } + List list + = ContainerUtil.filter(configurationManager.getDeploymentConfigurations(serverType), + new Condition() { - @NotNull - @Override - public String getTextFor(RunnerAndConfigurationSettings value) { - return value != null ? value.getName() : "Create..."; - } + @Override + public boolean value(RunnerAndConfigurationSettings settings) { + DeployToServerRunConfiguration configuration = + (DeployToServerRunConfiguration)settings.getConfiguration(); + return StringUtil.equals(server.getName(), configuration.getServerName()); + } + }); + if (canCreate) { + list.add(null); + } + ListPopup popup = + JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep(popupTitle, list) { + @Override + public Icon getIconFor(RunnerAndConfigurationSettings value) { + return value != null ? serverType.getIcon() : null; + } - @Override - public PopupStep onChosen(final RunnerAndConfigurationSettings selectedValue, boolean finalChoice) { - return doFinalStep(new Runnable() { - @Override - public void run() { - if (selectedValue != null) { - ProgramRunnerUtil.executeConfiguration(doGetProject(), selectedValue, DefaultRunExecutor.getRunExecutorInstance()); + @NotNull + @Override + public String getTextFor(RunnerAndConfigurationSettings value) { + return value != null ? value.getName() : "Create..."; + } + + @Override + public PopupStep onChosen(final RunnerAndConfigurationSettings selectedValue, boolean finalChoice) { + return doFinalStep(new Runnable() { + @Override + public void run() { + if (selectedValue != null) { + ProgramRunnerUtil.executeConfiguration(doGetProject(), selectedValue, executor); + } + else { + configurationManager.createAndRunConfiguration(serverType, RemoteServerNode.this.getValue()); + } } - else { - configurationManager.createAndRunConfiguration(serverType, RemoteServerNode.this.getValue()); - } - } - }); - } - }); + }); + } + }); if (e.getInputEvent() instanceof MouseEvent) { popup.show(new RelativePoint((MouseEvent)e.getInputEvent())); } @@ -212,45 +232,10 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { } } - @Override - public boolean isStopActionEnabled() { - return isConnected(); - } - - @Override - public void stopServer() { - ServerConnection connection = getConnection(); - if (connection != null) { - connection.disconnect(); - } - } - - @Override public void editConfiguration() { ShowSettingsUtil.getInstance().editConfigurable(doGetProject(), new SingleRemoteServerConfigurable(getValue(), null, false)); } - @Override - public boolean isStartActionEnabled(@NotNull Executor executor) { - ServerConnection connection = getConnection(); - return executor.equals(DefaultRunExecutor.getRunExecutorInstance()) && - (connection == null || connection.getStatus() == ConnectionStatus.DISCONNECTED); - } - - @Override - public void startServer(@NotNull Executor executor) { - ServerConnectionManager.getInstance().getOrCreateConnection(getValue()); - } - - @Override - public boolean isDeployAllActionEnabled() { - return false; - } - - @Override - public void deployAll() { - } - @Nullable private Icon getStatusIcon(final ConnectionStatus status) { switch (status) { @@ -278,23 +263,42 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { } @Override - public boolean isRedeployActionEnabled() { + public boolean isDeployActionVisible() { DeploymentTask deploymentTask = getValue().getDeploymentTask(); return deploymentTask instanceof DeploymentTaskImpl && ((DeploymentTaskImpl)deploymentTask).getExecutionEnvironment().getRunnerAndConfigurationSettings() != null; } @Override - public void redeploy() { + public boolean isDeployActionEnabled() { + return true; + } + + @Override + public void deploy() { + doDeploy(DefaultRunExecutor.getRunExecutorInstance()); + } + + public void doDeploy(Executor executor) { DeploymentTask deploymentTask = getValue().getDeploymentTask(); if (deploymentTask != null) { ExecutionEnvironment environment = ((DeploymentTaskImpl)deploymentTask).getExecutionEnvironment(); RunnerAndConfigurationSettings settings = environment.getRunnerAndConfigurationSettings(); if (settings != null) { - ProgramRunnerUtil.executeConfiguration(doGetProject(), settings, DefaultRunExecutor.getRunExecutorInstance()); + ProgramRunnerUtil.executeConfiguration(doGetProject(), settings, executor); } } } + @Override + public boolean isDebugActionVisible() { + return myParentNode.getValue().getType().createDebugConnector() != null; + } + + @Override + public void deployWithDebug() { + doDeploy(DefaultDebugExecutor.getDebugExecutorInstance()); + } + @Override public boolean isUndeployActionEnabled() { DeploymentRuntime runtime = getValue().getRuntime(); @@ -309,12 +313,10 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { } } - @Override - public boolean isEditConfigurationActionEnabled() { + public boolean isEditConfigurationActionVisible() { return getValue().getDeploymentTask() != null; } - @Override public void editConfiguration() { DeploymentTask task = getValue().getDeploymentTask(); if (task != null) { @@ -396,7 +398,7 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { } } - public class DeploymentLogNode extends AbstractTreeNode> implements LogProvidingNode { + public class DeploymentLogNode extends AbstractTreeNode> implements ServersTreeNode, LogProvidingNode { @NotNull private final DeploymentNodeImpl myDeploymentNode; public DeploymentLogNode(@NotNull Pair value, @NotNull DeploymentNodeImpl deploymentNode) { diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ChooseDeploymentAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ChooseDeploymentAction.java new file mode 100644 index 000000000000..1a762f75cf01 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ChooseDeploymentAction.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; +import org.jetbrains.annotations.NotNull; + +public class ChooseDeploymentAction extends ServersTreeAction { + + public ChooseDeploymentAction() { + super("Deploy", "Deploy a chosen item to the selected remote server", AllIcons.Nodes.Deploy); + } + + @Override + protected Class getTargetNodeClass() { + return ServersTreeStructure.RemoteServerNode.class; + } + + @Override + protected void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e, ServersTreeStructure.RemoteServerNode node) { + node.deploy(e); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ChooseDeploymentWithDebugAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ChooseDeploymentWithDebugAction.java new file mode 100644 index 000000000000..55e2b1cb509f --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ChooseDeploymentWithDebugAction.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; +import org.jetbrains.annotations.NotNull; + +public class ChooseDeploymentWithDebugAction extends ServersTreeAction { + + public ChooseDeploymentWithDebugAction() { + super("Debug", "Deploy and debug a chosen item on the selected remote server", AllIcons.Actions.StartDebugger); + } + + @Override + protected Class getTargetNodeClass() { + return ServersTreeStructure.RemoteServerNode.class; + } + + @Override + protected void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e, ServersTreeStructure.RemoteServerNode node) { + node.deployWithDebug(e); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DebugServerAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DebugServerAction.java deleted file mode 100644 index f519478ef84c..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DebugServerAction.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.execution.Executor; -import com.intellij.execution.executors.DefaultDebugExecutor; -import com.intellij.icons.AllIcons; - -/** - * @author michael.golubev - */ -public class DebugServerAction extends RunServerActionBase { - public DebugServerAction() { - super("Debug", "Start the selected server in debug mode", AllIcons.Actions.StartDebugger); - } - - @Override - protected Executor getExecutor() { - return DefaultDebugExecutor.getDebugExecutorInstance(); - } -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployAction.java index c6a38404192e..4b8bbeeea7e7 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployAction.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployAction.java @@ -1,67 +1,50 @@ package com.intellij.remoteServer.impl.runtime.ui.tree.actions; import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; import com.intellij.remoteServer.impl.runtime.ui.tree.DeploymentNode; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServerNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Set; - /** * @author michael.golubev */ -public class DeployAction extends ServersTreeActionBase { +public class DeployAction extends ServersTreeAction { + public DeployAction() { super("Deploy", "Deploy the selected item", AllIcons.Nodes.Deploy); } @Override - protected void updatePresentation(@NotNull Presentation presentation, @Nullable ServersToolWindowContent content) { - if (content != null) { - Set nodes = content.getSelectedDeploymentNodes(); - if (nodes.size() == 1) { - DeploymentNode node = nodes.iterator().next(); - if (node.isDeployed()) { - presentation.setText("Redeploy"); - presentation.setDescription("Redeploy '" + node.getDeploymentName() + "'"); - return; - } - } - } - presentation.setText(getTemplatePresentation().getText()); - presentation.setDescription(getTemplatePresentation().getDescription()); + protected Class getTargetNodeClass() { + return DeploymentNode.class; } @Override - protected boolean isEnabled(@NotNull ServersToolWindowContent content, AnActionEvent e) { - Set deploymentNodes = content.getSelectedDeploymentNodes(); - Set serverNodes = content.getSelectedServerNodes(); - if (deploymentNodes.size() + serverNodes.size() != 1) return false; - for (DeploymentNode node : deploymentNodes) { - if (!node.isRedeployActionEnabled()) { - return false; - } + protected void updatePresentation(@NotNull Presentation presentation, @Nullable DeploymentNode node) { + if (node != null && node.isDeployed()) { + presentation.setText("Redeploy"); + presentation.setDescription("Redeploy '" + node.getDeploymentName() + "'"); } - for (ServerNode serverNode : serverNodes) { - if (!serverNode.isDeployActionEnabled()) { - return false; - } + else { + presentation.setText(getTemplatePresentation().getText()); + presentation.setDescription(getTemplatePresentation().getDescription()); } - return true; } @Override - protected void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e) { - for (DeploymentNode node : content.getSelectedDeploymentNodes()) { - node.redeploy(); - } - for (ServerNode node : content.getSelectedServerNodes()) { - node.deploy(e); - } + protected boolean isVisible4(DeploymentNode node) { + return node.isDeployActionVisible(); + } + + @Override + protected boolean isEnabled4(DeploymentNode node) { + return node.isDeployActionEnabled(); + } + + @Override + protected void doActionPerformed(DeploymentNode node) { + node.deploy(); } } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployAllAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployAllAction.java deleted file mode 100644 index 818f0ad7619e..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployAllAction.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.icons.AllIcons; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServerNode; -import org.jetbrains.annotations.NotNull; - -/** - * @author michael.golubev - */ -public class DeployAllAction extends ServerActionBase { - - public DeployAllAction() { - super("Deploy All", "Deploy all the artifacts of the selected server", AllIcons.Nodes.Deploy); - } - - @Override - protected void performAction(@NotNull ServerNode serverNode) { - if (serverNode.isDeployAllActionEnabled()) { - serverNode.deployAll(); - } - } - - @Override - protected boolean isEnabledForServer(@NotNull ServerNode serverNode) { - return serverNode.isDeployAllActionEnabled(); - } -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployWithDebugAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployWithDebugAction.java new file mode 100644 index 000000000000..d9c00380b9e2 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeployWithDebugAction.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.icons.AllIcons; +import com.intellij.remoteServer.impl.runtime.ui.tree.DeploymentNode; + +public class DeployWithDebugAction extends ServersTreeAction { + + public DeployWithDebugAction() { + super("Debug", "Deploy and debug the selected item", AllIcons.Actions.StartDebugger); + } + + @Override + protected Class getTargetNodeClass() { + return DeploymentNode.class; + } + + @Override + protected boolean isVisible4(DeploymentNode node) { + return node.isDeployActionVisible() && node.isDebugActionVisible(); + } + + @Override + protected boolean isEnabled4(DeploymentNode node) { + return node.isDeployActionEnabled(); + } + + @Override + protected void doActionPerformed(DeploymentNode node) { + node.deployWithDebug(); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeploymentActionBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeploymentActionBase.java deleted file mode 100644 index 27bace389c41..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeploymentActionBase.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; -import com.intellij.remoteServer.impl.runtime.ui.tree.DeploymentNode; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * @author nik - */ -public abstract class DeploymentActionBase extends ServersTreeActionBase { - protected DeploymentActionBase(String text, String description, Icon icon) { - super(text, description, icon); - } - - protected abstract void perform(@NotNull List nodes, ServersToolWindowContent content, AnActionEvent e); - - protected abstract boolean isApplicable(@NotNull DeploymentNode node); - - @Override - public void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e) { - List toPerform = new ArrayList(); - for (DeploymentNode node : content.getSelectedDeploymentNodes()) { - if (isApplicable(node)) { - toPerform.add(node); - } - } - if (!toPerform.isEmpty()) { - perform(toPerform, content, e); - } - } - - @Override - protected boolean isEnabled(@NotNull ServersToolWindowContent content, AnActionEvent e) { - Set selectedElements = content.getBuilder().getSelectedElements(); - if (selectedElements.isEmpty() || selectedElements.size() != content.getSelectedDeploymentNodes().size()) { - return false; - } - - for (DeploymentNode node : content.getSelectedDeploymentNodes()) { - if (!isApplicable(node)) { - return false; - } - } - return true; - } -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeploymentConfigAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeploymentConfigAction.java new file mode 100644 index 000000000000..e7f1960ae41f --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/DeploymentConfigAction.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; + +public class DeploymentConfigAction extends EditConfigurationActionBase { + + public DeploymentConfigAction() { + super("Edit the selected deployment run configuration"); + } + + @Override + protected Class getTargetNodeClass() { + return ServersTreeStructure.DeploymentNodeImpl.class; + } + + @Override + protected boolean isVisible4(ServersTreeStructure.DeploymentNodeImpl node) { + return node.isEditConfigurationActionVisible(); + } + + @Override + protected void doActionPerformed(ServersTreeStructure.DeploymentNodeImpl node) { + node.editConfiguration(); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/EditConfigurationAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/EditConfigurationAction.java deleted file mode 100644 index 75d22a854114..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/EditConfigurationAction.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; -import com.intellij.remoteServer.impl.runtime.ui.tree.DeploymentNode; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServerNode; -import org.jetbrains.annotations.NotNull; - -import java.util.Set; - -/** - * @author michael.golubev - */ -public class EditConfigurationAction extends ServersTreeActionBase { - public EditConfigurationAction() { - super("Edit Configuration", "Edit configuration of the selected server", AllIcons.Actions.EditSource); - } - - @Override - protected void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e) { - Set deploymentNodes = content.getSelectedDeploymentNodes(); - Set serverNodes = content.getSelectedServerNodes(); - if (deploymentNodes.size() == 1) { - deploymentNodes.iterator().next().editConfiguration(); - } - else { - serverNodes.iterator().next().editConfiguration(); - } - } - - @Override - protected boolean isEnabled(@NotNull ServersToolWindowContent content, AnActionEvent e) { - Set deploymentNodes = content.getSelectedDeploymentNodes(); - Set serverNodes = content.getSelectedServerNodes(); - if (deploymentNodes.size() + serverNodes.size() != 1) return false; - if (deploymentNodes.size() == 1) { - return deploymentNodes.iterator().next().isEditConfigurationActionEnabled(); - } - return true; - } -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/EditConfigurationActionBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/EditConfigurationActionBase.java new file mode 100644 index 000000000000..05fcb95fede5 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/EditConfigurationActionBase.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.icons.AllIcons; +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeNode; + +public abstract class EditConfigurationActionBase extends ServersTreeAction { + + public EditConfigurationActionBase(String description) { + super("Edit Configuration", description, AllIcons.Actions.EditSource); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerConfigAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerConfigAction.java new file mode 100644 index 000000000000..b5f5456318da --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerConfigAction.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; + +public class RemoteServerConfigAction extends EditConfigurationActionBase { + + public RemoteServerConfigAction() { + super("Edit the selected remote server configuration"); + } + + @Override + protected Class getTargetNodeClass() { + return ServersTreeStructure.RemoteServerNode.class; + } + + @Override + protected void doActionPerformed(ServersTreeStructure.RemoteServerNode node) { + node.editConfiguration(); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerConnectAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerConnectAction.java new file mode 100644 index 000000000000..8fd5f7891748 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerConnectAction.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.icons.AllIcons; +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; +import com.intellij.remoteServer.runtime.ServerConnectionManager; + +public class RemoteServerConnectAction extends ServersTreeAction { + + public RemoteServerConnectAction() { + super("Connect", "Connect to the selected remote server", AllIcons.Actions.Execute); + } + + @Override + protected Class getTargetNodeClass() { + return ServersTreeStructure.RemoteServerNode.class; + } + + @Override + protected boolean isEnabled4(ServersTreeStructure.RemoteServerNode node) { + return !node.isConnected(); + } + + @Override + protected void doActionPerformed(ServersTreeStructure.RemoteServerNode node) { + ServerConnectionManager.getInstance().getOrCreateConnection(node.getValue()); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerDisconnectAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerDisconnectAction.java new file mode 100644 index 000000000000..96f21e56671f --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RemoteServerDisconnectAction.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 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.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.icons.AllIcons; +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; +import com.intellij.remoteServer.runtime.ServerConnection; +import com.intellij.remoteServer.runtime.ServerConnectionManager; + +public class RemoteServerDisconnectAction extends ServersTreeAction { + + public RemoteServerDisconnectAction() { + super("Disconnect", "Disconnect from the selected remote server", AllIcons.Actions.Suspend); + } + + @Override + protected Class getTargetNodeClass() { + return ServersTreeStructure.RemoteServerNode.class; + } + + @Override + protected boolean isEnabled4(ServersTreeStructure.RemoteServerNode node) { + return node.isConnected(); + } + + @Override + protected void doActionPerformed(ServersTreeStructure.RemoteServerNode node) { + ServerConnection connection = ServerConnectionManager.getInstance().getConnection(node.getValue()); + if (connection != null) { + connection.disconnect(); + } + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RunServerAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RunServerAction.java deleted file mode 100644 index aa16c77e2aeb..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RunServerAction.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.execution.Executor; -import com.intellij.execution.executors.DefaultRunExecutor; -import com.intellij.icons.AllIcons; - -/** - * @author michael.golubev - */ -public class RunServerAction extends RunServerActionBase { - - public RunServerAction() { - super("Run/Connect", "Run/Connect to the selected server", AllIcons.Actions.Execute); - } - - @Override - protected Executor getExecutor() { - return DefaultRunExecutor.getRunExecutorInstance(); - } -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RunServerActionBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RunServerActionBase.java deleted file mode 100644 index 07b1e4b683f1..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/RunServerActionBase.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - - -import com.intellij.execution.Executor; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServerNode; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; - -/** - * @author michael.golubev - */ -public abstract class RunServerActionBase extends ServerActionBase { - - protected RunServerActionBase(String text, String description, Icon icon) { - super(text, description, icon); - } - - protected void performAction(@NotNull ServerNode serverNode) { - if (serverNode.isStartActionEnabled(getExecutor())) { - serverNode.startServer(getExecutor()); - } - } - - @Override - protected boolean isEnabledForServer(@NotNull ServerNode serverNode) { - return serverNode.isStartActionEnabled(getExecutor()); - } - - protected abstract Executor getExecutor(); -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServerActionBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServerActionBase.java deleted file mode 100644 index 1b4d4f8bbd89..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServerActionBase.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServerNode; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.util.Set; - -/** - * @author michael.golubev - */ -public abstract class ServerActionBase extends ServersTreeActionBase { - - protected ServerActionBase(String text, String description, Icon icon) { - super(text, description, icon); - } - - @Override - protected final boolean isEnabled(@NotNull ServersToolWindowContent content, AnActionEvent e) { - Set selectedServerNodes = content.getSelectedServerNodes(); - Set selectedElements = content.getBuilder().getSelectedElements(); - if (selectedElements.size() != selectedServerNodes.size() || selectedElements.isEmpty()) { - return false; - } - - for (ServerNode selectedServer : selectedServerNodes) { - if (!isEnabledForServer(selectedServer)) { - return false; - } - } - return true; - } - - @Override - protected void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e) { - for (ServerNode node : content.getSelectedServerNodes()) { - performAction(node); - } - } - - protected abstract void performAction(@NotNull ServerNode serverNode); - - protected abstract boolean isEnabledForServer(@NotNull ServerNode serverNode); -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServersTreeAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServersTreeAction.java new file mode 100644 index 000000000000..d86a708196d2 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServersTreeAction.java @@ -0,0 +1,91 @@ +package com.intellij.remoteServer.impl.runtime.ui.tree.actions; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.Set; + +public abstract class ServersTreeAction extends AnAction { + + protected ServersTreeAction(String text, String description, Icon icon) { + super(text, description, icon); + } + + @Override + public void update(@NotNull AnActionEvent e) { + Presentation presentation = e.getPresentation(); + T targetNode = getTargetNode(e); + + boolean visible = false; + boolean enabled = false; + + if (targetNode != null) { + visible = isVisible4(targetNode); + if (visible) { + enabled = isEnabled4(targetNode); + } + } + + presentation.setVisible(visible); + presentation.setEnabled(enabled); + updatePresentation(presentation, targetNode); + } + + private T getTargetNode(AnActionEvent e) { + ServersToolWindowContent content = getContent(e); + if (content == null) { + return null; + } + Set selectedElements = content.getBuilder().getSelectedElements(); + if (selectedElements.size() != 1) { + return null; + } + ServersTreeNode node = (ServersTreeNode)selectedElements.iterator().next(); + Class targetNodeClass = getTargetNodeClass(); + if (!targetNodeClass.isInstance(node)) { + return null; + } + return targetNodeClass.cast(node); + } + + private static ServersToolWindowContent getContent(AnActionEvent e) { + return e.getData(ServersToolWindowContent.KEY); + } + + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + T targetNode = getTargetNode(e); + if (targetNode != null && isVisible4(targetNode) && isEnabled4(targetNode)) { + doActionPerformed(getContent(e), e, targetNode); + } + } + + + protected boolean isVisible4(T node) { + return true; + } + + protected boolean isEnabled4(T node) { + return true; + } + + protected void updatePresentation(@NotNull Presentation presentation, @Nullable T node) { + } + + + protected void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e, T node) { + doActionPerformed(node); + } + + protected void doActionPerformed(T node) { + throw new UnsupportedOperationException(); + } + + protected abstract Class getTargetNodeClass(); +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServersTreeActionBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServersTreeActionBase.java deleted file mode 100644 index 7e505bd06aab..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/ServersTreeActionBase.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -/** - * @author michael.golubev - */ -public abstract class ServersTreeActionBase extends AnAction { - - protected ServersTreeActionBase(String text, String description, Icon icon) { - super(text, description, icon); - } - - @Override - public void update(AnActionEvent e) { - ServersToolWindowContent content = e.getData(ServersToolWindowContent.KEY); - Presentation presentation = e.getPresentation(); - presentation.setEnabled(content != null && isEnabled(content, e)); - updatePresentation(presentation, content); - } - - protected void updatePresentation(@NotNull Presentation presentation, @Nullable ServersToolWindowContent content) { - } - - @Override - public void actionPerformed(AnActionEvent e) { - ServersToolWindowContent content = e.getData(ServersToolWindowContent.KEY); - if (content == null) { - return; - } - doActionPerformed(content, e); - } - - protected abstract boolean isEnabled(@NotNull ServersToolWindowContent content, AnActionEvent e); - - protected abstract void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e); -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/SingleServerActionBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/SingleServerActionBase.java deleted file mode 100644 index 50ec63646922..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/SingleServerActionBase.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2000-2013 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.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServerNode; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.util.Set; - -/** - * @author michael.golubev - */ -public abstract class SingleServerActionBase extends ServersTreeActionBase { - protected SingleServerActionBase(String text, String description, Icon icon) { - super(text, description, icon); - } - - @Override - protected void doActionPerformed(@NotNull ServersToolWindowContent content, AnActionEvent e) { - doActionPerformed(content, content.getSelectedServerNodes().iterator().next()); - } - - @Override - protected boolean isEnabled(@NotNull ServersToolWindowContent content, AnActionEvent e) { - Set serverNodes = content.getSelectedServerNodes(); - return content.getBuilder().getSelectedElements().size() == serverNodes.size() && serverNodes.size() == 1 && - isEnabledForServer(serverNodes.iterator().next()); - } - - protected abstract boolean isEnabledForServer(ServerNode serverNode); - - protected abstract void doActionPerformed(@NotNull ServersToolWindowContent content, @NotNull ServerNode server); -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/StopServerAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/StopServerAction.java deleted file mode 100644 index 7984c119036c..000000000000 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/StopServerAction.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.intellij.remoteServer.impl.runtime.ui.tree.actions; - -import com.intellij.icons.AllIcons; -import com.intellij.remoteServer.impl.runtime.ui.tree.ServerNode; -import org.jetbrains.annotations.NotNull; - -/** - * @author michael.golubev - */ -public class StopServerAction extends ServerActionBase { - - public StopServerAction() { - super("Stop/Disconnect", "Stop/disconnect from the selected server", AllIcons.Actions.Suspend); - } - - protected void performAction(@NotNull ServerNode serverNode) { - if (serverNode.isStopActionEnabled()) { - serverNode.stopServer(); - } - } - - @Override - protected boolean isEnabledForServer(@NotNull ServerNode serverNode) { - return serverNode.isStopActionEnabled(); - } -} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/UndeployAction.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/UndeployAction.java index bc11f8aa94a8..50c247eabd91 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/UndeployAction.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/tree/actions/UndeployAction.java @@ -1,30 +1,29 @@ package com.intellij.remoteServer.impl.runtime.ui.tree.actions; import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowContent; import com.intellij.remoteServer.impl.runtime.ui.tree.DeploymentNode; -import org.jetbrains.annotations.NotNull; - -import java.util.List; /** * @author michael.golubev */ -public class UndeployAction extends DeploymentActionBase { +public class UndeployAction extends ServersTreeAction { + public UndeployAction() { super("Undeploy", "Undeploy the selected item", AllIcons.Nodes.Undeploy); } @Override - protected boolean isApplicable(@NotNull DeploymentNode node) { + protected Class getTargetNodeClass() { + return DeploymentNode.class; + } + + @Override + protected boolean isEnabled4(DeploymentNode node) { return node.isUndeployActionEnabled(); } @Override - protected void perform(@NotNull List nodes, ServersToolWindowContent content, AnActionEvent e) { - for (DeploymentNode node : nodes) { - node.undeploy(); - } + protected void doActionPerformed(DeploymentNode node) { + node.undeploy(); } }