Search in sources :

Example 1 with TableViewerBuilder

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;
}
Also used : Table(org.eclipse.swt.widgets.Table) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) StyledString(org.eclipse.jface.viewers.StyledString) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder)

Example 2 with TableViewerBuilder

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();
}
Also used : ICellToolTipProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.ICellToolTipProvider) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) StringUtils(org.apache.commons.lang.StringUtils) ResourceKind(com.openshift.restclient.ResourceKind) SWT(org.eclipse.swt.SWT) IEvent(com.openshift.restclient.model.IEvent) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IEvent(com.openshift.restclient.model.IEvent) ICellToolTipProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.ICellToolTipProvider)

Example 3 with TableViewerBuilder

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;
}
Also used : IParameter(com.openshift.restclient.model.template.IParameter) IColumnLabelProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.IColumnLabelProvider) Table(org.eclipse.swt.widgets.Table) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ICellToolTipProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.ICellToolTipProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder) ParameterNameViewerComparator(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.TemplateParameterViewerUtils.ParameterNameViewerComparator)

Example 4 with TableViewerBuilder

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;
}
Also used : ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) IParameter(com.openshift.restclient.model.template.IParameter) IStatus(org.eclipse.core.runtime.IStatus) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Example 5 with TableViewerBuilder

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;
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Table(org.eclipse.swt.widgets.Table) IElementComparer(org.eclipse.jface.viewers.IElementComparer) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder)

Aggregations

TableViewerBuilder (org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder)9 TableViewer (org.eclipse.jface.viewers.TableViewer)7 Table (org.eclipse.swt.widgets.Table)7 IColumnLabelProvider (org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.IColumnLabelProvider)4 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)3 Viewer (org.eclipse.jface.viewers.Viewer)3 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)3 ICellToolTipProvider (org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.ICellToolTipProvider)3 IParameter (com.openshift.restclient.model.template.IParameter)2 ResourceKind (com.openshift.restclient.ResourceKind)1 IEvent (com.openshift.restclient.model.IEvent)1 IProject (com.openshift.restclient.model.IProject)1 StringUtils (org.apache.commons.lang.StringUtils)1 IStatus (org.eclipse.core.runtime.IStatus)1 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)1 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 DelegatingStyledCellLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)1 IElementComparer (org.eclipse.jface.viewers.IElementComparer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1