use of org.eclipse.core.databinding.observable.value.WritableValue in project jbosstools-openshift by jbosstools.
the class BasicAuthenticationDetailView method createControls.
@Override
public Composite createControls(Composite parent, Object context, DataBindingContext dbc) {
Composite composite = setControl(new Composite(parent, SWT.None));
GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(10, 10).applyTo(composite);
// username
Label usernameLabel = new Label(composite, SWT.NONE);
usernameLabel.setText("&Username:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(usernameLabel);
this.usernameText = new Text(composite, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(usernameText);
// password
Label passwordLabel = new Label(composite, SWT.NONE);
passwordLabel.setText("&Password:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(passwordLabel);
this.passwordText = new Text(composite, SWT.BORDER | SWT.PASSWORD);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(passwordText);
this.passwordObservable = new WritableValue(null, String.class);
this.rememberPasswordObservable = new WritableValue(Boolean.FALSE, Boolean.class);
this.rememberPasswordCheckbox = new Button(composite, SWT.CHECK);
rememberPasswordCheckbox.setText("&Save password (could trigger secure storage login)");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(2, 1).grab(true, false).applyTo(rememberPasswordCheckbox);
return composite;
}
use of org.eclipse.core.databinding.observable.value.WritableValue in project jbosstools-openshift by jbosstools.
the class ResourcePayloadPage method createLocalSourceControls.
private void createLocalSourceControls(DataBindingContext dbc, Group sourceGroup) {
Label label = new Label(sourceGroup, SWT.NONE);
GridDataFactory.fillDefaults().span(3, 1).applyTo(label);
label.setText("Enter a file path (workspace or local) or a full URL.");
// local template file name
Text sourceText = new Text(sourceGroup, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(3, 1).applyTo(sourceText);
final IObservableValue source = WidgetProperties.text(SWT.Modify).observe(sourceText);
final WritableValue<IStatus> sourceStatus = new WritableValue<IStatus>(Status.OK_STATUS, IStatus.class);
final ResourceContentValidator contentValidator = new ResourceContentValidator(sourceStatus);
ValueBindingBuilder.bind(source).validatingBeforeSet(contentValidator).to(BeanProperties.value(IResourcePayloadPageModel.PROPERTY_SOURCE).observe(model)).validatingBeforeSet(contentValidator).in(dbc);
MultiValidator validator = new MultiValidator() {
@Override
protected IStatus validate() {
String sourceValue = (String) source.getValue();
if (StringUtils.isEmpty(sourceValue)) {
return ValidationStatus.cancel("You need to provide a file path or an URL");
}
return !OpenshiftUIConstants.URL_VALIDATOR.isValid(sourceValue) && !isFile(sourceValue) ? ValidationStatus.error(sourceValue + " is not a file") : ValidationStatus.ok();
}
};
dbc.addValidationStatusProvider(validator);
dbc.addValidationStatusProvider(new MultiValidator() {
@Override
protected IStatus validate() {
source.getValue();
return sourceStatus.getValue();
}
});
ControlDecorationSupport.create(validator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
// browse button
Button btnBrowseFiles = new Button(sourceGroup, SWT.NONE);
btnBrowseFiles.setText("Browse File System...");
GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).span(2, 1).grab(true, false).applyTo(btnBrowseFiles);
btnBrowseFiles.addSelectionListener(onFileSystemBrowseClicked());
// browse button
Button btnBrowseWorkspaceFiles = new Button(sourceGroup, SWT.NONE);
btnBrowseWorkspaceFiles.setText("Browse Workspace...");
GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(btnBrowseWorkspaceFiles);
btnBrowseWorkspaceFiles.addSelectionListener(onBrowseWorkspaceClicked());
}
use of org.eclipse.core.databinding.observable.value.WritableValue in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorsTest method testBasicAuthenticationValidator.
@Test
public void testBasicAuthenticationValidator() {
Connection connection1 = mockConnection(HOST1, USER1, null);
mockConnection(HOST2, USER2, null);
ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
WritableValue<String> usernameObservable = new WritableValue<String>();
WritableValue<String> urlObservable = new WritableValue<String>();
MultiValidator v = ConnectionValidatorFactory.createBasicAuthenticationValidator(pageModel, usernameObservable, urlObservable);
v.observeValidatedValue(urlObservable);
// New connection
urlObservable.setValue(HOST3);
usernameObservable.setValue(USER3);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
urlObservable.setValue(HOST2);
// Host exists, but token is different
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
usernameObservable.setValue(USER2);
// Existing not selected connection
Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
// Selected connection
urlObservable.setValue(HOST1);
usernameObservable.setValue(USER1);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
}
use of org.eclipse.core.databinding.observable.value.WritableValue in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createResourceDetails.
private void createResourceDetails(IViewerObservableValue selectedResourceTreeItem, Composite parent, DataBindingContext dbc) {
ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
ExpandableComposite expandable = new ExpandableComposite(scrolledComposite, SWT.None);
scrolledComposite.setContent(expandable);
expandable.setText("Resource Details");
expandable.setExpanded(true);
expandable.setLayout(new FillLayout());
Composite detailsContainer = new Composite(expandable, SWT.NONE);
expandable.setClient(detailsContainer);
expandable.addExpansionListener(new ExpansionAdapter() {
@Override
public void expansionStateChanged(ExpansionEvent e) {
getControl().update();
((Composite) getControl()).layout(true);
}
});
IObservableValue<IResource> selectedResource = new WritableValue<>();
ValueBindingBuilder.bind(selectedResourceTreeItem).converting(new ObservableTreeItem2ModelConverter()).to(selectedResource).notUpdatingParticipant().in(dbc);
new ResourceDetailViews(selectedResource, detailsContainer, dbc).createControls();
}
use of org.eclipse.core.databinding.observable.value.WritableValue in project jbosstools-openshift by jbosstools.
the class BuildConfigWizardPage method doCreateControls.
@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(parent);
GridLayoutFactory.fillDefaults().applyTo(parent);
Group buildConfigsGroup = new Group(parent, SWT.NONE);
buildConfigsGroup.setText("Existing Build Configs:");
GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(buildConfigsGroup);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(buildConfigsGroup);
// build configs tree
TreeViewer buildConfigsViewer = createBuildConfigsViewer(new Tree(buildConfigsGroup, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL), model, dbc);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, 200).span(1, 2).applyTo(buildConfigsViewer.getControl());
final IObservableValue selectedItem = BeanProperties.value(IBuildConfigPageModel.PROPERTY_SELECTED_ITEM).observe(model);
Binding selectedBuildConfigBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(buildConfigsViewer)).converting(new ObservableTreeItem2ModelConverter()).to(selectedItem).converting(new Model2ObservableTreeItemConverter()).in(dbc);
dbc.addValidationStatusProvider(new MultiValidator() {
@Override
protected IStatus validate() {
if (!(selectedItem.getValue() instanceof IBuildConfig)) {
return ValidationStatus.cancel("Please select the existing build config that you want to import");
} else {
return ValidationStatus.ok();
}
}
});
IObservableValue connectionObservable = BeanProperties.value(IBuildConfigPageModel.PROPERTY_CONNECTION).observe(model);
DataBindingUtils.addDisposableValueChangeListener(onConnectionChanged(buildConfigsViewer, model), connectionObservable, buildConfigsViewer.getTree());
ControlDecorationSupport.create(selectedBuildConfigBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
// refresh button
Button refreshButton = new Button(buildConfigsGroup, SWT.PUSH);
refreshButton.setText("&Refresh");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(100, SWT.DEFAULT).applyTo(refreshButton);
refreshButton.addSelectionListener(onRefresh(buildConfigsViewer, model));
// filler
Label fillerLabel = new Label(buildConfigsGroup, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, true).applyTo(fillerLabel);
// details
ExpandableComposite expandable = new ExpandableComposite(buildConfigsGroup, SWT.None);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(expandable);
expandable.setText("Build config Details");
expandable.setExpanded(true);
GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(0, 0).applyTo(expandable);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(expandable);
Composite detailsContainer = new Composite(expandable, SWT.NONE);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(detailsContainer);
IObservableValue selectedService = new WritableValue();
ValueBindingBuilder.bind(selectedItem).to(selectedService).notUpdatingParticipant().in(dbc);
new BuildConfigDetailViews(selectedService, detailsContainer, dbc).createControls();
expandable.setClient(detailsContainer);
expandable.addExpansionListener(new IExpansionListener() {
@Override
public void expansionStateChanging(ExpansionEvent e) {
}
@Override
public void expansionStateChanged(ExpansionEvent e) {
buildConfigsGroup.update();
buildConfigsGroup.layout(true);
}
});
loadBuildConfigs(model);
}
Aggregations