diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/ServerType.java b/platform/remote-servers/api/src/com/intellij/remoteServer/ServerType.java index 34452ce5c15e..df82845f36e7 100644 --- a/platform/remote-servers/api/src/com/intellij/remoteServer/ServerType.java +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/ServerType.java @@ -82,4 +82,9 @@ public abstract class ServerType { } }; } + + @Nullable + public String getCustomToolWindowId() { + return null; + } } diff --git a/platform/remote-servers/impl/src/META-INF/RemoteServers.xml b/platform/remote-servers/impl/src/META-INF/RemoteServers.xml index 9aa2881cb4a6..be992ce3ce15 100644 --- a/platform/remote-servers/impl/src/META-INF/RemoteServers.xml +++ b/platform/remote-servers/impl/src/META-INF/RemoteServers.xml @@ -37,8 +37,8 @@ + factoryClass="com.intellij.remoteServer.impl.runtime.ui.DefaultServersToolWindowFactory" + conditionClass="com.intellij.remoteServer.impl.runtime.ui.DefaultServersToolWindowFactory"/> @@ -47,7 +47,7 @@ - com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowManager + com.intellij.remoteServer.impl.runtime.ui.DefaultServersToolWindowManager diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultRemoteServersViewContribution.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultRemoteServersViewContribution.java new file mode 100644 index 000000000000..861119867f44 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultRemoteServersViewContribution.java @@ -0,0 +1,92 @@ +/* + * Copyright 2000-2016 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; + +import com.intellij.ide.util.treeView.AbstractTreeNode; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Condition; +import com.intellij.remoteServer.configuration.RemoteServer; +import com.intellij.remoteServer.configuration.RemoteServersManager; +import com.intellij.remoteServer.impl.runtime.ui.tree.TreeBuilderBase; +import com.intellij.ui.treeStructure.Tree; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class DefaultRemoteServersViewContribution extends RemoteServersViewContribution { + + @Override + public boolean canContribute(@NotNull Project project) { + if (super.canContribute(project)) { + return true; + } + for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { + if (contributor.canContribute(project)) { + return true; + } + } + return false; + } + + @Override + public void setupAvailabilityListener(@NotNull Project project, @NotNull Runnable checkAvailability) { + for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { + contributor.setupAvailabilityListener(project, checkAvailability); + } + } + + @Override + public void setupTree(Project project, Tree tree, TreeBuilderBase builder) { + for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { + contributor.setupTree(project, tree, builder); + } + } + + @NotNull + @Override + public List> createServerNodes(Project project) { + List> result = new ArrayList>(); + for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { + result.addAll(contributor.createServerNodes(project)); + } + return result; + } + + @Nullable + @Override + public Object getData(@NotNull String dataId, @NotNull ServersToolWindowContent content) { + for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { + Object data = contributor.getData(dataId, content); + if (data != null) { + return data; + } + } + return null; + } + + @Override + public List> getRemoteServers() { + return ContainerUtil.filter(RemoteServersManager.getInstance().getServers(), new Condition>() { + @Override + public boolean value(RemoteServer server) { + return server.getType().getCustomToolWindowId() == null; + } + }); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultServersToolWindowFactory.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultServersToolWindowFactory.java new file mode 100644 index 000000000000..23e388123dfe --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultServersToolWindowFactory.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2016 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; + +public class DefaultServersToolWindowFactory extends ServersToolWindowFactory { + + public DefaultServersToolWindowFactory() { + super(new DefaultRemoteServersViewContribution()); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultServersToolWindowManager.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultServersToolWindowManager.java new file mode 100644 index 000000000000..25c24257a954 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/DefaultServersToolWindowManager.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2016 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; + +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +public class DefaultServersToolWindowManager extends ServersToolWindowManager { + + public static final String WINDOW_ID = "Application Servers"; + + public DefaultServersToolWindowManager(Project project) { + super(project, WINDOW_ID); + } + + @NotNull + public String getComponentName() { + return "ServersToolWindowManager"; + } + + @NotNull + @Override + protected ServersToolWindowFactory getFactory() { + return new DefaultServersToolWindowFactory(); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersViewContribution.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersViewContribution.java new file mode 100644 index 000000000000..cf0575aed205 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersViewContribution.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2016 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; + +import com.intellij.openapi.project.Project; +import com.intellij.remoteServer.configuration.RemoteServer; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public abstract class RemoteServersViewContribution extends RemoteServersViewContributor { + + public abstract List> getRemoteServers(); + + @Override + public boolean canContribute(@NotNull Project project) { + return !getRemoteServers().isEmpty(); + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersViewImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersViewImpl.java index 98d351d90cc1..ae6d2c91374a 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersViewImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersViewImpl.java @@ -1,6 +1,7 @@ package com.intellij.remoteServer.impl.runtime.ui; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.remoteServer.runtime.ServerConnection; @@ -20,7 +21,7 @@ public class RemoteServersViewImpl extends RemoteServersView { @Override public void showServerConnection(@NotNull final ServerConnection connection) { - final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ServersToolWindowManager.WINDOW_ID); + final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(getToolWindowId(connection)); if (toolWindow != null) { toolWindow.activate(new Runnable() { @Override @@ -42,7 +43,7 @@ public class RemoteServersViewImpl extends RemoteServersView { @Override public void showDeployment(@NotNull final ServerConnection connection, @NotNull final String deploymentName) { ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject); - final ToolWindow toolWindow = toolWindowManager.getToolWindow(ServersToolWindowManager.WINDOW_ID); + final ToolWindow toolWindow = toolWindowManager.getToolWindow(getToolWindowId(connection)); if (toolWindow != null) { toolWindowManager.invokeLater(new Runnable() { @Override @@ -55,4 +56,9 @@ public class RemoteServersViewImpl extends RemoteServersView { }); } } + + private static String getToolWindowId(ServerConnection connection) { + String customToolWindowId = connection.getServer().getType().getCustomToolWindowId(); + return StringUtil.notNullize(customToolWindowId, DefaultServersToolWindowManager.WINDOW_ID); + } } 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 87ebf9a852df..550f30fb9a1b 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 @@ -70,10 +70,12 @@ public class ServersToolWindowContent extends JPanel implements Disposable { private Set myCollapsedTreeNodeValues = new HashSet(); private final Project myProject; + private final RemoteServersViewContribution myContribution; - public ServersToolWindowContent(@NotNull Project project) { + public ServersToolWindowContent(@NotNull Project project, @NotNull RemoteServersViewContribution contribution) { super(new BorderLayout()); myProject = project; + myContribution = contribution; myTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); myTree = new Tree(myTreeModel); @@ -95,9 +97,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable { setupBuilder(project); - for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { - contributor.setupTree(myProject, myTree, myBuilder); - } + contribution.setupTree(myProject, myTree, myBuilder); myTree.addTreeSelectionListener(new TreeSelectionListener() { @Override @@ -210,7 +210,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable { } private void setupBuilder(final @NotNull Project project) { - ServersTreeStructure structure = new ServersTreeStructure(project); + ServersTreeStructure structure = new ServersTreeStructure(project, myContribution); myBuilder = new TreeBuilderBase(myTree, structure, myTreeModel) { @Override protected boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) { @@ -285,13 +285,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable { if (KEY.getName().equals(dataId)) { return ServersToolWindowContent.this; } - for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { - Object data = contributor.getData(dataId, ServersToolWindowContent.this); - if (data != null) { - return data; - } - } - return null; + return myContribution.getData(dataId, ServersToolWindowContent.this); } }); actionToolBar.setTargetComponent(myTree); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowFactory.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowFactory.java index 6fc065fdbf18..2f0bf8b3a4b5 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowFactory.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/ServersToolWindowFactory.java @@ -20,17 +20,22 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowFactory; -import com.intellij.remoteServer.configuration.RemoteServersManager; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import org.jetbrains.annotations.NotNull; public class ServersToolWindowFactory implements ToolWindowFactory, Condition { + private final RemoteServersViewContribution myContribution; + + public ServersToolWindowFactory(RemoteServersViewContribution contribution) { + myContribution = contribution; + } + @Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); - final ServersToolWindowContent serversContent = new ServersToolWindowContent(project); + final ServersToolWindowContent serversContent = new ServersToolWindowContent(project, myContribution); Content content = contentFactory.createContent(serversContent.getMainPanel(), null, false); Disposer.register(content, serversContent); toolWindow.getContentManager().addContent(content); @@ -38,18 +43,10 @@ public class ServersToolWindowFactory implements ToolWindowFactory, Condition server) { @@ -71,9 +70,9 @@ public class ServersToolWindowManager extends AbstractProjectComponent { @Override public void run() { - boolean available = ServersToolWindowFactory.isAvailable(myProject); + boolean available = getFactory().getContribution().canContribute(myProject); - final ToolWindow toolWindow = toolWindowManager.getToolWindow(WINDOW_ID); + final ToolWindow toolWindow = toolWindowManager.getToolWindow(myWindowId); if (toolWindow == null) { if (available) { @@ -94,15 +93,13 @@ public class ServersToolWindowManager extends AbstractProjectComponent { }); } - private static ToolWindow createToolWindow(Project project, ToolWindowManager toolWindowManager) { - ToolWindow toolWindow = toolWindowManager.registerToolWindow(WINDOW_ID, false, ToolWindowAnchor.BOTTOM); + private ToolWindow createToolWindow(Project project, ToolWindowManager toolWindowManager) { + ToolWindow toolWindow = toolWindowManager.registerToolWindow(myWindowId, false, ToolWindowAnchor.BOTTOM); toolWindow.setIcon(RemoteServersIcons.ServersToolWindow); - new ServersToolWindowFactory().createToolWindowContent(project, toolWindow); + getFactory().createToolWindowContent(project, toolWindow); return toolWindow; } @NotNull - public String getComponentName() { - return "ServersToolWindowManager"; - } + protected abstract ServersToolWindowFactory getFactory(); } 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 9ad30facdf6b..fe713148554d 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 @@ -24,7 +24,6 @@ import com.intellij.openapi.util.Factory; 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; @@ -32,7 +31,7 @@ import com.intellij.remoteServer.impl.configuration.deployment.DeployToServerRun import com.intellij.remoteServer.impl.runtime.deployment.DeploymentTaskImpl; import com.intellij.remoteServer.impl.runtime.log.DeploymentLogManagerImpl; import com.intellij.remoteServer.impl.runtime.log.LoggingHandlerBase; -import com.intellij.remoteServer.impl.runtime.ui.RemoteServersViewContributor; +import com.intellij.remoteServer.impl.runtime.ui.RemoteServersViewContribution; import com.intellij.remoteServer.runtime.ConnectionStatus; import com.intellij.remoteServer.runtime.Deployment; import com.intellij.remoteServer.runtime.ServerConnection; @@ -42,6 +41,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.Function; import com.intellij.util.containers.ContainerUtil; import icons.RemoteServersIcons; import org.jetbrains.annotations.NotNull; @@ -60,13 +60,15 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { private final ServersTreeRootNode myRootElement; private final Project myProject; + private final RemoteServersViewContribution myContribution; private final Map> myServer2DeploymentGroups = new HashMap>(); - public ServersTreeStructure(@NotNull Project project) { + public ServersTreeStructure(@NotNull Project project, @NotNull RemoteServersViewContribution contribution) { super(project); myProject = project; + myContribution = contribution; myRootElement = new ServersTreeRootNode(); } @@ -122,12 +124,13 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { @Override public Collection getChildren() { List> result = new ArrayList>(); - for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { - result.addAll(contributor.createServerNodes(doGetProject())); - } - for (RemoteServer server : RemoteServersManager.getInstance().getServers()) { - result.add(new RemoteServerNode(server)); - } + result.addAll(myContribution.createServerNodes(doGetProject())); + result.addAll(ContainerUtil.map(myContribution.getRemoteServers(), new Function, AbstractTreeNode>() { + @Override + public AbstractTreeNode fun(RemoteServer server) { + return new RemoteServerNode(server); + } + })); return result; }