use of org.eclipse.jface.viewers.ColumnLabelProvider in project linuxtools by eclipse.
the class BasePropertySection method createTableTreeViewer.
private TreeViewer createTableTreeViewer(final Composite container) {
final TreeViewer treeViewer = new TreeViewer(container, SWT.V_SCROLL | SWT.H_SCROLL);
final Tree tree = treeViewer.getTree();
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
final TreeViewerColumn propertyColumn = new TreeViewerColumn(treeViewer, SWT.BORDER);
propertyColumn.getColumn().setWidth(150);
propertyColumn.getColumn().setText("Property");
propertyColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof Object[]) {
final Object property = ((Object[]) element)[0];
return property.toString();
}
return super.getText(element);
}
});
final TreeViewerColumn valueColumn = new TreeViewerColumn(treeViewer, SWT.BORDER);
valueColumn.getColumn().setWidth(500);
valueColumn.getColumn().setText("Value");
valueColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof Object[]) {
final Object value = ((Object[]) element)[1];
// do not show values of a collection. There will be nested elements in the treeview for them.
if (value instanceof Collection) {
return "";
} else if (value instanceof String || value instanceof Boolean || value instanceof Integer) {
return value.toString();
}
return "";
}
return super.getText(element);
}
});
return treeViewer;
}
use of org.eclipse.jface.viewers.ColumnLabelProvider in project linuxtools by eclipse.
the class DockerContainersComparator method compareByColumn.
private int compareByColumn(final IDockerContainer container1, final IDockerContainer container2) {
final ColumnLabelProvider sortColumnLabelProvider = (ColumnLabelProvider) this.tableViewer.getLabelProvider(sortColumnIndex);
final String container1ColumnValue = sortColumnLabelProvider.getText(container1);
final String container2ColumnValue = sortColumnLabelProvider.getText(container2);
if (this.sortDirection == SWT.UP) {
return container1ColumnValue.compareToIgnoreCase(container2ColumnValue);
} else {
return container1ColumnValue.compareToIgnoreCase(container2ColumnValue) * -1;
}
}
use of org.eclipse.jface.viewers.ColumnLabelProvider in project linuxtools by eclipse.
the class DockerImagesComparator method compareByColumn.
private int compareByColumn(final IDockerImage image1, final IDockerImage image2) {
final ColumnLabelProvider sortColumnLabelProvider = (ColumnLabelProvider) this.tableViewer.getLabelProvider(sortColumnIndex);
final String image1ColumnValue;
final String image2ColumnValue;
// Special columns will provide a special value to use in comparing
if (sortColumnLabelProvider instanceof SpecialColumnLabelProvider) {
image1ColumnValue = ((SpecialColumnLabelProvider) sortColumnLabelProvider).getCompareText(image1);
image2ColumnValue = ((SpecialColumnLabelProvider) sortColumnLabelProvider).getCompareText(image2);
} else {
image1ColumnValue = sortColumnLabelProvider.getText(image1);
image2ColumnValue = sortColumnLabelProvider.getText(image2);
}
if (this.sortDirection == SWT.UP) {
return image1ColumnValue.compareToIgnoreCase(image2ColumnValue);
} else {
return image1ColumnValue.compareToIgnoreCase(image2ColumnValue) * -1;
}
}
use of org.eclipse.jface.viewers.ColumnLabelProvider in project linuxtools by eclipse.
the class DockerImagesView method createTableViewer.
private void createTableViewer(final Composite container) {
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 DockerImagesContentProvider());
final Table table = 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);
// 'Image' column
final TableViewerColumn idColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
"ID"));
setLayout(idColumn, tableLayout, 150);
idColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IDockerImage) {
// for image id, remove any sha256 digest prefix
// and truncate to max of 12 characters
String imageId = ((IDockerImage) element).id();
if (// $NON-NLS-1$
imageId.startsWith("sha256:"))
imageId = imageId.substring(7);
if (imageId.length() > 12) {
return imageId.substring(0, 12);
}
return imageId;
}
return super.getText(element);
}
});
// 'Repo/Tags' column
final TableViewerColumn tagsColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
"TAGS"));
setLayout(tagsColumn, tableLayout, 150);
tagsColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IDockerImage) {
final IDockerImage image = (IDockerImage) element;
final StringBuilder messageBuilder = new StringBuilder();
for (Iterator<String> iterator = image.repoTags().iterator(); iterator.hasNext(); ) {
final String repoTag = iterator.next();
messageBuilder.append(repoTag);
if (iterator.hasNext()) {
messageBuilder.append('\n');
}
}
return messageBuilder.toString();
}
return super.getText(element);
}
});
// 'Creation Date' column
final TableViewerColumn creationDateColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
"CREATED"));
setLayout(creationDateColumn, tableLayout, 150);
creationDateColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IDockerImage) {
return LabelProviderUtils.toCreatedDate(Long.parseLong(((IDockerImage) element).created()));
}
return super.getText(element);
}
});
// 'Virtual Size' column
final TableViewerColumn virtsizeColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
"VIRTSIZE"));
setLayout(virtsizeColumn, tableLayout, 150);
virtsizeColumn.setLabelProvider(new SpecialColumnLabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IDockerImage) {
Long size = ((IDockerImage) element).virtualSize();
if (size <= 0)
// $NON-NLS-1$
return "0";
final String[] units = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"B", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"kB", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"MB", "GB", // $NON-NLS-1$ //$NON-NLS-2$
"TB" };
int digitGroups = (int) (Math.log10(size) / Math.log10(1000));
return new DecimalFormat("#,##0.#").format(// $NON-NLS-1$
size / Math.pow(1000, digitGroups)) + " " + units[digitGroups];
}
return super.getText(element);
}
@Override
public String getCompareText(final Object element) {
// and not the shortened value with units appended.
if (element instanceof IDockerImage) {
return // $NON-NLS-1$
new DecimalFormat("000000000000000000000000").format((((IDockerImage) element).virtualSize()));
}
return super.getText(element);
}
});
// comparator
final DockerImagesComparator comparator = new DockerImagesComparator(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());
viewer.setComparator(comparator);
// apply search filter
this.viewer.addFilter(getImagesFilter());
setConnection(CommandUtils.getCurrentConnection(null));
// get the current selection in the tableviewer
getSite().setSelectionProvider(viewer);
}
use of org.eclipse.jface.viewers.ColumnLabelProvider in project linuxtools by eclipse.
the class JavaImageTab method createControl.
@Override
public void createControl(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);
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);
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;
if (conn == null || conn.getImages() == null) {
return new Object[0];
} else {
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();
selectedConnection = conn;
imageCmb.setInput(conn);
updateLaunchConfigurationDialog();
}
});
imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerImage img = (IDockerImage) sel.getFirstElement();
selectedImage = img;
updateLaunchConfigurationDialog();
}
});
Group dirGroup = new Group(composite, SWT.NONE);
dirGroup.setText(Messages.JavaImageTab_additional_dirs);
dirGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
dirGroup.setLayout(new GridLayout(2, false));
directoryList = new List(dirGroup, SWT.SINGLE | SWT.V_SCROLL);
directoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
directoryList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
removeButton.setEnabled(true);
}
});
addButton = createPushButton(dirGroup, Messages.JavaImageTab_button_add, null);
addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
String directory = dialog.open();
if (directory != null && !listContains(directoryList, directory)) {
directoryList.add(directory);
updateLaunchConfigurationDialog();
}
}
});
removeButton = createPushButton(dirGroup, Messages.JavaImageTab_button_remove, null);
removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int i = directoryList.getSelectionIndex();
if (i >= 0) {
directoryList.remove(i);
updateLaunchConfigurationDialog();
}
if (directoryList.getItemCount() == 0) {
removeButton.setEnabled(false);
}
}
});
removeButton.setEnabled(false);
setControl(composite);
}
Aggregations