Search in sources :

Example 1 with IDockerPortMapping

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

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

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

the class ShowInWebBrowserCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<IDockerPortMapping> portMappings = getSelectedPortMappings(activePart);
    if (portMappings == null || portMappings.isEmpty()) {
        return null;
    }
    final Job job = new Job(// $NON-NLS-1$
    CommandMessages.getString("command.showIn.webBrowser")) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                final IDockerConnection currentConnection = getCurrentConnection(activePart);
                final IDockerPortMapping selectedPort = portMappings.get(0);
                final URI connectionURI = new URI(currentConnection.getUri());
                if (// $NON-NLS-1$
                "tcp".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "unix".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "http".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "https".equalsIgnoreCase(connectionURI.getScheme())) {
                    final String host = // $NON-NLS-1$
                    "unix".equalsIgnoreCase(connectionURI.getScheme()) ? "127.0.0.1" : // $NON-NLS-1$
                    connectionURI.getHost();
                    final URL location = new // $NON-NLS-1$
                    URL(// $NON-NLS-1$
                    "http", // $NON-NLS-1$
                    host, selectedPort.getPublicPort(), // $NON-NLS-1$
                    "/");
                    openLocationInWebBrowser(location);
                }
            } catch (URISyntaxException | MalformedURLException e) {
                Activator.logErrorMessage(CommandMessages.getString(// $NON-NLS-1$
                "command.showIn.webBrowser.failure"), e);
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MalformedURLException(java.net.MalformedURLException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) URISyntaxException(java.net.URISyntaxException) IDockerPortMapping(org.eclipse.linuxtools.docker.core.IDockerPortMapping) Job(org.eclipse.core.runtime.jobs.Job) URI(java.net.URI) URL(java.net.URL)

Aggregations

IDockerPortMapping (org.eclipse.linuxtools.docker.core.IDockerPortMapping)3 EnumDockerStatus (org.eclipse.linuxtools.docker.core.EnumDockerStatus)2 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)2 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)2 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Iterator (java.util.Iterator)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)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 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