Search in sources :

Example 6 with IDockerImage

use of org.eclipse.linuxtools.docker.core.IDockerImage in project linuxtools by eclipse.

the class ImageRunSelectionPage method setDefaultValues.

/**
 * Sets the default values from the optional given {@link IDockerImage} and
 * {@link ILaunchConfiguration} elements
 */
private void setDefaultValues() {
    final IDockerImage selectedImage = model.getSelectedImage();
    if (selectedImage == null) {
        return;
    }
    final IDockerImageInfo selectedImageInfo = getImageInfo(selectedImage);
    // skip if a previous launch configuration was provided
    if (this.lastLaunchConfiguration != null) {
        try {
            this.model.setContainerName(lastLaunchConfiguration.getAttribute(CONTAINER_NAME, ""));
            this.model.setEntrypoint(lastLaunchConfiguration.getAttribute(ENTRYPOINT, ""));
            this.model.setCommand(lastLaunchConfiguration.getAttribute(COMMAND, ""));
            this.model.setPublishAllPorts(lastLaunchConfiguration.getAttribute(PUBLISH_ALL_PORTS, false));
            final List<String> exposedPortInfos = lastLaunchConfiguration.getAttribute(PUBLISHED_PORTS, Collections.<String>emptyList());
            // by the user.
            if (selectedImageInfo != null) {
                final List<ExposedPortModel> exposedPorts = ExposedPortModel.fromStrings(selectedImageInfo.config().exposedPorts());
                model.setExposedPorts(exposedPorts);
                final List<ExposedPortModel> selectedExposedPorts = ExposedPortModel.fromStrings(exposedPortInfos);
                this.model.setSelectedPorts(new HashSet<>(selectedExposedPorts));
            }
            // links
            this.model.setLinks(lastLaunchConfiguration.getAttribute(LINKS, Collections.<String>emptyList()));
            // other options
            this.model.setRemoveWhenExits(lastLaunchConfiguration.getAttribute(AUTO_REMOVE, false));
            this.model.setInteractiveMode(lastLaunchConfiguration.getAttribute(INTERACTIVE, false));
            this.model.setAllocatePseudoTTY(lastLaunchConfiguration.getAttribute(ALLOCATE_PSEUDO_CONSOLE, false));
            this.model.setPrivileged(lastLaunchConfiguration.getAttribute(PRIVILEGED, false));
            this.model.setBasicSecurity(lastLaunchConfiguration.getAttribute(READONLY, false));
        } catch (CoreException e) {
            Activator.log(e);
        }
    } else {
        applyImageInfo(selectedImageInfo);
    }
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) CoreException(org.eclipse.core.runtime.CoreException) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 7 with IDockerImage

use of org.eclipse.linuxtools.docker.core.IDockerImage in project linuxtools by eclipse.

the class DockerExplorerLabelProvider method getImage.

@Override
public Image getImage(final Object element) {
    if (element instanceof IDockerConnection) {
        if (((IDockerConnection) element).isOpen()) {
            return OPEN_CONNECTION_IMAGE;
        } else {
            return UNOPEN_CONNECTION_IMAGE;
        }
    } else if (element instanceof DockerImagesCategory) {
        return CATEGORY_IMAGE;
    } else if (element instanceof DockerContainersCategory) {
        return CATEGORY_IMAGE;
    } else if (element instanceof IDockerImage) {
        return IMAGE_IMAGE;
    } else if (element instanceof IDockerContainer) {
        final IDockerContainer container = (IDockerContainer) element;
        final EnumDockerStatus containerStatus = EnumDockerStatus.fromStatusMessage(container.status());
        if (containerStatus == EnumDockerStatus.RUNNING) {
            return STARTED_CONTAINER_IMAGE;
        } else if (containerStatus == EnumDockerStatus.PAUSED) {
            return PAUSED_CONTAINER_IMAGE;
        } else {
            return STOPPED_CONTAINER_IMAGE;
        }
    } else if (element instanceof DockerContainerLinksCategory || element instanceof DockerContainerLink) {
        return CONTAINER_LINK_IMAGE;
    } else if (element instanceof DockerContainerVolumesCategory || element instanceof DockerContainerVolume) {
        return CONTAINER_VOLUME_IMAGE;
    } else if (element instanceof DockerContainerPortMappingsCategory || element instanceof IDockerPortMapping) {
        return CONTAINER_PORT_IMAGE;
    } else if (element instanceof LoadingStub) {
        return LOADING_IMAGE;
    }
    return null;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) DockerContainerLinksCategory(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerLinksCategory) DockerContainerLink(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerLink) DockerContainerVolumesCategory(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolumesCategory) IDockerPortMapping(org.eclipse.linuxtools.docker.core.IDockerPortMapping) DockerImagesCategory(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerImagesCategory) DockerContainersCategory(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainersCategory) DockerContainerPortMappingsCategory(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerPortMappingsCategory) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerContainerVolume(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolume) EnumDockerStatus(org.eclipse.linuxtools.docker.core.EnumDockerStatus) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) LoadingStub(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.LoadingStub)

