use of org.eclipse.core.databinding.Binding in project jbosstools-openshift by jbosstools.
the class KeyValueWizardPage method doCreateControls.
@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);
Group group = new Group(parent, SWT.NONE);
group.setText(model.getGroupLabel());
group.setLayout(new GridLayout());
GridDataFactory.fillDefaults().hint(KEYVALUE_GROUP_WIDTH, SWT.DEFAULT).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(group);
Composite composite = new Composite(group, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(composite);
GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(composite);
Label nameLabel = new Label(composite, SWT.NONE);
// $NON-NLS-1$
nameLabel.setText(model.getKeyLabel() + ":");
if (model.getKeyDescription() != null) {
nameLabel.setToolTipText(model.getKeyDescription());
}
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(nameLabel);
Text keyText = new Text(composite, SWT.BORDER);
keyText.setEditable(model.isKeyEditable());
IObservableValue<String> keyTextObservable = WidgetProperties.text(SWT.Modify).observe(keyText);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(keyText);
Binding keyBinding = ValueBindingBuilder.bind(keyTextObservable).validatingAfterConvert(model.getKeyAfterConvertValidator()).to(BeanProperties.value(IKeyValueWizardModel.PROPERTY_KEY).observe(model)).in(dbc);
ControlDecorationSupport.create(keyBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
Label valueLabel = new Label(composite, SWT.NONE);
// $NON-NLS-1$
valueLabel.setText(model.getValueLabel() + ":");
if (model.getValueDescription() != null) {
valueLabel.setToolTipText(model.getValueDescription());
}
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(valueLabel);
Text valueText = new Text(composite, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(valueText);
IObservableValue<String> valueTextObservable = WidgetProperties.text(SWT.Modify).observe(valueText);
Binding valeuBinding = ValueBindingBuilder.bind(valueTextObservable).validatingAfterConvert(model.getValueAfterConvertValidator()).to(BeanProperties.value(IKeyValueWizardModel.PROPERTY_VALUE).observe(model)).in(dbc);
ControlDecorationSupport.create(valeuBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
if (!StringUtils.isEmpty(initialKey)) {
DataChangedValidator validator = new DataChangedValidator(keyTextObservable, valueTextObservable);
dbc.addValidationStatusProvider(validator);
}
initFocus(keyText, valueText);
}
use of org.eclipse.core.databinding.Binding in project jbosstools-openshift by jbosstools.
the class DeployImagePage method createProjectControl.
private void createProjectControl(Composite parent, DataBindingContext dbc) {
Label lblProject = new Label(parent, SWT.NONE);
lblProject.setText("OpenShift Project: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblProject);
StructuredViewer cmboProject = new ComboViewer(parent);
GridDataFactory.fillDefaults().span(NUM_COLUMS - 2, 1).applyTo(cmboProject.getControl());
final OpenShiftExplorerLabelProvider labelProvider = new OpenShiftExplorerLabelProvider();
cmboProject.setContentProvider(new ObservableListContentProvider());
cmboProject.setLabelProvider(labelProvider);
cmboProject.setInput(BeanProperties.list(IDeployImagePageModel.PROPERTY_PROJECTS).observe(model));
ProjectViewerComparator comparator = new ProjectViewerComparator(labelProvider);
cmboProject.setComparator(comparator);
model.setProjectsComparator(comparator.asProjectComparator());
IObservableValue<IProject> projectObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_PROJECT).observe(model);
ProjectStatusProvider validator = new ProjectStatusProvider(projectObservable);
IObservableValue selectedProjectObservable = ViewerProperties.singleSelection().observe(cmboProject);
Binding selectedProjectBinding = ValueBindingBuilder.bind(selectedProjectObservable).converting(new ObservableTreeItem2ModelConverter(IProject.class)).validatingAfterConvert(validator).to(projectObservable).in(dbc);
ControlDecorationSupport.create(selectedProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
Button newProjectButton = new Button(parent, SWT.PUSH);
newProjectButton.setText("New...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(newProjectButton);
UIUtils.setDefaultButtonWidth(newProjectButton);
newProjectButton.addSelectionListener(onNewProjectClicked());
dbc.addValidationStatusProvider(validator);
cmboProject.getControl().forceFocus();
}
use of org.eclipse.core.databinding.Binding in project jbosstools-openshift by jbosstools.
the class AdvancedConnectionEditor method createControls.
@SuppressWarnings("unchecked")
@Override
public Composite createControls(Composite parent, Object context, DataBindingContext dbc) {
this.pageModel = (ConnectionWizardPageModel) context;
this.selectedConnection = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION).observe(pageModel);
this.model = new AdvancedConnectionEditorModel();
Composite composite = setControl(new Composite(parent, SWT.None));
GridLayoutFactory.fillDefaults().applyTo(composite);
DialogAdvancedPart part = new DialogAdvancedPart() {
@Override
protected void createAdvancedContent(Composite advancedComposite) {
Label lblRegistry = new Label(advancedComposite, SWT.NONE);
lblRegistry.setText("Image Registry URL:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblRegistry);
Text txtRegistry = new Text(advancedComposite, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(txtRegistry);
Button registryDiscover = new Button(advancedComposite, SWT.PUSH);
registryDiscover.setText("Discover...");
registryDiscover.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
discoverRegistryPressed(registryDiscover.getShell());
}
});
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(registryDiscover);
UIUtils.setDefaultButtonWidth(registryDiscover);
registryURLObservable = WidgetProperties.text(SWT.Modify).observeDelayed(DELAY, txtRegistry);
Binding registryURLBinding = ValueBindingBuilder.bind(registryURLObservable).validatingAfterConvert(new URLValidator(VALIDATOR_URL_TYPE, true)).converting(new TrimTrailingSlashConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_REGISTRY_URL).observe(model)).in(dbc);
ControlDecorationSupport.create(registryURLBinding, SWT.LEFT | SWT.TOP);
Label lblNamespace = new Label(advancedComposite, SWT.NONE);
lblNamespace.setText("Cluster namespace:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblNamespace);
Text txtClusterNamespace = new Text(advancedComposite, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(txtClusterNamespace);
clusterNamespaceObservable = WidgetProperties.text(SWT.Modify).observeDelayed(DELAY, txtClusterNamespace);
ValueBindingBuilder.bind(clusterNamespaceObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_CLUSTER_NAMESPACE).observe(model)).in(dbc);
Link ocWorkspace = new Link(advancedComposite, SWT.PUSH);
ocWorkspace.setText("<a>Workspace OC Settings</a>");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(ocWorkspace);
// Override OC location widgets
Button overrideOC = new Button(advancedComposite, SWT.CHECK);
overrideOC.setText("Override 'oc' location: ");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblRegistry);
IObservableValue<Boolean> overrideOCObservable = WidgetProperties.selection().observe(overrideOC);
ValueBindingBuilder.bind(overrideOCObservable).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_OC_OVERRIDE).observe(model)).in(dbc);
final Text ocText = new Text(advancedComposite, SWT.SINGLE | SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(ocText);
IObservableValue<String> ocLocationObservable = WidgetProperties.text(SWT.Modify).observe(ocText);
Binding ocLocationBinding = ValueBindingBuilder.bind(ocLocationObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_OC_OVERRIDE_LOCATION).observe(model)).in(dbc);
overrideOCObservable.addValueChangeListener(new IValueChangeListener<Boolean>() {
@Override
public void handleValueChange(ValueChangeEvent<? extends Boolean> event) {
updateOcObservables();
}
});
ocLocationBinding.getValidationStatus().addValueChangeListener(new IValueChangeListener<IStatus>() {
@Override
public void handleValueChange(ValueChangeEvent<? extends IStatus> event) {
updateOcObservables();
}
});
ValueBindingBuilder.bind(overrideOCObservable).to(WidgetProperties.enabled().observe(ocText)).notUpdatingParticipant().in(dbc);
Button ocBrowse = new Button(advancedComposite, SWT.PUSH);
ocBrowse.setText("Browse...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(ocBrowse);
UIUtils.setDefaultButtonWidth(ocBrowse);
ocWorkspace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
PreferenceDialog pd = PreferencesUtil.createPreferenceDialogOn(null, IOpenShiftCoreConstants.OPEN_SHIFT_PREFERENCE_PAGE_ID, new String[] {}, null);
pd.open();
if (!overrideOC.getSelection()) {
String ocLoc = OpenShiftCorePreferences.INSTANCE.getOCBinaryLocation();
String nullsafe = ocLoc == null ? "" : ocLoc;
ocText.setText(nullsafe);
}
updateOcObservables();
}
});
// Validation here is done via a listener rather than dbc validators
// because dbc validators will validate in the UI thread, but validation
// of this field requires a background job.
ocBrowse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(ocBrowse.getShell());
fd.setText(ocText.getText());
IPath p = new Path(ocText.getText());
if (p.segmentCount() > 1) {
fd.setFilterPath(p.removeLastSegments(1).toOSString());
}
String result = fd.open();
if (result != null) {
ocLocationObservable.setValue(result);
}
}
});
ValueBindingBuilder.bind(overrideOCObservable).to(WidgetProperties.enabled().observe(ocBrowse)).notUpdatingParticipant().in(dbc);
ValidationStatusProvider ocValidator = new MultiValidator() {
public IObservableList getTargets() {
WritableList targets = new WritableList();
targets.add(ocLocationObservable);
targets.add(ocLocationValidity);
targets.add(ocVersionValidity);
return targets;
}
@Override
protected IStatus validate() {
// access all observables that the framework should listen to
IStatus ocLocationStatus = ocLocationValidity.getValue();
IStatus ocVersionStatus = ocVersionValidity.getValue();
IStatus status;
if (!ocLocationStatus.isOK()) {
status = ocLocationStatus;
} else {
status = ocVersionStatus;
}
return status;
}
};
dbc.addValidationStatusProvider(ocValidator);
ControlDecorationSupport.create(ocValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
}
protected GridLayoutFactory adjustAdvancedCompositeLayout(GridLayoutFactory gridLayoutFactory) {
return gridLayoutFactory.numColumns(3);
}
};
part.createAdvancedGroup(composite, 1);
this.connectionAdvancedPropertiesProvider = new ConnectionAdvancedPropertiesProvider();
updateOcObservables();
return composite;
}
use of org.eclipse.core.databinding.Binding in project jbosstools-openshift by jbosstools.
the class BuildConfigPage method createSourceControls.
@SuppressWarnings({ "unchecked" })
private void createSourceControls(Composite root, DataBindingContext dbc) {
Composite parent = new Composite(root, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(parent);
GridLayoutFactory.fillDefaults().numColumns(3).applyTo(parent);
// url
Label gitUrlLabel = new Label(parent, SWT.NONE);
gitUrlLabel.setText("Git Repository URL:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(gitUrlLabel);
final Text gitUrlText = new Text(parent, SWT.BORDER);
gitUrlText.setToolTipText("The URL to the Git repository.");
// TODO add 'try it' link here
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(gitUrlText);
Binding gitUrlBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observeDelayed(500, gitUrlText)).validatingAfterConvert(new IValidator() {
@Override
public IStatus validate(Object value) {
if (UrlUtils.isValid((String) value)) {
return Status.OK_STATUS;
}
return ValidationStatus.error("A valid URL to a Git repository is required");
}
}).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_GIT_REPOSITORY_URL).observe(model)).in(dbc);
ControlDecorationSupport.create(gitUrlBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
// reference
Label gitReferenceLabel = new Label(parent, SWT.NONE);
gitReferenceLabel.setText("Git Reference:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(gitReferenceLabel);
gitReferenceLabel.setToolTipText("Optional branch, tag, or commit.");
final Text gitReferenceText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(gitReferenceText);
IObservableValue gitReferenceTextObservable = WidgetProperties.text(SWT.Modify).observe(gitReferenceText);
GitReferenceValidator validator = new GitReferenceValidator(gitReferenceTextObservable);
Binding gitReferenceBinding = ValueBindingBuilder.bind(gitReferenceTextObservable).validatingAfterConvert(validator).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_GIT_REFERENCE).observe(model)).in(dbc);
dbc.addValidationStatusProvider(validator);
ControlDecorationSupport.create(gitReferenceBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
// context dir
Label contextDirLabel = new Label(parent, SWT.NONE);
contextDirLabel.setText("Context Directory:");
contextDirLabel.setToolTipText("Optional subdirectory for the application source code, used as the context directory for the build.");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(contextDirLabel);
final Text contextDirText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(contextDirText);
ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(contextDirText)).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_CONTEXT_DIR).observe(model)).in(dbc);
}
use of org.eclipse.core.databinding.Binding in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createSourcePathControls.
@SuppressWarnings("unchecked")
private void createSourcePathControls(Composite parent, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
Label sourcePathLabel = new Label(parent, SWT.NONE);
sourcePathLabel.setText("Source Path: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(sourcePathLabel);
Text sourcePathText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(sourcePathText);
Binding sourcePathBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(sourcePathText)).validatingAfterConvert(new IValidator() {
@Override
public IStatus validate(Object value) {
String path = (String) value;
if (StringUtils.isEmpty(path)) {
return ValidationStatus.cancel("Please provide a local path to deploy from.");
}
String provideValidPathMessage = "Please provide a valid local path to deploy from.";
try {
path = VariablesHelper.replaceVariables(path);
} catch (OpenShiftCoreException e) {
String message = org.apache.commons.lang.StringUtils.substringAfter(e.getMessage(), "Exception:");
return ValidationStatus.error(provideValidPathMessage + "\nError: " + message);
}
if (!isReadableFile(path)) {
return ValidationStatus.error(provideValidPathMessage);
}
return ValidationStatus.ok();
}
private boolean isReadableFile(String path) {
return new File(path).canRead();
}
}).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_SOURCE_PATH).observe(model)).in(dbc);
ControlDecorationSupport.create(sourcePathBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
Button browseSourceButton = new Button(parent, SWT.PUSH);
browseSourceButton.setText("Browse...");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(10, SWT.DEFAULT).applyTo(browseSourceButton);
browseSourceButton.addSelectionListener(onBrowseSource(browseSourceButton.getShell()));
Button browseWorkspaceSourceButton = new Button(parent, SWT.PUSH | SWT.READ_ONLY);
browseWorkspaceSourceButton.setText("Workspace...");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(browseWorkspaceSourceButton);
browseWorkspaceSourceButton.addSelectionListener(onBrowseWorkspace(browseWorkspaceSourceButton.getShell()));
UIUtils.setEqualButtonWidth(browseSourceButton, browseWorkspaceSourceButton);
}
Aggregations