[jbosstools-commits] JBoss Tools SVN: r35842 - 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 09:38:27 EDT 2011


Author: adietish
Date: 2011-10-20 09:38:27 -0400 (Thu, 20 Oct 2011)
New Revision: 35842

Added:
   trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ValueBindingBuilder.java
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/AdapterWizardPageModel.java
Log:
[JBIDE-9947] added binding builder to have nicer binding semantics

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 13:03:18 UTC (rev 35841)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java	2011-10-20 13:38:27 UTC (rev 35842)
@@ -62,6 +62,7 @@
 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.ssh.SshPrivateKeysPreferences;
@@ -72,7 +73,7 @@
 /**
  * @author André Dietisheim
  * @author Rob Stryker
- *
+ * 
  */
 public class AdapterWizardPage extends AbstractOpenShiftWizardPage implements IWizardPage, PropertyChangeListener {
 	private Text gitUriValueText;
@@ -322,11 +323,11 @@
 		domainLabel.setText("Host");
 		domainValueLabel = new Label(c, SWT.NONE);
 		DataBindingContext dbc = getDatabindingContext();
-		dbc.bindValue(
-				WidgetProperties.text().observe(domainValueLabel)
-				, BeanProperties.value(AdapterWizardPageModel.PROPERTY_APPLICATION_URL).observe(model)
-				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)
-				, null);
+		ValueBindingBuilder
+				.bind(WidgetProperties.text().observe(domainValueLabel))
+				.withoutUpdate()
+				.to(BeanProperties.value(AdapterWizardPageModel.PROPERTY_APPLICATION_URL).observe(model))
+				.using(dbc);
 		// appLabel = new Label(c, SWT.NONE);
 		Label modeLabel = new Label(c, SWT.NONE);
 		modeLabel.setText("Mode");
@@ -375,12 +376,14 @@
 		SelectedRuntimeValidator selectedRuntimeValidator = new SelectedRuntimeValidator();
 		dbc.addValidationStatusProvider(selectedRuntimeValidator);
 
-//		ControlDecorationSupport.create(selectedRuntimeValidator, SWT.TOP | SWT.LEFT);
+		// ControlDecorationSupport.create(selectedRuntimeValidator, SWT.TOP |
+		// SWT.LEFT);
 	}
 
 	private void updateSelectedRuntimeDelegate() {
 		if (!(new Integer(-1).equals(selectedRuntimeObservable.getValue()))) {
-			String selectedRuntimeName = (String) suitableRuntimesObservable.get((Integer) selectedRuntimeObservable.getValue());
+			String selectedRuntimeName = (String) suitableRuntimesObservable.get((Integer) selectedRuntimeObservable
+					.getValue());
 			runtimeDelegate = ServerCore.findRuntime(selectedRuntimeName);
 		} else {
 			runtimeDelegate = null;
@@ -433,7 +436,7 @@
 			selectedRuntimeObservable.setValue(0);
 			updateSelectedRuntimeDelegate();
 		}
-		
+
 		IRuntimeType type = getValidRuntimeType();
 		addRuntimeLink.setEnabled(type != null);
 		modeValueLabel.setText("Source");
@@ -462,7 +465,7 @@
 			IRuntime[] runtimes = getRuntimesOfType(type.getId());
 			fillRuntimeCombo(runtimes);
 		} else {
-//			suitableRuntimesCombo.setItems(new String[0]);
+			// suitableRuntimesCombo.setItems(new String[0]);
 			selectedRuntimeObservable.setValue(0);
 		}
 	}

Modified: trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java
===================================================================
--- trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java	2011-10-20 13:03:18 UTC (rev 35841)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPageModel.java	2011-10-20 13:38:27 UTC (rev 35842)
@@ -38,8 +38,6 @@
 	public static final String SERVER_TYPE = "serverType";
 
 	private ImportProjectWizardModel wizardModel;
-//	private String gitUri;
-//	private String applicationUrl;
 	private boolean loading;
 
 	public AdapterWizardPageModel(ImportProjectWizardModel wizardModel) {
@@ -49,7 +47,7 @@
 
 	public void loadGitUri() throws OpenShiftException {
 		setLoading(true);
-		setGitUri(null);
+		setGitUri("Loading...");
 		setGitUri(getGitUri());
 		setLoading(false);
 	}
@@ -68,7 +66,7 @@
 
 	public void loadApplicationUrl() throws OpenShiftException {
 		setLoading(true);
-		setApplicationUrl(null);
+		setApplicationUrl("Loading...");
 		setApplicationUrl(getApplicationUrl());
 		setLoading(false);
 	}

Added: 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	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ValueBindingBuilder.java	2011-10-20 13:38:27 UTC (rev 35842)
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui.databinding;
+
+import org.eclipse.core.databinding.Binding;
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.runtime.Assert;
+
+/**
+ * 
+ * A builder that offers a nice(r) semantic to build bindings.
+ * 
+ * @author André Dietisheim
+ * @see DataBindingContext#bindValue(IObservableValue, IObservableValue)
+ * 
+ */
+public class ValueBindingBuilder {
+
+	public static TargetDefinition bind(IObservableValue target) {
+		return new TargetDefinition(target);
+	}
+
+	private static Binding bind(TargetDefinition targetDefinition, ModelDefinition modelDefinition,
+			DataBindingContext dbc) {
+		return dbc.bindValue(
+				targetDefinition.getObservable()
+				, modelDefinition.getObservable()
+				, targetDefinition.getStrategy()
+				, modelDefinition.getStrategy());
+	}
+
+	private abstract static class BindingParticipantDefinition<PARTICIPANT> {
+
+		private IObservableValue observable;
+		private UpdateValueStrategy strategy;
+
+		public BindingParticipantDefinition(IObservableValue observable) {
+			this.observable = observable;
+		}
+
+		public PARTICIPANT withoutUpdate() {
+			return withStrategy(new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
+		}
+
+		@SuppressWarnings("unchecked")
+		public PARTICIPANT withStrategy(UpdateValueStrategy strategy) {
+			this.strategy = strategy;
+			return (PARTICIPANT) this;
+		}
+		
+		protected void assertObservable(String message) {
+			Assert.isLegal(this.observable != null, message);
+		}
+
+		public IObservableValue getObservable() {
+			return observable;
+		}
+
+		public UpdateValueStrategy getStrategy() {
+			return strategy;
+		}
+	}
+
+	public static class TargetDefinition extends BindingParticipantDefinition<TargetDefinition> {
+
+		public TargetDefinition(IObservableValue target) {
+			super(target);
+		}
+
+		public ModelDefinition to(IObservableValue model) {
+			assertObservable("You have to set the target first. call #bind(target).");
+			return new ModelDefinition(model, this);
+		}
+
+	}
+
+	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);
+		}
+	}
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/ValueBindingBuilder.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list