Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2016-07-22 20:06:15 +0000
committerBrian Vosburgh2017-05-18 22:38:16 +0000
commitfe3d5f806873233f410fa3293b6bd36ffbec9fda (patch)
tree2580bd353b53297c093bb92d91cf15b7bfd908cc
parentddf39d58d7934326d0981c9378b357e734911257 (diff)
downloadwebtools.dali-fe3d5f806873233f410fa3293b6bd36ffbec9fda.tar.gz
webtools.dali-fe3d5f806873233f410fa3293b6bd36ffbec9fda.tar.xz
webtools.dali-fe3d5f806873233f410fa3293b6bd36ffbec9fda.zip
add new property aspect adapters
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BaseCompoundPropertyValueModelAdapter.java183
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePluggablePropertyValueModel.java34
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePropertyPluggablePropertyValueModelAdapter.java138
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompoundModifiablePropertyValueModelAdapter.java64
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompoundPropertyValueModelAdapter.java54
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModifiablePropertyAspectAdapter.java100
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java10
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java19
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyValueModel.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java209
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggableModifiablePropertyValueModelAdapter.java64
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggablePropertyValueModelAdapter.java95
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java647
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/ModifiablePropertyValueModel.java19
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java249
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java1
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java14
17 files changed, 1002 insertions, 906 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BaseCompoundPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BaseCompoundPropertyValueModelAdapter.java
deleted file mode 100644
index 685ed65154..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BaseCompoundPropertyValueModelAdapter.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2016 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
-import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
-import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-
-/**
- * This adapter adapts an (<em>outer</em>) property value model whose
- * value is yet another (<em>inner</em>) property value model
- * and treats the <em>inner</em> model's value as this adapter's models's value.
- * As a result, this adapter listens for changes to either model
- * (<em>inner</em> or <em>outer</em>).
- * <p>
- * A typical usage:<br>A (simple) model <code>A</code> is wrapped by
- * a transformation model <code>B</code> that transforms model <code>A</code>'s
- * value to yet another model <code>C</code>. This adapter is
- * then constructed with model <code>B</code>.<ul>
- * <li>If model <code>A</code>'s value changes
- * (e.g. as the result of an Eclipse-generated event), model <code>B</code>
- * will recalculate its value, a new model <code>C</code>, and this adapter's value will
- * be recalculated etc.</li>
- * <li>If model <code>C</code>'s value changes
- * (e.g. its value is deleted from the Eclipse workspace), this adapter's value will
- * be recalculated etc.</li>
- * </ul>
- * This is an adapter that can be used by a {@link BasePluggablePropertyValueModel}.
- *
- * @param <V> the type of both the adapter's and the <em>inner</em> model's values
- * @param <IM> the type of the <em>inner</em> model (and the <em>outer</em> model's value)
- * @param <OM> the type of the <em>outer</em> model
- * @param <A> the type of the adapter itself
- * @param <F> the type of the adapter factory
- *
- * @see BasePluggablePropertyValueModel
- */
-public abstract class BaseCompoundPropertyValueModelAdapter<V, IM extends PropertyValueModel<? extends V>, OM extends PropertyValueModel<? extends IM>, A extends BasePluggablePropertyValueModel.Adapter<V>, F extends BaseCompoundPropertyValueModelAdapter.Factory<V, IM, OM, A>>
- implements BasePluggablePropertyValueModel.Adapter<V>
-{
- /** The <em>outer</em> model; whose value is cached as {@link #innerModel}. */
- protected final OM outerModel;
-
- /** Listens to {@link #outerModel}. */
- protected final PropertyChangeListener outerValueListener;
-
- /** The <em>inner</em> model; which is the value of {@link #outerModel}. Can be <code>null</code>. */
- protected volatile IM innerModel;
-
- /** Listens to {@link #innerModel}, if present. */
- protected final PropertyChangeListener innerValueListener;
-
- /** The derived value. */
- private volatile V value;
-
- /** The <em>real</em> adapter. */
- private final BasePluggablePropertyValueModel.Adapter.Listener<V> listener;
-
-
- public BaseCompoundPropertyValueModelAdapter(OM outerModel, BasePluggablePropertyValueModel.Adapter.Listener<V> listener) {
- super();
- if (outerModel == null) {
- throw new NullPointerException();
- }
- this.outerModel = outerModel;
- this.outerValueListener = new OuterValueListener();
-
- this.innerValueListener = new InnerValueListener();
-
- if (listener == null) {
- throw new NullPointerException();
- }
- this.listener = listener;
- }
-
- /* CU private */ class OuterValueListener
- extends PropertyChangeAdapter
- {
- @Override
- public void propertyChanged(PropertyChangeEvent event) {
- @SuppressWarnings("unchecked")
- IM newInnerModel = (IM) event.getNewValue();
- BaseCompoundPropertyValueModelAdapter.this.outerValueChanged(newInnerModel);
- }
- }
-
- /* CU private */ class InnerValueListener
- extends PropertyChangeAdapter
- {
- @Override
- public void propertyChanged(PropertyChangeEvent event) {
- @SuppressWarnings("unchecked")
- V newValue = (V) event.getNewValue();
- BaseCompoundPropertyValueModelAdapter.this.innerValueChanged(newValue);
- }
- }
-
-
- // ********** BasePluggablePropertyValueModel.Adapter **********
-
- public V engageModel() {
- this.outerModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.outerValueListener);
- this.innerModel = this.outerModel.getValue();
- return this.engageInnerModel();
- }
-
- private V engageInnerModel() {
- if (this.innerModel == null) {
- return null;
- }
- this.innerModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.innerValueListener);
- return this.value = this.innerModel.getValue();
- }
-
- public V disengageModel() {
- this.outerModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.outerValueListener);
- return this.disengageInnerModel();
- }
-
- private V disengageInnerModel() {
- if (this.innerModel == null) {
- return null;
- }
- this.innerModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.innerValueListener);
- this.innerModel = null;
- return this.value = null;
- }
-
-
- // ********** change events **********
-
- /**
- * Move our <em>inner</em> value listener to the new inner model.
- */
- protected void outerValueChanged(IM newInnerModel) {
- this.disengageInnerModel();
- this.innerModel = newInnerModel;
- this.engageInnerModel();
- this.listener.valueChanged(this.value);
- }
-
- protected void innerValueChanged(V newValue) {
- this.listener.valueChanged(this.value = newValue);
- }
-
- @Override
- public String toString() {
- return ObjectTools.toString(this, this.value);
- }
-
-
- // ********** Factory **********
-
- public abstract static class Factory<V, IM extends PropertyValueModel<? extends V>, OM extends PropertyValueModel<? extends IM>, A extends BasePluggablePropertyValueModel.Adapter<V>>
- implements BasePluggablePropertyValueModel.Adapter.Factory<V, A>
- {
- /* CU private */ final OM outerModel;
-
- public Factory(OM outerModel) {
- super();
- if (outerModel == null) {
- throw new NullPointerException();
- }
- this.outerModel = outerModel;
- }
-
- public abstract A buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V> listener);
-
- @Override
- public String toString() {
- return ObjectTools.toString(this);
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePluggablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePluggablePropertyValueModel.java
index 78797ba15f..1863e3d6ab 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePluggablePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePluggablePropertyValueModel.java
@@ -37,10 +37,7 @@ public abstract class BasePluggablePropertyValueModel<V, A extends BasePluggable
protected final A adapter;
/**
- * Cache the current value so we can pass an "old value" when
- * we fire a property change event.
- * We need this because the value may be calculated and we may
- * not able to derive the "old value" from any fired events.
+ * Cache the current value so we can determine whether it changes.
*/
protected volatile V value;
@@ -54,6 +51,9 @@ public abstract class BasePluggablePropertyValueModel<V, A extends BasePluggable
}
// a bit of instance leakage...
this.adapter = adapterFactory.buildAdapter(new AdapterListener());
+ if (this.adapter == null) {
+ throw new NullPointerException();
+ }
// our value is null when we are not listening to the model
this.value = null;
}
@@ -135,21 +135,19 @@ public abstract class BasePluggablePropertyValueModel<V, A extends BasePluggable
}
/**
- * Start listening to the underlying model and build the value.
+ * Start listening to the underlying model
+ * and cache its current value.
*/
protected void engageModel() {
- // sync our value *after* we start listening to the model,
- // since the model's value might change when a listener is added
this.value = this.adapter.engageModel();
}
/**
- * Clear the value and stop listening to the underlying model.
+ * Stop listening to the underlying model
+ * and reset our cached value.
*/
private void disengageModel() {
- // clear out our value when we are not listening to the model
- this.value = null;
- this.adapter.disengageModel();
+ this.value = this.adapter.disengageModel();
}
@@ -196,27 +194,27 @@ public abstract class BasePluggablePropertyValueModel<V, A extends BasePluggable
* listener passed to it via its {@link Adapter.Factory factory}
* about any model changes.
*/
- public interface Adapter<AV> {
+ public interface Adapter<V> {
/**
* Start listening to the adapted model
* and return its current value.
*/
- AV engageModel();
+ V engageModel();
/**
* Stop listening to the adapted model
* and return its current value.
*/
- AV disengageModel();
+ V disengageModel();
/**
* Callback interface.
*/
- interface Listener<ALV> {
+ interface Listener<V> {
/**
* Callback to notify listener that the adapted model has changed.
*/
- void valueChanged(ALV newValue);
+ void valueChanged(V newValue);
}
/**
@@ -224,11 +222,11 @@ public abstract class BasePluggablePropertyValueModel<V, A extends BasePluggable
* This factory allows both the pluggable property value model and its
* adapter to have circular <em>final</em> references to each other.
*/
- interface Factory<AFV, A extends Adapter<AFV>> {
+ interface Factory<V, A extends Adapter<V>> {
/**
* Create an adapter with the specified listener.
*/
- A buildAdapter(Listener<AFV> listener);
+ A buildAdapter(Listener<V> listener);
}
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePropertyPluggablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePropertyPluggablePropertyValueModelAdapter.java
deleted file mode 100644
index 36e7d45f76..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BasePropertyPluggablePropertyValueModelAdapter.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
-import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * Adapt a {@link PropertyValueModel property value model} to
- * another {@link PropertyValueModel property value model}, sorta.
- * <p>
- * This adapter is constructed with a {@link PropertyValueModel
- * property value model} and a {@link Transformer transformer} that can
- * transform the property to another value.
- * <p>
- * This is an adapter that can be used by a {@link BasePluggablePropertyValueModel}.
- *
- * @param <V1> the type of the <em>wrapped</em> model's value
- * @param <V2> the type of the model's <em>derived</em> value
- * @param <M> the type of the <em>wrapped</em> model
- * @param <A> the type of the adapter itself
- * @param <F> the type of the adapter factory
- *
- * @see BasePluggablePropertyValueModel
- */
-public abstract class BasePropertyPluggablePropertyValueModelAdapter<V1, V2, M extends PropertyValueModel<? extends V1>, A extends BasePluggablePropertyValueModel.Adapter<V2>, F extends BasePropertyPluggablePropertyValueModelAdapter.Factory<V1, V2, M, A>>
- implements BasePluggablePropertyValueModel.Adapter<V2>, PropertyChangeListener
-{
- /** The wrapped model */
- protected final M propertyModel;
-
- /** Transformer that converts the wrapped model's value to this model's value. */
- private final Transformer<? super V1, ? extends V2> transformer;
-
- /** The <em>real</em> adapter. */
- private final BasePluggablePropertyValueModel.Adapter.Listener<V2> listener;
-
- /** Cached copy of model's value. */
- private volatile V1 propertyModelValue;
-
- /** The derived value. */
- private volatile V2 value;
-
-
- // ********** constructors **********
-
- public BasePropertyPluggablePropertyValueModelAdapter(F factory, BasePluggablePropertyValueModel.Adapter.Listener<V2> listener) {
- super();
- if (factory == null) {
- throw new NullPointerException();
- }
- this.propertyModel = factory.propertyModel;
- this.transformer = factory.transformer;
- if (listener == null) {
- throw new NullPointerException();
- }
- this.listener = listener;
- }
-
-
- // ********** BasePluggablePropertyValueModel.Adapter **********
-
- public V2 engageModel() {
- this.propertyModel.addPropertyChangeListener(PropertyValueModel.VALUE, this);
- this.propertyModelValue = this.propertyModel.getValue();
- return this.value = this.buildValue();
- }
-
- public V2 disengageModel() {
- this.propertyModel.removePropertyChangeListener(PropertyValueModel.VALUE, this);
- this.propertyModelValue = null;
- return this.value = null;
- }
-
-
- // ********** PropertyChangeListener **********
-
- @SuppressWarnings("unchecked")
- public void propertyChanged(PropertyChangeEvent event) {
- this.propertyModelValue = (V1) event.getNewValue();
- this.update();
- }
-
-
- // ********** misc **********
-
- private void update() {
- this.listener.valueChanged(this.value = this.buildValue());
- }
-
- private V2 buildValue() {
- return this.transformer.transform(this.propertyModelValue);
- }
-
- @Override
- public String toString() {
- return ObjectTools.toString(this, this.value);
- }
-
-
- // ********** Factory **********
-
- public abstract static class Factory<V1, V2, M extends PropertyValueModel<? extends V1>, A extends BasePluggablePropertyValueModel.Adapter<V2>>
- implements BasePluggablePropertyValueModel.Adapter.Factory<V2, A>
- {
- /* CU private */ final M propertyModel;
- /* CU private */ final Transformer<? super V1, ? extends V2> transformer;
-
- public Factory(M propertyModel, Transformer<? super V1, ? extends V2> transformer) {
- super();
- if (propertyModel == null) {
- throw new NullPointerException();
- }
- this.propertyModel = propertyModel;
- if (transformer == null) {
- throw new NullPointerException();
- }
- this.transformer = transformer;
- }
-
- public abstract A buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V2> listener);
-
- @Override
- public String toString() {
- return ObjectTools.toString(this);
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompoundModifiablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompoundModifiablePropertyValueModelAdapter.java
deleted file mode 100644
index a7d57c5bf6..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompoundModifiablePropertyValueModelAdapter.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2016 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-
-/**
- * Add support for changing the model's value.
- * This also constrains the value's type, since it is read <em>and</em> written.
- * <p>
- * <strong>NB:</strong> If the model has no listeners,
- * {@link #setValue(Object) changes} will <em>not</em> be forwarded to the
- * <em>inner</em> model.
- *
- * @param <V> the type of both the adapter's and the <em>inner</em> model's values
- * @param <IM> the type of the <em>inner</em> model (and the <em>outer</em> model's value)
- * @param <OM> the type of the <em>outer</em> model
- */
-public final class CompoundModifiablePropertyValueModelAdapter<V, IM extends ModifiablePropertyValueModel<V>, OM extends PropertyValueModel<IM>>
- extends BaseCompoundPropertyValueModelAdapter<V, IM, OM, PluggableModifiablePropertyValueModel.Adapter<V>, CompoundModifiablePropertyValueModelAdapter.Factory<V, IM, OM>>
- implements PluggableModifiablePropertyValueModel.Adapter<V>
-{
-
- public CompoundModifiablePropertyValueModelAdapter(OM outerModel, BasePluggablePropertyValueModel.Adapter.Listener<V> listener) {
- super(outerModel, listener);
- }
-
- /**
- * Forward the specified value to the <em>inner</em> model.
- * Client's should be aware of a <code>null</code> <em>inner</em> model
- * (typically the <em>inner</em> will never be <code>null</code>).
- */
- public void setValue(V value) {
- if (this.innerModel == null) {
- throw new IllegalStateException();
- }
- this.innerModel.setValue(value);
- }
-
-
- // ********** Factory **********
-
- public static class Factory<V, IM extends ModifiablePropertyValueModel<V>, OM extends PropertyValueModel<IM>>
- extends BaseCompoundPropertyValueModelAdapter.Factory<V,IM, OM, PluggableModifiablePropertyValueModel.Adapter<V>>
- implements PluggableModifiablePropertyValueModel.Adapter.Factory<V>
- {
- public Factory(OM outerModel) {
- super(outerModel);
- }
-
- @Override
- public PluggableModifiablePropertyValueModel.Adapter<V> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V> listener) {
- return new CompoundModifiablePropertyValueModelAdapter<>(this.outerModel, listener);
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompoundPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompoundPropertyValueModelAdapter.java
deleted file mode 100644
index 11ead85180..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompoundPropertyValueModelAdapter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2016 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-
-/**
- * This adapter adapts an (<em>outer</em>) property value model whose
- * value is yet another (<em>inner</em>) property value model
- * and treats the <em>inner</em> model's value as this adapter's models's value.
- * As a result, this adapter listens for changes to either model
- * (<em>inner</em> or <em>outer</em>).
- * <p>
- * This is an adapter that can be used by a {@link BasePluggablePropertyValueModel}.
- *
- * @param <V> the type of both the adapter's and the <em>inner</em> model's values
- * @param <IM> the type of the <em>inner</em> model (and the <em>outer</em> model's value)
- * @param <OM> the type of the <em>outer</em> model
- *
- * @see BasePluggablePropertyValueModel
- */
-public final class CompoundPropertyValueModelAdapter<V, IM extends PropertyValueModel<? extends V>, OM extends PropertyValueModel<IM>>
- extends BaseCompoundPropertyValueModelAdapter<V, IM, OM, PluggablePropertyValueModel.Adapter<V>, CompoundPropertyValueModelAdapter.Factory<V, IM, OM>>
- implements PluggablePropertyValueModel.Adapter<V>
-{
-
- public CompoundPropertyValueModelAdapter(OM outerModel, BasePluggablePropertyValueModel.Adapter.Listener<V> listener) {
- super(outerModel, listener);
- }
-
-
- // ********** Factory **********
-
- public static class Factory<V, IM extends PropertyValueModel<? extends V>, OM extends PropertyValueModel<IM>>
- extends BaseCompoundPropertyValueModelAdapter.Factory<V, IM, OM, PluggablePropertyValueModel.Adapter<V>>
- implements PluggablePropertyValueModel.Adapter.Factory<V>
- {
- public Factory(OM outerModel) {
- super(outerModel);
- }
-
- @Override
- public PluggablePropertyValueModel.Adapter<V> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V> listener) {
- return new CompoundPropertyValueModelAdapter<>(this.outerModel, listener);
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModifiablePropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModifiablePropertyAspectAdapter.java
new file mode 100644
index 0000000000..70612a2b5f
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModifiablePropertyAspectAdapter.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import org.eclipse.jpt.common.utility.closure.BiClosure;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.model.Model;
+import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * Adapt a {@link ModifiablePropertyValueModel property value model} to
+ * another {@link ModifiablePropertyValueModel property value model}, sorta.
+ * <p>
+ * This adapter is constructed with a {@link ModifiablePropertyValueModel
+ * property value model} and two {@link Transformer transformers} that can
+ * transform the property to another value and vice versa.
+ * <p>
+ * This is an adapter that can be used by a {@link PluggableModifiablePropertyValueModel}.
+ *
+ * @param <V> the type of the adapter's value
+ * @param <S> the type of the subject (and the subject model's value)
+ * @param <SM> the type of the subject model
+ *
+ * @see PluggableModifiablePropertyValueModel
+ */
+public final class ModifiablePropertyAspectAdapter<V, S extends Model, SM extends PropertyValueModel<S>>
+ implements PluggableModifiablePropertyValueModel.Adapter<V>
+{
+ /** The "get" half of the aspect adapter */
+ private final PropertyAspectAdapter<V, S, SM> adapter;
+
+ /** The closure used to "set" the subject's new aspect value. */
+ private final BiClosure<? super S, ? super V> setClosure;
+
+
+ public ModifiablePropertyAspectAdapter(PropertyAspectAdapter<V, S, SM> adapter, BiClosure<? super S, ? super V> setClosure) {
+ super();
+ if (adapter == null) {
+ throw new NullPointerException();
+ }
+ this.adapter = adapter;
+ if (setClosure == null) {
+ throw new NullPointerException();
+ }
+ this.setClosure = setClosure;
+ }
+
+ public V engageModel() {
+ return this.adapter.engageModel();
+ }
+
+ public V disengageModel() {
+ return this.adapter.disengageModel();
+ }
+
+ public void setValue(V value) {
+ this.setClosure.execute(this.adapter.subject, value);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.adapter.buildValue());
+ }
+
+
+ // ********** Factory **********
+
+ public static final class Factory<V, S extends Model, SM extends PropertyValueModel<S>>
+ implements PluggableModifiablePropertyValueModel.Adapter.Factory<V>
+ {
+ private final PropertyAspectAdapter.Factory<V, S, SM> factory;
+ private final BiClosure<? super S, ? super V> setClosure;
+
+ public Factory(PropertyAspectAdapter.Factory<V, S, SM> factory, BiClosure<? super S, ? super V> setClosure) {
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.factory = factory;
+ if (setClosure == null) {
+ throw new NullPointerException();
+ }
+ this.setClosure = setClosure;
+ }
+
+ @Override
+ public PluggableModifiablePropertyValueModel.Adapter<V> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ return new ModifiablePropertyAspectAdapter<>(this.factory.buildAdapter(listener), this.setClosure);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java
index b855301273..165b8406dd 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java
@@ -42,17 +42,17 @@ public final class PluggableModifiablePropertyValueModel<V>
// ********** Adapter interfaces **********
- public interface Adapter<AV>
- extends BasePluggablePropertyValueModel.Adapter<AV>
+ public interface Adapter<V>
+ extends BasePluggablePropertyValueModel.Adapter<V>
{
/**
* Set the adapted model's value,
* based on the specified new value of the property value model.
*/
- void setValue(AV value);
+ void setValue(V value);
- interface Factory<AFV>
- extends BasePluggablePropertyValueModel.Adapter.Factory<AFV, Adapter<AFV>>
+ interface Factory<V>
+ extends BasePluggablePropertyValueModel.Adapter.Factory<V, Adapter<V>>
{
// NOP
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java
index ff2f905a05..a7bc54f549 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java
@@ -44,10 +44,6 @@ public class PluggableModifiablePropertyValueModelAdapter<V>
this.closure = closure;
}
- public void setValue(V value) {
- this.closure.execute(value);
- }
-
public V engageModel() {
return this.adapter.engageModel();
}
@@ -56,14 +52,23 @@ public class PluggableModifiablePropertyValueModelAdapter<V>
return this.adapter.disengageModel();
}
+ public void setValue(V value) {
+ this.closure.execute(value);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.adapter);
+ }
+
- // ********** PluggableModifiablePropertyValueModel.Adapter.Factory **********
+ // ********** Factory **********
public static class Factory<V>
implements PluggableModifiablePropertyValueModel.Adapter.Factory<V>
{
- /* CU private */ final BasePluggablePropertyValueModel.Adapter.Factory<V, ? extends BasePluggablePropertyValueModel.Adapter<V>> factory;
- /* CU private */ final Closure<? super V> closure;
+ private final BasePluggablePropertyValueModel.Adapter.Factory<V, ? extends BasePluggablePropertyValueModel.Adapter<V>> factory;
+ private final Closure<? super V> closure;
public Factory(BasePluggablePropertyValueModel.Adapter.Factory<V, ? extends BasePluggablePropertyValueModel.Adapter<V>> factory, Closure<? super V> closure) {
super();
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyValueModel.java
index 4a6991d59d..c2d9b5d10c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyValueModel.java
@@ -27,11 +27,11 @@ public final class PluggablePropertyValueModel<V>
// ********** Adapter interfaces **********
- public interface Adapter<AV>
- extends BasePluggablePropertyValueModel.Adapter<AV>
+ public interface Adapter<V>
+ extends BasePluggablePropertyValueModel.Adapter<V>
{
- interface Factory<AFV>
- extends BasePluggablePropertyValueModel.Adapter.Factory<AFV, Adapter<AFV>>
+ interface Factory<V>
+ extends BasePluggablePropertyValueModel.Adapter.Factory<V, Adapter<V>>
{
// NOP
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java
new file mode 100644
index 0000000000..a26367788f
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2016 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.model.Model;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * This adapter adapts an subject property value model whose value is another model
+ * and treats the <em>inner</em> model's value as this adapter's models's value.
+ * As a result, this adapter listens for changes to either model
+ * (<em>inner</em> or <em>subject</em>).
+ * <p>
+ * A typical usage:<br>A (simple) model <code>A</code> is wrapped by
+ * a transformation model <code>B</code> that transforms model <code>A</code>'s
+ * value to yet another model <code>C</code>. This adapter is
+ * then constructed with model <code>B</code>.<ul>
+ * <li>If model <code>A</code>'s value changes
+ * (e.g. as the result of an Eclipse-generated event), model <code>B</code>
+ * will recalculate its value, a new model <code>C</code>, and this adapter's value will
+ * be recalculated etc.</li>
+ * <li>If model <code>C</code>'s value changes
+ * (e.g. its value is deleted from the Eclipse workspace), this adapter's value will
+ * be recalculated etc.</li>
+ * </ul>
+ * This is an adapter that can be used by a {@link BasePluggablePropertyValueModel}.
+ *
+ * @param <V> the type of the adapter's value
+ * @param <S> the type of the subject (and the subject model's value)
+ * @param <SM> the type of the subject model
+ *
+ * @see BasePluggablePropertyValueModel
+ */
+public final class PropertyAspectAdapter<V, S extends Model, SM extends PropertyValueModel<? extends S>>
+ implements PluggablePropertyValueModel.Adapter<V>
+{
+ /** The subject model; whose value is cached as {@link #subject}. */
+ private final SM subjectModel;
+
+ /** Listens to {@link #subjectModel}. */
+ private final PropertyChangeListener subjectListener;
+
+ /** The subject; which is the value of {@link #subjectModel}. Can be <code>null</code>. */
+ /* package */ volatile S subject;
+
+ /** The name of the {@link #subject}'s aspect, which is transformed into the adapter's value. */
+ private final String aspectName;
+
+ /** The transformer that converts {@link #subject} into the adapter's value. */
+ private final Transformer<? super S, ? extends V> transformer;
+
+ /** Listens to {@link #subject}, if present. */
+ private final PropertyChangeListener aspectListener;
+
+ /** Backpointer to the <em>real</em> adapter. */
+ private final BasePluggablePropertyValueModel.Adapter.Listener<V> listener;
+
+
+ public PropertyAspectAdapter(Factory<V, S, SM> factory, BasePluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.subjectModel = factory.subjectModel;
+ this.subjectListener = new SubjectListener();
+
+ this.aspectName = factory.aspectName;
+ this.transformer = factory.transformer;
+
+ this.aspectListener = new AspectListener();
+
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ this.listener = listener;
+ }
+
+ /* CU private */ class SubjectListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ @SuppressWarnings("unchecked")
+ S newSubject = (S) event.getNewValue();
+ PropertyAspectAdapter.this.subjectChanged(newSubject);
+ }
+ }
+
+ /* CU private */ class AspectListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ @SuppressWarnings("unchecked")
+ V newValue = (V) event.getNewValue();
+ PropertyAspectAdapter.this.aspectChanged(newValue);
+ }
+ }
+
+
+ // ********** BasePluggablePropertyValueModel.Adapter **********
+
+ public V engageModel() {
+ this.subjectModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.subjectListener);
+ this.subject = this.subjectModel.getValue();
+ return this.engageSubject();
+ }
+
+ private V engageSubject() {
+ if (this.subject != null) {
+ this.subject.addPropertyChangeListener(this.aspectName, this.aspectListener);
+ }
+ return this.buildValue();
+ }
+
+ public V disengageModel() {
+ this.subjectModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.subjectListener);
+ return this.disengageSubject();
+ }
+
+ private V disengageSubject() {
+ if (this.subject != null) {
+ this.subject.removePropertyChangeListener(this.aspectName, this.aspectListener);
+ this.subject = null;
+ }
+ return null;
+ }
+
+
+ // ********** event handling **********
+
+ /**
+ * Move our aspect listener to the new subject.
+ */
+ protected void subjectChanged(S newSubject) {
+ this.disengageSubject();
+ this.subject = newSubject;
+ this.listener.valueChanged(this.engageSubject());
+ }
+
+ protected void aspectChanged(V newValue) {
+ this.listener.valueChanged(newValue);
+ }
+
+
+ // ********** misc **********
+
+ /* package */ V buildValue() {
+ return this.transformer.transform(this.subject);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.buildValue());
+ }
+
+
+ // ********** Factory **********
+
+ /**
+ * @see PropertyAspectAdapter
+ */
+ public static final class Factory<V, S extends Model, SM extends PropertyValueModel<? extends S>>
+ implements PluggablePropertyValueModel.Adapter.Factory<V>
+ {
+ /* CU private */ final SM subjectModel;
+ /* CU private */ final String aspectName;
+ /* CU private */ final Transformer<? super S, ? extends V> transformer;
+
+ public Factory(SM subjectModel, String aspectName, Transformer<? super S, ? extends V> transformer) {
+ super();
+ if (subjectModel == null) {
+ throw new NullPointerException();
+ }
+ this.subjectModel = subjectModel;
+
+ if (aspectName == null) {
+ throw new NullPointerException();
+ }
+ this.aspectName = aspectName;
+
+ if (transformer == null) {
+ throw new NullPointerException();
+ }
+ this.transformer = transformer;
+ }
+
+ public PropertyAspectAdapter<V, S, SM> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ return new PropertyAspectAdapter<>(this, listener);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggableModifiablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggableModifiablePropertyValueModelAdapter.java
deleted file mode 100644
index a0ac51af62..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggableModifiablePropertyValueModelAdapter.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * Adapt a {@link ModifiablePropertyValueModel property value model} to
- * another {@link ModifiablePropertyValueModel property value model}, sorta.
- * <p>
- * This adapter is constructed with a {@link ModifiablePropertyValueModel
- * property value model} and two {@link Transformer transformers} that can
- * transform the property to another value and vice versa.
- * <p>
- * This is an adapter that can be used by a {@link PluggableModifiablePropertyValueModel}.
- *
- * @param <V1> the type of the <em>wrapped</em> model's value
- * @param <V2> the type of the model's <em>derived</em> value
- *
- * @see PluggableModifiablePropertyValueModel
- */
-public final class PropertyPluggableModifiablePropertyValueModelAdapter<V1, V2>
- extends BasePropertyPluggablePropertyValueModelAdapter<V1, V2, ModifiablePropertyValueModel<V1>, PluggableModifiablePropertyValueModel.Adapter<V2>, PropertyPluggableModifiablePropertyValueModelAdapter.Factory<V1, V2>>
- implements PluggableModifiablePropertyValueModel.Adapter<V2>
-{
- private final Transformer<? super V2, ? extends V1> setTransformer;
-
- public PropertyPluggableModifiablePropertyValueModelAdapter(Factory<V1, V2> factory, BasePluggablePropertyValueModel.Adapter.Listener<V2> listener) {
- super(factory, listener);
- this.setTransformer = factory.setTransformer;
- }
-
- public void setValue(V2 value) {
- this.propertyModel.setValue(this.setTransformer.transform(value));
- }
-
-
- // ********** Factory **********
-
- public static class Factory<V1, V2>
- extends BasePropertyPluggablePropertyValueModelAdapter.Factory<V1, V2, ModifiablePropertyValueModel<V1>, PluggableModifiablePropertyValueModel.Adapter<V2>>
- implements PluggableModifiablePropertyValueModel.Adapter.Factory<V2>
- {
- /* CU private */ final Transformer<? super V2, ? extends V1> setTransformer;
-
- public Factory(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) {
- super(propertyModel, getTransformer);
- this.setTransformer = setTransformer;
- }
-
- @Override
- public PluggableModifiablePropertyValueModel.Adapter<V2> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V2> listener) {
- return new PropertyPluggableModifiablePropertyValueModelAdapter<>(this, listener);
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggablePropertyValueModelAdapter.java
index adbb3d04f1..e09258e8c3 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggablePropertyValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyPluggablePropertyValueModelAdapter.java
@@ -9,6 +9,9 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.transformer.Transformer;
@@ -18,7 +21,7 @@ import org.eclipse.jpt.common.utility.transformer.Transformer;
* <p>
* This adapter is constructed with a {@link PropertyValueModel
* property value model} and a {@link Transformer transformer} that can
- * transform the property to another value.
+ * transform the wrapped model's value to this model's derived value.
* <p>
* This is an adapter that can be used by a {@link PluggablePropertyValueModel}.
*
@@ -28,28 +31,104 @@ import org.eclipse.jpt.common.utility.transformer.Transformer;
* @see PluggablePropertyValueModel
*/
public final class PropertyPluggablePropertyValueModelAdapter<V1, V2>
- extends BasePropertyPluggablePropertyValueModelAdapter<V1, V2, PropertyValueModel<? extends V1>, PluggablePropertyValueModel.Adapter<V2>, PropertyPluggablePropertyValueModelAdapter.Factory<V1, V2>>
- implements PluggablePropertyValueModel.Adapter<V2>
+ implements PluggablePropertyValueModel.Adapter<V2>, PropertyChangeListener
{
+ /** The wrapped model */
+ private final PropertyValueModel<? extends V1> propertyModel;
+
+ /** Transformer that converts the wrapped model's value to this model's value. */
+ private final Transformer<? super V1, ? extends V2> transformer;
+
+ /** The <em>real</em> adapter. */
+ private final BasePluggablePropertyValueModel.Adapter.Listener<V2> listener;
+
+ /** Cached copy of model's value. */
+ /* package */ volatile V1 propertyModelValue;
+
+
+ // ********** constructors **********
public PropertyPluggablePropertyValueModelAdapter(Factory<V1, V2> factory, BasePluggablePropertyValueModel.Adapter.Listener<V2> listener) {
- super(factory, listener);
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.propertyModel = factory.propertyModel;
+ this.transformer = factory.transformer;
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ this.listener = listener;
+ }
+
+
+ // ********** BasePluggablePropertyValueModel.Adapter **********
+
+ public V2 engageModel() {
+ this.propertyModel.addPropertyChangeListener(PropertyValueModel.VALUE, this);
+ this.propertyModelValue = this.propertyModel.getValue();
+ return this.buildValue();
+ }
+
+ public V2 disengageModel() {
+ this.propertyModel.removePropertyChangeListener(PropertyValueModel.VALUE, this);
+ this.propertyModelValue = null;
+ return null;
+ }
+
+
+ // ********** PropertyChangeListener **********
+
+ @SuppressWarnings("unchecked")
+ public void propertyChanged(PropertyChangeEvent event) {
+ this.propertyModelValue = (V1) event.getNewValue();
+ this.update();
+ }
+
+
+ // ********** misc **********
+
+ private void update() {
+ this.listener.valueChanged(this.buildValue());
+ }
+
+ private V2 buildValue() {
+ return this.transformer.transform(this.propertyModelValue);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.buildValue());
}
// ********** Factory **********
public static class Factory<V1, V2>
- extends BasePropertyPluggablePropertyValueModelAdapter.Factory<V1, V2, PropertyValueModel<? extends V1>, PluggablePropertyValueModel.Adapter<V2>>
implements PluggablePropertyValueModel.Adapter.Factory<V2>
{
+ /* CU private */ final PropertyValueModel<? extends V1> propertyModel;
+ /* CU private */ final Transformer<? super V1, ? extends V2> transformer;
+
public Factory(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) {
- super(propertyModel, transformer);
+ super();
+ if (propertyModel == null) {
+ throw new NullPointerException();
+ }
+ this.propertyModel = propertyModel;
+ if (transformer == null) {
+ throw new NullPointerException();
+ }
+ this.transformer = transformer;
}
- @Override
- public PluggablePropertyValueModel.Adapter<V2> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V2> listener) {
+ public PropertyPluggablePropertyValueModelAdapter<V1, V2> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V2> listener) {
return new PropertyPluggablePropertyValueModelAdapter<>(this, listener);
}
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this);
+ }
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java
index 7907f101fa..b4765d099c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java
@@ -11,11 +11,15 @@ package org.eclipse.jpt.common.utility.internal.model.value;
import java.util.Collection;
import org.eclipse.jpt.common.utility.Association;
+import org.eclipse.jpt.common.utility.closure.BiClosure;
import org.eclipse.jpt.common.utility.closure.Closure;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.SimpleAssociation;
+import org.eclipse.jpt.common.utility.internal.closure.ClosureTools;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
+import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -27,7 +31,6 @@ import org.eclipse.jpt.common.utility.transformer.Transformer;
*/
public final class PropertyValueModelTools {
-
// ********** Boolean adapters **********
/**
@@ -211,7 +214,11 @@ public final class PropertyValueModelTools {
* @see #valueAffirms_(PropertyValueModel, Predicate)
* @see #valueAffirms(PropertyValueModel, Predicate, Boolean)
*/
- public static <V> PropertyValueModel<Boolean> valueAffirms(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> predicate, boolean nullResult) {
+ public static <V> PropertyValueModel<Boolean> valueAffirms(
+ PropertyValueModel<? extends V> propertyModel,
+ Predicate<? super V> predicate,
+ boolean nullResult
+ ) {
return valueAffirms(propertyModel, predicate, Boolean.valueOf(nullResult));
}
@@ -228,7 +235,11 @@ public final class PropertyValueModelTools {
* @see #valueAffirms_(PropertyValueModel, Predicate)
* @see #valueAffirms(PropertyValueModel, Predicate, boolean)
*/
- public static <V> PropertyValueModel<Boolean> valueAffirms(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> predicate, Boolean nullResult) {
+ public static <V> PropertyValueModel<Boolean> valueAffirms(
+ PropertyValueModel<? extends V> propertyModel,
+ Predicate<? super V> predicate,
+ Boolean nullResult
+ ) {
return transform_(propertyModel, TransformerTools.adapt(predicate, nullResult));
}
@@ -376,7 +387,11 @@ public final class PropertyValueModelTools {
* @see #filter(PropertyValueModel, Class)
* @see PredicateTools#instanceOf(Class)
*/
- public static <V> PropertyValueModel<V> filter(PropertyValueModel<?> propertyModel, Class<V> clazz, V defaultValue) {
+ public static <V> PropertyValueModel<V> filter(
+ PropertyValueModel<?> propertyModel,
+ Class<V> clazz,
+ V defaultValue
+ ) {
return transform(propertyModel, TransformerTools.cast(TransformerTools.filteringTransformer(PredicateTools.instanceOf(clazz), defaultValue)));
}
@@ -392,7 +407,11 @@ public final class PropertyValueModelTools {
* @see #filter(PropertyValueModel, Class)
* @see PredicateTools#instanceOf(Class)
*/
- public static <V> PropertyValueModel<V> filter_(PropertyValueModel<?> propertyModel, Class<V> clazz, V defaultValue) {
+ public static <V> PropertyValueModel<V> filter_(
+ PropertyValueModel<?> propertyModel,
+ Class<V> clazz,
+ V defaultValue
+ ) {
return transform_(propertyModel, TransformerTools.cast(TransformerTools.filteringTransformer(PredicateTools.instanceOf(clazz), defaultValue)));
}
@@ -448,7 +467,11 @@ public final class PropertyValueModelTools {
* @see #filter_(PropertyValueModel, Predicate, Object)
* @see PluggablePropertyValueModel
*/
- public static <V> PropertyValueModel<V> filter(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> filter, V defaultValue) {
+ public static <V> PropertyValueModel<V> filter(
+ PropertyValueModel<? extends V> propertyModel,
+ Predicate<? super V> filter,
+ V defaultValue
+ ) {
return filter_(propertyModel, PredicateTools.nullCheck(filter), defaultValue);
}
@@ -466,41 +489,14 @@ public final class PropertyValueModelTools {
* @see #filter_(PropertyValueModel, Predicate)
* @see PluggablePropertyValueModel
*/
- public static <V> PropertyValueModel<V> filter_(PropertyValueModel<? extends V> propertyModel, Predicate<? super V> filter, V defaultValue) {
+ public static <V> PropertyValueModel<V> filter_(
+ PropertyValueModel<? extends V> propertyModel,
+ Predicate<? super V> filter,
+ V defaultValue
+ ) {
return transform_(propertyModel, TransformerTools.filteringTransformer(filter, defaultValue));
}
- /**
- * Construct a modifiable property value model that wraps the specified
- * modifiable property value model and filters its value with the specified
- * filters. If the wrapped value passes the "get" filter,
- * the model simply returns it; otherwise it returns <code>null</code>.
- * If a new value passes the "set" filter, the model passes it to the wrapped
- * model; otherwise it sets the wrapped model's value to <code>null</code>.
- *
- * @see #filterModifiable(ModifiablePropertyValueModel, Predicate, Object, Predicate, Object)
- * @see PluggablePropertyValueModel
- */
- public static <V> ModifiablePropertyValueModel<V> filterModifiable(ModifiablePropertyValueModel<V> propertyModel, Predicate<? super V> getFilter, Predicate<? super V> setFilter) {
- return filterModifiable(propertyModel, getFilter, null, setFilter, null);
- }
-
- /**
- * Construct a modifiable property value model that wraps the specified
- * modifiable property value model and filters its value with the specified
- * filters. If the wrapped value passes the "get" filter,
- * the model simply returns it; otherwise it returns the specified
- * default "get" value.
- * If a new value passes the "set" filter, the model passes it to the wrapped
- * model; otherwise it sets the wrapped model's value to the specified
- * default "set" value.
- *
- * @see PluggablePropertyValueModel
- */
- public static <V> ModifiablePropertyValueModel<V> filterModifiable(ModifiablePropertyValueModel<V> propertyModel, Predicate<? super V> getFilter, V defaultGetValue, Predicate<? super V> setFilter, V defaultSetValue) {
- return transform(propertyModel, TransformerTools.filteringTransformer(getFilter, defaultGetValue), TransformerTools.filteringTransformer(setFilter, defaultSetValue));
- }
-
// ********** buffered wrapper **********
@@ -516,13 +512,18 @@ public final class PropertyValueModelTools {
/**
* Construct a property value model that wraps the specified
- * property value model and buffers its value, using the specified trigger.
+ * property value model and buffers its value using the specified trigger.
+ * Return an association of the buffered model and another boolean model
+ * that indicates whether the buffered model is actually buffering a value.
*
* @see BufferedPropertyValueModelAdapter
* @see #bufferedPropertyValueModelAdapterTrigger()
* @see PluggablePropertyValueModel
*/
- public static <V> Association<ModifiablePropertyValueModel<V>, PropertyValueModel<Boolean>> buffer(ModifiablePropertyValueModel<V> propertyModel, BufferedPropertyValueModelAdapter.Trigger trigger) {
+ public static <V> Association<ModifiablePropertyValueModel<V>, PropertyValueModel<Boolean>> buffer(
+ ModifiablePropertyValueModel<V> propertyModel,
+ BufferedPropertyValueModelAdapter.Trigger trigger
+ ) {
BufferedPropertyValueModelAdapter.Factory<V> factory = new BufferedPropertyValueModelAdapter.Factory<>(propertyModel, trigger);
ModifiablePropertyValueModel<V> model = modifiablePropertyValueModel(factory);
PropertyValueModel<Boolean> bufferingModel = factory.getBufferingModel();
@@ -556,7 +557,10 @@ public final class PropertyValueModelTools {
*
* @see PluggablePropertyValueModel
*/
- public static <V1, V2> PropertyValueModel<V2> transform(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) {
+ public static <V1, V2> PropertyValueModel<V2> transform(
+ PropertyValueModel<? extends V1> propertyModel,
+ Transformer<? super V1, ? extends V2> transformer
+ ) {
return propertyValueModel(pluggablePropertyValueModelAdapterFactory(propertyModel, transformer));
}
@@ -569,13 +573,51 @@ public final class PropertyValueModelTools {
*
* @see PluggablePropertyValueModel
*/
- public static <V1, V2> PropertyValueModel<V2> transform_(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) {
+ public static <V1, V2> PropertyValueModel<V2> transform_(
+ PropertyValueModel<? extends V1> propertyModel,
+ Transformer<? super V1, ? extends V2> transformer
+ ) {
return propertyValueModel(pluggablePropertyValueModelAdapterFactory_(propertyModel, transformer));
}
/**
* Construct a modifiable property value model that wraps the specified
* property value model and transforms its value with the specified
+ * transformers.
+ * <p>
+ * <strong>NB:</strong> The specified transformers will <em>never</em> be passed a <code>null</code> input.
+ * Instead, a <code>null</code> input will be transformed into a <code>null</code> output.
+ *
+ * @see PluggablePropertyValueModel
+ */
+ public static <V1, V2> ModifiablePropertyValueModel<V2> transform(
+ ModifiablePropertyValueModel<V1> propertyModel,
+ Transformer<? super V1, ? extends V2> getTransformer,
+ Transformer<? super V2, ? extends V1> setTransformer
+ ) {
+ return transform_(propertyModel, TransformerTools.nullCheck(getTransformer), TransformerTools.nullCheck(setTransformer));
+ }
+
+ /**
+ * Construct a modifiable property value model that wraps the specified
+ * property value model and transforms its value with the specified
+ * transformers.
+ * <p>
+ * <strong>NB:</strong> The specified transformers must be able to handle a <code>null</code> input.
+ *
+ * @see PluggablePropertyValueModel
+ */
+ public static <V1, V2> ModifiablePropertyValueModel<V2> transform_(
+ ModifiablePropertyValueModel<V1> propertyModel,
+ Transformer<? super V1, ? extends V2> getTransformer,
+ Transformer<? super V2, ? extends V1> setTransformer
+ ) {
+ return transform_(propertyModel, getTransformer, setTransformerClosureAdapter(propertyModel, setTransformer));
+ }
+
+ /**
+ * Construct a modifiable property value model that wraps the specified
+ * property value model and transforms its value with the specified
* transformer. The specified closure is invoked when the model's value is set.
* <p>
* <strong>NB:</strong> The specified transformer will <em>never</em> be passed a <code>null</code> input.
@@ -583,7 +625,11 @@ public final class PropertyValueModelTools {
*
* @see PluggablePropertyValueModel
*/
- public static <V1, V2> ModifiablePropertyValueModel<V2> transform(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer, Closure<? super V2> setValueClosure) {
+ public static <V1, V2> ModifiablePropertyValueModel<V2> transform(
+ PropertyValueModel<? extends V1> propertyModel,
+ Transformer<? super V1, ? extends V2> transformer,
+ Closure<? super V2> setValueClosure
+ ) {
return pluggableModifiablePropertyValueModel(pluggablePropertyValueModelAdapterFactory(propertyModel, transformer), setValueClosure);
}
@@ -596,7 +642,11 @@ public final class PropertyValueModelTools {
*
* @see PluggablePropertyValueModel
*/
- public static <V1, V2> ModifiablePropertyValueModel<V2> transform_(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer, Closure<? super V2> setValueClosure) {
+ public static <V1, V2> ModifiablePropertyValueModel<V2> transform_(
+ PropertyValueModel<? extends V1> propertyModel,
+ Transformer<? super V1, ? extends V2> transformer,
+ Closure<? super V2> setValueClosure
+ ) {
return pluggableModifiablePropertyValueModel(pluggablePropertyValueModelAdapterFactory_(propertyModel, transformer), setValueClosure);
}
@@ -609,7 +659,10 @@ public final class PropertyValueModelTools {
*
* @see PluggablePropertyValueModel
*/
- public static <V1, V2> PluggablePropertyValueModel.Adapter.Factory<V2> pluggablePropertyValueModelAdapterFactory(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) {
+ public static <V1, V2> PluggablePropertyValueModel.Adapter.Factory<V2> pluggablePropertyValueModelAdapterFactory(
+ PropertyValueModel<? extends V1> propertyModel,
+ Transformer<? super V1, ? extends V2> transformer
+ ) {
return pluggablePropertyValueModelAdapterFactory_(propertyModel, TransformerTools.nullCheck(transformer));
}
@@ -621,93 +674,434 @@ public final class PropertyValueModelTools {
*
* @see PluggablePropertyValueModel
*/
- public static <V1, V2> PluggablePropertyValueModel.Adapter.Factory<V2> pluggablePropertyValueModelAdapterFactory_(PropertyValueModel<? extends V1> propertyModel, Transformer<? super V1, ? extends V2> transformer) {
+ public static <V1, V2> PluggablePropertyValueModel.Adapter.Factory<V2> pluggablePropertyValueModelAdapterFactory_(
+ PropertyValueModel<? extends V1> propertyModel,
+ Transformer<? super V1, ? extends V2> transformer
+ ) {
return new PropertyPluggablePropertyValueModelAdapter.Factory<>(propertyModel, transformer);
}
+
+ // ********** misc **********
+
/**
- * Construct a property value model that wraps the specified
- * property value model and transforms its value with the specified
- * transformer.
- * <p>
- * <strong>NB:</strong> The specified transformers will <em>never</em> be passed a <code>null</code> input.
- * Instead, a <code>null</code> input will be transformed into a <code>null</code> output.
- *
- * @see PluggablePropertyValueModel
+ * Construct a "set" closure that wraps the specified modifiable property value model and
+ * uses the specified "set" transformer to transform the incoming value before
+ * forwarding it to the model.
*/
- public static <V1, V2> ModifiablePropertyValueModel<V2> transform(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) {
- return modifiablePropertyValueModel(pluggableModifiablePropertyValueModelAdapterFactory(propertyModel, getTransformer, setTransformer));
+ public static <V1, V2> Closure<V2> setTransformerClosureAdapter(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V2, ? extends V1> setTransformer) {
+ return new SetTransformerClosureAdapter<>(propertyModel, setTransformer);
}
/**
- * Construct a property value model that wraps the specified
- * property value model and transforms its value with the specified
- * transformer.
- * <p>
- * <strong>NB:</strong> The specified transformers must be able to handle a <code>null</code> input.
- *
- * @see PluggablePropertyValueModel
+ * "Set" closure that wraps a modifiable property value model and
+ * uses a "set" transformer to transform the incoming value before
+ * forwarding it to the model.
+ */
+ public static final class SetTransformerClosureAdapter<V1, V2>
+ implements Closure<V2>
+ {
+ private final ModifiablePropertyValueModel<V1> propertyModel;
+ private final Transformer<? super V2, ? extends V1> setTransformer;
+
+ public SetTransformerClosureAdapter(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V2, ? extends V1> setTransformer) {
+ super();
+ if (propertyModel == null) {
+ throw new NullPointerException();
+ }
+ this.propertyModel = propertyModel;
+ if (setTransformer == null) {
+ throw new NullPointerException();
+ }
+ this.setTransformer = setTransformer;
+ }
+
+ public void execute(V2 value) {
+ this.propertyModel.setValue(this.setTransformer.transform(value));
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.setTransformer);
+ }
+ }
+
+ /**
+ * Construct a "set" closure that wraps another "set" closure and
+ * provides a hook to do nothing if the target object is <code>null</code>.
*/
- public static <V1, V2> ModifiablePropertyValueModel<V2> transform_(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) {
- return modifiablePropertyValueModel(pluggableModifiablePropertyValueModelAdapterFactory_(propertyModel, getTransformer, setTransformer));
+ public static <A1, A2> BiClosure<A1, A2> nullCheckSetClosureWrapper(BiClosure<? super A1, ? super A2> closure) {
+ return nullCheckSetClosureWrapper(closure, ClosureTools.nullClosure());
}
/**
- * Construct a pluggable property value model adapter factory for the specified
- * property value model and transformer.
- * <p>
- * <strong>NB:</strong> The specified transformers will <em>never</em> be passed a <code>null</code> input.
- * Instead, a <code>null</code> input will be transformed into a <code>null</code> output.
- *
- * @see PluggablePropertyValueModel
+ * Construct a "set" closure that wraps another "set" closure and
+ * provides a hook to execute a different closure
+ * if the target object is <code>null</code>.
*/
- public static <V1, V2> PluggableModifiablePropertyValueModel.Adapter.Factory<V2> pluggableModifiablePropertyValueModelAdapterFactory(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) {
- return pluggableModifiablePropertyValueModelAdapterFactory_(propertyModel, TransformerTools.nullCheck(getTransformer), TransformerTools.nullCheck(setTransformer));
+ public static <A1, A2> BiClosure<A1, A2> nullCheckSetClosureWrapper(BiClosure<? super A1, ? super A2> closure, Closure<? super A2> nullTargetSetClosure) {
+ return new NullCheckSetClosureWrapper<>(closure, nullTargetSetClosure);
}
/**
- * Construct a pluggable property value model adapter factory for the specified
- * property value model and transformer.
- * <p>
- * <strong>NB:</strong> The specified transformers must be able to handle a <code>null</code> input.
- *
- * @see PluggablePropertyValueModel
+ * "Set" closure that wraps another "set" closure and
+ * provides a hook to execute a different closure
+ * if the target object is <code>null</code>.
+ */
+ public static final class NullCheckSetClosureWrapper<A1, A2>
+ implements BiClosure<A1, A2>
+ {
+ private final BiClosure<? super A1, ? super A2> closure;
+ private final Closure<? super A2> nullTargetClosure;
+
+ public NullCheckSetClosureWrapper(BiClosure<? super A1, ? super A2> closure, Closure<? super A2> nullTargetClosure) {
+ super();
+ if (closure == null) {
+ throw new NullPointerException();
+ }
+ this.closure = closure;
+ if (nullTargetClosure == null) {
+ throw new NullPointerException();
+ }
+ this.nullTargetClosure = nullTargetClosure;
+ }
+
+ public void execute(A1 argument1, A2 argument2) {
+ if (argument1 != null) {
+ this.closure.execute(argument1, argument2);
+ } else {
+ this.nullTargetClosure.execute(argument2);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.closure);
+ }
+ }
+
+ /**
+ * Construct a "set" bi-closure that wraps another "set" closure and
+ * forwards only the second argument to it.
*/
- public static <V1, V2> PluggableModifiablePropertyValueModel.Adapter.Factory<V2> pluggableModifiablePropertyValueModelAdapterFactory_(ModifiablePropertyValueModel<V1> propertyModel, Transformer<? super V1, ? extends V2> getTransformer, Transformer<? super V2, ? extends V1> setTransformer) {
- return new PropertyPluggableModifiablePropertyValueModelAdapter.Factory<>(propertyModel, getTransformer, setTransformer);
+ public static <A1, A2> BiClosure<A1, A2> setClosureAdapter(Closure<? super A2> closure) {
+ return new SetClosureAdapter<>(closure);
+ }
+
+ /**
+ * "Set" bi-closure that wraps another "set" closure and
+ * forwards only the second argument to it.
+ */
+ public static final class SetClosureAdapter<A1, A2>
+ implements BiClosure<A1, A2>
+ {
+ private final Closure<? super A2> closure;
+
+ public SetClosureAdapter(Closure<? super A2> closure) {
+ super();
+ if (closure == null) {
+ throw new NullPointerException();
+ }
+ this.closure = closure;
+ }
+
+ public void execute(A1 argument1, A2 argument2) {
+ this.closure.execute(argument2);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.closure);
+ }
}
// ********** compound PVMs **********
/**
- * Construct a compound property value model for the specified <em>outer</em> property value model.
+ * Construct a compound property value model for the
+ * specified <em>outer</em> property value model.
+ * <p>
+ * <strong>NB:</strong>
+ * If the <em>outer</em> model's value is ever <code>null</code>,
+ * the model's value will also be <code>null</code>.
*/
public static <V> PropertyValueModel<V> compound(PropertyValueModel<? extends PropertyValueModel<? extends V>> outerModel) {
return propertyValueModel(compoundPropertyValueModelAdapterFactory(outerModel));
}
/**
- * Construct a compound property value model adapter factory for the specified <em>outer</em> property value model.
+ * Construct a compound property value model for the
+ * specified <em>outer</em> property value model.
+ * <p>
+ * <strong>NB:</strong>
+ * If the <em>outer</em> model's value is ever <code>null</code>,
+ * the model will throw a {@link NullPointerException}.
*/
- public static <V> PluggablePropertyValueModel.Adapter.Factory<V> compoundPropertyValueModelAdapterFactory(PropertyValueModel<? extends PropertyValueModel<? extends V>> outerModel) {
- return new CompoundPropertyValueModelAdapter.Factory<>(outerModel);
+ public static <V> PropertyValueModel<V> compound_(PropertyValueModel<? extends PropertyValueModel<? extends V>> outerModel) {
+ return propertyValueModel(compoundPropertyValueModelAdapterFactory_(outerModel));
+ }
+
+ /**
+ * Construct a compound property value model adapter factory for
+ * the specified <em>outer</em> property value model.
+ * <p>
+ * <strong>NB:</strong>
+ * If the <em>outer</em> model's value is ever <code>null</code>,
+ * the factory's model's value will also be <code>null</code>.
+ */
+ public static <V, IM extends PropertyValueModel<? extends V>, OM extends PropertyValueModel<? extends IM>> PropertyAspectAdapter.Factory<V, IM, OM> compoundPropertyValueModelAdapterFactory(OM outerModel) {
+ return aspectAdapterFactory_(
+ outerModel,
+ PropertyValueModel.VALUE,
+ valueTransformer()
+ );
+ }
+
+ /**
+ * Construct a compound property value model adapter factory for
+ * the specified <em>outer</em> property value model.
+ * <p>
+ * <strong>NB:</strong>
+ * If the <em>outer</em> model's value is ever <code>null</code>,
+ * the factory's model will throw a {@link NullPointerException}.
+ */
+ public static <V, IM extends PropertyValueModel<? extends V>, OM extends PropertyValueModel<? extends IM>> PropertyAspectAdapter.Factory<V, IM, OM> compoundPropertyValueModelAdapterFactory_(OM outerModel) {
+ return aspectAdapterFactory_(
+ outerModel,
+ PropertyValueModel.VALUE,
+ valueTransformer_()
+ );
}
/**
* Construct a modifiable compound property value model
* for the specified <em>outer</em> property value model.
+ * <p>
+ * <strong>NB:</strong>
+ * If the <em>outer</em> model's value is ever <code>null</code>,
+ * the model's value will also be <code>null</code>
+ * and, if the model's value is set, it will do nothing.
*/
public static <V> ModifiablePropertyValueModel<V> compoundModifiable(PropertyValueModel<? extends ModifiablePropertyValueModel<V>> outerModel) {
return modifiablePropertyValueModel(compoundModifiablePropertyValueModelAdapterFactory(outerModel));
}
/**
+ * Construct a modifiable compound property value model
+ * for the specified <em>outer</em> property value model.
+ * <p>
+ * <strong>NB:</strong>
+ * If the <em>outer</em> model's value is ever <code>null</code>,
+ * the model will throw a {@link NullPointerException}
+ * when either its value is get or set.
+ */
+ public static <V> ModifiablePropertyValueModel<V> compoundModifiable_(PropertyValueModel<? extends ModifiablePropertyValueModel<V>> outerModel) {
+ return modifiablePropertyValueModel(compoundModifiablePropertyValueModelAdapterFactory_(outerModel));
+ }
+
+ /**
* Construct a modifiable compound property value model adapter factory
* for the specified <em>outer</em> property value model.
+ * <p>
+ * <strong>NB:</strong>
+ * If the <em>outer</em> model's value is ever <code>null</code>,
+ * the model's value will also be <code>null</code>
+ * and, if the model's value is set, it will do nothing.
*/
public static <V> PluggableModifiablePropertyValueModel.Adapter.Factory<V> compoundModifiablePropertyValueModelAdapterFactory(PropertyValueModel<? extends ModifiablePropertyValueModel<V>> outerModel) {
- return new CompoundModifiablePropertyValueModelAdapter.Factory<>(outerModel);
+ return modifiablePropertyAspectAdapterFactory_(
+ compoundPropertyValueModelAdapterFactory(outerModel),
+ setValueClosure()
+ );
+ }
+
+ /**
+ * Construct a modifiable compound property value model adapter factory
+ * for the specified <em>outer</em> property value model.
+ * <p>
+ * <strong>NB:</strong>
+ * If the <em>outer</em> model's value is ever <code>null</code>,
+ * the factory's model will throw a {@link NullPointerException}
+ * when either its value is get or set.
+ */
+ public static <V> PluggableModifiablePropertyValueModel.Adapter.Factory<V> compoundModifiablePropertyValueModelAdapterFactory_(PropertyValueModel<? extends ModifiablePropertyValueModel<V>> outerModel) {
+ return modifiablePropertyAspectAdapterFactory_(
+ compoundPropertyValueModelAdapterFactory_(outerModel),
+ setValueClosure_()
+ );
+ }
+
+
+ // ********** aspect adapters **********
+
+ /**
+ * Construct a property aspect adapter for the
+ * specified subject model, aspect name, and transformer.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified transformer will <em>never</em> be passed a <code>null</code> subject.
+ * Instead, a <code>null</code> subject will be transformed into a <code>null</code> value.
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<? extends S>> PropertyValueModel<V> aspectAdapter(
+ SM subjectModel,
+ String aspectName,
+ Transformer<? super S, ? extends V> transformer
+ ) {
+ return propertyValueModel(aspectAdapterFactory(subjectModel, aspectName, transformer));
+ }
+
+ /**
+ * Construct a property aspect adapter for the
+ * specified subject model, aspect name, and transformer.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified transformer must be able to handle a <code>null</code> subject.
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<? extends S>> PropertyValueModel<V> aspectAdapter_(
+ SM subjectModel,
+ String aspectName,
+ Transformer<? super S, ? extends V> transformer
+ ) {
+ return propertyValueModel(aspectAdapterFactory_(subjectModel, aspectName, transformer));
+ }
+
+ /**
+ * Construct a property aspect adapter factory for the
+ * specified subject model, aspect name, and transformer.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified transformer will <em>never</em> be passed a <code>null</code> subject.
+ * Instead, a <code>null</code> subject will be transformed into a <code>null</code> value.
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<? extends S>> PropertyAspectAdapter.Factory<V, S, SM> aspectAdapterFactory(
+ SM subjectModel,
+ String aspectName,
+ Transformer<? super S, ? extends V> transformer
+ ) {
+ return aspectAdapterFactory_(subjectModel, aspectName, TransformerTools.nullCheck(transformer));
+ }
+
+ /**
+ * Construct a property aspect adapter factory for the
+ * specified subject model, aspect name, and transformer.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified transformer must be able to handle a <code>null</code> subject.
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<? extends S>> PropertyAspectAdapter.Factory<V, S, SM> aspectAdapterFactory_(
+ SM subjectModel,
+ String aspectName,
+ Transformer<? super S, ? extends V> transformer
+ ) {
+ return new PropertyAspectAdapter.Factory<>(subjectModel, aspectName, transformer);
+ }
+
+
+ // ********** modifiable aspect adapters **********
+
+ /**
+ * Construct a modifiable property aspect adapter for the
+ * specified subject model, aspect name, transformer, and closure.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified transformer will <em>never</em> be passed a <code>null</code> subject.
+ * Instead, a <code>null</code> subject will be transformed into a <code>null</code> value.
+ * Likewise, if the subject is <code>null</code>, the specified closure will
+ * not be executed.
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<S>> ModifiablePropertyValueModel<V> modifiablePropertyAspectAdapter(
+ SM subjectModel,
+ String aspectName,
+ Transformer<? super S, ? extends V> getTransformer,
+ BiClosure<? super S, ? super V> setClosure
+ ) {
+ return modifiablePropertyValueModel(modifiablePropertyAspectAdapterFactory(subjectModel, aspectName, getTransformer, setClosure));
+ }
+
+ /**
+ * Construct a modifiable property aspect adapter for the
+ * specified subject model, aspect name, transformer, and closure.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified transformer must be able to handle a <code>null</code> subject.
+ * Likewise, the specified closure must be able to handle a <code>null</code>
+ * subject (i.e. first argument).
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<S>> ModifiablePropertyValueModel<V> modifiablePropertyAspectAdapter_(
+ SM subjectModel,
+ String aspectName,
+ Transformer<? super S, ? extends V> getTransformer,
+ BiClosure<? super S, ? super V> setClosure
+ ) {
+ return modifiablePropertyValueModel(modifiablePropertyAspectAdapterFactory_(subjectModel, aspectName, getTransformer, setClosure));
+ }
+
+ /**
+ * Construct a modifiable property aspect adapter factory for the
+ * specified subject model, aspect name, transformer, and closure.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified transformer will <em>never</em> be passed a <code>null</code> subject.
+ * Instead, a <code>null</code> subject will be transformed into a <code>null</code> value.
+ * Likewise, if the subject is <code>null</code>, the specified closure will
+ * not be executed.
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<S>> PluggableModifiablePropertyValueModel.Adapter.Factory<V> modifiablePropertyAspectAdapterFactory(
+ SM subjectModel,
+ String aspectName,
+ Transformer<? super S, ? extends V> getTransformer,
+ BiClosure<? super S, ? super V> setClosure
+ ) {
+ return modifiablePropertyAspectAdapterFactory(aspectAdapterFactory(subjectModel, aspectName, getTransformer), setClosure);
+ }
+
+ /**
+ * Construct a modifiable property aspect adapter factory for the
+ * specified subject model, aspect name, transformer, and closure.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified transformer must be able to handle a <code>null</code> subject.
+ * Likewise, the specified closure must be able to handle a <code>null</code>
+ * subject (i.e. first argument).
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<S>> PluggableModifiablePropertyValueModel.Adapter.Factory<V> modifiablePropertyAspectAdapterFactory_(
+ SM subjectModel,
+ String aspectName,
+ Transformer<? super S, ? extends V> getTransformer,
+ BiClosure<? super S, ? super V> setClosure
+ ) {
+ return modifiablePropertyAspectAdapterFactory_(aspectAdapterFactory_(subjectModel, aspectName, getTransformer), setClosure);
+ }
+
+ /**
+ * Construct a modifiable property aspect adapter factory for the
+ * specified factory and closure.
+ * <p>
+ * <strong>NB:</strong>
+ * If the subject is <code>null</code>, the specified closure will
+ * not be executed.
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<S>> PluggableModifiablePropertyValueModel.Adapter.Factory<V> modifiablePropertyAspectAdapterFactory(
+ PropertyAspectAdapter.Factory<V, S, SM> factory,
+ BiClosure<? super S, ? super V> setClosure
+ ) {
+ return modifiablePropertyAspectAdapterFactory_(factory, nullCheckSetClosureWrapper(setClosure));
+ }
+
+ /**
+ * Construct a modifiable property aspect adapter factory for the
+ * specified factory and closure.
+ * <p>
+ * <strong>NB:</strong>
+ * The specified closure must be able to handle a <code>null</code>
+ * subject (i.e. first argument).
+ */
+ public static <V, S extends Model, SM extends PropertyValueModel<S>> PluggableModifiablePropertyValueModel.Adapter.Factory<V> modifiablePropertyAspectAdapterFactory_(
+ PropertyAspectAdapter.Factory<V, S, SM> factory,
+ BiClosure<? super S, ? super V> setClosure
+ ) {
+ return new ModifiablePropertyAspectAdapter.Factory<>(factory, setClosure);
}
@@ -723,21 +1117,23 @@ public final class PropertyValueModelTools {
}
/**
- * Construct a modifiable property value model adapter for the specified adapter factory.
+ * Construct a <em>modifiable</em> property value model adapter for the specified
+ * property value model adapter adapter factory and closure.
+ * The specified closure is invoked when the model's value is set.
*
* @see PluggableModifiablePropertyValueModel
*/
- public static <V> ModifiablePropertyValueModel<V> modifiablePropertyValueModel(PluggableModifiablePropertyValueModel.Adapter.Factory<V> adapterFactory) {
- return new PluggableModifiablePropertyValueModel<>(adapterFactory);
+ public static <V> ModifiablePropertyValueModel<V> pluggableModifiablePropertyValueModel(BasePluggablePropertyValueModel.Adapter.Factory<V, ? extends BasePluggablePropertyValueModel.Adapter<V>> factory, Closure<? super V> setValueClosure) {
+ return modifiablePropertyValueModel(new PluggableModifiablePropertyValueModelAdapter.Factory<>(factory, setValueClosure));
}
/**
- * Construct a <em>modifiable</em> property value model adapter for the specified
- * property value model adapter adapter factory and closure.
- * The specified closure is invoked when the model's value is set.
+ * Construct a modifiable property value model adapter for the specified adapter factory.
+ *
+ * @see PluggableModifiablePropertyValueModel
*/
- public static <V> ModifiablePropertyValueModel<V> pluggableModifiablePropertyValueModel(BasePluggablePropertyValueModel.Adapter.Factory<V, ? extends BasePluggablePropertyValueModel.Adapter<V>> factory, Closure<? super V> setValueClosure) {
- return new PluggableModifiablePropertyValueModel<>(new PluggableModifiablePropertyValueModelAdapter.Factory<>(factory, setValueClosure));
+ public static <V> ModifiablePropertyValueModel<V> modifiablePropertyValueModel(PluggableModifiablePropertyValueModel.Adapter.Factory<V> adapterFactory) {
+ return new PluggableModifiablePropertyValueModel<>(adapterFactory);
}
@@ -753,44 +1149,93 @@ public final class PropertyValueModelTools {
}
- // ********** value transformers **********
+ // ********** value transformers/closures **********
/**
* Return a transformer that converts a property value model to its value
* but first checks whether the property value model passed to it is <code>null</code>.
+ * <p>
+ * <strong>NB:</strong>
* If the property value model is <code>null</code>, the transformer returns
* <code>null</code>.
*
+ * @see #valueTransformer(Object)
+ * @see #valueTransformer_()
* @see PropertyValueModel#VALUE_TRANSFORMER
*/
- public static <V, PVM extends PropertyValueModel<? extends V>> Transformer<PVM, V> nullCheckValueTransformer() {
- return nullCheckValueTransformer(null);
+ @SuppressWarnings("unchecked")
+ public static <V, PVM extends PropertyValueModel<? extends V>> Transformer<PVM, V> valueTransformer() {
+ return NULL_CHECK_VALUE_TRANSFORMER;
}
+ @SuppressWarnings("rawtypes")
+ public static final Transformer NULL_CHECK_VALUE_TRANSFORMER = TransformerTools.nullCheck(valueTransformer_(), null);
+
/**
* Return a transformer that converts a property value model to its value
* but first checks whether the property value model passed to it is <code>null</code>.
+ * <p>
+ * <strong>NB:</strong>
* If the property value model is <code>null</code>, the transformer returns
* the specified null value.
*
+ * @see #valueTransformer()
+ * @see #valueTransformer_()
* @see PropertyValueModel#VALUE_TRANSFORMER
*/
- public static <V, PVM extends PropertyValueModel<? extends V>> Transformer<PVM, V> nullCheckValueTransformer(V nullValue) {
- return TransformerTools.nullCheck(valueTransformer(), nullValue);
+ public static <V, PVM extends PropertyValueModel<? extends V>> Transformer<PVM, V> valueTransformer(V nullValue) {
+ return TransformerTools.nullCheck(valueTransformer_(), nullValue);
}
/**
* Return a transformer that converts a property value model to its value.
+ * <p>
+ * <strong>NB:</strong>
* If the property value model is <code>null</code>, the transformer throws
* a {@link NullPointerException}.
*
+ * @see #valueTransformer(Object)
+ * @see #valueTransformer()
* @see PropertyValueModel#VALUE_TRANSFORMER
*/
@SuppressWarnings("unchecked")
- public static <V, PVM extends PropertyValueModel<? extends V>> Transformer<PVM, V> valueTransformer() {
+ public static <V, PVM extends PropertyValueModel<? extends V>> Transformer<PVM, V> valueTransformer_() {
return PropertyValueModel.VALUE_TRANSFORMER;
}
+ /**
+ * Return a closure that sets a property value model's value.
+ * <p>
+ * <strong>NB:</strong>
+ * If the property value model is <code>null</code>, the closure
+ * does nothing.
+ *
+ * @see #setValueClosure_()
+ * @see PropertyValueModel#VALUE_TRANSFORMER
+ */
+ @SuppressWarnings("unchecked")
+ public static <V, PVM extends ModifiablePropertyValueModel<? super V>> BiClosure<PVM, V> setValueClosure() {
+ return NULL_CHECK_SET_VALUE_CLOSURE;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public static final BiClosure NULL_CHECK_SET_VALUE_CLOSURE = nullCheckSetClosureWrapper(setValueClosure_());
+
+ /**
+ * Return a closure that sets a property value model's value.
+ * <p>
+ * <strong>NB:</strong>
+ * If the property value model is <code>null</code>, the closure throws
+ * a {@link NullPointerException}.
+ *
+ * @see #setValueClosure()
+ * @see PropertyValueModel#VALUE_TRANSFORMER
+ */
+ @SuppressWarnings("unchecked")
+ public static <V, PVM extends ModifiablePropertyValueModel<? super V>> BiClosure<PVM, V> setValueClosure_() {
+ return ModifiablePropertyValueModel.SET_VALUE_CLOSURE;
+ }
+
// ********** suppressed constructor **********
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/ModifiablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/ModifiablePropertyValueModel.java
index 9afe050da4..613520b92b 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/ModifiablePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/ModifiablePropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. 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.
@@ -9,6 +9,9 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.model.value;
+import org.eclipse.jpt.common.utility.closure.BiClosure;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+
/**
* Extend {@link PropertyValueModel} to allow the setting of the property's value.
* <p>
@@ -28,4 +31,18 @@ public interface ModifiablePropertyValueModel<V>
* @see PropertyValueModel#VALUE
*/
void setValue(V value);
+
+ @SuppressWarnings("rawtypes")
+ BiClosure SET_VALUE_CLOSURE = new SetValueClosure();
+ class SetValueClosure<V>
+ implements BiClosure<ModifiablePropertyValueModel<V>, V>
+ {
+ public void execute(ModifiablePropertyValueModel<V> pvm, V value) {
+ pvm.setValue(value);
+ }
+ @Override
+ public String toString() {
+ return ObjectTools.singletonToString(this);
+ }
+ }
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
deleted file mode 100644
index 44eb7e895d..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2016 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal.model.value;
-
-import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
-import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter;
-import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
-import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
-import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
-import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.common.utility.predicate.Predicate;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-import junit.framework.TestCase;
-
-@SuppressWarnings("nls")
-public class FilteringPropertyValueModelTests
- extends TestCase
-{
- private ModifiablePropertyValueModel<String> innerModel;
- PropertyChangeEvent innerModelEvent;
-
- private ModifiablePropertyValueModel<String> filteredModel;
- PropertyChangeEvent filteredModelEvent;
-
- public FilteringPropertyValueModelTests(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- this.innerModel = new SimplePropertyValueModel<>("foo");
- this.filteredModel = PropertyValueModelTools.filterModifiable(this.innerModel, this.buildGetFilter(), this.buildSetFilter());
-// this.filteredModel = new FilteringModifiablePropertyValueModel<>(this.innerModel, this.buildGetFilter(), this.buildSetFilter());
- }
-
- private Predicate<String> buildGetFilter() {
- return new StringStartsWithB();
- }
-
- private Predicate<String> buildSetFilter() {
- return new StringStartsWithB();
- }
-
- class StringStartsWithB
- extends PredicateAdapter<String>
- {
- @Override
- public boolean evaluate(String s) {
- return (s != null) && s.startsWith("b");
- }
- }
-
- @Override
- protected void tearDown() throws Exception {
- TestTools.clear(this);
- super.tearDown();
- }
-
- public void testValue() {
- assertEquals("foo", this.innerModel.getValue());
- assertNull(this.filteredModel.getValue());
-
- ChangeListener innerListener = this.buildInnerListener();
- this.innerModel.addChangeListener(innerListener);
- ChangeListener filteredListener = this.buildFilteredListener();
- this.filteredModel.addChangeListener(filteredListener);
-
- assertEquals("foo", this.innerModel.getValue());
- assertNull(this.filteredModel.getValue());
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue("bar");
- assertEquals("bar", this.innerModel.getValue());
- assertEquals("bar", this.innerModelEvent.getNewValue());
- assertNotNull(this.filteredModel.getValue());
- assertEquals("bar", this.filteredModel.getValue());
- assertEquals("bar", this.filteredModelEvent.getNewValue());
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue("baz");
- assertEquals("baz", this.innerModel.getValue());
- assertEquals("baz", this.innerModelEvent.getNewValue());
- assertNotNull(this.filteredModel.getValue());
- assertEquals("baz", this.filteredModel.getValue());
- assertEquals("baz", this.filteredModelEvent.getNewValue());
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue(null);
- assertNull(this.innerModel.getValue());
- assertNull(this.innerModelEvent.getNewValue());
- assertNull(this.filteredModel.getValue());
- assertNull(this.filteredModelEvent.getNewValue());
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue("foo");
- assertEquals("foo", this.innerModel.getValue());
- assertEquals("foo", this.innerModelEvent.getNewValue());
- assertNull(this.filteredModel.getValue());
- assertNull(this.filteredModelEvent);
- }
-
- public void testSetValue() {
- assertEquals("foo", this.innerModel.getValue());
- assertNull(this.filteredModel.getValue());
-
- ChangeListener innerListener = this.buildInnerListener();
- this.innerModel.addChangeListener(innerListener);
- ChangeListener filteredListener = this.buildFilteredListener();
- this.filteredModel.addChangeListener(filteredListener);
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.filteredModel.setValue("bar");
- assertEquals("bar", this.innerModel.getValue());
- assertEquals("bar", this.innerModelEvent.getNewValue());
- assertEquals("bar", this.filteredModel.getValue());
- assertEquals("bar", this.filteredModelEvent.getNewValue());
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.filteredModel.setValue("foo");
- assertNull(this.innerModel.getValue());
- assertNull(this.innerModelEvent.getNewValue());
- assertNull(this.filteredModel.getValue());
- assertNull(this.filteredModelEvent.getNewValue());
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.filteredModel.setValue(null);
- assertNull(this.innerModel.getValue());
- assertNull(this.innerModelEvent);
- assertNull(this.filteredModel.getValue());
- assertNull(this.filteredModelEvent);
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.filteredModel.setValue("baz");
- assertEquals("baz", this.innerModel.getValue());
- assertEquals("baz", this.innerModelEvent.getNewValue());
- assertEquals("baz", this.filteredModel.getValue());
- assertEquals("baz", this.filteredModelEvent.getNewValue());
- }
-
- public void testLazyListening() {
- assertTrue(((AbstractModel) this.innerModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
- ChangeListener listener = this.buildFilteredListener();
- this.filteredModel.addChangeListener(listener);
- assertTrue(((AbstractModel) this.innerModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
- this.filteredModel.removeChangeListener(listener);
- assertTrue(((AbstractModel) this.innerModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
-
- this.filteredModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
- assertTrue(((AbstractModel) this.innerModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
- this.filteredModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
- assertTrue(((AbstractModel) this.innerModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
- }
-
- public void testPropertyChange1() {
- this.innerModel.addChangeListener(this.buildInnerListener());
- this.filteredModel.addChangeListener(this.buildFilteredListener());
- this.verifyPropertyChanges();
- }
-
- public void testPropertyChange2() {
- this.innerModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildInnerListener());
- this.filteredModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildFilteredListener());
- this.verifyPropertyChanges();
- }
-
- private void verifyPropertyChanges() {
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue("bar");
- this.verifyEvent(this.innerModelEvent, this.innerModel, "foo", "bar");
- this.verifyEvent(this.filteredModelEvent, this.filteredModel, null, "bar");
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue("baz");
- this.verifyEvent(this.innerModelEvent, this.innerModel, "bar", "baz");
- this.verifyEvent(this.filteredModelEvent, this.filteredModel, "bar", "baz");
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue("foo");
- this.verifyEvent(this.innerModelEvent, this.innerModel, "baz", "foo");
- this.verifyEvent(this.filteredModelEvent, this.filteredModel, "baz", null);
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue("fop");
- this.verifyEvent(this.innerModelEvent, this.innerModel, "foo", "fop");
- assertNull(this.filteredModelEvent);
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue(null);
- this.verifyEvent(this.innerModelEvent, this.innerModel, "fop", null);
- assertNull(this.filteredModelEvent);
-
- this.innerModelEvent = null;
- this.filteredModelEvent = null;
- this.innerModel.setValue("bar");
- this.verifyEvent(this.innerModelEvent, this.innerModel, null, "bar");
- this.verifyEvent(this.filteredModelEvent, this.filteredModel, null, "bar");
- }
-
- private ChangeListener buildInnerListener() {
- return new ChangeAdapter() {
- @Override
- public void propertyChanged(PropertyChangeEvent e) {
- FilteringPropertyValueModelTests.this.innerModelEvent = e;
- }
- };
- }
-
- private ChangeListener buildFilteredListener() {
- return new ChangeAdapter() {
- @Override
- public void propertyChanged(PropertyChangeEvent e) {
- FilteringPropertyValueModelTests.this.filteredModelEvent = e;
- }
- };
- }
-
- private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) {
- assertEquals(source, e.getSource());
- assertEquals(PropertyValueModel.VALUE, e.getPropertyName());
- assertEquals(oldValue, e.getOldValue());
- assertEquals(newValue, e.getNewValue());
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java
index be6e0220b3..ab482b3444 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java
@@ -37,7 +37,6 @@ public class JptCommonUtilityModelValueTests {
suite.addTestSuite(CompoundPropertyValueModelTests.class);
suite.addTestSuite(ExtendedListValueModelWrapperTests.class);
suite.addTestSuite(FilteringCollectionValueModelTests.class);
- suite.addTestSuite(FilteringPropertyValueModelTests.class);
suite.addTestSuite(ItemCollectionListValueModelAdapterTests.class);
suite.addTestSuite(ItemListListValueModelAdapterTests.class);
suite.addTestSuite(ItemPropertyListValueModelAdapterTests.class);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java
index bf6123c2fa..ef8a388aac 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java
@@ -1158,35 +1158,31 @@ public class PropertyValueModelToolsTests
private final ModifiablePropertyValueModel<String> stringModel;
private final PluggableModifiablePropertyValueModel.Adapter.Listener<String> listener;
private final PropertyChangeListener stringListener;
- private volatile String value;
public HalfStringModelAdapter(ModifiablePropertyValueModel<String> stringModel, PluggableModifiablePropertyValueModel.Adapter.Listener<String> listener) {
super();
this.stringModel = stringModel;
this.listener = listener;
this.stringListener = new StringListener();
- this.value = null;
}
public String engageModel() {
this.stringModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringListener);
String v = this.stringModel.getValue();
- return this.value = v.substring(v.length() / 2);
+ return v.substring(v.length() / 2);
}
public void setValue(String value) {
- this.value = value;
this.stringModel.setValue(value + value);
}
public String disengageModel() {
this.stringModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.stringListener);
- return this.value = null;
+ return null;
}
void stringChanged(String newStringValue) {
String newValue = newStringValue.substring(newStringValue.length() / 2);
- this.value = newValue;
this.listener.valueChanged(newValue);
}
@@ -1271,21 +1267,21 @@ public class PropertyValueModelToolsTests
public void testNullCheckValueTransformer() {
SimplePropertyValueModel<String> stringModel = new SimplePropertyValueModel<>("foo");
- Transformer<PropertyValueModel<String>, String> transformer = PropertyValueModelTools.nullCheckValueTransformer();
+ Transformer<PropertyValueModel<String>, String> transformer = PropertyValueModelTools.valueTransformer();
assertEquals("foo", transformer.transform(stringModel));
assertNull(transformer.transform(null));
}
public void testNullCheckValueTransformerObject() {
SimplePropertyValueModel<String> stringModel = new SimplePropertyValueModel<>("foo");
- Transformer<PropertyValueModel<String>, String> transformer = PropertyValueModelTools.nullCheckValueTransformer("XXX");
+ Transformer<PropertyValueModel<String>, String> transformer = PropertyValueModelTools.valueTransformer("XXX");
assertEquals("foo", transformer.transform(stringModel));
assertEquals("XXX", transformer.transform(null));
}
public void testValueTransformer() {
SimplePropertyValueModel<String> stringModel = new SimplePropertyValueModel<>("foo");
- Transformer<PropertyValueModel<String>, String> transformer = PropertyValueModelTools.valueTransformer();
+ Transformer<PropertyValueModel<String>, String> transformer = PropertyValueModelTools.valueTransformer_();
assertEquals("foo", transformer.transform(stringModel));
}

Back to the top