Example 8 with IDockerImage

use of org.eclipse.linuxtools.docker.core.IDockerImage in project linuxtools by eclipse.

the class DockerImagesContentProvider method getElements.

@Override
public Object[] getElements(final Object inputElement) {
    if (inputElement instanceof IDockerConnection) {
        final IDockerConnection connection = (IDockerConnection) inputElement;
        if (connection.isImagesLoaded()) {
            final List<IDockerImage> images = connection.getImages();
            if (images == null) {
                return EMPTY;
            }
            return images.toArray();
        }
        loadImages(connection);
        return EMPTY;
    }
    return EMPTY;
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 9 with IDockerImage

use of org.eclipse.linuxtools.docker.core.IDockerImage in project linuxtools by eclipse.

the class LabelProviderUtils method getStyledText.

/**
 * @param dockerImage
 *            the {@link IDockerImage} to process
 * @return the {@link StyledString} to be displayed.
 */
public static StyledString getStyledText(final IDockerImage dockerImage) {
    final StyledString result = new StyledString(dockerImage.repo());
    if (!dockerImage.tags().isEmpty()) {
        final List<String> tags = new ArrayList<>(dockerImage.tags());
        Collections.sort(tags);
        result.append(":");
        // $NON-NLS-1$
        result.append(// $NON-NLS-1$
        tags.stream().collect(Collectors.joining(", ")), StyledString.COUNTER_STYLER);
    }
    // TODO: remove the cast to 'DockerImage' once the 'shortId()'
    // method is in the public API
    // $NON-NLS-1$
    result.append(" (", StyledString.QUALIFIER_STYLER).append(((DockerImage) dockerImage).shortId(), StyledString.QUALIFIER_STYLER).append(')', // $NON-NLS-1$
    StyledString.QUALIFIER_STYLER);
    return result;
}
Also used : ArrayList(java.util.ArrayList) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) DockerImage(org.eclipse.linuxtools.internal.docker.core.DockerImage) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 10 with IDockerImage

use of org.eclipse.linuxtools.docker.core.IDockerImage in project linuxtools by eclipse.

the class DockerImageHierarchyViewAssertions method hasSelectedElement.

public void hasSelectedElement(final IDockerImage 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 instanceof IDockerImage) {
        final IDockerImage selectedImage = (IDockerImage) selectedElement;
        if (!selectedImage.id().equals(expectedSelection.id())) {
            failWithMessage("Expected Docker Image Hierarchy view to have a Docker images with id <%s> as the selected element, but it was <%s>", expectedSelection.id(), ((IDockerImage) selectedElement).id());
        }
    } else {
        failWithMessage("Expected Docker Image Hierarchy view to have a Docker Image as the selected element, but it was a <%s>", selectedElement.getClass());
    }
}
Also used : IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Aggregations

IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)41 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)16 DockerException (org.eclipse.linuxtools.docker.core.DockerException)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 IDockerImageHierarchyNode (org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)7 List (java.util.List)6 CoreException (org.eclipse.core.runtime.CoreException)6 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)5 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)5 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)5 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)5 HashMap (java.util.HashMap)4 Map (java.util.Map)3 Job (org.eclipse.core.runtime.jobs.Job)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 IDockerContainerConfig (org.eclipse.linuxtools.docker.core.IDockerContainerConfig)3 IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)3 DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)3