use of org.eclipse.jface.viewers.ColumnLabelProvider in project linuxtools by eclipse.
the class ImageSelectionDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
Label connLbl = new Label(composite, SWT.NONE);
connLbl.setText(Messages.ImageSelectionDialog_connection_label);
ComboViewer connCmb = new ComboViewer(composite, SWT.READ_ONLY);
connCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
connCmb.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
for (IDockerConnection conn : DockerConnectionManager.getInstance().getAllConnections()) {
try {
((DockerConnection) conn).open(false);
} catch (DockerException e) {
}
}
return DockerConnectionManager.getInstance().getAllConnections().stream().filter(c -> c.isOpen()).toArray(size -> new IDockerConnection[size]);
}
});
// $NON-NLS-1$
connCmb.setInput("place_holder");
Label imageLbl = new Label(composite, SWT.NONE);
imageLbl.setText(Messages.ImageSelectionDialog_image_label);
ComboViewer imageCmb = new ComboViewer(composite, SWT.READ_ONLY);
imageCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
imageCmb.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
IDockerConnection conn = (IDockerConnection) inputElement;
return conn.getImages().stream().filter(// $NON-NLS-1$
i -> !i.repoTags().get(0).equals("<none>:<none>")).toArray(size -> new IDockerImage[size]);
}
});
imageCmb.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
IDockerImage img = (IDockerImage) element;
return img.repoTags().get(0);
}
});
imageCmb.setInput(null);
connCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerConnection conn = (IDockerConnection) sel.getFirstElement();
connection = conn;
imageCmb.setInput(conn);
}
});
imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerImage img = (IDockerImage) sel.getFirstElement();
image = img;
getOkButton().setEnabled(true);
}
});
return composite;
}
use of org.eclipse.jface.viewers.ColumnLabelProvider 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.ColumnLabelProvider in project yamcs-studio by yamcs.
the class FunctionsView method createPartControl.
@Override
public void createPartControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
TreeColumnLayout tcl_composite = new TreeColumnLayout();
composite.setLayout(tcl_composite);
treeViewer = new TreeViewer(composite, SWT.BORDER);
Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
treeViewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
return null;
}
@Override
public String getText(Object element) {
if (element instanceof FormulaFunctionSet) {
return ((FormulaFunctionSet) element).getName();
} else if (element instanceof FormulaFunction) {
return FormulaFunctions.formatSignature((FormulaFunction) element);
}
return "";
}
});
TreeColumn trclmnNewColumn = treeViewerColumn.getColumn();
tcl_composite.setColumnData(trclmnNewColumn, new ColumnWeightData(10, ColumnWeightData.MINIMUM_WIDTH, true));
trclmnNewColumn.setText("Name");
TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(treeViewer, SWT.NONE);
treeViewerColumn_1.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
return null;
}
@Override
public String getText(Object element) {
if (element instanceof FormulaFunction) {
return ((FormulaFunction) element).getDescription();
} else if (element instanceof FormulaFunctionSet) {
return ((FormulaFunctionSet) element).getDescription();
}
return "";
}
});
TreeColumn trclmnNewColumn_1 = treeViewerColumn_1.getColumn();
tcl_composite.setColumnData(trclmnNewColumn_1, new ColumnWeightData(7, ColumnWeightData.MINIMUM_WIDTH, true));
trclmnNewColumn_1.setText("Description");
treeViewer.setContentProvider(new FunctionTreeContentProvider());
List<String> functionSetNames = new ArrayList<>(FormulaRegistry.getDefault().listFunctionSets());
Collections.sort(functionSetNames);
List<FormulaFunctionSet> functionSets = new ArrayList<>();
for (String functionSetName : functionSetNames) {
functionSets.add(FormulaRegistry.getDefault().findFunctionSet(functionSetName));
}
treeViewer.setInput(functionSets);
}
use of org.eclipse.jface.viewers.ColumnLabelProvider 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.ColumnLabelProvider 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