Search in sources :

Example 1 with EnumDockerStatus

use of org.eclipse.linuxtools.docker.core.EnumDockerStatus 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 2 with EnumDockerStatus

use of org.eclipse.linuxtools.docker.core.EnumDockerStatus 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 3 with EnumDockerStatus

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

the class HideStoppedContainersViewerFilter method select.

@Override
public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
    if (element instanceof IDockerContainer) {
        final IDockerContainer container = (IDockerContainer) element;
        final EnumDockerStatus containerStatus = EnumDockerStatus.fromStatusMessage(container.status());
        if (containerStatus == EnumDockerStatus.RUNNING || containerStatus == EnumDockerStatus.PAUSED) {
            return true;
        }
        return false;
    }
    return true;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) EnumDockerStatus(org.eclipse.linuxtools.docker.core.EnumDockerStatus)

Aggregations

EnumDockerStatus (org.eclipse.linuxtools.docker.core.EnumDockerStatus)3 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)3 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)2 IDockerPortMapping (org.eclipse.linuxtools.docker.core.IDockerPortMapping)2 Iterator (java.util.Iterator)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)1 DockerContainerLink (org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerLink)1 DockerContainerLinksCategory (org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerLinksCategory)1 DockerContainerPortMappingsCategory (org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerPortMappingsCategory)1 DockerContainerVolume (org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolume)1 DockerContainerVolumesCategory (org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolumesCategory)1 DockerContainersCategory (org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainersCategory)1 DockerImagesCategory (org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerImagesCategory)1 LoadingStub (org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.LoadingStub)1 Image (org.eclipse.swt.graphics.Image)1 Composite (org.eclipse.swt.widgets.Composite)1