diff options
Diffstat (limited to 'plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ExtendedMultiplicityObservableValue.java')
-rw-r--r-- | plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ExtendedMultiplicityObservableValue.java | 65 |
1 files changed, 38 insertions, 27 deletions
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 abda8146a77..bbb3e2a61ca 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,6 +1,6 @@ /***************************************************************************** * 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 2.0 * which accompanies this distribution, and is available at @@ -11,7 +11,7 @@ * Contributors: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation * Christian W. Damus - bug 491789 - * + * *****************************************************************************/ package org.eclipse.papyrus.uml.tools.databinding; @@ -22,7 +22,6 @@ 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; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; @@ -35,7 +34,13 @@ 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. + * + * @deprecated since 4.3 + * use {@link org.eclipe.papyrus.uml.properties.databinding.ExtendedMultiplicityObservableValue} API, instead + * + * This class Will be removed in Papyrus 5.0, see bug 540829 */ +@Deprecated public class ExtendedMultiplicityObservableValue extends ReferenceCountedObservable.Value implements AggregatedObservable { /** @@ -61,7 +66,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** - * + * * Constructor. * * @param domain @@ -81,7 +86,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva */ public ExtendedMultiplicityObservableValue(final EObject eObject, final EditingDomain domain) { this.domain = domain; - this.observableValues = new ArrayList<IObservableValue>(NUMBER_OBSERVABLE_VALUES); + this.observableValues = new ArrayList<>(NUMBER_OBSERVABLE_VALUES); if (null != eObject) { observableValues.add(new MultiplicityObservableValue(eObject, domain)); @@ -98,7 +103,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * {@inheritDoc} - * + * * @see org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable#aggregate(org.eclipse.core.databinding.observable.IObservable) */ @SuppressWarnings("unchecked") @@ -108,9 +113,9 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva final Object value = ((IObservableValue) observable).getValue(); if (value instanceof List<?> && NUMBER_OBSERVABLE_VALUES == ((List<?>) value).size() && isAllIObservableValueType((List<?>) value)) { final ExtendedMultiplicityObservableValue result = new ExtendedMultiplicityObservableValue(domain); - + int count = 0; - while(count < NUMBER_OBSERVABLE_VALUES){ + while (count < NUMBER_OBSERVABLE_VALUES) { final IObservableValue existingMultiplicityValues = observableValues.get(count); final IObservableValue multiplicityValueToAggregate = ((List<IObservableValue>) value).get(count); if (existingMultiplicityValues instanceof AggregatedObservable) { @@ -119,7 +124,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva } count++; } - + return result; } } @@ -128,8 +133,9 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * Get if all the elements of the list are observable values. - * - * @param values The values list. + * + * @param values + * The values list. * @return <code>true</code> if all the elements are observable values, <code>false</code> otherwise. */ private boolean isAllIObservableValueType(final List<?> values) { @@ -147,7 +153,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * {@inheritDoc} - * + * * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() */ @Override @@ -157,22 +163,24 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * {@inheritDoc} - * + * * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue() */ @Override protected Object doGetValue() { return getObservableValues(); } - + /** * If the input is a list of three elements that are all observable-values, - * take them. Otherwise, throw. + * take them. Otherwise, throw. * - * @param value the value to set - * - * @throws IllegalArgumentException if {@code value} is not a list of three - * {@link IObservableValue}s + * @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) { @@ -186,18 +194,18 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva 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; - + 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)); @@ -206,7 +214,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * Get the observable values. - * + * * @return the observableValues. */ public List<IObservableValue> getObservableValues() { @@ -215,7 +223,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * {@inheritDoc} - * + * * @see org.eclipse.core.databinding.observable.AbstractObservable#dispose() */ @Override @@ -230,6 +238,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * This retains the support. */ + @Override public void retain() { refCount.retain(); } @@ -237,6 +246,7 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * This releases the support. */ + @Override public void release() { refCount.release(); } @@ -244,13 +254,14 @@ public class ExtendedMultiplicityObservableValue extends ReferenceCountedObserva /** * This auto-relreases the support. */ + @Override public void autorelease() { refCount.autorelease(); } /** * {@inheritDoc} - * + * * @see org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable#hasDifferentValues() */ @Override |