Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-08-23 10:27:19 +0000
committerJeff Johnston2016-08-23 18:43:36 +0000
commitdfc26ceaafe0fb0957c8821f6081b9699ad29657 (patch)
tree48ec446ed6c05002c81b0fb989ed2267e46299fa
parentc0c70d37c102e8f4a74629c801d108f75c7b574b (diff)
downloadorg.eclipse.linuxtools-dfc26ceaafe0fb0957c8821f6081b9699ad29657.tar.gz
org.eclipse.linuxtools-dfc26ceaafe0fb0957c8821f6081b9699ad29657.tar.xz
org.eclipse.linuxtools-dfc26ceaafe0fb0957c8821f6081b9699ad29657.zip
Bug 499749 - Include Docker containers in Hierarchy view
The Image hierarchy view now displays the containers based on an image. From a selected image or container, the hierarchy view shows the path to the root image and all descending images and containers (but for the parent images, only the path to the selected element will be shown) Moved the logic to build the hierarchy view in a utility class (DockerImageHierarchyNodeUtils) Added a MenuAssertion class to the SWTBot tests Change-Id: Icceb228f7947166bf6a6dec864bfbeaf68dc8d26 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/79490 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/IDockerConnection2.java26
-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/docker/core/IDockerImageHierarchyNode.java57
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java50
-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.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHierarchyNode.java80
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHierarchyNodeUtils.java147
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerImageHierarchyViewAssertion.java72
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTUtils.java33
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyViewSWTBotTest.java197
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.properties6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.xml47
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java119
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/OpenInHierarchyViewCommandHandler.java (renamed from containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/OpenImageHierarchyViewCommandHandler.java)15
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java29
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/JobMessages.properties1
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/jobs/RetrieveImageHierarchyJob.java58
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerLabelProvider.java101
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyContentProvider.java14
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyLabelProvider.java22
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImageHierarchyView.java33
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java237
25 files changed, 995 insertions, 462 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection2.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection2.java
index 236142c934..20ff98d11d 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection2.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnection2.java
@@ -45,4 +45,30 @@ public interface IDockerConnection2 {
IDockerProgressHandler getDefaultBuildImageProgressHandler(String image,
int lines);
+ /**
+ * 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 IDockerImageHierarchyNode} as a node that can be
+ * traversed.
+ */
+ IDockerImageHierarchyNode resolveImageHierarchy(IDockerImage image);
+
+ /**
+ * Retrieves the whole hierarchy for the given {@link IDockerContainer}.
+ * This includes the path to all known parent images and their derived
+ * {@link IDockerContainer}.
+ *
+ * @param container
+ * the {@link IDockerContainer} for which the hierarchy should be
+ * resolved
+ * @return the {@link IDockerImageHierarchyNode} as a node that can be
+ * traversed.
+ */
+ IDockerImageHierarchyNode resolveImageHierarchy(IDockerContainer container);
+
}
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
deleted file mode 100644
index b934c4a2ac..0000000000
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageHiearchyNode.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * 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/docker/core/IDockerImageHierarchyNode.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageHierarchyNode.java
new file mode 100644
index 0000000000..bcc2ccc492
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImageHierarchyNode.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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 node in the hierarchy for a given {@link IDockerImage}
+ */
+public interface IDockerImageHierarchyNode {
+
+ /**
+ * @return the selected {@link IDockerImage} or {@link IDockerContainer}.
+ */
+ public Object getElement();
+
+ /**
+ * @return the {@link IDockerImageHierarchyNode} corresponding to the parent
+ * {@link IDockerImage} of the current element.
+ */
+ public IDockerImageHierarchyNode getParent();
+
+ /**
+ * @return the {@link IDockerImageHierarchyNode} of all {@link IDockerImage}
+ * and {@link IDockerContainer} whose parent is the
+ * {@link IDockerImage} associated with this
+ * {@link IDockerImageHierarchyNode}
+ */
+ public List<IDockerImageHierarchyNode> getChildren();
+
+ /**
+ * @return the {@link IDockerImageHierarchyNode} of the {@link IDockerImage}
+ * or {@link IDockerContainer} whose parent is the
+ * {@link IDockerImage} associated with this
+ * {@link IDockerImageHierarchyNode} and whose id matches the given
+ * {@code id}, or <code>null</code> if none was found.
+ * @param id
+ * the {@link IDockerContainer} or {@link IDockerImage} id to
+ * look-up.
+ */
+ public IDockerImageHierarchyNode getChild(String id);
+
+ /**
+ * @return the root node of the resolved hierarchy
+ */
+ public IDockerImageHierarchyNode 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 f3a5a2c275..8a5e514376 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,7 +29,6 @@ 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;
@@ -66,7 +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.IDockerImageHierarchyNode;
import org.eclipse.linuxtools.docker.core.IDockerImageInfo;
import org.eclipse.linuxtools.docker.core.IDockerImageListener;
import org.eclipse.linuxtools.docker.core.IDockerImageSearchResult;
@@ -2120,41 +2119,18 @@ public class DockerConnection
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;
+ @Override
+ public IDockerImageHierarchyNode resolveImageHierarchy(
+ final IDockerImage selectedImage) {
+ return DockerImageHierarchyNodeUtils.resolveImageHierarchy(this.images,
+ this.containers, selectedImage);
+ }
+
+ @Override
+ public IDockerImageHierarchyNode resolveImageHierarchy(
+ final IDockerContainer selectedContainer) {
+ return DockerImageHierarchyNodeUtils.resolveImageHierarchy(this.images,
+ selectedContainer);
}
}
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
deleted file mode 100644
index 19286a28fd..0000000000
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHiearchyNode.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * 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.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHierarchyNode.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHierarchyNode.java
new file mode 100644
index 0000000000..a15091a511
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHierarchyNode.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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.IDockerContainer;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode;
+
+/**
+ * Default implementation of the {@link IDockerImageHierarchyNode} interface.
+ */
+public class DockerImageHierarchyNode implements IDockerImageHierarchyNode {
+
+ private final Object image;
+
+ private IDockerImageHierarchyNode parent;
+
+ private List<IDockerImageHierarchyNode> children;
+
+ public DockerImageHierarchyNode(final Object image,
+ final IDockerImageHierarchyNode parentImageHiearchyNode) {
+ this.image = image;
+ this.children = new ArrayList<>();
+ this.parent = parentImageHiearchyNode;
+ if (parent != null) {
+ this.parent.getChildren().add(this);
+ }
+ }
+
+ @Override
+ public Object getElement() {
+ return this.image;
+ }
+
+ @Override
+ public IDockerImageHierarchyNode getParent() {
+ return this.parent;
+ }
+
+ @Override
+ public List<IDockerImageHierarchyNode> getChildren() {
+ return this.children;
+ }
+
+ @Override
+ public IDockerImageHierarchyNode getChild(final String id) {
+ return this.children.stream().filter(n -> {
+ if (n.getElement() instanceof IDockerImage) {
+ return ((IDockerImage) n.getElement()).id().equals(id);
+ } else {
+ return ((IDockerContainer) n.getElement()).id().equals(id);
+ }
+ }).findFirst().orElse(null);
+ }
+
+ @Override
+ public IDockerImageHierarchyNode getRoot() {
+ if (this.parent == null) {
+ return this;
+ }
+ return this.parent.getRoot();
+ }
+
+ @Override
+ public String toString() {
+ return getElement().toString();
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHierarchyNodeUtils.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHierarchyNodeUtils.java
new file mode 100644
index 0000000000..a99b323d79
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImageHierarchyNodeUtils.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * 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.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.linuxtools.docker.core.IDockerContainer;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode;
+
+/**
+ * Utility class to resolve {@link IDockerImageHierarchyNode}
+ */
+public class DockerImageHierarchyNodeUtils {
+
+ public static IDockerImageHierarchyNode resolveImageHierarchy(
+ final List<IDockerImage> images,
+ final List<IDockerContainer> containers, final IDockerImage image) {
+ // recursively find all parents and build associated
+ // IDockerImageHierarchyNode instances
+ final IDockerImageHierarchyNode parentImageNode = getImageParentImageNode(
+ images, image.parentId());
+ return getDockerImageHierarchyNode(images, containers, image,
+ parentImageNode);
+ }
+
+ public static IDockerImageHierarchyNode resolveImageHierarchy(
+ final List<IDockerImage> images,
+ final IDockerContainer container) {
+ final IDockerImageHierarchyNode parentImageNode = getContainerParentImageNode(
+ images, container.image());
+ final DockerImageHierarchyNode dockerImageHiearchyNode = getDockerImageHierarchyNode(
+ container, parentImageNode);
+ return dockerImageHiearchyNode;
+ }
+
+ /**
+ * Resolves the parent {@link IDockerImageHierarchyNode} for an
+ * {@link IDockerImage}.
+ *
+ * @param images
+ * all existing {@link IDockerImage}
+ * @param parentImageId
+ * the id of the parent {@link IDockerImage} to look-up
+ * @return the {@link IDockerImageHierarchyNode} corresponding to the parent
+ * {@link IDockerImage} to look-up or <code>null</code> if none was
+ * found.
+ */
+ private static IDockerImageHierarchyNode getImageParentImageNode(
+ final List<IDockerImage> images, final String parentImageId) {
+ // recursively find all parents and build associated
+ // IDockerImageHierarchyNode instances
+ return images.stream().filter(image -> image.id().equals(parentImageId))
+ // parent image found: get its own parent image hierarchy
+ .map(parentImage -> new DockerImageHierarchyNode(parentImage,
+ getImageParentImageNode(images,
+ parentImage.parentId())))
+ .findFirst()
+ // no parent image found: stop here.
+ .orElse(null);
+ }
+
+ /**
+ * Resolves the parent {@link IDockerImageHierarchyNode} for an
+ * {@link IDockerContainer}.
+ *
+ * @param images
+ * all existing {@link IDockerImage}
+ * @param parentImageName
+ * the name of the parent {@link IDockerImage} to look-up
+ * @return the {@link IDockerImageHierarchyNode} corresponding to the parent
+ * {@link IDockerImage} to look-up or <code>null</code> if none was
+ * found.
+ */
+ private static IDockerImageHierarchyNode getContainerParentImageNode(
+ final List<IDockerImage> images, final String parentImageName) {
+ // recursively find all parents and build associated
+ // IDockerImageHierarchyNode instances
+ return images.stream()
+ .filter(image -> image.repoTags().contains(parentImageName))
+ // parent image found: get its own parent image hierarchy
+ .map(parentImage -> new DockerImageHierarchyNode(parentImage,
+ getImageParentImageNode(images, parentImage.parentId())))
+ .findFirst()
+ // no parent image found: stop here.
+ .orElse(null);
+ }
+
+ private static DockerImageHierarchyNode getDockerImageHierarchyNode(
+ final List<IDockerImage> images,
+ final List<IDockerContainer> containers, final IDockerImage image,
+ final IDockerImageHierarchyNode parentImageNode) {
+ final DockerImageHierarchyNode imageNode = new DockerImageHierarchyNode(
+ image, parentImageNode);
+ // also includes all children images/containers, recursively
+ resolveChildrenImageNodes(images, containers, image.id(),
+ image.repoTags(), imageNode);
+ return imageNode;
+ }
+
+ private static void resolveChildrenImageNodes(
+ final List<IDockerImage> images,
+ final List<IDockerContainer> containers, final String imageId,
+ final List<String> imageRepoTags,
+ final IDockerImageHierarchyNode parentNode) {
+ // recursively find all parents and build associated
+ // IDockerImageHierarchyNode instances
+ images.stream().filter(image -> image.parentId() != null
+ && image.parentId().equals(imageId)).map(image -> {
+ final DockerImageHierarchyNode childNode = new DockerImageHierarchyNode(
+ image, parentNode);
+ resolveChildrenImageNodes(images, containers, image.id(),
+ image.repoTags(),
+ childNode);
+ return childNode;
+ }).collect(Collectors.toList());
+ containers.stream()
+ .filter(container -> container.image() != null
+ && imageRepoTags.contains(container.image()))
+ .map(container -> new DockerImageHierarchyNode(container,
+ parentNode))
+ .collect(Collectors.toList());
+ }
+
+ private static DockerImageHierarchyNode getDockerImageHierarchyNode(
+ final IDockerContainer container,
+ final IDockerImageHierarchyNode parentImageNode) {
+ // recursively find all parents and build associated
+ // IDockerImageHierarchyNode instances
+ final DockerImageHierarchyNode containerNode = new DockerImageHierarchyNode(
+ container, parentImageNode);
+ // there's no children images/containers for a container, so let's just
+ // return the node
+ return containerNode;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java
index 020dfe72c8..24fee81816 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java
@@ -72,7 +72,7 @@ public class MockContainerFactory {
return this;
}
- public Builder imageId(final String imageId) {
+ public Builder imageName(final String imageId) {
Mockito.when(this.container.image()).thenReturn(imageId);
return this;
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerImageHierarchyViewAssertion.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerImageHierarchyViewAssertion.java
new file mode 100644
index 0000000000..70cb401110
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerImageHierarchyViewAssertion.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.AbstractAssert;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyView;
+
+/**
+ * Custom assertions on an {@link DockerImageHierarchyView}.
+ */
+public class DockerImageHierarchyViewAssertion
+ extends AbstractAssert<DockerImageHierarchyViewAssertion, DockerImageHierarchyView> {
+
+ protected DockerImageHierarchyViewAssertion(final DockerImageHierarchyView actual) {
+ super(actual, DockerImageHierarchyViewAssertion.class);
+ }
+
+ public static DockerImageHierarchyViewAssertion assertThat(final DockerImageHierarchyView actual) {
+ return new DockerImageHierarchyViewAssertion(actual);
+ }
+
+ public DockerImageHierarchyViewAssertion isEmpty() {
+ notNullValue();
+ try {
+ // let's make sure changes in the UI were taken into account before
+ // performing assertions
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ if(actual.isShowingConnectionsPane()) {
+ failWithMessage("Expected Docker Explorer View to show the explanation pane but it did not");
+ }
+ return this;
+ }
+
+ public DockerImageHierarchyViewAssertion isNotEmpty() {
+ notNullValue();
+ if(!actual.isShowingConnectionsPane()) {
+ failWithMessage("Expected Docker Explorer View to show the connections pane but it did not");
+ }
+ return this;
+ }
+
+ public void hasSelectedElement(final Object expectedSelection) {
+ notNullValue();
+ final IStructuredSelection selection = (IStructuredSelection) actual.getCommonViewer().getSelection();
+ if (selection.size() != 1) {
+ failWithMessage("Expected Docker Image Hierarchy view to have <%s> selected elements, but there was <%s>",
+ 1, selection.size());
+ }
+ final Object selectedElement = ((IDockerImageHierarchyNode) selection.getFirstElement()).getElement();
+ if (!selectedElement.equals(expectedSelection)) {
+ failWithMessage(
+ "Expected Docker Image Hierarchy view to have <%s> as the selected element, but it was <%s>",
+ expectedSelection, selectedElement);
+ }
+ }
+}
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 73aa1f1373..372e22c7b9 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
@@ -36,6 +36,7 @@ import org.eclipse.swt.widgets.Tree;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
@@ -256,7 +257,7 @@ public class SWTUtils {
private static SWTBotTreeItem getTreeItem(final SWTBotTreeItem[] treeItems, final String[] paths) {
final SWTBotTreeItem swtBotTreeItem = Stream.of(treeItems).filter(item -> item.getText().startsWith(paths[0]))
- .findFirst().orElseThrow(() -> new RuntimeException("Available items: "
+ .findFirst().orElseThrow(() -> new RuntimeException("Only available items: "
+ Stream.of(treeItems).map(item -> item.getText()).collect(Collectors.joining(", "))));
if (paths.length > 1) {
syncExec(() -> swtBotTreeItem.expand());
@@ -342,21 +343,27 @@ public class SWTUtils {
* the tree whose {@link Menu} should be hidden
*/
public static void hideMenu(final SWTBotTree tree) {
- final Menu menu = UIThreadRunnable.syncExec((Result<Menu>) () -> tree.widget.getMenu());
- UIThreadRunnable.syncExec(new VoidResult() {
+ try {
+ final Menu menu = UIThreadRunnable.syncExec((Result<Menu>) () -> tree.widget.getMenu());
+ UIThreadRunnable.syncExec(new VoidResult() {
- @Override
- public void run() {
- hide(menu);
- }
+ @Override
+ public void run() {
+ hide(menu);
+ }
- private void hide(final Menu menu) {
- menu.notifyListeners(SWT.Hide, new Event());
- if (menu.getParentMenu() != null) {
- hide(menu.getParentMenu());
+ private void hide(final Menu menu) {
+ menu.notifyListeners(SWT.Hide, new Event());
+ if (menu.getParentMenu() != null) {
+ hide(menu.getParentMenu());
+ }
}
- }
- });
+ });
+ } 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.
+ }
}
/**
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
index 2cb68f726e..ebef2d08f1 100644
--- 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
@@ -13,15 +13,21 @@ package org.eclipse.linuxtools.internal.docker.ui.views;
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.linuxtools.docker.core.IDockerContainer;
import org.eclipse.linuxtools.docker.core.IDockerImage;
-import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
+import org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockContainerFactory;
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.DockerImageHierarchyViewAssertion;
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;
@@ -36,10 +42,12 @@ import org.junit.Rule;
import org.junit.Test;
import com.spotify.docker.client.DockerClient;
+import com.spotify.docker.client.messages.Container;
import com.spotify.docker.client.messages.Image;
/**
- * Testing the {@link DockerImageHierarchyView} call from the {@link DockerExplorerView}.
+ * Testing the {@link DockerImageHierarchyView} call from the
+ * {@link DockerExplorerView}.
*/
public class DockerImageHierarchyViewSWTBotTest {
@@ -56,9 +64,10 @@ public class DockerImageHierarchyViewSWTBotTest {
@Rule
public ClearConnectionManagerRule clearConnectionManager = new ClearConnectionManagerRule();
+ private DockerConnection connection;
@Before
- public void setup() {
+ public void setupViews() {
this.bot = new SWTWorkbenchBot();
SWTUtils.asyncExec(() -> {
try {
@@ -76,6 +85,45 @@ public class DockerImageHierarchyViewSWTBotTest {
.forEach(v -> v.close());
}
+ @Before
+ public void setupData() {
+ // data is built as follows:
+ // root_image
+ // |- foo_image1
+ // _|- foo_container1
+ // _|- foo_image2
+ // __|- foo_container21
+ // __|- foo_container22
+ // |- bar_image11
+ // _|- bar_container1
+
+ final Image rootImage = MockImageFactory.id("sha256:root_image").name("root_image").build();
+ final Image fooImage1 = MockImageFactory.id("sha256:foo_image1").name("foo_image1")
+ .parentId("sha256:root_image").build();
+ final Image fooImage2 = MockImageFactory.id("sha256:foo_image2").name("foo_image2", "foo_image2_alias")
+ .parentId("sha256:foo_image1")
+ .build();
+ final Container fooContainer1 = MockContainerFactory.id("sha256:foo_container1").name("foo_container1")
+ .imageName("foo_image1").build();
+ final Container fooContainer21 = MockContainerFactory.id("sha256:foo_container21").name("foo_container21")
+ .imageName("foo_image2").build();
+ final Container fooContainer22 = MockContainerFactory.id("sha256:foo_container22").name("foo_container22")
+ .imageName("foo_image2_alias").build();
+ final Image barImage1 = MockImageFactory.id("sha256:bar_image1").name("bar_image1")
+ .parentId("sha256:root_image")
+ .build();
+ final Container barContainer1 = MockContainerFactory.id("sha256:bar_container1").name("bar_container1")
+ .imageName("bar_image1").build();
+ final DockerClient client = MockDockerClientFactory.image(rootImage).image(fooImage1).container(fooContainer1)
+ .image(fooImage2).container(fooContainer21).container(fooContainer22).image(barImage1)
+ .container(barContainer1).build();
+ this.connection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
+ this.connection.getImages(true);
+ this.connection.getContainers(true);
+ DockerConnectionManagerUtils.configureConnectionManager(connection);
+
+ }
+
@After
public void hideMenu() {
try {
@@ -87,44 +135,135 @@ public class DockerImageHierarchyViewSWTBotTest {
}
}
+ private List<String> getChildrenElementIds(final IDockerImageHierarchyNode fooImageHierarchy) {
+ return fooImageHierarchy.getChildren().stream().map(e -> {
+ if (e.getElement() instanceof IDockerImage) {
+ return ((IDockerImage) e.getElement()).id();
+ }
+ return ((IDockerContainer) e.getElement()).id();
+ }).collect(Collectors.toList());
+ }
+
+ private DockerImageHierarchyView getDockerImageHierarchyView() {
+ final SWTBotView hierarchyViewBot = bot.viewById(DockerImageHierarchyView.VIEW_ID);
+ return (DockerImageHierarchyView) hierarchyViewBot.getViewReference().getView(true);
+ }
+
@Test
- public void shouldDisplayImageHierarchyView() {
+ public void shouldDisplayImageHierarchyViewWhenSelectingImage() {
// 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();
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo_image1").select();
+ // when
+ dockerExplorerViewBot.bot().tree().contextMenu("Open Image Hierarchy").click(); //$NON-NLS-1$
+ // then the view should be visible and selection should be on
+ // foo_image1
+ DockerImageHierarchyViewAssertion.assertThat(getDockerImageHierarchyView())
+ .hasSelectedElement(this.connection.getImage("sha256:foo_image1"));
+ }
+
+ @Test
+ public void shouldDisplayImageHierarchyViewWhenSelectingContainer() {
+ // given
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Containers", "foo_container1").select();
// when
- SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo").select();
dockerExplorerViewBot.bot().tree().contextMenu("Open Image Hierarchy").click(); //$NON-NLS-1$
+ // then the view should be visible and selection should be on
+ // foo_container1
+ DockerImageHierarchyViewAssertion.assertThat(getDockerImageHierarchyView())
+ .hasSelectedElement(this.connection.getContainer("sha256:foo_container1"));
+ }
+
+ @Test
+ public void shouldRetrieveImageHierarchyFromRootImage() {
+ // given
+ final IDockerImage rootImage = this.connection.getImage("sha256:root_image");
+ // when
+ final IDockerImageHierarchyNode rootImageHierarchy = this.connection.resolveImageHierarchy(rootImage);
+ // then
+ assertThat(rootImageHierarchy).isNotNull();
+ assertThat(rootImageHierarchy.getElement()).isEqualTo(rootImage);
+ // 2 direct children: foo_image1 and bar_image1
+ assertThat(rootImageHierarchy.getChildren()).hasSize(2);
+ assertThat(rootImageHierarchy.getParent()).isNull();
+ final IDockerImageHierarchyNode fooImage1Hierarchy = rootImageHierarchy.getChild("sha256:foo_image1");
+ assertThat(fooImage1Hierarchy.getParent()).isEqualTo(rootImageHierarchy);
+ // 2 direct children: foo_image2 and foo_container1
+ assertThat(fooImage1Hierarchy.getChildren()).hasSize(2);
+ }
+
+ @Test
+ public void shouldRetrieveImageHierarchyFromIntermediateImage() {
+ // given
+ final IDockerImage fooImage1 = this.connection.getImage("sha256:foo_image1");
+ // when
+ final IDockerImageHierarchyNode fooImage1Hierarchy = this.connection.resolveImageHierarchy(fooImage1);
+ // then
+ assertThat(fooImage1Hierarchy).isNotNull();
+ assertThat(fooImage1Hierarchy.getElement()).isEqualTo(fooImage1);
+ assertThat(getChildrenElementIds(fooImage1Hierarchy)).contains("sha256:foo_container1", "sha256:foo_image2");
+ final IDockerImage rootElement = (IDockerImage) fooImage1Hierarchy.getParent().getElement();
+ assertThat(rootElement.id()).isEqualTo("sha256:root_image");
+ // the parent only shows this child element, not its whole descendants
+ assertThat(fooImage1Hierarchy.getParent().getChildren()).containsExactly(fooImage1Hierarchy);
+ final IDockerImageHierarchyNode fooImage2HierarchyNode = fooImage1Hierarchy.getChild("sha256:foo_image2");
+ assertThat(fooImage2HierarchyNode).isNotNull();
+ // 2 child containers: foo_container21 and foo_container22
+ assertThat(fooImage2HierarchyNode.getChildren()).hasSize(2);
+ final IDockerImageHierarchyNode fooContainer1HierarchyNode = fooImage1Hierarchy
+ .getChild("sha256:foo_container1");
+ assertThat(fooContainer1HierarchyNode).isNotNull();
+ assertThat(fooContainer1HierarchyNode.getChildren()).isEmpty();
+ }
+
+ @Test
+ public void shouldRetrieveImageHierarchyFromLeafImage() {
+ // given
+ final IDockerImage fooImage2 = this.connection.getImage("sha256:foo_image2");
+ // when
+ final IDockerImageHierarchyNode fooImage2Hierarchy = this.connection.resolveImageHierarchy(fooImage2);
// then
- final SWTBotView dockerImageHierarchyView = bot.viewById(DockerImageHierarchyView.VIEW_ID);
+ assertThat(fooImage2Hierarchy).isNotNull();
+ assertThat(fooImage2Hierarchy.getElement()).isEqualTo(fooImage2);
+ // 2 containers: foo_container21 and foo_container22
+ assertThat(fooImage2Hierarchy.getChildren()).hasSize(2);
+ assertThat((IDockerContainer) fooImage2Hierarchy.getChild("sha256:foo_container21").getElement()).isNotNull();
+ final IDockerImageHierarchyNode fooImage1Hierarchy = fooImage2Hierarchy.getParent();
+ final IDockerImage fooImage = (IDockerImage) fooImage1Hierarchy.getElement();
+ assertThat(fooImage.id()).isEqualTo("sha256:foo_image1");
+ // in this case, intermediate image shows a single child
+ assertThat(fooImage1Hierarchy.getChildren()).hasSize(1);
+ assertThat(fooImage1Hierarchy.getChildren()).containsExactly(fooImage2Hierarchy);
+ }
+ @Test
+ public void shouldRetrieveImageHierarchyFromContainerBasedOnIntermediateImage() {
+ // given
+ final IDockerContainer fooContainer1 = this.connection.getContainer("sha256:foo_container1");
+ // when
+ final IDockerImageHierarchyNode fooContainer1Hierarchy = this.connection.resolveImageHierarchy(fooContainer1);
+ // then
+ assertThat(fooContainer1Hierarchy).isNotNull();
+ assertThat(fooContainer1Hierarchy.getElement()).isEqualTo(fooContainer1);
+ assertThat(fooContainer1Hierarchy.getChildren()).isEmpty();
+ final IDockerImage fooImage1 = (IDockerImage) fooContainer1Hierarchy.getParent().getElement();
+ assertThat(fooImage1.id()).isEqualTo("sha256:foo_image1");
+ // parent image hierarchy only shows the selected container as its
+ // child.
+ assertThat(fooContainer1Hierarchy.getParent().getChildren()).containsExactly(fooContainer1Hierarchy);
}
@Test
- public void shouldRetrieveImageHierarchy() {
+ public void shouldRetrieveImageHierarchyFromContainerBasedOnLeafImage() {
// 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);
+ final IDockerContainer barContainer1 = this.connection.getContainer("sha256:bar_container1");
+ final IDockerImageHierarchyNode barContainer1Hierarchy = this.connection.resolveImageHierarchy(barContainer1);
// 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);
+ assertThat(barContainer1Hierarchy).isNotNull();
+ assertThat(barContainer1Hierarchy.getElement()).isEqualTo(barContainer1);
+ assertThat(barContainer1Hierarchy.getChildren()).isEmpty();
+ final IDockerImage barImageElement = (IDockerImage) barContainer1Hierarchy.getParent().getElement();
+ assertThat(barImageElement.id()).isEqualTo("sha256:bar_image1");
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java
index c802827384..772ed958a3 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java
@@ -134,7 +134,7 @@ public class ImageRunSWTBotTest {
// container to be created
final String containerName = "foo_bar";
final Container createdContainer = MockContainerFactory.id("MockContainer").name(containerName)
- .imageId("1a2b3c4d5e6f7g").status("Started 1 second ago").build();
+ .imageName("1a2b3c4d5e6f7g").status("Started 1 second ago").build();
final ContainerInfo containerInfo = MockContainerInfoFactory.build();
final DockerClient client = MockDockerClientFactory.image(image, imageInfo)
//.container(createdContainer, containerInfo)
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
index 01b52dabd3..7ba98c9f27 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
@@ -136,10 +136,8 @@ 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
-
+command.openInHierarchyView.menu.name=Open Image Hierarchy
+command.openInHierarchyView.menu.description=Open the Docker image Hierarchy view
LaunchActionSet.label=Launch
RunMenu.label=&Run
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
index fa8fda9301..513c56ade0 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
@@ -162,6 +162,12 @@
point="org.eclipse.ui.navigator.viewer">
<viewer
viewerId="org.eclipse.linuxtools.docker.ui.dockerImageHierarchyView">
+ <options>
+ <property
+ name="org.eclipse.ui.navigator.hideLinkWithEditorAction"
+ value="true">
+ </property>
+ </options>
</viewer>
<viewerContentBinding
viewerId="org.eclipse.linuxtools.docker.ui.dockerImageHierarchyView">
@@ -338,16 +344,15 @@
id="org.eclipse.linuxtools.docker.ui.commands.showInSystemExplorer">
</command>
<command
+ name="%command.openInHierarchyView.menu.name"
+ description="%command.openInHierarchyView.menu.description"
+ id="org.eclipse.linuxtools.docker.ui.commands.openInHierarchyView">
+ </command>
+ <command
description="%command.execcontainer.description"
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
point="org.eclipse.ui.handlers">
@@ -706,16 +711,19 @@
</enabledWhen>
</handler>
<handler
- class="org.eclipse.linuxtools.internal.docker.ui.commands.OpenImageHierarchyViewCommandHandler"
- commandId="org.eclipse.linuxtools.docker.ui.commands.openImageHierarchyView">
+ class="org.eclipse.linuxtools.internal.docker.ui.commands.OpenInHierarchyViewCommandHandler"
+ commandId="org.eclipse.linuxtools.docker.ui.commands.openInHierarchyView">
<enabledWhen>
<with
variable="selection">
<iterate
ifEmpty="false">
- <instanceof
- value="org.eclipse.linuxtools.docker.core.IDockerImage">
- </instanceof>
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.docker.core.IDockerImage"/>
+ <instanceof
+ value="org.eclipse.linuxtools.docker.core.IDockerContainer"/>
+ </or>
</iterate>
</with>
</enabledWhen>
@@ -1216,9 +1224,9 @@
<menuContribution
locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=group.edit">
<command
- commandId="org.eclipse.linuxtools.docker.ui.commands.openImageHierarchyView"
+ commandId="org.eclipse.linuxtools.docker.ui.commands.openInHierarchyView"
icon="icons/class_hi.png"
- label="%command.openImageHierarchy.label"
+ label="%command.openInHierarchyView.menu.name"
mnemonic="R"
style="push">
<visibleWhen
@@ -1229,11 +1237,14 @@
value="1">
</count>
<iterate
- ifEmpty="false"
- operator="and">
- <instanceof
- value="org.eclipse.linuxtools.docker.core.IDockerImage" />
- </iterate>
+ ifEmpty="false">
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.docker.core.IDockerImage" />
+ <instanceof
+ value="org.eclipse.linuxtools.docker.core.IDockerContainer" />
+ </or>
+ </iterate>
</with>
</visibleWhen>
</command>
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
index 500f0070c7..3cb02a2264 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
@@ -11,10 +11,10 @@
package org.eclipse.linuxtools.internal.docker.ui.commands;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.IHandler;
@@ -75,20 +75,42 @@ public class CommandUtils {
* @param activePart
* - active Workbench part
*/
- public static IDockerConnection getCurrentConnection(final IWorkbenchPart activePart) {
+ public static IDockerConnection getCurrentConnection(
+ final IWorkbenchPart activePart) {
if (DockerConnectionWatcher.getInstance().getConnection() != null)
return DockerConnectionWatcher.getInstance().getConnection();
else if (activePart instanceof DockerContainersView) {
return ((DockerContainersView) activePart).getConnection();
} else if (activePart instanceof DockerImagesView) {
return ((DockerImagesView) activePart).getConnection();
- } else {
- // fall back to first active connection in list if one exists
- if (DockerConnectionManager.getInstance().hasConnections()) {
- return DockerConnectionManager.getInstance().getAllConnections()
- .stream().filter(c -> c.isOpen()).findFirst()
- .orElse(null);
- }
+ }
+ // fall back to first active connection in list if one exists
+ return Stream.of(DockerConnectionManager.getInstance().getConnections())
+ .filter(c -> c.isOpen()).findFirst().orElse(null);
+ }
+
+ /**
+ * @param activePart
+ * the active {@link IWorkbenchPart}
+ * @return the {@link List} of selected elements in the given active part or
+ * {@link Collections#emptyList()} if none was selected
+ */
+ public static List<Object> getSelectedElements(
+ final IWorkbenchPart activePart) {
+ return getSelectedElements(activePart, Object.class);
+ }
+
+ /**
+ * @param activePart
+ * the active {@link IWorkbenchPart}
+ * @return the of selected element in the given active part or
+ * <code>null</code> if none was found
+ */
+ public static Object getSelectedElement(final IWorkbenchPart activePart) {
+ final List<Object> selectedElements = getSelectedElements(activePart,
+ Object.class);
+ if (selectedElements != null && !selectedElements.isEmpty()) {
+ return selectedElements.get(0);
}
return null;
}
@@ -96,18 +118,25 @@ public class CommandUtils {
/**
* @param activePart
* the active {@link IWorkbenchPart}
+ * @param targetClass
* @return the {@link List} of selected {@link IDockerContainer} in the
* given active part of {@link Collections#emptyList()} if none was
* selected
*/
- public static List<IDockerContainer> getSelectedContainers(final IWorkbenchPart activePart) {
+ private static <T> List<T> getSelectedElements(
+ final IWorkbenchPart activePart, final Class<T> targetClass) {
if (activePart instanceof DockerContainersView) {
- final ISelection selection = ((DockerContainersView) activePart).getSelection();
- return convertSelectionTo(selection, IDockerContainer.class);
+ final ISelection selection = ((DockerContainersView) activePart)
+ .getSelection();
+ return convertSelectionTo(selection, targetClass);
+ } else if (activePart instanceof DockerImagesView) {
+ final ISelection selection = ((DockerImagesView) activePart)
+ .getSelection();
+ return convertSelectionTo(selection, targetClass);
} else if (activePart instanceof DockerExplorerView) {
final ISelection selection = ((DockerExplorerView) activePart)
.getCommonViewer().getSelection();
- return convertSelectionTo(selection, IDockerContainer.class);
+ return convertSelectionTo(selection, targetClass);
}
return Collections.emptyList();
}
@@ -115,22 +144,24 @@ public class CommandUtils {
/**
* @param activePart
* the active {@link IWorkbenchPart}
+ * @return the {@link List} of selected {@link IDockerContainer} in the
+ * given active part of {@link Collections#emptyList()} if none was
+ * selected
+ */
+ public static List<IDockerContainer> getSelectedContainers(final IWorkbenchPart activePart) {
+ return getSelectedElements(activePart, IDockerContainer.class);
+ }
+
+ /**
+ * @param activePart
+ * the active {@link IWorkbenchPart}
* @return the {@link List} of selected {@link DockerContainerPortMapping}
* in the given active part of {@link Collections#emptyList()} if
* none was selected
*/
public static List<IDockerPortMapping> getSelectedPortMappings(
final IWorkbenchPart activePart) {
- if (activePart instanceof DockerContainersView) {
- final ISelection selection = ((DockerContainersView) activePart)
- .getSelection();
- return convertSelectionTo(selection, IDockerPortMapping.class);
- } else if (activePart instanceof DockerExplorerView) {
- final ISelection selection = ((DockerExplorerView) activePart)
- .getCommonViewer().getSelection();
- return convertSelectionTo(selection, IDockerPortMapping.class);
- }
- return Collections.emptyList();
+ return getSelectedElements(activePart, IDockerPortMapping.class);
}
/**
@@ -142,16 +173,7 @@ public class CommandUtils {
*/
public static List<DockerContainerVolume> getSelectedVolumes(
final IWorkbenchPart activePart) {
- if (activePart instanceof DockerContainersView) {
- final ISelection selection = ((DockerContainersView) activePart)
- .getSelection();
- return convertSelectionTo(selection, DockerContainerVolume.class);
- } else if (activePart instanceof DockerExplorerView) {
- final ISelection selection = ((DockerExplorerView) activePart)
- .getCommonViewer().getSelection();
- return convertSelectionTo(selection, DockerContainerVolume.class);
- }
- return Collections.emptyList();
+ return getSelectedElements(activePart, DockerContainerVolume.class);
}
/**
@@ -176,6 +198,21 @@ public class CommandUtils {
}
/**
+ * @param activePart
+ * the active {@link IWorkbenchPart}
+ * @return the selected {@link IDockerImage} in the given active part of
+ * <code>null</code> if none was selected
+ */
+ public static IDockerImage getSelectedImage(
+ final IWorkbenchPart activePart) {
+ final List<IDockerImage> selectedImages = getSelectedImages(activePart);
+ if (selectedImages == null || selectedImages.isEmpty()) {
+ return null;
+ }
+ return selectedImages.get(0);
+ }
+
+ /**
*
* @param selection
* the current selection
@@ -187,16 +224,12 @@ public class CommandUtils {
private static <T> List<T> convertSelectionTo(final ISelection selection,
final Class<T> targetClass) {
if (selection instanceof IStructuredSelection) {
- final List<T> selectedContainers = new ArrayList<>();
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
- for (Iterator<?> iterator = structuredSelection.iterator(); iterator
- .hasNext();) {
- final Object selectedElement = iterator.next();
- if (targetClass.isAssignableFrom(selectedElement.getClass())) {
- selectedContainers.add((T) selectedElement);
- }
- }
- return Collections.unmodifiableList(selectedContainers);
+ return (List<T>) structuredSelection.toList().stream()
+ .filter(selectedElement -> targetClass
+ .isAssignableFrom(selectedElement.getClass()))
+ .map(selectedElement -> (T) selectedElement)
+ .collect(Collectors.toList());
}
return Collections.emptyList();
}
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/OpenInHierarchyViewCommandHandler.java
index e55545a10f..5d999b10cc 100644
--- 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/OpenInHierarchyViewCommandHandler.java
@@ -13,11 +13,10 @@ 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.docker.core.IDockerConnection2;
import org.eclipse.linuxtools.internal.docker.ui.jobs.RetrieveImageHierarchyJob;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyView;
import org.eclipse.swt.widgets.Display;
@@ -27,19 +26,19 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
/**
- * Handler for the
+ * Handler for the Images and Containers Hierarchy View
*/
-public class OpenImageHierarchyViewCommandHandler extends AbstractHandler {
+public class OpenInHierarchyViewCommandHandler extends AbstractHandler {
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
+ public Object execute(ExecutionEvent event) {
// retrieve the selected image
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
- final IDockerImage selectedImage = RunImageCommandHandler
- .getSelectedImage(activePart);
+ final IDockerConnection2 currentConnection = (IDockerConnection2) CommandUtils
+ .getCurrentConnection(activePart);
// run a job to retrieve the image hierarchy
final RetrieveImageHierarchyJob retrieveImageHierarchyJob = new RetrieveImageHierarchyJob(
- selectedImage);
+ currentConnection, CommandUtils.getSelectedElement(activePart));
retrieveImageHierarchyJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
index fe8058b0f1..35f3f7525c 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
@@ -44,7 +44,7 @@ public class PushImageCommandHandler extends AbstractHandler {
@Override
public Object execute(final ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
- final IDockerImage selectedImage = RunImageCommandHandler
+ final IDockerImage selectedImage = CommandUtils
.getSelectedImage(activePart);
final ImagePush wizard = new ImagePush(selectedImage,
selectedImage.repo() + ":" + selectedImage.tags().get(0));
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
index 3a1874bb0a..973ef4e1bf 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
@@ -22,8 +22,6 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.EnumDockerLoggingStatus;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
@@ -36,8 +34,6 @@ import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole;
import org.eclipse.linuxtools.internal.docker.ui.launch.LaunchConfigurationUtils;
import org.eclipse.linuxtools.internal.docker.ui.views.DVMessages;
-import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
-import org.eclipse.linuxtools.internal.docker.ui.views.DockerImagesView;
import org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRun;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPart;
@@ -57,7 +53,8 @@ public class RunImageCommandHandler extends AbstractHandler {
@Override
public Object execute(final ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
- final IDockerImage selectedImage = getSelectedImage(activePart);
+ final IDockerImage selectedImage = CommandUtils
+ .getSelectedImage(activePart);
if (selectedImage == null) {
Activator.logErrorMessage(
DVMessages.getString("RunImageUnableToRetrieveError.msg")); //$NON-NLS-1$
@@ -226,26 +223,4 @@ public class RunImageCommandHandler extends AbstractHandler {
}
- /**
- * @param activePart
- * the active {@link IWorkbenchPart}
- * @return the selected {@link IDockerImage} in the given active part of
- * <code>null</code> if none was selected
- */
- public static IDockerImage getSelectedImage(
- final IWorkbenchPart activePart) {
- if (activePart instanceof DockerExplorerView) {
- final ITreeSelection selection = (ITreeSelection) ((DockerExplorerView) activePart)
- .getCommonViewer().getSelection();
- return (IDockerImage) selection.getFirstElement();
- } else if (activePart instanceof DockerImagesView) {
- final IStructuredSelection selection = (IStructuredSelection) (((DockerImagesView) activePart)
- .getSelection());
- if (!selection.isEmpty()) {
- return (IDockerImage) selection.getFirstElement();
- }
- }
- return null;
- }
-
}
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 7fbb111032..1eb271720b 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
@@ -17,3 +17,4 @@ DockerCompose.dialog.title=Docker Compose
DockerComposeUp.title=Running 'docker-compose up' command
DockerComposeStop.title=Stopping Docker Compose...
DockerComposeStop.error=Docker Compose failed to stop
+RetrieveImageHierarchyJob.error=The selected element is not an Image nor a Container
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
index a5f2e1ea01..3c9f16efb2 100644
--- 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
@@ -11,53 +11,69 @@
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.IDockerConnection2;
+import org.eclipse.linuxtools.docker.core.IDockerContainer;
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.docker.core.IDockerImageHierarchyNode;
+import org.eclipse.linuxtools.docker.ui.Activator;
/**
- * A {@link Job} to retrieve the hierarchy of an {@link IDockerImage}
+ * A {@link Job} to retrieve the hierarchy of an {@link IDockerImage} or an
+ * {@link IDockerContainer}
*/
public class RetrieveImageHierarchyJob extends Job {
+ private final IDockerConnection2 connection;
+
/**
- * the {@link IDockerImage} for which the hierarchy needs to be retrieved.
+ * the {@link IDockerImage} or {@link IDockerContainer} for which the
+ * hierarchy needs to be retrieved.
*/
- private final IDockerImage dockerImage;
+ private final Object selectedElement;
/**
- * the {@link IDockerImageHiearchyNode} that was retrieved while the job was
- * executed.
+ * the resulting {@link IDockerImageHierarchyNode} that was retrieved while
+ * the job was executed.
*/
- private IDockerImageHiearchyNode imageHierarchy;
+ private IDockerImageHierarchyNode imageHierarchy;
/**
* Constructor
*
- * @param dockerImage
- * the {@link IDockerImage} for which the hierarchy needs to be
- * retrieved.
+ * @param connection
+ * the current {@link IDockerConnection2}
+ * @param selectedElement
+ * the {@link IDockerImage} or {@link IDockerContainer} for which
+ * the hierarchy needs to be retrieved.
*/
- public RetrieveImageHierarchyJob(final IDockerImage dockerImage) {
+ public RetrieveImageHierarchyJob(final IDockerConnection2 connection,
+ final Object selectedElement) {
super(JobMessages.getString("RetrieveImageHierarchyJob.title")); //$NON-NLS-1$
- this.dockerImage = dockerImage;
+ this.connection = connection;
+ this.selectedElement = selectedElement;
}
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
monitor.beginTask(
- JobMessages.getString("RetrieveImageHierarchyJob.title"),
+ JobMessages.getString("RetrieveImageHierarchyJob.title"), //$NON-NLS-1$
1);
- // TODO: remove the cast once the 'resolveImageHierarchy' method has
- // been added in the IDockerConnection interface.
- this.imageHierarchy = ((DockerConnection) dockerImage
- .getConnection())
- .resolveImageHierarchy(dockerImage);
+ if (selectedElement instanceof IDockerContainer) {
+ this.imageHierarchy = connection.resolveImageHierarchy(
+ (IDockerContainer) selectedElement);
+ } else if (selectedElement instanceof IDockerImage) {
+ this.imageHierarchy = connection
+ .resolveImageHierarchy((IDockerImage) selectedElement);
+ } else {
+ Activator.logErrorMessage(JobMessages
+ .getString("RetrieveImageHierarchyJob.error")); //$NON-NLS-1$
+ }
} finally {
monitor.done();
}
@@ -66,10 +82,10 @@ public class RetrieveImageHierarchyJob extends Job {
}
/**
- * @return the {@link IDockerImageHiearchyNode} that was retrieved while the
+ * @return the {@link IDockerImageHierarchyNode} that was retrieved while the
* job was executed.
*/
- public IDockerImageHiearchyNode getImageHierarchy() {
+ public IDockerImageHierarchyNode getImageHierarchy() {
return this.imageHierarchy;
}
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 96b1665c38..4623a0cf34 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
@@ -15,7 +15,6 @@ 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.IStructuredSelection;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.linuxtools.docker.core.EnumDockerStatus;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
@@ -39,7 +38,6 @@ import org.eclipse.swt.graphics.Image;
*/
public class DockerExplorerLabelProvider implements IStyledLabelProvider, ILabelProvider {
- private static final String UNNAMED_CONNECTION = "Connection.unnamed"; //$NON-NLS-1$
private Image OPEN_CONNECTION_IMAGE = SWTImagesFactory.DESC_REPOSITORY_MIDDLE
.createImage();
private Image UNOPEN_CONNECTION_IMAGE = SWTImagesFactory.DESC_REPOSITORY_MIDDLED
@@ -140,104 +138,7 @@ public class DockerExplorerLabelProvider implements IStyledLabelProvider, ILabel
@Override
public StyledString getStyledText(Object element) {
- // when the text to display is in the properties view title bar, the given element
- // is the TreeSelection from the contributing view (the Docker Explorer View)
- if(element instanceof IStructuredSelection) {
- return getStyledText(((IStructuredSelection)element).getFirstElement());
- }
- if(element instanceof IDockerConnection) {
- final IDockerConnection connection = (IDockerConnection) element;
- final String connectionName = (connection.getName() != null
- && !connection.getName().isEmpty())
- ? connection.getName()
- : DVMessages.getString(UNNAMED_CONNECTION);
- final StringBuilder messageBuilder = new StringBuilder();
- messageBuilder.append(connectionName);
- if (connection.getUri() != null && !connection.getUri().isEmpty()) {
- messageBuilder.append(" (").append(connection.getUri()) //$NON-NLS-1$
- .append(")"); //$NON-NLS-1$
- }
- final String message = messageBuilder.toString();
- final StyledString styledString = new StyledString(message);
- styledString.setStyle(connectionName.length(), message.length() - connectionName.length(), StyledString.QUALIFIER_STYLER);
- return styledString;
- } else if(element instanceof DockerImagesCategory) {
- return new StyledString(
- DVMessages.getString("DockerImagesCategory.label")); //$NON-NLS-1$
- } else if(element instanceof DockerContainersCategory) {
- return new StyledString(
- DVMessages.getString("DockerContainersCategory.label")); //$NON-NLS-1$
- } else if (element instanceof IDockerContainer) {
- final IDockerContainer dockerContainer = (IDockerContainer) element;
- final String containerName = dockerContainer.name();
- final String image = dockerContainer.image();
- final String message = containerName + " (" + image + ")";
- final StyledString styledString = new StyledString(message);
- styledString.setStyle(containerName.length(),
- message.length() - containerName.length(),
- StyledString.QUALIFIER_STYLER);
- return styledString;
- } else if (element instanceof IDockerImage) {
- return LabelProviderUtils.getStyleString((IDockerImage) element);
- } 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;
+ return LabelProviderUtils.getStyledText(element);
}
}
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
index 3dea80bc87..2ba52f41c2 100644
--- 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
@@ -14,7 +14,7 @@ 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.docker.core.IDockerImageHierarchyNode;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyView.DockerImageHiearchy;
/**
@@ -37,8 +37,8 @@ public class DockerImageHierarchyContentProvider
if (inputElement instanceof DockerImageHiearchy) {
final DockerImageHiearchy dockerImageHiearchy = (DockerImageHiearchy) inputElement;
return new Object[] { dockerImageHiearchy.getRoot() };
- } else if (inputElement instanceof IDockerImageHiearchyNode) {
- final IDockerImageHiearchyNode imageHiearchyNode = (IDockerImageHiearchyNode) inputElement;
+ } else if (inputElement instanceof IDockerImageHierarchyNode) {
+ final IDockerImageHierarchyNode imageHiearchyNode = (IDockerImageHierarchyNode) inputElement;
if (imageHiearchyNode != null
&& imageHiearchyNode.getChildren() != null) {
return imageHiearchyNode.getChildren().toArray();
@@ -54,8 +54,8 @@ public class DockerImageHierarchyContentProvider
@Override
public Object getParent(Object element) {
- if (element instanceof IDockerImageHiearchyNode) {
- final IDockerImageHiearchyNode imageHiearchyNode = (IDockerImageHiearchyNode) element;
+ if (element instanceof IDockerImageHierarchyNode) {
+ final IDockerImageHierarchyNode imageHiearchyNode = (IDockerImageHierarchyNode) element;
return imageHiearchyNode.getParent();
}
return null;
@@ -63,8 +63,8 @@ public class DockerImageHierarchyContentProvider
@Override
public boolean hasChildren(Object element) {
- if (element instanceof IDockerImageHiearchyNode) {
- final IDockerImageHiearchyNode imageHiearchyNode = (IDockerImageHiearchyNode) element;
+ if (element instanceof IDockerImageHierarchyNode) {
+ final IDockerImageHierarchyNode imageHiearchyNode = (IDockerImageHierarchyNode) 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
index b16cd18296..cf95a6ac71 100644
--- 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
@@ -15,7 +15,9 @@ import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelP
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.docker.core.IDockerContainer;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode;
import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
import org.eclipse.swt.graphics.Image;
@@ -28,15 +30,25 @@ public class DockerImageHierarchyLabelProvider
private Image IMAGE_IMAGE = SWTImagesFactory.DESC_IMAGE.createImage();
+ private Image CONTAINER_IMAGE = SWTImagesFactory.DESC_CONTAINER
+ .createImage();
+
@Override
public void dispose() {
IMAGE_IMAGE.dispose();
+ CONTAINER_IMAGE.dispose();
}
@Override
public Image getImage(Object element) {
- if (element instanceof IDockerImageHiearchyNode) {
+ if (element instanceof IDockerImageHierarchyNode
+ && (((IDockerImageHierarchyNode) element)
+ .getElement() instanceof IDockerImage)) {
return IMAGE_IMAGE;
+ } else if (element instanceof IDockerImageHierarchyNode
+ && (((IDockerImageHierarchyNode) element)
+ .getElement() instanceof IDockerContainer)) {
+ return CONTAINER_IMAGE;
}
return null;
}
@@ -48,9 +60,9 @@ public class DockerImageHierarchyLabelProvider
@Override
public StyledString getStyledText(Object element) {
- if (element instanceof IDockerImageHiearchyNode) {
- return LabelProviderUtils.getStyleString(
- ((IDockerImageHiearchyNode) element).getImage());
+ if (element instanceof IDockerImageHierarchyNode) {
+ return LabelProviderUtils.getStyledText(
+ ((IDockerImageHierarchyNode) element).getElement());
}
return null;
}
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
index 7ff8530596..dabbd4b9ec 100644
--- 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
@@ -13,9 +13,12 @@ package org.eclipse.linuxtools.internal.docker.ui.views;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerImage;
-import org.eclipse.linuxtools.docker.core.IDockerImageHiearchyNode;
+import org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -42,7 +45,9 @@ public class DockerImageHierarchyView extends CommonNavigator
private Control explanationsPane;
private PageBook pageBook;
- private IDockerImageHiearchyNode selectedImageHierarchy = null;
+ private IDockerImageHierarchyNode selectedImageHierarchy = null;
+
+ private Control currentPane;
@Override
protected Object getInitialInput() {
@@ -55,12 +60,16 @@ public class DockerImageHierarchyView extends CommonNavigator
*
* @param selectedImageHierarchy
* the hierarchy to display in this view
+ * @param selectedElement
+ * the element to select in the view
*/
- public void show(final IDockerImageHiearchyNode selectedImageHierarchy) {
+ public void show(final IDockerImageHierarchyNode selectedImageHierarchy) {
this.selectedImageHierarchy = selectedImageHierarchy;
this.getCommonViewer().setInput(
new DockerImageHiearchy(this.selectedImageHierarchy.getRoot()));
this.getCommonViewer().expandAll();
+ this.getCommonViewer()
+ .setSelection(new StructuredSelection(selectedImageHierarchy));
showHierarchyOrExplanations();
}
@@ -132,22 +141,34 @@ public class DockerImageHierarchyView extends CommonNavigator
*/
public void showHierarchyOrExplanations() {
if (this.selectedImageHierarchy == null) {
+ this.currentPane = explanationsPane;
pageBook.showPage(explanationsPane);
} else {
+ this.currentPane = hierarchyPane;
pageBook.showPage(hierarchyPane);
}
}
+ /**
+ * @return <code>true</code> if the current panel is the one containing a
+ * {@link TreeViewer} of {@link IDockerConnection}s,
+ * <code>false</code> otherwise.
+ */
+ public boolean isShowingConnectionsPane() {
+ return this.currentPane == hierarchyPane;
+ }
+
static class DockerImageHiearchy {
- private final IDockerImageHiearchyNode root;
+ private final IDockerImageHierarchyNode root;
- public DockerImageHiearchy(final IDockerImageHiearchyNode root) {
+ public DockerImageHiearchy(final IDockerImageHierarchyNode root) {
this.root = root;
}
- public IDockerImageHiearchyNode getRoot() {
+ public IDockerImageHierarchyNode getRoot() {
return this.root;
}
}
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java
index 641d1b145d..48be861a8e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java
@@ -22,11 +22,22 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StyledString;
+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.IDockerPortBinding;
import org.eclipse.linuxtools.docker.core.IDockerPortMapping;
import org.eclipse.linuxtools.internal.docker.core.DockerImage;
+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;
import org.eclipse.swt.custom.StyledText;
/**
@@ -34,11 +45,11 @@ import org.eclipse.swt.custom.StyledText;
*
*/
public class LabelProviderUtils {
-
+
public static final String CREATION_DATE_PATTERN = "yyyy-MM-dd";
public static final String FINISHED_DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.sssz";
-
+
/**
* @param elements
* the {@link List} to reduce
@@ -47,18 +58,18 @@ public class LabelProviderUtils {
* otherwise the given list itself.
*
*/
- public static <K,V> Object reduce(final Map<K, List<V>> elements) {
- if(elements == null || elements.isEmpty()) {
+ public static <K, V> Object reduce(final Map<K, List<V>> elements) {
+ if (elements == null || elements.isEmpty()) {
return "";
} else {
- final Map<Object,Object> result = new HashMap<>();
- for(Entry<K, List<V>> entry : elements.entrySet()) {
+ final Map<Object, Object> result = new HashMap<>();
+ for (Entry<K, List<V>> entry : elements.entrySet()) {
result.put(entry.getKey(), reduce(entry.getValue()));
}
- return result ;
+ return result;
}
}
-
+
/**
* Attempts to flatten the given {@link Set}.
*
@@ -88,69 +99,227 @@ public class LabelProviderUtils {
* the {@link List} to analyze
*/
public static Object reduce(final List<?> elements) {
- if(elements == null || elements.isEmpty()) {
+ if (elements == null || elements.isEmpty()) {
return "";
- } else if(elements.size() == 1) {
+ } else if (elements.size() == 1) {
return elements.get(0);
} else {
return elements;
}
}
-
+
public static String toCreatedDate(final long created) {
return toDate(created, CREATION_DATE_PATTERN);
}
-
+
public static String toCreatedDate(final Date created) {
return toDate(created, CREATION_DATE_PATTERN);
}
-
+
public static String toFinishedDate(final Date finished) {
return toDate(finished, FINISHED_DATE_PATTERN);
}
-
+
public static String toDate(final Long date, final String pattern) {
final long millis = Long.valueOf(date).longValue() * 1000;
final Date d = new Date(millis);
- final SimpleDateFormat sdf = new SimpleDateFormat(pattern); //$NON-NLS-1$
+ final SimpleDateFormat sdf = new SimpleDateFormat(pattern); // $NON-NLS-1$
return sdf.format(d);
}
public static String toDate(final Date date, final String pattern) {
- final SimpleDateFormat sdf = new SimpleDateFormat(pattern); //$NON-NLS-1$
+ final SimpleDateFormat sdf = new SimpleDateFormat(pattern); // $NON-NLS-1$
return sdf.format(date);
}
-
+
public static String containerPortMappingToString(
final IDockerPortMapping portMapping) {
final StringBuilder mappingBuffer = new StringBuilder();
- if(portMapping.getIp() != null && portMapping.getPublicPort() != 0) {
- mappingBuffer.append(portMapping.getIp()).append(':').append(portMapping.getPublicPort()).append("->");
+ if (portMapping.getIp() != null && portMapping.getPublicPort() != 0) {
+ mappingBuffer.append(portMapping.getIp()).append(':') // $NON-NLS-1$
+ .append(portMapping.getPublicPort()).append("->");
}
- mappingBuffer.append(portMapping.getPrivatePort()).append('/').append(portMapping.getType());
+ mappingBuffer.append(portMapping.getPrivatePort()).append('/') // $NON-NLS-1$
+ .append(portMapping.getType());
return mappingBuffer.toString();
}
-
+
public static String toString(final Object value) {
- if(value == null) {
- return "null";
+ if (value == null) {
+ return "null"; //$NON-NLS-1$
}
- if(value instanceof IDockerPortBinding) {
+ if (value instanceof IDockerPortBinding) {
final IDockerPortBinding binding = (IDockerPortBinding) value;
- final String hostIp = (binding.hostIp() == null || binding.hostIp().isEmpty()) ? "<unspecified>" : binding.hostIp();
- final String hostPort = (binding.hostPort() == null || binding.hostPort().isEmpty()) ? "<unspecified>" : binding.hostPort();
- return new StringBuilder().append(hostIp).append(':').append(hostPort).toString();
+ final String hostIp = (binding.hostIp() == null
+ || binding.hostIp().isEmpty()) ? "<unspecified>" //$NON-NLS-1$
+ : binding.hostIp();
+ final String hostPort = (binding.hostPort() == null
+ || binding.hostPort().isEmpty()) ? "<unspecified>" //$NON-NLS-1$
+ : binding.hostPort();
+ return new StringBuilder().append(hostIp).append(':')
+ .append(hostPort).toString();
}
return value.toString();
}
-
+
+ /**
+ * @param element
+ * the element whose {@link StyledText} needs to be provided
+ * @return the {@link StyledText} for the given {@code element}, or
+ * <code>null</code> if the type of element is not supported.
+ */
+ public static StyledString getStyledText(final Object element) {
+ // when the text to display is in the properties view title bar, the
+ // given element
+ // is the TreeSelection from the contributing view (the Docker Explorer
+ // View)
+ if (element instanceof IStructuredSelection) {
+ return getStyledText(
+ ((IStructuredSelection) element).getFirstElement());
+ }
+ if (element instanceof IDockerConnection) {
+ return getStyledText((IDockerConnection) element);
+ } else if (element instanceof DockerImagesCategory) {
+ return new StyledString(
+ DVMessages.getString("DockerImagesCategory.label")); //$NON-NLS-1$
+ } else if (element instanceof DockerContainersCategory) {
+ return new StyledString(
+ DVMessages.getString("DockerContainersCategory.label")); //$NON-NLS-1$
+ } else if (element instanceof IDockerContainer) {
+ return getStyledText((IDockerContainer) element);
+ } else if (element instanceof IDockerImage) {
+ return LabelProviderUtils.getStyledText((IDockerImage) element);
+ } else if (element instanceof DockerContainerPortMappingsCategory) {
+ return new StyledString(DVMessages
+ .getString("DockerContainerPortMappingsCategory.label")); //$NON-NLS-1$
+ } else if (element instanceof IDockerPortMapping) {
+ return getStyledText((IDockerPortMapping) element);
+ } else if (element instanceof DockerContainerVolumesCategory) {
+ return new StyledString(DVMessages
+ .getString("DockerContainerVolumesCategory.label")); //$NON-NLS-1$
+ } else if (element instanceof DockerContainerVolume) {
+ return getStyledText((DockerContainerVolume) element);
+ } else if (element instanceof DockerContainerLinksCategory) {
+ return new StyledString(
+ DVMessages.getString("DockerContainerLinksCategory.label")); //$NON-NLS-1$
+ } else if (element instanceof DockerContainerLink) {
+ return getStyledText((DockerContainerLink) element);
+ } else if (element instanceof String) {
+ return new StyledString((String) element);
+ } else if (element instanceof LoadingStub) {
+ return new StyledString(DVMessages.getString("Loading.label")); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * @param containerLink
+ * the {@link DockerContainerLink} to process
+ * @return the {@link StyledString} to be displayed.
+ */
+ public static StyledString getStyledText(
+ final DockerContainerLink containerLink) {
+ 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;
+ }
+
+ /**
+ * @param containerVolume
+ * the {@link DockerContainerVolume} to process
+ * @return the {@link StyledString} to be displayed.
+ */
+ public static StyledString getStyledText(
+ final DockerContainerVolume containerVolume) {
+ 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;
+ }
+
+ /**
+ * @param mapping
+ * the {@link IDockerPortMapping} to process
+ * @return the {@link StyledString} to be displayed.
+ */
+ public static StyledString getStyledText(final IDockerPortMapping mapping) {
+ 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;
+ }
+
+ /**
+ * @param dockerContainer
+ * the {@link IDockerContainer} to process
+ * @return the {@link StyledString} to be displayed.
+ */
+ public static StyledString getStyledText(
+ final IDockerContainer dockerContainer) {
+ final String containerName = dockerContainer.name();
+ final String image = dockerContainer.image();
+ final String message = containerName + " (" + image + ")";
+ final StyledString styledString = new StyledString(message);
+ styledString.setStyle(containerName.length(),
+ message.length() - containerName.length(),
+ StyledString.QUALIFIER_STYLER);
+ return styledString;
+ }
+
+ /**
+ * @param connection
+ * the {@link IDockerConnection} to process
+ * @return the {@link StyledString} to be displayed.
+ */
+ public static StyledString getStyledText(
+ final IDockerConnection connection) {
+ final String connectionName = (connection.getName() != null
+ && !connection.getName().isEmpty()) ? connection.getName()
+ : DVMessages.getString("Connection.unnamed"); //$NON-NLS-1$
+ final StringBuilder messageBuilder = new StringBuilder();
+ messageBuilder.append(connectionName);
+ if (connection.getUri() != null && !connection.getUri().isEmpty()) {
+ messageBuilder.append(" (").append(connection.getUri()) //$NON-NLS-1$
+ .append(")"); //$NON-NLS-1$
+ }
+ final String message = messageBuilder.toString();
+ final StyledString styledString = new StyledString(message);
+ styledString.setStyle(connectionName.length(),
+ message.length() - connectionName.length(),
+ StyledString.QUALIFIER_STYLER);
+ return styledString;
+ }
+
/**
* @param dockerImage
- * the {@link IDockerImage} whose {@link StyledText} needs to be
- * provided
- * @return the {@link StyledText} for the given {@link IDockerImage}.
+ * the {@link IDockerImage} to process
+ * @return the {@link StyledString} to be displayed.
*/
- public static StyledString getStyleString(final IDockerImage dockerImage) {
+ public static StyledString getStyledText(final IDockerImage dockerImage) {
final StringBuilder messageBuilder = new StringBuilder(
dockerImage.repo());
final int startTags = messageBuilder.length();
@@ -169,8 +338,8 @@ public class LabelProviderUtils {
final int startImageId = messageBuilder.length();
// TODO: remove the cast to 'DockerImage' once the 'shortId()'
// method is in the public API
- messageBuilder.append(" (")
- .append(((DockerImage) dockerImage).shortId()).append(')');
+ messageBuilder.append(" (") //$NON-NLS-1$
+ .append(((DockerImage) dockerImage).shortId()).append(')'); // $NON-NLS-1$
final String message = messageBuilder.toString();
final StyledString styledString = new StyledString(message);
// styled tags

Back to the top