diff options
| author | Christian W. Damus | 2016-04-25 22:14:53 +0000 |
|---|---|---|
| committer | Christian W. Damus | 2016-04-25 22:14:53 +0000 |
| commit | 1d11408fde404b87115a0a51bf9cc71272c9608f (patch) | |
| tree | 0041ebd29a89889d4cfaaa2e18a7f3d0f00faa13 | |
| parent | f83683ebc8a27729fdd53f12fdb92f851c0f4c19 (diff) | |
| download | org.eclipse.papyrus-1d11408fde404b87115a0a51bf9cc71272c9608f.tar.gz org.eclipse.papyrus-1d11408fde404b87115a0a51bf9cc71272c9608f.tar.xz org.eclipse.papyrus-1d11408fde404b87115a0a51bf9cc71272c9608f.zip | |
Bug 491789: [Properties] ExtendedMultiplicityObservableValue does not implement doSetValue(T)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=491789
Implement a plausible doSetValue(), accounting for setting the same
observables that we already have (which is, in fact, what always
happens in the Papyrus property sheet).
Change-Id: I50a97c897799b43864bf441f6ce8e8b8e2b74a7d
4 files changed, 48 insertions, 7 deletions
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/.classpath b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/.classpath index ad32c83a788..eca7bdba8f0 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/.classpath +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/.classpath @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/.settings/org.eclipse.jdt.core.prefs b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/.settings/org.eclipse.jdt.core.prefs index 410244d65a6..62a08f4494d 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/.settings/org.eclipse.jdt.core.prefs @@ -1,10 +1,10 @@ eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF index 738eb22d6c0..5df421b6b3b 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF @@ -31,4 +31,4 @@ Bundle-Activator: org.eclipse.papyrus.uml.tools.Activator Bundle-ManifestVersion: 2 Bundle-Description: %pluginDescription Bundle-SymbolicName: org.eclipse.papyrus.uml.tools;singleton:=true -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ExtendedMultiplicityObservableValue.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ExtendedMultiplicityObservableValue.java index 5206e9332b0..918b08fb700 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ExtendedMultiplicityObservableValue.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ExtendedMultiplicityObservableValue.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015 CEA LIST. + * Copyright (c) 2015, 2016 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * Christian W. Damus - bug 491789 * *****************************************************************************/ @@ -17,6 +18,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.IObservable; import org.eclipse.core.databinding.observable.value.AbstractObservableValue; import org.eclipse.core.databinding.observable.value.IObservableValue; @@ -32,7 +34,7 @@ import org.eclipse.uml2.uml.UMLPackage; /** * The multiplicity observable values contains a list of 3 observable values : The first the multiplicity lower and upper value for the 'simple' mode and the 2 following are the lower and the upper value observable value. */ -public class ExtendedMultiplicityObservableValue extends AbstractObservableValue implements AggregatedObservable { +public class ExtendedMultiplicityObservableValue extends ReferenceCountedObservable.Value implements AggregatedObservable { /** * The number of ObservableValue in the ObservableList. @@ -160,6 +162,45 @@ public class ExtendedMultiplicityObservableValue extends AbstractObservableValue protected Object doGetValue() { return getObservableValues(); } + + /** + * If the input is a list of three elements that are all observable-values, + * take them. Otherwise, throw. + * + * @param value the value to set + * + * @throws IllegalArgumentException if {@code value} is not a list of three + * {@link IObservableValue}s + */ + @Override + protected void doSetValue(Object value) { + if (!(value instanceof List<?>)) { + throw new IllegalArgumentException("value is not a List"); //$NON-NLS-1$ + } + List<?> listValue = (List<?>) value; + if (listValue.size() != NUMBER_OBSERVABLE_VALUES) { + throw new IllegalArgumentException(String.format("value is not a list of %d IObservableValues", NUMBER_OBSERVABLE_VALUES)); //$NON-NLS-1$ + } + if (!listValue.stream().allMatch(IObservableValue.class::isInstance)) { + throw new IllegalArgumentException(String.format("value is not a list of %d IObservableValues", NUMBER_OBSERVABLE_VALUES)); //$NON-NLS-1$ + } + + // Only do anything if the result would be different + if (!listValue.equals(observableValues)) { + @SuppressWarnings("unchecked") + List<? extends IObservableValue<?>> newObservables = (List<? extends IObservableValue<?>>)listValue; + + // Retain the new, release the old (some may be both) + newObservables.forEach(ReferenceCountedObservable.Util::retain); + observableValues.forEach(ReferenceCountedObservable.Util::autorelease); + + List<IObservableValue<?>> oldObservables = new ArrayList<>(observableValues); + + observableValues.clear(); + observableValues.addAll(newObservables); + fireValueChange(Diffs.createValueDiff(oldObservables, newObservables)); + } + } /** * Get the observable values. |
