diff options
author | Brian Vosburgh | 2016-06-27 20:25:01 +0000 |
---|---|---|
committer | Brian Vosburgh | 2017-05-18 22:37:26 +0000 |
commit | 6ec95b6cdd0fb727afa34e3cf9dc0ce8a06e978e (patch) | |
tree | cd7f2acdf5c5fee58999d9e617c09272b293f1b8 /common | |
parent | 0a077f35ef9ff55fe1baa5c9928445fe79251ded (diff) | |
download | webtools.dali-6ec95b6cdd0fb727afa34e3cf9dc0ce8a06e978e.tar.gz webtools.dali-6ec95b6cdd0fb727afa34e3cf9dc0ce8a06e978e.tar.xz webtools.dali-6ec95b6cdd0fb727afa34e3cf9dc0ce8a06e978e.zip |
remove factory indirection from pluggable value models
Diffstat (limited to 'common')
6 files changed, 64 insertions, 38 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyPluggablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyPluggablePropertyValueModelAdapter.java index d0e5f33f80..0e739425ea 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyPluggablePropertyValueModelAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyPluggablePropertyValueModelAdapter.java @@ -36,7 +36,11 @@ import org.eclipse.jpt.common.utility.transformer.Transformer; public abstract class AbstractPropertyPluggablePropertyValueModelAdapter<V1, V2, M extends PropertyValueModel<? extends V1>, A extends AbstractPluggablePropertyValueModel.Adapter<V2>, F extends AbstractPropertyPluggablePropertyValueModelAdapter.Factory<V1, V2, M, A>> implements AbstractPluggablePropertyValueModel.Adapter<V2>, PropertyChangeListener { - protected final F factory; + /** 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 AbstractPluggablePropertyValueModel.Adapter.Listener<V2> listener; @@ -55,7 +59,8 @@ public abstract class AbstractPropertyPluggablePropertyValueModelAdapter<V1, V2, if (factory == null) { throw new NullPointerException(); } - this.factory = factory; + this.propertyModel = factory.propertyModel; + this.transformer = factory.transformer; if (listener == null) { throw new NullPointerException(); } @@ -70,15 +75,15 @@ public abstract class AbstractPropertyPluggablePropertyValueModelAdapter<V1, V2, } public void engageModel() { - this.factory.propertyModel.addPropertyChangeListener(PropertyValueModel.VALUE, this); - this.propertyModelValue = this.factory.propertyModel.getValue(); + this.propertyModel.addPropertyChangeListener(PropertyValueModel.VALUE, this); + this.propertyModelValue = this.propertyModel.getValue(); this.value = this.buildValue(); } public void disengageModel() { this.value = null; this.propertyModelValue = null; - this.factory.propertyModel.removePropertyChangeListener(PropertyValueModel.VALUE, this); + this.propertyModel.removePropertyChangeListener(PropertyValueModel.VALUE, this); } @@ -98,7 +103,7 @@ public abstract class AbstractPropertyPluggablePropertyValueModelAdapter<V1, V2, } private V2 buildValue() { - return this.factory.transformer.transform(this.propertyModelValue); + return this.transformer.transform(this.propertyModelValue); } @Override @@ -112,7 +117,7 @@ public abstract class AbstractPropertyPluggablePropertyValueModelAdapter<V1, V2, public abstract static class Factory<V1, V2, M extends PropertyValueModel<? extends V1>, A extends AbstractPluggablePropertyValueModel.Adapter<V2>> implements AbstractPluggablePropertyValueModel.Adapter.Factory<V2, A> { - public final M propertyModel; + /* CU private */ final M propertyModel; /* CU private */ final Transformer<? super V1, ? extends V2> transformer; public Factory(M propertyModel, Transformer<? super V1, ? extends V2> transformer) { diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPluggablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPluggablePropertyValueModelAdapter.java index 5dcd52a786..34244514e6 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPluggablePropertyValueModelAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPluggablePropertyValueModelAdapter.java @@ -42,7 +42,11 @@ import org.eclipse.jpt.common.utility.transformer.Transformer; public final class CollectionPluggablePropertyValueModelAdapter<E, V> implements PluggablePropertyValueModel.Adapter<V>, CollectionChangeListener { - private final Factory<E, V> factory; + /** The wrapped model */ + private final CollectionValueModel<? extends E> collectionModel; + + /** Transformer that converts the wrapped model's value to this model's value. */ + private final Transformer<? super Collection<E>, V> transformer; /** The <em>real</em> adapter. */ private final AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener; @@ -64,7 +68,8 @@ public final class CollectionPluggablePropertyValueModelAdapter<E, V> if (factory == null) { throw new NullPointerException(); } - this.factory = factory; + this.collectionModel = factory.collectionModel; + this.transformer = factory.transformer; if (listener == null) { throw new NullPointerException(); } @@ -81,15 +86,15 @@ public final class CollectionPluggablePropertyValueModelAdapter<E, V> } public void engageModel() { - this.factory.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this); - CollectionTools.addAll(this.collection, this.factory.collectionModel); + this.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this); + CollectionTools.addAll(this.collection, this.collectionModel); this.value = this.buildValue(); } public void disengageModel() { this.value = null; this.collection.clear(); - this.factory.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this); + this.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this); } @@ -126,7 +131,7 @@ public final class CollectionPluggablePropertyValueModelAdapter<E, V> } private V buildValue() { - return this.factory.transformer.transform(this.unmodifiableCollection); + return this.transformer.transform(this.unmodifiableCollection); } @Override diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModelAdapter.java index db85a5b25a..53faeeb5cb 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModelAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModelAdapter.java @@ -52,7 +52,11 @@ import org.eclipse.jpt.common.utility.transformer.Transformer; public final class CompositePropertyValueModelAdapter<E, V> implements PluggablePropertyValueModel.Adapter<V>, CollectionChangeListener { - private final Factory<E, V> factory; + /** The wrapped model */ + private final CollectionValueModel<? extends PropertyValueModel<? extends E>> collectionModel; + + /** Transformer that converts the wrapped model's value to this model's value. */ + private final Transformer<? super Collection<E>, V> transformer; /** * The <em>real</em> adapter, passed to us as a listener. @@ -90,7 +94,8 @@ public final class CompositePropertyValueModelAdapter<E, V> if (factory == null) { throw new NullPointerException(); } - this.factory = factory; + this.collectionModel = factory.collectionModel; + this.transformer = factory.transformer; if (listener == null) { throw new NullPointerException(); } @@ -108,18 +113,18 @@ public final class CompositePropertyValueModelAdapter<E, V> } public void engageModel() { - this.factory.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this); - this.addComponentPVMs(this.factory.collectionModel); + this.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this); + this.addComponentPVMs(this.collectionModel); this.value = this.buildValue(); } public void disengageModel() { this.value = null; - this.removeComponentPVMs(this.factory.collectionModel); + this.removeComponentPVMs(this.collectionModel); if ( ! this.values.isEmpty()) { throw new IllegalStateException("extraneous values: " + this.values); //$NON-NLS-1$ } - this.factory.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this); + this.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this); } @@ -197,7 +202,7 @@ public final class CompositePropertyValueModelAdapter<E, V> } private V buildValue() { - return this.factory.transformer.transform(this.unmodifiableValues); + return this.transformer.transform(this.unmodifiableValues); } @Override diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCompositePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCompositePropertyValueModelAdapter.java index 3ec4dec4a4..e19ded2d6f 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCompositePropertyValueModelAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCompositePropertyValueModelAdapter.java @@ -55,7 +55,11 @@ import org.eclipse.jpt.common.utility.transformer.Transformer; public final class ListCompositePropertyValueModelAdapter<E, V> implements PluggablePropertyValueModel.Adapter<V>, ListChangeListener { - private final Factory<E, V> factory; + /** The wrapped model */ + private final ListValueModel<? extends PropertyValueModel<? extends E>> listModel; + + /** Transformer that converts the wrapped model's value to this model's value. */ + private final Transformer<? super List<E>, V> transformer; /** * The <em>real</em> adapter, passed to us as a listener. @@ -87,7 +91,8 @@ public final class ListCompositePropertyValueModelAdapter<E, V> if (factory == null) { throw new NullPointerException(); } - this.factory = factory; + this.listModel = factory.listModel; + this.transformer = factory.transformer; if (listener == null) { throw new NullPointerException(); } @@ -104,18 +109,18 @@ public final class ListCompositePropertyValueModelAdapter<E, V> } public void engageModel() { - this.factory.listModel.addListChangeListener(ListValueModel.LIST_VALUES, this); - this.addComponentPVMs(0, this.factory.listModel); + this.listModel.addListChangeListener(ListValueModel.LIST_VALUES, this); + this.addComponentPVMs(0, this.listModel); this.value = this.buildValue(); } public void disengageModel() { this.value = null; - this.removeComponentPVMs(0, this.factory.listModel.size(), this.factory.listModel); + this.removeComponentPVMs(0, this.listModel.size(), this.listModel); if ( ! this.values.isEmpty()) { throw new IllegalStateException("extraneous values: " + this.values); //$NON-NLS-1$ } - this.factory.listModel.removeListChangeListener(ListValueModel.LIST_VALUES, this); + this.listModel.removeListChangeListener(ListValueModel.LIST_VALUES, this); } @@ -181,8 +186,8 @@ public final class ListCompositePropertyValueModelAdapter<E, V> private void removeCachedPVMs() { @SuppressWarnings("unchecked") - Transformer<SimpleAssociation<PropertyValueModel<? extends E>, E>, PropertyValueModel<? extends E>> transformer = Association.KEY_TRANSFORMER; - this.removeComponentPVMs(this.values, ListTools.transform(this.values, transformer)); + Transformer<SimpleAssociation<PropertyValueModel<? extends E>, E>, PropertyValueModel<? extends E>> t = Association.KEY_TRANSFORMER; + this.removeComponentPVMs(this.values, ListTools.transform(this.values, t)); } private void removeComponentPVMs(int index, int length, Iterable<? extends PropertyValueModel<? extends E>> expectedPVMs) { @@ -211,8 +216,8 @@ public final class ListCompositePropertyValueModelAdapter<E, V> private V buildValue() { @SuppressWarnings("unchecked") - Transformer<SimpleAssociation<PropertyValueModel<? extends E>, E>, E> transformer = Association.VALUE_TRANSFORMER; - return this.factory.transformer.transform(ListTools.transform(this.values, transformer)); + Transformer<SimpleAssociation<PropertyValueModel<? extends E>, E>, E> t = Association.VALUE_TRANSFORMER; + return this.transformer.transform(ListTools.transform(this.values, t)); } @Override diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPluggablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPluggablePropertyValueModelAdapter.java index 5f1f88c9ad..b5b0545753 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPluggablePropertyValueModelAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPluggablePropertyValueModelAdapter.java @@ -46,7 +46,11 @@ import org.eclipse.jpt.common.utility.transformer.Transformer; public final class ListPluggablePropertyValueModelAdapter<E, V> implements PluggablePropertyValueModel.Adapter<V>, ListChangeListener { - private final Factory<E, V> factory; + /** The wrapped model */ + private final ListValueModel<? extends E> listModel; + + /** Transformer that converts the wrapped model's value to this model's value. */ + private final Transformer<? super List<E>, V> transformer; /** The <em>real</em> adapter. */ private final AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener; @@ -68,7 +72,8 @@ public final class ListPluggablePropertyValueModelAdapter<E, V> if (factory == null) { throw new NullPointerException(); } - this.factory = factory; + this.listModel = factory.listModel; + this.transformer = factory.transformer; if (listener == null) { throw new NullPointerException(); } @@ -85,15 +90,15 @@ public final class ListPluggablePropertyValueModelAdapter<E, V> } public void engageModel() { - this.factory.listModel.addListChangeListener(ListValueModel.LIST_VALUES, this); - ListTools.addAll(this.list, 0, this.factory.listModel); + this.listModel.addListChangeListener(ListValueModel.LIST_VALUES, this); + ListTools.addAll(this.list, 0, this.listModel); this.value = this.buildValue(); } public void disengageModel() { this.value = null; this.list.clear(); - this.factory.listModel.removeListChangeListener(ListValueModel.LIST_VALUES, this); + this.listModel.removeListChangeListener(ListValueModel.LIST_VALUES, this); } @@ -146,7 +151,7 @@ public final class ListPluggablePropertyValueModelAdapter<E, V> } private V buildValue() { - return this.factory.transformer.transform(this.unmodifiableList); + return this.transformer.transform(this.unmodifiableList); } @Override 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 index 4c6683cb85..dd4bd8bb38 100644 --- 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 @@ -31,17 +31,18 @@ public class PropertyPluggableModifiablePropertyValueModelAdapter<V1, V2> extends AbstractPropertyPluggablePropertyValueModelAdapter<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, AbstractPluggablePropertyValueModel.Adapter.Listener<V2> listener) { super(factory, listener); + this.setTransformer = factory.setTransformer; } public void setValue(V2 value) { - this.factory.propertyModel.setValue(this.factory.setTransformer.transform(value)); + this.propertyModel.setValue(this.setTransformer.transform(value)); } - // ********** PluggableModifiablePropertyValueModel.Adapter.Factory ********** public static class Factory<V1, V2> |