Docker integration - separate tool window

This commit is contained in:
Michael Golubev
2016-01-21 18:02:37 +01:00
parent 702eb8868f
commit 830a4cb995
11 changed files with 246 additions and 58 deletions
@@ -82,4 +82,9 @@ public abstract class ServerType<C extends ServerConfiguration> {
}
};
}
@Nullable
public String getCustomToolWindowId() {
return null;
}
}
@@ -37,8 +37,8 @@
<applicationService serviceInterface="com.intellij.remoteServer.impl.runtime.log.CloudTerminalProvider"
serviceImplementation="com.intellij.remoteServer.impl.runtime.log.ConsoleTerminalProvider"/>
<toolWindow id="Application Servers" anchor="bottom" icon="RemoteServersIcons.ServersToolWindow"
factoryClass="com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowFactory"
conditionClass="com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowFactory"/>
factoryClass="com.intellij.remoteServer.impl.runtime.ui.DefaultServersToolWindowFactory"
conditionClass="com.intellij.remoteServer.impl.runtime.ui.DefaultServersToolWindowFactory"/>
</extensions>
<application-components>
<component>
@@ -47,7 +47,7 @@
</application-components>
<project-components>
<component>
<implementation-class>com.intellij.remoteServer.impl.runtime.ui.ServersToolWindowManager</implementation-class>
<implementation-class>com.intellij.remoteServer.impl.runtime.ui.DefaultServersToolWindowManager</implementation-class>
</component>
</project-components>
@@ -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<AbstractTreeNode<?>> createServerNodes(Project project) {
List<AbstractTreeNode<?>> result = new ArrayList<AbstractTreeNode<?>>();
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<RemoteServer<?>> getRemoteServers() {
return ContainerUtil.filter(RemoteServersManager.getInstance().getServers(), new Condition<RemoteServer<?>>() {
@Override
public boolean value(RemoteServer<?> server) {
return server.getType().getCustomToolWindowId() == null;
}
});
}
}
@@ -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());
}
}
@@ -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();
}
}
@@ -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<RemoteServer<?>> getRemoteServers();
@Override
public boolean canContribute(@NotNull Project project) {
return !getRemoteServers().isEmpty();
}
}
@@ -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);
}
}
@@ -70,10 +70,12 @@ public class ServersToolWindowContent extends JPanel implements Disposable {
private Set<Object> myCollapsedTreeNodeValues = new HashSet<Object>();
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);
@@ -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<Project> {
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<Pr
@Override
public boolean value(Project project) {
return isAvailable(project);
return myContribution.canContribute(project);
}
public static boolean isAvailable(Project project) {
if (!RemoteServersManager.getInstance().getServers().isEmpty()) {
return true;
}
for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) {
if (contributor.canContribute(project)) {
return true;
}
}
return false;
public RemoteServersViewContribution getContribution() {
return myContribution;
}
}
@@ -26,12 +26,13 @@ import com.intellij.remoteServer.configuration.RemoteServerListener;
import icons.RemoteServersIcons;
import org.jetbrains.annotations.NotNull;
public class ServersToolWindowManager extends AbstractProjectComponent {
public abstract class ServersToolWindowManager extends AbstractProjectComponent {
public static final String WINDOW_ID = "Application Servers";
private final String myWindowId;
public ServersToolWindowManager(final Project project) {
public ServersToolWindowManager(final Project project, String windowId) {
super(project);
myWindowId = windowId;
}
public void projectOpened() {
@@ -43,14 +44,12 @@ public class ServersToolWindowManager extends AbstractProjectComponent {
}
public void setupListeners() {
for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) {
contributor.setupAvailabilityListener(myProject, new Runnable() {
@Override
public void run() {
updateWindowAvailable(true);
}
});
}
getFactory().getContribution().setupAvailabilityListener(myProject, new Runnable() {
@Override
public void run() {
updateWindowAvailable(true);
}
});
myProject.getMessageBus().connect().subscribe(RemoteServerListener.TOPIC, new RemoteServerListener() {
@Override
public void serverAdded(@NotNull RemoteServer<?> 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();
}
@@ -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<RemoteServer, Map<String, DeploymentGroup>> myServer2DeploymentGroups
= new HashMap<RemoteServer, Map<String, DeploymentGroup>>();
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<? extends AbstractTreeNode> getChildren() {
List<AbstractTreeNode<?>> result = new ArrayList<AbstractTreeNode<?>>();
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<RemoteServer<?>, AbstractTreeNode<?>>() {
@Override
public AbstractTreeNode<?> fun(RemoteServer<?> server) {
return new RemoteServerNode(server);
}
}));
return result;
}