Search in sources :

Example 1 with TableViewerCellDecorationManager

use of org.jboss.tools.openshift.internal.common.ui.utils.TableViewerCellDecorationManager in project jbosstools-openshift by jbosstools.

the class TemplateParametersPage method createTable.

public TableViewer createTable(final Composite tableContainer, IObservableList<IParameter> parametersObservable, DataBindingContext dbc) {
    final Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    Image decorationImage = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();
    final ObservableMap<String, IStatus> cellsValidationStatusObservable = new WritableMap<>(String.class, IStatus.class);
    final TableViewerCellDecorationManager decorations = new TableViewerCellDecorationManager(decorationImage, table);
    DataBindingUtils.addDisposableListChangeListener(onParametersChanged(decorations, cellsValidationStatusObservable), parametersObservable, table);
    TableViewer tableViewer = buildTableViewer(table, tableContainer, cellsValidationStatusObservable, decorations);
    // cells validity
    dbc.addValidationStatusProvider(new MultiValidator() {

        @Override
        protected IStatus validate() {
            for (Iterator<IStatus> iterator = (Iterator<IStatus>) cellsValidationStatusObservable.values().iterator(); iterator.hasNext(); ) {
                IStatus cellValidationStatus = iterator.next();
                if (cellValidationStatus != null && !cellValidationStatus.isOK()) {
                    return cellValidationStatus;
                }
            }
            return ValidationStatus.ok();
        }
    });
    return tableViewer;
}
Also used : TableViewerCellDecorationManager(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerCellDecorationManager) IStatus(org.eclipse.core.runtime.IStatus) Table(org.eclipse.swt.widgets.Table) WritableMap(org.eclipse.core.databinding.observable.map.WritableMap) Iterator(java.util.Iterator) Image(org.eclipse.swt.graphics.Image) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

Iterator (java.util.Iterator)1 WritableMap (org.eclipse.core.databinding.observable.map.WritableMap)1 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)1 IStatus (org.eclipse.core.runtime.IStatus)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Image (org.eclipse.swt.graphics.Image)1 Table (org.eclipse.swt.widgets.Table)1 TableViewerCellDecorationManager (org.jboss.tools.openshift.internal.common.ui.utils.TableViewerCellDecorationManager)1