Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-08-03 08:23:13 +0000
committerXavier Coulon2016-08-04 08:53:09 +0000
commitcf125f221c89f4a0f71cdb346ee2d26d64ca3711 (patch)
tree5ac7c5a8fea24ba84c09aa1211e291a2ec1323e0
parentdf0303e4b4dd0338287f7ca5ed40d2a976bed652 (diff)
downloadorg.eclipse.linuxtools-cf125f221c89f4a0f71cdb346ee2d26d64ca3711.tar.gz
org.eclipse.linuxtools-cf125f221c89f4a0f71cdb346ee2d26d64ca3711.tar.xz
org.eclipse.linuxtools-cf125f221c89f4a0f71cdb346ee2d26d64ca3711.zip
Bug 496308 - Docker Hierarchy view
Initial proposal for the hierarchy view Further commits may include context menu and even containers based on the selected image. Change-Id: Ic9ca000ea5b5969b5527e4bf4128a6c55df305e8 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/78177 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageHiearchyNode.java44
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java39
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHiearchyNode.java63
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerImageFactory.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageFactory.java5
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTUtils.java23
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyViewSWTBotTest.java129
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/icons/class_hi.pngbin0 -> 306 bytes
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.properties7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.xml82
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/OpenImageHierarchyViewCommandHandler.java71
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInPropertiesViewCommandHandler.java6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/BuildDockerImageJob.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/JobMessages.properties5
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/RetrieveImageHierarchyJob.java76
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInfoContentProvider.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInspectContentProvider.java32
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerLabelProvider.java35
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyContentProvider.java73
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyLabelProvider.java71
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyView.java153
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInfoContentProvider.java12
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInspectContentProvider.java24
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java (renamed from containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelUtils.java)45
28 files changed, 921 insertions, 102 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageHiearchyNode.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageHiearchyNode.java
new file mode 100644
index 0000000000..b934c4a2ac
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageHiearchyNode.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.docker.core;
+
+import java.util.List;
+
+/**
+ * The Hierarchy for a given {@link IDockerImage}
+ */
+public interface IDockerImageHiearchyNode {
+
+ /**
+ * @return the selected {@link IDockerImage}
+ */
+ public IDockerImage getImage();
+
+ /**
+ * @return the {@link IDockerImageHiearchyNode} of the parent
+ * {@link IDockerImage}
+ */
+ public IDockerImageHiearchyNode getParent();
+
+ /**
+ * @return the {@link IDockerImageHiearchyNode} of all {@link IDockerImage}
+ * whose parent is the {@link IDockerImage} associated with this
+ * {@link IDockerImageHiearchyNode}
+ */
+ public List<IDockerImageHiearchyNode> getChildren();
+
+ /**
+ * @return the root node of the resolved hierarchy
+ */
+ public IDockerImageHiearchyNode getRoot();
+
+}
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 234d72ef57..0df7651955 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
@@ -29,6 +29,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Set;
import javax.ws.rs.ProcessingException;
@@ -64,6 +65,7 @@ import org.eclipse.linuxtools.docker.core.IDockerContainerListener;
import org.eclipse.linuxtools.docker.core.IDockerHostConfig;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.core.IDockerImageBuildOptions;
+import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
import org.eclipse.linuxtools.docker.core.IDockerImageInfo;
import org.eclipse.linuxtools.docker.core.IDockerImageListener;
import org.eclipse.linuxtools.docker.core.IDockerImageSearchResult;
@@ -2075,4 +2077,41 @@ public class DockerConnection implements IDockerConnection, Closeable {
return getSettings().hashCode();
}
+ /**
+ * Retrieves the whole hierarchy for the given {@link IDockerImage}. This
+ * includes the path to all known parent images, along with all derived
+ * images based on the given {@code image}.
+ *
+ * @param image
+ * the {@link IDockerImage} for which the hierarchy should be
+ * resolved
+ * @return the {@link IDockerImageHiearchyNode} as a node that can be
+ * traversed.
+ */
+ // @Override
+ // TODO: add this method in the IDockerConnection interface
+ public IDockerImageHiearchyNode resolveImageHierarchy(
+ final IDockerImage image) {
+ // recursively find all parents and build associated
+ // IDockerImageHiearchyNode instances
+ return new DockerImageHiearchyNode(image,
+ getImageHierarchy(image.parentId()));
+ }
+
+ private IDockerImageHiearchyNode getImageHierarchy(final String imageId) {
+ // recursively find all parents and build associated
+ // IDockerImageHiearchyNode instances
+ final Optional<IDockerImage> optionalParentImage = this.images.stream()
+ .filter(image -> image.id().equals(imageId)).findFirst();
+ // parent image found: get its own parent image hierarchy
+ if (optionalParentImage.isPresent()) {
+ //
+ final IDockerImage parentImage = optionalParentImage.get();
+ return new DockerImageHiearchyNode(parentImage,
+ getImageHierarchy(parentImage.parentId()));
+ }
+ // no parent image found: stop here.
+ return null;
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHiearchyNode.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHiearchyNode.java
new file mode 100644
index 0000000000..19286a28fd
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHiearchyNode.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
+
+/**
+ * Default implementation of the {@link IDockerImageHiearchyNode} interface.
+ */
+public class DockerImageHiearchyNode implements IDockerImageHiearchyNode {
+
+ private final IDockerImage image;
+
+ private IDockerImageHiearchyNode parent;
+
+ private List<IDockerImageHiearchyNode> children;
+
+ public DockerImageHiearchyNode(final IDockerImage image,
+ final IDockerImageHiearchyNode parentImageHiearchyNode) {
+ this.image = image;
+ this.children = new ArrayList<>();
+ this.parent = parentImageHiearchyNode;
+ if (parent != null) {
+ this.parent.getChildren().add(this);
+ }
+ }
+
+ @Override
+ public IDockerImage getImage() {
+ return this.image;
+ }
+
+ @Override
+ public IDockerImageHiearchyNode getParent() {
+ return this.parent;
+ }
+
+ @Override
+ public List<IDockerImageHiearchyNode> getChildren() {
+ return this.children;
+ }
+
+ @Override
+ public IDockerImageHiearchyNode getRoot() {
+ if (this.parent == null) {
+ return this;
+ }
+ return this.parent.getRoot();
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerImageFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerImageFactory.java
index 59606f67cc..e8f9936796 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerImageFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerImageFactory.java
@@ -70,7 +70,7 @@ public class MockDockerImageFactory {
return this;
}
- public Builder connection(IDockerConnection connection) {
+ public Builder connection(final IDockerConnection connection) {
Mockito.when(this.image.getConnection()).thenReturn(connection);
return this;
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageFactory.java
index dc7df3293e..7f8439be46 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageFactory.java
@@ -70,6 +70,11 @@ public class MockImageFactory {
return this;
}
+ public Builder parentId(final String parentId) {
+ Mockito.when(this.image.parentId()).thenReturn(parentId);
+ return this;
+ }
+
public Image build() {
return image;
}
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 dd7e58adb3..1f7729a63f 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
@@ -380,27 +380,26 @@ public class SWTUtils {
return getSubMenu(subMenu, remainingPath);
}
- public static SWTBotTreeItem expand(final SWTBotTree tree, final String... path) {
- final SWTBotTreeItem rootItem = getTreeItem(tree, path[0]);
+ public static SWTBotTreeItem expand(final SWTBotTree tree, final String... paths) {
+ final SWTBotTreeItem rootItem = getTreeItem(tree, paths[0]);
expandTreeItem(rootItem);
-
- if(path.length > 1) {
- final String[] remainingPath = new String[path.length -1];
- System.arraycopy(path, 1, remainingPath, 0, remainingPath.length);
+ if (paths.length > 1) {
+ final String[] remainingPath = new String[paths.length - 1];
+ System.arraycopy(paths, 1, remainingPath, 0, remainingPath.length);
return expand(rootItem, remainingPath);
}
return rootItem;
}
- public static SWTBotTreeItem expand(final SWTBotTreeItem treeItem, final String... path) {
- final SWTBotTreeItem childItem = getTreeItem(treeItem, path[0]);
+ public static SWTBotTreeItem expand(final SWTBotTreeItem treeItem, final String... paths) {
+ final SWTBotTreeItem childItem = getTreeItem(treeItem, paths[0]);
expandTreeItem(childItem);
- if(path.length > 1) {
- final String[] remainingPath = new String[path.length -1];
- System.arraycopy(path, 1, remainingPath, 0, remainingPath.length);
+ if (paths.length > 1) {
+ final String[] remainingPath = new String[paths.length - 1];
+ System.arraycopy(paths, 1, remainingPath, 0, remainingPath.length);
return expand(childItem, remainingPath);
}
- return getTreeItem(treeItem, path[0]);
+ return getTreeItem(treeItem, paths[0]);
}
private static SWTBotTreeItem expandTreeItem(final SWTBotTreeItem treeItem) {
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 3d8ee20a5a..f41590b7b3 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
@@ -127,7 +127,7 @@ public class DockerExplorerViewSWTBotTest {
final SWTBotTreeItem imagesTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, connectionName, "Images");
SWTUtils.asyncExec(() -> imagesTreeItem.expand());
// select both containers
- SWTUtils.select(imagesTreeItem, imageNames);
+ SWTUtils.getTreeItem(imagesTreeItem, imageNames).select();
}
@Test
@@ -290,9 +290,9 @@ public class DockerExplorerViewSWTBotTest {
dockerExplorerViewBot.bot().tree().contextMenu("Refresh").click();
SWTUtils.asyncExec(() -> containers.expand());
// then all items should remain expanded (after they were reloaded)
- SWTBotTreeItemAssertions.assertThat(SWTUtils.select(containers, "foo_bar", "Links")).isExpanded();
- SWTBotTreeItemAssertions.assertThat(SWTUtils.select(containers, "foo_bar", "Ports")).isExpanded();
- SWTBotTreeItemAssertions.assertThat(SWTUtils.select(containers, "foo_bar", "Volumes")).isExpanded();
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containers, "foo_bar", "Links")).isExpanded();
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containers, "foo_bar", "Ports")).isExpanded();
+ SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containers, "foo_bar", "Volumes")).isExpanded();
}
@Test
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyViewSWTBotTest.java
new file mode 100644
index 0000000000..4440b20ec4
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyViewSWTBotTest.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.views;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
+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.MockImageFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionManagerRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TestLoggerRule;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.ui.PlatformUI;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.spotify.docker.client.DockerClient;
+import com.spotify.docker.client.messages.Image;
+
+/**
+ * Testing the {@link DockerImageHierarchyView} call from the {@link DockerExplorerView}.
+ */
+public class DockerImageHierarchyViewSWTBotTest {
+
+ private SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ private SWTBotView dockerExplorerViewBot;
+ private DockerExplorerView dockerExplorerView;
+
+ @ClassRule
+ public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule();
+
+ @Rule
+ public TestLoggerRule watcher = new TestLoggerRule();
+
+ @Rule
+ public ClearConnectionManagerRule clearConnectionManager = new ClearConnectionManagerRule();
+
+ @Before
+ public void setup() {
+ this.bot = new SWTWorkbenchBot();
+ SWTUtils.asyncExec(() -> {
+ try {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .showView(DockerExplorerView.VIEW_ID);
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail("Failed to open Docker Explorer view: " + e.getMessage());
+ }
+ });
+ this.dockerExplorerViewBot = bot.viewById(DockerExplorerView.VIEW_ID);
+ this.dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference().getView(true));
+ // make sure that the Docker Image Hierarchy view is closed
+ this.bot.views().stream().filter(v -> v.getReference().getId().equals(DockerImageHierarchyView.VIEW_ID))
+ .forEach(v -> v.close());
+ }
+
+ @After
+ public void hideMenu() {
+ try {
+ SWTUtils.hideMenu(dockerExplorerViewBot.bot().tree());
+ } catch (WidgetNotFoundException e) {
+ // ignore if widget is not found, that's probably because there's no
+ // tree in the
+ // Docker Explorer view for the test that just ran.
+ }
+ }
+
+ @Test
+ public void shouldDisplayImageHierarchyView() {
+ // given
+ final Image rootImage = MockImageFactory.id("sha256:root").name("root").build();
+ final Image fooImage = MockImageFactory.id("sha256:foo").name("foo").parentId("sha256:root").build();
+ final Image barImage = MockImageFactory.id("sha256:bar").name("bar").parentId("sha256:foo").build();
+ final DockerClient client = MockDockerClientFactory
+ .image(rootImage).image(fooImage).image(barImage).build();
+ final DockerConnection connection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
+ DockerConnectionManagerUtils.configureConnectionManager(connection);
+ connection.getImages(true);
+ final IDockerImage image = connection.getImages().stream().filter(i -> i.id().equals("sha256:foo")).findFirst().get();
+ // when
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo").select();
+ dockerExplorerViewBot.bot().tree().contextMenu("Open Image Hierarchy").click(); //$NON-NLS-1$
+ // then
+ final SWTBotView dockerImageHierarchyView = bot.viewById(DockerImageHierarchyView.VIEW_ID);
+
+ }
+
+ @Test
+ public void shouldRetrieveImageHierarchy() {
+ // given
+ final Image rootImage = MockImageFactory.id("sha256:root").name("root").build();
+ final Image fooImage = MockImageFactory.id("sha256:foo").name("foo").parentId("sha256:root").build();
+ final Image barImage = MockImageFactory.id("sha256:bar").name("bar").parentId("sha256:foo").build();
+ final DockerClient client = MockDockerClientFactory
+ .image(rootImage).image(fooImage).image(barImage).build();
+ final DockerConnection connection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
+ connection.getImages(true);
+ final IDockerImage image = connection.getImages().stream().filter(i -> i.id().equals("sha256:foo")).findFirst().get();
+ // when
+ final IDockerImageHiearchyNode imageHierarchy = connection.resolveImageHierarchy(image);
+ // then
+ assertThat(imageHierarchy).isNotNull();
+ assertThat(imageHierarchy.getImage().id()).isEqualTo("sha256:foo");
+ assertThat(imageHierarchy.getParent().getImage().id()).isEqualTo("sha256:root");
+ assertThat(imageHierarchy.getParent().getChildren()).containsExactly(imageHierarchy);
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/icons/class_hi.png b/containers/org.eclipse.linuxtools.docker.ui/icons/class_hi.png
new file mode 100644
index 0000000000..4f3f0638fb
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/icons/class_hi.png
Binary files differ
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
index 40f91fc098..3fbde356e7 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
@@ -4,6 +4,8 @@ DockerContainersView.name=Docker Containers
DockerContainersProvider.name=Docker Containers
DockerExplorerView.name=Docker Explorer
DockerExplorerContent.name=Docker daemons
+DockerImageHierarchyView.name=Docker Image Hierarchy
+DockerImageHierarchyContent.name=Docker Image Hierarchy
DockerPerspective.name=Docker Tooling
@@ -128,6 +130,11 @@ command.showInSystemExplorer.menu.descrption=Show in System Explorer
command.execcontainer.name = Execute Shell
command.execcontainer.description = Get an interactive shell into this container
+command.openImageHierarchy.name = Open Image Hierarchy
+command.openImageHierarchy.label = Open Image Hierarchy
+command.openImageHierarchy.description = Open the Docker image Hierarchy view
+
+
LaunchActionSet.label=Launch
RunMenu.label=&Run
OpenRunConfigurations.label=Ru&n Configurations...
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
index 93fa0ea091..feb23c84c9 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
@@ -64,6 +64,14 @@
name="%DockerExplorerView.name"
restorable="true">
</view>
+ <view
+ category="org.eclipse.linuxtools.docker.ui"
+ class="org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyView"
+ icon="icons/class_hi.png"
+ id="org.eclipse.linuxtools.docker.ui.dockerImageHierarchyView"
+ name="%DockerImageHierarchyView.name"
+ restorable="true">
+ </view>
</extension>
<extension
@@ -144,6 +152,32 @@
name="%StoppedContainerViewFilter.name">
</commonFilter>
</extension>
+ <extension
+ point="org.eclipse.ui.navigator.viewer">
+ <viewer
+ viewerId="org.eclipse.linuxtools.docker.ui.dockerImageHierarchyView">
+ </viewer>
+ <viewerContentBinding
+ viewerId="org.eclipse.linuxtools.docker.ui.dockerImageHierarchyView">
+ <includes>
+ <contentExtension
+ isRoot="true"
+ pattern="org.eclipse.linuxtools.docker.ui.dockerImageHierarchyContent">
+ </contentExtension>
+ </includes>
+ </viewerContentBinding>
+ </extension>
+ <extension
+ point="org.eclipse.ui.navigator.navigatorContent">
+ <navigatorContent
+ id="org.eclipse.linuxtools.docker.ui.dockerImageHierarchyContent"
+ name="%DockerImageHierarchyContent.name"
+ contentProvider="org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyContentProvider"
+ labelProvider="org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyLabelProvider"
+ priority="highest">
+ <triggerPoints></triggerPoints>
+ </navigatorContent>
+ </extension>
<!-- Refresh View -->
<extension
@@ -302,6 +336,11 @@
id="org.eclipse.linuxtools.docker.ui.commands.execContainer"
name="%command.execcontainer.name">
</command>
+ <command
+ description="%command.openImageHierarchy.description"
+ id="org.eclipse.linuxtools.docker.ui.commands.openImageHierarchyView"
+ name="%command.openImageHierarchy.name">
+ </command>
</extension>
<extension
@@ -660,6 +699,21 @@
</with>
</enabledWhen>
</handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.docker.ui.commands.OpenImageHierarchyViewCommandHandler"
+ commandId="org.eclipse.linuxtools.docker.ui.commands.openImageHierarchyView">
+ <enabledWhen>
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false">
+ <instanceof
+ value="org.eclipse.linuxtools.docker.core.IDockerImage">
+ </instanceof>
+ </iterate>
+ </with>
+ </enabledWhen>
+ </handler>
</extension>
<!-- property testers -->
@@ -743,7 +797,7 @@
</visibleWhen>
</command>
</menuContribution>
-
+ <!-- explorer view toolbar: enable connection -->
<menuContribution
locationURI="toolbar:org.eclipse.linuxtools.docker.ui.dockerExplorerView">
<command
@@ -1147,6 +1201,32 @@
</visibleWhen>
</command>
</menuContribution>
+ <!-- Docker Explorer View: open hierarchy -->
+ <menuContribution
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=group.edit">
+ <command
+ commandId="org.eclipse.linuxtools.docker.ui.commands.openImageHierarchyView"
+ icon="icons/class_hi.png"
+ label="%command.openImageHierarchy.label"
+ mnemonic="R"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <instanceof
+ value="org.eclipse.linuxtools.docker.core.IDockerImage" />
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
<!-- explorer view context menu: push image -->
<menuContribution
locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=org.eclipse.linuxtools.docker.ui.commands.removeImages">
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/OpenImageHierarchyViewCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/OpenImageHierarchyViewCommandHandler.java
new file mode 100644
index 0000000000..e55545a10f
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/OpenImageHierarchyViewCommandHandler.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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 org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.linuxtools.docker.core.Activator;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.internal.docker.ui.jobs.RetrieveImageHierarchyJob;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyView;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Handler for the
+ */
+public class OpenImageHierarchyViewCommandHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ // retrieve the selected image
+ final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ final IDockerImage selectedImage = RunImageCommandHandler
+ .getSelectedImage(activePart);
+ // run a job to retrieve the image hierarchy
+ final RetrieveImageHierarchyJob retrieveImageHierarchyJob = new RetrieveImageHierarchyJob(
+ selectedImage);
+ retrieveImageHierarchyJob.addJobChangeListener(new JobChangeAdapter() {
+ @Override
+ public void done(IJobChangeEvent event) {
+ // open the Image Hierarchy View and set the selected image as
+ // the new
+ // input
+ Display.getDefault().asyncExec(() -> {
+ try {
+ final DockerImageHierarchyView dockerImageHierarchyView = (DockerImageHierarchyView) PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage()
+ .showView(DockerImageHierarchyView.VIEW_ID);
+ dockerImageHierarchyView.show(
+ retrieveImageHierarchyJob.getImageHierarchy());
+ } catch (PartInitException e) {
+ Activator.logErrorMessage(CommandMessages.getString(
+ "command.showIn.propertiesView.failure"), //$NON-NLS-1$
+ e);
+
+ }
+ });
+ }
+ });
+ retrieveImageHierarchyJob.schedule();
+ //
+ return null;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInPropertiesViewCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInPropertiesViewCommandHandler.java
index 51167c4dea..56d893f52a 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInPropertiesViewCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/ShowInPropertiesViewCommandHandler.java
@@ -43,14 +43,10 @@ public class ShowInPropertiesViewCommandHandler extends AbstractHandler {
final PropertySheet propertySheet = (PropertySheet) PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
.getActivePage()
- .showView("org.eclipse.ui.views.PropertySheet");
+ .showView("org.eclipse.ui.views.PropertySheet"); //$NON-NLS-1$
final PropertyShowInContext showInContext = new PropertyShowInContext(
activePart, HandlerUtil.getCurrentSelection(event));
propertySheet.show(showInContext);
- // final TabbedPropertySheetPage tabbedPropertySheetPage =
- // activePart
- // .getAdapter(TabbedPropertySheetPage.class);
- // tabbedPropertySheetPage.setFocus();
} catch (PartInitException e) {
Activator.logErrorMessage(
CommandMessages.getString(
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/BuildDockerImageJob.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/BuildDockerImageJob.java
index 3867949b8c..09bb9061b5 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/BuildDockerImageJob.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/BuildDockerImageJob.java
@@ -44,7 +44,7 @@ import org.eclipse.ui.PlatformUI;
*/
public class BuildDockerImageJob extends Job implements IDockerProgressHandler {
- private static final String BUILD_IMAGE_JOB_TITLE = "BuildImageJog.title"; //$NON-NLS-1$
+ private static final String BUILD_IMAGE_JOB_TITLE = "BuildImageJob.title"; //$NON-NLS-1$
private static final String BUILD_IMAGE_ERROR_MESSAGE = "BuildImageError.msg"; //$NON-NLS-1$
private static final String DOCKERFILE_LINE_COUNT_ERROR = "ImageBuildError.msg"; //$NON-NLS-1$
private static final String SKIP_EMPTY_DOCKERFILE = "SkipEmptydockerfile.msg"; //$NON-NLS-1$
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/JobMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/JobMessages.properties
index 805d61decf..6d89693187 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/JobMessages.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/JobMessages.properties
@@ -9,6 +9,7 @@
# Red Hat - Initial Contribution
###############################################################################
-BuildImageJog.title=Building Docker Image
+BuildImageJob.title=Building Docker Image
BuildImageError.msg=Error while building Docker Image
-SkipEmptydockerfile.msg=Skipping empty Docker build file. \ No newline at end of file
+SkipEmptydockerfile.msg=Skipping empty Docker build file.
+RetrieveImageHierarchyJob.title=Retrieving Docker Image hierarchy \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/RetrieveImageHierarchyJob.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/RetrieveImageHierarchyJob.java
new file mode 100644
index 0000000000..a5f2e1ea01
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/RetrieveImageHierarchyJob.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.jobs;
+
+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.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+
+/**
+ * A {@link Job} to retrieve the hierarchy of an {@link IDockerImage}
+ */
+public class RetrieveImageHierarchyJob extends Job {
+
+ /**
+ * the {@link IDockerImage} for which the hierarchy needs to be retrieved.
+ */
+ private final IDockerImage dockerImage;
+
+ /**
+ * the {@link IDockerImageHiearchyNode} that was retrieved while the job was
+ * executed.
+ */
+ private IDockerImageHiearchyNode imageHierarchy;
+
+ /**
+ * Constructor
+ *
+ * @param dockerImage
+ * the {@link IDockerImage} for which the hierarchy needs to be
+ * retrieved.
+ */
+ public RetrieveImageHierarchyJob(final IDockerImage dockerImage) {
+ super(JobMessages.getString("RetrieveImageHierarchyJob.title")); //$NON-NLS-1$
+ this.dockerImage = dockerImage;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ monitor.beginTask(
+ JobMessages.getString("RetrieveImageHierarchyJob.title"),
+ 1);
+ // TODO: remove the cast once the 'resolveImageHierarchy' method has
+ // been added in the IDockerConnection interface.
+ this.imageHierarchy = ((DockerConnection) dockerImage
+ .getConnection())
+ .resolveImageHierarchy(dockerImage);
+ } finally {
+ monitor.done();
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * @return the {@link IDockerImageHiearchyNode} that was retrieved while the
+ * job was executed.
+ */
+ public IDockerImageHiearchyNode getImageHierarchy() {
+ return this.imageHierarchy;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInfoContentProvider.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInfoContentProvider.java
index 4a0fbf1e8e..b91aaf49ae 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInfoContentProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInfoContentProvider.java
@@ -45,7 +45,7 @@ public class ContainerInfoContentProvider implements ITreeContentProvider {
new Object[]{"Id", container.id().substring(0, 12)}, //$NON-NLS-1$
new Object[]{"Image", container.image()}, //$NON-NLS-1$
new Object[]{"Command", container.command()}, //$NON-NLS-1$
- new Object[]{"Created", LabelUtils.toCreatedDate(container.created())}, //$NON-NLS-1$
+ new Object[]{"Created", LabelProviderUtils.toCreatedDate(container.created())}, //$NON-NLS-1$
new Object[]{"Status", container.status()}, //$NON-NLS-1$
new Object[]{"Ports", getPorts(container)}, //$NON-NLS-1$
new Object[]{"Names", getNames(container)}, //$NON-NLS-1$
@@ -62,11 +62,11 @@ public class ContainerInfoContentProvider implements ITreeContentProvider {
if(container.ports().isEmpty()) {
return "";
} else if(container.ports().size() == 1) {
- return LabelUtils.containerPortMappingToString(container.ports().get(0));
+ return LabelProviderUtils.containerPortMappingToString(container.ports().get(0));
} else {
final List<String> ports = new ArrayList<>();
for (IDockerPortMapping portMapping : container.ports()) {
- ports.add(LabelUtils.containerPortMappingToString(portMapping));
+ ports.add(LabelProviderUtils.containerPortMappingToString(portMapping));
}
return ports;
}
@@ -95,7 +95,7 @@ public class ContainerInfoContentProvider implements ITreeContentProvider {
final List<Object> propertyValues = (List<Object>)propertyValue;
final Object[] result = new Object[propertyValues.size()];
for (int i = 0; i < propertyValues.size(); i++) {
- result[i] = new Object[]{"", LabelUtils.toString(propertyValues.get(i))};
+ result[i] = new Object[]{"", LabelProviderUtils.toString(propertyValues.get(i))};
}
return result;
} else if(value instanceof Object[]) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInspectContentProvider.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInspectContentProvider.java
index 1076a2f8c8..5c034864d5 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInspectContentProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ContainerInspectContentProvider.java
@@ -48,9 +48,9 @@ public class ContainerInspectContentProvider implements ITreeContentProvider {
return new Object[] {
new Object[]{"Id", info.id().substring(0, 12)}, //$NON-NLS-1$
new Object[]{"Name", info.name()}, //$NON-NLS-1$
- new Object[]{"Created", LabelUtils.toCreatedDate(info.created())}, //$NON-NLS-1$
+ new Object[]{"Created", LabelProviderUtils.toCreatedDate(info.created())}, //$NON-NLS-1$
new Object[]{"State", info.state()}, //$NON-NLS-1$
- new Object[]{"Args", LabelUtils.reduce(info.args())}, //$NON-NLS-1$
+ new Object[]{"Args", LabelProviderUtils.reduce(info.args())}, //$NON-NLS-1$
new Object[]{"Driver", info.driver()}, //$NON-NLS-1$
new Object[]{"ExecDriver", info.execDriver()}, //$NON-NLS-1$
new Object[] { "Config", info.config() }, //$NON-NLS-1$
@@ -76,7 +76,7 @@ public class ContainerInspectContentProvider implements ITreeContentProvider {
final IDockerContainerState containerState = (IDockerContainerState) propertyValue;
return new Object[] {
new Object[]{"ExitCode", containerState.exitCode()}, //$NON-NLS-1$
- new Object[]{"Finished at", LabelUtils.toFinishedDate(containerState.finishDate())}, //$NON-NLS-1$
+ new Object[]{"Finished at", LabelProviderUtils.toFinishedDate(containerState.finishDate())}, //$NON-NLS-1$
new Object[]{"Running", containerState.running()}, //$NON-NLS-1$
new Object[]{"Paused", containerState.paused()}, //$NON-NLS-1$
new Object[]{"Pid", containerState.pid()}, //$NON-NLS-1$
@@ -84,17 +84,17 @@ public class ContainerInspectContentProvider implements ITreeContentProvider {
} else if(propertyValue instanceof IDockerHostConfig) {
final IDockerHostConfig hostConfig = (IDockerHostConfig) propertyValue;
return new Object[] {
- new Object[]{"Binds", LabelUtils.reduce(hostConfig.binds())}, //$NON-NLS-1$
+ new Object[]{"Binds", LabelProviderUtils.reduce(hostConfig.binds())}, //$NON-NLS-1$
new Object[]{"ContainerIDFile", hostConfig.containerIDFile()}, //$NON-NLS-1$
- new Object[]{"Dns", LabelUtils.reduce(hostConfig.dns())}, //$NON-NLS-1$
- new Object[]{"DnsSearch", LabelUtils.reduce(hostConfig.dnsSearch())}, //$NON-NLS-1$
+ new Object[]{"Dns", LabelProviderUtils.reduce(hostConfig.dns())}, //$NON-NLS-1$
+ new Object[]{"DnsSearch", LabelProviderUtils.reduce(hostConfig.dnsSearch())}, //$NON-NLS-1$
new Object[]{"Links", splitLinks(hostConfig.links())}, //$NON-NLS-1$
new Object[]{"LxcConf", hostConfig.lxcConf()}, //$NON-NLS-1$
new Object[]{"NetworkMode", hostConfig.networkMode()}, //$NON-NLS-1$
- new Object[]{"PortBindings", LabelUtils.reduce(hostConfig.portBindings())}, //$NON-NLS-1$
+ new Object[]{"PortBindings", LabelProviderUtils.reduce(hostConfig.portBindings())}, //$NON-NLS-1$
new Object[]{"Privileged", hostConfig.privileged()}, //$NON-NLS-1$
new Object[]{"PublishAllPorts", hostConfig.publishAllPorts()}, //$NON-NLS-1$
- new Object[]{"VolumesFrom", LabelUtils.reduce(hostConfig.volumesFrom())}, //$NON-NLS-1$
+ new Object[]{"VolumesFrom", LabelProviderUtils.reduce(hostConfig.volumesFrom())}, //$NON-NLS-1$
};
} else if(propertyValue instanceof IDockerContainerConfig) {
final IDockerContainerConfig config = (IDockerContainerConfig) propertyValue;
@@ -102,13 +102,13 @@ public class ContainerInspectContentProvider implements ITreeContentProvider {
new Object[]{"AttachStderr", config.attachStderr()}, //$NON-NLS-1$
new Object[]{"AttachStdin", config.attachStdin()}, //$NON-NLS-1$
new Object[]{"AttachStdout", config.attachStdout()}, //$NON-NLS-1$
- new Object[]{"Cmd", LabelUtils.reduce(config.cmd())}, //$NON-NLS-1$
+ new Object[]{"Cmd", LabelProviderUtils.reduce(config.cmd())}, //$NON-NLS-1$
new Object[]{"CpuSet", config.cpuset()}, //$NON-NLS-1$
new Object[]{"CpuShares", config.cpuShares()}, //$NON-NLS-1$
new Object[]{"Domainname", config.domainname()}, //$NON-NLS-1$
- new Object[]{"Entrypoint", LabelUtils.reduce(config.entrypoint())}, //$NON-NLS-1$
- new Object[]{"Env", LabelUtils.reduce(config.env())}, //$NON-NLS-1$
- new Object[]{"ExposedPorts", LabelUtils.reduce(config.exposedPorts())}, //$NON-NLS-1$
+ new Object[]{"Entrypoint", LabelProviderUtils.reduce(config.entrypoint())}, //$NON-NLS-1$
+ new Object[]{"Env", LabelProviderUtils.reduce(config.env())}, //$NON-NLS-1$
+ new Object[]{"ExposedPorts", LabelProviderUtils.reduce(config.exposedPorts())}, //$NON-NLS-1$
new Object[]{"Hostname", config.hostname()}, //$NON-NLS-1$
new Object[]{"Image", config.image()}, //$NON-NLS-1$
new Object[] { "Labels", //$NON-NLS-1$
@@ -118,7 +118,7 @@ public class ContainerInspectContentProvider implements ITreeContentProvider {
new Object[]{"NetworkDisabled", config.networkDisabled()}, //$NON-NLS-1$
new Object[]{"OnBuild", config.onBuild()}, //$NON-NLS-1$
new Object[]{"OpenStdin", config.openStdin()}, //$NON-NLS-1$
- new Object[]{"PortSpecs", LabelUtils.reduce(config.portSpecs())}, //$NON-NLS-1$
+ new Object[]{"PortSpecs", LabelProviderUtils.reduce(config.portSpecs())}, //$NON-NLS-1$
new Object[]{"StdinOnce", config.stdinOnce()}, //$NON-NLS-1$
new Object[]{"Tty", config.tty()}, //$NON-NLS-1$
new Object[]{"Volumes", config.volumes()}, //$NON-NLS-1$
@@ -127,7 +127,7 @@ public class ContainerInspectContentProvider implements ITreeContentProvider {
} else if(propertyValue instanceof IDockerPortBinding) {
final IDockerPortBinding portBinding = (IDockerPortBinding) propertyValue;
return new Object[] {
- new Object[]{"Host IP/Port", LabelUtils.toString(portBinding)} //$NON-NLS-1$
+ new Object[]{"Host IP/Port", LabelProviderUtils.toString(portBinding)} //$NON-NLS-1$
};
} else if(propertyValue instanceof IDockerNetworkSettings) {
final IDockerNetworkSettings networkSettings = (IDockerNetworkSettings) propertyValue;
@@ -137,14 +137,14 @@ public class ContainerInspectContentProvider implements ITreeContentProvider {
new Object[]{"IPAddress", networkSettings.ipAddress()}, //$NON-NLS-1$
new Object[]{"IPPrefixLen", networkSettings.ipPrefixLen()}, //$NON-NLS-1$
new Object[]{"PortMapping", networkSettings.portMapping()}, //$NON-NLS-1$
- new Object[]{"Ports", LabelUtils.reduce(networkSettings.ports())}, //$NON-NLS-1$
+ new Object[]{"Ports", LabelProviderUtils.reduce(networkSettings.ports())}, //$NON-NLS-1$
};
} else if(propertyValue instanceof List<?>) {
@SuppressWarnings("unchecked")
final List<Object> propertyValues = (List<Object>)propertyValue;
final Object[] result = new Object[propertyValues.size()];
for (int i = 0; i < propertyValues.size(); i++) {
- result[i] = new Object[]{"", LabelUtils.toString(propertyValues.get(i))}; //$NON-NLS-1$
+ result[i] = new Object[]{"", LabelProviderUtils.toString(propertyValues.get(i))}; //$NON-NLS-1$
}
return result;
} else if(propertyValue instanceof Map<?,?>) {
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 2a3bb797e1..2ca9285f72 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
@@ -209,3 +209,5 @@ DockerContainerPortMappingsCategory.label=Ports
DockerContainerVolumesCategory.label=Volumes
DockerContainerLinksCategory.label=Links
DockerImagesCategory.label=Images
+
+DockerHierarchyViewNoImageSelected.msg=No Docker image was selected.
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
index 0804120212..5542bebead 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
@@ -278,7 +278,7 @@ public class DockerContainersView extends ViewPart implements
@Override
public String getText(final Object element) {
if (element instanceof IDockerContainer) {
- return LabelUtils.toCreatedDate(((IDockerContainer)element).created());
+ return LabelProviderUtils.toCreatedDate(((IDockerContainer)element).created());
}
return super.getText(element);
}
@@ -306,7 +306,7 @@ public class DockerContainersView extends ViewPart implements
for (Iterator<IDockerPortMapping> iterator = ((IDockerContainer) element)
.ports().iterator(); iterator.hasNext();) {
final IDockerPortMapping portMapping = iterator.next();
- ports.append(LabelUtils.containerPortMappingToString(portMapping));
+ ports.append(LabelProviderUtils.containerPortMappingToString(portMapping));
if(iterator.hasNext()) {
ports.append(", ");
}
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 ebb2784b03..96b1665c38 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
@@ -12,11 +12,6 @@
package org.eclipse.linuxtools.internal.docker.ui.views;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
@@ -183,35 +178,7 @@ public class DockerExplorerLabelProvider implements IStyledLabelProvider, ILabel
StyledString.QUALIFIER_STYLER);
return styledString;
} else if (element instanceof IDockerImage) {
- final IDockerImage dockerImage = (IDockerImage) element;
- final String imageShortId = (dockerImage.id().length() > 12)
- ? dockerImage.id().substring(0, 12) : dockerImage.id();
- final StringBuilder messageBuilder = new StringBuilder(
- dockerImage.repo());
- final int startTags = messageBuilder.length();
- if (!dockerImage.tags().isEmpty()) {
- final List<String> tags = new ArrayList<>(dockerImage.tags());
- Collections.sort(tags);
- messageBuilder.append(": ");
- for (Iterator<String> tagIterator = tags.iterator(); tagIterator
- .hasNext();) {
- messageBuilder.append(tagIterator.next());
- if (tagIterator.hasNext()) {
- 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;
+ return LabelProviderUtils.getStyleString((IDockerImage) element);
} else if (element instanceof DockerContainerPortMappingsCategory) {
return new StyledString(DVMessages
.getString("DockerContainerPortMappingsCategory.label")); //$NON-NLS-1$
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyContentProvider.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyContentProvider.java
new file mode 100644
index 0000000000..3dea80bc87
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyContentProvider.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.views;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyView.DockerImageHiearchy;
+
+/**
+ * The {@link ITreeContentProvider} implementation for the
+ * {@link DockerImageHierarchyView}
+ */
+public class DockerImageHierarchyContentProvider
+ implements ITreeContentProvider {
+
+ private TreeViewer viewer;
+
+ @Override
+ public void inputChanged(final Viewer viewer, final Object oldInput,
+ final Object newInput) {
+ this.viewer = (TreeViewer) viewer;
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof DockerImageHiearchy) {
+ final DockerImageHiearchy dockerImageHiearchy = (DockerImageHiearchy) inputElement;
+ return new Object[] { dockerImageHiearchy.getRoot() };
+ } else if (inputElement instanceof IDockerImageHiearchyNode) {
+ final IDockerImageHiearchyNode imageHiearchyNode = (IDockerImageHiearchyNode) inputElement;
+ if (imageHiearchyNode != null
+ && imageHiearchyNode.getChildren() != null) {
+ return imageHiearchyNode.getChildren().toArray();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ return getElements(parentElement);
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ if (element instanceof IDockerImageHiearchyNode) {
+ final IDockerImageHiearchyNode imageHiearchyNode = (IDockerImageHiearchyNode) element;
+ return imageHiearchyNode.getParent();
+ }
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof IDockerImageHiearchyNode) {
+ final IDockerImageHiearchyNode imageHiearchyNode = (IDockerImageHiearchyNode) element;
+ return !imageHiearchyNode.getChildren().isEmpty();
+ }
+ return false;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyLabelProvider.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyLabelProvider.java
new file mode 100644
index 0000000000..b16cd18296
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyLabelProvider.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.views;
+
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
+import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * the {@link ILabelProvider} implementation fo the
+ * {@link DockerImageHierarchyView}.
+ */
+public class DockerImageHierarchyLabelProvider
+ implements IStyledLabelProvider, ILabelProvider {
+
+ private Image IMAGE_IMAGE = SWTImagesFactory.DESC_IMAGE.createImage();
+
+ @Override
+ public void dispose() {
+ IMAGE_IMAGE.dispose();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof IDockerImageHiearchyNode) {
+ return IMAGE_IMAGE;
+ }
+ return null;
+ }
+
+ @Override
+ public String getText(Object element) {
+ return getStyledText(element).getString();
+ }
+
+ @Override
+ public StyledString getStyledText(Object element) {
+ if (element instanceof IDockerImageHiearchyNode) {
+ return LabelProviderUtils.getStyleString(
+ ((IDockerImageHiearchyNode) element).getImage());
+ }
+ return null;
+ }
+
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyView.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyView.java
new file mode 100644
index 0000000000..7ff8530596
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyView.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.views;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.widgets.Form;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.CommonViewer;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+
+/**
+ *
+ */
+public class DockerImageHierarchyView extends CommonNavigator
+ implements ITabbedPropertySheetPageContributor {
+
+ /** the id of the view as defined in {@code plugin.xml}. */
+ public static final String VIEW_ID = "org.eclipse.linuxtools.docker.ui.dockerImageHierarchyView"; //$NON-NLS-1$
+
+ private Control hierarchyPane;
+ private Control explanationsPane;
+ private PageBook pageBook;
+
+ private IDockerImageHiearchyNode selectedImageHierarchy = null;
+
+ @Override
+ protected Object getInitialInput() {
+ return this.selectedImageHierarchy;
+ }
+
+ /**
+ * Shows the given resolved hierarchy associated with the selected
+ * {@link IDockerImage}.
+ *
+ * @param selectedImageHierarchy
+ * the hierarchy to display in this view
+ */
+ public void show(final IDockerImageHiearchyNode selectedImageHierarchy) {
+ this.selectedImageHierarchy = selectedImageHierarchy;
+ this.getCommonViewer().setInput(
+ new DockerImageHiearchy(this.selectedImageHierarchy.getRoot()));
+ this.getCommonViewer().expandAll();
+ showHierarchyOrExplanations();
+ }
+
+ @Override
+ public void createPartControl(final Composite parent) {
+ final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
+ this.pageBook = new PageBook(parent, SWT.NONE);
+ this.hierarchyPane = createHierarchyPane(pageBook, toolkit);
+ this.explanationsPane = createExplanationPane(pageBook, toolkit);
+ showHierarchyOrExplanations();
+ }
+
+ private Control createExplanationPane(final PageBook pageBook,
+ final FormToolkit toolkit) {
+ final Form form = toolkit.createForm(pageBook);
+ final Composite container = form.getBody();
+ GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5)
+ .applyTo(container);
+ final Label label = new Label(container, SWT.NONE);
+ label.setText(
+ DVMessages.getString("DockerHierarchyViewNoImageSelected.msg")); //$NON-NLS-1$
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.FILL)
+ .grab(true, false).applyTo(label);
+ return form;
+ }
+
+ private Control createHierarchyPane(final PageBook pageBook,
+ final FormToolkit toolkit) {
+ final Form form = toolkit.createForm(pageBook);
+ final Composite container = form.getBody();
+ GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5)
+ .applyTo(container);
+ super.createPartControl(container);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
+ .grab(true, true).applyTo(getCommonViewer().getControl());
+ return form;
+ }
+
+ @Override
+ protected CommonViewer createCommonViewer(final Composite parent) {
+ final CommonViewer viewer = super.createCommonViewer(parent);
+ setLinkingEnabled(false);
+ return viewer;
+ }
+
+ @Override
+ public String getContributorId() {
+ return getSite().getId();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getAdapter(final Class<T> adapter) {
+ if (IPropertySheetPage.class.isAssignableFrom(adapter)) {
+ return (T) new TabbedPropertySheetPage(this, true);
+ }
+ return super.getAdapter(adapter);
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+
+ /**
+ * Shows the {@link DockerExplorerView#explanationsPane} or the
+ * {@link DockerExplorerView#hierarchyPane} depending on the number of
+ * connections in the {@link DockerConnectionManager}.
+ */
+ public void showHierarchyOrExplanations() {
+ if (this.selectedImageHierarchy == null) {
+ pageBook.showPage(explanationsPane);
+ } else {
+ pageBook.showPage(hierarchyPane);
+ }
+ }
+
+ static class DockerImageHiearchy {
+
+ private final IDockerImageHiearchyNode root;
+
+ public DockerImageHiearchy(final IDockerImageHiearchyNode root) {
+ this.root = root;
+ }
+
+ public IDockerImageHiearchyNode getRoot() {
+ return this.root;
+ }
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java
index da8340a008..64eacc0ff8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java
@@ -252,7 +252,7 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
@Override
public String getText(final Object element) {
if (element instanceof IDockerImage) {
- return LabelUtils.toCreatedDate(Long
+ return LabelProviderUtils.toCreatedDate(Long
.parseLong(((IDockerImage) element).created()));
}
return super.getText(element);
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInfoContentProvider.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInfoContentProvider.java
index 1e0b790d73..cf1f7cba9a 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInfoContentProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInfoContentProvider.java
@@ -45,14 +45,14 @@ public class ImageInfoContentProvider implements ITreeContentProvider {
image.createdDate() != null ? image.createdDate()
: "unknown" }, //$NON-NLS-1$
new Object[] {
- "RepoTags", LabelUtils.reduce(image.repoTags()) }, //$NON-NLS-1$
- new Object[] { "Size", LabelUtils.toString(image.size()) }, //$NON-NLS-1$
+ "RepoTags", LabelProviderUtils.reduce(image.repoTags()) }, //$NON-NLS-1$
+ new Object[] { "Size", LabelProviderUtils.toString(image.size()) }, //$NON-NLS-1$
new Object[] {
- "VirtualSize", LabelUtils.toString(image.virtualSize()) }, //$NON-NLS-1$
+ "VirtualSize", LabelProviderUtils.toString(image.virtualSize()) }, //$NON-NLS-1$
new Object[] {
- "IsIntermediateImage", LabelUtils.toString(image.isIntermediateImage()) }, //$NON-NLS-1$
+ "IsIntermediateImage", LabelProviderUtils.toString(image.isIntermediateImage()) }, //$NON-NLS-1$
new Object[] {
- "IsDangling", LabelUtils.toString(image.isDangling()) }, //$NON-NLS-1$
+ "IsDangling", LabelProviderUtils.toString(image.isDangling()) }, //$NON-NLS-1$
};
}
return EMPTY;
@@ -67,7 +67,7 @@ public class ImageInfoContentProvider implements ITreeContentProvider {
final List<Object> propertyValues = (List<Object>)propertyValue;
final Object[] result = new Object[propertyValues.size()];
for (int i = 0; i < propertyValues.size(); i++) {
- result[i] = new Object[]{"", LabelUtils.toString(propertyValues.get(i))};
+ result[i] = new Object[]{"", LabelProviderUtils.toString(propertyValues.get(i))};
}
return result;
} else if(value instanceof Object[]) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInspectContentProvider.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInspectContentProvider.java
index 7cf66cb143..af183a919a 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInspectContentProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/ImageInspectContentProvider.java
@@ -45,7 +45,7 @@ public class ImageInspectContentProvider implements ITreeContentProvider {
new Object[] { "Parent", info.parent() }, //$NON-NLS-1$
new Object[] { "Comment", info.comment() }, //$NON-NLS-1$
new Object[] {
- "Created", LabelUtils.toCreatedDate(info.created()) }, //$NON-NLS-1$
+ "Created", LabelProviderUtils.toCreatedDate(info.created()) }, //$NON-NLS-1$
new Object[] { "Container", info.container() }, //$NON-NLS-1$
new Object[] { "ContainerConfig", info.containerConfig() }, //$NON-NLS-1$
new Object[] { "DockerVersion", info.dockerVersion() }, //$NON-NLS-1$
@@ -53,7 +53,7 @@ public class ImageInspectContentProvider implements ITreeContentProvider {
new Object[] { "Config", info.config() }, //$NON-NLS-1$
new Object[] { "Architecture", info.architecture() }, //$NON-NLS-1$
new Object[] { "Os", info.os() }, //$NON-NLS-1$
- new Object[] { "Size", LabelUtils.toString(info.size()) }, //$NON-NLS-1$
+ new Object[] { "Size", LabelProviderUtils.toString(info.size()) }, //$NON-NLS-1$
};
}
return EMPTY;
@@ -69,32 +69,32 @@ public class ImageInspectContentProvider implements ITreeContentProvider {
new Object[] { "Domainname", config.domainname() }, //$NON-NLS-1$
new Object[] { "User", config.user() }, //$NON-NLS-1$
new Object[] {
- "Memory", LabelUtils.toString(config.memory()) }, //$NON-NLS-1$
+ "Memory", LabelProviderUtils.toString(config.memory()) }, //$NON-NLS-1$
new Object[] {
- "MemorySwap", LabelUtils.toString(config.memorySwap()) }, //$NON-NLS-1$
+ "MemorySwap", LabelProviderUtils.toString(config.memorySwap()) }, //$NON-NLS-1$
new Object[] {
- "CpuShares", LabelUtils.toString(config.cpuShares()) }, //$NON-NLS-1$
+ "CpuShares", LabelProviderUtils.toString(config.cpuShares()) }, //$NON-NLS-1$
new Object[] { "Cpuset", config.cpuset() }, //$NON-NLS-1$
new Object[] { "AttachStdin", config.attachStdin() }, //$NON-NLS-1$
new Object[] { "AttachStdout", config.attachStdout() }, //$NON-NLS-1$
new Object[] { "AttachStderr", config.attachStderr() }, //$NON-NLS-1$
new Object[] {
- "PortSpecs", LabelUtils.reduce(config.portSpecs()) }, //$NON-NLS-1$
+ "PortSpecs", LabelProviderUtils.reduce(config.portSpecs()) }, //$NON-NLS-1$
new Object[] { "ExposedPorts", config.exposedPorts() }, //$NON-NLS-1$
new Object[] { "Tty", config.tty() }, //$NON-NLS-1$
new Object[] { "OpenStdin", config.openStdin() }, //$NON-NLS-1$
new Object[] { "StdinOnce", config.stdinOnce() }, //$NON-NLS-1$
- new Object[] { "Env", LabelUtils.reduce(config.env()) }, //$NON-NLS-1$
- new Object[] { "Cmd", LabelUtils.reduce(config.cmd()) }, //$NON-NLS-1$
+ new Object[] { "Env", LabelProviderUtils.reduce(config.env()) }, //$NON-NLS-1$
+ new Object[] { "Cmd", LabelProviderUtils.reduce(config.cmd()) }, //$NON-NLS-1$
new Object[] { "Image", config.image() }, //$NON-NLS-1$
new Object[] {
- "Volumes", LabelUtils.reduce(config.volumes()) }, //$NON-NLS-1$
+ "Volumes", LabelProviderUtils.reduce(config.volumes()) }, //$NON-NLS-1$
new Object[] { "WorkingDir", config.workingDir() }, //$NON-NLS-1$
new Object[] {
- "EntryPoint", LabelUtils.reduce(config.entrypoint()) }, //$NON-NLS-1$
+ "EntryPoint", LabelProviderUtils.reduce(config.entrypoint()) }, //$NON-NLS-1$
new Object[] { "NetworkDisabled", config.networkDisabled() }, //$NON-NLS-1$
new Object[] {
- "OnBuild", LabelUtils.reduce(config.onBuild()) }, //$NON-NLS-1$
+ "OnBuild", LabelProviderUtils.reduce(config.onBuild()) }, //$NON-NLS-1$
};
} else if (propertyValue instanceof List<?>) {
@SuppressWarnings("unchecked")
@@ -102,7 +102,7 @@ public class ImageInspectContentProvider implements ITreeContentProvider {
final Object[] result = new Object[propertyValues.size()];
for (int i = 0; i < propertyValues.size(); i++) {
result[i] = new Object[] {
- "", LabelUtils.toString(propertyValues.get(i)) }; //$NON-NLS-1$
+ "", LabelProviderUtils.toString(propertyValues.get(i)) }; //$NON-NLS-1$
}
return result;
} else if (propertyValue instanceof Map<?, ?>) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelUtils.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java
index 7d221f2cac..75a85b0a6e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java
@@ -12,21 +12,27 @@
package org.eclipse.linuxtools.internal.docker.ui.views;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.core.IDockerPortBinding;
import org.eclipse.linuxtools.docker.core.IDockerPortMapping;
+import org.eclipse.swt.custom.StyledText;
/**
* @author xcoulon
*
*/
-public class LabelUtils {
+public class LabelProviderUtils {
public static final String CREATION_DATE_PATTERN = "yyyy-MM-dd";
@@ -137,4 +143,41 @@ public class LabelUtils {
return value.toString();
}
+ /**
+ * @param dockerImage
+ * the {@link IDockerImage} whose {@link StyledText} needs to be
+ * provided
+ * @return the {@link StyledText} for the given {@link IDockerImage}.
+ */
+ public static StyledString getStyleString(final IDockerImage dockerImage) {
+ final String imageShortId = (dockerImage.id().length() > 12)
+ ? dockerImage.id().substring(0, 12) : dockerImage.id();
+ final StringBuilder messageBuilder = new StringBuilder(
+ dockerImage.repo());
+ final int startTags = messageBuilder.length();
+ if (!dockerImage.tags().isEmpty()) {
+ final List<String> tags = new ArrayList<>(dockerImage.tags());
+ Collections.sort(tags);
+ messageBuilder.append(": ");
+ for (Iterator<String> tagIterator = tags.iterator(); tagIterator
+ .hasNext();) {
+ messageBuilder.append(tagIterator.next());
+ if (tagIterator.hasNext()) {
+ 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;
+ }
+
}

Back to the top