use of org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder in project jbosstools-openshift by jbosstools.
the class ResourceLabelsPage method createTable.
protected TableViewer createTable(Composite tableContainer) {
Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLinesVisible(true);
table.setHeaderVisible(true);
this.viewer = new TableViewerBuilder(table, tableContainer).contentProvider(new ArrayContentProvider()).<Label>column(new DelegatingStyledCellLabelProvider(new LabelTextProvider() {
@Override
public String getValue(Label label) {
return label.getName();
}
})).name(LABEL_KEY).align(SWT.LEFT).weight(2).minWidth(100).buildColumn().<Label>column(new DelegatingStyledCellLabelProvider(new LabelTextProvider() {
@Override
public String getValue(Label label) {
return label.getValue();
}
})).name("Value").align(SWT.LEFT).weight(2).minWidth(100).buildColumn().buildViewer();
viewer.addDoubleClickListener(e -> editLabel((Label) ((IStructuredSelection) e.getSelection()).getFirstElement()));
viewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
Label first = (Label) e1;
Label other = (Label) e2;
return first.getName().compareTo(other.getName());
}
});
return viewer;
}
use of org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder in project jbosstools-openshift by jbosstools.
the class EventsPropertySection method addColumns.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void addColumns(TableViewerBuilder tableViewerBuilder) {
addCreatedColumn(tableViewerBuilder);
ICellToolTipProvider toolTipProvider = new ICellToolTipProvider() {
@Override
public String getToolTipText(Object object) {
if (object instanceof IResourceWrapper && ((IResourceWrapper) object).getWrapped() instanceof IEvent) {
return ((IEvent) ((IResourceWrapper) object).getWrapped()).getMessage();
}
return null;
}
@Override
public int getToolTipDisplayDelayTime(Object event) {
return 0;
}
};
tableViewerBuilder.column(model -> StringUtils.substringBefore(getResource(model).getName(), ".")).name("Name").align(SWT.LEFT).weight(1).minWidth(15).cellToolTipProvider(toolTipProvider).buildColumn().column(model -> ((IEvent) getResource(model)).getInvolvedObject().getKind()).name("Kind").align(SWT.LEFT).weight(1).minWidth(5).cellToolTipProvider(toolTipProvider).buildColumn().column(model -> ((IEvent) getResource(model)).getReason()).name("Reason").align(SWT.LEFT).weight(1).minWidth(5).cellToolTipProvider(toolTipProvider).buildColumn();
}
use of org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder in project jbosstools-openshift by jbosstools.
the class NewApplicationSummaryFromTemplateDialog method createTable.
public TableViewer createTable(Composite tableContainer) {
Table table = new Table(tableContainer, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLinesVisible(true);
table.setHeaderVisible(true);
ICellToolTipProvider<IParameter> cellToolTipProvider = new ICellToolTipProvider<IParameter>() {
@Override
public String getToolTipText(IParameter object) {
return object.getDescription();
}
@Override
public int getToolTipDisplayDelayTime(IParameter object) {
return 0;
}
};
TableViewer viewer = new TableViewerBuilder(table, tableContainer).contentProvider(new ArrayContentProvider()).column(new IColumnLabelProvider<IParameter>() {
@Override
public String getValue(IParameter variable) {
return variable.getName();
}
}).cellToolTipProvider(cellToolTipProvider).name("Name").align(SWT.LEFT).weight(2).minWidth(100).buildColumn().column(new IColumnLabelProvider<IParameter>() {
@Override
public String getValue(IParameter parameter) {
return TemplateParameterViewerUtils.getValueLabel(parameter);
}
}).cellToolTipProvider(cellToolTipProvider).name("Value").align(SWT.LEFT).weight(2).minWidth(100).buildColumn().buildViewer();
viewer.setComparator(new ParameterNameViewerComparator());
viewer.addDoubleClickListener(onDoubleClick(table));
return viewer;
}
use of org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder in project jbosstools-openshift by jbosstools.
the class TemplateParametersPage method buildTableViewer.
private TableViewer buildTableViewer(Table table, Composite tableContainer, ObservableMap<String, IStatus> cellsValidationStatusObservable, TableViewerCellDecorationManager decorations) {
final TableViewerBuilder builder = new TableViewerBuilder(table, tableContainer);
TableViewer tableViewer = builder.contentProvider(new ObservableListContentProvider()).column(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Assert.isLegal(cell.getElement() instanceof IParameter, CELL_NOT_PARAMETER_ERROR);
IParameter parameter = (IParameter) cell.getElement();
String label = parameter.getName();
if (parameter.isRequired()) {
label = markRequired(label);
}
cell.setText(label);
}
private String markRequired(String label) {
return label += " *";
}
@Override
public String getToolTipText(Object object) {
Assert.isLegal(object instanceof IParameter, CELL_NOT_PARAMETER_ERROR);
return ((IParameter) object).getDescription();
}
@Override
public int getToolTipDisplayDelayTime(Object object) {
return 0;
}
}).name("Name").align(SWT.LEFT).weight(1).minWidth(180).buildColumn().column(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Assert.isLegal(cell.getElement() instanceof IParameter, CELL_NOT_PARAMETER_ERROR);
final IParameter parameter = (IParameter) cell.getElement();
String label = TemplateParameterViewerUtils.getValueLabel(parameter);
cell.setText(label);
boolean italic = ((ApplicationSourceFromTemplateModel) model).isParameterModified(parameter);
builder.applyFont(cell, italic);
IStatus validationStatus = validate(parameter);
cellsValidationStatusObservable.put(parameter.getName(), validationStatus);
decorations.toggle(!validationStatus.isOK(), cell);
}
private IStatus validate(IParameter parameter) {
if (parameter.isRequired() && StringUtils.isEmpty(parameter.getValue()) && StringUtils.isEmpty(parameter.getGeneratorName())) {
return ValidationStatus.error(NLS.bind("Parameter {0} is required, please provide a value.", parameter.getName()));
}
IStatus status = gitSourceValidator.validate(parameter);
if (!status.isOK()) {
return status;
}
return ValidationStatus.ok();
}
@Override
public String getToolTipText(Object object) {
Assert.isLegal(object instanceof IParameter, CELL_NOT_PARAMETER_ERROR);
return ((IParameter) object).getDescription();
}
@Override
public int getToolTipDisplayDelayTime(Object object) {
return 0;
}
}).name("Value").align(SWT.LEFT).weight(1).buildColumn().buildViewer();
tableViewer.setComparator(new TemplateParameterViewerUtils.ParameterNameViewerComparator());
return tableViewer;
}
use of org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder in project jbosstools-openshift by jbosstools.
the class ServicesAndRoutingPage method createTable.
protected TableViewer createTable(Composite tableContainer) {
Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableViewer viewer = new TableViewerBuilder(table, tableContainer).column("Name").align(SWT.LEFT).weight(2).minWidth(50).buildColumn().column("Service Port").align(SWT.LEFT).weight(1).minWidth(25).buildColumn().column("Pod Port").align(SWT.LEFT).weight(1).minWidth(25).buildColumn().column(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
boolean selected = ((ServicePortAdapter) element).isRoutePort();
return selected ? OpenShiftImages.CHECKED_IMG : OpenShiftImages.UNCHECKED_IMG;
}
@Override
public String getText(Object element) {
return null;
}
}).name("Used by route").align(SWT.LEFT).weight(1).buildColumn().buildViewer();
viewer.addDoubleClickListener(new EditHandler());
/*
* required because otherwise values are cached and causes the ObservableMapLabelProvider
* not to be updated because remove are not propagated.
*/
viewer.setComparer(new IElementComparer() {
@Override
public int hashCode(Object element) {
return System.identityHashCode(element);
}
@Override
public boolean equals(Object a, Object b) {
return a == b;
}
});
return viewer;
}
Aggregations