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);
}
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;
}
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;
}
Aggregations