[jbosstools-commits] JBoss Tools SVN: r35809 - trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Oct 19 11:13:58 EDT 2011


Author: adietish
Date: 2011-10-19 11:13:58 -0400 (Wed, 19 Oct 2011)
New Revision: 35809

Modified:
   trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java
Log:


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-19 15:10:21 UTC (rev 35808)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AdapterWizardPage.java	2011-10-19 15:13:58 UTC (rev 35809)
@@ -15,6 +15,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.core.databinding.Binding;
 import org.eclipse.core.databinding.DataBindingContext;
 import org.eclipse.core.databinding.UpdateValueStrategy;
 import org.eclipse.core.databinding.beans.BeanProperties;
@@ -275,23 +276,20 @@
 		serverAdapterGroup.setLayout(fillLayout);
 		fillServerAdapterGroup(serverAdapterGroup);
 		IObservableValue runtimeSelection = WidgetProperties.singleSelectionIndex().observe(suitableRuntimes);
-		dbc.bindValue(
-				WidgetProperties.singleSelectionIndex().observe(suitableRuntimes)
+
+		IObservableValue dummyObservable = new WritableValue();
+		Binding comboSelectionBinding = dbc.bindValue(
+				dummyObservable
 				, WidgetProperties.singleSelectionIndex().observe(suitableRuntimes)
 				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)
-				, new UpdateValueStrategy().setAfterGetValidator(new IValidator() {
-					public IStatus validate(Object value) {
-						if( !serverAdapterCheckbox.getSelection())
-							return Status.OK_STATUS;
-						if( new Integer(-1).equals(value)) {
-							if( suitableRuntimes.getItems() == null || suitableRuntimes.getItems().length == 0) {
-								return ValidationStatus.error("Please add a new valid runtime."); 
-							}
-							return ValidationStatus.error("Please select a runtime"); 
-						}
-						return Status.OK_STATUS;
-					}
-				}));
+				, new UpdateValueStrategy().setAfterGetValidator(new SelectedRuntimeValidator(null)));
+
+		dbc.bindValue(
+				dummyObservable
+				, WidgetProperties.selection().observe(serverAdapterCheckbox)
+				, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)
+				, new UpdateValueStrategy().setAfterGetValidator(new SelectedRuntimeValidator(comboSelectionBinding)));
+
 		runtimeSelection.setValue(null);
 
 		return serverAdapterGroup;
@@ -519,4 +517,34 @@
 		model.getParentModel().setProperty(AdapterWizardPageModel.CREATE_SERVER, canCreateServer);
 	}
 
+	private class SelectedRuntimeValidator implements IValidator {
+
+		private Binding binding;
+
+		public SelectedRuntimeValidator(Binding binding) {
+			this.binding = binding;
+		}
+
+		public IStatus validate(Object value) {
+			if (!serverAdapterCheckbox.getSelection()) {
+				updateBinding();
+				return Status.OK_STATUS;
+			}
+			if (new Integer(-1).equals(suitableRuntimes.getSelectionIndex())) {
+				if (suitableRuntimes.getItems() == null || suitableRuntimes.getItems().length == 0) {
+					return ValidationStatus.error("Please add a new valid runtime.");
+				}
+				return ValidationStatus.error("Please select a runtime");
+			}
+			updateBinding();
+			return Status.OK_STATUS;
+		}
+
+		private void updateBinding() {
+			if (binding != null) {
+				this.binding.updateModelToTarget();
+			}
+		}
+	}
+
 }



More information about the jbosstools-commits mailing list