Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/pom.xml1
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java19
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerPortMapping.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerContainer.java17
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortBinding.java32
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortMapping.java5
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml1
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/.classpath2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml67
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java36
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java3
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerFactory.java3
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerInfoFactory.java99
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java65
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTUtils.java54
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java139
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/icons/container_link.pngbin0 -> 1708 bytes
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/icons/container_port.pngbin0 -> 1706 bytes
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/icons/container_volume.pngbin0 -> 1754 bytes
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/pom.xml7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/SWTImagesFactory.java12
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerContentProvider.java519
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerLabelProvider.java96
26 files changed, 1096 insertions, 93 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/pom.xml b/containers/org.eclipse.linuxtools.docker.core/pom.xml
index 00bd9a942e..55e6e18e44 100644
--- a/containers/org.eclipse.linuxtools.docker.core/pom.xml
+++ b/containers/org.eclipse.linuxtools.docker.core/pom.xml
@@ -7,7 +7,6 @@
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.linuxtools.docker.core</artifactId>
- <version>1.2.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java
index 89573f3836..a38e7ab73e 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerContainer.java
@@ -49,11 +49,28 @@ public interface IDockerContainer {
public IDockerConnection getConnection();
/**
+ * @return <code>true</code> if the {@link IDockerContainerInfo} has been
+ * loaded, <code>false</code> otherwise.
+ */
+ public boolean isInfoLoaded();
+
+ /**
* @return the {@link IDockerContainerInfo} by calling the Docker daemon
* using the {@link IDockerConnection} associated with this
- * {@link IDockerContainer}.
+ * {@link IDockerContainer} if it was not loaded before, otherwise
+ * uses the previous version.
*/
public IDockerContainerInfo info();
+ /**
+ * @param force
+ * <code>true</code> to force refresh, <code>false</code> to use
+ * existing {@link IDockerContainerInfo} if it was loaded before.
+ * @return the {@link IDockerContainerInfo} by calling the Docker daemon
+ * using the {@link IDockerConnection} associated with this
+ * {@link IDockerContainer}.
+ */
+ public IDockerContainerInfo info(boolean force);
+
}
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 eb7919f9b9..a9cd77f38b 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 {
+public interface IDockerPortMapping extends Comparable<IDockerPortMapping> {
public int getPrivatePort();
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
index 386a92dec3..209a2183fc 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
@@ -590,7 +590,7 @@ public class DockerConnection implements IDockerConnection, Closeable {
}
@Override
- public IDockerContainerInfo getContainerInfo(String id) {
+ public IDockerContainerInfo getContainerInfo(final String id) {
try {
final ContainerInfo info = client.inspectContainer(id);
return new DockerContainerInfo(info);
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 ef5c42f871..408bbdc637 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
@@ -32,6 +32,7 @@ public class DockerContainer implements IDockerContainer {
private List<IDockerPortMapping> ports;
private Long sizeRw;
private Long sizeRootFs;
+ private IDockerContainerInfo containerInfo;
public DockerContainer(final IDockerConnection connection,
Container container) {
@@ -115,10 +116,24 @@ public class DockerContainer implements IDockerContainer {
public List<String> names() {
return names;
}
+
@Override
public IDockerContainerInfo info() {
- return this.parent.getContainerInfo(id);
+ return info(false);
+ }
+
+ @Override
+ public IDockerContainerInfo info(final boolean force) {
+ if (force || isInfoLoaded()) {
+ this.containerInfo = this.parent.getContainerInfo(id);
+ }
+ return this.containerInfo;
+ }
+
+ @Override
+ public boolean isInfoLoaded() {
+ return this.containerInfo != null;
}
@Override
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortBinding.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortBinding.java
index c1cafa570d..e781915919 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortBinding.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerPortBinding.java
@@ -45,4 +45,36 @@ public class DockerPortBinding implements IDockerPortBinding {
+ "\n";
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((hostIp == null) ? 0 : hostIp.hashCode());
+ result = prime * result
+ + ((hostPort == null) ? 0 : hostPort.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DockerPortBinding other = (DockerPortBinding) obj;
+ if (hostIp == null) {
+ if (other.hostIp != null)
+ return false;
+ } else if (!hostIp.equals(other.hostIp))
+ return false;
+ if (hostPort == null) {
+ if (other.hostPort != null)
+ return false;
+ } else if (!hostPort.equals(other.hostPort))
+ return false;
+ return true;
+ }
+
}
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 8c1f7a09d6..28589d3095 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
@@ -108,6 +108,11 @@ public class DockerPortMapping implements IDockerPortMapping {
return false;
return true;
}
+
+ @Override
+ public int compareTo(final IDockerPortMapping other) {
+ return other.getPublicPort() - this.publicPort;
+ }
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml
index ff4696ff94..0c6dd3ac06 100644
--- a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml
@@ -7,7 +7,6 @@
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.linuxtools.docker.tests.hamcrest-wrap</artifactId>
- <version>1.2.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath b/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath
index cf36b56119..9b7ff0481d 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/pom.xml b/containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml
index 0fc773e59f..613f33cab4 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml
@@ -7,7 +7,6 @@
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.linuxtools.docker.ui.tests</artifactId>
- <version>1.2.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
@@ -17,37 +16,10 @@
</properties>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.eclipse.tycho</groupId>
- <artifactId>tycho-surefire-plugin</artifactId>
- <version>${tycho-version}</version>
- <configuration>
- <!-- skipTests>true</skipTests -->
- <!-- useUIHarness>true</useUIHarness -->
- <useUIThread>false</useUIThread>
- <!-- kill test JVM if tests take more than 10 minutes (600 seconds)
- to finish -->
- <forkedProcessTimeoutInSeconds>${tycho.surefire.timeout}</forkedProcessTimeoutInSeconds>
- <argLine>${tycho.test.jvmArgs}</argLine>
- <includes>
- <include>**/*Test.class</include>
- </includes>
- <excludes>
- <exclude>**/*SWTBotTest.class</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
-
<profiles>
<profile>
<!-- Ignore optional deps to swt.macosx -->
- <id>ignore-mac-deps-on-other-os</id>
+ <id>ignore-mac-deps-on-other-os-and-skip-swtbot-tests</id>
<activation>
<os>
<family>!mac</family>
@@ -71,6 +43,26 @@
<optionalDependencies>ignore</optionalDependencies>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <!-- skipTests>true</skipTests -->
+ <!-- useUIHarness>true</useUIHarness -->
+ <useUIThread>false</useUIThread>
+ <!-- kill test JVM if tests take more than 10 minutes (600 seconds)
+ to finish -->
+ <forkedProcessTimeoutInSeconds>${tycho.surefire.timeout}</forkedProcessTimeoutInSeconds>
+ <argLine>${tycho.test.jvmArgs}</argLine>
+ <includes>
+ <include>**/*Test.class</include>
+ </includes>
+ <excludes>
+ <exclude>**/*SWTBotTest.class</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
</plugins>
</build>
</profile>
@@ -101,6 +93,23 @@
</environments>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <configuration>
+ <!-- skipTests>true</skipTests -->
+ <!-- useUIHarness>true</useUIHarness -->
+ <useUIThread>false</useUIThread>
+ <!-- kill test JVM if tests take more than 10 minutes (600 seconds) to
+ finish -->
+ <forkedProcessTimeoutInSeconds>${tycho.surefire.timeout}</forkedProcessTimeoutInSeconds>
+ <argLine>${tycho.test.jvmArgs}</argLine>
+ <!-- execute all tests on Mac -->
+ <includes>
+ <include>**/*Test.class</include>
+ </includes>
+ </configuration>
+ </plugin>
</plugins>
</build>
</profile>
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
index aa505b8bff..e9c3893d57 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
@@ -45,7 +45,7 @@ public class DockerConnectionManagerTest {
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
dockerConnectionManager
.setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(dockerConnection));
- SWTUtils.asyncExec(() -> dockerConnectionManager.reloadConnections());
+ SWTUtils.syncExec(() -> dockerConnectionManager.reloadConnections());
// when
dockerConnection.getContainers();
// then
@@ -59,7 +59,7 @@ public class DockerConnectionManagerTest {
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
dockerConnectionManager
.setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(dockerConnection));
- dockerConnectionManager.reloadConnections();
+ SWTUtils.syncExec(() -> dockerConnectionManager.reloadConnections());
dockerConnection.getContainers();
Assertions.assertThat(dockerContainersRefreshManager.getConnections()).contains(dockerConnection);
// when
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
index ae9b76ff98..51f9bddfba 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
@@ -11,16 +11,18 @@
package org.eclipse.linuxtools.internal.docker.ui.testutils;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.mockito.Matchers;
import org.mockito.Mockito;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.DockerException;
import com.spotify.docker.client.messages.Container;
+import com.spotify.docker.client.messages.ContainerInfo;
import com.spotify.docker.client.messages.Image;
/**
@@ -43,38 +45,48 @@ public class MockDockerClientFactory {
private final DockerClient dockerClient;
+ private final List<Container> containers = new ArrayList<>();
+
private Builder() {
this.dockerClient = Mockito.mock(DockerClient.class);
}
public Builder images(final List<Image> images) {
try {
- Mockito.when(dockerClient.listImages(Mockito.any())).thenReturn(images);
+ Mockito.when(dockerClient.listImages(Matchers.any())).thenReturn(images);
} catch (DockerException | InterruptedException e) {
// rest assured, nothing will happen while mocking the DockerClient
}
return this;
}
- public Builder noImages() {
- return images(Collections.emptyList());
- }
- public DockerClient containers(final List<Container> containers) {
+ public Builder container(final Container container) {
+ this.containers.add(container);
+ return this;
+ }
+
+ public Builder container(final Container container, final ContainerInfo containerInfo) {
+ this.containers.add(container);
try {
- Mockito.when(dockerClient.listContainers(Mockito.any())).thenReturn(containers);
+ Mockito.when(this.dockerClient.inspectContainer(container.id())).thenReturn(containerInfo);
} catch (DockerException | InterruptedException e) {
// rest assured, nothing will happen while mocking the DockerClient
}
- return this.dockerClient;
+ return this;
}
- public DockerClient containers(final Container... containers) {
- return containers(Arrays.asList(containers));
+ public DockerClient build() {
+ try {
+ Mockito.when(this.dockerClient.listContainers(Matchers.any())).thenReturn(this.containers);
+ } catch (DockerException | InterruptedException e) {
+ // nothing may happen when mocking the method call
+ }
+ return this.dockerClient;
}
-
+
public DockerClient noContainers() {
- return containers(Collections.emptyList());
+ return this.dockerClient;
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java
index f346e51721..c90834d57a 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.internal.docker.ui.testutils;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.internal.docker.core.DockerClientFactory;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.mockito.Matchers;
import org.mockito.Mockito;
import com.spotify.docker.client.DockerCertificateException;
@@ -37,7 +38,7 @@ public class MockDockerConnectionFactory {
final DockerClientFactory dockerClientFactory = Mockito.mock(DockerClientFactory.class);
this.connection.setDockerClientFactory(dockerClientFactory);
try {
- Mockito.when(dockerClientFactory.getClient(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(dockerClient);
+ Mockito.when(dockerClientFactory.getClient(Matchers.anyString(), Matchers.anyString(), Matchers.anyString())).thenReturn(dockerClient);
} catch (DockerCertificateException e) {
// rest assured, nothing will happen while mocking the DockerClientFactory
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerFactory.java
index 6bcfdb3641..ac50a34978 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerFactory.java
@@ -39,7 +39,7 @@ public class MockDockerContainerFactory {
private static char[] hexa = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private final Container container;
-
+
private Builder(final String name, final String... otherNames) {
this.container = Mockito
.mock(Container.class);
@@ -59,5 +59,6 @@ public class MockDockerContainerFactory {
public Container build() {
return container;
}
+
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerInfoFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerInfoFactory.java
new file mode 100644
index 0000000000..a19eeda0be
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerInfoFactory.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.testutils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.mockito.Mockito;
+
+import com.spotify.docker.client.messages.ContainerInfo;
+import com.spotify.docker.client.messages.HostConfig;
+import com.spotify.docker.client.messages.NetworkSettings;
+import com.spotify.docker.client.messages.PortBinding;
+
+/**
+ *
+ */
+public class MockDockerContainerInfoFactory {
+
+ public static Builder port(final String privatePort, final String hostIp, final String hostPort) {
+ return new Builder().port(privatePort, hostIp, hostPort);
+ }
+
+ public static Builder link(final String link) {
+ return new Builder().link(link);
+ }
+
+ public static Builder volume(final String volume) {
+ return new Builder().volume(volume);
+ }
+
+ public static class Builder {
+
+ private final ContainerInfo containerInfo;
+
+ private Map<String, List<PortBinding>> ports;
+
+ private List<String> links;
+
+ private List<String> volumes;
+
+ private Builder() {
+ this.containerInfo = Mockito
+ .mock(ContainerInfo.class, Mockito.RETURNS_DEEP_STUBS);
+ }
+
+ public Builder link(final String link) {
+ if(this.links == null) {
+ this.links = new ArrayList<>();
+ }
+ this.links.add(link);
+ return this;
+ }
+
+ public Builder volume(final String volume) {
+ if(this.volumes == null) {
+ this.volumes = new ArrayList<>();
+ }
+ this.volumes.add(volume);
+ return this;
+ }
+
+ public Builder port(final String privatePort, final String hostIp, final String hostPort) {
+ if(this.ports == null) {
+ this.ports = new HashMap<>();
+ }
+ final PortBinding binding = Mockito.mock(PortBinding.class);
+ Mockito.when(binding.hostIp()).thenReturn(hostIp);
+ Mockito.when(binding.hostPort()).thenReturn(hostPort);
+ ports.put(privatePort, new ArrayList<>());
+ ports.get(privatePort).add(binding);
+ return this;
+ }
+
+ public ContainerInfo build() {
+ final NetworkSettings networkSettings = Mockito.mock(NetworkSettings.class);
+ Mockito.when(this.containerInfo.networkSettings()).thenReturn(networkSettings);
+ Mockito.when(networkSettings.ports()).thenReturn(this.ports);
+ final HostConfig hostConfig = Mockito.mock(HostConfig.class);
+ Mockito.when(this.containerInfo.hostConfig()).thenReturn(hostConfig);
+ Mockito.when(hostConfig.links()).thenReturn(this.links);
+ Mockito.when(hostConfig.binds()).thenReturn(this.volumes);
+ return containerInfo;
+ }
+ }
+
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java
new file mode 100644
index 0000000000..5ac1a21c5e
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.testutils.swt;
+
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.assertj.core.api.Assertions;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+
+/**
+ *
+ */
+public class SWTBotTreeItemAssertions extends AbstractSWTBotAssertion<SWTBotTreeItemAssertions, SWTBotTreeItem> {
+
+ protected SWTBotTreeItemAssertions(final SWTBotTreeItem actual) {
+ super(actual, SWTBotTreeItemAssertions.class);
+ }
+
+ public static SWTBotTreeItemAssertions assertThat(final SWTBotTreeItem containerPortsTreeItem) {
+ return new SWTBotTreeItemAssertions(containerPortsTreeItem);
+ }
+
+ public SWTBotTreeItemAssertions isExpanded() {
+ notNullValue();
+ if(!actual.isExpanded()) {
+ failWithMessage("Expected tree item %s to be expanded but it was not.", actual.getText());;
+ }
+ return this;
+ }
+
+ /**
+ * Checks the number of items and also verifies that each item has an image and a text
+ * @param expectedCount
+ * @return
+ */
+ public SWTBotTreeItemAssertions hasChildItems(final int expectedCount) {
+ notNullValue();
+ if(actual.getItems().length != expectedCount) {
+ failWithMessage("Expected tree item %s to be have %s items but it had %s.", actual.getText(), expectedCount, actual.getItems().length);;
+ }
+ for (SWTBotTreeItem swtBotTreeItem : actual.getItems()) {
+ Assertions.assertThat(swtBotTreeItem.getText()).isNotNull();
+ Assertions.assertThat(swtBotTreeItem.widget.getImage()).isNotNull();
+ }
+ return this;
+ }
+
+ public SWTBotTreeItemAssertions hasText(final String expectedText) {
+ notNullValue();
+ if(!actual.getText().equals(expectedText)) {
+ failWithMessage("Expected node to have text %s but it was %s", expectedText, actual.getText());
+ }
+ return this;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTUtils.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTUtils.java
index 1ce4d8838c..55a44f4582 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTUtils.java
@@ -121,23 +121,59 @@ public class SWTUtils {
}
/**
+ * Waits for all {@link Job} to complete.
+ *
+ * @throws InterruptedException
+ */
+ public static void waitForJobsToComplete() throws InterruptedException {
+ Thread.sleep(TimeUnit.SECONDS.toMillis(1));
+ while (!Job.getJobManager().isIdle()) {
+ Thread.sleep(TimeUnit.SECONDS.toMillis(1));
+ }
+ }
+
+ /**
* @param viewBot the {@link SWTBotView} containing the {@link Tree} to traverse
- * @param path the node path in the {@link SWTBotTree} associated with the given {@link SWTBotView}
+ * @param paths the node path in the {@link SWTBotTree} associated with the given {@link SWTBotView}
* @return the first {@link SWTBotTreeItem} matching the given node names
*/
- public static SWTBotTreeItem getTreeItem(final SWTBotView viewBot, final String... path) {
+ public static SWTBotTreeItem getTreeItem(final SWTBotView viewBot, final String... paths) {
final SWTBotTree tree = viewBot.bot().tree();
- return getTreeItem(tree.getAllItems(), path);
+ return getTreeItem(tree.getAllItems(), paths);
+ }
+
+ public static SWTBotTreeItem getTreeItem(final SWTBotTreeItem parentTreeItem, final String... paths) {
+ if(paths.length == 1) {
+ return getTreeItem(parentTreeItem, paths[0]);
+ }
+ final String[] remainingPaths = new String[paths.length-1];
+ System.arraycopy(paths, 1, remainingPaths, 0, paths.length-1);
+ return getTreeItem(getTreeItem(parentTreeItem, paths[0]), remainingPaths);
}
- private static SWTBotTreeItem getTreeItem(final SWTBotTreeItem[] treeItems, final String[] path) {
- final SWTBotTreeItem swtBotTreeItem = Stream.of(treeItems).filter(item -> item.getText().startsWith(path[0])).findFirst().get();
- if(path.length > 1) {
- final String[] remainingPath = new String[path.length -1];
- System.arraycopy(path, 1, remainingPath, 0, remainingPath.length);
+ /**
+ * Returns the first child node in the given parent tree item whose text matches (ie, begins with) the given path argument.
+ * @param parentTreeItem the parent tree item
+ * @param path the text of the node that should match
+ * @return the first matching node or <code>null</code> if none could be found
+ */
+ public static SWTBotTreeItem getTreeItem(final SWTBotTreeItem parentTreeItem, final String path) {
+ for (SWTBotTreeItem child : parentTreeItem.getItems()) {
+ if(child.getText().startsWith(path)) {
+ return child;
+ }
+ }
+ return null;
+ }
+
+ private static SWTBotTreeItem getTreeItem(final SWTBotTreeItem[] treeItems, final String[] paths) {
+ final SWTBotTreeItem swtBotTreeItem = Stream.of(treeItems).filter(item -> item.getText().startsWith(paths[0])).findFirst().get();
+ if(paths.length > 1) {
+ final String[] remainingPath = new String[paths.length -1];
+ System.arraycopy(paths, 1, remainingPath, 0, remainingPath.length);
return getTreeItem(swtBotTreeItem.getItems(), remainingPath);
}
return swtBotTreeItem;
}
-
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
index 2badf1f9df..8121be146e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
@@ -24,9 +24,11 @@ import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFacto
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.DockerExplorerViewAssertion;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTBotTreeItemAssertions;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
@@ -95,7 +97,7 @@ public class DockerExplorerViewSWTBotTest {
dockerExplorerView.getCommonViewer().refresh(true);
dockerExplorerView.showConnectionsOrExplanations();});
}
-
+
@AfterClass
public static void restoreDefaultConfig() {
DockerConnectionManager.getInstance().setConnectionStorageManager(new DefaultDockerConnectionStorageManager());
@@ -131,7 +133,7 @@ public class DockerExplorerViewSWTBotTest {
}
@Test
- public void shouldRefreshImagesAndShowChanges() throws Exception {
+ public void shouldRefreshImagesAndShowChanges() throws InterruptedException {
// given
final DockerClient client = MockDockerClientFactory.noImages().noContainers();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
@@ -159,9 +161,9 @@ public class DockerExplorerViewSWTBotTest {
Assertions.assertThat(imagesTreeItem.isExpanded()).isTrue();
Assertions.assertThat(imagesTreeItem.getItems().length).isEqualTo(1);
}
-
+
@Test
- public void shouldRefreshContainersAndShowChanges() throws Exception {
+ public void shouldRefreshContainersAndShowChanges() throws InterruptedException {
// given
final DockerClient client = MockDockerClientFactory.noImages().noContainers();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
@@ -178,7 +180,7 @@ public class DockerExplorerViewSWTBotTest {
Assertions.assertThat(containersTreeItem.getItems().length).isEqualTo(0);
// update the client
- final DockerClient updatedClient = MockDockerClientFactory.noImages().containers(MockDockerContainerFactory.name("foo_bar").build());
+ final DockerClient updatedClient = MockDockerClientFactory.noImages().container(MockDockerContainerFactory.name("foo_bar").build()).build();
dockerConnection.setClient(updatedClient);
dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
dockerExplorerViewTreeBot.select(containersTreeItem);
@@ -190,4 +192,131 @@ public class DockerExplorerViewSWTBotTest {
Assertions.assertThat(containersTreeItem.getItems().length).isEqualTo(1);
}
+ @Test
+ public void shouldShowContainerPortMapping() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(), MockDockerContainerInfoFactory
+ .port("8080/tcp", "0.0.0.0", "8080").port("8787/tcp", "0.0.0.0", "8787").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ // when a second call to expand the container is done (because the first
+ // expandAll stopped with a "Loading..." job that retrieved the
+ // containers)
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test (null)",
+ "Containers", "foo_bar (null)");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ final SWTBotTreeItem containerPortsTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test (null)",
+ "Containers", "foo_bar (null)", "Ports");
+ SWTUtils.asyncExec(() -> containerPortsTreeItem.expand());
+ // then
+ SWTUtils.syncAssert(() -> {
+ SWTBotTreeItemAssertions.assertThat(containerPortsTreeItem).isExpanded().hasChildItems(2);
+ SWTBotTreeItemAssertions.assertThat(containerPortsTreeItem.getNode(0))
+ .hasText("0.0.0.0:8080 -> 8080 (tcp)");
+ SWTBotTreeItemAssertions.assertThat(containerPortsTreeItem.getNode(1))
+ .hasText("0.0.0.0:8787 -> 8787 (tcp)");
+ });
+ }
+
+ @Test
+ public void shouldShowContainerLinks() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(), MockDockerContainerInfoFactory
+ .link("/postgres-demo:/foo_bar/postgres1").link("/postgres-demo:/foo_bar/postgres2").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ configureConnectionManager(dockerConnection);
+ SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ // when a second call to expand the container is done (because the first
+ // expandAll stopped with a "Loading..." job that retrieved the
+ // containers)
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test (null)",
+ "Containers", "foo_bar (null)");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ final SWTBotTreeItem containerLinksTreeItem = SWTUtils.getTreeItem(containerTreeItem, "Links");
+ SWTUtils.asyncExec(() -> containerLinksTreeItem.expand());
+ // then
+ SWTUtils.syncAssert(() -> {
+ SWTBotTreeItemAssertions.assertThat(containerLinksTreeItem).isExpanded().hasChildItems(2);
+ SWTBotTreeItemAssertions.assertThat(containerLinksTreeItem.getNode(0)).hasText("postgres-demo (postgres1)");
+ SWTBotTreeItemAssertions.assertThat(containerLinksTreeItem.getNode(1)).hasText("postgres-demo (postgres2)");
+ });
+ }
+
+ @Test
+ public void shouldShowContainerVolumes() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(),
+ MockDockerContainerInfoFactory.volume("/path/to/container")
+ .volume("/path/to/host:/path/to/container")
+ .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());
+ // when a second call to expand the container is done (because the first
+ // expandAll stopped with a "Loading..." job that retrieved the
+ // containers)
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test (null)",
+ "Containers", "foo_bar (null)");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ final SWTBotTreeItem containerVolumesItem = SWTUtils.getTreeItem(containerTreeItem, "Volumes");
+ SWTUtils.asyncExec(() -> containerVolumesItem.expand());
+ // then
+ SWTUtils.syncAssert(() -> {
+ SWTBotTreeItemAssertions.assertThat(containerVolumesItem).isExpanded().hasChildItems(3);
+ SWTBotTreeItemAssertions.assertThat(containerVolumesItem.getNode(0)).hasText("/path/to/container");
+ SWTBotTreeItemAssertions.assertThat(containerVolumesItem.getNode(1))
+ .hasText("/path/to/host -> /path/to/container");
+ SWTBotTreeItemAssertions.assertThat(containerVolumesItem.getNode(2))
+ .hasText("/path/to/host -> /path/to/container (Z,ro)");
+ });
+ }
+
+ @Test
+ public void shouldRemainExpandedAfterRefresh() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.noImages()
+ .container(MockDockerContainerFactory.name("foo_bar").build(),
+ MockDockerContainerInfoFactory.volume("/path/to/container")
+ .port("8080/tcp", "0.0.0.0", "8080")
+ .link("/foo:/bar/foo")
+ .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 (null)",
+ "Containers");
+ final SWTBotTreeItem containerTreeItem = SWTUtils.getTreeItem(containersTreeItem, "foo_bar (null)");
+ SWTUtils.asyncExec(() -> containerTreeItem.expand());
+ SWTUtils.asyncExec(() -> SWTUtils.getTreeItem(containerTreeItem, "Links").expand());
+ SWTUtils.asyncExec(() -> SWTUtils.getTreeItem(containerTreeItem, "Ports").expand());
+ SWTUtils.asyncExec(() -> SWTUtils.getTreeItem(containerTreeItem, "Volumes").expand());
+ // ensure items are actually expanded before calling the 'refresh' command
+ SWTUtils.syncAssert(() -> {
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containerTreeItem, "Links")).isExpanded();
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containerTreeItem, "Ports")).isExpanded();
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containerTreeItem, "Volumes")).isExpanded();
+ });
+ // when refreshing the container
+ SWTUtils.asyncExec(() -> {
+ dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
+ dockerExplorerViewTreeBot.select(containersTreeItem);
+ dockerExplorerViewTreeBot.contextMenu("Refresh").click();
+ });
+ SWTUtils.asyncExec(() -> containersTreeItem.expand());
+ // then all items should remain expanded (after they were reloaded)
+ SWTUtils.syncAssert(() -> {
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containerTreeItem, "Links")).isExpanded();
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containerTreeItem, "Ports")).isExpanded();
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containerTreeItem, "Volumes")).isExpanded();
+ });
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/icons/container_link.png b/containers/org.eclipse.linuxtools.docker.ui/icons/container_link.png
new file mode 100644
index 0000000000..cbcc0ca097
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/icons/container_link.png
Binary files differ
diff --git a/containers/org.eclipse.linuxtools.docker.ui/icons/container_port.png b/containers/org.eclipse.linuxtools.docker.ui/icons/container_port.png
new file mode 100644
index 0000000000..bd86db81b1
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/icons/container_port.png
Binary files differ
diff --git a/containers/org.eclipse.linuxtools.docker.ui/icons/container_volume.png b/containers/org.eclipse.linuxtools.docker.ui/icons/container_volume.png
new file mode 100644
index 0000000000..3d8c16c6f5
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/icons/container_volume.png
Binary files differ
diff --git a/containers/org.eclipse.linuxtools.docker.ui/pom.xml b/containers/org.eclipse.linuxtools.docker.ui/pom.xml
index 7054666361..ea2ffbfe38 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/pom.xml
+++ b/containers/org.eclipse.linuxtools.docker.ui/pom.xml
@@ -2,12 +2,11 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.eclipse.linuxtools</groupId>
- <artifactId>org.eclipse.linuxtools.docker</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <groupId>org.eclipse.linuxtools</groupId>
+ <artifactId>org.eclipse.linuxtools.docker</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.linuxtools.docker.ui</artifactId>
- <version>1.2.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/SWTImagesFactory.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/SWTImagesFactory.java
index 55117df391..1f7d7b89e8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/SWTImagesFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/SWTImagesFactory.java
@@ -87,6 +87,12 @@ public class SWTImagesFactory {
+ "container_paused.png"; //$NON-NLS-1$
public static final String IMG_CONTAINER_STOPPED = NAME_PREFIX
+ "container_stopped.png"; //$NON-NLS-1$
+ public static final String IMG_CONTAINER_VOLUME = NAME_PREFIX
+ + "container_volume.png"; //$NON-NLS-1$
+ public static final String IMG_CONTAINER_PORT = NAME_PREFIX
+ + "container_port.png"; //$NON-NLS-1$
+ public static final String IMG_CONTAINER_LINK = NAME_PREFIX
+ + "container_link.png"; //$NON-NLS-1$
public static final String IMG_SYSTEM_PROCESS = NAME_PREFIX
+ "systemprocess.gif"; //$NON-NLS-1$
public static final String IMG_CHECKED = NAME_PREFIX + "checked.gif"; //$NON-NLS-1$
@@ -164,6 +170,12 @@ public class SWTImagesFactory {
"", IMG_CONTAINER_PAUSED);
public static final ImageDescriptor DESC_CONTAINER_STOPPED = createManaged(
"", IMG_CONTAINER_STOPPED);
+ public static final ImageDescriptor DESC_CONTAINER_VOLUME = createManaged("",
+ IMG_CONTAINER_VOLUME);
+ public static final ImageDescriptor DESC_CONTAINER_PORT = createManaged("",
+ IMG_CONTAINER_PORT);
+ public static final ImageDescriptor DESC_CONTAINER_LINK = createManaged("",
+ IMG_CONTAINER_LINK);
public static final ImageDescriptor DESC_SYSTEM_PROCESS = createManaged("",
IMG_SYSTEM_PROCESS);
public static final ImageDescriptor DESC_CHECKED = createManaged("",
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
index c5577999ac..5ab0cd1f32 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
@@ -147,6 +147,7 @@ ViewerDaemonMissing.msg=No Docker daemon selected
ImagesLoadJob.msg=Loading images...
ContainersLoadJob.msg=Loading containers...
+ContainerInfoLoadJob.msg=Loading container info...
ImagesRemove.msg=Removing Images...
ImageRemove.msg=Removing {0}
@@ -193,4 +194,7 @@ Connection.unnamed=<unnamed>
Loading.label=Loading...
DockerContainersCategory.label=Containers
+DockerContainerPortMappingsCategory.label=Ports
+DockerContainerVolumesCategory.label=Volumes
+DockerContainerLinksCategory.label=Links
DockerImagesCategory.label=Images
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 5cb6b938c9..192e307b3e 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
@@ -11,6 +11,12 @@
package org.eclipse.linuxtools.internal.docker.ui.views;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -23,10 +29,18 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerContainer;
+import org.eclipse.linuxtools.docker.core.IDockerContainerInfo;
+import org.eclipse.linuxtools.docker.core.IDockerHostConfig;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerNetworkSettings;
+import org.eclipse.linuxtools.docker.core.IDockerPortBinding;
+import org.eclipse.linuxtools.docker.core.IDockerPortMapping;
+import org.eclipse.linuxtools.internal.docker.core.DockerPortMapping;
import org.eclipse.swt.widgets.Display;
/**
- * @author xcoulon
+ * {@link ITreeContentProvider} for the {@link DockerExplorerView}
*
*/
public class DockerExplorerContentProvider implements ITreeContentProvider {
@@ -75,6 +89,34 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
}
loadImages(imagesCategory);
return new Object[] { new LoadingStub(imagesCategory) };
+ } else if (parentElement instanceof IDockerContainer) {
+ final IDockerContainer container = (IDockerContainer) parentElement;
+ if (container.isInfoLoaded()) {
+ final IDockerContainerInfo info = container.info();
+ final IDockerNetworkSettings networkSettings = info
+ .networkSettings();
+ final IDockerHostConfig hostConfig = info.hostConfig();
+ return new Object[] {
+ new DockerContainerPortMappingsCategory(container,
+ networkSettings.ports()),
+ new DockerContainerVolumesCategory(container,
+ hostConfig.binds()),
+ new DockerContainerLinksCategory(container,
+ hostConfig.links()) };
+ }
+ loadContainerInfo(container);
+ return new Object[] { new LoadingStub(container) };
+ } else if (parentElement instanceof DockerContainerLinksCategory) {
+ final DockerContainerLinksCategory linksCategory = (DockerContainerLinksCategory) parentElement;
+ return linksCategory.getLinks().toArray();
+ } else
+ if (parentElement instanceof DockerContainerPortMappingsCategory) {
+ final DockerContainerPortMappingsCategory portMappingsCategory = (DockerContainerPortMappingsCategory) parentElement;
+ return portMappingsCategory.getPortMappings().toArray();
+
+ } else if (parentElement instanceof DockerContainerVolumesCategory) {
+ final DockerContainerVolumesCategory volumesCategory = (DockerContainerVolumesCategory) parentElement;
+ return volumesCategory.getVolumes().toArray();
}
return EMPTY;
}
@@ -84,7 +126,8 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
* @param containersCategory the selected {@link DockerContainersCategory}
*/
private void loadContainers(final DockerContainersCategory containersCategory) {
- final Job loadContainersJob = new Job("Loading containers...") {
+ final Job loadContainersJob = new Job(
+ DVMessages.getString("ContainersLoadJob.msg")) { //$NON-NLS-1$
@Override
protected IStatus run(final IProgressMonitor monitor) {
containersCategory.getConnection().getContainers(true);
@@ -112,11 +155,49 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
}
/**
+ * Call the {@link IDockerConnection#getContainers(boolean)} in a background
+ * job to avoid blocking the UI.
+ *
+ * @param container
+ * the selected {@link DockerContainersCategory}
+ */
+ private void loadContainerInfo(final IDockerContainer container) {
+ // only retain expanded tree paths if container was expanded
+ final TreePath[] expandedTreePaths = this.viewer.getExpandedState(
+ container) ? this.viewer.getExpandedTreePaths() : null;
+ final Job loadContainersJob = new Job(
+ DVMessages.getString("ContainerInfoLoadJob.msg")) { //$NON-NLS-1$
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ container.info(true);
+ return Status.OK_STATUS;
+ }
+ };
+ loadContainersJob.addJobChangeListener(new JobChangeAdapter() {
+ @Override
+ public void done(final IJobChangeEvent event) {
+ event.getResult();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ refreshTarget(container);
+ if (expandedTreePaths != null) {
+ viewer.setExpandedTreePaths(expandedTreePaths);
+ }
+ }
+ });
+ }
+ });
+ loadContainersJob.schedule();
+ }
+
+ /**
* Call the {@link IDockerConnection#getImages(boolean)} in a background job to avoid blocking the UI.
* @param imagesCategory the selected {@link DockerImagesCategory}
*/
private void loadImages(final DockerImagesCategory imagesCategory) {
- final Job loadImagesJob = new Job("Loading images...") {
+ final Job loadImagesJob = new Job(
+ DVMessages.getString("ImagesLoadJob.msg")) { //$NON-NLS-1$
@Override
protected IStatus run(final IProgressMonitor monitor) {
imagesCategory.getConnection().getImages(true);
@@ -150,7 +231,19 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
@Override
public boolean hasChildren(final Object element) {
- return (element instanceof IDockerConnection || element instanceof DockerContainersCategory || element instanceof DockerImagesCategory);
+ return (element instanceof IDockerConnection
+ || element instanceof DockerContainersCategory
+ || element instanceof DockerImagesCategory
+ || element instanceof IDockerContainer
+ || (element instanceof DockerContainerLinksCategory
+ && !((DockerContainerLinksCategory) element).getLinks()
+ .isEmpty())
+ || (element instanceof DockerContainerPortMappingsCategory
+ && !((DockerContainerPortMappingsCategory) element)
+ .getPortMappings().isEmpty())
+ || (element instanceof DockerContainerVolumesCategory
+ && !((DockerContainerVolumesCategory) element)
+ .getVolumes().isEmpty()));
}
/**
@@ -163,11 +256,11 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
private void refreshTarget(final Object target) {
// this piece of code must run in an async manner to avoid reentrant
// call while viewer is busy.
- Display.getDefault().asyncExec(new Runnable() {
+ Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
if (viewer != null) {
- TreePath[] treePaths = viewer.getExpandedTreePaths();
+ final TreePath[] treePaths = viewer.getExpandedTreePaths();
viewer.refresh(target, true);
viewer.setExpandedTreePaths(treePaths);
}
@@ -175,13 +268,17 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
});
}
+ /**
+ * Wrapper node to display {@link IDockerImage} of a given
+ * {@link IDockerConnection}
+ */
public static class DockerImagesCategory {
private final IDockerConnection connection;
/**
- * @param connection
- * - Docker connection
+ * @param container
+ * - Docker container
*/
public DockerImagesCategory(final IDockerConnection connection) {
this.connection = connection;
@@ -219,13 +316,17 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
}
+ /**
+ * Wrapper node to display {@link IDockerContainer} of a given
+ * {@link IDockerConnection}
+ */
public static class DockerContainersCategory {
private final IDockerConnection connection;
/**
- * @param connection
- * - Docker connection
+ * @param container
+ * - Docker container
*/
public DockerContainersCategory(final IDockerConnection connection) {
this.connection = connection;
@@ -260,10 +361,406 @@ public class DockerExplorerContentProvider implements ITreeContentProvider {
return false;
return true;
}
-
}
+ /**
+ * Wrapper node to display {@link IDockerPortMapping} of a given
+ * {@link IDockerContainer}
+ */
+ public static class DockerContainerPortMappingsCategory {
+
+ private final IDockerContainer container;
+
+ private final Map<String, List<IDockerPortBinding>> bindings;
+
+ /**
+ * @param container
+ * @param bindings
+ * - the container bindings
+ */
+ public DockerContainerPortMappingsCategory(
+ 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<>();
+ if (bindings != null) {
+ for (Entry<String, List<IDockerPortBinding>> entry : bindings
+ .entrySet()) {
+ // internal port is in the following form: "8080/tcp"
+ final String[] source = entry.getKey().split("/");
+ 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()));
+ }
+ }
+ }
+ Collections.sort(portMappings);
+ return portMappings;
+ }
+
+ @Override
+ public String toString() {
+ return "Port mappings for " + this.container.name();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((container == null) ? 0 : container.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DockerContainerPortMappingsCategory other = (DockerContainerPortMappingsCategory) obj;
+ if (container == null) {
+ if (other.container != null)
+ return false;
+ } else if (!container.equals(other.container))
+ return false;
+ return true;
+ }
+
+ }
+
+ /**
+ * Wrapper node to display the {@link DockerContainerLink} of a given
+ * {@link IDockerContainer}
+ */
+ public static class DockerContainerLinksCategory {
+
+ private final IDockerContainer container;
+
+ private final List<DockerContainerLink> links;
+
+ /**
+ * Constructor.
+ *
+ * @param container
+ *
+ * @param links
+ * - the container links
+ */
+ public DockerContainerLinksCategory(final IDockerContainer container,
+ final List<String> links) {
+ this.container = container;
+ this.links = new ArrayList<>();
+ if (links != null) {
+ for (String link : links) {
+ this.links.add(new DockerContainerLink(link));
+ }
+ }
+ }
+
+ public List<DockerContainerLink> getLinks() {
+ if (this.links == null) {
+ return Collections.emptyList();
+ }
+ return this.links;
+ }
+
+ @Override
+ public String toString() {
+ return "Container links for " + this.container.name();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((container == null) ? 0 : container.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DockerContainerLinksCategory other = (DockerContainerLinksCategory) obj;
+ if (container == null) {
+ if (other.container != null)
+ return false;
+ } else if (!container.equals(other.container))
+ return false;
+ return true;
+ }
+
+ }
+
+ public static class DockerContainerLink {
+
+ private final String containerName;
+
+ private final String containerAlias;
+
+ /**
+ * Constructor.
+ *
+ * @param linkValue
+ * the bind value provided by the {@link IDockerHostConfig}.
+ */
+ public DockerContainerLink(final String linkValue) {
+ // format: "container_name:containerAlias"
+ final String[] args = linkValue.split(":");
+ this.containerName = getDisplayableContainerName(args[0]);
+ this.containerAlias = args.length > 0
+ ? getDisplayableContainerAlias(args[1]) : null;
+ }
+
+ /**
+ * Removes the heading "/" i(if found) in the given container name
+ *
+ * @param containerName
+ * @return a displayable container name
+ */
+ private String getDisplayableContainerName(final String containerName) {
+ return containerName.startsWith("/") ? containerName.substring(1)
+ : containerName;
+ }
+
+ /**
+ * Removes the heading "/" i(if found) in the given container name
+ *
+ * @param containerName
+ * @return a displayable container name
+ */
+ private String getDisplayableContainerAlias(
+ final String containerAlias) {
+ final String[] containerAliasSplit = containerAlias.split("/");
+ if (containerAliasSplit.length > 1) {
+ return containerAliasSplit[2];
+ }
+ return null;
+ }
+
+ public String getContainerName() {
+ return containerName;
+ }
+
+ public String getContainerAlias() {
+ return containerAlias;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((containerAlias == null) ? 0 : containerAlias.hashCode());
+ result = prime * result
+ + ((containerName == null) ? 0 : containerName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DockerContainerLink other = (DockerContainerLink) obj;
+ if (containerAlias == null) {
+ if (other.containerAlias != null)
+ return false;
+ } else if (!containerAlias.equals(other.containerAlias))
+ return false;
+ if (containerName == null) {
+ if (other.containerName != null)
+ return false;
+ } else if (!containerName.equals(other.containerName))
+ return false;
+ return true;
+ }
+
+ }
+
+ /**
+ * Wrapper node to display {@link DockerContainerVolume} of a given
+ * {@link IDockerContainer}
+ */
+ public static class DockerContainerVolumesCategory {
+
+ private final IDockerContainer container;
+
+ private final List<DockerContainerVolume> volumes;
+
+ /**
+ * Constructor.
+ *
+ * @param container
+ *
+ * @param volumes
+ * - the parent Docker container
+ */
+ public DockerContainerVolumesCategory(final IDockerContainer container,
+ final List<String> volumes) {
+ this.container = container;
+ this.volumes = new ArrayList<>();
+ if (volumes != null) {
+ for (String volume : volumes) {
+ this.volumes.add(new DockerContainerVolume(volume));
+ }
+ }
+ }
+
+ public List<DockerContainerVolume> getVolumes() {
+ if (this.volumes == null) {
+ return Collections.emptyList();
+ }
+ return volumes;
+ }
+
+ @Override
+ public String toString() {
+ return "Volumes for " + this.container.name();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((container == null) ? 0 : container.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DockerContainerVolumesCategory other = (DockerContainerVolumesCategory) obj;
+ if (container == null) {
+ if (other.container != null)
+ return false;
+ } else if (!container.equals(other.container))
+ return false;
+ return true;
+ }
+
+ }
+
+ public static class DockerContainerVolume {
+
+ private final String hostPath;
+
+ private final String containerPath;
+
+ private final String flags;
+
+ /**
+ * @param volume
+ * the volume value provided by the {@link IDockerHostConfig}
+ * .
+ * @return a {@link DockerContainerVolume}
+ */
+ public DockerContainerVolume(final String volume) {
+ // (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
+ // (3) "host_path:container_path:ro" to make the bind-mount
+ // read-only
+ // inside the container.
+ final String[] args = volume.split(":");
+ // on case (1), hostPath is null
+ this.hostPath = args.length > 1 ? args[0] : null;
+ // on case (1), containerPath is the first (and only) arg, otherwise
+ // it's the second one.
+ this.containerPath = args.length > 1 ? args[1] : args[0];
+ // flags exists on case (3) only
+ this.flags = args.length > 2 ? args[2] : null;
+ }
+
+ public String getHostPath() {
+ return hostPath;
+ }
+
+ public String getContainerPath() {
+ return containerPath;
+ }
+
+ public String getFlags() {
+ return flags;
+ }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((containerPath == null) ? 0 : containerPath.hashCode());
+ result = prime * result + ((flags == null) ? 0 : flags.hashCode());
+ result = prime * result
+ + ((hostPath == null) ? 0 : hostPath.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DockerContainerVolume other = (DockerContainerVolume) obj;
+ if (containerPath == null) {
+ if (other.containerPath != null)
+ return false;
+ } else if (!containerPath.equals(other.containerPath))
+ return false;
+ if (flags == null) {
+ if (other.flags != null)
+ return false;
+ } else if (!flags.equals(other.flags))
+ return false;
+ if (hostPath == null) {
+ if (other.hostPath != null)
+ return false;
+ } else if (!hostPath.equals(other.hostPath))
+ return false;
+ return true;
+ }
+
+ }
+
+ /**
+ * Node to indicate that a job is running and loading data.
+ */
public static class LoadingStub {
private final Object element;
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 c1649f1210..42f88aeac5 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
@@ -26,7 +26,13 @@ import org.eclipse.linuxtools.docker.core.EnumDockerStatus;
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.internal.docker.ui.SWTImagesFactory;
+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.DockerExplorerContentProvider.LoadingStub;
@@ -78,6 +84,15 @@ public class DockerExplorerLabelProvider implements IStyledLabelProvider, ILabel
} else {
return SWTImagesFactory.DESC_CONTAINER_STOPPED.createImage();
}
+ } else if (element instanceof DockerContainerLinksCategory
+ || element instanceof DockerContainerLink) {
+ return SWTImagesFactory.DESC_CONTAINER_LINK.createImage();
+ } else if (element instanceof DockerContainerVolumesCategory
+ || element instanceof DockerContainerVolume) {
+ return SWTImagesFactory.DESC_CONTAINER_VOLUME.createImage();
+ } else if (element instanceof DockerContainerPortMappingsCategory
+ || element instanceof IDockerPortMapping) {
+ return SWTImagesFactory.DESC_CONTAINER_PORT.createImage();
} else if(element instanceof LoadingStub) {
return SWTImagesFactory.DESC_SYSTEM_PROCESS.createImage();
}
@@ -135,7 +150,7 @@ public class DockerExplorerLabelProvider implements IStyledLabelProvider, ILabel
if (!dockerImage.tags().isEmpty()) {
final List<String> tags = new ArrayList<>(dockerImage.tags());
Collections.sort(tags);
- messageBuilder.append(":");
+ messageBuilder.append(": ");
for (Iterator<String> tagIterator = tags.iterator(); tagIterator
.hasNext();) {
messageBuilder.append(tagIterator.next());
@@ -143,18 +158,75 @@ public class DockerExplorerLabelProvider implements IStyledLabelProvider, ILabel
messageBuilder.append(", ");
}
}
- final int startImageId = messageBuilder.length();
- messageBuilder.append(" (").append(imageShortId).append(')');
- final String message = messageBuilder.toString();
- final StyledString styledString = new StyledString(message);
- // styled tags
- styledString.setStyle(startTags, startImageId - startTags, StyledString.COUNTER_STYLER);
- // styled image id
- styledString.setStyle(startImageId, message.length() - startImageId, StyledString.QUALIFIER_STYLER);
- return styledString;
}
- } else if (element instanceof LoadingStub) {
- return new StyledString(DVMessages.getString("Loading.label")); //$NON-NLS-1$
+ final int startImageId = messageBuilder.length();
+ messageBuilder.append(" (").append(imageShortId).append(')');
+ final String message = messageBuilder.toString();
+ final StyledString styledString = new StyledString(message);
+ // styled tags
+ styledString.setStyle(startTags, startImageId - startTags,
+ StyledString.COUNTER_STYLER);
+ // styled image id
+ styledString.setStyle(startImageId, message.length() - startImageId,
+ StyledString.QUALIFIER_STYLER);
+ return styledString;
+ } else if (element instanceof DockerContainerPortMappingsCategory) {
+ return new StyledString(DVMessages
+ .getString("DockerContainerPortMappingsCategory.label")); //$NON-NLS-1$
+ } else if (element instanceof IDockerPortMapping) {
+ final IDockerPortMapping mapping = (IDockerPortMapping) element;
+ final String hostMapping = mapping.getIp() + ":"
+ + mapping.getPublicPort() + " -> ";
+ final String containerMapping = Integer
+ .toString(mapping.getPrivatePort());
+ final String mappingType = " (" + mapping.getType() + ")";
+ final StyledString styledString = new StyledString(
+ hostMapping + containerMapping + mappingType);
+ styledString.setStyle(
+ hostMapping.length() + containerMapping.length(),
+ mappingType.length(), StyledString.QUALIFIER_STYLER);
+ return styledString;
+ } else if (element instanceof DockerContainerVolumesCategory) {
+ return new StyledString(DVMessages
+ .getString("DockerContainerVolumesCategory.label")); //$NON-NLS-1$
+ } else if (element instanceof DockerContainerVolume) {
+ final DockerContainerVolume containerVolume = (DockerContainerVolume) element;
+ final String hostPath = containerVolume.getHostPath();
+ final StyledString styledString = new StyledString();
+ if (containerVolume.getHostPath() != null
+ && containerVolume.getContainerPath() != null) {
+ styledString.append(hostPath).append(" -> ")
+ .append(containerVolume.getContainerPath());
+ } else if (containerVolume.getHostPath() == null
+ && containerVolume.getContainerPath() != null) {
+ styledString.append(containerVolume.getContainerPath());
+ }
+ if (containerVolume.getFlags() != null) {
+ final int offset = styledString.length();
+ styledString.append(" (" + containerVolume.getFlags() + ")");
+ styledString.setStyle(offset, styledString.length() - offset,
+ StyledString.QUALIFIER_STYLER);
+ }
+ return styledString;
+ } else if (element instanceof DockerContainerLinksCategory) {
+ return new StyledString(
+ DVMessages.getString("DockerContainerLinksCategory.label")); //$NON-NLS-1$
+ } else if (element instanceof DockerContainerLink) {
+ final DockerContainerLink containerLink = (DockerContainerLink) element;
+ final String containerName = containerLink.getContainerName();
+ final String containerAlias = " ("
+ + containerLink.getContainerAlias() + ")";
+ final StyledString styledString = new StyledString(
+ containerName + containerAlias);
+ styledString.setStyle(containerName.length(),
+ containerAlias.length(), StyledString.QUALIFIER_STYLER);
+ return styledString;
+ } else if (element instanceof String) {
+ return new StyledString((String) element);
+ }
+
+ else if (element instanceof LoadingStub) {
+ return new StyledString(DVMessages.getString("Loading.label"));
}
return null;
}

Back to the top