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