Search in sources :

Example 1 with IDockerContainer

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

the class WizardUtils method getContainerNames.

/**
 * @param connection
 *            the current {@link IDockerContainer}
 * @return the {@link List} of name of the {@link IDockerContainer}
 */
public static List<String> getContainerNames(final IDockerConnection connection) {
    final List<String> containerNames = new ArrayList<>();
    for (IDockerContainer container : connection.getContainers()) {
        containerNames.add(container.name());
    }
    Collections.sort(containerNames);
    return containerNames;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) ArrayList(java.util.ArrayList)

Example 2 with IDockerContainer

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

the class DockerImageHierarchyNodeUtils method resolveChildrenImageNodes.

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)).forEach(image -> {
        final DockerImageHierarchyNode childNode = new DockerImageHierarchyImageNode(image, parentNode);
        resolveChildrenImageNodes(images, containers, image.id(), image.repoTags(), childNode);
    });
    containers.stream().filter(container -> container.image() != null && imageRepoTags.contains(container.image())).forEach(container -> new DockerImageHierarchyContainerNode(container, parentNode));
}
Also used : List(java.util.List) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode) IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)

Example 3 with IDockerContainer

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

the class ContainerPropertyTester method test.

@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
    if (receiver instanceof IDockerContainer) {
        IDockerContainer container = (IDockerContainer) receiver;
        /*
			 * The 'receiver' is not updated if the selection remains unchanged
			 * but a context menu command may have modified container state
			 * requiring a change in menu items.
			 */
        final IDockerContainer newContainer = container.getConnection().getContainer(container.id());
        if (newContainer != null) {
            container = newContainer;
        }
        switch(property) {
            case IS_RUNNING:
                return checkIfStateMatchesExpectation(container, EnumDockerStatus.RUNNING, expectedValue);
            case IS_STOPPED:
                return checkIfStateMatchesExpectation(container, EnumDockerStatus.STOPPED, expectedValue);
            case IS_UNKNOWN:
                return checkIfStateMatchesExpectation(container, EnumDockerStatus.UNKNOWN, expectedValue);
            case IS_PAUSED:
                return checkIfStateMatchesExpectation(container, EnumDockerStatus.PAUSED, expectedValue);
            case IS_REMOVABLE:
                return checkIfStateMatchesExpectation(container, EnumDockerStatus.STOPPED, expectedValue) || checkIfStateMatchesExpectation(container, EnumDockerStatus.UNKNOWN, expectedValue);
        }
    } else if (receiver instanceof IDockerImageHierarchyContainerNode) {
        return test(((IDockerImageHierarchyContainerNode) receiver).getElement(), property, args, expectedValue);
    }
    return false;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IDockerImageHierarchyContainerNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyContainerNode)

Example 4 with IDockerContainer

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

the class DockerContainersView method createTableViewer.

