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 index cf0575aed205..47271ff63152 100644 --- 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 @@ -15,8 +15,11 @@ */ package com.intellij.remoteServer.impl.runtime.ui; +import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.openapi.project.Project; import com.intellij.remoteServer.configuration.RemoteServer; +import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure; +import com.intellij.remoteServer.runtime.ServerConnection; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -29,4 +32,29 @@ public abstract class RemoteServersViewContribution extends RemoteServersViewCon public boolean canContribute(@NotNull Project project) { return !getRemoteServers().isEmpty(); } + + public ServersTreeStructure createTreeStructure(@NotNull final Project project) { + return new ServersTreeStructure(project, this); + } + + public TreeNodeSelector createLogNodeSelector(final ServerConnection connection, + final String deploymentName, + final String logName) { + return new TreeNodeSelector() { + @Override + public boolean visit(@NotNull ServersTreeStructure.DeploymentLogNode node) { + AbstractTreeNode parent = node.getParent(); + return parent instanceof ServersTreeStructure.DeploymentNodeImpl + && + ServersToolWindowContent.isDeploymentNodeMatch((ServersTreeStructure.DeploymentNodeImpl)parent, connection, deploymentName) + && + node.getValue().getPresentableName().equals(logName); + } + + @Override + public Class getNodeClass() { + return ServersTreeStructure.DeploymentLogNode.class; + } + }; + } } 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 550f30fb9a1b..02925d01adf4 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 @@ -210,7 +210,7 @@ public class ServersToolWindowContent extends JPanel implements Disposable { } private void setupBuilder(final @NotNull Project project) { - ServersTreeStructure structure = new ServersTreeStructure(project, myContribution); + ServersTreeStructure structure = myContribution.createTreeStructure(project); myBuilder = new TreeBuilderBase(myTree, structure, myTreeModel) { @Override protected boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) { @@ -338,15 +338,8 @@ public class ServersToolWindowContent extends JPanel implements Disposable { myBuilder.getUi().queueUpdate(connection).doWhenDone(new Runnable() { @Override public void run() { - myBuilder.select(ServersTreeStructure.DeploymentLogNode.class, new TreeVisitor() { - @Override - public boolean visit(@NotNull ServersTreeStructure.DeploymentLogNode node) { - AbstractTreeNode parent = node.getParent(); - return parent instanceof ServersTreeStructure.DeploymentNodeImpl - && isDeploymentNodeMatch((ServersTreeStructure.DeploymentNodeImpl)parent, connection, deploymentName) - && node.getValue().getPresentableName().equals(logName); - } - }, null, false); + TreeNodeSelector nodeSelector = myContribution.createLogNodeSelector(connection, deploymentName, logName); + myBuilder.select(nodeSelector.getNodeClass(), nodeSelector, null, false); } }); } @@ -356,8 +349,8 @@ public class ServersToolWindowContent extends JPanel implements Disposable { return node.getServer().equals(connection.getServer()); } - private static boolean isDeploymentNodeMatch(@NotNull ServersTreeStructure.DeploymentNodeImpl node, - @NotNull final ServerConnection connection, @NotNull final String deploymentName) { + public static boolean isDeploymentNodeMatch(@NotNull ServersTreeStructure.DeploymentNodeImpl node, + @NotNull final ServerConnection connection, @NotNull final String deploymentName) { ServersTreeStructure.RemoteServerNode serverNode = node.getServerNode(); return isServerNodeMatch(serverNode, connection) && node.getDeployment().getName().equals(deploymentName); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/TreeNodeSelector.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/TreeNodeSelector.java new file mode 100644 index 000000000000..f4eb4eea7d75 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/TreeNodeSelector.java @@ -0,0 +1,25 @@ +/* + * 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.TreeVisitor; +import org.jetbrains.annotations.NotNull; + +public interface TreeNodeSelector extends TreeVisitor { + boolean visit(@NotNull T node); + + Class getNodeClass(); +} 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 fe713148554d..8a78c702171e 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 @@ -89,7 +89,7 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { } @NotNull - Project doGetProject() { + protected Project doGetProject() { return myProject; } @@ -107,6 +107,10 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { return false; } + protected AbstractTreeNode createDeploymentNode(ServerConnection connection, RemoteServerNode serverNode, Deployment deployment) { + return new DeploymentNodeImpl(connection, serverNode, deployment); + } + public interface LogProvidingNode { @Nullable JComponent getComponent(); @@ -162,7 +166,7 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { for (Deployment deployment : connection.getDeployments()) { final String groupName = deployment.getGroup(); if (groupName == null) { - children.add(new DeploymentNodeImpl(connection, this, deployment)); + children.add(createDeploymentNode(connection, this, deployment)); } else { Map groups @@ -293,7 +297,7 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { private final ServerConnection myConnection; private final RemoteServerNode myServerNode; - private DeploymentNodeImpl(@NotNull ServerConnection connection, @NotNull RemoteServerNode serverNode, @NotNull Deployment value) { + protected DeploymentNodeImpl(@NotNull ServerConnection connection, @NotNull RemoteServerNode serverNode, @NotNull Deployment value) { super(doGetProject(), value); myConnection = connection; myServerNode = serverNode; @@ -399,7 +403,7 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { } @Nullable - private DeploymentLogManagerImpl getLogManager() { + protected DeploymentLogManagerImpl getLogManager() { return (DeploymentLogManagerImpl)myConnection.getLogManager(getDeployment()); } @@ -508,7 +512,7 @@ public class ServersTreeStructure extends AbstractTreeStructureBase { List children = new ArrayList(); for (Deployment deployment : myConnection.getDeployments()) { if (StringUtil.equals(getGroup().getName(), deployment.getGroup())) { - children.add(new DeploymentNodeImpl(myConnection, myServerNode, deployment)); + children.add(createDeploymentNode(myConnection, myServerNode, deployment)); } } return children;