[jbosstools-commits] JBoss Tools SVN: r35870 - in trunk: common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Oct 20 18:25:26 EDT 2011


Author: adietish
Date: 2011-10-20 18:25:25 -0400 (Thu, 20 Oct 2011)
New Revision: 35870

Modified:
   trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java
   trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ValueBindingBuilder.java
Log:
[JBIDE-9947] switched bindings to new ValueBindingBuilder

Modified: trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java
===================================================================
--- trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java	2011-10-20 21:57:28 UTC (rev 35869)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java	2011-10-20 22:25:25 UTC (rev 35870)
@@ -16,7 +16,6 @@
 import java.util.List;
 
 import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.UpdateValueStrategy;
 import org.eclipse.core.databinding.beans.BeanProperties;
 import org.eclipse.core.databinding.observable.list.IObservableList;
 import org.eclipse.core.databinding.observable.value.IObservableValue;
@@ -62,9 +61,9 @@
 import org.eclipse.wst.server.ui.internal.wizard.WizardTaskUtil;
 import org.eclipse.wst.server.ui.wizard.WizardFragment;
 import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
-import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
 import org.jboss.tools.common.ui.databinding.DataBindingUtils;
 import org.jboss.tools.common.ui.databinding.InvertingBooleanConverter;
+import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
 import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
 import org.jboss.tools.openshift.express.client.ICartridge;
 import org.jboss.tools.openshift.express.client.OpenShiftException;
@@ -130,25 +129,23 @@
 		gitUriValueText = new Text(cloneGroup, SWT.BORDER);
 		gitUriValueText.setEditable(false);
 		// gitUriValueText.setBackground(cloneGroup.getBackground());
-		GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).grab(true, false)
-				.applyTo(gitUriValueText);
-		dbc.bindValue(
-				WidgetProperties.text(SWT.Modify).observe(gitUriValueText)
-				, BeanProperties.value(AdapterWizardPageModel.PROPERTY_GIT_URI).observe(model)
-				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)
-				, null);
-		dbc.bindValue(
-				WidgetProperties.enabled().observe(gitUriValueText)
-				, BeanProperties.value(AdapterWizardPageModel.PROPERTY_LOADING).observe(model)
-				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)
-				, new UpdateValueStrategy().setConverter(new InvertingBooleanConverter()));
+		GridDataFactory
+				.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(gitUriValueText);
+		ValueBindingBuilder
+				.bind(WidgetProperties.text(SWT.Modify).observe(gitUriValueText))
+				.notUpdating(BeanProperties.value(AdapterWizardPageModel.PROPERTY_GIT_URI).observe(model))
+				.using(dbc);
+		ValueBindingBuilder
+				.bind(WidgetProperties.enabled().observe(gitUriValueText))
+				.notUpdating(BeanProperties.value(AdapterWizardPageModel.PROPERTY_LOADING).observe(model))
+				.converting(new InvertingBooleanConverter())
+				.using(dbc);
 
 		// bind loading state to page complete
-		dbc.bindValue(
-				new WritableValue(false, Boolean.class)
-				, BeanProperties.value(AdapterWizardPageModel.PROPERTY_LOADING).observe(model)
-				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)
-				, new UpdateValueStrategy().setAfterGetValidator(new IValidator() {
+		ValueBindingBuilder
+				.bind(new WritableValue(false, Boolean.class))
+				.notUpdating(BeanProperties.value(AdapterWizardPageModel.PROPERTY_LOADING).observe(model))
+				.validatingAfterGet(new IValidator() {
 
 					@Override
 					public IStatus validate(Object value) {
@@ -158,7 +155,8 @@
 							return ValidationStatus.cancel("Loading...");
 						}
 					}
-				}));
+				})
+				.using(dbc);
 
 		Label repoPathLabel = new Label(cloneGroup, SWT.NONE);
 		GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(repoPathLabel);
@@ -176,22 +174,24 @@
 				.align(SWT.LEFT, SWT.CENTER).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(repoPathText);
 		DataBindingUtils.bindMandatoryTextField(
 				repoPathText, "Location", AdapterWizardPageModel.PROPERTY_REPO_PATH, model, dbc);