private void createTableViewer(final Composite container) {
    this.search = new Text(container, SWT.SEARCH | SWT.ICON_SEARCH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(search);
    search.addModifyListener(onSearch());
    Composite tableArea = new Composite(container, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(tableArea);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableArea);
    final TableColumnLayout tableLayout = new TableColumnLayout();
    tableArea.setLayout(tableLayout);
    this.viewer = new TableViewer(tableArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    this.viewer.setContentProvider(new DockerContainersContentProvider());
    final Table table = this.viewer.getTable();
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(table);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(table);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    // 'Name' column
    // $NON-NLS-1$
    final TableViewerColumn nameColumn = createColumn(DVMessages.getString("NAME"));
    setLayout(nameColumn, tableLayout, 150);
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return ((IDockerContainer) element).name();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof IDockerContainer) {
                final IDockerContainer container = (IDockerContainer) element;
                final EnumDockerStatus containerStatus = EnumDockerStatus.fromStatusMessage(container.status());
                if (containerStatus == EnumDockerStatus.RUNNING) {
                    return STARTED_IMAGE;
                } else if (containerStatus == EnumDockerStatus.PAUSED) {
                    return PAUSED_IMAGE;
                } else {
                    return STOPPED_IMAGE;
                }
            }
            return super.getImage(element);
        }
    });
    // 'Image' column
    // $NON-NLS-1$
    final TableViewerColumn imageColumn = createColumn(DVMessages.getString("IMAGE"));
    setLayout(imageColumn, tableLayout, 150);
    imageColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return ((IDockerContainer) element).image();
            }
            return super.getText(element);
        }
    });
    // 'Creation Date' column
    // $NON-NLS-1$
    final TableViewerColumn creationDateColumn = createColumn(DVMessages.getString("CREATED"));
    setLayout(creationDateColumn, tableLayout, 150);
    creationDateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return LabelProviderUtils.toCreatedDate(((IDockerContainer) element).created());
            }
            return super.getText(element);
        }
    });
    // 'Command' column
    final TableViewerColumn commandColumn = createColumn(// $NON-NLS-1$
    DVMessages.getString("COMMAND"));
    setLayout(commandColumn, tableLayout, 150);
    commandColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return ((IDockerContainer) element).command();
            }
            return super.getText(element);
        }
    });
    // 'Ports' column
    // $NON-NLS-1$
    final TableViewerColumn portsColumn = createColumn(DVMessages.getString("PORTS"));
    setLayout(portsColumn, tableLayout, 150);
    portsColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                final StringBuilder ports = new StringBuilder();
                for (Iterator<IDockerPortMapping> iterator = ((IDockerContainer) element).ports().iterator(); iterator.hasNext(); ) {
                    final IDockerPortMapping portMapping = iterator.next();
                    ports.append(LabelProviderUtils.containerPortMappingToString(portMapping));
                    if (iterator.hasNext()) {
                        ports.append(", ");
                    }
                }
                return ports.toString();
            }
            return super.getText(element);
        }
    });
    // 'Status' column
    // $NON-NLS-1$
    final TableViewerColumn statusColumn = createColumn(DVMessages.getString("STATUS"));
    setLayout(statusColumn, tableLayout, 150);
    statusColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerContainer) {
                return ((IDockerContainer) element).status();
            }
            return super.getText(element);
        }
    });
    // comparator
    final DockerContainersComparator comparator = new DockerContainersComparator(this.viewer);
    comparator.setColumn(creationDateColumn.getColumn());
    // Set column a second time so we reverse the order and default to most
    // currently created containers first
    comparator.setColumn(creationDateColumn.getColumn());
    this.viewer.setComparator(comparator);
    // apply search filter
    this.viewer.setFilters(getContainersFilter());
    setConnection(CommandUtils.getCurrentConnection(null));
    this.viewer.addSelectionChangedListener(onContainerSelection());
    // get the current selection in the tableviewer
    getSite().setSelectionProvider(this.viewer);
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Text(org.eclipse.swt.widgets.Text) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(org.eclipse.swt.graphics.Image) IDockerPortMapping(org.eclipse.linuxtools.docker.core.IDockerPortMapping) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Iterator(java.util.Iterator) EnumDockerStatus(org.eclipse.linuxtools.docker.core.EnumDockerStatus) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 5 with IDockerContainer

use of org.eclipse.linuxtools.docker.core.IDockerContainer 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)

Aggregations

IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)25 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)9 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)8 Job (org.eclipse.core.runtime.jobs.Job)7 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)4 IDockerImageHierarchyNode (org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)4 Test (org.junit.Test)4 DockerException (org.eclipse.linuxtools.docker.core.DockerException)3 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)3 DockerClient (com.spotify.docker.client.DockerClient)2 Container (com.spotify.docker.client.messages.Container)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)2 EnumDockerLoggingStatus (org.eclipse.linuxtools.docker.core.EnumDockerLoggingStatus)2 EnumDockerStatus (org.eclipse.linuxtools.docker.core.EnumDockerStatus)2 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)2 IDockerPortBinding (org.eclipse.linuxtools.docker.core.IDockerPortBinding)2