use of org.eclipse.jface.viewers.TableViewerColumn in project linuxtools by eclipse.
the class ImageRunSelectionPage method createTableViewerColum.
private TableViewerColumn createTableViewerColum(final TableViewer tableViewer, final String title, final int width) {
final TableViewerColumn viewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
final TableColumn column = viewerColumn.getColumn();
if (title != null) {
column.setText(title);
}
column.setWidth(width);
return viewerColumn;
}
use of org.eclipse.jface.viewers.TableViewerColumn 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.jface.viewers.TableViewerColumn in project linuxtools by eclipse.
the class DockerImagesView method createColumn.
private TableViewerColumn createColumn(final String title) {
final TableViewerColumn propertyColumn = new TableViewerColumn(viewer, SWT.BORDER);
propertyColumn.getColumn().setText(title);
propertyColumn.getColumn().addSelectionListener(onColumnSelected());
return propertyColumn;
}
use of org.eclipse.jface.viewers.TableViewerColumn in project yamcs-studio by yamcs.
the class ClientsTableViewer method addFixedColumns.
private void addFixedColumns() {
TableViewerColumn idColumn = new TableViewerColumn(this, SWT.CENTER);
idColumn.getColumn().setText(COL_ID);
idColumn.getColumn().setWidth(30);
idColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return String.valueOf(client.getId());
}
});
TableViewerColumn userColumn = new TableViewerColumn(this, SWT.LEFT);
userColumn.getColumn().setText(COL_USER);
userColumn.getColumn().setWidth(100);
userColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return String.valueOf(client.getUsername());
}
});
TableViewerColumn applicationColumn = new TableViewerColumn(this, SWT.LEFT);
applicationColumn.getColumn().setText(COL_APPLICATION);
applicationColumn.getColumn().setWidth(100);
applicationColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getApplicationName();
}
});
TableViewerColumn instanceColumn = new TableViewerColumn(this, SWT.LEFT);
instanceColumn.getColumn().setText(COL_INSTANCE);
instanceColumn.getColumn().setWidth(100);
instanceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getInstance();
}
});
TableViewerColumn processorColumn = new TableViewerColumn(this, SWT.LEFT);
processorColumn.getColumn().setText(COL_PROCESSOR);
processorColumn.getColumn().setWidth(100);
processorColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getProcessorName();
}
});
// prevent resize to 0
for (TableColumn column : getTable().getColumns()) {
column.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (column.getWidth() < 5) {
column.setWidth(5);
}
}
});
}
}
use of org.eclipse.jface.viewers.TableViewerColumn in project yamcs-studio by yamcs.
the class AddParameterPage method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
setControl(composite);
GridLayout gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.numColumns = 2;
gl.makeColumnsEqualWidth = false;
composite.setLayout(gl);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite tableWrapper1 = new Composite(composite, SWT.NONE);
contentProvider = new ParameterContentProvider();
trcl = new TreeColumnLayout();
tableWrapper1.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper1.setLayout(trcl);
namespaceTable = new TreeViewer(tableWrapper1, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
namespaceTable.getTree().setHeaderVisible(true);
namespaceTable.getTree().setLinesVisible(true);
// column container
TreeViewerColumn pathColumn = new TreeViewerColumn(namespaceTable, SWT.NONE);
pathColumn.getColumn().setText(COL_NAMESPACE);
pathColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
String namespace = (String) element;
return namespace;
}
});
trcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
namespaceTable.addSelectionChangedListener(evt -> {
IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
contentProvider.setNamespace(null);
return;
}
contentProvider.setNamespace((String) sel.getFirstElement());
});
namespaceTable.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection sel = new IStructuredSelection() {
@Override
public boolean isEmpty() {
return false;
}
@Override
public List toList() {
return Arrays.asList(contentProvider.getElements(event));
}
@Override
public Object[] toArray() {
return contentProvider.getElements(event);
}
@Override
public int size() {
return contentProvider.getElements(event).length;
}
@Override
public Iterator iterator() {
return Arrays.asList(contentProvider.getElements(event)).iterator();
}
@Override
public Object getFirstElement() {
return null;
}
};
parameterTable.setSelection(sel);
}
});
namespaceTable.setContentProvider(new NamespaceContentProvider());
namespaceTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
String n1 = (String) o1;
String n2 = (String) o2;
return n1.compareTo(n2);
}
});
Composite tableWrapper2 = new Composite(composite, SWT.NONE);
tcl = new TableColumnLayout();
tableWrapper2.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper2.setLayout(tcl);
parameterTable = new TableViewer(tableWrapper2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
parameterTable.getTable().setHeaderVisible(true);
parameterTable.getTable().setLinesVisible(true);
TableViewerColumn nameColumn = new TableViewerColumn(parameterTable, SWT.NONE);
nameColumn.getColumn().setText(COL_NAME);
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ParameterInfo obj = (ParameterInfo) element;
return obj.getQualifiedName();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
parameterTable.addSelectionChangedListener(evt -> {
IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
setParameter(new ArrayList<>());
return;
}
List<ParameterInfo> parameters = new ArrayList<>();
for (Object obj : sel.toArray()) {
parameters.add((ParameterInfo) obj);
}
setParameter(parameters);
setPageComplete(true);
});
parameterTable.setContentProvider(contentProvider);
parameterTable.setInput(contentProvider);
ParameterCatalogue.getInstance().getMetaParameters().forEach(pmtr -> {
for (NamedObjectId alias : pmtr.getAliasList()) {
String namespace = alias.getNamespace();
if (!namespace.startsWith("/"))
return;
if (!parameterInfos.containsKey(namespace)) {
parameterInfos.put(namespace, new ArrayList<>());
}
parameterInfos.get(namespace).add(pmtr);
String parentns = namespace.substring(0, namespace.lastIndexOf("/"));
while (!parentns.isEmpty()) {
if (!parameterInfos.containsKey(parentns)) {
parameterInfos.put(parentns, new ArrayList<>());
}
parentns = parentns.substring(0, parentns.lastIndexOf("/"));
}
}
});
namespaceTable.setInput(parameterInfos.keySet());
parameterTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
ParameterInfo n1 = (ParameterInfo) o1;
ParameterInfo n2 = (ParameterInfo) o2;
return n1.getQualifiedName().compareTo(n2.getQualifiedName());
}
});
}
Aggregations