diff options
13 files changed, 899 insertions, 493 deletions
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 1863e3d6ab..7814396fe8 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 @@ -171,7 +171,9 @@ public abstract class BasePluggablePropertyValueModel<V, A extends BasePluggable // ********** Adapter Listener ********** /** - * Simple callback. Allows us to keep the callback method internal. + * Simple callback. + * Allows us to keep the callback method internal. + * Also, a type cannot extend or implement one of its member types. */ /* CU private */ class AdapterListener implements Adapter.Listener<V> diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModelPropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModelPropertyAspectAdapter.java new file mode 100644 index 0000000000..0038844ca8 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModelPropertyAspectAdapter.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * 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.PropertyChangeListener; +import org.eclipse.jpt.common.utility.transformer.Transformer; + +/** + * This adapter can be used by a {@link PluggablePropertyAspectAdapter + * pluggable property aspect adapter} to convert one of a {@link Model model's} + * <em>bound</em> properties to a + * {@link org.eclipse.jpt.common.utility.model.value.PropertyValueModel property value model}. + * + * @param <V> the type of the adapter's value + * @param <S> the type of the subject whose <em>bound</em> property is transformed into + * the value + */ +public final class ModelPropertyAspectAdapter<V, S extends Model> + implements PluggablePropertyAspectAdapter.SubjectAdapter<V, S>, PropertyChangeListener +{ + private final String propertyName; + + private final Transformer<? super S, ? extends V> propertyTransformer; + + private final PluggablePropertyAspectAdapter.SubjectAdapter.Listener<V> listener; // backpointer to aspect adapter + + + public ModelPropertyAspectAdapter(String propertyName, Transformer<? super S, ? extends V> propertyTransformer, PluggablePropertyAspectAdapter.SubjectAdapter.Listener<V> listener) { + super(); + if (propertyName == null) { + throw new NullPointerException(); + } + this.propertyName = propertyName; + + if (propertyTransformer == null) { + throw new NullPointerException(); + } + this.propertyTransformer = propertyTransformer; + + if (listener == null) { + throw new NullPointerException(); + } + this.listener = listener; + } + + public V engageSubject(S subject) { + if (subject != null) { + subject.addPropertyChangeListener(this.propertyName, this); + } + return this.propertyTransformer.transform(subject); + } + + public V disengageSubject(S subject) { + if (subject != null) { + subject.removePropertyChangeListener(this.propertyName, this); + } + return this.propertyTransformer.transform(subject); + } + + public void propertyChanged(PropertyChangeEvent event) { + @SuppressWarnings("unchecked") + V newValue = (V) event.getNewValue(); + this.listener.valueChanged(newValue); + } + + @Override + public String toString() { + return ObjectTools.toString(this, this.propertyName); + } + + + // ********** Factory ********** + + /** + * @see PluggablePropertyAspectAdapter + */ + public static final class Factory<V, S extends Model> + implements PluggablePropertyAspectAdapter.SubjectAdapter.Factory<V, S> + { + /* CU private */ final String propertyName; + /* CU private */ final Transformer<? super S, ? extends V> propertyTransformer; + + public Factory(String propertyName, Transformer<? super S, ? extends V> propertyTransformer) { + super(); + if (propertyName == null) { + throw new NullPointerException(); + } + this.propertyName = propertyName; + + if (propertyTransformer == null) { + throw new NullPointerException(); + } + this.propertyTransformer = propertyTransformer; + } + + public PluggablePropertyAspectAdapter.SubjectAdapter<V, S> buildAdapter(PluggablePropertyAspectAdapter.SubjectAdapter.Listener<V> listener) { + return new ModelPropertyAspectAdapter<>(this.propertyName, this.propertyTransformer, 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/ModifiablePropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ModifiablePropertyAspectAdapter.java index 70612a2b5f..d8a3e5bd4d 100644 --- 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 @@ -11,9 +11,7 @@ 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; /** @@ -28,26 +26,26 @@ import org.eclipse.jpt.common.utility.transformer.Transformer; * * @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>> +public final class ModifiablePropertyAspectAdapter<V, S> implements PluggableModifiablePropertyValueModel.Adapter<V> { - /** The "get" half of the aspect adapter */ - private final PropertyAspectAdapter<V, S, SM> adapter; + /** The adapter used to "get" the subject's aspect value. */ + private final GetAdapter<V, S> getAdapter; /** 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) { + public ModifiablePropertyAspectAdapter(GetAdapter<V, S> getAdapter, BiClosure<? super S, ? super V> setClosure) { super(); - if (adapter == null) { + if (getAdapter == null) { throw new NullPointerException(); } - this.adapter = adapter; + this.getAdapter = getAdapter; + if (setClosure == null) { throw new NullPointerException(); } @@ -55,37 +53,55 @@ public final class ModifiablePropertyAspectAdapter<V, S extends Model, SM extend } public V engageModel() { - return this.adapter.engageModel(); + return this.getAdapter.engageModel(); } public V disengageModel() { - return this.adapter.disengageModel(); + return this.getAdapter.disengageModel(); } public void setValue(V value) { - this.setClosure.execute(this.adapter.subject, value); + this.setClosure.execute(this.getAdapter.getSubject(), value); } @Override public String toString() { - return ObjectTools.toString(this, this.adapter.buildValue()); + return ObjectTools.toString(this, this.getAdapter); } + /** + * Extend the pluggable pvm adapter so we can get the + * other adapter's subject and set the value of its aspect. + */ + public interface GetAdapter<V, S> + extends PluggablePropertyValueModel.Adapter<V> + { + /** + * Return the adapter's subject. + */ + S getSubject(); + + interface Factory<V, S> { + GetAdapter<V, S> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V> listener); + } + } + // ********** Factory ********** - public static final class Factory<V, S extends Model, SM extends PropertyValueModel<S>> + public static final class Factory<V, S> implements PluggableModifiablePropertyValueModel.Adapter.Factory<V> { - private final PropertyAspectAdapter.Factory<V, S, SM> factory; + private final ModifiablePropertyAspectAdapter.GetAdapter.Factory<V, S> getAdapterFactory; private final BiClosure<? super S, ? super V> setClosure; - public Factory(PropertyAspectAdapter.Factory<V, S, SM> factory, BiClosure<? super S, ? super V> setClosure) { + public Factory(GetAdapter.Factory<V, S> getAdapterFactory, BiClosure<? super S, ? super V> setClosure) { super(); - if (factory == null) { + if (getAdapterFactory == null) { throw new NullPointerException(); } - this.factory = factory; + this.getAdapterFactory = getAdapterFactory; + if (setClosure == null) { throw new NullPointerException(); } @@ -94,7 +110,7 @@ public final class ModifiablePropertyAspectAdapter<V, S extends Model, SM extend @Override public PluggableModifiablePropertyValueModel.Adapter<V> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V> listener) { - return new ModifiablePropertyAspectAdapter<>(this.factory.buildAdapter(listener), this.setClosure); + return new ModifiablePropertyAspectAdapter<>(this.getAdapterFactory.buildAdapter(listener), this.setClosure); } } } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyAspectAdapter.java new file mode 100644 index 0000000000..dbdc48992b --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyAspectAdapter.java @@ -0,0 +1,217 @@ +/******************************************************************************* + * 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.PropertyChangeListener; +import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; + +/** + * 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 + * @see ModifiablePropertyAspectAdapter + */ +public final class PluggablePropertyAspectAdapter<V, S, SM extends PropertyValueModel<? extends S>> + implements ModifiablePropertyAspectAdapter.GetAdapter<V, S>, PropertyChangeListener +{ + private final SM subjectModel; + + private volatile S subject; + + private final SubjectAdapter<V, S> subjectAdapter; + + private final BasePluggablePropertyValueModel.Adapter.Listener<V> listener; // backpointer + + + public PluggablePropertyAspectAdapter(SM subjectModel, SubjectAdapter.Factory<V, S> subjectAdapterFactory, BasePluggablePropertyValueModel.Adapter.Listener<V> listener) { + super(); + if (subjectModel == null) { + throw new NullPointerException(); + } + this.subjectModel = subjectModel; + + if (subjectAdapterFactory == null) { + throw new NullPointerException(); + } + this.subjectAdapter = subjectAdapterFactory.buildAdapter(new SubjectAdapterListener()); + + if (listener == null) { + throw new NullPointerException(); + } + this.listener = listener; + } + + /** + * Simple callback. + * Allows us to keep the callback method internal. + * Also, a type cannot extend or implement one of its member types. + */ + /* CU private */ class SubjectAdapterListener + implements SubjectAdapter.Listener<V> + { + public void valueChanged(V newValue) { + PluggablePropertyAspectAdapter.this.aspectChanged(newValue); + } + @Override + public String toString() { + return ObjectTools.toString(this); + } + } + + + // ********** BasePluggablePropertyValueModel.Adapter ********** + + public V engageModel() { + this.subjectModel.addPropertyChangeListener(PropertyValueModel.VALUE, this); + this.subject = this.subjectModel.getValue(); + return this.subjectAdapter.engageSubject(this.subject); + } + + public V disengageModel() { + S old = this.subject; + this.subjectModel.removePropertyChangeListener(PropertyValueModel.VALUE, this); + this.subject = null; + return this.subjectAdapter.disengageSubject(old); + } + + public S getSubject() { + return this.subject; + } + + + // ********** event handling ********** + + /** + * Move our subject adapter to the new subject. + */ + public void propertyChanged(PropertyChangeEvent event) { + @SuppressWarnings("unchecked") + S newSubject = (S) event.getNewValue(); + this.subjectAdapter.disengageSubject(this.subject); + this.subject = newSubject; + this.listener.valueChanged(this.subjectAdapter.engageSubject(this.subject)); + } + + /* CU private */ void aspectChanged(V newValue) { + this.listener.valueChanged(newValue); + } + + + // ********** misc ********** + + @Override + public String toString() { + return ObjectTools.toString(this, this.subjectAdapter); + } + + + // ********** Subject Adapter ********** + + /** + * Adapt an arbitrary subject to the aspect adapter's value; + * notifying the aspect adapter (via the {@link SubjectAdapter.Listener} interface) + * of any changes to the value. + */ + public interface SubjectAdapter<V, S> { + + /** + * Engage the specified subject, which can be <code>null</code>, + * and return the current value. + */ + V engageSubject(S subject); + + /** + * Disengage the specified subject, which can be <code>null</code>, + * and return the current value. + */ + V disengageSubject(S subject); + + /** + * Callback interface. + */ + interface Listener<V> { + /** + * Callback to notify listener that the subject's aspect value + * has changed. + */ + void valueChanged(V newValue); + } + + /** + * Subject adapter factory interface. + * This factory allows both the pluggable property value model adapter and its + * subject adapter to have circular <em>final</em> references to each other. + */ + interface Factory<V, S> { + /** + * Create a subject adapter with the specified listener. + */ + SubjectAdapter<V, S> buildAdapter(Listener<V> listener); + } + } + + + // ********** Factory ********** + + /** + * @see PluggablePropertyAspectAdapter + */ + public static final class Factory<V, S, SM extends PropertyValueModel<? extends S>> + implements PluggablePropertyValueModel.Adapter.Factory<V>, ModifiablePropertyAspectAdapter.GetAdapter.Factory<V, S> + { + private final SM subjectModel; + private final SubjectAdapter.Factory<V, S> subjectAdapterFactory; + + public Factory(SM subjectModel, SubjectAdapter.Factory<V, S> subjectAdapterFactory) { + super(); + if (subjectModel == null) { + throw new NullPointerException(); + } + this.subjectModel = subjectModel; + + if (subjectAdapterFactory == null) { + throw new NullPointerException(); + } + this.subjectAdapterFactory = subjectAdapterFactory; + } + + public PluggablePropertyAspectAdapter<V, S, SM> buildAdapter(BasePluggablePropertyValueModel.Adapter.Listener<V> listener) { + return new PluggablePropertyAspectAdapter<>(this.subjectModel, this.subjectAdapterFactory, 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/PropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java deleted file mode 100644 index a26367788f..0000000000 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java +++ /dev/null @@ -1,209 +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.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/PropertyValueModelTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java index b4765d099c..1a50efd17f 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 @@ -850,8 +850,8 @@ public final class PropertyValueModelTools { * 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_( + public static <V, IM extends PropertyValueModel<? extends V>, OM extends PropertyValueModel<? extends IM>> PluggablePropertyAspectAdapter.Factory<V, IM, OM> compoundPropertyValueModelAdapterFactory(OM outerModel) { + return modelAspectAdapterFactory_( outerModel, PropertyValueModel.VALUE, valueTransformer() @@ -866,8 +866,8 @@ public final class PropertyValueModelTools { * 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_( + public static <V, IM extends PropertyValueModel<? extends V>, OM extends PropertyValueModel<? extends IM>> PluggablePropertyAspectAdapter.Factory<V, IM, OM> compoundPropertyValueModelAdapterFactory_(OM outerModel) { + return modelAspectAdapterFactory_( outerModel, PropertyValueModel.VALUE, valueTransformer_() @@ -936,65 +936,87 @@ public final class PropertyValueModelTools { // ********** aspect adapters ********** /** - * Construct a property aspect adapter for the + * Construct a model 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( + public static <V, S extends Model, SM extends PropertyValueModel<? extends S>> PropertyValueModel<V> modelAspectAdapter( SM subjectModel, String aspectName, Transformer<? super S, ? extends V> transformer ) { - return propertyValueModel(aspectAdapterFactory(subjectModel, aspectName, transformer)); + return propertyValueModel(modelAspectAdapterFactory(subjectModel, aspectName, transformer)); } /** - * Construct a property aspect adapter for the + * Construct a model 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_( + public static <V, S extends Model, SM extends PropertyValueModel<? extends S>> PropertyValueModel<V> modelAspectAdapter_( SM subjectModel, String aspectName, Transformer<? super S, ? extends V> transformer ) { - return propertyValueModel(aspectAdapterFactory_(subjectModel, aspectName, transformer)); + return propertyValueModel(modelAspectAdapterFactory_(subjectModel, aspectName, transformer)); } /** - * Construct a property aspect adapter factory for the + * Construct a model 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( + public static <V, S extends Model, SM extends PropertyValueModel<? extends S>> PluggablePropertyAspectAdapter.Factory<V, S, SM> modelAspectAdapterFactory( SM subjectModel, String aspectName, Transformer<? super S, ? extends V> transformer ) { - return aspectAdapterFactory_(subjectModel, aspectName, TransformerTools.nullCheck(transformer)); + return modelAspectAdapterFactory_(subjectModel, aspectName, TransformerTools.nullCheck(transformer)); } /** - * Construct a property aspect adapter factory for the + * Construct a model 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_( + public static <V, S extends Model, SM extends PropertyValueModel<? extends S>> PluggablePropertyAspectAdapter.Factory<V, S, SM> modelAspectAdapterFactory_( SM subjectModel, String aspectName, Transformer<? super S, ? extends V> transformer ) { - return new PropertyAspectAdapter.Factory<>(subjectModel, aspectName, transformer); + return pluggableAspectAdapterFactory(subjectModel, new ModelPropertyAspectAdapter.Factory<>(aspectName, transformer)); + } + + /** + * Construct a property aspect adapter for the + * specified subject model and subject adapter factory. + */ + public static <V, S, SM extends PropertyValueModel<? extends S>> PropertyValueModel<V> aspectAdapter( + SM subjectModel, + PluggablePropertyAspectAdapter.SubjectAdapter.Factory<V, S> subjectAdapterFactory + ) { + return propertyValueModel(pluggableAspectAdapterFactory(subjectModel, subjectAdapterFactory)); + } + + /** + * Construct a property aspect adapter factory for the + * specified subject model and subject adapter factory. + */ + public static <V, S, SM extends PropertyValueModel<? extends S>> PluggablePropertyAspectAdapter.Factory<V, S, SM> pluggableAspectAdapterFactory( + SM subjectModel, + PluggablePropertyAspectAdapter.SubjectAdapter.Factory<V, S> subjectAdapterFactory + ) { + return new PluggablePropertyAspectAdapter.Factory<>(subjectModel, subjectAdapterFactory); } @@ -1053,7 +1075,7 @@ public final class PropertyValueModelTools { Transformer<? super S, ? extends V> getTransformer, BiClosure<? super S, ? super V> setClosure ) { - return modifiablePropertyAspectAdapterFactory(aspectAdapterFactory(subjectModel, aspectName, getTransformer), setClosure); + return modifiablePropertyAspectAdapterFactory(modelAspectAdapterFactory(subjectModel, aspectName, getTransformer), setClosure); } /** @@ -1071,7 +1093,7 @@ public final class PropertyValueModelTools { Transformer<? super S, ? extends V> getTransformer, BiClosure<? super S, ? super V> setClosure ) { - return modifiablePropertyAspectAdapterFactory_(aspectAdapterFactory_(subjectModel, aspectName, getTransformer), setClosure); + return modifiablePropertyAspectAdapterFactory_(modelAspectAdapterFactory_(subjectModel, aspectName, getTransformer), setClosure); } /** @@ -1082,11 +1104,11 @@ public final class PropertyValueModelTools { * 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, + public static <V, S> PluggableModifiablePropertyValueModel.Adapter.Factory<V> modifiablePropertyAspectAdapterFactory( + ModifiablePropertyAspectAdapter.GetAdapter.Factory<V, S> getAdapterFactory, BiClosure<? super S, ? super V> setClosure ) { - return modifiablePropertyAspectAdapterFactory_(factory, nullCheckSetClosureWrapper(setClosure)); + return modifiablePropertyAspectAdapterFactory_(getAdapterFactory, nullCheckSetClosureWrapper(setClosure)); } /** @@ -1097,11 +1119,11 @@ public final class PropertyValueModelTools { * 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, + public static <V, S> PluggableModifiablePropertyValueModel.Adapter.Factory<V> modifiablePropertyAspectAdapterFactory_( + ModifiablePropertyAspectAdapter.GetAdapter.Factory<V, S> getAdapterFactory, BiClosure<? super S, ? super V> setClosure ) { - return new ModifiablePropertyAspectAdapter.Factory<>(factory, setClosure); + return new ModifiablePropertyAspectAdapter.Factory<>(getAdapterFactory, setClosure); } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompoundPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompoundPropertyValueModelTests.java index 1f126b396e..4f60c24c5b 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompoundPropertyValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompoundPropertyValueModelTests.java @@ -125,7 +125,7 @@ public class CompoundPropertyValueModelTests assertEquals("foo", this.keyModel.getValue()); // simple PVM assertNull(this.valueModelModel.getValue()); - assertNull(this.testModel.getValue()); + assertEquals("XXX", this.testModel.getValue()); } public void testLazyListening() { diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/AbstractNavigatorItemLabelProviderFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/AbstractNavigatorItemLabelProviderFactory.java index 9014ef667c..0d7abb71df 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/AbstractNavigatorItemLabelProviderFactory.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/AbstractNavigatorItemLabelProviderFactory.java @@ -15,7 +15,8 @@ import org.eclipse.jpt.common.ui.internal.jface.ModelItemExtendedLabelProvider; import org.eclipse.jpt.common.ui.internal.jface.NullItemExtendedLabelProvider; import org.eclipse.jpt.common.ui.internal.jface.StaticItemExtendedLabelProvider; import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider; -import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter; +import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel; import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapterXXXX; import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools; import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; @@ -125,32 +126,55 @@ public abstract class AbstractNavigatorItemLabelProviderFactory } public PropertyValueModel<ImageDescriptor> buildJavaClassImageDescriptorModel(JavaClass item) { - return new JavaClassImageDescriptorModel(item); + return PropertyValueModelTools.propertyValueModel(this.JavaClassImageDescriptorModelAdapterFactory(item)); } - - protected class JavaClassImageDescriptorModel - extends AspectPropertyValueModelAdapter<JavaClass, ImageDescriptor> { - - protected final PropertyValueModel<Boolean> isXmlRegistryModel; + + private PluggablePropertyValueModel.Adapter.Factory<ImageDescriptor> JavaClassImageDescriptorModelAdapterFactory(JavaClass item) { + return new JavaClassImageDescriptorModelAdapter.Factory(item); + } + + protected static class JavaClassImageDescriptorModelAdapter + implements PluggablePropertyValueModel.Adapter<ImageDescriptor> + { + protected final JavaClass javaClass; + protected final PluggablePropertyValueModel.Adapter.Listener<ImageDescriptor> listener; + + protected final PropertyValueModel<Boolean> xmlRegistryModel; + protected volatile Boolean xmlRegistry; + protected final PropertyChangeListener xmlRegistryListener; protected final PropertyValueModel<JavaClassMapping> mappingModel; + protected volatile JavaClassMapping mapping; + protected final PropertyChangeListener mappingListener; - protected final PropertyValueModel<Boolean> isXmlTransientModel; - - protected final PropertyChangeListener propertyChangeListener; + protected final PropertyValueModel<Boolean> xmlTransientModel; + protected volatile Boolean xmlTransient; + protected final PropertyChangeListener xmlTransientListener; - public JavaClassImageDescriptorModel(JavaClass subject) { - super(PropertyValueModelTools.staticPropertyValueModel(subject)); - this.isXmlRegistryModel = buildIsXmlRegistryModel(); - this.mappingModel = buildMappingModel(); - this.isXmlTransientModel = buildIsXmlTransientModel(); - this.propertyChangeListener = buildPropertyChangeListener(); + public JavaClassImageDescriptorModelAdapter(JavaClass javaClass, PluggablePropertyValueModel.Adapter.Listener<ImageDescriptor> listener) { + super(); + if (javaClass == null) { + throw new NullPointerException(); + } + this.javaClass = javaClass; + if (listener == null) { + throw new NullPointerException(); + } + this.listener = listener; + + this.xmlRegistryModel = this.buildXmlRegistryModel(); + this.xmlRegistryListener = this.buildXmlRegistryListener(); + + this.mappingModel = this.buildMappingModel(); + this.mappingListener = this.buildMappingListener(); + + this.xmlTransientModel = this.buildXmlTransientModel(); + this.xmlTransientListener = buildXmlTransientListener(); } - - protected PropertyValueModel<Boolean> buildIsXmlRegistryModel() { - return new PropertyAspectAdapterXXXX<JavaClass, Boolean>(JavaClass.XML_REGISTRY_PROPERTY, this.subject) { + protected PropertyValueModel<Boolean> buildXmlRegistryModel() { + return new PropertyAspectAdapterXXXX<JavaClass, Boolean>(JavaClass.XML_REGISTRY_PROPERTY, this.javaClass) { @Override protected Boolean buildValue_() { return Boolean.valueOf(this.subject.getXmlRegistry() != null); @@ -159,7 +183,7 @@ public abstract class AbstractNavigatorItemLabelProviderFactory } protected PropertyValueModel<JavaClassMapping> buildMappingModel() { - return new PropertyAspectAdapterXXXX<JavaClass, JavaClassMapping> (JavaType.MAPPING_PROPERTY, this.subject) { + return new PropertyAspectAdapterXXXX<JavaClass, JavaClassMapping> (JavaType.MAPPING_PROPERTY, this.javaClass) { @Override protected JavaClassMapping buildValue_() { return this.subject.getMapping(); @@ -167,7 +191,7 @@ public abstract class AbstractNavigatorItemLabelProviderFactory }; } - protected PropertyValueModel<Boolean> buildIsXmlTransientModel() { + protected PropertyValueModel<Boolean> buildXmlTransientModel() { return new PropertyAspectAdapterXXXX<JavaClassMapping, Boolean>(this.mappingModel, JaxbTypeMapping.XML_TRANSIENT_PROPERTY) { @Override protected Boolean buildValue_() { @@ -175,44 +199,91 @@ public abstract class AbstractNavigatorItemLabelProviderFactory } }; } - - protected PropertyChangeListener buildPropertyChangeListener() { - // transform the subject's property change events into VALUE property change events + + protected PropertyChangeListener buildXmlRegistryListener() { return new PropertyChangeListener() { public void propertyChanged(PropertyChangeEvent event) { - JavaClassImageDescriptorModel.this.aspectChanged(); + JavaClassImageDescriptorModelAdapter.this.xmlRegistry = (Boolean) event.getNewValue(); + JavaClassImageDescriptorModelAdapter.this.update(); } }; } - @Override - protected void aspectChanged() { - super.aspectChanged(); + protected PropertyChangeListener buildMappingListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + JavaClassImageDescriptorModelAdapter.this.mapping = (JavaClassMapping) event.getNewValue(); + JavaClassImageDescriptorModelAdapter.this.update(); + } + }; } - @Override - protected ImageDescriptor buildValue_() { - if ((this.mappingModel.getValue() != null) && (this.isXmlTransientModel.getValue() == Boolean.TRUE)) { + protected PropertyChangeListener buildXmlTransientListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + JavaClassImageDescriptorModelAdapter.this.xmlTransient = (Boolean) event.getNewValue(); + JavaClassImageDescriptorModelAdapter.this.update(); + } + }; + } + + /* CU private */ void update() { + this.listener.valueChanged(this.buildValue()); + } + + private ImageDescriptor buildValue() { + if ((this.mapping != null) && ObjectTools.equals(this.xmlTransient, Boolean.TRUE)) { return JptJaxbUiImages.JAXB_TRANSIENT_CLASS; } - if (this.isXmlRegistryModel.getValue() == Boolean.TRUE) { + if (ObjectTools.equals(this.xmlRegistry, Boolean.TRUE)) { return JptJaxbUiImages.JAXB_REGISTRY; } return JptJaxbUiImages.JAXB_CLASS; } - @Override - protected void engageSubject_() { - this.isXmlRegistryModel.addPropertyChangeListener(VALUE, this.propertyChangeListener); - this.mappingModel.addPropertyChangeListener(VALUE, this.propertyChangeListener); - this.isXmlTransientModel.addPropertyChangeListener(VALUE, this.propertyChangeListener); + public ImageDescriptor engageModel() { + this.xmlRegistryModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.xmlRegistryListener); + this.xmlRegistry = this.xmlRegistryModel.getValue(); + this.mappingModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.mappingListener); + this.mapping = this.mappingModel.getValue(); + this.xmlTransientModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.xmlTransientListener); + this.xmlTransient = this.xmlTransientModel.getValue(); + return this.buildValue(); } - @Override - protected void disengageSubject_() { - this.isXmlRegistryModel.removePropertyChangeListener(VALUE, this.propertyChangeListener); - this.mappingModel.removePropertyChangeListener(VALUE, this.propertyChangeListener); - this.isXmlTransientModel.removePropertyChangeListener(VALUE, this.propertyChangeListener); + public ImageDescriptor disengageModel() { + this.xmlRegistryModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.xmlRegistryListener); + this.xmlRegistry = null; + this.mappingModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.mappingListener); + this.mapping = null; + this.xmlTransientModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.xmlTransientListener); + this.xmlTransient = null; + return null; + } + + // ********** Factory ********** + + public static class Factory + implements PluggablePropertyValueModel.Adapter.Factory<ImageDescriptor> + { + private final JavaClass javaClass; + + public Factory(JavaClass javaClass) { + super(); + if (javaClass == null) { + throw new NullPointerException(); + } + this.javaClass = javaClass; + } + + public JavaClassImageDescriptorModelAdapter buildAdapter(PluggablePropertyValueModel.Adapter.Listener<ImageDescriptor> listener) { + return new JavaClassImageDescriptorModelAdapter(this.javaClass, listener); + } + + @Override + public String toString() { + return ObjectTools.toString(this); + } } } @@ -230,29 +301,49 @@ public abstract class AbstractNavigatorItemLabelProviderFactory } public PropertyValueModel<ImageDescriptor> buildJavaEnumImageDescriptorModel(JavaEnum item) { - return new JavaEnumImageDescriptorModel(item); + return PropertyValueModelTools.propertyValueModel(this.JavaEnumImageDescriptorModelAdapterFactory(item)); + } + + private PluggablePropertyValueModel.Adapter.Factory<ImageDescriptor> JavaEnumImageDescriptorModelAdapterFactory(JavaEnum item) { + return new JavaEnumImageDescriptorModelAdapter.Factory(item); } - protected class JavaEnumImageDescriptorModel - extends AspectPropertyValueModelAdapter<JavaEnum, ImageDescriptor> { - + protected static class JavaEnumImageDescriptorModelAdapter + implements PluggablePropertyValueModel.Adapter<ImageDescriptor> + { + protected final JavaEnum javaEnum; + protected final PluggablePropertyValueModel.Adapter.Listener<ImageDescriptor> listener; + protected final PropertyValueModel<JavaEnumMapping> mappingModel; + protected volatile JavaEnumMapping mapping; + protected final PropertyChangeListener mappingListener; - protected final PropertyValueModel<Boolean> isXmlTransientModel; + protected final PropertyValueModel<Boolean> xmlTransientModel; + protected volatile Boolean xmlTransient; + protected final PropertyChangeListener xmlTransientListener; - protected final PropertyChangeListener propertyChangeListener; - - public JavaEnumImageDescriptorModel(JavaEnum subject) { - super(PropertyValueModelTools.staticPropertyValueModel(subject)); - this.mappingModel = buildMappingModel(); - this.isXmlTransientModel = buildIsXmlTransientModel(); - this.propertyChangeListener = buildPropertyChangeListener(); + public JavaEnumImageDescriptorModelAdapter(JavaEnum javaEnum, PluggablePropertyValueModel.Adapter.Listener<ImageDescriptor> listener) { + super(); + if (javaEnum == null) { + throw new NullPointerException(); + } + this.javaEnum = javaEnum; + if (listener == null) { + throw new NullPointerException(); + } + this.listener = listener; + + this.mappingModel = this.buildMappingModel(); + this.mappingListener = this.buildMappingListener(); + + this.xmlTransientModel = this.buildXmlTransientModel(); + this.xmlTransientListener = this.buildXmlTransientListener(); } protected PropertyValueModel<JavaEnumMapping> buildMappingModel() { - return new PropertyAspectAdapterXXXX<JavaEnum, JavaEnumMapping> (JavaType.MAPPING_PROPERTY, this.subject) { + return new PropertyAspectAdapterXXXX<JavaEnum, JavaEnumMapping> (JavaType.MAPPING_PROPERTY, this.javaEnum) { @Override protected JavaEnumMapping buildValue_() { return this.subject.getMapping(); @@ -260,7 +351,16 @@ public abstract class AbstractNavigatorItemLabelProviderFactory }; } - protected PropertyValueModel<Boolean> buildIsXmlTransientModel() { + protected PropertyChangeListener buildMappingListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + JavaEnumImageDescriptorModelAdapter.this.mapping = (JavaEnumMapping) event.getNewValue(); + JavaEnumImageDescriptorModelAdapter.this.update(); + } + }; + } + + protected PropertyValueModel<Boolean> buildXmlTransientModel() { return new PropertyAspectAdapterXXXX<JavaEnumMapping, Boolean>(this.mappingModel, JaxbTypeMapping.XML_TRANSIENT_PROPERTY) { @Override protected Boolean buildValue_() { @@ -269,38 +369,64 @@ public abstract class AbstractNavigatorItemLabelProviderFactory }; } - protected PropertyChangeListener buildPropertyChangeListener() { - // transform the subject's property change events into VALUE property change events + protected PropertyChangeListener buildXmlTransientListener() { return new PropertyChangeListener() { public void propertyChanged(PropertyChangeEvent event) { - JavaEnumImageDescriptorModel.this.aspectChanged(); + JavaEnumImageDescriptorModelAdapter.this.xmlTransient = (Boolean) event.getNewValue(); + JavaEnumImageDescriptorModelAdapter.this.update(); } }; } - @Override - protected void aspectChanged() { - super.aspectChanged(); + /* CU private */ void update() { + this.listener.valueChanged(this.buildValue()); } - - @Override - protected ImageDescriptor buildValue_() { - if ((this.mappingModel.getValue() != null) && (this.isXmlTransientModel.getValue() == Boolean.TRUE)) { - return JptJaxbUiImages.JAXB_TRANSIENT_ENUM; - } - return JptJaxbUiImages.JAXB_ENUM; + + private ImageDescriptor buildValue() { + return ((this.mapping != null) && ObjectTools.equals(this.xmlTransient, Boolean.TRUE)) ? + JptJaxbUiImages.JAXB_TRANSIENT_ENUM : + JptJaxbUiImages.JAXB_ENUM; } - @Override - protected void engageSubject_() { - this.mappingModel.addPropertyChangeListener(VALUE, this.propertyChangeListener); - this.isXmlTransientModel.addPropertyChangeListener(VALUE, this.propertyChangeListener); + public ImageDescriptor engageModel() { + this.mappingModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.mappingListener); + this.mapping = this.mappingModel.getValue(); + this.xmlTransientModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.xmlTransientListener); + this.xmlTransient = this.xmlTransientModel.getValue(); + return this.buildValue(); } - - @Override - protected void disengageSubject_() { - this.mappingModel.removePropertyChangeListener(VALUE, this.propertyChangeListener); - this.isXmlTransientModel.removePropertyChangeListener(VALUE, this.propertyChangeListener); + + public ImageDescriptor disengageModel() { + this.mappingModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.mappingListener); + this.mapping = null; + this.xmlTransientModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.xmlTransientListener); + this.xmlTransient = null; + return null; + } + + // ********** Factory ********** + + public static class Factory + implements PluggablePropertyValueModel.Adapter.Factory<ImageDescriptor> + { + private final JavaEnum javaEnum; + + public Factory(JavaEnum javaEnum) { + super(); + if (javaEnum == null) { + throw new NullPointerException(); + } + this.javaEnum = javaEnum; + } + + public JavaEnumImageDescriptorModelAdapter buildAdapter(PluggablePropertyValueModel.Adapter.Listener<ImageDescriptor> listener) { + return new JavaEnumImageDescriptorModelAdapter(this.javaEnum, listener); + } + + @Override + public String toString() { + return ObjectTools.toString(this); + } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfile.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfile.java index a8815874ce..747371b127 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfile.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionProfile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. + * Copyright (c) 2008, 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. @@ -12,6 +12,8 @@ package org.eclipse.jpt.jpa.db; import java.sql.Connection; import org.eclipse.core.runtime.IStatus; import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; /** * Database connection profile @@ -134,6 +136,15 @@ public interface ConnectionProfile * @see #isActive() */ boolean isConnected(); + Transformer<ConnectionProfile, Boolean> CONNECTED_TRANSFORMER = new DisconnectedTransformer(); + class ConnectedTransformer + extends TransformerAdapter<ConnectionProfile, Boolean> + { + @Override + public Boolean transform(ConnectionProfile connectionProfile) { + return Boolean.valueOf(connectionProfile.isConnected()); + } + } /** * Return whether the profile is not connected to a live database session @@ -142,6 +153,15 @@ public interface ConnectionProfile * @see #isConnected() */ boolean isDisconnected(); + Transformer<ConnectionProfile, Boolean> DISCONNECTED_TRANSFORMER = new DisconnectedTransformer(); + class DisconnectedTransformer + extends TransformerAdapter<ConnectionProfile, Boolean> + { + @Override + public Boolean transform(ConnectionProfile connectionProfile) { + return Boolean.valueOf(connectionProfile.isDisconnected()); + } + } /** * Connect to the database. diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java index 090576b9e7..677f58a199 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java @@ -12,7 +12,6 @@ package org.eclipse.jpt.jpa.ui.internal; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.jpt.common.utility.internal.model.value.BasePluggablePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.model.value.CollectionPluggablePropertyValueModelAdapter; import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel; import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools; @@ -90,7 +89,7 @@ public class ProjectAdapterFactory * (At least we hope there is only a single JPA project remaining.) */ LocalJpaProjectModel(IProject project) { - super(new CollectionPluggablePropertyValueModelAdapter.Factory<>( + super(CollectionValueModelTools.pluggablePropertyValueModelAdapterFactory( CollectionValueModelTools.filter( project.getWorkspace().getAdapter(JpaProjectsModel.class), new JpaProject.ProjectEquals(project) diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java index 403569095b..a30af934bc 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java @@ -34,15 +34,16 @@ import org.eclipse.jpt.common.utility.Association; import org.eclipse.jpt.common.utility.internal.BitTools; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.jpt.common.utility.internal.closure.ClosureAdapter; import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.model.value.AbstractCollectionValueModel; import org.eclipse.jpt.common.utility.internal.model.value.AspectCollectionValueModelAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter; import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel; import org.eclipse.jpt.common.utility.internal.model.value.ExtendedListValueModelWrapper; import org.eclipse.jpt.common.utility.internal.model.value.PluggableModifiablePropertyValueModel; +import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyAspectAdapter; import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel; import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapterXXXX; import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter; @@ -238,10 +239,45 @@ public class JpaProjectPropertiesPage } // ***** JPA platform config model + /** + * The JPA platform ID is stored in the project preferences. + * The JPA platform does not change for a JPA project - if the user wants a + * different JPA platform, we build an entirely new JPA project. + */ private Association<ModifiablePropertyValueModel<JpaPlatform.Config>, PropertyValueModel<Boolean>> buildJpaPlatformConfigModel() { - return PropertyValueModelTools.buffer(new JpaPlatformConfigModel(this.jpaProjectModel), this.trigger); + return PropertyValueModelTools.buffer(this.buildJpaPlatformConfigModel_(), this.trigger); + } + + private ModifiablePropertyValueModel<JpaPlatform.Config> buildJpaPlatformConfigModel_() { + return PropertyValueModelTools.transform(this.jpaProjectModel, JPA_PROJECT_PLATFORM_CONFIG_TRANSFORMER, new JpaProjectSetPlatformConfigClosure()); + } + + private static final TransformerAdapter<JpaProject, JpaPlatform.Config> JPA_PROJECT_PLATFORM_CONFIG_TRANSFORMER = new JpaProjectPlatformConfigTransformer(); + static class JpaProjectPlatformConfigTransformer + extends TransformerAdapter<JpaProject, JpaPlatform.Config> + { + @Override + public JpaPlatform.Config transform(JpaProject jpaProject) { + String jpaPlatformID = JpaPreferences.getJpaPlatformID(jpaProject.getProject()); + JpaPlatformManager jpaPlatformManager = getJpaPlatformManager(); + return (jpaPlatformManager == null) ? null : jpaPlatformManager.getJpaPlatformConfig(jpaPlatformID); + } } + class JpaProjectSetPlatformConfigClosure + extends ClosureAdapter<JpaPlatform.Config> + { + @Override + public void execute(JpaPlatform.Config platformConfig) { + JpaProjectPropertiesPage.this.setJpaProjectPlatformConfig(platformConfig); + } + } + + void setJpaProjectPlatformConfig(JpaPlatform.Config jpaPlatformConfig) { + String jpaPlatformID = jpaPlatformConfig.getId(); + JpaPreferences.setJpaPlatformID(this.jpaProjectModel.getValue().getProject(), jpaPlatformID); + } + private PropertyChangeListener buildJpaPlatformConfigListener(){ return new JpaPlatformConfigListener(); } @@ -283,8 +319,15 @@ public class JpaProjectPropertiesPage } } + /** + * Monitor the connection profile's connection to the database + * (used to enable the "Connect" link) + */ private PropertyValueModel<Boolean> buildDisconnectedModel() { - return new DisconnectedModel(this.connectionProfileModel); + return PropertyValueModelTools.aspectAdapter( + this.connectionProfileModel, + new ConnectionProfilePropertyAspectAdapter.Factory<>(ConnectionProfile.DISCONNECTED_TRANSFORMER) + ); } // ***** catalog models @@ -308,8 +351,14 @@ public class JpaProjectPropertiesPage ); } + /** + * Database-determined default catalog + */ private PropertyValueModel<String> buildDatabaseDefaultCatalogModel() { - return new DatabaseDefaultCatalogModel(this.connectionProfileModel); + return PropertyValueModelTools.aspectAdapter( + this.connectionProfileModel, + new ConnectionProfilePropertyAspectAdapter.Factory<>(CONNECTION_PROFILE_DATABASE_DEFAULT_CATALOG_TRANSFORMER) + ); } /** @@ -358,7 +407,11 @@ public class JpaProjectPropertiesPage } private PropertyValueModel<String> buildDatabaseDefaultSchemaModel() { - return new DatabaseDefaultSchemaModel(this.connectionProfileModel, this.defaultCatalogModel); + return PropertyValueModelTools.propertyValueModel(this.buildDatabaseDefaultSchemaModelAdapterFactory()); + } + + private PluggablePropertyValueModel.Adapter.Factory<String> buildDatabaseDefaultSchemaModelAdapterFactory() { + return new DatabaseDefaultSchemaModelAdapter.Factory(this.connectionProfileModel, this.disconnectedModel, this.defaultCatalogModel); } /** @@ -1051,44 +1104,6 @@ public class JpaProjectPropertiesPage /** - * Treat the JPA platform config as an "aspect" of the JPA project. - * The JPA platform ID is stored in the project preferences. - * The JPA platform does not change for a JPA project - if the user wants a - * different JPA platform, we build an entirely new JPA project. - */ - static class JpaPlatformConfigModel - extends AspectPropertyValueModelAdapter<JpaProject, JpaPlatform.Config> - { - JpaPlatformConfigModel(PropertyValueModel<JpaProject> jpaProjectModel) { - super(jpaProjectModel); - } - - @Override - protected JpaPlatform.Config buildValue_() { - String jpaPlatformID = JpaPreferences.getJpaPlatformID(this.subject.getProject()); - JpaPlatformManager jpaPlatformManager = getJpaPlatformManager(); - return (jpaPlatformManager == null) ? null : jpaPlatformManager.getJpaPlatformConfig(jpaPlatformID); - } - - @Override - public void setValue_(JpaPlatform.Config jpaPlatformConfig) { - String jpaPlatformID = jpaPlatformConfig.getId(); - JpaPreferences.setJpaPlatformID(this.subject.getProject(), jpaPlatformID); - } - - @Override - protected void engageSubject_() { - // the JPA platform does not change - } - - @Override - protected void disengageSubject_() { - // the JPA platform does not change - } - } - - - /** * The connections are held by a singleton, so the model can be a singleton * also. */ @@ -1420,23 +1435,31 @@ public class JpaProjectPropertiesPage /** - * Abstract property aspect adapter for DTP connection profile connection/database + * property aspect adapter for DTP connection profile connection/database */ - abstract static class ConnectionProfilePropertyAspectAdapter<V> - extends AspectPropertyValueModelAdapter<ConnectionProfile, V> + static class ConnectionProfilePropertyAspectAdapter<V> + implements PluggablePropertyAspectAdapter.SubjectAdapter<V, ConnectionProfile> { + private final Transformer<? super ConnectionProfile, ? extends V> transformer; + private final PluggablePropertyAspectAdapter.SubjectAdapter.Listener<V> listener; private final ConnectionListener connectionListener; - ConnectionProfilePropertyAspectAdapter(PropertyValueModel<ConnectionProfile> connectionProfileModel) { - super(connectionProfileModel); - this.connectionListener = this.buildConnectionListener(); - } + ConnectionProfilePropertyAspectAdapter(Transformer<? super ConnectionProfile, ? extends V> transformer, PluggablePropertyAspectAdapter.SubjectAdapter.Listener<V> listener) { + super(); + if (transformer == null) { + throw new NullPointerException(); + } + this.transformer = transformer; - // the connection opening is probably the only thing that will happen... - private ConnectionListener buildConnectionListener() { - return new LocalConnectionListener(); + if (listener == null) { + throw new NullPointerException(); + } + this.listener = listener; + + this.connectionListener = new LocalConnectionListener(); } + // the connection opening is probably the only thing that will happen... class LocalConnectionListener extends ConnectionAdapter { @@ -1447,54 +1470,58 @@ public class JpaProjectPropertiesPage } void connectionOpened(ConnectionProfile profile) { - if (profile.equals(this.subject)) { - this.aspectChanged(); - } + this.listener.valueChanged(this.transformer.transform(profile)); } - @Override - protected void engageSubject_() { - this.subject.addConnectionListener(this.connectionListener); + public V engageSubject(ConnectionProfile subject) { + if (subject != null) { + subject.addConnectionListener(this.connectionListener); + } + return this.transformer.transform(subject); } - @Override - protected void disengageSubject_() { - this.subject.removeConnectionListener(this.connectionListener); + public V disengageSubject(ConnectionProfile subject) { + if (subject != null) { + subject.removeConnectionListener(this.connectionListener); + } + return this.transformer.transform(subject); } - } + // ********** Factory ********** - /** - * Monitor the connection profile's connection to the database - * (used to enable the "Connect" link) - */ - static class DisconnectedModel - extends ConnectionProfilePropertyAspectAdapter<Boolean> - { - DisconnectedModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) { - super(connectionProfileModel); - } + static class Factory<V> + implements PluggablePropertyAspectAdapter.SubjectAdapter.Factory<V, ConnectionProfile> + { + /* CU private */ final Transformer<? super ConnectionProfile, ? extends V> transformer; - @Override - protected Boolean buildValue_() { - return Boolean.valueOf((this.subject != null) && this.subject.isDisconnected()); + public Factory(Transformer<? super ConnectionProfile, ? extends V> transformer) { + super(); + if (transformer == null) { + throw new NullPointerException(); + } + this.transformer = TransformerTools.nullCheck(transformer); + } + + public PluggablePropertyAspectAdapter.SubjectAdapter<V, ConnectionProfile> buildAdapter(PluggablePropertyAspectAdapter.SubjectAdapter.Listener<V> listener) { + return new ConnectionProfilePropertyAspectAdapter<>(this.transformer, listener); + } + + @Override + public String toString() { + return ObjectTools.toString(this); + } } } - /** - * Database-determined default catalog - */ - static class DatabaseDefaultCatalogModel - extends ConnectionProfilePropertyAspectAdapter<String> - { - DatabaseDefaultCatalogModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) { - super(connectionProfileModel); - } + private static final Transformer<ConnectionProfile, String> CONNECTION_PROFILE_DATABASE_DEFAULT_CATALOG_TRANSFORMER = new ConnectionProfileDatabaseDefaultCatalogTransformer(); + static class ConnectionProfileDatabaseDefaultCatalogTransformer + extends TransformerAdapter<ConnectionProfile, String> + { @Override - protected String buildValue_() { - Database db = this.subject.getDatabase(); + public String transform(ConnectionProfile cp) { + Database db = cp.getDatabase(); return (db == null) ? null : db.getDefaultCatalogIdentifier(); } } @@ -1505,48 +1532,90 @@ public class JpaProjectPropertiesPage * on the current value of the default catalog (which may be overridden * by the user). */ - static class DatabaseDefaultSchemaModel - extends ConnectionProfilePropertyAspectAdapter<String> + static class DatabaseDefaultSchemaModelAdapter + implements PluggablePropertyValueModel.Adapter<String> { + private final PropertyValueModel<ConnectionProfile> connectionProfileModel; + private final PropertyChangeListener connectionProfileListener; + /* class private */ volatile ConnectionProfile connectionProfile; + + private final PropertyValueModel<Boolean> connectionProfileConnectedModel; + private final PropertyChangeListener connectionProfileConnectedListener; + /* class private */ volatile Boolean connectionProfileConnected; + private final PropertyValueModel<String> defaultCatalogModel; - private final PropertyChangeListener catalogListener; + private final PropertyChangeListener defaultCatalogListener; + /* class private */ volatile String defaultCatalog; + + private final PluggablePropertyValueModel.Adapter.Listener<String> listener; + - DatabaseDefaultSchemaModel( + DatabaseDefaultSchemaModelAdapter( PropertyValueModel<ConnectionProfile> connectionProfileModel, - PropertyValueModel<String> defaultCatalogModel + PropertyValueModel<Boolean> connectionProfileConnectedModel, + PropertyValueModel<String> defaultCatalogModel, + PluggablePropertyValueModel.Adapter.Listener<String> listener ) { - super(connectionProfileModel); + super(); + if (connectionProfileModel == null) { + throw new NullPointerException(); + } + this.connectionProfileModel = connectionProfileModel; + this.connectionProfileListener = new ConnectionProfileListener(); + + if (connectionProfileConnectedModel == null) { + throw new NullPointerException(); + } + this.connectionProfileConnectedModel = connectionProfileConnectedModel; + this.connectionProfileConnectedListener = new ConnectionProfileConnectedListener(); + + if (defaultCatalogModel == null) { + throw new NullPointerException(); + } this.defaultCatalogModel = defaultCatalogModel; - this.catalogListener = new CatalogListener(); + this.defaultCatalogListener = new DefaultCatalogListener(); + + if (listener == null) { + throw new NullPointerException(); + } + this.listener = listener; } - /* class private */ class CatalogListener + /* class private */ class ConnectionProfileListener extends PropertyChangeAdapter { @Override public void propertyChanged(PropertyChangeEvent event) { - DatabaseDefaultSchemaModel.this.catalogChanged(); + DatabaseDefaultSchemaModelAdapter.this.connectionProfile = (ConnectionProfile) event.getNewValue(); + DatabaseDefaultSchemaModelAdapter.this.update(); } } - void catalogChanged() { - this.aspectChanged(); + /* class private */ class ConnectionProfileConnectedListener + extends PropertyChangeAdapter + { + @Override + public void propertyChanged(PropertyChangeEvent event) { + DatabaseDefaultSchemaModelAdapter.this.connectionProfileConnected = (Boolean) event.getNewValue(); + DatabaseDefaultSchemaModelAdapter.this.update(); + } } - @Override - protected void engageSubject_() { - super.engageSubject_(); - this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); + /* class private */ class DefaultCatalogListener + extends PropertyChangeAdapter + { + @Override + public void propertyChanged(PropertyChangeEvent event) { + DatabaseDefaultSchemaModelAdapter.this.defaultCatalog = (String) event.getNewValue(); + DatabaseDefaultSchemaModelAdapter.this.update(); + } } - @Override - protected void disengageSubject_() { - this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); - super.disengageSubject_(); + /* class private */ void update() { + this.listener.valueChanged(this.buildValue()); } - @Override - protected String buildValue_() { + private String buildValue() { SchemaContainer sc = this.getSchemaContainer(); return (sc == null) ? null : sc.getDefaultSchemaIdentifier(); } @@ -1561,13 +1630,75 @@ public class JpaProjectPropertiesPage } private Catalog getCatalog() { - String name = this.defaultCatalogModel.getValue(); // if we get here we know the database is not null - return (name == null) ? null : this.getDatabase().getCatalogForIdentifier(name); + return (this.defaultCatalog == null) ? null : this.getDatabase().getCatalogForIdentifier(this.defaultCatalog); } private Database getDatabase() { - return this.subject.getDatabase(); + return (this.connectionProfile == null) ? null : this.connectionProfile.getDatabase(); + } + + public String engageModel() { + this.connectionProfileModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.connectionProfileListener); + this.connectionProfile = this.connectionProfileModel.getValue(); + this.connectionProfileConnectedModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.connectionProfileConnectedListener); + this.connectionProfileConnected = this.connectionProfileConnectedModel.getValue(); + this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.defaultCatalogListener); + this.defaultCatalog = this.defaultCatalogModel.getValue(); + return this.buildValue(); + } + + public String disengageModel() { + this.connectionProfileModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.connectionProfileListener); + this.connectionProfile = null; + this.connectionProfileConnectedModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.connectionProfileConnectedListener); + this.connectionProfileConnected = null; + this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.defaultCatalogListener); + this.defaultCatalog = null; + return null; + } + + // ********** Factory ********** + + static class Factory + implements PluggablePropertyValueModel.Adapter.Factory<String> + { + private final PropertyValueModel<ConnectionProfile> connectionProfileModel; + + private final PropertyValueModel<Boolean> connectionProfileConnectedModel; + + private final PropertyValueModel<String> defaultCatalogModel; + + public Factory( + PropertyValueModel<ConnectionProfile> connectionProfileModel, + PropertyValueModel<Boolean> connectionProfileConnectedModel, + PropertyValueModel<String> defaultCatalogModel + ) { + super(); + if (connectionProfileModel == null) { + throw new NullPointerException(); + } + this.connectionProfileModel = connectionProfileModel; + + if (connectionProfileConnectedModel == null) { + throw new NullPointerException(); + } + this.connectionProfileConnectedModel = connectionProfileConnectedModel; + + if (defaultCatalogModel == null) { + throw new NullPointerException(); + } + this.defaultCatalogModel = defaultCatalogModel; + } + + public DatabaseDefaultSchemaModelAdapter buildAdapter(PluggablePropertyValueModel.Adapter.Listener<String> listener) { + return new DatabaseDefaultSchemaModelAdapter(this.connectionProfileModel, this.connectionProfileConnectedModel, this.defaultCatalogModel, listener); + } + + @Override + public String toString() { + return ObjectTools.toString(this); + } } } @@ -1733,7 +1864,6 @@ public class JpaProjectPropertiesPage /* CU private */ volatile String databaseDefault = null; private final PluggablePropertyValueModel.Adapter.Listener<String> listener; - private volatile String value = null; public DefaultDatabaseComponentModelAdapter(Factory factory, PluggablePropertyValueModel.Adapter.Listener<String> listener) { @@ -1763,18 +1893,18 @@ public class JpaProjectPropertiesPage this.userOverrideDefaultFlagModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.userOverrideDefaultFlagListener); this.userOverrideDefaultModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.userOverrideDefaultListener); this.databaseDefaultModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.databaseDefaultListener); - return this.value = this.buildValue(); + return this.buildValue(); } public String disengageModel() { this.databaseDefaultModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.databaseDefaultListener); this.userOverrideDefaultModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.userOverrideDefaultListener); this.userOverrideDefaultFlagModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.userOverrideDefaultFlagListener); - return this.value = null; + return null; } /* CU private */ void update() { - this.listener.valueChanged(this.value = this.buildValue()); + this.listener.valueChanged(this.buildValue()); } /** @@ -1787,7 +1917,7 @@ public class JpaProjectPropertiesPage @Override public String toString() { - return ObjectTools.toString(this, this.value); + return ObjectTools.toString(this, this.buildValue()); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java index baaa8e2a9e..e77b1f86b6 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 Oracle. All rights reserved. + * Copyright (c) 2010, 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. @@ -55,10 +55,11 @@ import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; -import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter; +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.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools; 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.ModifiablePropertyValueModel; @@ -304,7 +305,8 @@ public class JpaMakePersistentWizardPage } }); - SWTBindingTools.bindEnabledState(new ListInOrmMappingFileModel(this.annotateInJavaModel), mappingFileLink, mappingFileText, browseButton); + PropertyValueModel<Boolean> notAnnotateInJavaModel = PropertyValueModelTools.transform_(this.annotateInJavaModel, TransformerTools.notBooleanTransformer()); + SWTBindingTools.bindEnabledState(notAnnotateInJavaModel, mappingFileLink, mappingFileText, browseButton); return composite; } @@ -649,24 +651,6 @@ public class JpaMakePersistentWizardPage return this.javaElementComparator.compare(viewer, ((TypeConfig) e1).jdtType, ((TypeConfig) e2).jdtType); } } - - static class ListInOrmMappingFileModel - extends AspectPropertyValueModelAdapter<Boolean, Boolean> - { - ListInOrmMappingFileModel(PropertyValueModel<Boolean> annotateInJavaModel) { - super(annotateInJavaModel); - } - - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(!this.subject.booleanValue()); - } - - @Override - protected void engageSubject_() {/*nothing*/} - @Override - protected void disengageSubject_() {/*nothing*/} - } // ********** add to orm.xml runnable ********** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizardPage.java index 85fd248484..781002d4a0 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 Oracle. All rights reserved. + * Copyright (c) 2010, 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. @@ -56,8 +56,9 @@ import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools; -import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter; +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.transformer.TransformerTools; 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.ModifiablePropertyValueModel; @@ -315,7 +316,8 @@ public class JpaMakePersistentWizardPage } }); - SWTBindingTools.bindEnabledState(new ListInOrmMappingFileModel(this.annotateInJavaModel), mappingFileLink, mappingFileText, browseButton); + PropertyValueModel<Boolean> notAnnotateInJavaModel = PropertyValueModelTools.transform_(this.annotateInJavaModel, TransformerTools.notBooleanTransformer()); + SWTBindingTools.bindEnabledState(notAnnotateInJavaModel, mappingFileLink, mappingFileText, browseButton); return composite; } @@ -634,24 +636,6 @@ public class JpaMakePersistentWizardPage } } - static class ListInOrmMappingFileModel - extends AspectPropertyValueModelAdapter<Boolean, Boolean> - { - ListInOrmMappingFileModel(PropertyValueModel<Boolean> annotateInJavaModel) { - super(annotateInJavaModel); - } - - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(!this.subject.booleanValue()); - } - - @Override - protected void engageSubject_() {/*nothing*/} - @Override - protected void disengageSubject_() {/*nothing*/} - } - // ********** add to orm.xml runnable ********** |