Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2015-11-19 16:52:55 -0500
committerRoland Grunberg2015-11-19 16:56:49 -0500
commit67af2cf84c9672e52906fd633b7921680faab5ed (patch)
treec257643b9b1e4ca26c80daa1ed00a1cd0167de69
parent9741c6b29b6a2a97ca4cc7c1901632e9269dedf4 (diff)
downloadorg.eclipse.linuxtools-67af2cf84c9672e52906fd633b7921680faab5ed.tar.gz
org.eclipse.linuxtools-67af2cf84c9672e52906fd633b7921680faab5ed.tar.xz
org.eclipse.linuxtools-67af2cf84c9672e52906fd633b7921680faab5ed.zip
Bug 479856 - Add "Show in>Web Browser" and "Show in>File Browser"
Added a menu entry in the popup for the "Show In" group Added 2 menu contributions, one for the Web browser when a DockerContainerPort is selected, and the other one when a DockerContainerVolume is selected Opening in the System Explorer reuses some code borrowed from org.elipse.ui.ide with some adaptations because the host directory for the container volume is not necessarily a file or a folder in the workspace, hence it cannot be adapted (as in IAdaptable) into an IResource Change-Id: Ief810a5b89072c0eed673363df93efb0800ed80d Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/60815 Reviewed-by: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Activator.java7
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerPortMapping.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortMapping.java33
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/.classpath2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java278
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF1
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.properties8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.xml66
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/Activator.java7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandMessages.java38
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandMessages.properties7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java106
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInSystemExplorerCommandHandler.java149
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInWebBrowserCommandHandler.java105
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerContentProvider.java82
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerLabelProvider.java2
18 files changed, 817 insertions, 82 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Activator.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Activator.java
index 13a1bce73a..fe71cc209c 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Activator.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Activator.java
@@ -52,10 +52,15 @@ public class Activator extends Plugin {
Activator.getDefault().getLog().log(status);
}
- public static void logErrorMessage(String message) {
+ public static void logErrorMessage(final String message) {
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, null));
}
+ public static void logErrorMessage(final String message,
+ final Throwable e) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e));
+ }
+
public static void log(Throwable e) {
if (e instanceof InvocationTargetException)
e = ((InvocationTargetException) e).getTargetException();
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerPortMapping.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerPortMapping.java
index a9cd77f38b..410e80116e 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerPortMapping.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerPortMapping.java
@@ -15,7 +15,7 @@ package org.eclipse.linuxtools.docker.core;
* Port mapping for {@link IDockerContainer}
*
*/
-public interface IDockerPortMapping extends Comparable<IDockerPortMapping> {
+public interface IDockerPortMapping {
public int getPrivatePort();
@@ -25,4 +25,6 @@ public interface IDockerPortMapping extends Comparable<IDockerPortMapping> {
public String getIp();
+ public IDockerContainer getContainer();
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java
index 408bbdc637..5f3728e6dd 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java
@@ -54,7 +54,7 @@ public class DockerContainer implements IDockerContainer {
this.sizeRootFs = container.sizeRootFs();
this.ports = new ArrayList<>();
for (Container.PortMapping port : container.ports()) {
- final DockerPortMapping portMapping = new DockerPortMapping(
+ final DockerPortMapping portMapping = new DockerPortMapping(this,
port.getPrivatePort(), port.getPublicPort(), port.getType(),
port.getIp());
ports.add(portMapping);
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortMapping.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortMapping.java
index 28589d3095..d9d1e21882 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortMapping.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortMapping.java
@@ -14,9 +14,6 @@ package org.eclipse.linuxtools.internal.docker.core;
import org.eclipse.linuxtools.docker.core.IDockerContainer;
import org.eclipse.linuxtools.docker.core.IDockerPortMapping;
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
/**
* Port mapping for {@link IDockerContainer}
* @author xcoulon
@@ -32,9 +29,14 @@ public class DockerPortMapping implements IDockerPortMapping {
private final String ip;
+ private final IDockerContainer container;
+
/**
* Full constructor
*
+ * @param container
+ * the parent container
+ *
* @param privatePort
* private port
* @param publicPort
@@ -44,8 +46,10 @@ public class DockerPortMapping implements IDockerPortMapping {
* @param ip
* of port
*/
- @JsonCreator
- public DockerPortMapping(@JsonProperty("privatePort") int privatePort, @JsonProperty("publicPort") int publicPort, @JsonProperty("type") String type, @JsonProperty("ip") String ip) {
+ public DockerPortMapping(final IDockerContainer container,
+ final int privatePort, final int publicPort,
+ final String type, final String ip) {
+ this.container = container;
this.privatePort = privatePort;
this.publicPort = publicPort;
this.type = type;
@@ -53,18 +57,23 @@ public class DockerPortMapping implements IDockerPortMapping {
}
@Override
+ public IDockerContainer getContainer() {
+ return this.container;
+ }
+
+ @Override
public int getPrivatePort() {
- return privatePort;
+ return this.privatePort;
}
@Override
public int getPublicPort() {
- return publicPort;
+ return this.publicPort;
}
@Override
public String getType() {
- return type;
+ return this.type;
}
@Override
@@ -109,12 +118,4 @@ public class DockerPortMapping implements IDockerPortMapping {
return true;
}
- @Override
- public int compareTo(final IDockerPortMapping other) {
- return other.getPublicPort() - this.publicPort;
- }
-
-
-
-
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath b/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath
index 9b7ff0481d..cf36b56119 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java
new file mode 100644
index 0000000000..feb9fd7d39
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java
@@ -0,0 +1,278 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.commands;
+
+import java.util.stream.Stream;
+
+import org.assertj.core.api.Assertions;
+import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionStorageManager;
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionStorageManagerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerContainerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerContainerInfoFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerImageFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.PlatformUI;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import com.spotify.docker.client.DockerClient;
+
+/**
+ *
+ */
+public class CommandUtilsSWTBotTest {
+
+ private SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ private SWTBotView dockerExplorerViewBot;
+ private DockerExplorerView dockerExplorerView;
+
+ @ClassRule
+ public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule();
+
+ @Before
+ public void lookupDockerExplorerView() throws InterruptedException {
+ SWTUtils.asyncExec(() -> {
+ try {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .showView("org.eclipse.linuxtools.docker.ui.dockerExplorerView");
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail("Failed to open Docker Explorer view: " + e.getMessage());
+ }
+ });
+ dockerExplorerViewBot = bot.viewById("org.eclipse.linuxtools.docker.ui.dockerExplorerView");
+ dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference().getView(true));
+ bot.views().stream()
+ .filter(v -> v.getReference().getId().equals("org.eclipse.linuxtools.docker.ui.dockerContainersView")
+ || v.getReference().getId().equals("org.eclipse.linuxtools.docker.ui.dockerImagesView"))
+ .forEach(v -> v.close());
+ }
+
+ @After
+ public void clearConnectionManager() throws InterruptedException {
+ SWTUtils.syncExec(() -> {
+ Stream.of(DockerConnectionManager.getInstance().getConnections())
+ .forEach(c -> DockerConnectionManager.getInstance().removeConnection(c));
+ dockerExplorerView.getCommonViewer().refresh(true);
+ });
+ }
+
+ @AfterClass
+ public static void restoreDefaultConfig() {
+ DockerConnectionManager.getInstance().setConnectionStorageManager(new DefaultDockerConnectionStorageManager());
+ }
+
+ private void configureConnectionManager(final IDockerConnection... connections) throws InterruptedException {
+ DockerConnectionManager.getInstance()
+ .setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(connections));
+ SWTUtils.asyncExec(() -> {
+ DockerConnectionManager.getInstance().reloadConnections();
+ dockerExplorerView.getCommonViewer().refresh();
+ });
+
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedContainersCategory() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build()).build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ // when selecting the container
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Containers").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedContainer() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build()).build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ // when selecting the container
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Containers", "foo_bar").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedContainerLinksCategory() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(),
+ MockDockerContainerInfoFactory.link("/foo:/bar/foo").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
+ "Containers");
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(containersTreeItem, "foo_bar");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ // when selecting the port
+ SWTUtils.getTreeItem(containerTreeItem, "Links").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedContainerLink() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(),
+ MockDockerContainerInfoFactory.link("/foo:/bar/foo").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
+ "Containers");
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(containersTreeItem, "foo_bar");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ SWTUtils.asyncExec(() -> SWTUtils.getTreeItem(containerTreeItem, "Links").expand());
+ // when selecting the port
+ SWTUtils.getTreeItem(containerTreeItem, "Links", "foo (foo)").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedContainerVolumesCategory() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(),
+ MockDockerContainerInfoFactory.volume("/path/to/host:/path/to/container:Z,ro").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
+ "Containers");
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(containersTreeItem, "foo_bar");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ SWTUtils.asyncExec(() -> SWTUtils.getTreeItem(containerTreeItem, "Volumes").expand());
+ // when selecting the port
+ SWTUtils.getTreeItem(containerTreeItem, "Volumes").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedContainerVolume() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(),
+ MockDockerContainerInfoFactory.volume("/path/to/host:/path/to/container:Z,ro").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
+ "Containers");
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(containersTreeItem, "foo_bar");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ SWTUtils.asyncExec(() -> SWTUtils.getTreeItem(containerTreeItem, "Volumes").expand());
+ // when selecting the volume
+ SWTUtils.getTreeItem(containerTreeItem, "Volumes", "/path/to/host").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedContainerPortsCategory() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(),
+ MockDockerContainerInfoFactory.port("8080/tcp", "0.0.0.0", "8080").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
+ "Containers");
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(containersTreeItem, "foo_bar");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ // when selecting the port
+ SWTUtils.getTreeItem(containerTreeItem, "Ports").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedContainerPort() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(),
+ MockDockerContainerInfoFactory.port("8080/tcp", "0.0.0.0", "8080").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
+ "Containers");
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(containersTreeItem, "foo_bar");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ SWTUtils.asyncExec(() -> SWTUtils.getTreeItem(containerTreeItem, "Ports").expand());
+ // when selecting the port
+ SWTUtils.getTreeItem(containerTreeItem, "Ports", "0.0.0.0:8080 -> 8080 (tcp)").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedImagesCategory() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.images(MockDockerImageFactory.name("foo").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ // when selecting the images category
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+ @Test
+ public void shouldRetrieveConnectionFromSelectedImage() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.images(MockDockerImageFactory.name("foo").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ // when selecting the image
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo").select();
+ // then current connection should be found
+ Assertions.assertThat(CommandUtils.getCurrentConnection(dockerExplorerView)).isEqualTo(dockerConnection);
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF b/containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF
index ca3791af75..9150e20569 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF
+++ b/containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF
@@ -29,6 +29,7 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.linuxtools.docker.ui,
org.eclipse.linuxtools.docker.ui.launch,
org.eclipse.linuxtools.docker.ui.wizards,
+ org.eclipse.linuxtools.internal.docker.ui.commands;x-friends:="org.eclipse.linuxtools.docker.ui.tests",
org.eclipse.linuxtools.internal.docker.ui.preferences,
org.eclipse.linuxtools.internal.docker.ui.views;x-friends:="org.eclipse.linuxtools.docker.ui.tests",
org.eclipse.linuxtools.internal.docker.ui.wizards;x-friends:="org.eclipse.linuxtools.docker.ui.tests"
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
index 31a0d5c63b..e900cb56e2 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
@@ -101,3 +101,11 @@ command.addconnection.label=&Add Connection
command.runimage.name=Run Image
command.runimage.label=Run Image...
+
+menu.showIn=Show In
+
+command.showInWebBrowser.menu.name=Web Browser
+command.showInWebBrowser.menu.description=Show in Web Browser
+
+command.showInSystemExplorer.menu.name=System Explorer
+command.showInSystemExplorer.menu.descrption=Show in System Explorer
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
index cc12c92b17..3fa347c888 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
@@ -66,6 +66,7 @@
<insertionPoint name="group.edit" separator="true"/>
<insertionPoint name="group.logs" separator="true"/>
<insertionPoint name="group.tags" separator="true"/>
+ <insertionPoint name="group.showIn" separator="true"/>
</popupMenu>
<options>
<property
@@ -247,6 +248,17 @@
id="org.eclipse.linuxtools.docker.ui.commands.runImage"
name="%command.runimage.name">
</command>
+ <command
+ name="%command.showInWebBrowser.menu.name"
+ description="%command.showInWebBrowser.menu.description"
+ id="org.eclipse.linuxtools.docker.ui.commands.showInWebBrowser">
+ </command>
+ <command
+ name="%command.showInSystemExplorer.menu.name"
+ description="%command.showInSystemExplorer.menu.description"
+ id="org.eclipse.linuxtools.docker.ui.commands.showInSystemExplorer">
+ </command>
+
</extension>
<extension
point="org.eclipse.ui.handlers">
@@ -475,7 +487,6 @@
</with>
</enabledWhen>
</handler>
-
<handler
commandId="org.eclipse.linuxtools.docker.ui.commands.showAllImages"
class="org.eclipse.linuxtools.internal.docker.ui.commands.ShowAllImagesCommandHandler">
@@ -492,6 +503,14 @@
</with>
</enabledWhen>
</handler>
+ <handler
+ commandId="org.eclipse.linuxtools.docker.ui.commands.showInWebBrowser"
+ class="org.eclipse.linuxtools.internal.docker.ui.commands.ShowInWebBrowserCommandHandler">
+ </handler>
+ <handler
+ commandId="org.eclipse.linuxtools.docker.ui.commands.showInSystemExplorer"
+ class="org.eclipse.linuxtools.internal.docker.ui.commands.ShowInSystemExplorerCommandHandler">
+ </handler>
</extension>
<!-- property testers -->
@@ -942,9 +961,47 @@
</visibleWhen>
</command>
</menuContribution>
-
-
-
+ <!-- explorer view context menu: Show In -->
+ <menuContribution
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=group.showIn">
+ <menu
+ id="org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu.showIn"
+ label="%menu.showIn">
+ </menu>
+ </menuContribution>
+ <!-- explorer view context menu: Show In>Web Browser (on container ports)-->
+ <menuContribution
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu.showIn">
+ <command
+ commandId="org.eclipse.linuxtools.docker.ui.commands.showInWebBrowser"
+ style="push">
+ <visibleWhen>
+ <with variable="selection">
+ <count value="1"/>
+ <iterate ifEmpty="false">
+ <instanceof value="org.eclipse.linuxtools.docker.core.IDockerPortMapping"></instanceof>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <!-- explorer view context menu: Show In>File System (on container volumes)-->
+ <menuContribution
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu.showIn">
+ <command
+ commandId="org.eclipse.linuxtools.docker.ui.commands.showInSystemExplorer"
+ label="%command.showInSystemExplorer.menu.name"
+ style="push">
+ <visibleWhen>
+ <with variable="selection">
+ <count value="1"/>
+ <iterate ifEmpty="false">
+ <instanceof value="org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider$DockerContainerVolume"></instanceof>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
<!-- containers view toolbar: start containers -->
<menuContribution
locationURI="toolbar:org.eclipse.linuxtools.docker.ui.dockerContainersView">
@@ -1176,7 +1233,6 @@
</command>
</menuContribution>
-
</extension>
<extension point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/Activator.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/Activator.java
index b8fc5ba16e..eb2b2aba93 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/Activator.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/Activator.java
@@ -62,10 +62,15 @@ public class Activator extends AbstractUIPlugin {
Activator.getDefault().getLog().log(status);
}
- public static void logErrorMessage(String message) {
+ public static void logErrorMessage(final String message) {
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, null));
}
+ public static void logErrorMessage(final String message,
+ final Throwable e) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e));
+ }
+
public static void log(Throwable e) {
if (e instanceof InvocationTargetException)
e = ((InvocationTargetException) e).getTargetException();
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java
index 0b4548f82c..55ebd3566a 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java
@@ -37,7 +37,7 @@ public class ImageSearch extends Wizard {
*/
private final ImageSearchModel imageSearchModel;
- /*
+ /**
* Default Constructor
*
* @param connection
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandMessages.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandMessages.java
new file mode 100644
index 0000000000..9a30b1d174
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandMessages.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.docker.ui.commands;
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class CommandMessages {
+
+ private static final String BUNDLE_NAME = CommandMessages.class.getName();
+
+ public static String getString(String key) {
+ try {
+ return ResourceBundle.getBundle(BUNDLE_NAME).getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ } catch (NullPointerException e) {
+ return '#' + key + '#';
+ }
+ }
+
+ public static String getFormattedString(String key, String arg) {
+ return MessageFormat.format(getString(key), new Object[] { arg });
+ }
+
+ public static String getFormattedString(String key, String... args) {
+ return MessageFormat.format(getString(key), (Object[]) args);
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandMessages.properties
new file mode 100644
index 0000000000..b942924940
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandMessages.properties
@@ -0,0 +1,7 @@
+command.showIn.webBrowser=Opening in Web Browser...
+command.showIn.webBrowser.failure=Failed to open in Web Browser
+
+command.showIn.systemExplorer=Opening in System Explorer...
+command.showIn.systemExplorer.failure=Failed to open in Web Browser
+command.showIn.systemExplorer.failure.command_unavailable=Failed to open in Web Browser: command unavailable
+command.showIn.systemExplorer.failure.execute=Failed to execute {0}. Return code was: {1} \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
index 7077d8e729..c6549ab204 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
@@ -27,10 +27,16 @@ import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerContainer;
import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerPortMapping;
import org.eclipse.linuxtools.docker.ui.Activator;
import org.eclipse.linuxtools.internal.docker.ui.RunConsole;
import org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerLink;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerLinksCategory;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerPortMappingsCategory;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolume;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolumesCategory;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainersCategory;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerImagesCategory;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
@@ -87,6 +93,29 @@ public class CommandUtils {
} else if (firstElement instanceof DockerContainersCategory) {
return ((DockerContainersCategory) firstElement)
.getConnection();
+ } else if (firstElement instanceof DockerContainersCategory) {
+ return ((DockerContainersCategory) firstElement)
+ .getConnection();
+ } else if (firstElement instanceof DockerContainerLinksCategory) {
+ return ((DockerContainerLinksCategory) firstElement)
+ .getContainer().getConnection();
+ } else if (firstElement instanceof DockerContainerLink) {
+ return ((DockerContainerLink) firstElement).getContainer()
+ .getConnection();
+ } else
+ if (firstElement instanceof DockerContainerPortMappingsCategory) {
+ return ((DockerContainerPortMappingsCategory) firstElement)
+ .getContainer().getConnection();
+ } else if (firstElement instanceof IDockerPortMapping) {
+ return ((IDockerPortMapping) firstElement)
+ .getContainer()
+ .getConnection();
+ } else if (firstElement instanceof DockerContainerVolumesCategory) {
+ return ((DockerContainerVolumesCategory) firstElement)
+ .getContainer().getConnection();
+ } else if (firstElement instanceof DockerContainerVolume) {
+ return ((DockerContainerVolume) firstElement).getContainer()
+ .getConnection();
} else if (firstElement instanceof DockerImagesCategory) {
return ((DockerImagesCategory) firstElement).getConnection();
}
@@ -104,37 +133,57 @@ public class CommandUtils {
public static List<IDockerContainer> getSelectedContainers(final IWorkbenchPart activePart) {
if (activePart instanceof DockerContainersView) {
final ISelection selection = ((DockerContainersView) activePart).getSelection();
- return getSelectedContainers(selection);
+ return convertSelectionTo(selection, IDockerContainer.class);
} else if (activePart instanceof DockerExplorerView) {
final ISelection selection = ((DockerExplorerView) activePart)
.getCommonViewer().getSelection();
- return getSelectedContainers(selection);
+ return convertSelectionTo(selection, IDockerContainer.class);
}
return Collections.emptyList();
}
/**
- *
- * @param selection
- * the current selection
- * @return the {@link List} of {@link IDockerContainer} associated with the
- * given {@link ISelection}, or {@link Collections#emptyList()} if
- * none was selected.
+ * @param activePart
+ * the active {@link IWorkbenchPart}
+ * @return the {@link List} of selected {@link DockerContainerPortMapping}
+ * in the given active part of {@link Collections#emptyList()} if
+ * none was selected
*/
- public static List<IDockerContainer> getSelectedContainers(final ISelection selection) {
- if (selection instanceof IStructuredSelection) {
- final List<IDockerContainer> selectedContainers = new ArrayList<>();
- final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
- for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
- final Object selectedElement = iterator.next();
- if (selectedElement instanceof IDockerContainer) {
- selectedContainers.add((IDockerContainer) selectedElement);
- }
- }
- return Collections.unmodifiableList(selectedContainers);
+ public static List<IDockerPortMapping> getSelectedPortMappings(
+ final IWorkbenchPart activePart) {
+ if (activePart instanceof DockerContainersView) {
+ final ISelection selection = ((DockerContainersView) activePart)
+ .getSelection();
+ return convertSelectionTo(selection, IDockerPortMapping.class);
+ } else if (activePart instanceof DockerExplorerView) {
+ final ISelection selection = ((DockerExplorerView) activePart)
+ .getCommonViewer().getSelection();
+ return convertSelectionTo(selection, IDockerPortMapping.class);
}
return Collections.emptyList();
}
+
+ /**
+ * @param activePart
+ * the active {@link IWorkbenchPart}
+ * @return the {@link List} of selected {@link DockerContainerVolume} in the
+ * given active part of {@link Collections#emptyList()} if none was
+ * selected
+ */
+ public static List<DockerContainerVolume> getSelectedVolumes(
+ final IWorkbenchPart activePart) {
+ if (activePart instanceof DockerContainersView) {
+ final ISelection selection = ((DockerContainersView) activePart)
+ .getSelection();
+ return convertSelectionTo(selection, DockerContainerVolume.class);
+ } else if (activePart instanceof DockerExplorerView) {
+ final ISelection selection = ((DockerExplorerView) activePart)
+ .getCommonViewer().getSelection();
+ return convertSelectionTo(selection, DockerContainerVolume.class);
+ }
+ return Collections.emptyList();
+ }
+
/**
* @param activePart
* the active {@link IWorkbenchPart}
@@ -147,11 +196,11 @@ public class CommandUtils {
if (activePart instanceof DockerImagesView) {
final ISelection selection = ((DockerImagesView) activePart)
.getSelection();
- return getSelectedImages(selection);
+ return convertSelectionTo(selection, IDockerImage.class);
} else if (activePart instanceof DockerExplorerView) {
final ISelection selection = ((DockerExplorerView) activePart)
.getCommonViewer().getSelection();
- return getSelectedImages(selection);
+ return convertSelectionTo(selection, IDockerImage.class);
}
return Collections.emptyList();
}
@@ -160,23 +209,24 @@ public class CommandUtils {
*
* @param selection
* the current selection
- * @return the {@link List} of {@link IDockerImage} associated with the
+ * @return the {@link List} of {@link IDockerContainer} associated with the
* given {@link ISelection}, or {@link Collections#emptyList()} if
* none was selected.
*/
- public static List<IDockerImage> getSelectedImages(
- final ISelection selection) {
+ @SuppressWarnings("unchecked")
+ private static <T> List<T> convertSelectionTo(final ISelection selection,
+ final Class<T> targetClass) {
if (selection instanceof IStructuredSelection) {
- final List<IDockerImage> selectedImages = new ArrayList<>();
+ final List<T> selectedContainers = new ArrayList<>();
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
for (Iterator<?> iterator = structuredSelection.iterator(); iterator
.hasNext();) {
final Object selectedElement = iterator.next();
- if (selectedElement instanceof IDockerImage) {
- selectedImages.add((IDockerImage) selectedElement);
+ if (targetClass.isAssignableFrom(selectedElement.getClass())) {
+ selectedContainers.add((T) selectedElement);
}
}
- return Collections.unmodifiableList(selectedImages);
+ return Collections.unmodifiableList(selectedContainers);
}
return Collections.emptyList();
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInSystemExplorerCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInSystemExplorerCommandHandler.java
new file mode 100644
index 0000000000..a8a7e89a28
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInSystemExplorerCommandHandler.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.commands;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.util.Util;
+import org.eclipse.linuxtools.docker.ui.Activator;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolume;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.internal.ide.handlers.ShowInSystemExplorerHandler;
+
+/**
+ * Command handler to open the selection in the Web Browser.
+ *
+ * @see ShowInSystemExplorerHandler
+ */
+@SuppressWarnings("restriction")
+public class ShowInSystemExplorerCommandHandler extends AbstractHandler {
+
+ private static final String VARIABLE_RESOURCE = "${selected_resource_loc}"; //$NON-NLS-1$
+ private static final String VARIABLE_RESOURCE_URI = "${selected_resource_uri}"; //$NON-NLS-1$
+ private static final String VARIABLE_FOLDER = "${selected_resource_parent_loc}"; //$NON-NLS-1$
+
+ @Override
+ public Object execute(final ExecutionEvent event) {
+ final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ final List<DockerContainerVolume> volumes = CommandUtils
+ .getSelectedVolumes(activePart);
+ if (volumes == null || volumes.isEmpty()) {
+ return null;
+ }
+ final DockerContainerVolume selectedVolume = volumes.get(0);
+ final File hostFile = new File(selectedVolume.getHostPath());
+ final String launchCmd = getShowInSystemExplorerCommand(hostFile);
+
+ if (launchCmd == null) {
+ return null;
+ }
+ final Job job = new Job(
+ CommandMessages.getString("command.showIn.systemExplorer")) {
+ // $NON-NLS-1$
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+
+ try {
+ final Process p = getLaunchProcess(launchCmd, hostFile);
+ final int retCode = p.waitFor();
+ if (retCode != 0 && !Util.isWindows()) {
+ Activator.logErrorMessage(
+ CommandMessages.getFormattedString(
+ "command.showIn.systemExplorer.failure.command.execute", //$NON-NLS-1$
+ launchCmd, Integer.toString(retCode)));
+ }
+ } catch (IOException | InterruptedException e) {
+ Activator
+ .logErrorMessage(CommandMessages.getFormattedString(
+ "command.showIn.systemExplorer.failure", //$NON-NLS-1$
+ launchCmd), e);
+ } finally {
+ monitor.done();
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+ return null;
+ }
+
+ /**
+ * @param launchCmd
+ * the launch command
+ * @return the platform-dependent {@link Process} to run to open the file in
+ * the System Explorer
+ * @throws IOException
+ */
+ private Process getLaunchProcess(final String launchCmd, final File dir)
+ throws IOException {
+ if (Util.isLinux() || Util.isMac()) {
+ return Runtime.getRuntime().exec(
+ new String[] { "/bin/sh", "-c", launchCmd }, null, dir); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ return Runtime.getRuntime().exec(launchCmd, null, dir);
+ }
+ }
+
+ /**
+ * Prepare command for launching system explorer to show a path
+ *
+ * @param path
+ * the path to show
+ * @return the command that shows the path
+ * @see ShowInSystemExplorerHandler#getDefaultCommand()
+ */
+ private String getShowInSystemExplorerCommand(final File path) {
+ String command = ShowInSystemExplorerHandler.getDefaultCommand();
+ if ("".equals(command)) {
+ Activator.logErrorMessage(CommandMessages.getString(
+ "command.showIn.systemExplorer.failure.command_unavailable"));
+ return null;
+ }
+ try {
+ command = Util.replaceAll(command, VARIABLE_RESOURCE,
+ quotePath(path.getCanonicalPath()));
+ command = Util.replaceAll(command, VARIABLE_RESOURCE_URI,
+ path.getCanonicalFile().toURI().toString());
+ File parent = path.getParentFile();
+ if (parent != null) {
+ command = Util.replaceAll(command, VARIABLE_FOLDER,
+ quotePath(parent.getCanonicalPath()));
+ }
+ return command;
+ } catch (IOException e) {
+ Activator.logErrorMessage(CommandMessages
+ .getString("command.showIn.systemExplorer.failure"), e);
+ return null;
+ }
+ }
+
+ private String quotePath(String path) {
+ if (Util.isLinux() || Util.isMac()) {
+ // Quote for usage inside "", man sh, topic QUOTING:
+ path = path.replaceAll("[\"$`]", "\\\\$0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ // Windows: Can't quote, since explorer.exe has a very special command
+ // line parsing strategy.
+ return path;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInWebBrowserCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInWebBrowserCommandHandler.java
new file mode 100644
index 0000000000..21a47df797
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInWebBrowserCommandHandler.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.commands;
+
+import static org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils.getCurrentConnection;
+import static org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils.getSelectedPortMappings;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.docker.core.Activator;
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerPortMapping;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Command handler to open the selection in the Web Browser.
+ */
+public class ShowInWebBrowserCommandHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(final ExecutionEvent event) {
+ final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ final List<IDockerPortMapping> portMappings = getSelectedPortMappings(
+ activePart);
+ if (portMappings == null || portMappings.isEmpty()) {
+ return null;
+ }
+ final Job job = new Job(
+ CommandMessages.getString("command.showIn.webBrowser")) { //$NON-NLS-1$
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ try {
+ final IDockerConnection currentConnection = getCurrentConnection(
+ activePart);
+ final IDockerPortMapping selectedPort = portMappings
+ .get(0);
+ final URI connectionURI = new URI(
+ currentConnection.getUri());
+ if ("tcp".equalsIgnoreCase(connectionURI.getScheme()) //$NON-NLS-1$
+ || "unix" //$NON-NLS-1$
+ .equalsIgnoreCase(connectionURI.getScheme())
+ || "http" //$NON-NLS-1$
+ .equalsIgnoreCase(connectionURI.getScheme())
+ || "https".equalsIgnoreCase( //$NON-NLS-1$
+ connectionURI.getScheme())) {
+ final String host = connectionURI.getHost();
+ final URL location = new URL("http", host, //$NON-NLS-1$
+ selectedPort.getPublicPort(), "/");
+ openLocationInWebBrowser(location);
+ }
+ } catch (URISyntaxException | MalformedURLException e) {
+ Activator.logErrorMessage(
+ CommandMessages.getString(
+ "command.showIn.webBrowser.failure"), //$NON-NLS-1$
+ e);
+ }
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+ return null;
+ }
+
+ private void openLocationInWebBrowser(final URL location) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ PlatformUI.getWorkbench().getBrowserSupport()
+ .getExternalBrowser().openURL(location);
+ } catch (Exception e) {
+ Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ CommandMessages.getString(
+ "command.showIn.webBrowser.failure"), //$NON-NLS-1$
+ e));
+ }
+ }
+ });
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerContentProvider.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerContentProvider.java
index 192e307b3e..f6dd1a41f0 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerContentProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerContentProvider.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.docker.ui.views;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -371,7 +372,7 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
private final IDockerContainer container;
- private final Map<String, List<IDockerPortBinding>> bindings;
+ private final List<IDockerPortMapping> portMappings;
/**
* @param container
@@ -382,11 +383,7 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
final IDockerContainer container,
final Map<String, List<IDockerPortBinding>> bindings) {
this.container = container;
- this.bindings = bindings;
- }
-
- public List<IDockerPortMapping> getPortMappings() {
- final List<IDockerPortMapping> portMappings = new ArrayList<>();
+ this.portMappings = new ArrayList<>();
if (bindings != null) {
for (Entry<String, List<IDockerPortBinding>> entry : bindings
.entrySet()) {
@@ -395,14 +392,32 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
final int privatePort = Integer.parseInt(source[0]);
final String type = source[1];
for (IDockerPortBinding portBinding : entry.getValue()) {
- portMappings.add(new DockerPortMapping(privatePort,
- Integer.parseInt(portBinding.hostPort()), type,
- portBinding.hostIp()));
+ portMappings.add(
+ new DockerPortMapping(container, privatePort,
+ Integer.parseInt(
+ portBinding.hostPort()),
+ type, portBinding.hostIp()));
}
}
}
- Collections.sort(portMappings);
- return portMappings;
+ Collections.sort(portMappings,
+ new Comparator<IDockerPortMapping>() {
+
+ @Override
+ public int compare(final IDockerPortMapping portMapping,
+ final IDockerPortMapping otherPortMapping) {
+ return portMapping.getPrivatePort()
+ - otherPortMapping.getPrivatePort();
+ }
+ });
+ }
+
+ public IDockerContainer getContainer() {
+ return container;
+ }
+
+ public List<IDockerPortMapping> getPortMappings() {
+ return this.portMappings;
}
@Override
@@ -435,7 +450,6 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
return false;
return true;
}
-
}
/**
@@ -462,11 +476,15 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
this.links = new ArrayList<>();
if (links != null) {
for (String link : links) {
- this.links.add(new DockerContainerLink(link));
+ this.links.add(new DockerContainerLink(container, link));
}
}
}
+ public IDockerContainer getContainer() {
+ return container;
+ }
+
public List<DockerContainerLink> getLinks() {
if (this.links == null) {
return Collections.emptyList();
@@ -479,11 +497,6 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
return "Container links for " + this.container.name();
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
@Override
public int hashCode() {
final int prime = 31;
@@ -493,11 +506,6 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
return result;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -519,6 +527,8 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
public static class DockerContainerLink {
+ private final IDockerContainer container;
+
private final String containerName;
private final String containerAlias;
@@ -529,7 +539,9 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
* @param linkValue
* the bind value provided by the {@link IDockerHostConfig}.
*/
- public DockerContainerLink(final String linkValue) {
+ public DockerContainerLink(final IDockerContainer container,
+ final String linkValue) {
+ this.container = container;
// format: "container_name:containerAlias"
final String[] args = linkValue.split(":");
this.containerName = getDisplayableContainerName(args[0]);
@@ -537,6 +549,10 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
? getDisplayableContainerAlias(args[1]) : null;
}
+ public IDockerContainer getContainer() {
+ return container;
+ }
+
/**
* Removes the heading "/" i(if found) in the given container name
*
@@ -629,11 +645,16 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
this.volumes = new ArrayList<>();
if (volumes != null) {
for (String volume : volumes) {
- this.volumes.add(new DockerContainerVolume(volume));
+ this.volumes
+ .add(new DockerContainerVolume(container, volume));
}
}
}
+ public IDockerContainer getContainer() {
+ return container;
+ }
+
public List<DockerContainerVolume> getVolumes() {
if (this.volumes == null) {
return Collections.emptyList();
@@ -676,6 +697,8 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
public static class DockerContainerVolume {
+ private final IDockerContainer container;
+
private final String hostPath;
private final String containerPath;
@@ -683,12 +706,15 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
private final String flags;
/**
+ * @param container
* @param volume
* the volume value provided by the {@link IDockerHostConfig}
* .
* @return a {@link DockerContainerVolume}
*/
- public DockerContainerVolume(final String volume) {
+ public DockerContainerVolume(final IDockerContainer container,
+ final String volume) {
+ this.container = container;
// (1) "container_path" to create a new volume for the container
// (2) "host_path:container_path" to bind-mount a host path into the
// container
@@ -705,6 +731,10 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
this.flags = args.length > 2 ? args[2] : null;
}
+ public IDockerContainer getContainer() {
+ return container;
+ }
+
public String getHostPath() {
return hostPath;
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerLabelProvider.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerLabelProvider.java
index 42f88aeac5..3ddd57823e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerLabelProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerLabelProvider.java
@@ -176,7 +176,7 @@ public class DockerExplorerLabelProvider implements IStyledLabelProvider, ILabel
} else if (element instanceof IDockerPortMapping) {
final IDockerPortMapping mapping = (IDockerPortMapping) element;
final String hostMapping = mapping.getIp() + ":"
- + mapping.getPublicPort() + " -> ";
+ + mapping.getPublicPort() + " -> ";
final String containerMapping = Integer
.toString(mapping.getPrivatePort());
final String mappingType = " (" + mapping.getType() + ")";

Back to the top