changeset 112:4d5e3d32d681

Add validation to Options UI The wizard itself is still not connected to the validation system since that breaks when the master list is empty.
author Omair Majid <omajid@redhat.com>
date Fri, 28 Feb 2014 12:06:10 -0500
parents 6369d2282c1d
children b2822596b9a0
files com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/OptionsWizard.java
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/OptionsWizard.java	Fri Feb 28 11:09:26 2014 -0500
+++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/editor/OptionsWizard.java	Fri Feb 28 12:06:10 2014 -0500
@@ -2,16 +2,17 @@
 
 import java.util.Objects;
 
+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;
-import org.eclipse.core.databinding.observable.ChangeEvent;
-import org.eclipse.core.databinding.observable.IChangeListener;
 import org.eclipse.core.databinding.observable.list.IListChangeListener;
 import org.eclipse.core.databinding.observable.list.ListChangeEvent;
 import org.eclipse.core.databinding.observable.list.WritableList;
 import org.eclipse.core.databinding.observable.map.IObservableMap;
 import org.eclipse.core.databinding.observable.set.IObservableSet;
 import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
 import org.eclipse.jface.databinding.swt.WidgetProperties;
 import org.eclipse.jface.databinding.viewers.IViewerObservableValue;
 import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
@@ -26,7 +27,6 @@
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
@@ -43,7 +43,7 @@
 /**
  * A {@link Wizard} for editing the command line options for a command.
  * <p>
- * The wizrad allows adding/editing and removing options.
+ * The wizard allows adding/editing and removing options.
  */
 public class OptionsWizard extends Wizard {
 
@@ -207,15 +207,23 @@
 
             IObservableValue longNameWidgetValue = WidgetProperties.text(SWT.Modify).observe(longName);
             IObservableValue longNameModelValue = BeanProperties.value(Option.class, "longName").observeDetail(selectedOption); //$NON-NLS-1$
-            dataBindingContext.bindValue(longNameWidgetValue, longNameModelValue);
+            UpdateValueStrategy longNameWidgetToModelUpdate = new UpdateValueStrategy();
+            longNameWidgetToModelUpdate.setBeforeSetValidator(new Validators.NonEmptyStringRequired("Long name can not be empty"));
+            Binding longNameBinding = dataBindingContext.bindValue(longNameWidgetValue, longNameModelValue, longNameWidgetToModelUpdate, null);
+            ControlDecorationSupport.create(longNameBinding, SWT.TOP | SWT.LEFT);
 
             IObservableValue shortNameWidgetValue = WidgetProperties.text(SWT.Modify).observe(shortName);
             IObservableValue shortNameModelValue = BeanProperties.value(Option.class, "shortName").observeDetail(selectedOption); //$NON-NLS-1$
-            dataBindingContext.bindValue(shortNameWidgetValue, shortNameModelValue);
+            UpdateValueStrategy shortNameWidgetToModelUpdate = new UpdateValueStrategy();
+            shortNameWidgetToModelUpdate.setConverter(new Converters.EmptyStringToNullConverter());
+            dataBindingContext.bindValue(shortNameWidgetValue, shortNameModelValue,shortNameWidgetToModelUpdate, null);
 
             IObservableValue descriptionWidgetValue = WidgetProperties.text(SWT.Modify).observe(description);
             IObservableValue descriptionModelValue = BeanProperties.value(Option.class, "description").observeDetail(selectedOption); //$NON-NLS-1$
-            dataBindingContext.bindValue(descriptionWidgetValue, descriptionModelValue);
+            UpdateValueStrategy descriptionWidgetToModelUpdate = new UpdateValueStrategy();
+            descriptionWidgetToModelUpdate.setBeforeSetValidator(new Validators.NonEmptyStringRequired("Description can not be empty"));
+            Binding descriptionBinding = dataBindingContext.bindValue(descriptionWidgetValue, descriptionModelValue, descriptionWidgetToModelUpdate, null);
+            ControlDecorationSupport.create(descriptionBinding, SWT.TOP | SWT.LEFT);
 
             IObservableValue argumentWidgetValue = WidgetProperties.text(SWT.Modify).observe(argument);
             IObservableValue argumentModelValue = BeanProperties.value(Option.class, "argument").observeDetail(selectedOption); //$NON-NLS-1$
@@ -249,6 +257,7 @@
                 }
             };
             allOptions.addListChangeListener(enableDisableRemoveButton);
+            // invoke manually during initialization to set initial state
             enableDisableRemoveButton.handleListChange(new ListChangeEvent(allOptions, null));
 
             IListChangeListener enableDisableDataWidgets = new IListChangeListener() {
@@ -270,6 +279,7 @@
                 }
             };
             allOptions.addListChangeListener(enableDisableDataWidgets);
+            // invoke manually during initialization to set initial state
             enableDisableDataWidgets.handleListChange(new ListChangeEvent(allOptions, null));
 
         }