Search in sources :

Example 1 with IParameter

use of com.openshift.restclient.model.template.IParameter in project jbosstools-openshift by jbosstools.

the class ApplicationSourceFromTemplateModelTest method updateParameterValueShouldUpdateTheParameterValue.

@Test
public void updateParameterValueShouldUpdateTheParameterValue() {
    IParameter param = mock(IParameter.class);
    model.updateParameterValue(param, "abc123");
    verify(param).setValue(eq("abc123"));
}
Also used : IParameter(com.openshift.restclient.model.template.IParameter) Test(org.junit.Test)

Example 2 with IParameter

use of com.openshift.restclient.model.template.IParameter in project jbosstools-openshift by jbosstools.

the class NewApplicationSummaryFromTemplateDialog method onDoubleClick.

private IDoubleClickListener onDoubleClick(final Control control) {
    return new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IParameter param = (IParameter) selection.getFirstElement();
            if (param != null) {
                String text = param.getValue();
                if (StringUtils.isNotBlank(text)) {
                    String notification = param.getName() + " value copied to clipboard";
                    copyToClipBoard(control, text, notification);
                }
            }
        }
    };
}
Also used : IParameter(com.openshift.restclient.model.template.IParameter) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with IParameter

use of com.openshift.restclient.model.template.IParameter 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 IParameter

use of com.openshift.restclient.model.template.IParameter 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 IParameter

use of com.openshift.restclient.model.template.IParameter in project jbosstools-openshift by jbosstools.

the class ResourceDetailsLabelProviderTest method init.

@BeforeClass
public static void init() {
    IParameter p1 = mock(IParameter.class);
    when(p1.getValue()).thenReturn("Dmitrii");
    IParameter p2 = mock(IParameter.class);
    when(p2.getValue()).thenReturn("Bocharov");
    templateParameters = new HashMap<>();
    templateParameters.put("name", p1);
    templateParameters.put("surname", p2);
    labelsProvider = new ResourceDetailsLabelProvider(templateParameters);
}
Also used : IParameter(com.openshift.restclient.model.template.IParameter) ResourceDetailsLabelProvider(org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsLabelProvider) BeforeClass(org.junit.BeforeClass)

Aggregations

IParameter (com.openshift.restclient.model.template.IParameter)10 TableViewer (org.eclipse.jface.viewers.TableViewer)2 TableViewerBuilder (org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 IStatus (org.eclipse.core.runtime.IStatus)1 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ViewerCell (org.eclipse.jface.viewers.ViewerCell)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Table (org.eclipse.swt.widgets.Table)1 IsNotNull2BooleanConverter (org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)1 ICellToolTipProvider (org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.ICellToolTipProvider)1