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;
}
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;
}
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");
}
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());
}
});
}
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);
}
Aggregations