summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2013-08-09 10:34:06 (EDT)
committerJuergen Haug2013-08-14 12:46:08 (EDT)
commit15e669f38a57d9e7908e46b70716e64adb129b90 (patch)
treed70ddbade57d4c5564f8cbfa56ff8f621b3adbfc
parente824f11e77181092b53d6393eb2ef9d7af058fb4 (diff)
downloadorg.eclipse.etrice-15e669f38a57d9e7908e46b70716e64adb129b90.zip
org.eclipse.etrice-15e669f38a57d9e7908e46b70716e64adb129b90.tar.gz
org.eclipse.etrice-15e669f38a57d9e7908e46b70716e64adb129b90.tar.bz2
[ui] multi validation support in property dialog + Bug 412389 refs/changes/22/15422/2
-rw-r--r--plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF7
-rw-r--r--plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/AbstractPropertyDialog.java204
-rw-r--r--plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/MultiValidator2.java111
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java84
5 files changed, 282 insertions, 128 deletions
diff --git a/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF
index c111a62..be6b5c3 100644
--- a/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF
@@ -7,8 +7,6 @@ Bundle-Vendor: Eclipse eTrice (Incubation)
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.4.0",
org.eclipse.core.databinding;bundle-version="1.3.100",
- org.eclipse.core.databinding.beans;bundle-version="1.2.100",
- org.eclipse.jface.databinding;bundle-version="1.4.0",
org.eclipse.emf.transaction;bundle-version="1.4.0",
org.eclipse.graphiti;bundle-version="0.8.0",
org.eclipse.ui.ide;bundle-version="3.6.0",
@@ -16,7 +14,10 @@ Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.4.0",
org.eclipse.gef;bundle-version="3.6.1",
org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100",
org.eclipse.xtext.ui;bundle-version="2.1.1",
- org.eclipse.xtext.ui.shared;bundle-version="2.1.1"
+ org.eclipse.xtext.ui.shared;bundle-version="2.1.1",
+ org.eclipse.emf.databinding,
+ org.eclipse.jface.databinding,
+ org.eclipse.core.databinding.property;bundle-version="1.4.200"
Export-Package: org.eclipse.etrice.ui.common,
org.eclipse.etrice.ui.common.commands,
org.eclipse.etrice.ui.common.dialogs,
diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/AbstractPropertyDialog.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/AbstractPropertyDialog.java
index a12d0cd..6f2df7f 100644
--- a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/AbstractPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/AbstractPropertyDialog.java
@@ -12,6 +12,8 @@
package org.eclipse.etrice.ui.common.dialogs;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -19,21 +21,25 @@ import org.eclipse.core.databinding.AggregateValidationStatus;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
-import org.eclipse.core.databinding.beans.PojoObservables;
+import org.eclipse.core.databinding.ValidationStatusProvider;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.conversion.IConverter;
-import org.eclipse.core.databinding.observable.ChangeEvent;
-import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IObservableCollection;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.value.ComputedValue;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.databinding.EMFProperties;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.jface.databinding.swt.ISWTObservable;
-import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecoration;
@@ -49,6 +55,7 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.forms.FormDialog;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.Form;
@@ -57,7 +64,7 @@ import org.eclipse.xtext.resource.IEObjectDescription;
public abstract class AbstractPropertyDialog extends FormDialog {
-
+
static class DescriptionBased_Reference2StringConverter extends Converter {
private EAttribute nameAttr;
@@ -171,14 +178,19 @@ public abstract class AbstractPropertyDialog extends FormDialog {
}
}
+ private static String DATA_KEY_STATUS = "etrice.status";
private String title;
private FormToolkit toolkit;
private DataBindingContext bindingContext;
- private HashMap<Control, ControlDecoration> decoratorMap = new HashMap<Control, ControlDecoration>();
+
+ // decoration -> validation status
+ private HashMap<ControlDecoration, IObservableValue> decoratorMap = new HashMap<ControlDecoration, IObservableValue>();
+
+ // top validation message
+ private IObservableValue displayedValidationStatus;
private Label validationLabel;
private Label validationText;
- private AggregateValidationStatus aggregateValidationStatus;
public AbstractPropertyDialog(Shell shell, String title) {
super(shell);
@@ -213,44 +225,40 @@ public abstract class AbstractPropertyDialog extends FormDialog {
GridData.FILL_HORIZONTAL));
createContent(mform, body, bindingContext);
-
- aggregateValidationStatus = new AggregateValidationStatus(
- bindingContext.getBindings(),
- AggregateValidationStatus.MAX_SEVERITY);
-
- bindingContext.bindValue(SWTObservables
- .observeText(validationText),
- aggregateValidationStatus, null,
- null);
-
- aggregateValidationStatus.addChangeListener(new IChangeListener() {
- public void handleChange(ChangeEvent event) {
-
+
+ displayedValidationStatus = new ComputedValue(IStatus.class) {
+
+ Collection<ControlDecoration> decorations = decoratorMap.keySet();
+
+ @Override
+ protected Object calculate() {
boolean ok = true;
- for (Object o : bindingContext.getBindings()) {
- Binding binding = (Binding) o;
- IStatus status = (IStatus) binding.getValidationStatus()
- .getValue();
- Control control = null;
- if (binding.getTarget() instanceof ISWTObservable) {
- ISWTObservable swtObservable = (ISWTObservable) binding
- .getTarget();
- control = (Control) swtObservable.getWidget();
- }
- ControlDecoration decoration = decoratorMap.get(control);
- if (decoration != null) {
- if (status.isOK()) {
- decoration.hide();
- } else {
- ok = false;
- decoration.setDescriptionText(status.getMessage());
- decoration.show();
- }
- }
+ IStatus newStatus = ValidationStatus.ok();
+
+ // iterate over all decoration and there validation status
+ for(ControlDecoration decoration: decorations){
+ IObservableValue observableValue = decoratorMap.get(decoration);
+ IStatus status = (IStatus) observableValue.getValue();
+
+ if (!status.isOK()) {
+ // validation error
+ ok = false;
+ decoration.setDescriptionText(status.getMessage());
+ decoration.show();
+ // select severest and meaningful message
+ if(status.getSeverity() > newStatus.getSeverity())
+ if(!status.getMessage().isEmpty())
+ newStatus = status;
+ } else
+ decoration.hide();
}
- updateValidationFeedback(ok);
+
+ updateValidationFeedback(ok && newStatus.isOK());
+ return newStatus;
}
- });
+ };
+
+ bindingContext.bindValue(WidgetProperties.text().observe(validationText), displayedValidationStatus);
}
/* (non-Javadoc)
@@ -260,7 +268,7 @@ public abstract class AbstractPropertyDialog extends FormDialog {
protected Control createButtonBar(Composite parent) {
Control bar = super.createButtonBar(parent);
- Object value = aggregateValidationStatus.getValue();
+ Object value = displayedValidationStatus.getValue();
if (value instanceof IStatus) {
boolean ok = ((IStatus) value).isOK();
updateValidationFeedback(ok);
@@ -313,6 +321,10 @@ public abstract class AbstractPropertyDialog extends FormDialog {
}
protected Text createText(Composite parent, String label, EObject obj, EStructuralFeature feat, IValidator validator, IConverter s2m, IConverter m2s, boolean multiline) {
+ return createText(parent, label, obj, feat, validator, null, s2m, m2s, multiline);
+ }
+
+ protected Text createText(Composite parent, String label, EObject obj, EStructuralFeature feat, IValidator singleValidator, MultiValidator2 multiValidator, IConverter s2m, IConverter m2s, boolean multiline) {
Label l = toolkit.createLabel(parent, label, SWT.NONE);
l.setLayoutData(new GridData(SWT.NONE));
@@ -322,27 +334,28 @@ public abstract class AbstractPropertyDialog extends FormDialog {
Text text = toolkit.createText(parent, "", style);
GridData gd = new GridData(multiline?GridData.FILL_BOTH:GridData.FILL_HORIZONTAL);
text.setLayoutData(gd);
-
+
UpdateValueStrategy t2m = null;
UpdateValueStrategy m2t = null;
- if (validator!=null || s2m!=null || m2s!=null) {
+ if (singleValidator!=null || s2m!=null || m2s!=null) {
t2m = new UpdateValueStrategy();
if (s2m!=null)
t2m.setConverter(s2m);
- if (validator!=null) {
- t2m.setAfterConvertValidator(validator);
- t2m.setBeforeSetValidator(validator);
+ if (singleValidator!=null) {
+ t2m.setAfterConvertValidator(singleValidator);
+ t2m.setBeforeSetValidator(singleValidator);
}
m2t = new UpdateValueStrategy();
if (m2s!=null)
m2t.setConverter(m2s);
- if (validator!=null) {
- m2t.setAfterConvertValidator(validator);
- m2t.setBeforeSetValidator(validator);
+ if (singleValidator!=null) {
+ m2t.setAfterConvertValidator(singleValidator);
+ m2t.setBeforeSetValidator(singleValidator);
}
}
- bindingContext.bindValue(SWTObservables.observeText(text, SWT.Modify), PojoObservables.observeValue(
- obj, feat.getName()), t2m, m2t);
+
+ Object type = (s2m!= null)?s2m.getToType():String.class;
+ createBinding(text, obj, feat, type, t2m, m2t, multiValidator);
return text;
}
@@ -363,10 +376,10 @@ public abstract class AbstractPropertyDialog extends FormDialog {
}
protected Button createCheck(Composite parent, String label, EObject obj, EAttribute att) {
- return createCheck(parent, label, obj, att, null);
+ return createCheck(parent, label, obj, att, null, null);
}
- protected Button createCheck(Composite parent, String label, EObject obj, EAttribute att, IValidator validator) {
+ protected Button createCheck(Composite parent, String label, EObject obj, EAttribute att, IValidator validator, MultiValidator2 multiValidator) {
Label l = toolkit.createLabel(parent, label, SWT.NONE);
l.setLayoutData(new GridData(SWT.NONE));
@@ -383,17 +396,16 @@ public abstract class AbstractPropertyDialog extends FormDialog {
m2t.setAfterConvertValidator(validator);
m2t.setBeforeSetValidator(validator);
}
- bindingContext.bindValue(SWTObservables.observeSelection(check), PojoObservables.observeValue(
- obj, att.getName()), t2m, m2t);
+ createBinding(check, obj, att, Boolean.class, t2m, m2t, multiValidator);
return check;
}
protected Combo createCombo(Composite parent, String label, EObject obj, Object type, EReference ref, List<? extends EObject> candidates, EAttribute nameAttr) {
- return createCombo(parent, label, obj, type, ref, candidates, nameAttr, null);
+ return createCombo(parent, label, obj, type, ref, candidates, nameAttr, null, null);
}
- protected Combo createCombo(Composite parent, String label, EObject obj, Object type, EReference ref, List<? extends EObject> candidates, EAttribute nameAttr, IValidator validator) {
+ protected Combo createCombo(Composite parent, String label, EObject obj, Object type, EReference ref, List<? extends EObject> candidates, EAttribute nameAttr, IValidator validator, MultiValidator2 multiValidator) {
Label l = toolkit.createLabel(parent, label, SWT.NONE);
l.setLayoutData(new GridData(SWT.NONE));
@@ -416,12 +428,16 @@ public abstract class AbstractPropertyDialog extends FormDialog {
m2t.setAfterConvertValidator(validator);
m2t.setBeforeSetValidator(validator);
}
- bindingContext.bindValue(SWTObservables.observeText(combo), PojoObservables.observeValue(obj, ref.getName()), t2m, m2t);
+ createBinding(combo, obj, ref, type, t2m, m2t, multiValidator);
return combo;
}
- protected Combo createComboUsingDesc(Composite parent, String label, EObject obj, Object type, EReference ref, List<IEObjectDescription> candidates, EAttribute nameAttr, IValidator validator) {
+ protected Combo createComboUsingDesc(Composite parent, String label, EObject obj, Object type, EReference ref, List<IEObjectDescription> candidates, EAttribute nameAttr, IValidator validator){
+ return createComboUsingDesc(parent, label, obj, type, ref, candidates, nameAttr, validator, null);
+ }
+
+ protected Combo createComboUsingDesc(Composite parent, String label, EObject obj, Object type, EReference ref, List<IEObjectDescription> candidates, EAttribute nameAttr, IValidator validator, MultiValidator2 multiValidator) {
Label l = toolkit.createLabel(parent, label, SWT.NONE);
l.setLayoutData(new GridData(SWT.NONE));
@@ -444,16 +460,17 @@ public abstract class AbstractPropertyDialog extends FormDialog {
m2t.setAfterConvertValidator(validator);
m2t.setBeforeSetValidator(validator);
}
- bindingContext.bindValue(SWTObservables.observeText(combo), PojoObservables.observeValue(obj, ref.getName()), t2m, m2t);
+
+ createBinding(combo, obj, ref, type, t2m, m2t, multiValidator);
return combo;
}
protected Combo createCombo(Composite parent, String label, EObject obj, Object type, EAttribute att, List<? extends Enumerator> choices) {
- return createCombo(parent, label, obj, type, att, choices, null);
+ return createCombo(parent, label, obj, type, att, choices, null, null);
}
- protected Combo createCombo(Composite parent, String label, EObject obj, Object type, EAttribute att, List<? extends Enumerator> choices, IValidator validator) {
+ protected Combo createCombo(Composite parent, String label, EObject obj, Object type, EAttribute att, List<? extends Enumerator> choices, IValidator singleValidator, MultiValidator2 multiValidator) {
Label l = toolkit.createLabel(parent, label, SWT.NONE);
l.setLayoutData(new GridData(SWT.NONE));
@@ -462,23 +479,46 @@ public abstract class AbstractPropertyDialog extends FormDialog {
combo.setVisibleItemCount(10);
toolkit.adapt(combo, true, true);
- for (Enumerator o : choices) {
+ for (Enumerator o : choices)
combo.add(o.getLiteral());
- }
UpdateValueStrategy t2m = new UpdateValueStrategy().setConverter(new String2EnumConverter(type, choices));
UpdateValueStrategy m2t = new UpdateValueStrategy().setConverter(new Enum2StringConverter());
- if (validator!=null) {
- t2m.setAfterConvertValidator(validator);
- t2m.setBeforeSetValidator(validator);
- m2t.setAfterConvertValidator(validator);
- m2t.setBeforeSetValidator(validator);
+ if (singleValidator!=null) {
+ t2m.setAfterConvertValidator(singleValidator);
+ t2m.setBeforeSetValidator(singleValidator);
+ m2t.setAfterConvertValidator(singleValidator);
+ m2t.setBeforeSetValidator(singleValidator);
}
- bindingContext.bindValue(SWTObservables.observeText(combo), PojoObservables.observeValue(obj, att.getName()), t2m, m2t);
+
+ createBinding(combo, obj, att, type, t2m, m2t, multiValidator);
return combo;
}
+ private void createBinding(Widget widget, EObject obj, EStructuralFeature feature, Object objType, UpdateValueStrategy t2m, UpdateValueStrategy m2t, MultiValidator2 multiValidator){
+ IObservableValue observableWidget = null;
+ if(widget instanceof Text)
+ observableWidget = WidgetProperties.text(SWT.Modify).observe(widget);
+ else if(widget instanceof Button || widget instanceof Combo)
+ observableWidget = WidgetProperties.selection().observe(widget);
+ IObservableValue observableObj = EMFProperties.value(feature).observe(obj);
+
+ if(multiValidator != null){
+ IObservableValue convertedObservable = new WritableValue(null, objType);
+ Binding convertBinding = bindingContext.bindValue(observableWidget, convertedObservable, t2m, m2t);
+ multiValidator.installValidator(convertBinding, observableObj);
+
+ List<ValidationStatusProvider> valProviders = new ArrayList<ValidationStatusProvider>();
+ valProviders.add(convertBinding);
+ valProviders.add(multiValidator);
+ widget.setData(DATA_KEY_STATUS, createAggregateValidationStatus(valProviders));
+ } else {
+ Binding binding = bindingContext.bindValue(observableWidget, observableObj, t2m, m2t);
+ widget.setData(DATA_KEY_STATUS, binding.getValidationStatus());
+ }
+ }
+
protected ControlDecoration createDecorator(Control ctrl, String message) {
ControlDecoration controlDecoration = new ControlDecoration(ctrl, SWT.LEFT | SWT.TOP);
controlDecoration.setDescriptionText(message);
@@ -486,8 +526,10 @@ public abstract class AbstractPropertyDialog extends FormDialog {
FieldDecorationRegistry.DEC_ERROR);
controlDecoration.setImage(fieldDecoration.getImage());
controlDecoration.hide();
-
- decoratorMap.put(ctrl, controlDecoration);
+
+ IObservableValue status = getObservableStatus(ctrl);
+ if(status != null)
+ decoratorMap.put(controlDecoration, status);
return controlDecoration;
}
@@ -505,6 +547,13 @@ public abstract class AbstractPropertyDialog extends FormDialog {
protected DataBindingContext getBindingContext() {
return bindingContext;
}
+
+ /**
+ * Returns the observable validation status for the given widget.
+ */
+ protected IObservableValue getObservableStatus(Widget widget){
+ return (IObservableValue) widget.getData(DATA_KEY_STATUS);
+ }
/**
* @return the toolkit
@@ -516,4 +565,9 @@ public abstract class AbstractPropertyDialog extends FormDialog {
protected void setTitle(String title) {
this.title = title;
}
+
+ private IObservableValue createAggregateValidationStatus(Collection<ValidationStatusProvider> valProvider){
+ IObservableCollection observableStatusProvider = new WritableList(valProvider, ValidationStatusProvider.class);
+ return new AggregateValidationStatus(observableStatusProvider, AggregateValidationStatus.MAX_SEVERITY);
+ }
}
diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/MultiValidator2.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/MultiValidator2.java
new file mode 100644
index 0000000..1d6e064
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/dialogs/MultiValidator2.java
@@ -0,0 +1,111 @@
+package org.eclipse.etrice.ui.common.dialogs;
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.databinding.AggregateValidationStatus;
+import org.eclipse.core.databinding.Binding;
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.ValidationStatusProvider;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.validation.MultiValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * A validator for cross-constraints between observables.
+ * <p>
+ * Validates <i>n</i> values and returns one common validation status.
+ * <p>
+ * See how a single validated value behaves: {@link MultiValidator#observeValidatedValue(IObservableValue)}
+ * But is aware of converters and pre-validators and treats a last valid state of any value as failure.
+ *
+ */
+public abstract class MultiValidator2 extends MultiValidator {
+
+ private int targetCount;
+ private DataBindingContext bindingContext;
+
+ private List<IObservableValue> targets;
+ private IObservableList converterStatusProviders;
+ private IObservableValue converterStatusObservable;
+
+ public MultiValidator2(DataBindingContext bindingContext, int values) {
+ this.bindingContext = bindingContext;
+ targetCount = values;
+
+ converterStatusProviders = new WritableList(new ArrayList<ValidationStatusProvider>(targetCount),
+ ValidationStatusProvider.class);
+ converterStatusObservable = new AggregateValidationStatus(converterStatusProviders,
+ AggregateValidationStatus.MAX_SEVERITY);
+ targets = new ArrayList<IObservableValue>(targetCount);
+ bindingContext.addValidationStatusProvider(this);
+ }
+
+ @Override
+ protected final IStatus validate() {
+ List<Object> values = new ArrayList<Object>(targetCount);
+ for (IObservableValue observable : targets)
+ // important, read from observable every time, otherwise
+ // MultiValidator loses listeners to targets
+ values.add(observable.getValue());
+
+ // return validation error if not all inputs are valid
+ IStatus converterStatus = (IStatus) converterStatusObservable.getValue();
+ if (!converterStatus.isOK())
+ return ValidationStatus.error("");
+
+ // no validation if not complete
+ if (targetCount != targets.size())
+ return ValidationStatus.ok();
+
+ return validate(values);
+ }
+
+ /**
+ * Validate all associated values.<br>
+ * Called when a value has changed and all values are in a valid state.
+ *
+ * @param values
+ * all 'middle' values from
+ * {@link #installValidator(targetToMiddle,model)}
+ * <ul>
+ * <li>ordered according to calls of installValidator</li>
+ * <li>if existent, a value is converted and validated</li>
+ * <li>complete</li>
+ * </ul>
+ * @return a common status
+ */
+ public abstract IStatus validate(List<Object> values);
+
+ /**
+ * Creates a binding between middle and model, that is validated by this
+ * multi-validator.
+ *
+ * @param targetToMiddle
+ * binding from a target (e.g. widget) to a middle value (may
+ * have optional converters and validators between)
+ * @param model
+ */
+ public void installValidator(Binding targetToMiddle, IObservableValue model) {
+ IObservableValue target = (IObservableValue) targetToMiddle.getModel();
+ targets.add(target);
+ IObservableValue validatedObservable = observeValidatedValue(target);
+ bindingContext.bindValue(validatedObservable, model);
+
+ converterStatusProviders.add(targetToMiddle);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
index 8a32b12..07c0cea 100644
--- a/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.ui.structure/META-INF/MANIFEST.MF
@@ -16,8 +16,8 @@ Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.4.0",
org.eclipse.emf.transaction;bundle-version="1.4.0",
org.eclipse.xtext.ui;bundle-version="2.1.1",
org.eclipse.xtext.ui.shared;bundle-version="2.1.1",
- org.eclipse.jface.databinding;bundle-version="1.5.0",
- org.eclipse.core.databinding.beans;bundle-version="1.2.100"
+ org.eclipse.jface.databinding,
+ org.eclipse.core.databinding.beans;bundle-version="1.2.200"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.etrice.ui.structure,
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
index 035fc87..a1bde23 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
@@ -14,6 +14,7 @@ package org.eclipse.etrice.ui.structure.dialogs;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.validation.IValidator;
@@ -34,6 +35,7 @@ import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.core.room.SubSystemRef;
import org.eclipse.etrice.core.validation.ValidationUtil;
import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
+import org.eclipse.etrice.ui.common.dialogs.MultiValidator2;
import org.eclipse.etrice.ui.structure.Activator;
import org.eclipse.etrice.ui.structure.dialogs.PortPropertyDialog.Multiplicity2StringConverter;
import org.eclipse.etrice.ui.structure.dialogs.PortPropertyDialog.String2MultiplicityConverter;
@@ -111,64 +113,48 @@ public class ActorContainerRefPropertyDialog extends AbstractPropertyDialog {
}
}
- class SizeValidator implements IValidator {
-
- private ActorRef ref;
+ class SizeAndRefTypeValidator extends MultiValidator2{
- public SizeValidator(ActorRef ref) {
- this.ref = ref;
+ public SizeAndRefTypeValidator(DataBindingContext bindingContext) {
+ super(bindingContext, 2);
}
@Override
- public IStatus validate(Object value) {
- if (value instanceof Integer) {
- int m = (Integer) value;
- if (m==0)
- return ValidationStatus.error("multiplicity must not be 0");
- if (m<-1)
- return ValidationStatus.error("multiplicity must be -1 or positive");
- if (ref.getRefType()==ReferenceType.OPTIONAL) {
- if (m>1)
- return ValidationStatus.error("multiplicity >1 not allowed (only fixed actors)");
- }
- else {
- if (m==-1)
- return ValidationStatus.error("multiplicity * not allowed (only optional actors)");
- }
+ public IStatus validate(List<Object> values) {
+ int m = (Integer) values.get(0);
+ ReferenceType rt = (ReferenceType) values.get(1);
+ if (m==0)
+ return ValidationStatus.error("multiplicity must not be 0");
+ if (m<-1)
+ return ValidationStatus.error("multiplicity must be -1 or positive");
+ if (rt==ReferenceType.OPTIONAL) {
+ if (m>1)
+ return ValidationStatus.error("multiplicity >1 not allowed (only fixed actors)");
}
- return Status.OK_STATUS;
+ else {
+ if (m==-1)
+ return ValidationStatus.error("multiplicity * not allowed (only optional actors)");
+ }
+
+ return ValidationStatus.ok();
}
+
}
- class RefTypeValidator implements IValidator {
-
- private ActorRef ref;
+ class SizeValidator implements IValidator {
- public RefTypeValidator(ActorRef ref) {
- this.ref = ref;
- }
-
@Override
public IStatus validate(Object value) {
- if (value instanceof String) {
- if (ReferenceType.OPTIONAL.getLiteral().equals(value))
- if (ref.getMultiplicity()>1)
- return ValidationStatus.error("replicated optional actors must have multiplicity *");
- if (ReferenceType.FIXED.getLiteral().equals(value))
- if (ref.getMultiplicity()<0)
- return ValidationStatus.error("replicated fixed actors must have fixed multiplicity");
- }
- else if (value instanceof ReferenceType) {
- if (ReferenceType.OPTIONAL==value)
- if (ref.getMultiplicity()>1)
- return ValidationStatus.error("replicated optional actors must have multiplicity *");
- if (ReferenceType.FIXED==value)
- if (ref.getMultiplicity()<0)
- return ValidationStatus.error("replicated fixed actors must have fixed multiplicity");
+ if(value instanceof Integer){
+ int m = (Integer) value;
+ if (m==0)
+ return ValidationStatus.error("multiplicity must not be 0");
+ if (m<-1)
+ return ValidationStatus.error("multiplicity must be -1 or positive");
}
- return Status.OK_STATUS;
+
+ return ValidationStatus.ok();
}
-
}
private ActorContainerRef ref;
@@ -236,7 +222,10 @@ public class ActorContainerRefPropertyDialog extends AbstractPropertyDialog {
if (ref instanceof ActorRef) {
Multiplicity2StringConverter m2s = new Multiplicity2StringConverter();
String2MultiplicityConverter s2m = new String2MultiplicityConverter();
- Text size = createText(body, "&Multiplicity", ref, RoomPackage.eINSTANCE.getActorRef_Multiplicity(), new SizeValidator(((ActorRef) ref)), s2m, m2s, false);
+ MultiValidator2 multiValidator = new SizeAndRefTypeValidator(bindingContext);
+
+ IValidator sizeValidator = new SizeValidator();
+ Text size = createText(body, "&Multiplicity", ref, RoomPackage.eINSTANCE.getActorRef_Multiplicity(), sizeValidator, multiValidator, s2m, m2s, false);
if (hasInterfacePortWithMultiplicityAny(((ActorRef) ref).getType())) {
size.setEnabled(false);
createInfoDecorator(size, "size fixed since actor has interface ports with multiplicity *");
@@ -245,8 +234,7 @@ public class ActorContainerRefPropertyDialog extends AbstractPropertyDialog {
createDecorator(size, "multiplicity");
}
- RefTypeValidator rtv = new RefTypeValidator((ActorRef) ref);
- Combo refType = createCombo(body, "Reference &Type:", ref, ReferenceType.class, RoomPackage.Literals.ACTOR_REF__REF_TYPE, ReferenceType.VALUES, rtv);
+ Combo refType = createCombo(body, "Reference &Type:", ref, ReferenceType.class, RoomPackage.eINSTANCE.getActorRef_RefType(), ReferenceType.VALUES, null, multiValidator);
createDecorator(refType, "invalid ref type");
}