-		dbc.bindValue(
-				defaultRepoButtonSelection
-				, WidgetProperties.enabled().observe(repoPathText)
-				, new UpdateValueStrategy().setConverter(new InvertingBooleanConverter())
-				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
+		ValueBindingBuilder
+				.bind(defaultRepoButtonSelection)
+				.converting(new InvertingBooleanConverter())
+				.to(WidgetProperties.enabled().observe(repoPathText))
+				.notUpdatingParticipant()
+				.using(dbc);
 
 		Button browseRepoPathButton = new Button(cloneGroup, SWT.PUSH);
 		browseRepoPathButton.setText("Browse");
 		GridDataFactory.fillDefaults()
 				.align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(browseRepoPathButton);
 		browseRepoPathButton.addSelectionListener(onRepoPath());
-		dbc.bindValue(
-				defaultRepoButtonSelection
-				, WidgetProperties.enabled().observe(browseRepoPathButton)
-				, new UpdateValueStrategy().setConverter(new InvertingBooleanConverter())
-				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
+		ValueBindingBuilder
+				.bind(defaultRepoButtonSelection)
+				.converting(new InvertingBooleanConverter())
+				.to(WidgetProperties.enabled().observe(browseRepoPathButton))
+				.notUpdatingParticipant()
+				.using(dbc);
 
 		defaultRepoButtonSelection.setValue(true);
 
@@ -213,11 +213,12 @@
 				remoteNameText, "Remote name", AdapterWizardPageModel.PROPERTY_REMOTE_NAME, model, dbc);
 
 		IObservableValue defaultRemoteNameSelection = WidgetProperties.selection().observe(defaultRemoteNameButton);
-		dbc.bindValue(
-				defaultRemoteNameSelection
-				, WidgetProperties.enabled().observe(remoteNameText)
-				, new UpdateValueStrategy().setConverter(new InvertingBooleanConverter())
-				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
+		ValueBindingBuilder
+				.bind(defaultRemoteNameSelection)
+				.converting(new InvertingBooleanConverter())
+				.to(WidgetProperties.enabled().observe(remoteNameText))
+				.notUpdatingParticipant()
+				.using(dbc);
 		defaultRemoteNameSelection.setValue(true);
 
 		Link sshPrefsLink = new Link(cloneGroup, SWT.NONE);

Modified: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ValueBindingBuilder.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ValueBindingBuilder.java	2011-10-20 21:57:28 UTC (rev 35869)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ValueBindingBuilder.java	2011-10-20 22:25:25 UTC (rev 35870)
@@ -13,8 +13,9 @@
 import org.eclipse.core.databinding.Binding;
 import org.eclipse.core.databinding.DataBindingContext;
 import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.conversion.IConverter;
 import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.databinding.validation.IValidator;
 
 /**
  * 
@@ -39,6 +40,36 @@
 				, modelDefinition.getStrategy());
 	}
 
+	public static class TargetDefinition extends BindingParticipantDefinition<TargetDefinition> {
+
+		public TargetDefinition(IObservableValue target) {
+			super(target);
+		}
+
+		public ModelDefinition to(IObservableValue model) {
+			return new ModelDefinition(model, this);
+		}
+
+		public ModelDefinition notUpdating(IObservableValue model) {
+			notUpdatingParticipant();
+			return to(model);
+		}
+	}
+
+	public static class ModelDefinition extends BindingParticipantDefinition<ModelDefinition> {
+
+		private TargetDefinition targetDefinition;
+
+		public ModelDefinition(IObservableValue model, TargetDefinition targetDefinition) {
+			super(model);
+			this.targetDefinition = targetDefinition;
+		}
+
+		public Binding using(DataBindingContext dbc) {
+			return bind(targetDefinition, this, dbc);
+		}
+	}
+	
 	private abstract static class BindingParticipantDefinition<PARTICIPANT> {
 
 		private IObservableValue observable;
@@ -48,7 +79,7 @@
 			this.observable = observable;
 		}
 
-		public PARTICIPANT withoutUpdate() {
+		public PARTICIPANT notUpdatingParticipant() {
 			return withStrategy(new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
 		}
 
@@ -58,37 +89,48 @@
 			return (PARTICIPANT) this;
 		}
 		
-		public IObservableValue getObservable() {
-			return observable;
+		@SuppressWarnings("unchecked")
+		public PARTICIPANT validatingAfterGet(IValidator validator) {
+			ensureHasStrategy();
+			strategy.setAfterGetValidator(validator);
+			return (PARTICIPANT) this;
 		}
 
-		public UpdateValueStrategy getStrategy() {
-			return strategy;
+		@SuppressWarnings("unchecked")
+		public PARTICIPANT validatingAfterConvert(IValidator validator) {
+			ensureHasStrategy();
+			strategy.setAfterConvertValidator(validator);
+			return (PARTICIPANT) this;
 		}
-	}
 
-	public static class TargetDefinition extends BindingParticipantDefinition<TargetDefinition> {
-
-		public TargetDefinition(IObservableValue target) {
-			super(target);
+		@SuppressWarnings("unchecked")
+		public PARTICIPANT validatingBeforeSet(IValidator validator) {
+			ensureHasStrategy();
+			strategy.setBeforeSetValidator(validator);
+			return (PARTICIPANT) this;
 		}
 
-		public ModelDefinition to(IObservableValue model) {
-			return new ModelDefinition(model, this);
+		@SuppressWarnings("unchecked")
+		public PARTICIPANT converting(IConverter converter) {
+			ensureHasStrategy();
+			strategy.setConverter(converter);
+			return (PARTICIPANT) this;
 		}
-	}
 
-	public static class ModelDefinition extends BindingParticipantDefinition<ModelDefinition> {
-
-		private TargetDefinition targetDefinition;
-
-		public ModelDefinition(IObservableValue model, TargetDefinition targetDefinition) {
-			super(model);
-			this.targetDefinition = targetDefinition;
+		private UpdateValueStrategy ensureHasStrategy() {
+			if (strategy == null) {
+				this.strategy = new UpdateValueStrategy();
+			}
+			return strategy;
 		}
+		
+		IObservableValue getObservable() {
+			return observable;
+		}
 
-		public Binding using(DataBindingContext dbc) {
-			return bind(targetDefinition, this, dbc);
+		UpdateValueStrategy getStrategy() {
+			return strategy;
 		}
 	}
+
 }



More information about the jbosstools-commits mailing list