Search in sources :

Example 6 with IParameter

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

the class ApplicationSourceFromTemplateModelTest method givenTheTemplateHasParameters.

private Map<String, IParameter> givenTheTemplateHasParameters() {
    IParameter param = mock(IParameter.class);
    when(param.getName()).thenReturn("foo");
    when(param.clone()).thenReturn(param);
    Map<String, IParameter> parameters = new HashMap<>();
    parameters.put(param.getName(), param);
    when(template.getParameters()).thenReturn(parameters);
    return parameters;
}
Also used : IParameter(com.openshift.restclient.model.template.IParameter) HashMap(java.util.HashMap)

Example 7 with IParameter

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

the class ApplicationSourceFromTemplateModelTest method mockParameter.

private IParameter mockParameter(String name, String value) {
    IParameter parameter = mock(IParameter.class);
    doReturn(name).when(parameter).getName();
    doReturn(value).when(parameter).getValue();
    return parameter;
}
Also used : IParameter(com.openshift.restclient.model.template.IParameter)

Example 8 with IParameter

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

the class ApplicationSourceFromTemplateModelTest method resetParameterShouldSetTheOriginalValue.

@Test
public void resetParameterShouldSetTheOriginalValue() {
    IParameter param = mock(IParameter.class);
    when(param.getName()).thenReturn("foo");
    when(param.getValue()).thenReturn("abc");
    when(param.clone()).thenReturn(param);
    IParameter other = mock(IParameter.class);
    when(other.getName()).thenReturn("foo");
    when(other.getValue()).thenReturn("xyz");
    model.setParameters(Arrays.asList(new IParameter[] { param }));
    model.resetParameter(other);
    verify(other).setValue("abc");
}
Also used : IParameter(com.openshift.restclient.model.template.IParameter) Test(org.junit.Test)

Example 9 with IParameter

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

the class TemplateParametersPage method doCreateControls.

@Override
@SuppressWarnings("unchecked")
protected void doCreateControls(Composite container, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(container);
    // parameters table
    Composite tableContainer = new Composite(container, SWT.NONE);
    IObservableList<IParameter> parametersObservable = BeanProperties.list(ITemplateParametersPageModel.PROPERTY_PARAMETERS).observe(model);
    this.viewer = createTable(tableContainer, parametersObservable, dbc);
    GridDataFactory.fillDefaults().span(1, 5).align(SWT.FILL, SWT.FILL).grab(true, true).hint(500, 300).applyTo(tableContainer);
    viewer.setInput(parametersObservable);
    IObservableValue<IParameter> selectedParameter = BeanProperties.value(ITemplateParametersPageModel.PROPERTY_SELECTED_PARAMETER).observe(model);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(viewer)).to(selectedParameter).in(dbc);
    viewer.addDoubleClickListener(onDoubleClick());
    // edit button
    Button editExistingButton = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(editExistingButton);
    editExistingButton.setText("Edit...");
    UIUtils.setDefaultButtonWidth(editExistingButton);
    editExistingButton.addSelectionListener(onEdit());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(editExistingButton)).notUpdatingParticipant().to(selectedParameter).converting(new IsNotNull2BooleanConverter()).in(dbc);
    // reset button
    Button resetButton = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(resetButton);
    resetButton.setText("Reset");
    UIUtils.setDefaultButtonWidth(resetButton);
    resetButton.addSelectionListener(onReset());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(resetButton)).notUpdatingParticipant().to(selectedParameter).converting(new IsNotNull2BooleanConverter() {

        @Override
        public Object convert(Object fromObject) {
            return fromObject instanceof IParameter && ((ApplicationSourceFromTemplateModel) model).isParameterModified((IParameter) fromObject);
        }
    }).in(dbc);
    // reset all button
    Button resetAllButton = new Button(container, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(resetAllButton);
    resetAllButton.setText("Reset All");
    UIUtils.setDefaultButtonWidth(resetAllButton);
    resetAllButton.addSelectionListener(onResetAll());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(resetAllButton)).notUpdatingParticipant().to(selectedParameter).converting(new IsNotNull2BooleanConverter() {

        @Override
        public Object convert(Object fromObject) {
            return model.getParameters().stream().anyMatch(p -> ((ApplicationSourceFromTemplateModel) model).isParameterModified(p));
        }
    }).in(dbc);
    // required explanation
    Label requiredExplanationLabel = new Label(container, SWT.None);
    requiredExplanationLabel.setText("* = value required, click the 'Edit...' button or double-click on a value to edit it.");
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(requiredExplanationLabel);
    // selected parameter details
    final Group detailsContainer = new Group(container, SWT.NONE);
    detailsContainer.setText("Details");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(2, 1).hint(SWT.DEFAULT, 106).applyTo(detailsContainer);
    new TemplateParameterDetailViews(selectedParameter, detailsContainer, dbc).createControls();
    ((ApplicationSourceFromTemplateModel) model).addPropertyChangeListener(evt -> {
        if (ApplicationSourceFromTemplateModel.PROPERTY_MODIFIED_PARAMETER.equals(evt.getPropertyName())) {
            viewer.refresh(evt.getNewValue());
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) IParameter(com.openshift.restclient.model.template.IParameter) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter)

Example 10 with IParameter

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

the class ApplicationSourceFromTemplateModel method updateParameterValue.

@Override
public void updateParameterValue(IParameter param, String value) {
    param.setValue(value);
    firePropertyChange(PROPERTY_MODIFIED_PARAMETER, null, param);
    // Let's flip the selection to cause refresh of the state of buttons.
    // Otherwise, we would have to introduce more properties and keep there state.
    IParameter s = selectedParameter;
    setSelectedParameter(null);
    setSelectedParameter(s);
}
Also used : IParameter(com.openshift.restclient.model.template.IParameter)

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