Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java22
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java9
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPluggablePropertyValueModel.java239
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java118
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPluggablePropertyValueModelAdapter.java169
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPropertyValueModelAdapter.java174
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelTools.java342
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java13
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java350
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java197
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModelAdapter.java266
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ElementPropertyValueModelAdapter.java131
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java43
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCompositePropertyValueModelAdapter.java284
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPluggablePropertyValueModelAdapter.java189
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPropertyValueModelAdapter.java176
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelTools.java222
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java60
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java93
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyValueModel.java39
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueModelTools.java)30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java18
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java220
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionValueModelToolsTests.java438
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeAndBooleanPropertyValueModelTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeBooleanPropertyValueModelTests.java)68
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeOrBooleanPropertyValueModelTests.java227
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java144
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java119
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java8
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListCompositePropertyValueModelTests.java304
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListPropertyValueModelAdapterTests.java316
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListValueModelToolsTests.java438
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java175
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JaxbProjectModel.java8
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ProjectAdapterFactory.java62
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertCombo.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertersComposite.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java70
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkTenantDiscriminatorColumnsComposite.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java69
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityCachingPropertyComposite.java86
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityListComposite.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/customization/EclipseLinkEntityListComposite.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java88
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java64
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractSecondaryTablesComposite.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/IdMappingGenerationComposite.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java48
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java72
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java78
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/QueriesComposite.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java40
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPrimaryKeyJoinColumnsComposite.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsGeneratorsComposite.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPrimaryKeyJoinColumnsComposite.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmSecondaryTablesComposite.java49
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/JpaXmlEditor.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/CollectionTableComposite2_0.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceUnitEditorPageDefinition2_0.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/PersistenceUnitClassesComposite.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/AbstractNavigatorItemContentProviderFactory.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java259
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java80
73 files changed, 4959 insertions, 2164 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java
index 373833d6a6..df59dc5316 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2011, 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.
@@ -73,7 +73,7 @@ public abstract class JptProjectPropertiesPage
public JptProjectPropertiesPage() {
super();
- this.projectModel = new SimplePropertyValueModel<IProject>();
+ this.projectModel = new SimplePropertyValueModel<>();
this.trigger = new BufferedModifiablePropertyValueModel.Trigger();
this.buildModels();
@@ -438,7 +438,7 @@ public abstract class JptProjectPropertiesPage
@Override
protected IStatus performValidation() {
- HashMap<Integer, ArrayList<IStatus>> statuses = new HashMap<Integer, ArrayList<IStatus>>();
+ HashMap<Integer, ArrayList<IStatus>> statuses = new HashMap<>();
statuses.put(ERROR_STATUS, new ArrayList<IStatus>());
statuses.put(WARNING_STATUS, new ArrayList<IStatus>());
statuses.put(INFO_STATUS, new ArrayList<IStatus>());
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java
index c743b4d086..cd88a5a9f9 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -16,7 +16,7 @@ import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterable.EmptyListIterable;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
@@ -753,25 +753,15 @@ public abstract class AddRemovePane<T extends Model, E extends Object> extends P
}
protected PropertyValueModel<Boolean> buildSingleSelectedItemEnabledModel(CollectionValueModel<E> selectedItemsModel) {
- return new CollectionPropertyValueModelAdapter<Boolean, Object>(selectedItemsModel) {
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.collectionModel.size() == 1);
- }
- };
+ return CollectionValueModelTools.containsSingleElementPropertyValueModel(selectedItemsModel);
}
public PropertyValueModel<Boolean> buildRemoveButtonEnabledModel(CollectionValueModel<E> selectedItemsModel) {
- return this.buildMultipleSelectedItemsEnabledModel(selectedItemsModel);
+ return this.buildOneOrMoreSelectedItemsEnabledModel(selectedItemsModel);
}
- protected PropertyValueModel<Boolean> buildMultipleSelectedItemsEnabledModel(CollectionValueModel<E> selectedItemsModel) {
- return new CollectionPropertyValueModelAdapter<Boolean, E>(selectedItemsModel) {
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.collectionModel.size() >= 1);
- }
- };
+ protected PropertyValueModel<Boolean> buildOneOrMoreSelectedItemsEnabledModel(CollectionValueModel<E> selectedItemsModel) {
+ return CollectionValueModelTools.isNotEmptyPropertyValueModel(selectedItemsModel);
}
/*
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
index 93616257cc..f6d95bbaed 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -27,7 +27,7 @@ import org.eclipse.jpt.common.ui.internal.swt.TriStateCheckBoxModelAdapter;
import org.eclipse.jpt.common.ui.internal.swt.bindings.SWTBindingTools;
import org.eclipse.jpt.common.ui.internal.swt.events.DisposeAdapter;
import org.eclipse.jpt.common.ui.internal.swt.listeners.SWTListenerTools;
-import org.eclipse.jpt.common.utility.internal.model.value.CompositeBooleanPropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.NullCheckPropertyValueModelWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.PredicatePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
@@ -334,11 +334,10 @@ public abstract class Pane<T extends Model> {
* pane is <em>enabled</em> <em>and</em> the pane's model indicates the
* pane should be <em>enabled</em>.
*/
- @SuppressWarnings("unchecked")
private static PropertyValueModel<Boolean> andEnabledModel(Pane<?> pane, PropertyValueModel<Boolean> enabledModel) {
enabledModel = buildNonNullModel(enabledModel);
// NB: we fetch private state from the pane
- return (pane == null) ? enabledModel : CompositeBooleanPropertyValueModel.and(pane.enabledModel, enabledModel);
+ return (pane == null) ? enabledModel : CollectionValueModelTools.and(pane.enabledModel, enabledModel);
}
/**
@@ -351,7 +350,7 @@ public abstract class Pane<T extends Model> {
* (which is typical with aspect adapters etc.).
*/
private static PropertyValueModel<Boolean> buildNonNullModel(PropertyValueModel<Boolean> booleanModel) {
- return new NullCheckPropertyValueModelWrapper<Boolean>(booleanModel, Boolean.FALSE);
+ return new NullCheckPropertyValueModelWrapper<>(booleanModel, Boolean.FALSE);
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPluggablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPluggablePropertyValueModel.java
new file mode 100644
index 0000000000..7dcf3cc7c9
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPluggablePropertyValueModel.java
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * 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.
+ *
+ * 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.internal.model.AbstractModel;
+import org.eclipse.jpt.common.utility.internal.model.ChangeSupport;
+import org.eclipse.jpt.common.utility.internal.model.SingleAspectChangeSupport;
+import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+
+/**
+ * This class provides the infrastructure needed to wrap
+ * a model, "lazily" listen to it, and convert
+ * its change notifications into <em>property</em> value model change
+ * notifications.
+ *
+ * @param <V> the type of the model's derived value
+ */
+public abstract class AbstractPluggablePropertyValueModel<V, A extends AbstractPluggablePropertyValueModel.Adapter<V>>
+ extends AbstractModel
+ implements PropertyValueModel<V>
+{
+ /**
+ * Adapter that listens to some model and
+ * calls back whenever that model changes in a way that
+ * affects this model's value.
+ */
+ protected final A adapter;
+
+ /**
+ * Cache the current value so we can pass an "old value" when
+ * we fire a property change event.
+ * We need this because the value may be calculated and we may
+ * not able to derive the "old value" from any fired events.
+ */
+ protected volatile V value;
+
+
+ // ********** constructor/initialization **********
+
+ protected AbstractPluggablePropertyValueModel(Adapter.Factory<V, A> adapterFactory) {
+ super();
+ if (adapterFactory == null) {
+ throw new NullPointerException();
+ }
+ // a bit of instance leakage...
+ this.adapter = adapterFactory.buildAdapter(new AdapterListener());
+ // our value is null when we are not listening to the model
+ this.value = null;
+ }
+
+ @Override
+ protected ChangeSupport buildChangeSupport() {
+ return new SingleAspectChangeSupport(this, PropertyChangeListener.class, PropertyValueModel.VALUE);
+ }
+
+
+ // ********** PropertyValueModel implementation **********
+
+ /**
+ * Return the cached value.
+ */
+ public V getValue() {
+ return this.value;
+ }
+
+
+ // ********** listeners **********
+
+ /**
+ * Extend to start listening to the underlying model if necessary.
+ */
+ @Override
+ public synchronized void addChangeListener(ChangeListener listener) {
+ if (this.hasNoListeners()) {
+ this.engageModel();
+ }
+ super.addChangeListener(listener);
+ }
+
+ /**
+ * Extend to stop listening to the underlying model if necessary.
+ */
+ @Override
+ public synchronized void removeChangeListener(ChangeListener listener) {
+ super.removeChangeListener(listener);
+ if (this.hasNoListeners()) {
+ this.disengageModel();
+ }
+ }
+
+ /**
+ * Extend to start listening to the underlying model if necessary.
+ */
+ @Override
+ public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ if (propertyName.equals(PropertyValueModel.VALUE) && this.hasNoListeners()) {
+ this.engageModel();
+ }
+ super.addPropertyChangeListener(propertyName, listener);
+ }
+
+ /**
+ * Extend to stop listening to the underlying model if necessary.
+ */
+ @Override
+ public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ super.removePropertyChangeListener(propertyName, listener);
+ if (propertyName.equals(PropertyValueModel.VALUE) && this.hasNoListeners()) {
+ this.disengageModel();
+ }
+ }
+
+ /**
+ * Return whether the model has no property value listeners.
+ */
+ public boolean hasNoListeners() {
+ return ! this.hasListeners();
+ }
+
+ /**
+ * Return whether the model has any property value listeners.
+ */
+ public boolean hasListeners() {
+ return this.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE);
+ }
+
+ /**
+ * Start listening to the underlying model and build the value.
+ */
+ protected void engageModel() {
+ this.adapter.engageModel();
+ // sync our value *after* we start listening to the model,
+ // since the model's value might change when a listener is added
+ this.value = this.adapter.getValue();
+ }
+
+ /**
+ * Clear the value and stop listening to the underlying model.
+ */
+ private void disengageModel() {
+ // clear out our value when we are not listening to the model
+ this.value = null;
+ this.adapter.disengageModel();
+ }
+
+
+ // ********** Misc **********
+
+ /**
+ * The underlying model changed in some fashion.
+ * Notify our listeners.
+ */
+ /* CU private */ void valueChanged(V newValue) {
+ Object old = this.value;
+ this.firePropertyChanged(VALUE, old, this.value = newValue);
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.value);
+ }
+
+
+ // ********** Adapter Listener **********
+
+ /**
+ * Simple callback.
+ */
+ /* CU private */ class AdapterListener
+ implements Adapter.Listener<V>
+ {
+ public void valueChanged(V newValue) {
+ AbstractPluggablePropertyValueModel.this.valueChanged(newValue);
+ }
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this);
+ }
+ }
+
+
+ // ********** Adapter interfaces **********
+
+ /**
+ * Minimal methods necessary to adapt some model to {@link PropertyValueModel}.
+ * This adapter is expected to listen to its adapted model and notify the
+ * listener passed to it via its {@link Adapter.Factory factory}
+ * about any model changes.
+ */
+ public interface Adapter<AV> {
+ /**
+ * Return the current property value, as derived from the
+ * current state of the adapted model.
+ */
+ AV getValue();
+
+ /**
+ * Start listening to the adapted model.
+ */
+ void engageModel();
+
+ /**
+ * Stop listening to the adapted model.
+ */
+ void disengageModel();
+
+ /**
+ * Callback interface.
+ */
+ interface Listener<ALV> {
+ /**
+ * Callback to notify listener that the adapted model has changed.
+ */
+ void valueChanged(ALV newValue);
+ }
+
+ /**
+ * Adapter factory interface.
+ * This factory allows both the pluggable property value model and its
+ * adapter to have circular <em>final</em> references to each other.
+ */
+ interface Factory<AFV, A extends Adapter<AFV>> {
+ /**
+ * Create an adapter with the specified listener.
+ */
+ A buildAdapter(Listener<AFV> listener);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java
deleted file mode 100644
index a77b11b6cf..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-
-/**
- * This abstract class provides the infrastructure needed to wrap
- * a model, "lazily" listen to it, and convert
- * its change notifications into <em>property</em> value model change
- * notifications.
- * <p>
- * Subclasses must implement:<ul>
- * <li>{@link #buildValue()}<p>
- * to return the current property value, as derived from the
- * current state of the underlying model
- * <li>{@link #engageModel_()}<p>
- * to start listening to the underlying (adapted) model
- * <li>{@link #disengageModel_()}<p>
- * to stop listening to the underlying (adapted) model
- * </ul>
- * Subclasses can call {@link #propertyChanged()} whenever the calculated
- * value of the property changes (as determined by the subclass).
- *
- * @param <V> the type of the model's value
- */
-public abstract class AbstractPropertyValueModelAdapter<V>
- extends AbstractPropertyValueModel
- implements PropertyValueModel<V>
-{
- /**
- * Cache the current value so we can pass an "old value" when
- * we fire a property change event.
- * We need this because the value may be calculated and we may
- * not able to derive the "old value" from any fired events.
- */
- protected volatile V value;
-
-
- // ********** constructor/initialization **********
-
- protected AbstractPropertyValueModelAdapter() {
- super();
- // our value is null when we are not listening to the model
- this.value = null;
- }
-
-
- // ********** PropertyValueModel implementation **********
-
- /**
- * Return the cached value.
- */
- public V getValue() {
- return this.value;
- }
-
-
- // ********** behavior **********
-
- /**
- * Start listening to the underlying model and build the value.
- */
- @Override
- protected void engageModel() {
- this.engageModel_();
- // sync our value *after* we start listening to the model,
- // since the model's value might change when a listener is added
- this.value = this.buildValue();
- }
-
- /**
- * Start listening to the underlying model.
- */
- protected abstract void engageModel_();
-
- /**
- * Build and return the current value, as derived from the
- * current state of the underlying model.
- */
- protected abstract V buildValue();
-
- /**
- * Stop listening to the underlying model and clear the value.
- */
- @Override
- protected void disengageModel() {
- this.disengageModel_();
- // clear out our value when we are not listening to the model
- this.value = null;
- }
-
- /**
- * Stop listening to the underlying model.
- */
- protected abstract void disengageModel_();
-
- /**
- * The underlying model changed in some fashion.
- * Recalculate the model's value and notify listeners.
- */
- protected void propertyChanged() {
- Object old = this.value;
- this.firePropertyChanged(VALUE, old, this.value = this.buildValue());
- }
-
- @Override
- public void toString(StringBuilder sb) {
- sb.append(this.value);
- }
-}
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
new file mode 100644
index 0000000000..4f2c0387c0
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPluggablePropertyValueModelAdapter.java
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel.Adapter;
+import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
+import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * Adapt a {@link CollectionValueModel collection value model} to
+ * a {@link PropertyValueModel property value model}, sorta.
+ * <p>
+ * This adapter is constructed with a {@link CollectionValueModel
+ * collection value model} and a {@link Transformer transformer} that can
+ * transform the collection to a single value.
+ * <p>
+ * This is an adapter that can be plugged into a {@link PluggablePropertyValueModel}.
+ *
+ * @param <E> the type of the adapted collection value model's elements
+ * @param <V> the type of the model's derived value
+ *
+ * @see PluggablePropertyValueModel
+ */
+public final class CollectionPluggablePropertyValueModelAdapter<E, V>
+ implements PluggablePropertyValueModel.Adapter<V>, CollectionChangeListener
+{
+ private final Factory<E, V> factory;
+
+ /** The <em>real</em> adapter. */
+ private final AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener;
+
+ /** Cached copy of model's elements. */
+ private final LinkedList<E> collection;
+
+ /** Protects {@link #collection} from {@link Factory#transformer}. */
+ private final Collection<E> unmodifiableCollection;
+
+ /** The derived value. */
+ private volatile V value;
+
+
+ // ********** constructors **********
+
+ public CollectionPluggablePropertyValueModelAdapter(Factory<E, V> factory, AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.factory = factory;
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ this.listener = listener;
+ this.collection = new LinkedList<>();
+ this.unmodifiableCollection = Collections.unmodifiableCollection(this.collection);
+ }
+
+
+ // ********** PropertyValueModelAdapter.Adapter **********
+
+ public V getValue() {
+ return this.value;
+ }
+
+ public void engageModel() {
+ this.factory.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this);
+ CollectionTools.addAll(this.collection, this.factory.collectionModel);
+ this.value = this.buildValue();
+ }
+
+ public void disengageModel() {
+ this.value = null;
+ this.collection.clear();
+ this.factory.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this);
+ }
+
+
+ // ********** CollectionChangeListener **********
+
+ @SuppressWarnings("unchecked")
+ public void itemsAdded(CollectionAddEvent event) {
+ CollectionTools.addAll(this.collection, (Iterable<E>) event.getItems());
+ this.update();
+ }
+
+ public void itemsRemoved(CollectionRemoveEvent event) {
+ CollectionTools.removeAll(this.collection, event.getItems());
+ this.update();
+ }
+
+ public void collectionCleared(CollectionClearEvent event) {
+ this.collection.clear();
+ this.update();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void collectionChanged(CollectionChangeEvent event) {
+ this.collection.clear();
+ CollectionTools.addAll(this.collection, (Iterable<E>) event.getCollection());
+ this.update();
+ }
+
+
+ // ********** misc **********
+
+ private void update() {
+ V newValue = this.buildValue();
+ this.value = newValue;
+ this.listener.valueChanged(newValue);
+ }
+
+ private V buildValue() {
+ return this.factory.transformer.transform(this.unmodifiableCollection);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.value);
+ }
+
+
+ // ********** PluggablePropertyValueModel.Adapter.Factory **********
+
+ public static class Factory<E, V>
+ implements PluggablePropertyValueModel.Adapter.Factory<V>
+ {
+ /* CU private */ final CollectionValueModel<? extends E> collectionModel;
+ /* CU private */ final Transformer<? super Collection<E>, V> transformer;
+
+ public Factory(CollectionValueModel<? extends E> collectionModel, Transformer<? super Collection<E>, V> transformer) {
+ super();
+ if (collectionModel == null) {
+ throw new NullPointerException();
+ }
+ this.collectionModel = collectionModel;
+ if (transformer == null) {
+ throw new NullPointerException();
+ }
+ this.transformer = transformer;
+ }
+
+ public Adapter<V> buildAdapter(AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ return new CollectionPluggablePropertyValueModelAdapter<>(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/CollectionPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPropertyValueModelAdapter.java
deleted file mode 100644
index 1f636e5fd1..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPropertyValueModelAdapter.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
-import org.eclipse.jpt.common.utility.model.listener.CollectionChangeAdapter;
-import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-
-/**
- * This abstract class provides the infrastructure needed to wrap
- * a collection value model, "lazily" listen to it, and convert
- * its change notifications into property value model change
- * notifications.
- * <p>
- * Subclasses must override:<ul>
- * <li>{@link #buildValue()}<p>
- * to return the current property value, as derived from the
- * current collection value
- * </ul>
- * Subclasses might want to override the following methods
- * to improve performance (by not recalculating the value, if possible):<ul>
- * <li>{@link #itemsAdded(CollectionAddEvent event)}
- * <li>{@link #itemsAdded(Iterable)}
- * <li>{@link #itemsRemoved(CollectionRemoveEvent event)}
- * <li>{@link #itemsRemoved(Iterable)}
- * <li>{@link #collectionCleared(CollectionClearEvent event)}
- * <li>{@link #collectionChanged(CollectionChangeEvent event)}
- * </ul>
- *
- * @param <V> the type of the model's value
- * @param <E> the type of the wrapped collection value model's elements
- */
-public abstract class CollectionPropertyValueModelAdapter<V, E>
- extends AbstractPropertyValueModelAdapter<V>
-{
- /** The wrapped collection value model. */
- protected final CollectionValueModel<? extends E> collectionModel;
-
- /** A listener that allows us to sync with changes to the wrapped collection model. */
- protected final CollectionChangeListener collectionListener;
-
-
- // ********** constructor/initialization **********
-
- /**
- * Construct a property value model with the specified wrapped
- * collection value model.
- */
- protected CollectionPropertyValueModelAdapter(CollectionValueModel<? extends E> collectionModel) {
- super();
- if (collectionModel == null) {
- throw new NullPointerException();
- }
- this.collectionModel = collectionModel;
- this.collectionListener = this.buildCollectionListener();
- }
-
- protected CollectionChangeListener buildCollectionListener() {
- return new CollectionListener();
- }
-
- /**
- * Straightforward callbacks to the adapter.
- */
- protected class CollectionListener
- extends CollectionChangeAdapter
- {
- @Override
- public void itemsAdded(CollectionAddEvent event) {
- CollectionPropertyValueModelAdapter.this.itemsAdded(event);
- }
- @Override
- public void itemsRemoved(CollectionRemoveEvent event) {
- CollectionPropertyValueModelAdapter.this.itemsRemoved(event);
- }
- @Override
- public void collectionCleared(CollectionClearEvent event) {
- CollectionPropertyValueModelAdapter.this.collectionCleared(event);
- }
- @Override
- public void collectionChanged(CollectionChangeEvent event) {
- CollectionPropertyValueModelAdapter.this.collectionChanged(event);
- }
- }
-
-
- // ********** listener **********
-
- /**
- * Start listening to the collection holder.
- */
- @Override
- protected void engageModel_() {
- this.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this.collectionListener);
- }
-
- /**
- * Stop listening to the collection holder.
- */
- @Override
- protected void disengageModel_() {
- this.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this.collectionListener);
- }
-
-
- // ********** collection change support **********
-
- /**
- * Items were added to the wrapped collection holder;
- * propagate the change notification appropriately.
- */
- protected void itemsAdded(CollectionAddEvent event) {
- @SuppressWarnings("unchecked")
- Iterable<E> items = (Iterable<E>) event.getItems();
- this.itemsAdded(items);
- }
-
- /**
- * The specified items were added to the wrapped collection holder;
- * propagate the change notification appropriately.
- */
- protected void itemsAdded(@SuppressWarnings("unused") Iterable<E> items) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * Items were removed from the wrapped collection holder;
- * propagate the change notification appropriately.
- */
- protected void itemsRemoved(CollectionRemoveEvent event) {
- @SuppressWarnings("unchecked")
- Iterable<E> items = (Iterable<E>) event.getItems();
- this.itemsRemoved(items);
- }
-
- /**
- * The specified items were removed from the wrapped collection holder;
- * propagate the change notification appropriately.
- */
- protected void itemsRemoved(@SuppressWarnings("unused") Iterable<E> items) {
- // by default, simply recalculate the value and fire an event if necessary
- this.propertyChanged();
- }
-
- /**
- * The wrapped collection holder was cleared;
- * propagate the change notification appropriately.
- */
- protected void collectionCleared(@SuppressWarnings("unused") CollectionClearEvent event) {
- // by default, simply recalculate the value and fire an event if necessary
- this.propertyChanged();
- }
-
- /**
- * The value of the wrapped collection holder has changed;
- * propagate the change notification appropriately.
- */
- protected void collectionChanged(@SuppressWarnings("unused") CollectionChangeEvent event) {
- // by default, simply recalculate the value and fire an event if necessary
- this.propertyChanged();
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelTools.java
new file mode 100644
index 0000000000..cf3ab7d6ae
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelTools.java
@@ -0,0 +1,342 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.eclipse.jpt.common.utility.closure.Closure;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
+import org.eclipse.jpt.common.utility.internal.closure.ClosureTools;
+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.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.predicate.Predicate;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * {@link CollectionValueModel Collection value model} utility methods.
+ */
+public final class CollectionValueModelTools {
+
+ // ********** composite PVMs **********
+
+ /**
+ * Construct a composite property value model adapter for the specified
+ * transformer and property value models.
+ */
+ @SafeVarargs
+ public static <E, V> PropertyValueModel<V> compositePropertyValueModel(Transformer<? super Collection<E>, V> transformer, PropertyValueModel<? extends E>... propertyValueModels) {
+ return compositePropertyValueModel(Arrays.asList(propertyValueModels), transformer);
+ }
+
+ /**
+ * Construct a composite property value model adapter for the specified
+ * property value models and transformer.
+ */
+ public static <E, V> PropertyValueModel<V> compositePropertyValueModel(Collection<? extends PropertyValueModel<? extends E>> propertyValueModels, Transformer<? super Collection<E>, V> transformer) {
+ return compositePropertyValueModel(new StaticCollectionValueModel<>(propertyValueModels), transformer);
+ }
+
+ /**
+ * Construct a composite property value model adapter for the specified
+ * collection value model and transformer.
+ * @see PluggablePropertyValueModel
+ */
+ public static <E, V> PropertyValueModel<V> compositePropertyValueModel(CollectionValueModel<? extends PropertyValueModel<? extends E>> collectionModel, Transformer<? super Collection<E>, V> transformer) {
+ return PropertyValueModelTools.propertyValueModel(new CompositePropertyValueModelAdapter.Factory<>(collectionModel, transformer));
+ }
+
+
+ // ********** collection meta data adapters **********
+
+ /**
+ * Construct a property value model adapter for the specified
+ * collection value model.
+ * If the collection is empty, the model's value is <code>null</code>;
+ * otherwise, it is the first element in the collection.
+ */
+ public static <E> PropertyValueModel<E> firstElementPropertyValueModel(CollectionValueModel<? extends E> collectionModel) {
+ return propertyValueModel(collectionModel, TransformerTools.collectionFirstElementTransformer());
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * collection value model.
+ * If the collection is empty, the model's value is <code>null</code>;
+ * otherwise, it is the last element in the collection.
+ */
+ public static <E> PropertyValueModel<E> lastElementPropertyValueModel(CollectionValueModel<? extends E> collectionModel) {
+ return propertyValueModel(collectionModel, TransformerTools.collectionLastElementTransformer());
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * collection value model.
+ * If the collection contains <em>only</em> a single element,
+ * the model's value is that element; otherwise,
+ * the model's value is <code>null</code>.
+ */
+ public static <E> PropertyValueModel<E> singleElementPropertyValueModel(CollectionValueModel<? extends E> collectionModel) {
+ return propertyValueModel(collectionModel, TransformerTools.collectionSingleElementTransformer());
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * collection value model that returns whether the collection is <em>not</em> empty.
+ */
+ public static PropertyValueModel<Boolean> isNotEmptyPropertyValueModel(CollectionValueModel<?> collectionModel) {
+ return propertyValueModel(collectionModel, TransformerTools.collectionIsNotEmptyTransformer());
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapter for the specified
+ * collection value model that returns whether the collection is <em>not</em> empty.
+ * This model can also be used to populate or clear the collection value model.
+ * The specified collection mutator is used to convert the collection value model:
+ * it should populate the collection value model when passed <code>true</code>
+ * and clear the collection value model when passed <code>false</code>.
+ */
+ public static ModifiablePropertyValueModel<Boolean> isNotEmptyModifiablePropertyValueModel(CollectionValueModel<?> collectionModel, BooleanClosure.Adapter collectionMutator) {
+ return booleanModifiablePropertyValueModel(collectionModel, TransformerTools.collectionIsNotEmptyTransformer(), collectionMutator);
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * collection value model that returns whether the collection is empty.
+ */
+ public static PropertyValueModel<Boolean> isEmptyPropertyValueModel(CollectionValueModel<?> collectionModel) {
+ return propertyValueModel(collectionModel, TransformerTools.collectionIsEmptyTransformer());
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapter for the specified
+ * collection value model that returns whether the collection is empty.
+ * This model can also be used to populate or clear the collection value model.
+ * The specified collection mutator is used to convert the collection value model:
+ * it should clear the collection value model when passed <code>true</code>
+ * and populate the collection value model when passed <code>false</code>.
+ */
+ public static ModifiablePropertyValueModel<Boolean> isEmptyModifiablePropertyValueModel(CollectionValueModel<?> collectionModel, BooleanClosure.Adapter collectionMutator) {
+ return booleanModifiablePropertyValueModel(collectionModel, TransformerTools.collectionIsEmptyTransformer(), collectionMutator);
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * collection value model that returns whether the collection contains
+ * exactly one element.
+ */
+ public static PropertyValueModel<Boolean> containsSingleElementPropertyValueModel(CollectionValueModel<?> collectionModel) {
+ return propertyValueModel(collectionModel, TransformerTools.collectionContainsSingleElementTransformer());
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * collection value model that returns whether the collection's size
+ * equals the specified size.
+ */
+ public static PropertyValueModel<Boolean> sizeEqualsPropertyValueModel(CollectionValueModel<?> collectionModel, int size) {
+ return propertyValueModel(collectionModel, TransformerTools.collectionSizeEqualsTransformer(size));
+ }
+
+
+ // ********** boolean PVM adapters **********
+
+ /**
+ * Construct a boolean property value model that is a composite AND of the
+ * specified boolean property value models; i.e. the model's value is {@link Boolean#TRUE}
+ * if all the contained models' values are {@link Boolean#TRUE},
+ * otherwise its value is {@link Boolean#FALSE}.
+ * The model's default value, when it contains no nested models, is {@link Boolean#TRUE}.
+ */
+ @SafeVarargs
+ public static PropertyValueModel<Boolean> and(PropertyValueModel<Boolean>... models) {
+ return compositePropertyValueModel(AND_TRANSFORMER, models);
+ }
+
+ /**
+ * Construct a boolean property value model that is a composite AND of the
+ * specified boolean property value models; i.e. the model's value is {@link Boolean#TRUE}
+ * if all the contained models' values are {@link Boolean#TRUE},
+ * otherwise its value is {@link Boolean#FALSE}.
+ * The model's default value, when it contains no nested models, is {@link Boolean#TRUE}.
+ */
+ public static PropertyValueModel<Boolean> and(Collection<? extends PropertyValueModel<Boolean>> models) {
+ return compositePropertyValueModel(models, AND_TRANSFORMER);
+ }
+
+ /**
+ * Construct a boolean property value model that is a composite AND of the
+ * specified boolean property value models; i.e. the model's value is {@link Boolean#TRUE}
+ * if all the contained models' values are {@link Boolean#TRUE},
+ * otherwise its value is {@link Boolean#FALSE}.
+ * The model's default value, when it contains no nested models, is {@link Boolean#TRUE}.
+ */
+ public static PropertyValueModel<Boolean> and(CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
+ return compositePropertyValueModel(collectionModel, AND_TRANSFORMER);
+ }
+
+ /**
+ * @see AndTransformer
+ */
+ public static final Transformer<Collection<Boolean>, Boolean> AND_TRANSFORMER = new AndTransformer();
+
+ /**
+ * A transformer that transforms a collection of {@link Boolean}s into a single
+ * {@link Boolean} by ANDing them together. Its default value is {@link Boolean#TRUE}.
+ * @see #and(CollectionValueModel)
+ */
+ public static final class AndTransformer
+ extends TransformerAdapter<Collection<Boolean>, Boolean>
+ {
+ @Override
+ public Boolean transform(Collection<Boolean> booleans) {
+ for (Boolean b : booleans) {
+ if ( ! b.booleanValue()) {
+ return Boolean.FALSE;
+ }
+ }
+ return Boolean.TRUE;
+ }
+ }
+
+ /**
+ * Construct a boolean property value model that is a composite OR of the
+ * specified boolean property value models; i.e. the model's value is {@link Boolean#FALSE}
+ * if all the contained models' values are {@link Boolean#FALSE},
+ * otherwise its value is {@link Boolean#TRUE}.
+ * The model's default value, when it contains no nested models, is {@link Boolean#FALSE}.
+ */
+ @SafeVarargs
+ public static PropertyValueModel<Boolean> or(PropertyValueModel<Boolean>... models) {
+ return compositePropertyValueModel(OR_TRANSFORMER, models);
+ }
+
+ /**
+ * Construct a boolean property value model that is a composite OR of the
+ * specified boolean property value models; i.e. the model's value is {@link Boolean#FALSE}
+ * if all the contained models' values are {@link Boolean#FALSE},
+ * otherwise its value is {@link Boolean#TRUE}.
+ * The model's default value, when it contains no nested models, is {@link Boolean#FALSE}.
+ */
+ public static PropertyValueModel<Boolean> or(Collection<? extends PropertyValueModel<Boolean>> models) {
+ return compositePropertyValueModel(models, OR_TRANSFORMER);
+ }
+
+ /**
+ * Construct a boolean property value model that is a composite OR of the
+ * specified boolean property value models; i.e. the model's value is {@link Boolean#FALSE}
+ * if all the contained models' values are {@link Boolean#FALSE},
+ * otherwise its value is {@link Boolean#TRUE}.
+ * The model's default value, when it contains no nested models, is {@link Boolean#FALSE}.
+ */
+ public static PropertyValueModel<Boolean> or(CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
+ return compositePropertyValueModel(collectionModel, OR_TRANSFORMER);
+ }
+
+ /**
+ * @see OrTransformer
+ */
+ public static final Transformer<Collection<Boolean>, Boolean> OR_TRANSFORMER = new OrTransformer();
+
+ /**
+ * A transformer that transforms a collection of {@link Boolean}s into a single
+ * {@link Boolean} by ORing them together. Its default value is {@link Boolean#FALSE}.
+ * @see #or(CollectionValueModel)
+ */
+ public static final class OrTransformer
+ extends TransformerAdapter<Collection<Boolean>, Boolean>
+ {
+ @Override
+ public Boolean transform(Collection<Boolean> booleans) {
+ for (Boolean b : booleans) {
+ if (b.booleanValue()) {
+ return Boolean.TRUE;
+ }
+ }
+ return Boolean.FALSE;
+ }
+ }
+
+
+ // ********** PVM adapters **********
+
+ /**
+ * Construct a boolean property value model adapter for the specified
+ * collection value model and predicate. The returned model will indicate whether
+ * the collection belongs to the set defined by the predicate.
+ */
+ public static PropertyValueModel<Boolean> booleanPropertyValueModel(CollectionValueModel<?> collectionModel, Predicate<? super Collection<?>> predicate) {
+ return propertyValueModel(collectionModel, TransformerTools.adapt(predicate));
+ }
+
+
+ /**
+ * Construct a property value model adapted to the specified
+ * collection value model and transformer.
+ * @see PluggablePropertyValueModel
+ */
+ public static <E, V> PropertyValueModel<V> propertyValueModel(CollectionValueModel<? extends E> collectionModel, Transformer<? super Collection<E>, V> transformer) {
+ return PropertyValueModelTools.propertyValueModel(pluggablePropertyValueModelAdapterFactory(collectionModel, transformer));
+ }
+
+ /**
+ * Construct a pluggable property value model adapter factory for the specified
+ * collection value model and transformer.
+ * @see PluggablePropertyValueModel
+ */
+ public static <E, V> PluggablePropertyValueModel.Adapter.Factory<V> pluggablePropertyValueModelAdapterFactory(CollectionValueModel<? extends E> collectionModel, Transformer<? super Collection<E>, V> transformer) {
+ return new CollectionPluggablePropertyValueModelAdapter.Factory<>(collectionModel, transformer);
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapted to the specified
+ * collection value model that returns whether the collection belongs to the set defined
+ * by the specified predicate.
+ * This model will use the specified collection mutator to modify the collection value model.
+ */
+ public static ModifiablePropertyValueModel<Boolean> booleanModifiablePropertyValueModel(CollectionValueModel<?> collectionModel, Predicate<? super Collection<?>> predicate, BooleanClosure.Adapter collectionMutator) {
+ return booleanModifiablePropertyValueModel(collectionModel, TransformerTools.adapt(predicate), collectionMutator);
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapter for the specified
+ * collection value model that returns whether the collection belongs to the set defined
+ * by the specified transformer.
+ * This model will use the specified collection mutator to modify the collection value model.
+ */
+ public static ModifiablePropertyValueModel<Boolean> booleanModifiablePropertyValueModel(CollectionValueModel<?> collectionModel, Transformer<? super Collection<?>, Boolean> transformer, BooleanClosure.Adapter collectionMutator) {
+ PluggablePropertyValueModel.Adapter.Factory<Boolean> factory = pluggablePropertyValueModelAdapterFactory(collectionModel, transformer);
+ Closure<Boolean> closure = ClosureTools.booleanClosure(collectionMutator);
+ return PropertyValueModelTools.pluggableModifiablePropertyValueModel(factory, closure);
+ }
+
+
+ // ********** filtering **********
+
+ /**
+ * Construct a collection value model with the specified wrapped collection value model and filter.
+ */
+ public static <E> CollectionValueModel<E> filter(CollectionValueModel<? extends E> collectionModel, Predicate<E> filter) {
+ return new FilteringCollectionValueModel<>(collectionModel, filter);
+ }
+
+
+ // ********** suppressed constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private CollectionValueModelTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java
index 4d36f09f93..377d290b57 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,6 +21,17 @@ import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
* another collection value model, "lazily" listen to it, and propagate
* its change notifications. Subclasses must implement the appropriate
* {@link CollectionValueModel}.
+ * <p>
+ * Subclasses must implement the following methods:<ul>
+ * <li>{@link #itemsAdded(CollectionAddEvent)}<p>
+ * implement this method to handle added items
+ * <li>{@link #itemsRemoved(CollectionRemoveEvent)}<p>
+ * implement this method to handle removed items
+ * <li>{@link #collectionCleared(CollectionClearEvent)}<p>
+ * implement this method to handle cleared collection
+ * <li>{@link #collectionChanged(CollectionChangeEvent)}<p>
+ * implement this method to handle changed collection
+ * </ul>
*
* @param <E> the type of elements held by the model
*/
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java
deleted file mode 100644
index e032203172..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2012 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 java.util.Collection;
-import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.common.utility.transformer.Transformer;
-
-/**
- * A <code>CompositeBooleanPropertyValueModel</code> adapts a
- * {@link CollectionValueModel} holding boolean {@link PropertyValueModel}s
- * to a single boolean {@link PropertyValueModel}. The composite value is
- * determined by the {@link CompositeBooleanPropertyValueModel.Adapter} provided
- * at construction. Typically the composite will be either an AND or an OR of
- * all the boolean values.
- * <p>
- * If there are <em>no</em> boolean {@link PropertyValueModel}s, the composite
- * will return its default value; which, by default, is <code>null</code>.
- * <p>
- * <strong>NB:</strong> None of the wrapped boolean models can return a
- * <code>null</code> value or this class will throw an exception. The assumption
- * is that all the wrapped boolean models are configured with "default" values
- * that determine the model's value (TRUE or FALSE) when <code>null</code>.
- */
-public class CompositeBooleanPropertyValueModel
- extends CompositePropertyValueModel<Boolean, Boolean>
-{
- /**
- * Calculation of the model's value is delegated to this adapter.
- */
- protected final Adapter adapter;
-
- /**
- * The default setting for the composite boolean property value model;
- * for when the underlying collection model is empty.
- * The default [default value] is <code>null</code>.
- */
- private final Boolean defaultValue;
-
-
- // ********** AND factory methods **********
-
- /**
- * Construct a boolean property value model that is a composite AND of the
- * specified boolean property value models; i.e. the model's value is true
- * if all the contained models are true, otherwise its value is false.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public static CompositeBooleanPropertyValueModel and(PropertyValueModel<Boolean>... array) {
- return new CompositeBooleanPropertyValueModel(AND_ADAPTER, array);
- }
-
- /**
- * Construct a boolean property value model that is a composite AND of the
- * specified boolean property value models; i.e. the model's value is true
- * if all the contained models are true, otherwise its value is false.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public static CompositeBooleanPropertyValueModel and(Boolean defaultValue, PropertyValueModel<Boolean>... array) {
- return new CompositeBooleanPropertyValueModel(AND_ADAPTER, defaultValue, array);
- }
-
- /**
- * Construct a boolean property value model that is a composite AND of the
- * specified boolean property value models; i.e. the model's value is true
- * if all the contained models are true, otherwise its value is false.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public static <E extends PropertyValueModel<Boolean>> CompositeBooleanPropertyValueModel and(Collection<E> collection) {
- return new CompositeBooleanPropertyValueModel(AND_ADAPTER, collection);
- }
-
- /**
- * Construct a boolean property value model that is a composite AND of the
- * specified boolean property value models; i.e. the model's value is true
- * if all the contained models are true, otherwise its value is false.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public static <E extends PropertyValueModel<Boolean>> CompositeBooleanPropertyValueModel and(Boolean defaultValue, Collection<E> collection) {
- return new CompositeBooleanPropertyValueModel(AND_ADAPTER, defaultValue, collection);
- }
-
- /**
- * Construct a boolean property value model that is a composite AND of the
- * specified boolean property value models; i.e. the model's value is true
- * if all the contained models are true, otherwise its value is false.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public static CompositeBooleanPropertyValueModel and(CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
- return new CompositeBooleanPropertyValueModel(AND_ADAPTER, collectionModel);
- }
-
- /**
- * Construct a boolean property value model that is a composite AND of the
- * specified boolean property value models; i.e. the model's value is true
- * if all the contained models are true, otherwise its value is false.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public static CompositeBooleanPropertyValueModel and(Boolean defaultValue, CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
- return new CompositeBooleanPropertyValueModel(AND_ADAPTER, defaultValue, collectionModel);
- }
-
-
- // ********** OR factory methods **********
-
- /**
- * Construct a boolean property value model that is a composite OR of the
- * specified boolean property value models; i.e. the model's value is false
- * if all the contained models are false, otherwise its value is true.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public static CompositeBooleanPropertyValueModel or(PropertyValueModel<Boolean>... array) {
- return new CompositeBooleanPropertyValueModel(OR_ADAPTER, array);
- }
-
- /**
- * Construct a boolean property value model that is a composite OR of the
- * specified boolean property value models; i.e. the model's value is false
- * if all the contained models are false, otherwise its value is true.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public static CompositeBooleanPropertyValueModel or(Boolean defaultValue, PropertyValueModel<Boolean>... array) {
- return new CompositeBooleanPropertyValueModel(OR_ADAPTER, defaultValue, array);
- }
-
- /**
- * Construct a boolean property value model that is a composite OR of the
- * specified boolean property value models; i.e. the model's value is false
- * if all the contained models are false, otherwise its value is true.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public static <E extends PropertyValueModel<Boolean>> CompositeBooleanPropertyValueModel or(Collection<E> collection) {
- return new CompositeBooleanPropertyValueModel(OR_ADAPTER, collection);
- }
-
- /**
- * Construct a boolean property value model that is a composite OR of the
- * specified boolean property value models; i.e. the model's value is false
- * if all the contained models are false, otherwise its value is true.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public static <E extends PropertyValueModel<Boolean>> CompositeBooleanPropertyValueModel or(Boolean defaultValue, Collection<E> collection) {
- return new CompositeBooleanPropertyValueModel(OR_ADAPTER, defaultValue, collection);
- }
-
- /**
- * Construct a boolean property value model that is a composite OR of the
- * specified boolean property value models; i.e. the model's value is false
- * if all the contained models are false, otherwise its value is true.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public static CompositeBooleanPropertyValueModel or(CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
- return new CompositeBooleanPropertyValueModel(OR_ADAPTER, collectionModel);
- }
-
- /**
- * Construct a boolean property value model that is a composite OR of the
- * specified boolean property value models; i.e. the model's value is false
- * if all the contained models are false, otherwise its value is true.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public static CompositeBooleanPropertyValueModel or(Boolean defaultValue, CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
- return new CompositeBooleanPropertyValueModel(OR_ADAPTER, defaultValue, collectionModel);
- }
-
-
- // ********** constructors **********
-
- /**
- * Construct a boolean property value model that is a composite of the specified
- * boolean property value models, as defined by the specified adapter.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public CompositeBooleanPropertyValueModel(Adapter adapter, PropertyValueModel<Boolean>... array) {
- this(adapter, null, array);
- }
-
- /**
- * Construct a boolean property value model that is a composite of the specified
- * boolean property value models, as defined by the specified adapter.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public CompositeBooleanPropertyValueModel(Adapter adapter, Boolean defaultValue, PropertyValueModel<Boolean>... array) {
- super(array);
- if (adapter == null) {
- throw new NullPointerException();
- }
- this.adapter = adapter;
- this.defaultValue = defaultValue;
- }
-
- /**
- * Construct a boolean property value model that is a composite of the specified
- * boolean property value models, as defined by the specified adapter.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public <E extends PropertyValueModel<Boolean>> CompositeBooleanPropertyValueModel(Adapter adapter, Collection<E> collection) {
- this(adapter, null, collection);
- }
-
- /**
- * Construct a boolean property value model that is a composite of the specified
- * boolean property value models, as defined by the specified adapter.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public <E extends PropertyValueModel<Boolean>> CompositeBooleanPropertyValueModel(Adapter adapter, Boolean defaultValue, Collection<E> collection) {
- super(collection);
- if (adapter == null) {
- throw new NullPointerException();
- }
- this.adapter = adapter;
- this.defaultValue = defaultValue;
- }
-
- /**
- * Construct a boolean property value model that is a composite of the specified
- * boolean property value models, as defined by the specified adapter.
- * The model's default value, when it contains no nested models, is
- * <code>null</code>.
- */
- public CompositeBooleanPropertyValueModel(Adapter adapter, CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
- this(adapter, null, collectionModel);
- }
-
- /**
- * Construct a boolean property value model that is a composite of the specified
- * boolean property value models, as defined by the specified adapter.
- * When the model contains no nested models, its value will be the
- * specified default.
- */
- public CompositeBooleanPropertyValueModel(Adapter adapter, Boolean defaultValue, CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
- super(collectionModel);
- if (adapter == null) {
- throw new NullPointerException();
- }
- this.adapter = adapter;
- this.defaultValue = defaultValue;
- }
-
-
- // ********** implementation **********
-
- /**
- * Return the {@link #defaultValue} if the collection is empty;
- * otherwise delegate to the {@link #adapter}.
- */
- @Override
- protected Boolean buildValue() {
- return (this.collectionModel.size() == 0) ? this.defaultValue : this.buildValue_();
- }
-
- protected Boolean buildValue_() {
- return this.adapter.buildValue(this.getBooleans());
- }
-
- protected Iterable<Boolean> getBooleans() {
- return new TransformationIterable<PropertyValueModel<? extends Boolean>, Boolean>(this.collectionModel, BOOLEAN_TRANSFORMER);
- }
-
- protected static final Transformer<PropertyValueModel<? extends Boolean>, Boolean> BOOLEAN_TRANSFORMER = new BooleanTransformer();
- protected static class BooleanTransformer
- implements Transformer<PropertyValueModel<? extends Boolean>, Boolean>
- {
- public Boolean transform(PropertyValueModel<? extends Boolean> booleanModel) {
- return booleanModel.getValue();
- }
- @Override
- public String toString() {
- return this.getClass().getSimpleName();
- }
- }
-
-
- // ********** adapter **********
-
- /**
- * This adapter allows the {@link CompositeBooleanPropertyValueModel} to be
- * pluggable.
- */
- public interface Adapter {
- /**
- * Return the composite boolean value of the specified collection
- * of booleans.
- */
- Boolean buildValue(Iterable<Boolean> booleans);
- }
-
- /**
- * Return <code>true</code> if all the booleans are <code>true</code>;
- * otherwise return <code>false</code>.
- */
- public static final Adapter AND_ADAPTER = new Adapter() {
- public Boolean buildValue(Iterable<Boolean> booleans) {
- for (Boolean b : booleans) {
- if ( ! b.booleanValue()) {
- return Boolean.FALSE;
- }
- }
- return Boolean.TRUE;
- }
- @Override
- public String toString() {
- return "AND_ADAPTER"; //$NON-NLS-1$
- }
- };
-
- /**
- * Return <code>false</code> if all the booleans are <code>false</code>;
- * otherwise return <code>true</code>.
- */
- public static final Adapter OR_ADAPTER = new Adapter() {
- public Boolean buildValue(Iterable<Boolean> booleans) {
- for (Boolean b : booleans) {
- if (b.booleanValue()) {
- return Boolean.TRUE;
- }
- }
- return Boolean.FALSE;
- }
- @Override
- public String toString() {
- return "OR_ADAPTER"; //$NON-NLS-1$
- }
- };
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java
deleted file mode 100644
index 796c53b7d6..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2012 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 java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import org.eclipse.jpt.common.utility.internal.collection.IdentityHashBag;
-import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
-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.CollectionValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-
-/**
- * A <code>CompositePropertyValueModel</code> adapts a
- * {@link CollectionValueModel} holding other {@link PropertyValueModel}s
- * to a single {@link PropertyValueModel}.
- * <p>
- * Subclasses must implement:<ul>
- * <li>{@link #buildValue()}<p>
- * to return the current property value, as derived from the
- * component values
- * </ul>
- * <strong>NB:</strong> The wrapped collection must not contain any duplicates
- * or this class will throw an exception.
- *
- * @param <V> the type of the model's value
- * @param <E> the type of the wrapped collection value model's
- * property value model's values
- */
-public abstract class CompositePropertyValueModel<V, E>
- extends CollectionPropertyValueModelAdapter<V, PropertyValueModel<? extends E>>
-{
- /**
- * Cache the component property value models so we can stop listening to
- * them when they are removed from the collection value model.
- */
- protected final IdentityHashBag<PropertyValueModel<? extends E>> componentPVMs =
- new IdentityHashBag<PropertyValueModel<? extends E>>();
-
- /**
- * Listen to every property value model in the collection value model.
- * If one changes, we need to re-calculate our value.
- */
- protected final PropertyChangeListener componentListener;
-
-
- // ********** constructors **********
-
- /**
- * Construct a property value model that is a composite of the specified
- * property value models.
- */
- public CompositePropertyValueModel(PropertyValueModel<? extends E>... collection) {
- this(Arrays.asList(collection));
- }
-
- /**
- * Construct a property value model that is a composite of the specified
- * property value models.
- */
- public <P extends PropertyValueModel<? extends E>> CompositePropertyValueModel(Collection<? extends P> collection) {
- this(new StaticCollectionValueModel<P>(collection));
- }
-
- /**
- * Construct a property value model that is a composite of the specified
- * property value models.
- */
- public <P extends PropertyValueModel<? extends E>> CompositePropertyValueModel(CollectionValueModel<P> collectionModel) {
- super(collectionModel);
- this.componentListener = this.buildComponentListener();
- }
-
-
- // ********** initialization **********
-
- protected PropertyChangeListener buildComponentListener() {
- return new ComponentListener();
- }
-
- protected class ComponentListener
- extends PropertyChangeAdapter
- {
- @Override
- public void propertyChanged(PropertyChangeEvent event) {
- CompositePropertyValueModel.this.componentChanged(event);
- }
- }
-
-
- // ********** behavior **********
-
- /**
- * Subclasses can override this method if the event can be used to improve
- * the performance of building a new value (e.g. some property changes may
- * not necessitate the re-calculation of the value).
- */
- protected void componentChanged(@SuppressWarnings("unused") PropertyChangeEvent event) {
- this.propertyChanged();
- }
-
-
- // ********** CollectionPropertyValueModelAdapter overrides **********
-
- @Override
- protected void engageModel_() {
- super.engageModel_();
- this.addComponentPVMs(this.collectionModel);
- }
-
- protected <P extends PropertyValueModel<? extends E>> void addComponentPVMs(Iterable<P> pvms) {
- for (P each : pvms) {
- this.componentPVMs.add(each);
- each.addPropertyChangeListener(VALUE, this.componentListener);
- }
- }
-
- @Override
- protected void disengageModel_() {
- this.removeComponentPVMs(this.collectionModel);
- super.disengageModel_();
- }
-
- protected <P extends PropertyValueModel<? extends E>> void removeComponentPVMs(Iterable<P> pvms) {
- for (P each : pvms) {
- each.removePropertyChangeListener(VALUE, this.componentListener);
- this.componentPVMs.remove(each);
- }
- }
-
- @Override
- protected void itemsAdded(CollectionAddEvent event) {
- this.addComponentPVMs(this.getItems(event));
- super.itemsAdded(event);
- }
-
- @Override
- protected void itemsRemoved(CollectionRemoveEvent event) {
- this.removeComponentPVMs(this.getItems(event));
- super.itemsRemoved(event);
- }
-
- @Override
- protected void collectionCleared(CollectionClearEvent event) {
- this.removeAllComponentPVMs();
- super.collectionCleared(event);
- }
-
- protected void removeAllComponentPVMs() {
- // copy the list so we don't eat our own tail
- ArrayList<PropertyValueModel<? extends E>> copy = new ArrayList<PropertyValueModel<? extends E>>(this.componentPVMs);
- this.removeComponentPVMs(copy);
- }
-
- @Override
- protected void collectionChanged(CollectionChangeEvent event) {
- this.removeAllComponentPVMs();
- this.addComponentPVMs(this.collectionModel);
- super.collectionChanged(event);
- }
-
-
- // ********** convenience methods **********
-
- /**
- * Our constructor accepts only a
- * {@link CollectionValueModel}{@code<? extends }{@link PropertyValueModel}{@code<? extends E>>}.
- */
- // minimize scope of suppressed warnings
- @SuppressWarnings("unchecked")
- protected Iterable<? extends PropertyValueModel<? extends E>> getItems(CollectionAddEvent event) {
- return (Iterable<? extends PropertyValueModel<? extends E>>) event.getItems();
- }
-
- /**
- * Our constructor accepts only a
- * {@link CollectionValueModel}{@code<? extends }{@link PropertyValueModel}{@code<? extends E>>}.
- */
- // minimize scope of suppressed warnings
- @SuppressWarnings("unchecked")
- protected Iterable<? extends PropertyValueModel<? extends E>> getItems(CollectionRemoveEvent event) {
- return (Iterable<? extends PropertyValueModel<? extends E>>) event.getItems();
- }
-}
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
new file mode 100644
index 0000000000..3ae453b06d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModelAdapter.java
@@ -0,0 +1,266 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.collection.ListTools;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel.Adapter;
+import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
+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.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * Adapt a {@link CollectionValueModel collection value model} holding
+ * {@link PropertyValueModel property value models}
+ * to a single {@link PropertyValueModel property value model}, sorta.
+ * <p>
+ * This adapter is constructed with a {@link CollectionValueModel
+ * collection value model} and a {@link Transformer transformer} that can
+ * transform the collection's property value models' values to a single value.
+ * <p>
+ * This is an adapter that can be plugged into a {@link PluggablePropertyValueModel}.
+ * <p>
+ * <strong>NB:</strong> The wrapped collection value model must not contain any
+ * <code>null</code>s or duplicate property value models.
+ *
+ * @param <E> the type of the adapted collection value model's
+ * property value models' values
+ * @param <V> the type of the model's derived value
+ *
+ * @see PluggablePropertyValueModel
+ * @see CollectionPluggablePropertyValueModelAdapter
+ */
+public final class CompositePropertyValueModelAdapter<E, V>
+ implements PluggablePropertyValueModel.Adapter<V>, CollectionChangeListener
+{
+ private final Factory<E, V> factory;
+
+ /**
+ * The <em>real</em> adapter, passed to us as a listener.
+ */
+ private final AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener;
+
+ /**
+ * Listen to every property value model in the collection value model.
+ * If one changes, we need to re-calculate {@link #value}
+ * and notify @{link #listener}.
+ */
+ private final PropertyChangeListener componentListener;
+
+ /**
+ * Cached copy of {@link Factory#collectionModel}'s elements
+ * and their values.
+ */
+ private final IdentityHashMap<PropertyValueModel<? extends E>, E> values;
+
+ /**
+ * Protects {@link #values} from {@link Factory#transformer}.
+ */
+ private final Collection<E> unmodifiableValues;
+
+ /**
+ * The derived value.
+ */
+ private volatile V value;
+
+
+ // ********** constructor **********
+
+ public CompositePropertyValueModelAdapter(Factory<E, V> factory, AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.factory = factory;
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ this.listener = listener;
+ this.componentListener = this.buildComponentListener();
+ this.values = new IdentityHashMap<>();
+ this.unmodifiableValues = Collections.unmodifiableCollection(this.values.values());
+ }
+
+
+ // ********** PropertyValueModelAdapter.Adapter **********
+
+ public V getValue() {
+ return this.value;
+ }
+
+ public void engageModel() {
+ this.factory.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this);
+ this.addComponentPVMs(this.factory.collectionModel);
+ this.value = this.buildValue();
+ }
+
+ public void disengageModel() {
+ this.value = null;
+ this.removeComponentPVMs(this.factory.collectionModel);
+ if ( ! this.values.isEmpty()) {
+ throw new IllegalStateException("extraneous values: " + this.values); //$NON-NLS-1$
+ }
+ this.factory.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this);
+ }
+
+
+ // ********** CollectionChangeListener **********
+
+ @SuppressWarnings("unchecked")
+ public void itemsAdded(CollectionAddEvent event) {
+ this.addComponentPVMs((Iterable<? extends PropertyValueModel<? extends E>>) event.getItems());
+ this.update();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void itemsRemoved(CollectionRemoveEvent event) {
+ this.removeComponentPVMs((Iterable<? extends PropertyValueModel<? extends E>>) event.getItems());
+ this.update();
+ }
+
+ public void collectionCleared(CollectionClearEvent event) {
+ this.removeCachedPVMs();
+ this.update();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void collectionChanged(CollectionChangeEvent event) {
+ this.removeCachedPVMs();
+ this.addComponentPVMs((Iterable<? extends PropertyValueModel<? extends E>>) event.getCollection());
+ this.update();
+ }
+
+
+ // ********** add/remove component PVMs **********
+
+ private void addComponentPVMs(Iterable<? extends PropertyValueModel<? extends E>> pvms) {
+ for (PropertyValueModel<? extends E> pvm : pvms) {
+ this.addComponentPVM(pvm);
+ }
+ }
+
+ private void addComponentPVM(PropertyValueModel<? extends E> pvm) {
+ if (pvm == null) {
+ throw new NullPointerException();
+ }
+ if (this.values.containsKey(pvm)) {
+ throw new IllegalStateException("duplicate component: " + pvm); //$NON-NLS-1$
+ }
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, this.componentListener);
+ this.values.put(pvm, pvm.getValue());
+ }
+
+ private void removeCachedPVMs() {
+ // copy the list so we don't eat our own tail
+ ArrayList<PropertyValueModel<? extends E>> copy = ListTools.arrayList(this.values.keySet());
+ this.removeComponentPVMs(copy);
+ }
+
+ private void removeComponentPVMs(Iterable<? extends PropertyValueModel<? extends E>> pvms) {
+ for (PropertyValueModel<? extends E> pvm : pvms) {
+ this.removeComponentPVM(pvm);
+ }
+ }
+
+ private void removeComponentPVM(PropertyValueModel<? extends E> pvm) {
+ if ( ! this.values.containsKey(pvm)) {
+ throw new IllegalStateException("missing component: " + pvm); //$NON-NLS-1$
+ }
+ this.values.remove(pvm);
+ pvm.removePropertyChangeListener(PropertyValueModel.VALUE, this.componentListener);
+ }
+
+
+ // ********** misc **********
+
+ private void update() {
+ this.listener.valueChanged(this.value = this.buildValue());
+ }
+
+ private V buildValue() {
+ return this.factory.transformer.transform(this.unmodifiableValues);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.value);
+ }
+
+
+ // ********** component listener **********
+
+ private PropertyChangeListener buildComponentListener() {
+ return new ComponentListener();
+ }
+
+ /* CU private */ class ComponentListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ CompositePropertyValueModelAdapter.this.componentChanged(event);
+ }
+ }
+
+ /* CU private */ void componentChanged(PropertyChangeEvent event) {
+ @SuppressWarnings("unchecked")
+ PropertyValueModel<? extends E> source = (PropertyValueModel<? extends E>) event.getSource();
+ if ( ! this.values.containsKey(source)) {
+ throw new IllegalStateException("invalid component: " + source); //$NON-NLS-1$
+ }
+ @SuppressWarnings("unchecked")
+ E newValue = (E) event.getNewValue();
+ this.values.put(source, newValue);
+ this.update();
+ }
+
+
+ // ********** PluggablePropertyValueModel.Adapter.Factory **********
+
+ public static class Factory<E, V>
+ implements PluggablePropertyValueModel.Adapter.Factory<V>
+ {
+ /* CU private */ final CollectionValueModel<? extends PropertyValueModel<? extends E>> collectionModel;
+ /* CU private */ final Transformer<? super Collection<E>, V> transformer;
+
+ public Factory(CollectionValueModel<? extends PropertyValueModel<? extends E>> collectionModel, Transformer<? super Collection<E>, V> transformer) {
+ super();
+ if (collectionModel == null) {
+ throw new NullPointerException();
+ }
+ this.collectionModel = collectionModel;
+ if (transformer == null) {
+ throw new NullPointerException();
+ }
+ this.transformer = transformer;
+ }
+
+ public Adapter<V> buildAdapter(AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ return new CompositePropertyValueModelAdapter<>(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/ElementPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ElementPropertyValueModelAdapter.java
deleted file mode 100644
index 8cc9d6f8ae..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ElementPropertyValueModelAdapter.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2013 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.CollectionChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.predicate.Predicate;
-
-/**
- * Adapt an element in a collection value model to a property value model.
- * The property model's value is determined by whether the collection model
- * contains the value: If the collection model contains the value,
- * the property model's value is <em>that</em> element; otherwise, the property
- * model's value is <code>null</code>. A {@link #predicate} is used to determine
- * whether the collection model contains the relevant value.
- * <p>
- * This is useful for a client (e.g. a UI widget) that is longer-living than its
- * underlying model. Obviously, the client must be prepared to handle a value of
- * <code>null</code>.
- *
- * @param <V> the type of the both the model's value and
- * the wrapped collection value model's elements
- */
-public class ElementPropertyValueModelAdapter<V>
- extends CollectionPropertyValueModelAdapter<V, V>
-{
- /**
- * A predicate used to determine whether an element in the wrapped
- * collection model is the model's value.
- */
- protected final Predicate<V> predicate;
-
-
- /**
- * Construct a property value model whose value depends on whether the
- * specified collection value model contains the value. The specified
- * filter is used to determine whether an element in the specified
- * collection model is the property value.
- */
- public ElementPropertyValueModelAdapter(CollectionValueModel<? extends V> collectionModel, Predicate<V> predicate) {
- super(collectionModel);
- if (predicate == null) {
- throw new NullPointerException();
- }
- this.predicate = predicate;
- }
-
- /**
- * If the collection model contains the property model's {@link #value},
- * return that element; otherwise return <code>null</code>.
- */
- @Override
- protected V buildValue() {
- for (V each : this.collectionModel) {
- if (this.predicate.evaluate(each)) {
- return each;
- }
- }
- return null;
- }
-
- /**
- * Check whether the wrapped collection model now contains the
- * {@link #value}.
- */
- @Override
- protected void itemsAdded(Iterable<V> items) {
- if (this.value == null) {
- this.itemsAdded_(items);
- }
- }
-
- protected void itemsAdded_(Iterable<V> items) {
- for (V each : items) {
- if (this.predicate.evaluate(each)) {
- this.firePropertyChanged(VALUE, null, this.value = each);
- return;
- }
- }
- }
-
- /**
- * Check whether the wrapped collection model no longer contains the
- * {@link #value}.
- */
- @Override
- protected void itemsRemoved(Iterable<V> items) {
- if (this.value != null) {
- this.itemsRemoved_(items);
- }
- }
-
- protected void itemsRemoved_(Iterable<V> items) {
- for (V each : items) {
- if (ObjectTools.equals(each, this.value)) {
- V old = this.value;
- this.firePropertyChanged(VALUE, old, this.value = null);
- return;
- }
- }
- }
-
- /**
- * The {@link #value} must now be <code>null</code>.
- */
- @Override
- protected void collectionCleared(CollectionClearEvent event) {
- if (this.value != null) {
- V old = this.value;
- this.firePropertyChanged(VALUE, old, this.value = null);
- }
- }
-
- /**
- * Re-calculate the {@link #value}.
- */
- @Override
- protected void collectionChanged(CollectionChangeEvent event) {
- V old = this.value;
- this.firePropertyChanged(VALUE, old, this.value = this.buildValue());
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java
index ca51df9aae..95bf6e8abd 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,18 +9,16 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
-import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.collection.HashBag;
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.predicate.PredicateTools;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.predicate.Predicate;
/**
@@ -48,25 +46,17 @@ public class FilteringCollectionValueModel<E>
extends CollectionValueModelWrapper<E>
implements CollectionValueModel<E>
{
- /** This filters the items in the nested collection. */
- private Predicate<E> filter;
+ /** This filters the items in the wrapped collection. */
+ private volatile Predicate<E> filter;
/** Cache the items that were accepted by the filter */
- private final ArrayList<E> filteredItems = new ArrayList<E>();
+ private final HashBag<E> filteredItems = new HashBag<>();
// ********** constructors **********
/**
* Construct a collection value model with the specified wrapped
- * collection value model and a filter that simply accepts every object.
- */
- public FilteringCollectionValueModel(CollectionValueModel<? extends E> collectionModel) {
- this(collectionModel, PredicateTools.<E>true_());
- }
-
- /**
- * Construct a collection value model with the specified wrapped
* collection value model and filter.
*/
public FilteringCollectionValueModel(CollectionValueModel<? extends E> collectionModel, Predicate<E> filter) {
@@ -77,22 +67,6 @@ public class FilteringCollectionValueModel<E>
this.filter = filter;
}
- /**
- * Construct a collection value model with the specified wrapped
- * list value model and a filter that simply accepts every object.
- */
- public FilteringCollectionValueModel(ListValueModel<? extends E> listModel) {
- this(new ListCollectionValueModelAdapter<E>(listModel));
- }
-
- /**
- * Construct a collection value model with the specified wrapped
- * list value model and filter.
- */
- public FilteringCollectionValueModel(ListValueModel<? extends E> listModel, Predicate<E> filter) {
- this(new ListCollectionValueModelAdapter<E>(listModel), filter);
- }
-
// ********** CollectionValueModel implementation **********
@@ -150,6 +124,13 @@ public class FilteringCollectionValueModel<E>
// ********** miscellaneous **********
/**
+ * Return the current filter.
+ */
+ public Predicate<E> getFilter() {
+ return this.filter;
+ }
+
+ /**
* Change the filter and rebuild the collection.
*/
public void setFilter(Predicate<E> filter) {
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
new file mode 100644
index 0000000000..48804c2f1c
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCompositePropertyValueModelAdapter.java
@@ -0,0 +1,284 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.jpt.common.utility.Association;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.SimpleAssociation;
+import org.eclipse.jpt.common.utility.internal.collection.ListTools;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel.Adapter;
+import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
+import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
+import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
+import org.eclipse.jpt.common.utility.model.event.ListMoveEvent;
+import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
+import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
+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.ListValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * Adapt a {@link ListValueModel list value model} holding
+ * {@link PropertyValueModel property value models}
+ * to a single {@link PropertyValueModel property value model}, sorta.
+ * <p>
+ * This adapter is constructed with a {@link ListValueModel
+ * list value model} and a {@link Transformer transformer} that can
+ * transform the list's property value models' values to a single value.
+ * <p>
+ * This is an adapter that can be plugged into a {@link PluggablePropertyValueModel}.
+ * <p>
+ * <strong>NB:</strong> The wrapped list value model must not contain any
+ * <code>null</code>s or duplicate property value models.
+ *
+ * @param <E> the type of the adapted list value model's
+ * property value models' values
+ * @param <V> the type of the model's derived value
+ *
+ * @see PluggablePropertyValueModel
+ * @see ListPluggablePropertyValueModelAdapter
+ */
+public final class ListCompositePropertyValueModelAdapter<E, V>
+ implements PluggablePropertyValueModel.Adapter<V>, ListChangeListener
+{
+ private final Factory<E, V> factory;
+
+ /**
+ * The <em>real</em> adapter, passed to us as a listener.
+ */
+ private final AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener;
+
+ /**
+ * Listen to every property value model in the list value model.
+ * If one changes, we need to re-calculate {@link #value}
+ * and notify @{link #listener}.
+ */
+ private final PropertyChangeListener componentListener;
+
+ /**
+ * Cached copy of {@link Factory#listModel}'s elements' values.
+ */
+ private final ArrayList<SimpleAssociation<PropertyValueModel<? extends E>, E>> values;
+
+ /**
+ * The derived value.
+ */
+ private volatile V value;
+
+
+ // ********** constructor **********
+
+ public ListCompositePropertyValueModelAdapter(Factory<E, V> factory, AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.factory = factory;
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ this.listener = listener;
+ this.componentListener = this.buildComponentListener();
+ this.values = new ArrayList<>();
+ }
+
+
+ // ********** PropertyValueModelAdapter.Adapter **********
+
+ public V getValue() {
+ return this.value;
+ }
+
+ public void engageModel() {
+ this.factory.listModel.addListChangeListener(ListValueModel.LIST_VALUES, this);
+ this.addComponentPVMs(0, this.factory.listModel);
+ this.value = this.buildValue();
+ }
+
+ public void disengageModel() {
+ this.value = null;
+ this.removeComponentPVMs(0, this.factory.listModel.size(), this.factory.listModel);
+ if ( ! this.values.isEmpty()) {
+ throw new IllegalStateException("extraneous values: " + this.values); //$NON-NLS-1$
+ }
+ this.factory.listModel.removeListChangeListener(ListValueModel.LIST_VALUES, this);
+ }
+
+
+ // ********** ListChangeListener **********
+
+ @SuppressWarnings("unchecked")
+ public void itemsAdded(ListAddEvent event) {
+ this.addComponentPVMs(event.getIndex(), (Iterable<? extends PropertyValueModel<? extends E>>) event.getItems());
+ this.update();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void itemsRemoved(ListRemoveEvent event) {
+ this.removeComponentPVMs(event.getIndex(), event.getItemsSize(), (Iterable<? extends PropertyValueModel<? extends E>>) event.getItems());
+ this.update();
+ }
+
+ public void itemsMoved(ListMoveEvent event) {
+ ListTools.move(this.values, event.getTargetIndex(), event.getSourceIndex(), event.getLength());
+ this.update();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void itemsReplaced(ListReplaceEvent event) {
+ this.removeComponentPVMs(event.getIndex(), event.getItemsSize(), (Iterable<? extends PropertyValueModel<? extends E>>) event.getOldItems());
+ this.addComponentPVMs(event.getIndex(), (Iterable<? extends PropertyValueModel<? extends E>>) event.getNewItems());
+ this.update();
+ }
+
+ public void listCleared(ListClearEvent event) {
+ this.removeCachedPVMs();
+ this.update();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void listChanged(ListChangeEvent event) {
+ this.removeCachedPVMs();
+ this.addComponentPVMs(0, (Iterable<? extends PropertyValueModel<? extends E>>) event.getList());
+ this.update();
+ }
+
+
+ // ********** add/remove component PVMs **********
+
+ private void addComponentPVMs(int index, Iterable<? extends PropertyValueModel<? extends E>> pvms) {
+ for (PropertyValueModel<? extends E> pvm : pvms) {
+ this.addComponentPVM(index++, pvm);
+ }
+ }
+
+ private void addComponentPVM(int index, PropertyValueModel<? extends E> pvm) {
+ if (pvm == null) {
+ throw new NullPointerException();
+ }
+ for (SimpleAssociation<PropertyValueModel<? extends E>, E> each : this.values) {
+ if (each.getKey() == pvm) {
+ throw new IllegalStateException("duplicate component: " + pvm); //$NON-NLS-1$
+ }
+ }
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, this.componentListener);
+ this.values.add(index, new SimpleAssociation<>(pvm, pvm.getValue()));
+ }
+
+ 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));
+ }
+
+ private void removeComponentPVMs(int index, int length, Iterable<? extends PropertyValueModel<? extends E>> expectedPVMs) {
+ this.removeComponentPVMs(this.values.subList(index, index + length), expectedPVMs);
+ }
+
+ private void removeComponentPVMs(List<SimpleAssociation<PropertyValueModel<? extends E>, E>> subList, Iterable<? extends PropertyValueModel<? extends E>> expectedPVMs) {
+ Iterator<? extends PropertyValueModel<? extends E>> stream = expectedPVMs.iterator();
+ for (SimpleAssociation<PropertyValueModel<? extends E>, E> each : subList) {
+ PropertyValueModel<? extends E> pvm = each.getKey();
+ PropertyValueModel<? extends E> expectedPVM = stream.next();
+ if (pvm != expectedPVM) {
+ throw new IllegalStateException("inconsistent component: " + pvm + " - expected: " + expectedPVM); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ pvm.removePropertyChangeListener(PropertyValueModel.VALUE, this.componentListener);
+ }
+ subList.clear();
+ }
+
+
+ // ********** misc **********
+
+ private void update() {
+ this.listener.valueChanged(this.value = this.buildValue());
+ }
+
+ 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));
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.value);
+ }
+
+
+ // ********** component listener **********
+
+ private PropertyChangeListener buildComponentListener() {
+ return new ComponentListener();
+ }
+
+ /* CU private */ class ComponentListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ ListCompositePropertyValueModelAdapter.this.componentChanged(event);
+ }
+ }
+
+ /* CU private */ void componentChanged(PropertyChangeEvent event) {
+ @SuppressWarnings("unchecked")
+ PropertyValueModel<? extends E> source = (PropertyValueModel<? extends E>) event.getSource();
+ for (SimpleAssociation<PropertyValueModel<? extends E>, E> each : this.values) {
+ if (each.getKey() == source) {
+ @SuppressWarnings("unchecked")
+ E newValue = (E) event.getNewValue();
+ each.setValue(newValue);
+ this.update();
+ return;
+ }
+ }
+ throw new IllegalStateException("invalid component: " + source); //$NON-NLS-1$
+ }
+
+
+ // ********** PluggablePropertyValueModel.Adapter.Factory **********
+
+ public static class Factory<E, V>
+ implements PluggablePropertyValueModel.Adapter.Factory<V>
+ {
+ /* CU private */ final ListValueModel<? extends PropertyValueModel<? extends E>> listModel;
+ /* CU private */ final Transformer<? super List<E>, V> transformer;
+
+ public Factory(ListValueModel<? extends PropertyValueModel<? extends E>> listModel, Transformer<? super List<E>, V> transformer) {
+ super();
+ if (listModel == null) {
+ throw new NullPointerException();
+ }
+ this.listModel = listModel;
+ if (transformer == null) {
+ throw new NullPointerException();
+ }
+ this.transformer = transformer;
+ }
+
+ public Adapter<V> buildAdapter(AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ return new ListCompositePropertyValueModelAdapter<>(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/ListPluggablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPluggablePropertyValueModelAdapter.java
new file mode 100644
index 0000000000..d1c4eb1536
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPluggablePropertyValueModelAdapter.java
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.collection.ListTools;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel.Adapter;
+import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
+import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
+import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
+import org.eclipse.jpt.common.utility.model.event.ListMoveEvent;
+import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
+import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
+import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
+import org.eclipse.jpt.common.utility.model.value.ListValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * Adapt a {@link ListValueModel list value model} to
+ * a {@link PropertyValueModel property value model}, sorta.
+ * <p>
+ * This adapter is constructed with a {@link ListValueModel
+ * list value model} and a {@link Transformer transformer} that can
+ * transform the list to a single value.
+ * <p>
+ * This is an adapter that can be plugged into a {@link PluggablePropertyValueModel}.
+ *
+ * @param <E> the type of the adapted list value model's elements
+ * @param <V> the type of the model's derived value
+ *
+ * @see PluggablePropertyValueModel
+ */
+public final class ListPluggablePropertyValueModelAdapter<E, V>
+ implements PluggablePropertyValueModel.Adapter<V>, ListChangeListener
+{
+ private final Factory<E, V> factory;
+
+ /** The <em>real</em> adapter. */
+ private final AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener;
+
+ /** Cached copy of model's elements. */
+ private final ArrayList<E> list;
+
+ /** Protects {@link #list} from {@link Factory#transformer}. */
+ private final List<E> unmodifiableList;
+
+ /** The derived value. */
+ private volatile V value;
+
+
+ // ********** constructors **********
+
+ public ListPluggablePropertyValueModelAdapter(Factory<E, V> factory, AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.factory = factory;
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ this.listener = listener;
+ this.list = new ArrayList<>();
+ this.unmodifiableList = Collections.unmodifiableList(this.list);
+ }
+
+
+ // ********** PropertyValueModelAdapter.Adapter **********
+
+ public V getValue() {
+ return this.value;
+ }
+
+ public void engageModel() {
+ this.factory.listModel.addListChangeListener(ListValueModel.LIST_VALUES, this);
+ ListTools.addAll(this.list, 0, this.factory.listModel);
+ this.value = this.buildValue();
+ }
+
+ public void disengageModel() {
+ this.value = null;
+ this.list.clear();
+ this.factory.listModel.removeListChangeListener(ListValueModel.LIST_VALUES, this);
+ }
+
+
+ // ********** ListChangeListener **********
+
+ @SuppressWarnings("unchecked")
+ public void itemsAdded(ListAddEvent event) {
+ ListTools.addAll(this.list, event.getIndex(), (Iterable<E>) event.getItems(), event.getItemsSize());
+ this.update();
+ }
+
+ public void itemsRemoved(ListRemoveEvent event) {
+ ListTools.removeElementsAtIndex(this.list, event.getIndex(), event.getItemsSize());
+ this.update();
+ }
+
+ public void itemsReplaced(ListReplaceEvent event) {
+ @SuppressWarnings("unchecked")
+ Iterable<E> newItems = (Iterable<E>) event.getNewItems();
+ Iterator<E> stream = newItems.iterator();
+ int last = event.getIndex() + event.getItemsSize();
+ for (int i = event.getIndex(); i < last; i++) {
+ this.list.set(i, stream.next());
+ }
+ this.update();
+ }
+
+ public void itemsMoved(ListMoveEvent event) {
+ ListTools.move(this.list, event.getTargetIndex(), event.getSourceIndex(), event.getLength());
+ this.update();
+ }
+
+ public void listCleared(ListClearEvent event) {
+ this.list.clear();
+ this.update();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void listChanged(ListChangeEvent event) {
+ this.list.clear();
+ CollectionTools.addAll(this.list, (Iterable<E>) event.getList());
+ this.update();
+ }
+
+
+ // ********** misc **********
+
+ private void update() {
+ V newValue = this.buildValue();
+ this.value = newValue;
+ this.listener.valueChanged(newValue);
+ }
+
+ private V buildValue() {
+ return this.factory.transformer.transform(this.unmodifiableList);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.value);
+ }
+
+
+ // ********** PluggablePropertyValueModel.Adapter.Factory **********
+
+ public static class Factory<E, V>
+ implements PluggablePropertyValueModel.Adapter.Factory<V>
+ {
+ /* CU private */ final ListValueModel<? extends E> listModel;
+ /* CU private */ final Transformer<? super List<E>, V> transformer;
+
+ public Factory(ListValueModel<? extends E> listModel, Transformer<? super List<E>, V> transformer) {
+ super();
+ if (listModel == null) {
+ throw new NullPointerException();
+ }
+ this.listModel = listModel;
+ if (transformer == null) {
+ throw new NullPointerException();
+ }
+ this.transformer = transformer;
+ }
+
+ public Adapter<V> buildAdapter(AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ return new ListPluggablePropertyValueModelAdapter<>(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/ListPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPropertyValueModelAdapter.java
deleted file mode 100644
index de238160c9..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPropertyValueModelAdapter.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
-import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
-import org.eclipse.jpt.common.utility.model.event.ListMoveEvent;
-import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
-import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
-import org.eclipse.jpt.common.utility.model.listener.ListChangeAdapter;
-import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
-import org.eclipse.jpt.common.utility.model.value.ListValueModel;
-
-/**
- * This abstract class provides the infrastructure needed to wrap
- * a list value model, "lazily" listen to it, and convert
- * its change notifications into property value model change
- * notifications.
- * <p>
- * Subclasses must override:<ul>
- * <li>{@link #buildValue()}<p>
- * to return the current property value, as derived from the
- * current list value
- * </ul>
- * Subclasses might want to override the following methods
- * to improve performance (by not recalculating the value, if possible):<ul>
- * <li>{@link #itemsAdded(ListAddEvent event)}
- * <li>{@link #itemsRemoved(ListRemoveEvent event)}
- * <li>{@link #itemsReplaced(ListReplaceEvent event)}
- * <li>{@link #itemsMoved(ListMoveEvent event)}
- * <li>{@link #listCleared(ListClearEvent event)}
- * <li>{@link #listChanged(ListChangeEvent event)}
- * </ul>
- */
-public abstract class ListPropertyValueModelAdapter<T>
- extends AbstractPropertyValueModelAdapter<T>
-{
- /** The wrapped list value model. */
- protected final ListValueModel<?> listModel;
-
- /** A listener that allows us to sync with changes to the wrapped list model. */
- protected final ListChangeListener listListener;
-
-
- // ********** constructor/initialization **********
-
- /**
- * Construct a property value model with the specified wrapped
- * list value model.
- */
- protected ListPropertyValueModelAdapter(ListValueModel<?> listModel) {
- super();
- if (listModel == null) {
- throw new NullPointerException();
- }
- this.listModel = listModel;
- this.listListener = this.buildListListener();
- }
-
- protected ListChangeListener buildListListener() {
- return new ListListener();
- }
-
- protected class ListListener
- extends ListChangeAdapter
- {
- @Override
- public void itemsAdded(ListAddEvent event) {
- ListPropertyValueModelAdapter.this.itemsAdded(event);
- }
- @Override
- public void itemsRemoved(ListRemoveEvent event) {
- ListPropertyValueModelAdapter.this.itemsRemoved(event);
- }
- @Override
- public void itemsReplaced(ListReplaceEvent event) {
- ListPropertyValueModelAdapter.this.itemsReplaced(event);
- }
- @Override
- public void itemsMoved(ListMoveEvent event) {
- ListPropertyValueModelAdapter.this.itemsMoved(event);
- }
- @Override
- public void listCleared(ListClearEvent event) {
- ListPropertyValueModelAdapter.this.listCleared(event);
- }
- @Override
- public void listChanged(ListChangeEvent event) {
- ListPropertyValueModelAdapter.this.listChanged(event);
- }
- }
-
-
- // ********** listener **********
-
- /**
- * Start listening to the list holder.
- */
- @Override
- protected void engageModel_() {
- this.listModel.addListChangeListener(ListValueModel.LIST_VALUES, this.listListener);
- }
-
- /**
- * Stop listening to the list holder.
- */
- @Override
- protected void disengageModel_() {
- this.listModel.removeListChangeListener(ListValueModel.LIST_VALUES, this.listListener);
- }
-
-
- // ********** list change support **********
-
- /**
- * Items were added to the wrapped list holder;
- * propagate the change notification appropriately.
- */
- protected void itemsAdded(@SuppressWarnings("unused") ListAddEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * Items were removed from the wrapped list holder;
- * propagate the change notification appropriately.
- */
- protected void itemsRemoved(@SuppressWarnings("unused") ListRemoveEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * Items were replaced in the wrapped list holder;
- * propagate the change notification appropriately.
- */
- protected void itemsReplaced(@SuppressWarnings("unused") ListReplaceEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * Items were moved in the wrapped list holder;
- * propagate the change notification appropriately.
- */
- protected void itemsMoved(@SuppressWarnings("unused") ListMoveEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * The wrapped list holder was cleared;
- * propagate the change notification appropriately.
- */
- protected void listCleared(@SuppressWarnings("unused") ListClearEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * The value of the wrapped list holder has changed;
- * propagate the change notification appropriately.
- */
- protected void listChanged(@SuppressWarnings("unused") ListChangeEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelTools.java
new file mode 100644
index 0000000000..1e49f0a853
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelTools.java
@@ -0,0 +1,222 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.jpt.common.utility.closure.Closure;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
+import org.eclipse.jpt.common.utility.internal.closure.ClosureTools;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.ListValueModel;
+import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.predicate.Predicate;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * {@link ListValueModel List value model} utility methods.
+ */
+public final class ListValueModelTools {
+
+ // ********** composite PVMs **********
+
+ /**
+ * Construct a composite property value model adapter for the specified
+ * transformer and property value models.
+ */
+ @SafeVarargs
+ public static <E, V> PropertyValueModel<V> compositePropertyValueModel(Transformer<? super List<E>, V> transformer, PropertyValueModel<? extends E>... propertyValueModels) {
+ return compositePropertyValueModel(Arrays.asList(propertyValueModels), transformer);
+ }
+
+ /**
+ * Construct a composite property value model adapter for the specified
+ * property value models and transformer.
+ */
+ public static <E, V> PropertyValueModel<V> compositePropertyValueModel(Collection<? extends PropertyValueModel<? extends E>> propertyValueModels, Transformer<? super List<E>, V> transformer) {
+ return compositePropertyValueModel(new StaticListValueModel<>(propertyValueModels), transformer);
+ }
+
+ /**
+ * Construct a composite property value model adapter for the specified
+ * list value model and transformer.
+ * @see PluggablePropertyValueModel
+ */
+ public static <E, V> PropertyValueModel<V> compositePropertyValueModel(ListValueModel<? extends PropertyValueModel<? extends E>> listModel, Transformer<? super List<E>, V> transformer) {
+ return PropertyValueModelTools.propertyValueModel(new ListCompositePropertyValueModelAdapter.Factory<>(listModel, transformer));
+ }
+
+
+ // ********** list meta data adapters **********
+
+ /**
+ * Construct a property value model adapter for the specified
+ * list value model.
+ * If the list is empty, the model's value is <code>null</code>;
+ * otherwise, it is the first element in the list.
+ */
+ public static <E> PropertyValueModel<E> firstElementPropertyValueModel(ListValueModel<? extends E> listModel) {
+ return propertyValueModel(listModel, TransformerTools.collectionFirstElementTransformer());
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * list value model.
+ * If the list is empty, the model's value is <code>null</code>;
+ * otherwise, it is the last element in the list.
+ */
+ public static <E> PropertyValueModel<E> lastElementPropertyValueModel(ListValueModel<? extends E> listModel) {
+ return propertyValueModel(listModel, TransformerTools.collectionLastElementTransformer());
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * list value model.
+ * If the list contains <em>only</em> a single element,
+ * the model's value is that element; otherwise,
+ * the model's value is <code>null</code>.
+ */
+ public static <E> PropertyValueModel<E> singleElementPropertyValueModel(ListValueModel<? extends E> listModel) {
+ return propertyValueModel(listModel, TransformerTools.collectionSingleElementTransformer());
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * list value model that returns whether the list is <em>not</em> empty.
+ */
+ public static PropertyValueModel<Boolean> isNotEmptyPropertyValueModel(ListValueModel<?> listModel) {
+ return propertyValueModel(listModel, TransformerTools.collectionIsNotEmptyTransformer());
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapter for the specified
+ * list value model that returns whether the list is <em>not</em> empty.
+ * This model can also be used to populate or clear the list value model.
+ * The specified list mutator is used to convert the list value model:
+ * it should populate the list value model when passed <code>true</code>
+ * and clear the list value model when passed <code>false</code>.
+ */
+ public static ModifiablePropertyValueModel<Boolean> isNotEmptyModifiablePropertyValueModel(ListValueModel<?> listModel, BooleanClosure.Adapter listMutator) {
+ return booleanModifiablePropertyValueModel(listModel, TransformerTools.collectionIsNotEmptyTransformer(), listMutator);
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * list value model that returns whether the list is empty.
+ */
+ public static PropertyValueModel<Boolean> isEmptyPropertyValueModel(ListValueModel<?> listModel) {
+ return propertyValueModel(listModel, TransformerTools.collectionIsEmptyTransformer());
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapter for the specified
+ * list value model that returns whether the list is empty.
+ * This model can also be used to populate or clear the list value model.
+ * The specified list mutator is used to convert the list value model:
+ * it should populate the list value model when passed <code>true</code>
+ * and clear the list value model when passed <code>false</code>.
+ */
+ public static ModifiablePropertyValueModel<Boolean> isEmptyModifiablePropertyValueModel(ListValueModel<?> listModel, BooleanClosure.Adapter listMutator) {
+ return booleanModifiablePropertyValueModel(listModel, TransformerTools.collectionIsEmptyTransformer(), listMutator);
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * list value model that returns whether the list contains
+ * exactly one element.
+ */
+ public static PropertyValueModel<Boolean> containsSingleElementPropertyValueModel(ListValueModel<?> listModel) {
+ return propertyValueModel(listModel, TransformerTools.collectionContainsSingleElementTransformer());
+ }
+
+ /**
+ * Construct a property value model adapter for the specified
+ * list value model that returns whether the list's size
+ * equals the specified size.
+ */
+ public static PropertyValueModel<Boolean> sizeEqualsPropertyValueModel(ListValueModel<?> listModel, int size) {
+ return propertyValueModel(listModel, TransformerTools.collectionSizeEqualsTransformer(size));
+ }
+
+ // ********** PVM adapters **********
+
+ /**
+ * Construct a boolean property value model adapter for the specified
+ * list value model and predicate. The returned model will indicate whether
+ * the list belongs to the set defined by the predicate.
+ */
+ public static PropertyValueModel<Boolean> booleanPropertyValueModel(ListValueModel<?> listModel, Predicate<? super List<?>> predicate) {
+ return propertyValueModel(listModel, TransformerTools.adapt(predicate));
+ }
+
+ /**
+ * Construct a property value model adapted to the specified
+ * list value model and transformer.
+ * @see PluggablePropertyValueModel
+ */
+ public static <E, V> PropertyValueModel<V> propertyValueModel(ListValueModel<? extends E> listModel, Transformer<? super List<E>, V> transformer) {
+ return PropertyValueModelTools.propertyValueModel(pluggablePropertyValueModelAdapterFactory(listModel, transformer));
+ }
+
+ /**
+ * Construct a pluggable property value model adapter factory for the specified
+ * list value model and transformer.
+ * @see PluggablePropertyValueModel
+ */
+ public static <E, V> PluggablePropertyValueModel.Adapter.Factory<V> pluggablePropertyValueModelAdapterFactory(ListValueModel<? extends E> listModel, Transformer<? super List<E>, V> transformer) {
+ return new ListPluggablePropertyValueModelAdapter.Factory<>(listModel, transformer);
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapter for the specified
+ * list value model that returns whether the list belongs to the set defined
+ * by the specified predicate.
+ * This model will use the specified list mutator to modify the list value model.
+ */
+ public static ModifiablePropertyValueModel<Boolean> booleanModifiablePropertyValueModel(ListValueModel<?> listModel, Predicate<? super Collection<?>> predicate, BooleanClosure.Adapter listMutator) {
+ return booleanModifiablePropertyValueModel(listModel, TransformerTools.adapt(predicate), listMutator);
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapted to the specified
+ * list value model that returns whether the list belongs to the set defined
+ * by the specified transformer.
+ * This model will use the specified list mutator to modify the list value model.
+ */
+ public static ModifiablePropertyValueModel<Boolean> booleanModifiablePropertyValueModel(ListValueModel<?> listModel, Transformer<? super Collection<?>, Boolean> transformer, BooleanClosure.Adapter listMutator) {
+ PluggablePropertyValueModel.Adapter.Factory<Boolean> factory = pluggablePropertyValueModelAdapterFactory(listModel, transformer);
+ Closure<Boolean> closure = ClosureTools.booleanClosure(listMutator);
+ return PropertyValueModelTools.pluggableModifiablePropertyValueModel(factory, closure);
+ }
+
+
+ // ********** filtering **********
+
+ /**
+ * Construct a collection value model with the specified wrapped list value model and filter.
+ */
+ public static <E> CollectionValueModel<E> filter(ListValueModel<? extends E> listModel, Predicate<E> filter) {
+ return CollectionValueModelTools.filter(new ListCollectionValueModelAdapter<E>(listModel), filter);
+ }
+
+
+ // ********** suppressed constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private ListValueModelTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java
new file mode 100644
index 0000000000..b9bbf39ca6
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModel.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+
+/**
+ * This class provides the infrastructure needed to wrap
+ * a <em>modifiable</em> model, "lazily" listen to it, and convert
+ * its change notifications into <em>property</em> value model change
+ * notifications.
+ *
+ * @param <V> the type of the model's derived value
+ */
+public class PluggableModifiablePropertyValueModel<V>
+ extends AbstractPluggablePropertyValueModel<V, PluggableModifiablePropertyValueModel.Adapter<V>>
+ implements ModifiablePropertyValueModel<V>
+{
+ public PluggableModifiablePropertyValueModel(Adapter.Factory<V> adapterFactory) {
+ super(adapterFactory);
+ }
+
+
+ // ********** ModifiablePropertyValueModel implementation **********
+
+ /**
+ * Forward the new value to the adapter.
+ * Our value will be updated by notification from the adapter,
+ * if appropriate.
+ */
+ public void setValue(V value) {
+ this.adapter.setValue(value);
+ }
+
+
+ // ********** Adapter interfaces **********
+
+ public interface Adapter<AV>
+ extends AbstractPluggablePropertyValueModel.Adapter<AV>
+ {
+ /**
+ * Set the adapted model's value,
+ * based on the specified new value of the property value model.
+ */
+ void setValue(AV value);
+
+ interface Factory<AFV>
+ extends AbstractPluggablePropertyValueModel.Adapter.Factory<AFV, Adapter<AFV>>
+ {
+ // NOP
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java
new file mode 100644
index 0000000000..409b8991d1
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggableModifiablePropertyValueModelAdapter.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import org.eclipse.jpt.common.utility.closure.Closure;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+
+/**
+ * This class adds support for plugging in a closure that can be used to set
+ * the model's value.
+ * <p>
+ * This class is most useful when the adapted model is changed <em>outside</em>
+ * the property value model; typically by modifying the original
+ * <em>domain</em> model.
+ *
+ * @param <V> the type of the model's derived value
+ */
+public class PluggableModifiablePropertyValueModelAdapter<V>
+ implements PluggableModifiablePropertyValueModel.Adapter<V>
+{
+ /** Read the adapted model with this. */
+ private final AbstractPluggablePropertyValueModel.Adapter<V> adapter;
+
+ /** Write the adapted model with this. */
+ private final Closure<V> closure;
+
+
+ public PluggableModifiablePropertyValueModelAdapter(AbstractPluggablePropertyValueModel.Adapter<V> adapter, Closure<V> closure) {
+ super();
+ if (adapter == null) {
+ throw new NullPointerException();
+ }
+ this.adapter = adapter;
+ if (closure == null) {
+ throw new NullPointerException();
+ }
+ this.closure = closure;
+ }
+
+ public V getValue() {
+ return this.adapter.getValue();
+ }
+
+ public void setValue(V value) {
+ this.closure.execute(value);
+ }
+
+ public void engageModel() {
+ this.adapter.engageModel();
+ }
+
+ public void disengageModel() {
+ this.adapter.disengageModel();
+ }
+
+
+ // ********** PluggableModifiablePropertyValueModel.Adapter.Factory **********
+
+ public static class Factory<V>
+ implements PluggableModifiablePropertyValueModel.Adapter.Factory<V>
+ {
+ /* CU private */ final AbstractPluggablePropertyValueModel.Adapter.Factory<V, ? extends AbstractPluggablePropertyValueModel.Adapter<V>> factory;
+ /* CU private */ final Closure<V> closure;
+
+ public Factory(AbstractPluggablePropertyValueModel.Adapter.Factory<V, ? extends AbstractPluggablePropertyValueModel.Adapter<V>> factory, Closure<V> closure) {
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.factory = factory;
+ if (closure == null) {
+ throw new NullPointerException();
+ }
+ this.closure = closure;
+ }
+
+ public PluggableModifiablePropertyValueModel.Adapter<V> buildAdapter(AbstractPluggablePropertyValueModel.Adapter.Listener<V> listener) {
+ return new PluggableModifiablePropertyValueModelAdapter<>(this.factory.buildAdapter(listener), this.closure);
+ }
+
+ @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/PluggablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyValueModel.java
new file mode 100644
index 0000000000..42f248d7c1
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PluggablePropertyValueModel.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+/**
+ * This class provides the infrastructure needed to wrap
+ * a model, "lazily" listen to it, and convert
+ * its change notifications into <em>property</em> value model change
+ * notifications.
+ *
+ * @param <V> the type of the model's derived value
+ */
+public class PluggablePropertyValueModel<V>
+ extends AbstractPluggablePropertyValueModel<V, PluggablePropertyValueModel.Adapter<V>>
+{
+ public PluggablePropertyValueModel(Adapter.Factory<V> adapterFactory) {
+ super(adapterFactory);
+ }
+
+
+ // ********** Adapter interfaces **********
+
+ public interface Adapter<AV>
+ extends AbstractPluggablePropertyValueModel.Adapter<AV>
+ {
+ interface Factory<AFV>
+ extends AbstractPluggablePropertyValueModel.Adapter.Factory<AFV, Adapter<AFV>>
+ {
+ // NOP
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueModelTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java
index 79c106fe24..7b1835cbe6 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueModelTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelTools.java
@@ -9,13 +9,39 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
+import org.eclipse.jpt.common.utility.closure.Closure;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
/**
* Value Model utility methods.
*/
-public final class ValueModelTools {
+public final class PropertyValueModelTools {
+
+ /**
+ * Construct a property value model adapter for the specified adapter factory.
+ * @see PluggablePropertyValueModel
+ */
+ public static <V> PropertyValueModel<V> propertyValueModel(PluggablePropertyValueModel.Adapter.Factory<V> adapterFactory) {
+ return new PluggablePropertyValueModel<>(adapterFactory);
+ }
+
+ /**
+ * Construct a modifiable property value model adapter for the specified adapter factory.
+ * @see PluggableModifiablePropertyValueModel
+ */
+ public static <V> ModifiablePropertyValueModel<V> modifiablePropertyValueModel(PluggableModifiablePropertyValueModel.Adapter.Factory<V> adapterFactory) {
+ return new PluggableModifiablePropertyValueModel<>(adapterFactory);
+ }
+
+ /**
+ * Construct a <em>modifiable</em> property value model adapter for the specified
+ * property value model adapter adapter factory and closure.
+ * The specified closure is invoked when the model's value is set.
+ */
+ public static <V> ModifiablePropertyValueModel<V> pluggableModifiablePropertyValueModel(AbstractPluggablePropertyValueModel.Adapter.Factory<V, ? extends AbstractPluggablePropertyValueModel.Adapter<V>> factory, Closure<V> setValueClosure) {
+ return new PluggableModifiablePropertyValueModel<>(new PluggableModifiablePropertyValueModelAdapter.Factory<>(factory, setValueClosure));
+ }
// ********** double PVMs **********
@@ -44,7 +70,7 @@ public final class ValueModelTools {
/**
* Suppress default constructor, ensuring non-instantiability.
*/
- private ValueModelTools() {
+ private PropertyValueModelTools() {
super();
throw new UnsupportedOperationException();
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java
index 3842893b13..c7dcb27ea9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -62,7 +62,7 @@ public class SimpleCollectionValueModel<E>
// ********** CollectionValueModel implementation **********
public Iterator<E> iterator() {
- return new LocalIterator<E>(this.collection.iterator());
+ return new LocalIterator<>(this.collection.iterator());
}
public int size() {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java
index da81f0c2de..3c633626b7 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -65,11 +65,11 @@ public class SimpleListValueModel<E>
// ********** ListValueModel implementation **********
public Iterator<E> iterator() {
- return new LocalIterator<E>(this.list.iterator());
+ return new LocalIterator<>(this.list.iterator());
}
public ListIterator<E> listIterator() {
- return new LocalListIterator<E>(this.list.listIterator());
+ return new LocalListIterator<>(this.list.listIterator());
}
public int size() {
@@ -186,7 +186,7 @@ public class SimpleListValueModel<E>
}
public ListIterator<E> listIterator(int index) {
- return new LocalListIterator<E>(this.list.listIterator(index));
+ return new LocalListIterator<>(this.list.listIterator(index));
}
public List<E> subList(int fromIndex, int toIndex) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java
index c098c884de..c39b5df007 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,9 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.model.value;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.model.Model;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
/**
* Interface used to abstract property accessing and
@@ -31,4 +33,18 @@ public interface PropertyValueModel<V>
*/
V getValue();
String VALUE = "value"; //$NON-NLS-1$
+
+ @SuppressWarnings("rawtypes")
+ Transformer VALUE_TRANSFORMER = new ValueTransformer();
+ class ValueTransformer<V>
+ implements Transformer<PropertyValueModel<V>, V>
+ {
+ public V transform(PropertyValueModel<V> pvm) {
+ return pvm.getValue();
+ }
+ @Override
+ public String toString() {
+ return ObjectTools.singletonToString(this);
+ }
+ }
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
index bdf7a7e20b..bc9ae272a0 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,13 +10,12 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import java.util.Collection;
-
-import junit.framework.TestCase;
-
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+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.PropertyValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
@@ -24,13 +23,16 @@ import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+import junit.framework.TestCase;
@SuppressWarnings("nls")
-public class CollectionPropertyValueModelAdapterTests extends TestCase {
- private ModifiablePropertyValueModel<Boolean> adapter;
- private SimpleCollectionValueModel<String> wrappedCollectionHolder;
+public class CollectionPropertyValueModelAdapterTests
+ extends TestCase
+{
+ private PropertyValueModel<Boolean> adapter;
+ private SimpleCollectionValueModel<String> collectionModel;
PropertyChangeEvent event;
public CollectionPropertyValueModelAdapterTests(String name) {
@@ -40,8 +42,8 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.wrappedCollectionHolder = new SimpleCollectionValueModel<String>();
- this.adapter = new LocalAdapter(this.wrappedCollectionHolder, "666");
+ this.collectionModel = new SimpleCollectionValueModel<>();
+ this.adapter = CollectionValueModelTools.propertyValueModel(this.collectionModel, new LocalTransformer("666"));
this.event = null;
}
@@ -52,11 +54,12 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
}
private boolean booleanValue() {
- return this.adapter.getValue().booleanValue();
+ Boolean value = this.adapter.getValue();
+ return (value != null) && value.booleanValue();
}
private Collection<String> wrappedCollection() {
- return CollectionTools.hashBag(this.wrappedCollectionHolder.iterator());
+ return CollectionTools.hashBag(this.collectionModel.iterator());
}
public void testValue() {
@@ -66,41 +69,25 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
assertFalse(this.booleanValue());
assertFalse(this.wrappedCollection().contains("666"));
- this.wrappedCollectionHolder.add("111");
+ this.collectionModel.add("111");
assertFalse(this.booleanValue());
- this.wrappedCollectionHolder.add("222");
+ this.collectionModel.add("222");
assertFalse(this.booleanValue());
- this.wrappedCollectionHolder.add("666");
+ this.collectionModel.add("666");
assertTrue(this.booleanValue());
assertTrue(this.wrappedCollection().contains("666"));
- this.wrappedCollectionHolder.remove("666");
+ this.collectionModel.remove("666");
assertFalse(this.booleanValue());
assertFalse(this.wrappedCollection().contains("666"));
- this.wrappedCollectionHolder.add("666");
+ this.collectionModel.add("666");
assertTrue(this.booleanValue());
assertTrue(this.wrappedCollection().contains("666"));
- this.wrappedCollectionHolder.clear();
- assertFalse(this.booleanValue());
- assertFalse(this.wrappedCollection().contains("666"));
- }
-
- public void testSetValue() {
- this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent e) {/* OK */}
- });
- assertFalse(this.booleanValue());
- assertFalse(this.wrappedCollection().contains("666"));
-
- this.adapter.setValue(Boolean.TRUE);
- assertTrue(this.booleanValue());
- assertTrue(this.wrappedCollection().contains("666"));
-
- this.adapter.setValue(Boolean.FALSE);
+ this.collectionModel.clear();
assertFalse(this.booleanValue());
assertFalse(this.wrappedCollection().contains("666"));
}
@@ -113,22 +100,22 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
});
assertNull(this.event);
- this.wrappedCollectionHolder.add("111");
+ this.collectionModel.add("111");
assertNull(this.event);
- this.wrappedCollectionHolder.add("222");
+ this.collectionModel.add("222");
assertNull(this.event);
- this.wrappedCollectionHolder.add("666");
+ this.collectionModel.add("666");
this.verifyEvent(false, true);
- this.wrappedCollectionHolder.remove("666");
+ this.collectionModel.remove("666");
this.verifyEvent(true, false);
- this.wrappedCollectionHolder.add("666");
+ this.collectionModel.add("666");
this.verifyEvent(false, true);
- this.wrappedCollectionHolder.clear();
+ this.collectionModel.clear();
this.verifyEvent(true, false);
}
@@ -144,7 +131,7 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
public void propertyChanged(PropertyChangeEvent e) {/* OK */}
};
this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
- this.wrappedCollectionHolder.add("666");
+ this.collectionModel.add("666");
assertTrue(this.booleanValue());
assertTrue(this.wrappedCollection().contains("666"));
@@ -159,7 +146,7 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
public void testHasListeners() {
assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
- assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
+ assertFalse(((AbstractModel) this.collectionModel).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
ChangeListener listener = new ChangeAdapter() {
@Override
@@ -167,73 +154,130 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
};
this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
- assertTrue(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
+ assertTrue(((AbstractModel) this.collectionModel).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
this.adapter.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
- assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
+ assertFalse(((AbstractModel) this.collectionModel).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
this.adapter.addChangeListener(listener);
assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
- assertTrue(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
+ assertTrue(((AbstractModel) this.collectionModel).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
this.adapter.removeChangeListener(listener);
assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
- assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
+ assertFalse(((AbstractModel) this.collectionModel).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
+ }
+
+ public void testToString1() {
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {/* OK */}
+ });
+ assertTrue(this.adapter.toString().endsWith("(false)"));
+ this.collectionModel.add("666");
+ assertTrue(this.adapter.toString().endsWith("(true)"));
+ }
+
+ public void testToString3() {
+ CollectionPluggablePropertyValueModelAdapter.Factory<String, Boolean> f = new CollectionPluggablePropertyValueModelAdapter.Factory<>(this.collectionModel, new LocalTransformer("666"));
+ assertTrue(f.toString().indexOf("Factory") != -1);
+ }
+
+ public void testToString4() {
+ PropertyChangeListener listener = new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {/* OK */}
+ };
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ Object a = ObjectTools.get(this.adapter, "adapter");
+ Object l = ObjectTools.get(a, "listener");
+ assertTrue(l.toString().indexOf("AdapterListener") != -1);
+ }
+
+ public void testCtor_NPE1A() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = CollectionValueModelTools.propertyValueModel(null, new LocalTransformer("666"));
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE1B() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = CollectionValueModelTools.propertyValueModel(null, new LocalTransformer("666"));
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE2A() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = CollectionValueModelTools.propertyValueModel(this.collectionModel, null);
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE2B() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = CollectionValueModelTools.propertyValueModel(this.collectionModel, null);
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE4() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = PropertyValueModelTools.propertyValueModel(null);
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
}
// ********** member class **********
/**
- * the value is true if the wrapped collection contains the specified item,
- * otherwise the value is false
+ * Transform the collection to <code>true</code> if it contains the specified item,
+ * otherwise transform it to <code>false</code>.
*/
- static class LocalAdapter
- extends CollectionPropertyValueModelAdapter<Boolean, String>
- implements ModifiablePropertyValueModel<Boolean>
+ static class LocalTransformer
+ implements Transformer<Collection<String>, Boolean>
{
- private String item;
+ private final String item;
- LocalAdapter(CollectionValueModel<String> collectionHolder, String item) {
- super(collectionHolder);
+ LocalTransformer(String item) {
+ super();
this.item = item;
}
- // ********** CollectionPropertyValueModelAdapter implementation **********
- /**
- * always return a Boolean
- */
- @Override
- public Boolean getValue() {
- Boolean result = super.getValue();
- return (result == null) ? Boolean.FALSE : result;
- }
- @SuppressWarnings("unchecked")
- public void setValue(Boolean value) {
- if (this.booleanValue()) {
- if ( ! this.booleanValueOf(value)) {
- // the value is changing from true to false
- ((SimpleCollectionValueModel<String>) this.collectionModel).remove(this.item);
- }
- } else {
- if (this.booleanValueOf(value)) {
- // the value is changing from false to true
- ((SimpleCollectionValueModel<String>) this.collectionModel).add(this.item);
- }
- }
- }
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(IteratorTools.contains(this.collectionModel.iterator(), this.item));
+ public Boolean transform(Collection<String> collection) {
+ return Boolean.valueOf(collection.contains(this.item));
}
- // ********** internal methods **********
- private boolean booleanValue() {
- return this.booleanValueOf(this.value);
- }
- private boolean booleanValueOf(Object b) {
- return (b == null) ? false : ((Boolean) b).booleanValue();
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.item);
}
}
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionValueModelToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionValueModelToolsTests.java
new file mode 100644
index 0000000000..e7f0f726a1
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionValueModelToolsTests.java
@@ -0,0 +1,438 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import org.eclipse.jpt.common.utility.internal.ClassTools;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
+import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
+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.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class CollectionValueModelToolsTests
+ extends TestCase
+{
+ public CollectionValueModelToolsTests(String name) {
+ super(name);
+ }
+
+ public void testFirstElementPVMAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ PropertyValueModel<String> pvm = CollectionValueModelTools.firstElementPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertNull(pvm.getValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertEquals("foo", pvm.getValue());
+ assertEquals("foo", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertTrue(pvm.getValue().equals("foo") || pvm.getValue().equals("bar"));
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertEquals("bar", pvm.getValue());
+ // unpredictable
+ // assertEquals("bar", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertNull(pvm.getValue());
+ assertNull(listener.event.getNewValue());
+ }
+
+ public void testLastElementPVMAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ PropertyValueModel<String> pvm = CollectionValueModelTools.lastElementPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertNull(pvm.getValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertEquals("foo", pvm.getValue());
+ assertEquals("foo", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertTrue(pvm.getValue().equals("foo") || pvm.getValue().equals("bar"));
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertEquals("bar", pvm.getValue());
+ // unpredictable
+ // assertEquals("bar", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertNull(pvm.getValue());
+ assertNull(listener.event.getNewValue());
+ }
+
+ public void testSingleElementPVMAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ PropertyValueModel<String> pvm = CollectionValueModelTools.singleElementPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertNull(pvm.getValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertEquals("foo", pvm.getValue());
+ assertEquals("foo", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertNull(pvm.getValue());
+ assertNull(listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertEquals("bar", pvm.getValue());
+ assertEquals("bar", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertNull(pvm.getValue());
+ assertNull(listener.event.getNewValue());
+ }
+
+ public void testIsNotEmptyPropertyValueModelAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ PropertyValueModel<Boolean> pvm = CollectionValueModelTools.isNotEmptyPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ }
+
+ public void testIsNotEmptyModifiablePropertyValueModelAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ BooleanClosure.Adapter adapter = new NotEmptyBooleanClosureAdapter(cvm);
+ ModifiablePropertyValueModel<Boolean> pvm = CollectionValueModelTools.isNotEmptyModifiablePropertyValueModel(cvm, adapter);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ pvm.setValue(Boolean.FALSE);
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ assertEquals(0, cvm.size());
+
+ listener.event = null;
+ pvm.setValue(Boolean.TRUE);
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+ assertEquals(2, cvm.size());
+ assertTrue(cvm.contains("baz"));
+ assertTrue(cvm.contains("xxx"));
+
+ listener.event = null;
+ cvm.remove("baz");
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("xxx");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ }
+
+ public static class NotEmptyBooleanClosureAdapter
+ implements BooleanClosure.Adapter
+ {
+ final SimpleCollectionValueModel<String> cvm;
+ public NotEmptyBooleanClosureAdapter(SimpleCollectionValueModel<String> cvm) {
+ this.cvm = cvm;
+ }
+ public void execute(boolean argument) {
+ if (argument) {
+ ArrayList<String> list = new ArrayList<>();
+ list.add("baz");
+ list.add("xxx");
+ this.cvm.setValues(list);
+ } else {
+ this.cvm.clear();
+ }
+ }
+ }
+
+ public void testIsEmptyPropertyValueModelAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ PropertyValueModel<Boolean> pvm = CollectionValueModelTools.isEmptyPropertyValueModel(cvm);
+ this.verifyIsEmptyPropertyValueModelAdapter(cvm, pvm);
+ }
+
+ private void verifyIsEmptyPropertyValueModelAdapter(SimpleCollectionValueModel<String> cvm, PropertyValueModel<Boolean> pvm) {
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+ }
+
+ public void testBooleanPVM() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ PropertyValueModel<Boolean> pvm = CollectionValueModelTools.booleanPropertyValueModel(cvm, PredicateTools.collectionIsEmptyPredicate());
+ this.verifyIsEmptyPropertyValueModelAdapter(cvm, pvm);
+ }
+
+ public void testIsEmptyModifiablePropertyValueModelAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ BooleanClosure.Adapter adapter = new EmptyBooleanClosureAdapter(cvm);
+ ModifiablePropertyValueModel<Boolean> pvm = CollectionValueModelTools.isEmptyModifiablePropertyValueModel(cvm, adapter);
+ this.verifyIsEmptyModifiablePropertyValueModelAdapter(cvm, pvm);
+ }
+
+ public void testBooleanModifiablePVM() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ BooleanClosure.Adapter adapter = new EmptyBooleanClosureAdapter(cvm);
+ ModifiablePropertyValueModel<Boolean> pvm = CollectionValueModelTools.booleanModifiablePropertyValueModel(cvm, PredicateTools.collectionIsEmptyPredicate(), adapter);
+ this.verifyIsEmptyPropertyValueModelAdapter(cvm, pvm);
+ }
+
+ private void verifyIsEmptyModifiablePropertyValueModelAdapter(SimpleCollectionValueModel<String> cvm, ModifiablePropertyValueModel<Boolean> pvm) {
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ pvm.setValue(Boolean.TRUE);
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+ assertEquals(0, cvm.size());
+
+ listener.event = null;
+ pvm.setValue(Boolean.FALSE);
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ assertEquals(2, cvm.size());
+ assertTrue(cvm.contains("baz"));
+ assertTrue(cvm.contains("xxx"));
+
+ listener.event = null;
+ cvm.remove("baz");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("xxx");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+ }
+
+ public static class EmptyBooleanClosureAdapter
+ implements BooleanClosure.Adapter
+ {
+ final SimpleCollectionValueModel<String> cvm;
+ public EmptyBooleanClosureAdapter(SimpleCollectionValueModel<String> cvm) {
+ this.cvm = cvm;
+ }
+ public void execute(boolean argument) {
+ if (argument) {
+ this.cvm.clear();
+ } else {
+ ArrayList<String> list = new ArrayList<>();
+ list.add("baz");
+ list.add("xxx");
+ this.cvm.setValues(list);
+ }
+ }
+ }
+
+ public void testContainsSingleElementPropertyValueModelAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ PropertyValueModel<Boolean> pvm = CollectionValueModelTools.containsSingleElementPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ }
+
+ public void testSizeEqualsPropertyValueModelAdapter() {
+ SimpleCollectionValueModel<String> cvm = new SimpleCollectionValueModel<>();
+ PropertyValueModel<Boolean> pvm = CollectionValueModelTools.sizeEqualsPropertyValueModel(cvm, 2);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("bar");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("baz");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("baz");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+ }
+
+ public static class LocalPropertyChangeListener
+ extends PropertyChangeAdapter
+ {
+ public PropertyChangeEvent event;
+ public LocalPropertyChangeListener() {
+ super();
+ }
+ @Override
+ public void propertyChanged(PropertyChangeEvent e) {
+ this.event = e;
+ }
+ }
+
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object o = ClassTools.newInstance(CollectionValueModelTools.class);
+ fail("bogus: " + o);
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeBooleanPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeAndBooleanPropertyValueModelTests.java
index 29201ce800..a6de1c427a 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeBooleanPropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeAndBooleanPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 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.
@@ -10,22 +10,23 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
-
-import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.model.value.CompositeBooleanPropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
-public class CompositeBooleanPropertyValueModelTests extends TestCase {
+public class CompositeAndBooleanPropertyValueModelTests
+ extends TestCase
+{
private SimplePropertyValueModel<Boolean> pvm1;
private ModifiablePropertyValueModel<Boolean> pvm2;
private ModifiablePropertyValueModel<Boolean> pvm3;
@@ -36,29 +37,29 @@ public class CompositeBooleanPropertyValueModelTests extends TestCase {
PropertyChangeEvent event;
- public CompositeBooleanPropertyValueModelTests(String name) {
+ public CompositeAndBooleanPropertyValueModelTests(String name) {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
- this.pvm1 = new SimplePropertyValueModel<Boolean>(Boolean.TRUE);
- this.pvm2 = new SimplePropertyValueModel<Boolean>(Boolean.TRUE);
- this.pvm3 = new SimplePropertyValueModel<Boolean>(Boolean.TRUE);
- this.pvm4 = new SimplePropertyValueModel<Boolean>(Boolean.TRUE);
- this.collection = new ArrayList<ModifiablePropertyValueModel<Boolean>>();
+ this.pvm1 = new SimplePropertyValueModel<>(Boolean.TRUE);
+ this.pvm2 = new SimplePropertyValueModel<>(Boolean.TRUE);
+ this.pvm3 = new SimplePropertyValueModel<>(Boolean.TRUE);
+ this.pvm4 = new SimplePropertyValueModel<>(Boolean.TRUE);
+ this.collection = new ArrayList<>();
this.collection.add(this.pvm1);
this.collection.add(this.pvm2);
this.collection.add(this.pvm3);
this.collection.add(this.pvm4);
- this.cvm = new SimpleCollectionValueModel<ModifiablePropertyValueModel<Boolean>>(this.collection);
+ this.cvm = new SimpleCollectionValueModel<>(this.collection);
this.compositePVM = this.buildCompositePVM(this.cvm);
}
private PropertyValueModel<Boolean> buildCompositePVM(CollectionValueModel<ModifiablePropertyValueModel<Boolean>> pvms) {
- return CompositeBooleanPropertyValueModel.and(pvms);
+ return CollectionValueModelTools.and(pvms);
}
@Override
@@ -67,7 +68,23 @@ public class CompositeBooleanPropertyValueModelTests extends TestCase {
super.tearDown();
}
- public void testGetValue() {
+ public void testGetValue1() {
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertTrue(this.compositePVM.getValue().booleanValue());
+ }
+
+ public void testGetValue2() {
+ this.compositePVM = CollectionValueModelTools.and(this.pvm1, this.pvm2, this.pvm3, this.pvm4);
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertTrue(this.compositePVM.getValue().booleanValue());
+ }
+
+ public void testGetValue3() {
+ this.compositePVM = CollectionValueModelTools.and(Arrays.asList(this.pvm1, this.pvm2, this.pvm3, this.pvm4));
assertNull(this.compositePVM.getValue());
ChangeListener listener = this.buildListener();
this.compositePVM.addChangeListener(listener);
@@ -136,7 +153,7 @@ public class CompositeBooleanPropertyValueModelTests extends TestCase {
private void verifyCollectionChange() {
this.event = null;
- ModifiablePropertyValueModel<Boolean> pvm = new SimplePropertyValueModel<Boolean>(Boolean.FALSE);
+ ModifiablePropertyValueModel<Boolean> pvm = new SimplePropertyValueModel<>(Boolean.FALSE);
this.cvm.add(pvm);
this.verifyEvent(true, false);
@@ -145,15 +162,23 @@ public class CompositeBooleanPropertyValueModelTests extends TestCase {
this.verifyEvent(false, true);
this.event = null;
+ this.cvm.add(pvm);
+ this.verifyEvent(true, false);
+
+ this.event = null;
this.cvm.clear();
- this.verifyEvent(Boolean.TRUE, null);
+ this.verifyEvent(false, true);
- Collection<ModifiablePropertyValueModel<Boolean>> c2 = new ArrayList<ModifiablePropertyValueModel<Boolean>>();
+ this.event = null;
+ this.cvm.add(pvm);
+ this.verifyEvent(true, false);
+
+ Collection<ModifiablePropertyValueModel<Boolean>> c2 = new ArrayList<>();
c2.add(this.pvm1);
c2.add(this.pvm2);
this.event = null;
this.cvm.setValues(c2);
- this.verifyEvent(null, Boolean.TRUE);
+ this.verifyEvent(false, true);
}
public void testLazyListening1() {
@@ -182,7 +207,7 @@ public class CompositeBooleanPropertyValueModelTests extends TestCase {
return new ChangeAdapter() {
@Override
public void propertyChanged(PropertyChangeEvent e) {
- CompositeBooleanPropertyValueModelTests.this.event = e;
+ CompositeAndBooleanPropertyValueModelTests.this.event = e;
}
};
}
@@ -192,6 +217,7 @@ public class CompositeBooleanPropertyValueModelTests extends TestCase {
}
private void verifyEvent(Boolean oldValue, Boolean newValue) {
+ assertNotNull(this.event);
assertEquals(this.compositePVM, this.event.getSource());
assertEquals(PropertyValueModel.VALUE, this.event.getPropertyName());
assertEquals(oldValue, this.event.getOldValue());
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeOrBooleanPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeOrBooleanPropertyValueModelTests.java
new file mode 100644
index 0000000000..a85722c639
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeOrBooleanPropertyValueModelTests.java
@@ -0,0 +1,227 @@
+/*******************************************************************************
+ * 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.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
+
+public class CompositeOrBooleanPropertyValueModelTests
+ extends TestCase
+{
+ private SimplePropertyValueModel<Boolean> pvm1;
+ private ModifiablePropertyValueModel<Boolean> pvm2;
+ private ModifiablePropertyValueModel<Boolean> pvm3;
+ private ModifiablePropertyValueModel<Boolean> pvm4;
+ private Collection<ModifiablePropertyValueModel<Boolean>> collection;
+ private SimpleCollectionValueModel<ModifiablePropertyValueModel<Boolean>> cvm;
+ private PropertyValueModel<Boolean> compositePVM;
+ PropertyChangeEvent event;
+
+
+ public CompositeOrBooleanPropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.pvm1 = new SimplePropertyValueModel<>(Boolean.FALSE);
+ this.pvm2 = new SimplePropertyValueModel<>(Boolean.FALSE);
+ this.pvm3 = new SimplePropertyValueModel<>(Boolean.FALSE);
+ this.pvm4 = new SimplePropertyValueModel<>(Boolean.FALSE);
+ this.collection = new ArrayList<>();
+ this.collection.add(this.pvm1);
+ this.collection.add(this.pvm2);
+ this.collection.add(this.pvm3);
+ this.collection.add(this.pvm4);
+ this.cvm = new SimpleCollectionValueModel<>(this.collection);
+
+ this.compositePVM = this.buildCompositePVM(this.cvm);
+ }
+
+ private PropertyValueModel<Boolean> buildCompositePVM(CollectionValueModel<ModifiablePropertyValueModel<Boolean>> pvms) {
+ return CollectionValueModelTools.or(pvms);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testGetValue1() {
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertFalse(this.compositePVM.getValue().booleanValue());
+ }
+
+ public void testGetValue2() {
+ this.compositePVM = CollectionValueModelTools.or(this.pvm1, this.pvm2, this.pvm3, this.pvm4);
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertFalse(this.compositePVM.getValue().booleanValue());
+ }
+
+ public void testGetValue3() {
+ this.compositePVM = CollectionValueModelTools.or(Arrays.asList(this.pvm1, this.pvm2, this.pvm3, this.pvm4));
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertFalse(this.compositePVM.getValue().booleanValue());
+ }
+
+ public void testValueAndListeners1() {
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertFalse(this.compositePVM.getValue().booleanValue());
+ this.compositePVM.removeChangeListener(listener);
+ assertNull(this.compositePVM.getValue());
+ }
+
+ public void testValueAndListeners2() {
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertFalse(this.compositePVM.getValue().booleanValue());
+ this.compositePVM.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertNull(this.compositePVM.getValue());
+ }
+
+ public void testPropertyChange1() {
+ this.compositePVM.addChangeListener(this.buildListener());
+ this.verifyPropertyChange();
+ }
+
+ public void testPropertyChange2() {
+ this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
+ this.verifyPropertyChange();
+ }
+
+ private void verifyPropertyChange() {
+ this.event = null;
+ this.pvm1.setValue(Boolean.TRUE);
+ this.verifyEvent(false, true);
+
+ this.event = null;
+ this.pvm2.setValue(Boolean.TRUE);
+ assertNull(this.event); // no change
+
+ this.event = null;
+ this.pvm2.setValue(Boolean.FALSE);
+ assertNull(this.event); // no change
+
+ this.event = null;
+ this.pvm1.setValue(Boolean.FALSE);
+ this.verifyEvent(true, false);
+
+ this.event = null;
+ this.pvm4.setValue(Boolean.TRUE);
+ this.verifyEvent(false, true);
+ }
+
+ public void testCollectionChange1() {
+ this.compositePVM.addChangeListener(this.buildListener());
+ this.verifyCollectionChange();
+ }
+
+ public void testCollectionChange2() {
+ this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
+ this.verifyCollectionChange();
+ }
+
+ private void verifyCollectionChange() {
+ this.event = null;
+ ModifiablePropertyValueModel<Boolean> pvm = new SimplePropertyValueModel<>(Boolean.TRUE);
+ this.cvm.add(pvm);
+ this.verifyEvent(false, true);
+
+ this.event = null;
+ this.cvm.remove(pvm);
+ this.verifyEvent(true, false);
+
+ this.event = null;
+ this.cvm.add(pvm);
+ this.verifyEvent(false, true);
+
+ this.event = null;
+ this.cvm.clear();
+ this.verifyEvent(true, false);
+
+ this.event = null;
+ this.cvm.add(pvm);
+ this.verifyEvent(false, true);
+
+ Collection<ModifiablePropertyValueModel<Boolean>> c2 = new ArrayList<>();
+ c2.add(this.pvm1);
+ c2.add(this.pvm2);
+ this.event = null;
+ this.cvm.setValues(c2);
+ this.verifyEvent(true, false);
+ }
+
+ public void testLazyListening1() {
+ assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ ChangeListener listener = this.buildListener();
+
+ this.compositePVM.addChangeListener(listener);
+ assertTrue(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.compositePVM.removeChangeListener(listener);
+ assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testLazyListening2() {
+ assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ ChangeListener listener = this.buildListener();
+
+ this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.compositePVM.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ private ChangeListener buildListener() {
+ return new ChangeAdapter() {
+ @Override
+ public void propertyChanged(PropertyChangeEvent e) {
+ CompositeOrBooleanPropertyValueModelTests.this.event = e;
+ }
+ };
+ }
+
+ private void verifyEvent(boolean oldValue, boolean newValue) {
+ this.verifyEvent(Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
+ }
+
+ private void verifyEvent(Boolean oldValue, Boolean newValue) {
+ assertNotNull(this.event);
+ assertEquals(this.compositePVM, this.event.getSource());
+ assertEquals(PropertyValueModel.VALUE, this.event.getPropertyName());
+ assertEquals(oldValue, this.event.getOldValue());
+ assertEquals(newValue, this.event.getNewValue());
+ }
+
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
index 56acea9e90..47f632d08f 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -11,27 +11,32 @@ package org.eclipse.jpt.common.utility.tests.internal.model.value;
import java.util.ArrayList;
import java.util.Collection;
-
-import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.model.value.CompositePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.exception.RuntimeExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.model.ChangeSupport;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
-public class CompositePropertyValueModelTests extends TestCase {
+@SuppressWarnings("nls")
+public class CompositePropertyValueModelTests
+ extends TestCase
+{
private SimplePropertyValueModel<Integer> pvm1;
private ModifiablePropertyValueModel<Integer> pvm2;
private ModifiablePropertyValueModel<Integer> pvm3;
private ModifiablePropertyValueModel<Integer> pvm4;
- private Collection<ModifiablePropertyValueModel<Integer>> collection;
- private SimpleCollectionValueModel<ModifiablePropertyValueModel<Integer>> cvm;
+ private Collection<PropertyValueModel<Integer>> collection;
+ private SimpleCollectionValueModel<PropertyValueModel<Integer>> cvm;
private PropertyValueModel<Integer> compositePVM;
PropertyChangeEvent event;
@@ -43,31 +48,49 @@ public class CompositePropertyValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.pvm1 = new SimplePropertyValueModel<Integer>(Integer.valueOf(1));
- this.pvm2 = new SimplePropertyValueModel<Integer>(Integer.valueOf(2));
- this.pvm3 = new SimplePropertyValueModel<Integer>(Integer.valueOf(3));
- this.pvm4 = new SimplePropertyValueModel<Integer>(Integer.valueOf(4));
- this.collection = new ArrayList<ModifiablePropertyValueModel<Integer>>();
+ this.pvm1 = new SimplePropertyValueModel<>(Integer.valueOf(1));
+ this.pvm2 = new SimplePropertyValueModel<>(Integer.valueOf(2));
+ this.pvm3 = new SimplePropertyValueModel<>(Integer.valueOf(3));
+ this.pvm4 = new SimplePropertyValueModel<>(Integer.valueOf(4));
+ this.collection = new ArrayList<>();
this.collection.add(this.pvm1);
this.collection.add(this.pvm2);
this.collection.add(this.pvm3);
this.collection.add(this.pvm4);
- this.cvm = new SimpleCollectionValueModel<ModifiablePropertyValueModel<Integer>>(this.collection);
+ this.cvm = new LocalSimpleCollectionValueModel<>(this.collection);
this.compositePVM = this.buildCompositePVM(this.cvm);
}
- private <T extends PropertyValueModel<Integer>> PropertyValueModel<Integer> buildCompositePVM(CollectionValueModel<T> pvms) {
- return new CompositePropertyValueModel<Integer, Integer>(pvms) {
- @Override
- protected Integer buildValue() {
- int sum = 0;
- for (PropertyValueModel<? extends Integer> each : this.collectionModel) {
- sum += each.getValue().intValue();
+ public static class LocalSimpleCollectionValueModel<E>
+ extends SimpleCollectionValueModel<E>
+ {
+ public LocalSimpleCollectionValueModel(Collection<E> collection) {
+ super(collection);
+ }
+ @Override
+ protected ChangeSupport buildChangeSupport() {
+ return new ChangeSupport(this, RuntimeExceptionHandler.instance());
+ }
+ }
+
+ private PropertyValueModel<Integer> buildCompositePVM(CollectionValueModel<PropertyValueModel<Integer>> pvms) {
+ return CollectionValueModelTools.compositePropertyValueModel(pvms, new LocalTransformer());
+ }
+
+ public static class LocalTransformer
+ extends TransformerAdapter<Collection<Integer>, Integer>
+ {
+ @Override
+ public Integer transform(Collection<Integer> integers) {
+ int sum = 0;
+ for (Integer integer : integers) {
+ if (integer != null) {
+ sum += integer.intValue();
}
- return Integer.valueOf(sum);
}
- };
+ return Integer.valueOf(sum);
+ }
}
@Override
@@ -76,7 +99,25 @@ public class CompositePropertyValueModelTests extends TestCase {
super.tearDown();
}
- public void testGetValue() {
+ public void testGetValue1() {
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertEquals(10, this.compositePVM.getValue().intValue());
+ }
+
+ public void testGetValue2() {
+ ArrayList<PropertyValueModel<Integer>> list = new ArrayList<>();
+ CollectionTools.addAll(list, this.cvm);
+ this.compositePVM = CollectionValueModelTools.compositePropertyValueModel(list, new LocalTransformer());
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertEquals(10, this.compositePVM.getValue().intValue());
+ }
+
+ public void testGetValue3() {
+ this.compositePVM = CollectionValueModelTools.compositePropertyValueModel(new LocalTransformer(), this.pvm1, this.pvm2, this.pvm3, this.pvm4);
assertNull(this.compositePVM.getValue());
ChangeListener listener = this.buildListener();
this.compositePVM.addChangeListener(listener);
@@ -133,7 +174,7 @@ public class CompositePropertyValueModelTests extends TestCase {
private void verifyCollectionChange() {
this.event = null;
- ModifiablePropertyValueModel<Integer> pvm = new SimplePropertyValueModel<Integer>(Integer.valueOf(77));
+ ModifiablePropertyValueModel<Integer> pvm = new SimplePropertyValueModel<>(Integer.valueOf(77));
this.cvm.add(pvm);
this.verifyEvent(10, 87);
@@ -145,7 +186,7 @@ public class CompositePropertyValueModelTests extends TestCase {
this.cvm.clear();
this.verifyEvent(10, 0);
- Collection<ModifiablePropertyValueModel<Integer>> c2 = new ArrayList<ModifiablePropertyValueModel<Integer>>();
+ Collection<PropertyValueModel<Integer>> c2 = new ArrayList<>();
c2.add(this.pvm1);
c2.add(this.pvm2);
this.event = null;
@@ -175,6 +216,54 @@ public class CompositePropertyValueModelTests extends TestCase {
assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
}
+ public void testCtor_NPE1() {
+ boolean exCaught = false;
+ try {
+ this.compositePVM = this.buildCompositePVM(null);
+ fail("bogus: " + this.compositePVM);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE2() {
+ boolean exCaught = false;
+ try {
+ this.compositePVM = CollectionValueModelTools.compositePropertyValueModel((CollectionValueModel<PropertyValueModel<Integer>>) this.cvm, (TransformerAdapter<Collection<Integer>, Integer>) null);
+ fail("bogus: " + this.compositePVM);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testNullPVM() {
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ boolean exCaught = false;
+ try {
+ this.cvm.add(null);
+ fail("bogus: " + this.cvm);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testDuplicatePVM() {
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ boolean exCaught = false;
+ try {
+ this.cvm.add(this.pvm1);
+ fail("bogus: " + this.cvm);
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
private ChangeListener buildListener() {
return new ChangeAdapter() {
@Override
@@ -185,6 +274,7 @@ public class CompositePropertyValueModelTests extends TestCase {
}
private void verifyEvent(int oldValue, int newValue) {
+ assertNotNull(this.event);
assertEquals(this.compositePVM, this.event.getSource());
assertEquals(PropertyValueModel.VALUE, this.event.getPropertyName());
assertEquals(Integer.valueOf(oldValue), this.event.getOldValue());
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
index 369d19e5f5..af4dc8ab43 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
@@ -10,7 +10,7 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.ValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -24,7 +24,7 @@ public class DoubleModifiablePropertyValueModelTests
@Override
protected PropertyValueModel<String> buildDoubleModel(ModifiablePropertyValueModel<ModifiablePropertyValueModel<String>> modelModel) {
- return ValueModelTools.wrapModifiable(modelModel);
+ return PropertyValueModelTools.wrapModifiable(modelModel);
}
protected ModifiablePropertyValueModel<String> getDoubleModel() {
@@ -44,7 +44,13 @@ public class DoubleModifiablePropertyValueModelTests
this.stringModelModel.setValue(null);
assertNull(this.doubleModel.getValue());
- this.getDoubleModel().setValue("TTT"); // NOP?
+ boolean exCaught = false;
+ try {
+ this.getDoubleModel().setValue("TTT"); // unsupported?
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
assertEquals("bar", this.stringModel.getValue());
assertNull(this.doubleModel.getValue());
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java
index fef14c236c..d6a5fe85e9 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java
@@ -11,7 +11,7 @@ package org.eclipse.jpt.common.utility.tests.internal.model.value;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.ValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
@@ -55,7 +55,7 @@ public class DoublePropertyValueModelTests
}
protected PropertyValueModel<String> buildDoubleModel(ModifiablePropertyValueModel<ModifiablePropertyValueModel<String>> modelModel) {
- return ValueModelTools.wrap(modelModel);
+ return PropertyValueModelTools.wrap(modelModel);
}
@Override
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java
index 92362adabc..011cf3f978 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,7 @@ import java.util.Vector;
import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.FilteringCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter;
@@ -31,13 +32,13 @@ import org.eclipse.jpt.common.utility.tests.internal.TestTools;
@SuppressWarnings("nls")
public class FilteringCollectionValueModelTests extends TestCase {
- private SimpleCollectionValueModel<String> collectionHolder;
+ private SimpleCollectionValueModel<String> simpleCVM;
CollectionAddEvent addEvent;
CollectionRemoveEvent removeEvent;
CollectionClearEvent collectionClearedEvent;
CollectionChangeEvent collectionChangedEvent;
- private CollectionValueModel<String> filteredCollectionHolder;
+ private CollectionValueModel<String> filteredCVM;
CollectionAddEvent filteredAddEvent;
CollectionRemoveEvent filteredRemoveEvent;
CollectionClearEvent filteredCollectionClearedEvent;
@@ -50,12 +51,12 @@ public class FilteringCollectionValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.collectionHolder = new SimpleCollectionValueModel<String>(buildCollection());
- this.filteredCollectionHolder = new FilteringCollectionValueModel<String>(this.collectionHolder, this.buildFilter());
+ this.simpleCVM = new SimpleCollectionValueModel<>(buildCollection());
+ this.filteredCVM = CollectionValueModelTools.filter(this.simpleCVM, this.buildFilter());
}
private Collection<String> buildCollection() {
- Collection<String> collection = new Vector<String>();
+ Collection<String> collection = new Vector<>();
collection.add("foo");
return collection;
}
@@ -81,72 +82,72 @@ public class FilteringCollectionValueModelTests extends TestCase {
public void testIterator() {
// add a listener to "activate" the wrapper
- this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
+ this.filteredCVM.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
- assertEquals("foo", this.collectionHolder.iterator().next());
- assertFalse(this.filteredCollectionHolder.iterator().hasNext());
+ assertEquals("foo", this.simpleCVM.iterator().next());
+ assertFalse(this.filteredCVM.iterator().hasNext());
- this.collectionHolder.add("bar");
- Iterator<String> collectionHolderValue = this.collectionHolder.iterator();
+ this.simpleCVM.add("bar");
+ Iterator<String> collectionHolderValue = this.simpleCVM.iterator();
assertEquals("foo", collectionHolderValue.next());
assertEquals("bar", collectionHolderValue.next());
- assertTrue(this.filteredCollectionHolder.iterator().hasNext());
- assertEquals("bar", this.filteredCollectionHolder.iterator().next());
+ assertTrue(this.filteredCVM.iterator().hasNext());
+ assertEquals("bar", this.filteredCVM.iterator().next());
- this.collectionHolder.remove("bar");
- assertEquals("foo", this.collectionHolder.iterator().next());
- assertFalse(this.filteredCollectionHolder.iterator().hasNext());
+ this.simpleCVM.remove("bar");
+ assertEquals("foo", this.simpleCVM.iterator().next());
+ assertFalse(this.filteredCVM.iterator().hasNext());
- this.collectionHolder.remove("foo");
- assertFalse(this.collectionHolder.iterator().hasNext());
- assertFalse(this.filteredCollectionHolder.iterator().hasNext());
+ this.simpleCVM.remove("foo");
+ assertFalse(this.simpleCVM.iterator().hasNext());
+ assertFalse(this.filteredCVM.iterator().hasNext());
- this.collectionHolder.add("foo");
- assertEquals("foo", this.collectionHolder.iterator().next());
- assertFalse(this.filteredCollectionHolder.iterator().hasNext());
+ this.simpleCVM.add("foo");
+ assertEquals("foo", this.simpleCVM.iterator().next());
+ assertFalse(this.filteredCVM.iterator().hasNext());
}
public void testSetValue() {
// add a listener to "activate" the wrapper
- this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
+ this.filteredCVM.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
- Collection<String> newCollection = new Vector<String>();
+ Collection<String> newCollection = new Vector<>();
newCollection.add("fox");
newCollection.add("baz");
- this.collectionHolder.setValues(newCollection);
+ this.simpleCVM.setValues(newCollection);
- Iterator<String> collectionValues = this.collectionHolder.iterator();
+ Iterator<String> collectionValues = this.simpleCVM.iterator();
assertEquals("fox", collectionValues.next());
assertEquals("baz", collectionValues.next());
- Iterator<String> filteredCollectionValues = this.filteredCollectionHolder.iterator();
+ Iterator<String> filteredCollectionValues = this.filteredCVM.iterator();
assertEquals("baz", filteredCollectionValues.next());
assertFalse(filteredCollectionValues.hasNext());
}
public void testLazyListening() {
- assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES));
+ assertTrue(((AbstractModel) this.simpleCVM).hasNoCollectionChangeListeners(CollectionValueModel.VALUES));
ChangeListener listener = this.buildFilteredChangeListener();
- this.filteredCollectionHolder.addChangeListener(listener);
- assertTrue(((AbstractModel) this.collectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
- this.filteredCollectionHolder.removeChangeListener(listener);
- assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES));
-
- this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, listener);
- assertTrue(((AbstractModel) this.collectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
- this.filteredCollectionHolder.removeCollectionChangeListener(CollectionValueModel.VALUES, listener);
- assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES));
+ this.filteredCVM.addChangeListener(listener);
+ assertTrue(((AbstractModel) this.simpleCVM).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
+ this.filteredCVM.removeChangeListener(listener);
+ assertTrue(((AbstractModel) this.simpleCVM).hasNoCollectionChangeListeners(CollectionValueModel.VALUES));
+
+ this.filteredCVM.addCollectionChangeListener(CollectionValueModel.VALUES, listener);
+ assertTrue(((AbstractModel) this.simpleCVM).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
+ this.filteredCVM.removeCollectionChangeListener(CollectionValueModel.VALUES, listener);
+ assertTrue(((AbstractModel) this.simpleCVM).hasNoCollectionChangeListeners(CollectionValueModel.VALUES));
}
public void testCollectionChange1() {
- this.collectionHolder.addChangeListener(this.buildChangeListener());
- this.filteredCollectionHolder.addChangeListener(this.buildFilteredChangeListener());
+ this.simpleCVM.addChangeListener(this.buildChangeListener());
+ this.filteredCVM.addChangeListener(this.buildFilteredChangeListener());
this.verifyCollectionChanges();
}
public void testCollectionChange2() {
- this.collectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildListener());
- this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
+ this.simpleCVM.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildListener());
+ this.filteredCVM.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
this.verifyCollectionChanges();
}
@@ -163,48 +164,48 @@ public class FilteringCollectionValueModelTests extends TestCase {
private void verifyCollectionChanges() {
clearEvents();
- this.collectionHolder.add("bar");
- Collection<String> tempCollection = new Vector<String>();
+ this.simpleCVM.add("bar");
+ Collection<String> tempCollection = new Vector<>();
tempCollection.add("bar");
- this.verifyEvent(this.addEvent, this.collectionHolder, tempCollection);
- this.verifyEvent(this.filteredAddEvent, this.filteredCollectionHolder, tempCollection);
+ this.verifyEvent(this.addEvent, this.simpleCVM, tempCollection);
+ this.verifyEvent(this.filteredAddEvent, this.filteredCVM, tempCollection);
clearEvents();
- this.collectionHolder.remove("foo");
+ this.simpleCVM.remove("foo");
tempCollection.remove("bar");
tempCollection.add("foo");
- this.verifyEvent(this.removeEvent, this.collectionHolder, tempCollection);
+ this.verifyEvent(this.removeEvent, this.simpleCVM, tempCollection);
assertNull(this.filteredRemoveEvent);
clearEvents();
- this.collectionHolder.remove("bar");
+ this.simpleCVM.remove("bar");
tempCollection.add("bar");
tempCollection.remove("foo");
- this.verifyEvent(this.removeEvent, this.collectionHolder, tempCollection);
- this.verifyEvent(this.filteredRemoveEvent, this.filteredCollectionHolder, tempCollection);
+ this.verifyEvent(this.removeEvent, this.simpleCVM, tempCollection);
+ this.verifyEvent(this.filteredRemoveEvent, this.filteredCVM, tempCollection);
clearEvents();
- this.collectionHolder.add("foo");
+ this.simpleCVM.add("foo");
tempCollection.remove("bar");
tempCollection.add("foo");
- this.verifyEvent(this.addEvent, this.collectionHolder, tempCollection);
+ this.verifyEvent(this.addEvent, this.simpleCVM, tempCollection);
assertNull(this.filteredAddEvent);
clearEvents();
- Collection<String> newCollection = new Vector<String>();
+ Collection<String> newCollection = new Vector<>();
newCollection.add("fox");
newCollection.add("baz");
- this.collectionHolder.setValues(newCollection);
+ this.simpleCVM.setValues(newCollection);
- this.verifyEvent(this.collectionChangedEvent, this.collectionHolder);
+ this.verifyEvent(this.collectionChangedEvent, this.simpleCVM);
tempCollection.remove("foo");
tempCollection.add("baz");
- this.verifyEvent(this.filteredCollectionChangedEvent, this.filteredCollectionHolder);
+ this.verifyEvent(this.filteredCollectionChangedEvent, this.filteredCVM);
}
@@ -303,8 +304,8 @@ public class FilteringCollectionValueModelTests extends TestCase {
public void testRemoveFilteredItem() {
// build collection with TestItems
- SimpleCollectionValueModel<TestItem> tiHolder = new SimpleCollectionValueModel<TestItem>(this.buildCollection2());
- CollectionValueModel<TestItem> filteredTIHolder = new FilteringCollectionValueModel<TestItem>(tiHolder, this.buildFilter2());
+ SimpleCollectionValueModel<TestItem> tiHolder = new SimpleCollectionValueModel<>(this.buildCollection2());
+ CollectionValueModel<TestItem> filteredTIHolder = new FilteringCollectionValueModel<>(tiHolder, this.buildFilter2());
// add a listener to "activate" the wrapper
filteredTIHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
@@ -325,7 +326,7 @@ public class FilteringCollectionValueModelTests extends TestCase {
}
private Collection<TestItem> buildCollection2() {
- Collection<TestItem> collection = new Vector<TestItem>();
+ Collection<TestItem> collection = new Vector<>();
collection.add(new TestItem("foo"));
return collection;
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java
index ea56db400d..ab6f729e9b 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptCommonUtilityModelValueTests.java
@@ -27,9 +27,11 @@ public class JptCommonUtilityModelValueTests {
suite.addTestSuite(CollectionAspectAdapterTests.class);
suite.addTestSuite(CollectionListValueModelAdapterTests.class);
suite.addTestSuite(CollectionPropertyValueModelAdapterTests.class);
- suite.addTestSuite(CompositeBooleanPropertyValueModelTests.class);
+ suite.addTestSuite(CollectionValueModelToolsTests.class);
+ suite.addTestSuite(CompositeAndBooleanPropertyValueModelTests.class);
suite.addTestSuite(CompositeCollectionValueModelTests.class);
suite.addTestSuite(CompositeListValueModelTests.class);
+ suite.addTestSuite(CompositeOrBooleanPropertyValueModelTests.class);
suite.addTestSuite(CompositePropertyValueModelTests.class);
suite.addTestSuite(DoubleModifiablePropertyValueModelTests.class);
suite.addTestSuite(DoublePropertyValueModelTests.class);
@@ -42,13 +44,17 @@ public class JptCommonUtilityModelValueTests {
suite.addTestSuite(ItemStateListValueModelAdapterTests.class);
suite.addTestSuite(ListAspectAdapterTests.class);
suite.addTestSuite(ListCollectionValueModelAdapterTests.class);
+ suite.addTestSuite(ListCompositePropertyValueModelTests.class);
suite.addTestSuite(ListCuratorTests.class);
+ suite.addTestSuite(ListPropertyValueModelAdapterTests.class);
+ suite.addTestSuite(ListValueModelToolsTests.class);
suite.addTestSuite(NullCollectionValueModelTests.class);
suite.addTestSuite(NullListValueModelTests.class);
suite.addTestSuite(NullPropertyValueModelTests.class);
suite.addTestSuite(PropertyAspectAdapterTests.class);
suite.addTestSuite(PropertyCollectionValueModelAdapterTests.class);
suite.addTestSuite(PropertyListValueModelAdapterTests.class);
+ suite.addTestSuite(PropertyValueModelToolsTests.class);
suite.addTestSuite(ReadOnlyModifiablePropertyValueModelWrapperTests.class);
suite.addTestSuite(SetCollectionValueModelTests.class);
suite.addTestSuite(SimpleCollectionValueModelTests.class);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListCompositePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListCompositePropertyValueModelTests.java
new file mode 100644
index 0000000000..4f28cd8185
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListCompositePropertyValueModelTests.java
@@ -0,0 +1,304 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.jpt.common.utility.internal.collection.ListTools;
+import org.eclipse.jpt.common.utility.internal.exception.RuntimeExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.model.ChangeSupport;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
+import org.eclipse.jpt.common.utility.model.value.ListValueModel;
+import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class ListCompositePropertyValueModelTests
+ extends TestCase
+{
+ private SimplePropertyValueModel<String> pvm1;
+ private ModifiablePropertyValueModel<String> pvm2;
+ private ModifiablePropertyValueModel<String> pvm3;
+ private ModifiablePropertyValueModel<String> pvm4;
+ private List<PropertyValueModel<String>> collection;
+ private SimpleListValueModel<PropertyValueModel<String>> lvm;
+ private PropertyValueModel<String> compositePVM;
+ PropertyChangeEvent event;
+
+
+ public ListCompositePropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.pvm1 = new SimplePropertyValueModel<>("111");
+ this.pvm2 = new SimplePropertyValueModel<>("222");
+ this.pvm3 = new SimplePropertyValueModel<>("333");
+ this.pvm4 = new SimplePropertyValueModel<>("444");
+ this.collection = new ArrayList<>();
+ this.collection.add(this.pvm1);
+ this.collection.add(this.pvm2);
+ this.collection.add(this.pvm3);
+ this.collection.add(this.pvm4);
+ this.lvm = new LocalSimpleListValueModel<>(this.collection);
+
+ this.compositePVM = this.buildCompositePVM(this.lvm);
+ }
+
+ public static class LocalSimpleListValueModel<E>
+ extends SimpleListValueModel<E>
+ {
+ public LocalSimpleListValueModel(List<E> list) {
+ super(list);
+ }
+ @Override
+ protected ChangeSupport buildChangeSupport() {
+ return new ChangeSupport(this, RuntimeExceptionHandler.instance());
+ }
+ }
+
+ private PropertyValueModel<String> buildCompositePVM(ListValueModel<PropertyValueModel<String>> pvms) {
+ return ListValueModelTools.compositePropertyValueModel(pvms, new LocalTransformer());
+ }
+
+ public static class LocalTransformer
+ extends TransformerAdapter<List<String>, String>
+ {
+ @Override
+ public String transform(List<String> strings) {
+ StringBuilder sb = new StringBuilder();
+ for (Iterator<String> stream = strings.iterator(); stream.hasNext(); ) {
+ String string = stream.next();
+ sb.append(string);
+ if (stream.hasNext()) {
+ sb.append("-");
+ }
+ }
+ return sb.toString();
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testGetValue1() {
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertEquals("111-222-333-444", this.compositePVM.getValue());
+ }
+
+ public void testGetValue2() {
+ ArrayList<PropertyValueModel<String>> list = new ArrayList<>();
+ ListTools.addAll(list, 0, this.lvm);
+ this.compositePVM = ListValueModelTools.compositePropertyValueModel(list, new LocalTransformer());
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertEquals("111-222-333-444", this.compositePVM.getValue());
+ }
+
+ public void testGetValue3() {
+ this.compositePVM = ListValueModelTools.compositePropertyValueModel(new LocalTransformer(), this.pvm1, this.pvm2, this.pvm3, this.pvm4);
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertEquals("111-222-333-444", this.compositePVM.getValue());
+ }
+
+ public void testValueAndListeners1() {
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ assertEquals("111-222-333-444", this.compositePVM.getValue());
+ this.compositePVM.removeChangeListener(listener);
+ assertNull(this.compositePVM.getValue());
+ }
+
+ public void testValueAndListeners2() {
+ assertNull(this.compositePVM.getValue());
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertEquals("111-222-333-444", this.compositePVM.getValue());
+ this.compositePVM.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertNull(this.compositePVM.getValue());
+ }
+
+ public void testPropertyChange1() {
+ this.compositePVM.addChangeListener(this.buildListener());
+ this.verifyPropertyChange();
+ }
+
+ public void testPropertyChange2() {
+ this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
+ this.verifyPropertyChange();
+ }
+
+ private void verifyPropertyChange() {
+ this.event = null;
+ this.pvm1.setValue("555");
+ this.verifyEvent("111-222-333-444", "555-222-333-444");
+
+ this.event = null;
+ this.pvm4.setValue("000");
+ this.verifyEvent("555-222-333-444", "555-222-333-000");
+ }
+
+ public void testListChange1() {
+ this.compositePVM.addChangeListener(this.buildListener());
+ this.verifyListChange();
+ }
+
+ public void testListChange2() {
+ this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
+ this.verifyListChange();
+ }
+
+ private void verifyListChange() {
+ this.event = null;
+ ModifiablePropertyValueModel<String> pvm7 = new SimplePropertyValueModel<>("777");
+ this.lvm.add(pvm7);
+ this.verifyEvent("111-222-333-444", "111-222-333-444-777");
+
+ this.event = null;
+ this.lvm.remove(pvm7);
+ this.verifyEvent("111-222-333-444-777", "111-222-333-444");
+
+ this.event = null;
+ ModifiablePropertyValueModel<String> pvmX = new SimplePropertyValueModel<>("XXX");
+ this.lvm.add(2, pvmX);
+ this.verifyEvent("111-222-333-444", "111-222-XXX-333-444");
+
+ this.event = null;
+ this.lvm.move(3, 2);
+ this.verifyEvent("111-222-XXX-333-444", "111-222-333-XXX-444");
+
+ this.event = null;
+ ModifiablePropertyValueModel<String> pvmZ = new SimplePropertyValueModel<>("ZZZ");
+ this.lvm.set(3, pvmZ);
+ this.verifyEvent("111-222-333-XXX-444", "111-222-333-ZZZ-444");
+
+ this.event = null;
+ this.lvm.remove(3);
+ this.verifyEvent("111-222-333-ZZZ-444", "111-222-333-444");
+
+ this.event = null;
+ this.lvm.clear();
+ this.verifyEvent("111-222-333-444", "");
+
+ List<PropertyValueModel<String>> c2 = new ArrayList<>();
+ c2.add(this.pvm1);
+ c2.add(this.pvm2);
+ this.event = null;
+ this.lvm.setListValues(c2);
+ this.verifyEvent("", "111-222");
+ }
+
+ public void testLazyListening1() {
+ assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ ChangeListener listener = this.buildListener();
+
+ this.compositePVM.addChangeListener(listener);
+ assertTrue(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.compositePVM.removeChangeListener(listener);
+ assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testLazyListening2() {
+ assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ ChangeListener listener = this.buildListener();
+
+ this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.compositePVM.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testCtor_NPE1() {
+ boolean exCaught = false;
+ try {
+ this.compositePVM = this.buildCompositePVM(null);
+ fail("bogus: " + this.compositePVM);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE2() {
+ boolean exCaught = false;
+ try {
+ this.compositePVM = ListValueModelTools.compositePropertyValueModel((ListValueModel<PropertyValueModel<String>>) this.lvm, (TransformerAdapter<List<String>, String>) null);
+ fail("bogus: " + this.compositePVM);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testNullPVM() {
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ boolean exCaught = false;
+ try {
+ this.lvm.add(null);
+ fail("bogus: " + this.lvm);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testDuplicatePVM() {
+ ChangeListener listener = this.buildListener();
+ this.compositePVM.addChangeListener(listener);
+ boolean exCaught = false;
+ try {
+ this.lvm.add(this.pvm1);
+ fail("bogus: " + this.lvm);
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ private ChangeListener buildListener() {
+ return new ChangeAdapter() {
+ @Override
+ public void propertyChanged(PropertyChangeEvent e) {
+ ListCompositePropertyValueModelTests.this.event = e;
+ }
+ };
+ }
+
+ private void verifyEvent(String oldValue, String newValue) {
+ assertNotNull(this.event);
+ assertEquals(this.compositePVM, this.event.getSource());
+ assertEquals(PropertyValueModel.VALUE, this.event.getPropertyName());
+ assertEquals(oldValue, this.event.getOldValue());
+ assertEquals(newValue, this.event.getNewValue());
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListPropertyValueModelAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListPropertyValueModelAdapterTests.java
new file mode 100644
index 0000000000..84ffde9534
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListPropertyValueModelAdapterTests.java
@@ -0,0 +1,316 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import java.util.Arrays;
+import java.util.List;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.common.utility.internal.model.value.ListPluggablePropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.ListValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class ListPropertyValueModelAdapterTests
+ extends TestCase
+{
+ private PropertyValueModel<Boolean> adapter;
+ private SimpleListValueModel<String> listModel;
+ PropertyChangeEvent event;
+
+ public ListPropertyValueModelAdapterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.listModel = new SimpleListValueModel<>();
+ this.adapter = ListValueModelTools.propertyValueModel(this.listModel, new LocalTransformer(2, "666"));
+ this.event = null;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ private boolean booleanValue() {
+ Boolean value = this.adapter.getValue();
+ return (value != null) && value.booleanValue();
+ }
+
+ private boolean listModelContains(int index, String value) {
+ return (this.listModel.size() > index) && ObjectTools.equals(this.listModel.get(index), value);
+ }
+
+ public void testValue() {
+ assertNull(this.adapter.getValue());
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {/* OK */}
+ });
+ assertFalse(this.booleanValue());
+ assertFalse(this.listModelContains(2, "666"));
+
+ this.listModel.add("111");
+ assertFalse(this.booleanValue());
+
+ this.listModel.add("222");
+ assertFalse(this.booleanValue());
+
+ this.listModel.add("666");
+ assertTrue(this.booleanValue());
+ assertTrue(this.listModelContains(2, "666"));
+
+ this.listModel.remove("666");
+ assertFalse(this.booleanValue());
+ assertFalse(this.listModelContains(2, "666"));
+
+ this.listModel.add("666");
+ assertTrue(this.booleanValue());
+ assertTrue(this.listModelContains(2, "666"));
+
+ this.listModel.clear();
+ assertFalse(this.booleanValue());
+ assertFalse(this.listModelContains(2, "666"));
+
+ this.listModel.add("111");
+ this.listModel.add("222");
+ this.listModel.add("666");
+ assertTrue(this.booleanValue());
+ assertTrue(this.listModelContains(2, "666"));
+
+ this.listModel.set(2, "333");
+ assertFalse(this.booleanValue());
+ assertFalse(this.listModelContains(2, "666"));
+
+ this.listModel.set(2, "666");
+ assertTrue(this.booleanValue());
+ assertTrue(this.listModelContains(2, "666"));
+
+ this.listModel.move(0, 2);
+ assertFalse(this.booleanValue());
+ assertTrue(this.listModelContains(0, "666"));
+
+ this.listModel.setListValues(Arrays.asList("111", "222", "666"));
+ assertTrue(this.booleanValue());
+ assertTrue(this.listModelContains(2, "666"));
+ }
+
+ public void testEventFiring() {
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ ListPropertyValueModelAdapterTests.this.event = e;
+ }
+ });
+ assertNull(this.event);
+
+ this.listModel.add("111");
+ assertNull(this.event);
+
+ this.listModel.add("222");
+ assertNull(this.event);
+
+ this.listModel.add("666");
+ this.verifyEvent(false, true);
+
+ this.listModel.remove("666");
+ this.verifyEvent(true, false);
+
+ this.listModel.add("666");
+ this.verifyEvent(false, true);
+
+ this.listModel.clear();
+ this.verifyEvent(true, false);
+ }
+
+ private void verifyEvent(boolean oldValue, boolean newValue) {
+ assertEquals(this.adapter, this.event.getSource());
+ assertEquals(Boolean.valueOf(oldValue), this.event.getOldValue());
+ assertEquals(Boolean.valueOf(newValue), this.event.getNewValue());
+ this.event = null;
+ }
+
+ public void testStaleValue() {
+ PropertyChangeListener listener = new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {/* OK */}
+ };
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ this.listModel.add("111");
+ this.listModel.add("222");
+ this.listModel.add("666");
+ assertTrue(this.booleanValue());
+ assertTrue(this.listModelContains(2, "666"));
+
+ this.adapter.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertFalse(this.booleanValue());
+ assertTrue(this.listModelContains(2, "666"));
+
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(this.booleanValue());
+ assertTrue(this.listModelContains(2, "666"));
+ }
+
+ public void testHasListeners() {
+ assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(((AbstractModel) this.listModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+
+ ChangeListener listener = new ChangeAdapter() {
+ @Override
+ public void propertyChanged(PropertyChangeEvent e) {/* OK */}
+ };
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.listModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+
+ this.adapter.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(((AbstractModel) this.listModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+
+ this.adapter.addChangeListener(listener);
+ assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.listModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+
+ this.adapter.removeChangeListener(listener);
+ assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(((AbstractModel) this.listModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+ }
+
+ public void testToString1() {
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {/* OK */}
+ });
+ assertTrue(this.adapter.toString().endsWith("(false)"));
+ this.listModel.add("111");
+ this.listModel.add("222");
+ this.listModel.add("666");
+ assertTrue(this.adapter.toString().endsWith("(true)"));
+ }
+
+ public void testToString3() {
+ ListPluggablePropertyValueModelAdapter.Factory<String, Boolean> f = new ListPluggablePropertyValueModelAdapter.Factory<>(this.listModel, new LocalTransformer(2, "666"));
+ assertTrue(f.toString().indexOf("Factory") != -1);
+ }
+
+ public void testToString4() {
+ PropertyChangeListener listener = new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {/* OK */}
+ };
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ Object a = ObjectTools.get(this.adapter, "adapter");
+ Object l = ObjectTools.get(a, "listener");
+ assertTrue(l.toString().indexOf("AdapterListener") != -1);
+ }
+
+ public void testCtor_NPE1A() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = ListValueModelTools.propertyValueModel(null, new LocalTransformer(2, "666"));
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE1B() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = ListValueModelTools.propertyValueModel(null, new LocalTransformer(2, "666"));
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE2A() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = ListValueModelTools.propertyValueModel(this.listModel, null);
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE2B() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = ListValueModelTools.propertyValueModel(this.listModel, null);
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testCtor_NPE4() {
+ Object object;
+ boolean exCaught = false;
+ try {
+ object = PropertyValueModelTools.propertyValueModel(null);
+ fail("bogus: " + object);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+
+ // ********** member class **********
+
+ /**
+ * Transform the list to <code>true</code> if it contains the specified item
+ * at the specified index, otherwise transform it to <code>false</code>.
+ */
+ static class LocalTransformer
+ implements Transformer<List<String>, Boolean>
+ {
+ private final int index;
+ private final String item;
+
+ LocalTransformer(int index, String item) {
+ super();
+ this.index = index;
+ this.item = item;
+ }
+
+ public Boolean transform(List<String> list) {
+ return Boolean.valueOf(this.transform_(list));
+ }
+
+ public boolean transform_(List<String> list) {
+ return (list.size() > this.index) && ObjectTools.equals(this.item, list.get(this.index));
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.item);
+ }
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListValueModelToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListValueModelToolsTests.java
new file mode 100644
index 0000000000..12ce703f86
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListValueModelToolsTests.java
@@ -0,0 +1,438 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import org.eclipse.jpt.common.utility.internal.ClassTools;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel;
+import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
+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.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class ListValueModelToolsTests
+ extends TestCase
+{
+ public ListValueModelToolsTests(String name) {
+ super(name);
+ }
+
+ public void testFirstElementPVMAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ PropertyValueModel<String> pvm = ListValueModelTools.firstElementPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertNull(pvm.getValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertEquals("foo", pvm.getValue());
+ assertEquals("foo", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertEquals("foo", pvm.getValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertEquals("bar", pvm.getValue());
+ assertEquals("bar", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertNull(pvm.getValue());
+ assertNull(listener.event.getNewValue());
+ }
+
+ public void testLastElementPVMAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ PropertyValueModel<String> pvm = ListValueModelTools.lastElementPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertNull(pvm.getValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertEquals("foo", pvm.getValue());
+ assertEquals("foo", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertEquals("bar", pvm.getValue());
+ assertEquals("bar", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertEquals("bar", pvm.getValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertNull(pvm.getValue());
+ assertNull(listener.event.getNewValue());
+ }
+
+ public void testSingleElementPVMAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ PropertyValueModel<String> pvm = ListValueModelTools.singleElementPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertNull(pvm.getValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertEquals("foo", pvm.getValue());
+ assertEquals("foo", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertNull(pvm.getValue());
+ assertNull(listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertEquals("bar", pvm.getValue());
+ assertEquals("bar", listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertNull(pvm.getValue());
+ assertNull(listener.event.getNewValue());
+ }
+
+ public void testIsNotEmptyPropertyValueModelAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ PropertyValueModel<Boolean> pvm = ListValueModelTools.isNotEmptyPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ }
+
+ public void testIsNotEmptyModifiablePropertyValueModelAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ BooleanClosure.Adapter adapter = new NotEmptyBooleanClosureAdapter(cvm);
+ ModifiablePropertyValueModel<Boolean> pvm = ListValueModelTools.isNotEmptyModifiablePropertyValueModel(cvm, adapter);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ pvm.setValue(Boolean.FALSE);
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ assertEquals(0, cvm.size());
+
+ listener.event = null;
+ pvm.setValue(Boolean.TRUE);
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+ assertEquals(2, cvm.size());
+ assertTrue(cvm.contains("baz"));
+ assertTrue(cvm.contains("xxx"));
+
+ listener.event = null;
+ cvm.remove("baz");
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("xxx");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ }
+
+ public static class NotEmptyBooleanClosureAdapter
+ implements BooleanClosure.Adapter
+ {
+ final SimpleListValueModel<String> cvm;
+ public NotEmptyBooleanClosureAdapter(SimpleListValueModel<String> cvm) {
+ this.cvm = cvm;
+ }
+ public void execute(boolean argument) {
+ if (argument) {
+ ArrayList<String> list = new ArrayList<>();
+ list.add("baz");
+ list.add("xxx");
+ this.cvm.setListValues(list);
+ } else {
+ this.cvm.clear();
+ }
+ }
+ }
+
+ public void testIsEmptyPropertyValueModelAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ PropertyValueModel<Boolean> pvm = ListValueModelTools.isEmptyPropertyValueModel(cvm);
+ this.verifyIsEmptyPropertyValueModelAdapter(cvm, pvm);
+ }
+
+ private void verifyIsEmptyPropertyValueModelAdapter(SimpleListValueModel<String> cvm, PropertyValueModel<Boolean> pvm) {
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+ }
+
+ public void testBooleanPVM() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ PropertyValueModel<Boolean> pvm = ListValueModelTools.booleanPropertyValueModel(cvm, PredicateTools.collectionIsEmptyPredicate());
+ this.verifyIsEmptyPropertyValueModelAdapter(cvm, pvm);
+ }
+
+ public void testIsEmptyModifiablePropertyValueModelAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ BooleanClosure.Adapter adapter = new EmptyBooleanClosureAdapter(cvm);
+ ModifiablePropertyValueModel<Boolean> pvm = ListValueModelTools.isEmptyModifiablePropertyValueModel(cvm, adapter);
+ this.verifyIsEmptyModifiablePropertyValueModelAdapter(cvm, pvm);
+ }
+
+ public void testBooleanModifiablePVM() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ BooleanClosure.Adapter adapter = new EmptyBooleanClosureAdapter(cvm);
+ ModifiablePropertyValueModel<Boolean> pvm = ListValueModelTools.booleanModifiablePropertyValueModel(cvm, PredicateTools.collectionIsEmptyPredicate(), adapter);
+ this.verifyIsEmptyPropertyValueModelAdapter(cvm, pvm);
+ }
+
+ private void verifyIsEmptyModifiablePropertyValueModelAdapter(SimpleListValueModel<String> cvm, ModifiablePropertyValueModel<Boolean> pvm) {
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertTrue(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ pvm.setValue(Boolean.TRUE);
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+ assertEquals(0, cvm.size());
+
+ listener.event = null;
+ pvm.setValue(Boolean.FALSE);
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ assertEquals(2, cvm.size());
+ assertTrue(cvm.contains("baz"));
+ assertTrue(cvm.contains("xxx"));
+
+ listener.event = null;
+ cvm.remove("baz");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.remove("xxx");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+ }
+
+ public static class EmptyBooleanClosureAdapter
+ implements BooleanClosure.Adapter
+ {
+ final SimpleListValueModel<String> cvm;
+ public EmptyBooleanClosureAdapter(SimpleListValueModel<String> cvm) {
+ this.cvm = cvm;
+ }
+ public void execute(boolean argument) {
+ if (argument) {
+ this.cvm.clear();
+ } else {
+ ArrayList<String> list = new ArrayList<>();
+ list.add("baz");
+ list.add("xxx");
+ this.cvm.setListValues(list);
+ }
+ }
+ }
+
+ public void testContainsSingleElementPropertyValueModelAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ PropertyValueModel<Boolean> pvm = ListValueModelTools.containsSingleElementPropertyValueModel(cvm);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+ }
+
+ public void testSizeEqualsPropertyValueModelAdapter() {
+ SimpleListValueModel<String> cvm = new SimpleListValueModel<>();
+ PropertyValueModel<Boolean> pvm = ListValueModelTools.sizeEqualsPropertyValueModel(cvm, 2);
+ LocalPropertyChangeListener listener = new LocalPropertyChangeListener();
+ pvm.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+
+ listener.event = null;
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+
+ listener.event = null;
+ cvm.add("bar");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.add("baz");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("baz");
+ assertTrue(pvm.getValue().booleanValue());
+ assertEquals(Boolean.TRUE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("foo");
+ assertFalse(pvm.getValue().booleanValue());
+ assertEquals(Boolean.FALSE, listener.event.getNewValue());
+
+ listener.event = null;
+ cvm.remove("bar");
+ assertFalse(pvm.getValue().booleanValue());
+ assertNull(listener.event);
+ }
+
+ public static class LocalPropertyChangeListener
+ extends PropertyChangeAdapter
+ {
+ public PropertyChangeEvent event;
+ public LocalPropertyChangeListener() {
+ super();
+ }
+ @Override
+ public void propertyChanged(PropertyChangeEvent e) {
+ this.event = e;
+ }
+ }
+
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object o = ClassTools.newInstance(ListValueModelTools.class);
+ fail("bogus: " + o); //$NON-NLS-1$
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java
new file mode 100644
index 0000000000..1943731ab0
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import java.lang.reflect.InvocationTargetException;
+import org.eclipse.jpt.common.utility.closure.Closure;
+import org.eclipse.jpt.common.utility.internal.ClassTools;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggableModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggableModifiablePropertyValueModel.Adapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
+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;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class PropertyValueModelToolsTests
+ extends TestCase
+{
+
+ public PropertyValueModelToolsTests(String name) {
+ super(name);
+ }
+
+ public void testModifiablePropertyValueModel() {
+ ModifiablePropertyValueModel<String> doubleStringModel = new SimplePropertyValueModel<>("foofoo");
+ PluggableModifiablePropertyValueModel.Adapter.Factory<String> factory = new HalfStringModelAdapter.Factory(doubleStringModel);
+ ModifiablePropertyValueModel<String> halfStringModel = PropertyValueModelTools.modifiablePropertyValueModel(factory);
+ HalfStringListener halfStringListener = new HalfStringListener();
+ halfStringModel.addPropertyChangeListener(PropertyValueModel.VALUE, halfStringListener);
+
+ halfStringListener.event = null;
+ assertEquals("foofoo", doubleStringModel.getValue());
+ assertEquals("foo", halfStringModel.getValue());
+ assertNull(halfStringListener.event);
+
+ halfStringListener.event = null;
+ halfStringModel.setValue("bar");
+ assertEquals("bar", halfStringModel.getValue());
+ assertEquals("barbar", doubleStringModel.getValue());
+ assertEquals("bar", halfStringListener.event.getNewValue());
+
+ halfStringListener.event = null;
+ halfStringModel.setValue("bar");
+ assertEquals("bar", halfStringModel.getValue());
+ assertEquals("barbar", doubleStringModel.getValue());
+ assertNull(halfStringListener.event);
+
+ halfStringListener.event = null;
+ doubleStringModel.setValue("xxxxxx");
+ assertEquals("xxx", halfStringModel.getValue());
+ assertEquals("xxxxxx", doubleStringModel.getValue());
+ assertEquals("xxx", halfStringListener.event.getNewValue());
+
+ halfStringListener.event = null;
+ halfStringModel.removePropertyChangeListener(PropertyValueModel.VALUE, halfStringListener);
+ assertNull(halfStringModel.getValue());
+ assertEquals("xxxxxx", doubleStringModel.getValue());
+ assertNull(halfStringListener.event);
+ }
+
+ public static class HalfStringListener
+ implements PropertyChangeListener
+ {
+ public PropertyChangeEvent event;
+ public void propertyChanged(PropertyChangeEvent e) {
+ this.event = e;
+ }
+ }
+
+ public static class HalfStringModelAdapter
+ implements PluggableModifiablePropertyValueModel.Adapter<String>
+ {
+ private final ModifiablePropertyValueModel<String> stringModel;
+ private final PluggableModifiablePropertyValueModel.Adapter.Listener<String> listener;
+ private final PropertyChangeListener stringListener;
+ private volatile String value;
+
+ public HalfStringModelAdapter(ModifiablePropertyValueModel<String> stringModel, PluggableModifiablePropertyValueModel.Adapter.Listener<String> listener) {
+ super();
+ this.stringModel = stringModel;
+ this.listener = listener;
+ this.stringListener = new StringListener();
+ this.value = null;
+ }
+
+ public void engageModel() {
+ this.stringModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringListener);
+ String v = this.stringModel.getValue();
+ this.value = v.substring(v.length() / 2);
+ }
+
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ this.stringModel.setValue(value + value);
+ }
+
+ public void disengageModel() {
+ this.value = null;
+ this.stringModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.stringListener);
+ }
+
+ void stringChanged(String newStringValue) {
+ String newValue = newStringValue.substring(newStringValue.length() / 2);
+ this.value = newValue;
+ this.listener.valueChanged(newValue);
+ }
+
+ public class StringListener
+ implements PropertyChangeListener
+ {
+ public void propertyChanged(PropertyChangeEvent event) {
+ HalfStringModelAdapter.this.stringChanged((String) event.getNewValue());
+ }
+ }
+
+ public static class Factory
+ implements PluggableModifiablePropertyValueModel.Adapter.Factory<String>
+ {
+ private final ModifiablePropertyValueModel<String> stringModel;
+ public Factory(ModifiablePropertyValueModel<String> stringModel) {
+ super();
+ this.stringModel = stringModel;
+ }
+ public Adapter<String> buildAdapter(PluggableModifiablePropertyValueModel.Adapter.Listener<String> listener) {
+ return new HalfStringModelAdapter(this.stringModel, listener);
+ }
+ }
+ }
+
+ public void testPluggableModifiablePropertyValueModel_NPE() {
+ PluggablePropertyValueModel.Adapter.Factory<String> factory = CollectionValueModelTools.pluggablePropertyValueModelAdapterFactory(new SimpleCollectionValueModel<>(), new TransformerAdapter<>());
+ Closure<String> closure = null;
+ boolean exCaught = false;
+ try {
+ ModifiablePropertyValueModel<String> pvm = PropertyValueModelTools.pluggableModifiablePropertyValueModel(factory, closure);
+ fail("bogus: " + pvm);
+ } catch (NullPointerException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object o = ClassTools.newInstance(PropertyValueModelTools.class);
+ fail("bogus: " + o);
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JaxbProjectModel.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JaxbProjectModel.java
index 0b9d3d4c97..94eaba2aa7 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JaxbProjectModel.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/JaxbProjectModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Oracle. All rights reserved.
+ * 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.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.jaxb.ui;
-import org.eclipse.core.resources.IProject;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jaxb.core.JaxbProject;
@@ -26,8 +25,5 @@ import org.eclipse.jpt.jaxb.core.JaxbProject;
public interface JaxbProjectModel
extends PropertyValueModel<JaxbProject>
{
- /**
- * Return the project corresponding to the JPA project model.
- */
- IProject getProject();
+ // simply an interface we can use in an adapter definition
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ProjectAdapterFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ProjectAdapterFactory.java
index 62bea17c61..f0e2eaf7b3 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ProjectAdapterFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/ProjectAdapterFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 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.
@@ -10,10 +10,11 @@
package org.eclipse.jpt.jaxb.ui.internal;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.jpt.common.utility.internal.model.value.ElementPropertyValueModelAdapter;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+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;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.ui.JaxbProjectModel;
import org.eclipse.jpt.jaxb.ui.JaxbProjectsModel;
@@ -41,56 +42,61 @@ public class ProjectAdapterFactory
return ADAPTER_LIST;
}
- public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adaptableObject instanceof IProject) {
return this.getAdapter((IProject) adaptableObject, adapterType);
}
return null;
}
- private Object getAdapter(IProject project, Class<?> adapterType) {
+ @SuppressWarnings("unchecked")
+ private <T> T getAdapter(IProject project, Class<T> adapterType) {
if (adapterType == JaxbProjectModel.class) {
- return this.getJaxbProjectModel(project);
+ return (T) this.getJaxbProjectModel(project);
}
return null;
}
private JaxbProjectModel getJaxbProjectModel(IProject project) {
- return new JaxbProjectModelAdapter(this.getJaxbProjectsModel(project.getWorkspace()), project);
- }
-
- private JaxbProjectsModel getJaxbProjectsModel(IWorkspace workspace) {
- return (JaxbProjectsModel) workspace.getAdapter(JaxbProjectsModel.class);
+ return new LocalJaxbProjectModel(project);
}
- // ********** JPA project model **********
+ // ********** JAXB project model **********
/**
- * Implement a property value model for the JPA project corresponding to a
+ * Implement a property value model for the JAXB project corresponding to a
* {@link IProject project}. The model will fire change events when the
- * corresponding JPA project is added or removed from the JPA project
+ * corresponding JAXB project is added or removed from the JAXB project
* manager. This is useful for UI code that does not want to wait to
- * retrieve a JPA project but wants to be notified when it is available.
+ * retrieve a JAXB project but wants to be notified when it is available.
* <p>
- * Subclass {@link ElementPropertyValueModelAdapter} so we can
+ * Subclass {@link PluggablePropertyValueModel} so we can
* implement {@link org.eclipse.jpt.jaxb.ui.JaxbProjectModel}.
* <p>
* <strong>NB:</strong> This model operates outside of all the other
- * activity synchronized by the JPA project manager; but that should be OK
- * since it will be kept synchronized with the JPA manager's collection of
- * JPA projects in the end.
+ * activity synchronized by the JAXB project manager; but that should be OK
+ * since it will be kept synchronized with the JAXB manager's collection of
+ * JAXB projects in the end.
*/
- /* CU private */ static class JaxbProjectModelAdapter
- extends ElementPropertyValueModelAdapter<JaxbProject>
+ /* CU private */ static class LocalJaxbProjectModel
+ extends PluggablePropertyValueModel<JaxbProject>
implements JaxbProjectModel
{
- JaxbProjectModelAdapter(CollectionValueModel<JaxbProject> jpaProjectsModel, IProject project) {
- super(jpaProjectsModel, new JaxbProject.ProjectEquals(project));
- }
-
- public IProject getProject() {
- return ((JaxbProject.ProjectEquals) this.predicate).getCriterion();
+ /**
+ * Get all the JAXB projects, then filter down to those corresponding
+ * to the specified project, then get the single JAXB project remaining.
+ * (At least we hope there is only a single JAXB project remaining.)
+ */
+ LocalJaxbProjectModel(IProject project) {
+ super(new CollectionPluggablePropertyValueModelAdapter.Factory<>(
+ CollectionValueModelTools.filter(
+ project.getWorkspace().getAdapter(JaxbProjectsModel.class),
+ new JaxbProject.ProjectEquals(project)
+ ),
+ TransformerTools.collectionSingleElementTransformer()
+ )
+ );
}
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
index 7b6f3b794d..3d7f2e830c 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
@@ -56,7 +56,7 @@ import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.value.AspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.BufferedModifiablePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
@@ -296,12 +296,7 @@ public class JaxbSchemasPropertiesPage
}
private PropertyValueModel<Boolean> buildEditEnabledModel() {
- return new CollectionPropertyValueModelAdapter<Boolean, Schema>(this.schemasSelectionModel) {
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.collectionModel.size() == 1);
- }
- };
+ return CollectionValueModelTools.containsSingleElementPropertyValueModel(this.schemasSelectionModel);
}
private void editSelectedSchema() {
@@ -325,12 +320,7 @@ public class JaxbSchemasPropertiesPage
}
private PropertyValueModel<Boolean> buildRemoveEnabledModel() {
- return new CollectionPropertyValueModelAdapter<Boolean, Schema>(this.schemasSelectionModel) {
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.collectionModel.size() >= 1);
- }
- };
+ return CollectionValueModelTools.isNotEmptyPropertyValueModel(this.schemasSelectionModel);
}
private void removeSelectedSchemas() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertCombo.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertCombo.java
index 88e7763aec..e4aff94a62 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertCombo.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertCombo.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2006, 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.
@@ -16,8 +16,8 @@ import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.FilteringCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SetCollectionValueModel;
@@ -194,7 +194,7 @@ public class EclipseLinkConvertCombo
}
protected CollectionValueModel<String> buildConverterNamesModel() {
- return new FilteringCollectionValueModel<String>(this.buildConverterNamesModel_(), StringTools.IS_NOT_BLANK);
+ return ListValueModelTools.filter(this.buildConverterNamesModel_(), StringTools.IS_NOT_BLANK);
}
protected ListValueModel<String> buildConverterNamesModel_() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertersComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertersComposite.java
index 80a97b8f26..14cfcc9a08 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertersComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConvertersComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -19,7 +19,7 @@ import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.Adapter;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
@@ -90,23 +90,15 @@ public class EclipseLinkConvertersComposite
protected void initialize() {
super.initialize();
this.selectedConvertersModel = this.buildSelectedConvertersModel();
- this.selectedConverterModel = this.buildSelectedConverterModel(this.selectedConvertersModel);
+ this.selectedConverterModel = this.buildSelectedConverterModel();
}
private ModifiableCollectionValueModel<EclipseLinkConverter> buildSelectedConvertersModel() {
- return new SimpleCollectionValueModel<EclipseLinkConverter>();
+ return new SimpleCollectionValueModel<>();
}
- protected PropertyValueModel<EclipseLinkConverter> buildSelectedConverterModel(ModifiableCollectionValueModel<EclipseLinkConverter> selectedConvertersModel) {
- return new CollectionPropertyValueModelAdapter<EclipseLinkConverter, EclipseLinkConverter>(selectedConvertersModel) {
- @Override
- protected EclipseLinkConverter buildValue() {
- if (this.collectionModel.size() == 1) {
- return this.collectionModel.iterator().next();
- }
- return null;
- }
- };
+ protected PropertyValueModel<EclipseLinkConverter> buildSelectedConverterModel() {
+ return CollectionValueModelTools.singleElementPropertyValueModel(this.selectedConvertersModel);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java
index 5c0bf0a8fb..3feba0dbdb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2011, 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.
@@ -15,9 +15,10 @@ import org.eclipse.jpt.common.ui.internal.swt.bindings.SWTBindingTools;
import org.eclipse.jpt.common.ui.internal.widgets.EnumFormComboViewer;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.ui.internal.widgets.TriStateCheckBox;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.PredicatePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ReadOnlyModifiablePropertyValueModelWrapper;
@@ -119,7 +120,7 @@ public class EclipseLinkMultitenancyComposite extends Pane<EclipseLinkMultitenan
addCheckBox(
tenantDiscriminatorColumnGroupPane,
JptJpaEclipseLinkUiDetailsMessages.ECLIPSELINK_MULTITENANCY_OVERRIDE_DEFAULT_TENANT_DISCRIMINATOR_COLUMNS,
- buildOverrideDefaultTenantDiscriminatorColumnHolder(),
+ buildOverrideDefaultTenantDiscriminatorColumnModel(),
null
);
@@ -296,16 +297,16 @@ public class EclipseLinkMultitenancyComposite extends Pane<EclipseLinkMultitenan
private static final Predicate<EclipseLinkMultitenancy2_3> IS_COMPATIBLE_WITH_ECLIPSELINK_2_4 =
PredicateTools.nullCheck(new EclipseLinkVersionIsCompatibleWith(EclipseLinkJpaPlatformFactory2_4.VERSION));
- private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultTenantDiscriminatorColumnHolder() {
- return new OverrideDefaultTenantDiscriminatorColumnHolder();
+ private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultTenantDiscriminatorColumnModel() {
+ return ListValueModelTools.isNotEmptyModifiablePropertyValueModel(this.buildSpecifiedTenantDiscriminatorColumnsListModel(), new OverrideDefaultTenantDiscriminatorColumnModelSetValueClosure());
}
- ListValueModel<EclipseLinkTenantDiscriminatorColumn2_3> buildSpecifiedTenantDiscriminatorColumnsListHolder() {
+ ListValueModel<EclipseLinkTenantDiscriminatorColumn2_3> buildSpecifiedTenantDiscriminatorColumnsListModel() {
return new ListAspectAdapter<EclipseLinkMultitenancy2_3, EclipseLinkTenantDiscriminatorColumn2_3>(
getSubjectHolder(), EclipseLinkMultitenancy2_3.SPECIFIED_TENANT_DISCRIMINATOR_COLUMNS_LIST) {
@Override
protected ListIterable<EclipseLinkTenantDiscriminatorColumn2_3> getListIterable() {
- return new SuperListIterableWrapper<EclipseLinkTenantDiscriminatorColumn2_3>(this.subject.getSpecifiedTenantDiscriminatorColumns());
+ return new SuperListIterableWrapper<>(this.subject.getSpecifiedTenantDiscriminatorColumns());
}
@Override
protected int size_() {
@@ -314,48 +315,39 @@ public class EclipseLinkMultitenancyComposite extends Pane<EclipseLinkMultitenan
};
}
- private class OverrideDefaultTenantDiscriminatorColumnHolder
- extends ListPropertyValueModelAdapter<Boolean>
- implements ModifiablePropertyValueModel<Boolean>
- {
- public OverrideDefaultTenantDiscriminatorColumnHolder() {
- super(buildSpecifiedTenantDiscriminatorColumnsListHolder());
- }
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.listModel.size() > 0);
+ class OverrideDefaultTenantDiscriminatorColumnModelSetValueClosure
+ implements BooleanClosure.Adapter
+ {
+ public void execute(boolean value) {
+ updateTenantDiscriminatorColumns(value);
}
+ }
- public void setValue(Boolean value) {
- updateTenantDiscriminatorColumns(value.booleanValue());
+ void updateTenantDiscriminatorColumns(boolean selected) {
+ if (isPopulating()) {
+ return;
}
- private void updateTenantDiscriminatorColumns(boolean selected) {
- if (isPopulating()) {
- return;
- }
+ setPopulating(true);
- setPopulating(true);
+ try {
+ EclipseLinkMultitenancy2_3 subject = getSubject();
- try {
- EclipseLinkMultitenancy2_3 subject = getSubject();
-
- if (selected) {
- EclipseLinkSpecifiedTenantDiscriminatorColumn2_3 newTenantDiscriminatorColumn = subject.addSpecifiedTenantDiscriminatorColumn();
- newTenantDiscriminatorColumn.setSpecifiedName(EclipseLinkTenantDiscriminatorColumn2_3.DEFAULT_NAME);
- }
- // Remove all the specified tenant discriminator columns
- else {
- for (int index = subject.getSpecifiedTenantDiscriminatorColumnsSize(); --index >= 0; ) {
- subject.removeSpecifiedTenantDiscriminatorColumn(index);
- }
- }
+ if (selected) {
+ EclipseLinkSpecifiedTenantDiscriminatorColumn2_3 newTenantDiscriminatorColumn = subject.addSpecifiedTenantDiscriminatorColumn();
+ newTenantDiscriminatorColumn.setSpecifiedName(EclipseLinkTenantDiscriminatorColumn2_3.DEFAULT_NAME);
}
- finally {
- setPopulating(false);
+ // Remove all the specified tenant discriminator columns
+ else {
+ for (int index = subject.getSpecifiedTenantDiscriminatorColumnsSize(); --index >= 0; ) {
+ subject.removeSpecifiedTenantDiscriminatorColumn(index);
+ }
}
}
+ finally {
+ setPopulating(false);
+ }
}
/* CU private */ class TenantDiscriminatorColumnPaneEnablerHolder
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkTenantDiscriminatorColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkTenantDiscriminatorColumnsComposite.java
index a13430acee..c53350841f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkTenantDiscriminatorColumnsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkTenantDiscriminatorColumnsComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2011, 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.
@@ -18,7 +18,7 @@ import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.AbstractAdapter;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.Adapter;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
@@ -71,23 +71,15 @@ public class EclipseLinkTenantDiscriminatorColumnsComposite<T extends JpaModel>
protected void initialize() {
super.initialize();
this.selectedTenantDiscriminatorColumnsModel = this.buildSelectedTenantDiscriminatorColumnsModel();
- this.selectedTenantDiscriminatorColumnModel = this.buildSelectedTenantDiscriminatorColumnModel(this.selectedTenantDiscriminatorColumnsModel);
+ this.selectedTenantDiscriminatorColumnModel = this.buildSelectedTenantDiscriminatorColumnModel();
}
private ModifiableCollectionValueModel<EclipseLinkTenantDiscriminatorColumn2_3> buildSelectedTenantDiscriminatorColumnsModel() {
- return new SimpleCollectionValueModel<EclipseLinkTenantDiscriminatorColumn2_3>();
+ return new SimpleCollectionValueModel<>();
}
- private PropertyValueModel<EclipseLinkTenantDiscriminatorColumn2_3> buildSelectedTenantDiscriminatorColumnModel(CollectionValueModel<EclipseLinkTenantDiscriminatorColumn2_3> selectedTenantDiscriminatorColumnsModel) {
- return new CollectionPropertyValueModelAdapter<EclipseLinkTenantDiscriminatorColumn2_3, EclipseLinkTenantDiscriminatorColumn2_3>(selectedTenantDiscriminatorColumnsModel) {
- @Override
- protected EclipseLinkTenantDiscriminatorColumn2_3 buildValue() {
- if (this.collectionModel.size() == 1) {
- return this.collectionModel.iterator().next();
- }
- return null;
- }
- };
+ private PropertyValueModel<EclipseLinkTenantDiscriminatorColumn2_3> buildSelectedTenantDiscriminatorColumnModel() {
+ return CollectionValueModelTools.singleElementPropertyValueModel(this.selectedTenantDiscriminatorColumnsModel);
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java
index 3c781adf22..e09f683051 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2011, 2012 Oracle. All rights reserved.
+* Copyright (c) 2011, 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.
@@ -10,9 +10,10 @@
package org.eclipse.jpt.jpa.eclipselink.ui.internal.details.orm;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.ReadOnlyModifiablePropertyValueModelWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ValueListAdapter;
@@ -22,8 +23,8 @@ import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
-import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkTenantDiscriminatorColumn2_3;
import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkSpecifiedTenantDiscriminatorColumn2_3;
+import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkTenantDiscriminatorColumn2_3;
import org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkEntityMappings;
import org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkOrmSpecifiedTenantDiscriminatorColumn2_3;
import org.eclipse.jpt.jpa.eclipselink.ui.details.JptJpaEclipseLinkUiDetailsMessages;
@@ -52,7 +53,7 @@ public class EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite extend
addCheckBox(
tenantDiscriminatorColumnGroupPane,
JptJpaEclipseLinkUiDetailsMessages.ECLIPSELINK_MULTITENANCY_OVERRIDE_DEFAULT_TENANT_DISCRIMINATOR_COLUMNS,
- buildOverrideDefaultTenantDiscriminatorColumnHolder(),
+ buildOverrideDefaultTenantDiscriminatorColumnModel(),
null
);
@@ -115,11 +116,11 @@ public class EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite extend
}
}
- private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultTenantDiscriminatorColumnHolder() {
- return new OverrideDefaultTenantDiscriminatorColumnHolder();
+ private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultTenantDiscriminatorColumnModel() {
+ return ListValueModelTools.isNotEmptyModifiablePropertyValueModel(this.buildSpecifiedTenantDiscriminatorColumnsListModel(), new OverrideDefaultTenantDiscriminatorColumnModelSetValueClosure());
}
- ListValueModel<EclipseLinkTenantDiscriminatorColumn2_3> buildSpecifiedTenantDiscriminatorColumnsListHolder() {
+ ListValueModel<EclipseLinkTenantDiscriminatorColumn2_3> buildSpecifiedTenantDiscriminatorColumnsListModel() {
return new ListAspectAdapter<EntityMappings, EclipseLinkTenantDiscriminatorColumn2_3>(
getSubjectHolder(), EclipseLinkEntityMappings.SPECIFIED_TENANT_DISCRIMINATOR_COLUMNS_LIST) {
@Override
@@ -134,48 +135,38 @@ public class EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite extend
};
}
- private class OverrideDefaultTenantDiscriminatorColumnHolder
- extends ListPropertyValueModelAdapter<Boolean>
- implements ModifiablePropertyValueModel<Boolean>
+ class OverrideDefaultTenantDiscriminatorColumnModelSetValueClosure
+ implements BooleanClosure.Adapter
{
- public OverrideDefaultTenantDiscriminatorColumnHolder() {
- super(buildSpecifiedTenantDiscriminatorColumnsListHolder());
- }
-
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.listModel.size() > 0);
+ public void execute(boolean value) {
+ updateTenantDiscriminatorColumns(value);
}
+ }
- public void setValue(Boolean value) {
- updateTenantDiscriminatorColumns(value.booleanValue());
+ void updateTenantDiscriminatorColumns(boolean selected) {
+ if (isPopulating()) {
+ return;
}
- private void updateTenantDiscriminatorColumns(boolean selected) {
- if (isPopulating()) {
- return;
- }
-
- setPopulating(true);
+ setPopulating(true);
- try {
- EclipseLinkEntityMappings subject = (EclipseLinkEntityMappings) getSubject();
+ try {
+ EclipseLinkEntityMappings subject = (EclipseLinkEntityMappings) getSubject();
- if (selected) {
- EclipseLinkSpecifiedTenantDiscriminatorColumn2_3 newTenantDiscriminatorColumn = subject.addSpecifiedTenantDiscriminatorColumn();
- newTenantDiscriminatorColumn.setSpecifiedName(EclipseLinkTenantDiscriminatorColumn2_3.DEFAULT_NAME);
- }
- // Remove all the specified tenant discriminator columns
- else {
- for (int index = subject.getSpecifiedTenantDiscriminatorColumnsSize(); --index >= 0; ) {
- subject.removeSpecifiedTenantDiscriminatorColumn(index);
- }
- }
+ if (selected) {
+ EclipseLinkSpecifiedTenantDiscriminatorColumn2_3 newTenantDiscriminatorColumn = subject.addSpecifiedTenantDiscriminatorColumn();
+ newTenantDiscriminatorColumn.setSpecifiedName(EclipseLinkTenantDiscriminatorColumn2_3.DEFAULT_NAME);
}
- finally {
- setPopulating(false);
+ // Remove all the specified tenant discriminator columns
+ else {
+ for (int index = subject.getSpecifiedTenantDiscriminatorColumnsSize(); --index >= 0; ) {
+ subject.removeSpecifiedTenantDiscriminatorColumn(index);
+ }
}
}
+ finally {
+ setPopulating(false);
+ }
}
/* CU private */ class TenantDiscriminatorColumnPaneEnablerHolder
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityCachingPropertyComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityCachingPropertyComposite.java
index a2c60d059b..849650d873 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityCachingPropertyComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityCachingPropertyComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -18,7 +18,7 @@ import org.eclipse.jpt.common.ui.internal.widgets.IntegerCombo;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.ui.internal.widgets.TriStateCheckBox;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
@@ -42,7 +42,7 @@ public class EclipseLinkEntityCachingPropertyComposite
/**
* Creates a new <code>EntityCachingPropertyComposite</code>.
*
- * @param parentPane The parent container of this one
+ * @param parentComposite The parent container of this one
* @param subjectHolder The holder of this pane's subject
* @param parent The parent container
*/
@@ -60,6 +60,7 @@ public class EclipseLinkEntityCachingPropertyComposite
}
@Override
+ @SuppressWarnings("unused")
protected void initializeLayout(Composite container) {
this.addLabel(container, JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_CACHING_TAB_CACHE_TYPE_LABEL);
new CacheTypeComboViewer(container);
@@ -72,7 +73,7 @@ public class EclipseLinkEntityCachingPropertyComposite
container,
JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_CACHING_TAB_SHARED_CACHE_LABEL,
this.buildSharedCacheHolder(),
- this.buildSharedCacheStringHolder(),
+ this.buildSharedCacheStringModel(),
EclipseLinkHelpContextIds.PERSISTENCE_CACHING
);
GridData gridData = new GridData();
@@ -80,9 +81,9 @@ public class EclipseLinkEntityCachingPropertyComposite
sharedCacheCheckBox.getCheckBox().setLayoutData(gridData);
}
- private class CacheTypeComboViewer extends EnumFormComboViewer<EclipseLinkCachingEntity, EclipseLinkCacheType> {
+ class CacheTypeComboViewer extends EnumFormComboViewer<EclipseLinkCachingEntity, EclipseLinkCacheType> {
- private CacheTypeComboViewer(Composite parent) {
+ CacheTypeComboViewer(Composite parent) {
super(EclipseLinkEntityCachingPropertyComposite.this, parent);
}
@@ -95,8 +96,8 @@ public class EclipseLinkEntityCachingPropertyComposite
private PropertyValueModel<EclipseLinkCaching> buildCachingHolder() {
return new TransformationPropertyValueModel<EclipseLinkCachingEntity, EclipseLinkCaching>(getSubjectHolder()) {
@Override
- protected EclipseLinkCaching transform_(EclipseLinkCachingEntity value) {
- return value.getParent();
+ protected EclipseLinkCaching transform_(EclipseLinkCachingEntity entity) {
+ return entity.getParent();
}
};
}
@@ -105,9 +106,9 @@ public class EclipseLinkEntityCachingPropertyComposite
return new PropertyAspectAdapter<EclipseLinkCaching, EclipseLinkCacheType>(buildCachingHolder(), EclipseLinkCaching.CACHE_TYPE_DEFAULT_PROPERTY) {
@Override
protected EclipseLinkCacheType buildValue_() {
- EclipseLinkCacheType cacheType = subject.getCacheTypeDefault();
+ EclipseLinkCacheType cacheType = this.subject.getCacheTypeDefault();
if (cacheType == null) {
- cacheType = subject.getDefaultCacheTypeDefault();
+ cacheType = this.subject.getDefaultCacheTypeDefault();
}
return cacheType;
}
@@ -199,14 +200,15 @@ public class EclipseLinkEntityCachingPropertyComposite
}
}
- private String getSubjectName() {
+ String getSubjectName() {
return this.getSubjectHolder().getValue().getName();
}
- private EclipseLinkCaching getSubjectParent() {
+ EclipseLinkCaching getSubjectParent() {
return this.getSubjectHolder().getValue().getParent();
}
+ @SuppressWarnings("unused")
private void addCacheSizeCombo(Composite container) {
new IntegerCombo<EclipseLinkCachingEntity>(this, container) {
@Override
@@ -218,11 +220,11 @@ public class EclipseLinkEntityCachingPropertyComposite
return new PropertyAspectAdapter<EclipseLinkCaching, Integer>(buildCachingHolder(), EclipseLinkCaching.CACHE_SIZE_DEFAULT_PROPERTY) {
@Override
protected Integer buildValue_() {
- Integer value = this.subject.getCacheSizeDefault();
- if (value == null) {
- value = this.subject.getDefaultCacheSizeDefault();
+ Integer size = this.subject.getCacheSizeDefault();
+ if (size == null) {
+ size = this.subject.getDefaultCacheSizeDefault();
}
- return value;
+ return size;
}
};
}
@@ -244,11 +246,11 @@ public class EclipseLinkEntityCachingPropertyComposite
};
}
- private PropertyValueModel<EclipseLinkCaching> buildCachingHolder() {
+ PropertyValueModel<EclipseLinkCaching> buildCachingHolder() {
return new TransformationPropertyValueModel<EclipseLinkCachingEntity, EclipseLinkCaching>(this.getSubjectHolder()) {
@Override
- protected EclipseLinkCaching transform_(EclipseLinkCachingEntity value) {
- return value.getParent();
+ protected EclipseLinkCaching transform_(EclipseLinkCachingEntity entity) {
+ return entity.getParent();
}
};
}
@@ -268,12 +270,12 @@ public class EclipseLinkEntityCachingPropertyComposite
};
}
- private PropertyValueModel<String> buildSharedCacheStringHolder() {
- return new TransformationPropertyValueModel<Boolean, String>(buildDefaultAndNonDefaultSharedCacheHolder()) {
+ private PropertyValueModel<String> buildSharedCacheStringModel() {
+ return new TransformationPropertyValueModel<Boolean, String>(buildDefaultAndNonDefaultSharedCacheModel()) {
@Override
- protected String transform(Boolean value) {
- if (value != null) {
- String defaultStringValue = value.booleanValue() ? JptCommonUiMessages.BOOLEAN_TRUE : JptCommonUiMessages.BOOLEAN_FALSE;
+ protected String transform(Boolean b) {
+ if (b != null) {
+ String defaultStringValue = b.booleanValue() ? JptCommonUiMessages.BOOLEAN_TRUE : JptCommonUiMessages.BOOLEAN_FALSE;
return NLS.bind(JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_CACHING_TAB_DEFAULT_SHARED_CACHE_LABEL, defaultStringValue);
}
return JptJpaEclipseLinkUiMessages.PERSISTENCE_XML_CACHING_TAB_SHARED_CACHE_LABEL;
@@ -281,38 +283,28 @@ public class EclipseLinkEntityCachingPropertyComposite
};
}
- private PropertyValueModel<Boolean> buildDefaultAndNonDefaultSharedCacheHolder() {
- return new ListPropertyValueModelAdapter<Boolean>(
- buildDefaultAndNonDefaultSharedCacheListHolder()
- ) {
- @Override
- protected Boolean buildValue() {
- // If the number of ListValueModel equals 1, that means the shared
- // Cache properties is not set (partially selected), which means we
- // want to see the default value appended to the text
- if (this.listModel.size() == 1) {
- return (Boolean) this.listModel.listIterator().next();
- }
- return null;
- }
- };
+ private PropertyValueModel<Boolean> buildDefaultAndNonDefaultSharedCacheModel() {
+ // If the size of ListValueModel equals 1, that means the shared
+ // Cache properties is not set (partially selected), which means we
+ // want to see the default value appended to the text
+ return ListValueModelTools.singleElementPropertyValueModel(this.buildDefaultAndNonDefaultSharedCacheListModel());
}
- private ListValueModel<Boolean> buildDefaultAndNonDefaultSharedCacheListHolder() {
- ArrayList<ListValueModel<Boolean>> holders = new ArrayList<ListValueModel<Boolean>>(2);
+ private ListValueModel<Boolean> buildDefaultAndNonDefaultSharedCacheListModel() {
+ ArrayList<ListValueModel<Boolean>> holders = new ArrayList<>(2);
holders.add(buildSharedCacheListHolder());
holders.add(buildDefaultSharedCacheListHolder());
return CompositeListValueModel.forModels(holders);
}
private ListValueModel<Boolean> buildSharedCacheListHolder() {
- return new PropertyListValueModelAdapter<Boolean>(
+ return new PropertyListValueModelAdapter<>(
buildSharedCacheHolder()
);
}
private ListValueModel<Boolean> buildDefaultSharedCacheListHolder() {
- return new PropertyListValueModelAdapter<Boolean>(
+ return new PropertyListValueModelAdapter<>(
buildDefaultSharedCacheHolder()
);
}
@@ -321,11 +313,11 @@ public class EclipseLinkEntityCachingPropertyComposite
return new PropertyAspectAdapter<EclipseLinkCaching, Boolean>(buildCachingHolder(), EclipseLinkCaching.SHARED_CACHE_DEFAULT_PROPERTY) {
@Override
protected Boolean buildValue_() {
- Boolean value = this.subject.getSharedCacheDefault();
- if (value == null) {
- value = this.subject.getDefaultSharedCacheDefault();
+ Boolean b = this.subject.getSharedCacheDefault();
+ if (b == null) {
+ b = this.subject.getDefaultSharedCacheDefault();
}
- return value;
+ return b;
}
};
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityListComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityListComposite.java
index 6d37098088..a51ad39bdf 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityListComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/EclipseLinkEntityListComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,7 +22,7 @@ import org.eclipse.jface.window.Window;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.StringTools;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
@@ -58,23 +58,15 @@ public class EclipseLinkEntityListComposite<T extends EclipseLinkCaching>
protected void initialize() {
super.initialize();
this.selectedEntitiesModel = this.buildSelectedEntitiesModel();
- this.selectedEntityModel = this.buildSelectedEntityModel(this.selectedEntitiesModel);
+ this.selectedEntityModel = this.buildSelectedEntityModel();
}
private ModifiableCollectionValueModel<EclipseLinkCachingEntity> buildSelectedEntitiesModel() {
- return new SimpleCollectionValueModel<EclipseLinkCachingEntity>();
+ return new SimpleCollectionValueModel<>();
}
- private PropertyValueModel<EclipseLinkCachingEntity> buildSelectedEntityModel(CollectionValueModel<EclipseLinkCachingEntity> selectedEntitiesModel) {
- return new CollectionPropertyValueModelAdapter<EclipseLinkCachingEntity, EclipseLinkCachingEntity>(selectedEntitiesModel) {
- @Override
- protected EclipseLinkCachingEntity buildValue() {
- if (this.collectionModel.size() == 1) {
- return this.collectionModel.iterator().next();
- }
- return null;
- }
- };
+ private PropertyValueModel<EclipseLinkCachingEntity> buildSelectedEntityModel() {
+ return CollectionValueModelTools.singleElementPropertyValueModel(this.selectedEntitiesModel);
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/customization/EclipseLinkEntityListComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/customization/EclipseLinkEntityListComposite.java
index c26da814c7..2a6b139db7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/customization/EclipseLinkEntityListComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/customization/EclipseLinkEntityListComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,7 +23,7 @@ import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.ClassChooserPane;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.StringTools;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
@@ -64,23 +64,15 @@ public class EclipseLinkEntityListComposite
protected void initialize() {
super.initialize();
this.selectedEntitiesModel = this.buildSelectedEntitiesModel();
- this.selectedEntityModel = this.buildSelectedEntityModel(this.selectedEntitiesModel);
+ this.selectedEntityModel = this.buildSelectedEntityModel();
}
private ModifiableCollectionValueModel<EclipseLinkCustomizationEntity> buildSelectedEntitiesModel() {
- return new SimpleCollectionValueModel<EclipseLinkCustomizationEntity>();
+ return new SimpleCollectionValueModel<>();
}
- private PropertyValueModel<EclipseLinkCustomizationEntity> buildSelectedEntityModel(CollectionValueModel<EclipseLinkCustomizationEntity> selectedEntitiesModel) {
- return new CollectionPropertyValueModelAdapter<EclipseLinkCustomizationEntity, EclipseLinkCustomizationEntity>(selectedEntitiesModel) {
- @Override
- protected EclipseLinkCustomizationEntity buildValue() {
- if (this.collectionModel.size() == 1) {
- return this.collectionModel.iterator().next();
- }
- return null;
- }
- };
+ private PropertyValueModel<EclipseLinkCustomizationEntity> buildSelectedEntityModel() {
+ return CollectionValueModelTools.singleElementPropertyValueModel(this.selectedEntitiesModel);
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java
index 8ad990cb48..62c8ccbe77 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Oracle. All rights reserved.
+ * 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.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui;
-import org.eclipse.core.resources.IFile;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaFile;
@@ -27,8 +26,5 @@ import org.eclipse.jpt.jpa.core.JpaFile;
public interface JpaFileModel
extends PropertyValueModel<JpaFile>
{
- /**
- * Return the file corresponding to the JPA file model.
- */
- IFile getFile();
+ // simply an interface we can use in an adapter definition
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java
index af63d17873..af46b3cd2c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Oracle. All rights reserved.
+ * 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.
@@ -9,7 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui;
-import org.eclipse.core.resources.IProject;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaProject;
@@ -26,8 +25,5 @@ import org.eclipse.jpt.jpa.core.JpaProject;
public interface JpaProjectModel
extends PropertyValueModel<JpaProject>
{
- /**
- * Return the project corresponding to the JPA project model.
- */
- IProject getProject();
+ // simply an interface we can use in an adapter definition
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java
index f224ffb44f..7523879f76 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -10,12 +10,12 @@
package org.eclipse.jpt.jpa.ui.internal;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ElementPropertyValueModelAdapter;
-import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+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;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
@@ -43,30 +43,61 @@ public class FileAdapterFactory
return ADAPTER_LIST;
}
- public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adaptableObject instanceof IFile) {
return this.getAdapter((IFile) adaptableObject, adapterType);
}
return null;
}
- private Object getAdapter(IFile file, Class<?> adapterType) {
+ @SuppressWarnings("unchecked")
+ private <T> T getAdapter(IFile file, Class<T> adapterType) {
if (adapterType == JpaFileModel.class) {
- return this.getJpaFileModel(file);
+ return (T) this.getJpaFileModel(file);
}
return null;
}
private JpaFileModel getJpaFileModel(IFile file) {
- return new JpaFileModelAdapter(this.buildJpaFilesModel(file.getProject()), file);
+ return new LocalJpaFileModel(file);
}
- private CollectionValueModel<JpaFile> buildJpaFilesModel(IProject project) {
- return new JpaFilesModel(this.getJpaProjectModel(project));
- }
- private JpaProjectModel getJpaProjectModel(IProject project) {
- return (JpaProjectModel) project.getAdapter(JpaProjectModel.class);
+ // ********** JPA file model **********
+
+ /**
+ * Implement a property value model for the JPA file corresponding to a
+ * {@link IFile file}. The model will fire change events when the
+ * corresponding JPA file is added or removed from the JPA project
+ * or when the JPA project is created or destroyed.
+ * This is useful for UI code that does not want to wait to
+ * retrieve a JPA file but wants to be notified when it is available.
+ * <p>
+ * Subclass {@link PluggablePropertyValueModel} so we can
+ * implement {@link org.eclipse.jpt.jpa.ui.JpaFileModel}.
+ *
+ * @see JpaProjectModel
+ */
+ /* CU private */ static class LocalJpaFileModel
+ extends PluggablePropertyValueModel<JpaFile>
+ implements JpaFileModel
+ {
+ /**
+ * Get the JPA project corresponding to the file's project,
+ * then get that JPA project's JPA files, then filter down to those corresponding
+ * to the specified file, then get the single JPA file remaining.
+ * (At least we hope there is only a single JPA file remaining.)
+ */
+ LocalJpaFileModel(IFile file) {
+ super(new CollectionPluggablePropertyValueModelAdapter.Factory<>(
+ CollectionValueModelTools.filter(
+ new JpaFilesModel(file.getProject().getAdapter(JpaProjectModel.class)),
+ new JpaFile.FileEquals(file)
+ ),
+ TransformerTools.collectionSingleElementTransformer()
+ )
+ );
+ }
}
@@ -93,33 +124,4 @@ public class FileAdapterFactory
return this.subject.getJpaFilesSize();
}
}
-
-
- // ********** JPA file model **********
-
- /**
- * Implement a property value model for the JPA file corresponding to a
- * {@link IFile file}. The model will fire change events when the
- * corresponding JPA file is added or removed from the JPA project
- * or when the JPA project is created or destroyed.
- * This is useful for UI code that does not want to wait to
- * retrieve a JPA file but wants to be notified when it is available.
- * <p>
- * Subclass {@link ElementPropertyValueModelAdapter} so we can
- * implement {@link org.eclipse.jpt.jpa.ui.JpaFileModel}.
- *
- * @see JpaProjectModel
- */
- /* CU private */ static class JpaFileModelAdapter
- extends ElementPropertyValueModelAdapter<JpaFile>
- implements JpaFileModel
- {
- JpaFileModelAdapter(CollectionValueModel<JpaFile> jpaFilesModel, IFile file) {
- super(jpaFilesModel, new JpaFile.FileEquals(file));
- }
-
- public IFile getFile() {
- return ((JpaFile.FileEquals) this.predicate).getCriterion();
- }
- }
}
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 10e78f1c82..4f9425a204 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 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.
@@ -10,10 +10,11 @@
package org.eclipse.jpt.jpa.ui.internal;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.jpt.common.utility.internal.model.value.ElementPropertyValueModelAdapter;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+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;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.ui.JpaProjectModel;
import org.eclipse.jpt.jpa.ui.JpaProjectsModel;
@@ -21,9 +22,9 @@ import org.eclipse.jpt.jpa.ui.JpaProjectsModel;
/**
* Factory to build Dali JPA adapters for an {@link IProject}:<ul>
* <li>{@link org.eclipse.jpt.jpa.ui.JpaProjectModel JpaProjectModel} -
- * This adapter will only return a JPA project if it is immediately
+ * This adapter will return a JPA project only if it is immediately
* available; but it will also notify listeners if the JPA project is
- * ever created.
+ * ever created.<br>
* This adapter should be used by any process that can temporarily ignore
* any uncreated JPA projects but should be notified if the JPA project
* <em>is</em> ever created (e.g. UI views).
@@ -41,26 +42,23 @@ public class ProjectAdapterFactory
return ADAPTER_LIST;
}
- public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adaptableObject instanceof IProject) {
return this.getAdapter((IProject) adaptableObject, adapterType);
}
return null;
}
- private Object getAdapter(IProject project, Class<?> adapterType) {
+ @SuppressWarnings("unchecked")
+ private <T> T getAdapter(IProject project, Class<T> adapterType) {
if (adapterType == JpaProjectModel.class) {
- return this.getJpaProjectModel(project);
+ return (T) this.getJpaProjectModel(project);
}
return null;
}
private JpaProjectModel getJpaProjectModel(IProject project) {
- return new JpaProjectModelAdapter(this.getJpaProjectsModel(project.getWorkspace()), project);
- }
-
- private JpaProjectsModel getJpaProjectsModel(IWorkspace workspace) {
- return (JpaProjectsModel) workspace.getAdapter(JpaProjectsModel.class);
+ return new LocalJpaProjectModel(project);
}
@@ -73,7 +71,7 @@ public class ProjectAdapterFactory
* manager. This is useful for UI code that does not want to wait to
* retrieve a JPA project but wants to be notified when it is available.
* <p>
- * Subclass {@link ElementPropertyValueModelAdapter} so we can
+ * Subclass {@link PluggablePropertyValueModel} so we can
* implement {@link org.eclipse.jpt.jpa.ui.JpaProjectModel}.
* <p>
* <strong>NB:</strong> This model operates outside of all the other
@@ -81,16 +79,24 @@ public class ProjectAdapterFactory
* since it will be kept synchronized with the JPA manager's collection of
* JPA projects in the end.
*/
- /* CU private */ static class JpaProjectModelAdapter
- extends ElementPropertyValueModelAdapter<JpaProject>
+ /* CU private */ static class LocalJpaProjectModel
+ extends PluggablePropertyValueModel<JpaProject>
implements JpaProjectModel
{
- JpaProjectModelAdapter(CollectionValueModel<JpaProject> jpaProjectsModel, IProject project) {
- super(jpaProjectsModel, new JpaProject.ProjectEquals(project));
- }
-
- public IProject getProject() {
- return ((JpaProject.ProjectEquals) this.predicate).getCriterion();
+ /**
+ * Get all the JPA projects, then filter down to those corresponding
+ * to the specified project, then get the single JPA project remaining.
+ * (At least we hope there is only a single JPA project remaining.)
+ */
+ LocalJpaProjectModel(IProject project) {
+ super(new CollectionPluggablePropertyValueModelAdapter.Factory<>(
+ CollectionValueModelTools.filter(
+ project.getWorkspace().getAdapter(JpaProjectsModel.class),
+ new JpaProject.ProjectEquals(project)
+ ),
+ TransformerTools.collectionSingleElementTransformer()
+ )
+ );
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java
index 714dde7c72..c9d3440ad5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2006, 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.
@@ -17,11 +17,12 @@ import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.AbstractAdapter;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.Adapter;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.iterable.ListIterable;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
@@ -29,11 +30,11 @@ import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiableCollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.Entity;
-import org.eclipse.jpt.jpa.core.context.SpecifiedPrimaryKeyJoinColumn;
import org.eclipse.jpt.jpa.core.context.BaseJoinColumn;
+import org.eclipse.jpt.jpa.core.context.Entity;
import org.eclipse.jpt.jpa.core.context.NamedColumn;
import org.eclipse.jpt.jpa.core.context.PrimaryKeyJoinColumn;
+import org.eclipse.jpt.jpa.core.context.SpecifiedPrimaryKeyJoinColumn;
import org.eclipse.jpt.jpa.ui.details.JptJpaUiDetailsMessages;
import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds;
import org.eclipse.osgi.util.NLS;
@@ -63,10 +64,10 @@ public abstract class AbstractPrimaryKeyJoinColumnsComposite<T extends Entity>
return dialog.wasConfirmed() ? this.addJoinColumn(dialog.getSubject()) : null;
}
- protected abstract ListValueModel<? extends PrimaryKeyJoinColumn> buildDefaultJoinColumnsListHolder();
+ protected abstract ListValueModel<? extends PrimaryKeyJoinColumn> buildDefaultJoinColumnsListModel();
private ModifiableCollectionValueModel<SpecifiedPrimaryKeyJoinColumn> buildSelectedJoinColumnsModel() {
- return new SimpleCollectionValueModel<SpecifiedPrimaryKeyJoinColumn>();
+ return new SimpleCollectionValueModel<>();
}
String buildJoinColumnLabel(PrimaryKeyJoinColumn joinColumn) {
@@ -152,20 +153,20 @@ public abstract class AbstractPrimaryKeyJoinColumnsComposite<T extends Entity>
};
}
- private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() {
- return new OverrideDefaultPrimaryKeyJoinColumnHolder();
+ private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultPrimaryKeyJoinColumnModel() {
+ return ListValueModelTools.isNotEmptyModifiablePropertyValueModel(this.buildSpecifiedJoinColumnsListModel(), new OverrideDefaultPrimaryKeyJoinColumnModelSetValueClosure());
}
- private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListHolder() {
- List<ListValueModel<? extends PrimaryKeyJoinColumn>> list = new ArrayList<ListValueModel<? extends PrimaryKeyJoinColumn>>();
- list.add(buildSpecifiedJoinColumnsListHolder());
- list.add(buildDefaultJoinColumnsListHolder());
+ private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListModel() {
+ List<ListValueModel<? extends PrimaryKeyJoinColumn>> list = new ArrayList<>();
+ list.add(buildSpecifiedJoinColumnsListModel());
+ list.add(buildDefaultJoinColumnsListModel());
return CompositeListValueModel.forModels(list);
}
- private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListModel() {
- return new ItemPropertyListValueModelAdapter<PrimaryKeyJoinColumn>(
- buildPrimaryKeyJoinColumnsListHolder(),
+ private ListValueModel<PrimaryKeyJoinColumn> buildUIPrimaryKeyJoinColumnsListModel() {
+ return new ItemPropertyListValueModelAdapter<>(
+ buildPrimaryKeyJoinColumnsListModel(),
NamedColumn.SPECIFIED_NAME_PROPERTY,
NamedColumn.DEFAULT_NAME_PROPERTY,
BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY,
@@ -173,16 +174,16 @@ public abstract class AbstractPrimaryKeyJoinColumnsComposite<T extends Entity>
);
}
- ListValueModel<SpecifiedPrimaryKeyJoinColumn> buildSpecifiedJoinColumnsListHolder() {
+ ListValueModel<SpecifiedPrimaryKeyJoinColumn> buildSpecifiedJoinColumnsListModel() {
return new ListAspectAdapter<Entity, SpecifiedPrimaryKeyJoinColumn>(getSubjectHolder(), Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) {
@Override
protected ListIterable<SpecifiedPrimaryKeyJoinColumn> getListIterable() {
- return new SuperListIterableWrapper<SpecifiedPrimaryKeyJoinColumn>(subject.getSpecifiedPrimaryKeyJoinColumns());
+ return new SuperListIterableWrapper<>(this.subject.getSpecifiedPrimaryKeyJoinColumns());
}
@Override
protected int size_() {
- return subject.getSpecifiedPrimaryKeyJoinColumnsSize();
+ return this.subject.getSpecifiedPrimaryKeyJoinColumnsSize();
}
};
}
@@ -223,7 +224,7 @@ public abstract class AbstractPrimaryKeyJoinColumnsComposite<T extends Entity>
addCheckBox(
container,
JptJpaUiDetailsMessages.PRIMARY_KEY_JOIN_COLUMNS_COMPOSITE_OVERRIDE_DEFAULT_PRIMARY_KEY_JOIN_COLUMNS,
- buildOverrideDefaultJoinColumnHolder(),
+ buildOverrideDefaultPrimaryKeyJoinColumnModel(),
null
);
// Primary Key Join Columns list pane
@@ -231,10 +232,10 @@ public abstract class AbstractPrimaryKeyJoinColumnsComposite<T extends Entity>
this,
container,
buildJoinColumnsAdapter(),
- buildPrimaryKeyJoinColumnsListModel(),
+ buildUIPrimaryKeyJoinColumnsListModel(),
this.selectedPkJoinColumnsModel,
buildJoinColumnsListLabelProvider(),
- buildOverrideDefaultJoinColumnHolder(),
+ buildOverrideDefaultPrimaryKeyJoinColumnModel(),
JpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS
);
}
@@ -257,20 +258,11 @@ public abstract class AbstractPrimaryKeyJoinColumnsComposite<T extends Entity>
}
}
- private class OverrideDefaultPrimaryKeyJoinColumnHolder extends ListPropertyValueModelAdapter<Boolean>
- implements ModifiablePropertyValueModel<Boolean> {
-
- public OverrideDefaultPrimaryKeyJoinColumnHolder() {
- super(buildSpecifiedJoinColumnsListHolder());
- }
-
- @Override
- protected Boolean buildValue() {
- return listModel.size() > 0;
- }
-
- public void setValue(Boolean value) {
- updatePrimaryKeyJoinColumns(value.booleanValue());
+ class OverrideDefaultPrimaryKeyJoinColumnModelSetValueClosure
+ implements BooleanClosure.Adapter
+ {
+ public void execute(boolean value) {
+ updatePrimaryKeyJoinColumns(value);
}
}
-} \ No newline at end of file
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractSecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractSecondaryTablesComposite.java
index 03e8bb71eb..0e724e8d9f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractSecondaryTablesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractSecondaryTablesComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,14 +9,16 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.details;
+import java.util.Collection;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window;
-import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.AbstractAdapter;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
+import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.AbstractAdapter;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiableCollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -80,19 +82,11 @@ public abstract class AbstractSecondaryTablesComposite<T extends Entity> extends
}
protected ModifiableCollectionValueModel<SpecifiedSecondaryTable> buildSelectedSecondaryTablesModel() {
- return new SimpleCollectionValueModel<SpecifiedSecondaryTable>();
+ return new SimpleCollectionValueModel<>();
}
protected PropertyValueModel<SpecifiedSecondaryTable> buildSelectedSecondaryTableModel(CollectionValueModel<SpecifiedSecondaryTable> selectedSecondaryTablesModel) {
- return new CollectionPropertyValueModelAdapter<SpecifiedSecondaryTable, SpecifiedSecondaryTable>(selectedSecondaryTablesModel) {
- @Override
- protected SpecifiedSecondaryTable buildValue() {
- if (this.collectionModel.size() == 1) {
- return this.collectionModel.iterator().next();
- }
- return null;
- }
- };
+ return CollectionValueModelTools.singleElementPropertyValueModel(selectedSecondaryTablesModel);
}
protected ILabelProvider buildSecondaryTableLabelProvider() {
@@ -155,16 +149,16 @@ public abstract class AbstractSecondaryTablesComposite<T extends Entity> extends
@Override
public PropertyValueModel<Boolean> buildOptionalButtonEnabledModel(CollectionValueModel<SpecifiedSecondaryTable> selectedItemsModel) {
- return new CollectionPropertyValueModelAdapter<Boolean, SpecifiedSecondaryTable>(selectedItemsModel) {
+ return CollectionValueModelTools.propertyValueModel(selectedItemsModel, new TransformerAdapter<Collection<SpecifiedSecondaryTable>, Boolean>() {
@Override
- protected Boolean buildValue() {
- if (this.collectionModel.size() == 1) {
- SpecifiedSecondaryTable secondaryTable = this.collectionModel.iterator().next();
- return Boolean.valueOf(!secondaryTable.isVirtual());
- }
- return Boolean.FALSE;
+ public Boolean transform(Collection<SpecifiedSecondaryTable> collection) {
+ return Boolean.valueOf(this.transform_(collection));
+ }
+ private boolean transform_(Collection<SpecifiedSecondaryTable> collection) {
+ return (collection.size() == 1) &&
+ ! collection.iterator().next().isVirtual();
}
- };
+ });
}
};
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/IdMappingGenerationComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/IdMappingGenerationComposite.java
index de756d663a..6f02c7fa9f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/IdMappingGenerationComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/IdMappingGenerationComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -15,8 +15,8 @@ import org.eclipse.jpt.common.ui.internal.widgets.EnumFormComboViewer;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.FilteringCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SetCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
@@ -499,7 +499,7 @@ public class IdMappingGenerationComposite extends Pane<IdMapping>
}
protected CollectionValueModel<String> buildGeneratorNamesModel() {
- return new FilteringCollectionValueModel<String>(this.buildGeneratorNamesModel_(), StringTools.IS_NOT_BLANK);
+ return ListValueModelTools.filter(this.buildGeneratorNamesModel_(), StringTools.IS_NOT_BLANK);
}
protected ListValueModel<String> buildGeneratorNamesModel_() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java
index 146217b804..1fc6a94dcb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 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.
@@ -10,9 +10,10 @@
package org.eclipse.jpt.jpa.ui.internal.details;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.ReadOnlyModifiablePropertyValueModelWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ValueListAdapter;
@@ -23,23 +24,20 @@ import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
-import org.eclipse.jpt.jpa.core.context.SpecifiedJoinTable;
import org.eclipse.jpt.jpa.core.context.JoinColumn;
import org.eclipse.jpt.jpa.core.context.JoinTable;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinTable;
import org.eclipse.jpt.jpa.ui.details.JptJpaUiDetailsMessages;
import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds;
import org.eclipse.jpt.jpa.ui.internal.details.JoinColumnsComposite.JoinColumnsEditor;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
public class JoinTableComposite
extends ReferenceTableComposite<JoinTable>
{
- private Button overrideDefaultInverseJoinColumnsCheckBox;
-
private JoinColumnsComposite<JoinTable> inverseJoinColumnsComposite;
@@ -85,10 +83,10 @@ public class JoinTableComposite
joinColumnGroupPane.setLayoutData(gridData);
// Override Default Join Columns check box
- this.overrideDefaultJoinColumnsCheckBox = addCheckBox(
+ addCheckBox(
joinColumnGroupPane,
JptJpaUiDetailsMessages.JOIN_TABLE_COMPOSITE_OVERRIDE_DEFAULT_JOIN_COLUMNS,
- buildOverrideDefaultJoinColumnHolder(),
+ buildOverrideDefaultJoinColumnModel(),
null
);
@@ -109,10 +107,10 @@ public class JoinTableComposite
inverseJoinColumnGroupPane.setLayoutData(gridData);
// Override Default Inverse Join Columns check box
- this.overrideDefaultInverseJoinColumnsCheckBox = addCheckBox(
+ addCheckBox(
inverseJoinColumnGroupPane,
JptJpaUiDetailsMessages.JOIN_TABLE_COMPOSITE_OVERRIDE_DEFAULT_INVERSE_JOIN_COLUMNS,
- buildOverrideDefaultInverseJoinColumnHolder(),
+ buildOverrideDefaultInverseJoinColumnModel(),
null
);
@@ -154,11 +152,11 @@ public class JoinTableComposite
return new InverseJoinColumnsProvider();
}
- private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultInverseJoinColumnHolder() {
- return new OverrideDefaultInverseJoinColumnHolder();
+ private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultInverseJoinColumnModel() {
+ return ListValueModelTools.isNotEmptyModifiablePropertyValueModel(this.buildSpecifiedInverseJoinColumnsListModel(), new OverrideDefaultInverseJoinColumnModelSetValueClosure());
}
- ListValueModel<JoinColumn> buildSpecifiedInverseJoinColumnsListHolder() {
+ ListValueModel<JoinColumn> buildSpecifiedInverseJoinColumnsListModel() {
return new ListAspectAdapter<JoinTable, JoinColumn>(getSubjectHolder(), JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST) {
@Override
protected ListIterable<JoinColumn> getListIterable() {
@@ -189,7 +187,7 @@ public class JoinTableComposite
}
}
- void updateInverseJoinColumns() {
+ void updateInverseJoinColumns(boolean selected) {
if (this.isPopulating()) {
return;
}
@@ -199,7 +197,6 @@ public class JoinTableComposite
return;
}
- boolean selected = this.overrideDefaultInverseJoinColumnsCheckBox.getSelection();
this.setPopulating(true);
try {
@@ -255,20 +252,11 @@ public class JoinTableComposite
}
}
- private class OverrideDefaultInverseJoinColumnHolder extends ListPropertyValueModelAdapter<Boolean>
- implements ModifiablePropertyValueModel<Boolean> {
-
- public OverrideDefaultInverseJoinColumnHolder() {
- super(buildSpecifiedInverseJoinColumnsListHolder());
- }
-
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.listModel.size() > 0);
- }
-
- public void setValue(Boolean value) {
- updateInverseJoinColumns();
+ class OverrideDefaultInverseJoinColumnModelSetValueClosure
+ implements BooleanClosure.Adapter
+ {
+ public void execute(boolean value) {
+ updateInverseJoinColumns(value);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java
index ebe252c502..e5cc98807b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 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.
@@ -10,18 +10,18 @@
package org.eclipse.jpt.jpa.ui.internal.details;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.iterable.ListIterable;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
-import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumnRelationship;
-import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumnRelationshipStrategy;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.JoinColumn;
import org.eclipse.jpt.jpa.core.context.JoinColumnRelationshipStrategy;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumnRelationshipStrategy;
import org.eclipse.jpt.jpa.ui.details.JptJpaUiDetailsMessages;
import org.eclipse.swt.widgets.Composite;
@@ -45,7 +45,7 @@ public class JoiningStrategyJoinColumnsWithOverrideOptionComposite
addCheckBox(
container,
JptJpaUiDetailsMessages.JOINING_STRATEGY_JOIN_COLUMNS_COMPOSITE_OVERRIDE_DEFAULT_JOIN_COLUMNS,
- buildOverrideDefaultJoinColumnHolder(),
+ buildOverrideDefaultJoinColumnModel(),
null
);
@@ -56,11 +56,11 @@ public class JoiningStrategyJoinColumnsWithOverrideOptionComposite
this.joiningStrategyComposite.setSelectedJoinColumn(joinColumn);
}
- private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() {
- return new OverrideDefaultJoinColumnHolder();
+ private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnModel() {
+ return ListValueModelTools.isNotEmptyModifiablePropertyValueModel(this.buildSpecifiedJoinColumnsListModel(), new OverrideDefaultJoinColumnModelSetValueClosure());
}
- ListValueModel<JoinColumn> buildSpecifiedJoinColumnsListHolder() {
+ ListValueModel<JoinColumn> buildSpecifiedJoinColumnsListModel() {
return new ListAspectAdapter<JoinColumnRelationshipStrategy, JoinColumn>(
getSubjectHolder(), JoinColumnRelationshipStrategy.SPECIFIED_JOIN_COLUMNS_LIST) {
@Override
@@ -75,45 +75,35 @@ public class JoiningStrategyJoinColumnsWithOverrideOptionComposite
};
}
- private class OverrideDefaultJoinColumnHolder
- extends ListPropertyValueModelAdapter<Boolean>
- implements ModifiablePropertyValueModel<Boolean>
+ class OverrideDefaultJoinColumnModelSetValueClosure
+ implements BooleanClosure.Adapter
{
- public OverrideDefaultJoinColumnHolder() {
- super(buildSpecifiedJoinColumnsListHolder());
+ public void execute(boolean value) {
+ updateJoinColumns(value);
}
-
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.listModel.size() > 0);
+ }
+
+ void updateJoinColumns(boolean selected) {
+ if (isPopulating()) {
+ return;
}
- public void setValue(Boolean value) {
- updateJoinColumns(value.booleanValue());
- }
+ setPopulating(true);
- private void updateJoinColumns(boolean selected) {
- if (isPopulating()) {
- return;
- }
-
- setPopulating(true);
-
- try {
- SpecifiedJoinColumnRelationshipStrategy subject = (SpecifiedJoinColumnRelationshipStrategy) getSubject();
- if (selected) {
- if (subject.getDefaultJoinColumn() != null) {//TODO can this be null, disable override default check box? or have it checked if there are not default join columns?
- subject.convertDefaultJoinColumnsToSpecified();
- JoiningStrategyJoinColumnsWithOverrideOptionComposite.this.setSelectedJoinColumn(subject.getSpecifiedJoinColumn(0));
- }
- }
- else {
- subject.clearSpecifiedJoinColumns();
+ try {
+ SpecifiedJoinColumnRelationshipStrategy subject = (SpecifiedJoinColumnRelationshipStrategy) getSubject();
+ if (selected) {
+ if (subject.getDefaultJoinColumn() != null) {//TODO can this be null, disable override default check box? or have it checked if there are not default join columns?
+ subject.convertDefaultJoinColumnsToSpecified();
+ JoiningStrategyJoinColumnsWithOverrideOptionComposite.this.setSelectedJoinColumn(subject.getSpecifiedJoinColumn(0));
}
}
- finally {
- setPopulating(false);
+ else {
+ subject.clearSpecifiedJoinColumns();
}
}
+ finally {
+ setPopulating(false);
+ }
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java
index d44abc3359..2bd39ada4d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,33 +10,40 @@
package org.eclipse.jpt.jpa.ui.internal.details;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
+import org.eclipse.jpt.common.utility.closure.Closure;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
+import org.eclipse.jpt.common.utility.internal.closure.ClosureTools;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
import org.eclipse.jpt.common.utility.iterable.ListIterable;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiableCollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.SpecifiedBaseJoinColumn;
-import org.eclipse.jpt.jpa.core.context.SpecifiedPrimaryKeyJoinColumn;
import org.eclipse.jpt.jpa.core.context.BaseJoinColumn;
import org.eclipse.jpt.jpa.core.context.NamedColumn;
import org.eclipse.jpt.jpa.core.context.PrimaryKeyJoinColumn;
import org.eclipse.jpt.jpa.core.context.SecondaryTable;
+import org.eclipse.jpt.jpa.core.context.SpecifiedBaseJoinColumn;
+import org.eclipse.jpt.jpa.core.context.SpecifiedPrimaryKeyJoinColumn;
import org.eclipse.jpt.jpa.core.context.SpecifiedSecondaryTable;
import org.eclipse.jpt.jpa.ui.details.JptJpaUiDetailsMessages;
import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds;
@@ -97,7 +104,7 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite
};
}
- private ListValueModel<PrimaryKeyJoinColumn> buildDefaultJoinColumnListHolder() {
+ private ListValueModel<PrimaryKeyJoinColumn> buildDefaultPrimaryKeyJoinColumnListModel() {
return new PropertyListValueModelAdapter<PrimaryKeyJoinColumn>(
buildDefaultJoinColumnHolder()
);
@@ -154,8 +161,13 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite
};
}
- private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() {
- return new OverrideDefaultJoinColumnHolder();
+ private ModifiablePropertyValueModel<Boolean> buildOverrideDefaultPrimaryKeyJoinColumnModel() {
+ PluggablePropertyValueModel.Adapter.Factory<Boolean> factory = ListValueModelTools.pluggablePropertyValueModelAdapterFactory(
+ this.buildSpecifiedPrimaryKeyJoinColumnsListModel(),
+ new OverrideDefaultPrimaryKeyJoinColumnModelTransformer()
+ );
+ Closure<Boolean> closure = ClosureTools.booleanClosure(new OverrideDefaultPrimaryKeyJoinColumnModelSetValueClosure());
+ return PropertyValueModelTools.pluggableModifiablePropertyValueModel(factory, closure);
}
private AddRemovePane.Adapter<SpecifiedPrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnAdapter() {
@@ -197,16 +209,16 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite
return new SimpleCollectionValueModel<SpecifiedPrimaryKeyJoinColumn>();
}
- private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListHolder() {
- List<ListValueModel<PrimaryKeyJoinColumn>> list = new ArrayList<ListValueModel<PrimaryKeyJoinColumn>>();
- list.add(buildSpecifiedJoinColumnsListHolder());
- list.add(buildDefaultJoinColumnListHolder());
+ private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListModel() {
+ List<ListValueModel<PrimaryKeyJoinColumn>> list = new ArrayList<>();
+ list.add(buildSpecifiedPrimaryKeyJoinColumnsListModel());
+ list.add(buildDefaultPrimaryKeyJoinColumnListModel());
return CompositeListValueModel.forModels(list);
}
- private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListModel() {
- return new ItemPropertyListValueModelAdapter<PrimaryKeyJoinColumn>(
- buildPrimaryKeyJoinColumnsListHolder(),
+ private ListValueModel<PrimaryKeyJoinColumn> buildUIPrimaryKeyJoinColumnsListModel() {
+ return new ItemPropertyListValueModelAdapter<>(
+ buildPrimaryKeyJoinColumnsListModel(),
NamedColumn.SPECIFIED_NAME_PROPERTY,
NamedColumn.DEFAULT_NAME_PROPERTY,
BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY,
@@ -214,7 +226,7 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite
);
}
- ListValueModel<PrimaryKeyJoinColumn> buildSpecifiedJoinColumnsListHolder() {
+ ListValueModel<PrimaryKeyJoinColumn> buildSpecifiedPrimaryKeyJoinColumnsListModel() {
return new ListAspectAdapter<SecondaryTable, PrimaryKeyJoinColumn>(getSubjectHolder(), SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) {
@Override
protected ListIterable<PrimaryKeyJoinColumn> getListIterable() {
@@ -261,7 +273,7 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite
Button overrideDefaultCheckBox = addCheckBox(
container,
JptJpaUiDetailsMessages.PRIMARY_KEY_JOIN_COLUMNS_COMPOSITE_OVERRIDE_DEFAULT_PRIMARY_KEY_JOIN_COLUMNS,
- buildOverrideDefaultJoinColumnHolder(),
+ buildOverrideDefaultPrimaryKeyJoinColumnModel(),
null,
buildControlBooleanHolder()
);
@@ -274,10 +286,10 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite
this,
container,
buildPrimaryKeyJoinColumnAdapter(),
- buildPrimaryKeyJoinColumnsListModel(),
+ buildUIPrimaryKeyJoinColumnsListModel(),
this.selectedPkJoinColumnsModel,
buildJoinColumnsListLabelProvider(),
- buildOverrideDefaultJoinColumnHolder(),
+ buildOverrideDefaultPrimaryKeyJoinColumnModel(),
JpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS
);
}
@@ -304,25 +316,25 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite
}
}
- private class OverrideDefaultJoinColumnHolder extends ListPropertyValueModelAdapter<Boolean>
- implements ModifiablePropertyValueModel<Boolean> {
-
- public OverrideDefaultJoinColumnHolder() {
- super(buildSpecifiedJoinColumnsListHolder());
- }
-
+ class OverrideDefaultPrimaryKeyJoinColumnModelTransformer
+ extends TransformerAdapter<Collection<?>, Boolean>
+ {
@Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.buildValue_());
+ public Boolean transform(Collection<?> specifiedPKJoinColumns) {
+ return Boolean.valueOf(this.transform_(specifiedPKJoinColumns));
}
- protected boolean buildValue_() {
+ protected boolean transform_(Collection<?> specifiedPKJoinColumns) {
SecondaryTable table = getSubject();
- return (table != null) && ! table.isVirtual() && listModel.size() > 0;
+ return (table != null) && ! table.isVirtual() && specifiedPKJoinColumns.size() > 0;
}
-
- public void setValue(Boolean value) {
- updatePrimaryKeyJoinColumns(value.booleanValue());
+ }
+
+ class OverrideDefaultPrimaryKeyJoinColumnModelSetValueClosure
+ implements BooleanClosure.Adapter
+ {
+ public void execute(boolean value) {
+ updatePrimaryKeyJoinColumns(value);
}
}
-} \ No newline at end of file
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/QueriesComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/QueriesComposite.java
index 8e55002415..07ee4117d4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/QueriesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/QueriesComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -21,7 +21,7 @@ import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.Adapter;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
@@ -99,23 +99,15 @@ public class QueriesComposite
protected void initialize() {
super.initialize();
this.selectedQueriesModel = this.buildSelectedQueriesModel();
- this.selectedQueryModel = this.buildSelectedQueryModel(this.selectedQueriesModel);
+ this.selectedQueryModel = this.buildSelectedQueryModel();
}
private ModifiableCollectionValueModel<Query> buildSelectedQueriesModel() {
- return new SimpleCollectionValueModel<Query>();
+ return new SimpleCollectionValueModel<>();
}
- private PropertyValueModel<Query> buildSelectedQueryModel(CollectionValueModel<Query> selectedQueriesModel) {
- return new CollectionPropertyValueModelAdapter<Query, Query>(selectedQueriesModel) {
- @Override
- protected Query buildValue() {
- if (this.collectionModel.size() == 1) {
- return this.collectionModel.iterator().next();
- }
- return null;
- }
- };
+ private PropertyValueModel<Query> buildSelectedQueryModel() {
+ return CollectionValueModelTools.singleElementPropertyValueModel(this.selectedQueriesModel);
}
protected PropertyValueModel<Query> getSelectedQueryModel() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java
index bfed4cc98e..f402736ae2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -14,9 +14,10 @@ import java.util.Collection;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
import org.eclipse.jpt.common.utility.internal.iterable.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.ReadOnlyModifiablePropertyValueModelWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ValueListAdapter;
@@ -26,25 +27,22 @@ import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
import org.eclipse.jpt.jpa.core.context.JoinColumn;
import org.eclipse.jpt.jpa.core.context.ReferenceTable;
-import org.eclipse.jpt.jpa.core.context.Table;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
import org.eclipse.jpt.jpa.core.context.SpecifiedReferenceTable;
+import org.eclipse.jpt.jpa.core.context.Table;
import org.eclipse.jpt.jpa.db.Schema;
import org.eclipse.jpt.jpa.db.SchemaContainer;
import org.eclipse.jpt.jpa.ui.internal.details.JoinColumnsComposite.JoinColumnsEditor;
import org.eclipse.jpt.jpa.ui.internal.details.db.CatalogCombo;
import org.eclipse.jpt.jpa.ui.internal.details.db.SchemaCombo;
import org.eclipse.jpt.jpa.ui.internal.details.db.TableCombo;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
public abstract class ReferenceTableComposite<T extends ReferenceTable>
extends Pane<T>
{
- protected Button overrideDefaultJoinColumnsCheckBox;
-
protected JoinColumnsComposite<T> joinColumnsComposite;
protected ReferenceTableComposite(
@@ -86,11 +84,11 @@ public abstract class ReferenceTableComposite<T extends ReferenceTable>
return new JoinColumnsProvider();
}
- protected ModifiablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() {
- return new OverrideDefaultJoinColumnHolder();
+ protected ModifiablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnModel() {
+ return ListValueModelTools.isNotEmptyModifiablePropertyValueModel(this.buildSpecifiedJoinColumnsListModel(), new OverrideDefaultJoinColumnModelSetValueClosure());
}
- ListValueModel<JoinColumn> buildSpecifiedJoinColumnsListHolder() {
+ ListValueModel<JoinColumn> buildSpecifiedJoinColumnsListModel() {
return new ListAspectAdapter<T, JoinColumn>(getSubjectHolder(), ReferenceTable.SPECIFIED_JOIN_COLUMNS_LIST) {
@Override
protected ListIterable<JoinColumn> getListIterable() {
@@ -272,7 +270,7 @@ public abstract class ReferenceTableComposite<T extends ReferenceTable>
stateObject.updateJoinColumn(stateObject.getJoinColumn());
}
- void updateJoinColumns() {
+ void updateJoinColumns(boolean selected) {
if (this.isPopulating()) {
return;
}
@@ -282,7 +280,6 @@ public abstract class ReferenceTableComposite<T extends ReferenceTable>
return;
}
- boolean selected = this.overrideDefaultJoinColumnsCheckBox.getSelection();
this.setPopulating(true);
try {
@@ -341,20 +338,11 @@ public abstract class ReferenceTableComposite<T extends ReferenceTable>
}
- private class OverrideDefaultJoinColumnHolder extends ListPropertyValueModelAdapter<Boolean>
- implements ModifiablePropertyValueModel<Boolean> {
-
- public OverrideDefaultJoinColumnHolder() {
- super(buildSpecifiedJoinColumnsListHolder());
- }
-
- @Override
- protected Boolean buildValue() {
- return Boolean.valueOf(this.listModel.size() > 0);
- }
-
- public void setValue(Boolean value) {
- updateJoinColumns();
+ class OverrideDefaultJoinColumnModelSetValueClosure
+ implements BooleanClosure.Adapter
+ {
+ public void execute(boolean value) {
+ updateJoinColumns(value);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPrimaryKeyJoinColumnsComposite.java
index 87100b37dd..c55f0891df 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPrimaryKeyJoinColumnsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPrimaryKeyJoinColumnsComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 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.
@@ -35,7 +35,7 @@ public class JavaPrimaryKeyJoinColumnsComposite extends AbstractPrimaryKeyJoinCo
}
@Override
- protected ListValueModel<SpecifiedPrimaryKeyJoinColumn> buildDefaultJoinColumnsListHolder() {
+ protected ListValueModel<SpecifiedPrimaryKeyJoinColumn> buildDefaultJoinColumnsListModel() {
return new PropertyListValueModelAdapter<SpecifiedPrimaryKeyJoinColumn>(buildDefaultJoinColumnHolder());
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsGeneratorsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsGeneratorsComposite.java
index 5777be9535..84c2fb4e5f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsGeneratorsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsGeneratorsComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -19,7 +19,7 @@ import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.Adapter;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
@@ -104,23 +104,15 @@ public class EntityMappingsGeneratorsComposite extends Pane<EntityMappings>
protected void initialize() {
super.initialize();
this.selectedGeneratorsModel = this.buildSelectedGeneratorsModel();
- this.selectedGeneratorModel = this.buildSelectedGeneratorModel(this.selectedGeneratorsModel);
+ this.selectedGeneratorModel = this.buildSelectedGeneratorModel();
}
private ModifiableCollectionValueModel<OrmGenerator> buildSelectedGeneratorsModel() {
- return new SimpleCollectionValueModel<OrmGenerator>();
+ return new SimpleCollectionValueModel<>();
}
- protected PropertyValueModel<OrmGenerator> buildSelectedGeneratorModel(ModifiableCollectionValueModel<OrmGenerator> selectedGeneratorsModel) {
- return new CollectionPropertyValueModelAdapter<OrmGenerator, OrmGenerator>(selectedGeneratorsModel) {
- @Override
- protected OrmGenerator buildValue() {
- if (this.collectionModel.size() == 1) {
- return this.collectionModel.iterator().next();
- }
- return null;
- }
- };
+ protected PropertyValueModel<OrmGenerator> buildSelectedGeneratorModel() {
+ return CollectionValueModelTools.singleElementPropertyValueModel(this.selectedGeneratorsModel);
}
OrmGenerator addGenerator() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPrimaryKeyJoinColumnsComposite.java
index 22e456f929..469eb003c6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPrimaryKeyJoinColumnsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPrimaryKeyJoinColumnsComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 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.
@@ -34,7 +34,7 @@ public class OrmPrimaryKeyJoinColumnsComposite extends AbstractPrimaryKeyJoinCol
}
@Override
- protected ListValueModel<PrimaryKeyJoinColumn> buildDefaultJoinColumnsListHolder() {
+ protected ListValueModel<PrimaryKeyJoinColumn> buildDefaultJoinColumnsListModel() {
return new ListAspectAdapter<OrmEntity, PrimaryKeyJoinColumn>(
getSubjectHolder(),
OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST)
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmSecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmSecondaryTablesComposite.java
index bab9ccd9c9..0febafa8d7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmSecondaryTablesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmSecondaryTablesComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2006, 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.
@@ -13,18 +13,19 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
+import org.eclipse.jpt.common.utility.internal.closure.BooleanClosure;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.iterable.ListIterable;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiableCollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.jpa.core.context.Entity;
import org.eclipse.jpt.jpa.core.context.SecondaryTable;
-import org.eclipse.jpt.jpa.core.context.Table;
import org.eclipse.jpt.jpa.core.context.SpecifiedSecondaryTable;
+import org.eclipse.jpt.jpa.core.context.Table;
import org.eclipse.jpt.jpa.core.context.orm.OrmEntity;
import org.eclipse.jpt.jpa.core.context.orm.OrmSpecifiedSecondaryTable;
import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualSecondaryTable;
@@ -74,22 +75,21 @@ public class OrmSecondaryTablesComposite extends AbstractSecondaryTablesComposit
}
private ModifiablePropertyValueModel<Boolean> buildDefineInXmlModel() {
- return new DefineInXmlModel();
+ return ListValueModelTools.isEmptyModifiablePropertyValueModel(this.buildVirtualSecondaryTablesModel(), new DefineInXmlSetValueClosure());
}
- private ListValueModel<SecondaryTable> buildSecondaryTablesListHolder() {
- List<ListValueModel<? extends SecondaryTable>> list = new ArrayList<ListValueModel<? extends SecondaryTable>>();
- list.add(buildSpecifiedSecondaryTablesListHolder());
- list.add(buildVirtualSecondaryTablesListHolder());
+ private ListValueModel<SecondaryTable> buildSecondaryTablesModel() {
+ List<ListValueModel<? extends SecondaryTable>> list = new ArrayList<>();
+ list.add(buildSpecifiedSecondaryTablesModel());
+ list.add(buildVirtualSecondaryTablesModel());
return CompositeListValueModel.forModels(list);
}
private ListValueModel<SecondaryTable> buildSecondaryTablesListModel() {
- return new ItemPropertyListValueModelAdapter<SecondaryTable>(buildSecondaryTablesListHolder(),
- Table.SPECIFIED_NAME_PROPERTY);
+ return new ItemPropertyListValueModelAdapter<>(buildSecondaryTablesModel(), Table.SPECIFIED_NAME_PROPERTY);
}
- private ListValueModel<OrmSpecifiedSecondaryTable> buildSpecifiedSecondaryTablesListHolder() {
+ private ListValueModel<OrmSpecifiedSecondaryTable> buildSpecifiedSecondaryTablesModel() {
return new ListAspectAdapter<OrmEntity, OrmSpecifiedSecondaryTable>(getSubjectHolder(), Entity.SPECIFIED_SECONDARY_TABLES_LIST) {
@Override
protected ListIterable<OrmSpecifiedSecondaryTable> getListIterable() {
@@ -103,7 +103,7 @@ public class OrmSecondaryTablesComposite extends AbstractSecondaryTablesComposit
};
}
- ListValueModel<OrmVirtualSecondaryTable> buildVirtualSecondaryTablesListHolder() {
+ ListValueModel<OrmVirtualSecondaryTable> buildVirtualSecondaryTablesModel() {
return new ListAspectAdapter<OrmEntity, OrmVirtualSecondaryTable>(getSubjectHolder(), OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST) {
@Override
protected ListIterable<OrmVirtualSecondaryTable> getListIterable() {
@@ -118,6 +118,7 @@ public class OrmSecondaryTablesComposite extends AbstractSecondaryTablesComposit
}
@Override
+ @SuppressWarnings("unused")
protected void initializeLayout(Composite container) {
ModifiableCollectionValueModel<SpecifiedSecondaryTable> selectedSecondaryTablesModel =
buildSelectedSecondaryTablesModel();
@@ -163,23 +164,11 @@ public class OrmSecondaryTablesComposite extends AbstractSecondaryTablesComposit
getSubject().getMappingFileRoot().getSchema());
}
- private class DefineInXmlModel extends ListPropertyValueModelAdapter<Boolean>
- implements ModifiablePropertyValueModel<Boolean> {
-
- public DefineInXmlModel() {
- super(buildVirtualSecondaryTablesListHolder());
- }
-
- @Override
- protected Boolean buildValue() {
- if (getSubject() == null) {
- return Boolean.FALSE;
- }
- return Boolean.valueOf(getSubject().secondaryTablesAreDefinedInXml());
- }
-
- public void setValue(Boolean value) {
- getSubject().setSecondaryTablesAreDefinedInXml(value.booleanValue());
+ class DefineInXmlSetValueClosure
+ implements BooleanClosure.Adapter
+ {
+ public void execute(boolean value) {
+ getSubject().setSecondaryTablesAreDefinedInXml(value);
}
}
-} \ No newline at end of file
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/JpaXmlEditor.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/JpaXmlEditor.java
index 6a63423fd7..05205a8e1b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/JpaXmlEditor.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/JpaXmlEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -25,7 +25,7 @@ import org.eclipse.jpt.common.ui.internal.widgets.FormWidgetFactory;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.StringBuilderTools;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.DoublePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
@@ -59,7 +59,6 @@ import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
@@ -88,7 +87,7 @@ public class JpaXmlEditor
* <p>
* @see #setInput(IEditorInput)
*/
- private final ModifiablePropertyValueModel<IFileEditorInput> editorInputModel = new SimplePropertyValueModel<IFileEditorInput>();
+ private final ModifiablePropertyValueModel<IFileEditorInput> editorInputModel = new SimplePropertyValueModel<>();
/**
* The root structure node model is built from the editorInputModel. We assume
@@ -224,7 +223,7 @@ public class JpaXmlEditor
}
JpaPlatform jpaPlatform = rootStructureNode.getJpaPlatform();
- JpaPlatformUi jpaPlatformUI = (JpaPlatformUi) jpaPlatform.getAdapter(JpaPlatformUi.class);
+ JpaPlatformUi jpaPlatformUI = jpaPlatform.getAdapter(JpaPlatformUi.class);
if (jpaPlatformUI == null) {
return;
}
@@ -272,9 +271,10 @@ public class JpaXmlEditor
* Delegate to the {@link #structuredTextEditor} if necessary.
*/
@Override
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapterClass) {
+ @SuppressWarnings("unchecked")
+ public <T> T getAdapter(Class<T> adapterClass) {
Object adapter = super.getAdapter(adapterClass);
- return (adapter != null) ? adapter : this.structuredTextEditor.getAdapter(adapterClass);
+ return (T) ((adapter != null) ? adapter : this.structuredTextEditor.getAdapter(adapterClass));
}
@Override
@@ -296,11 +296,11 @@ public class JpaXmlEditor
// ********** JPA file **********
private PropertyValueModel<JpaFile> buildJpaFileModel() {
- return new DoublePropertyValueModel<JpaFile>(this.buildJpaFileModelModel());
+ return new DoublePropertyValueModel<>(this.buildJpaFileModelModel());
}
private PropertyValueModel<PropertyValueModel<JpaFile>> buildJpaFileModelModel() {
- return new TransformationPropertyValueModel<IFileEditorInput, PropertyValueModel<JpaFile>>(this.editorInputModel, JPA_FILE_MODEL_TRANSFORMER);
+ return new TransformationPropertyValueModel<>(this.editorInputModel, JPA_FILE_MODEL_TRANSFORMER);
}
private static final Transformer<IFileEditorInput, PropertyValueModel<JpaFile>> JPA_FILE_MODEL_TRANSFORMER = new JpaFileModelTransformer();
@@ -310,7 +310,7 @@ public class JpaXmlEditor
{
@Override
protected PropertyValueModel<JpaFile> transform_(IFileEditorInput fileEditorInput) {
- return (JpaFileModel) fileEditorInput.getFile().getAdapter(JpaFileModel.class);
+ return fileEditorInput.getFile().getAdapter(JpaFileModel.class);
}
}
@@ -344,26 +344,14 @@ public class JpaXmlEditor
}
}
if (rootStructureNode != null) {
- this.pageRootStructureNodeModel = new SimplePropertyValueModel<JpaStructureNode>(rootStructureNode);
+ this.pageRootStructureNodeModel = new SimplePropertyValueModel<>(rootStructureNode);
this.addSpecificPages(this.pageRootStructureNodeModel);
}
}
//*should* be only 1 root structure node for the jpa file (this is true for persistence.xml and orm.xml files)
private PropertyValueModel<JpaStructureNode> buildRootStructureNodeModel() {
- return new RootStructureNodeModel(this.buildRootStructureNodesCollectionModel());
- }
-
- /* CU private */ static class RootStructureNodeModel
- extends CollectionPropertyValueModelAdapter<JpaStructureNode, JpaStructureNode>
- {
- RootStructureNodeModel(CollectionValueModel<? extends JpaStructureNode> collectionModel) {
- super(collectionModel);
- }
- @Override
- protected JpaStructureNode buildValue() {
- return this.collectionModel.size() > 0 ? this.collectionModel.iterator().next() : null;
- }
+ return CollectionValueModelTools.firstElementPropertyValueModel(this.buildRootStructureNodesCollectionModel());
}
private CollectionValueModel<JpaStructureNode> buildRootStructureNodesCollectionModel() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/CollectionTableComposite2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/CollectionTableComposite2_0.java
index cd072963a5..8683e94d57 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/CollectionTableComposite2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/CollectionTableComposite2_0.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -64,10 +64,10 @@ public class CollectionTableComposite2_0
joinColumnGroupPane.setLayoutData(gridData);
// Override Default Join Columns check box
- this.overrideDefaultJoinColumnsCheckBox = addCheckBox(
+ addCheckBox(
joinColumnGroupPane,
JptJpaUiDetailsMessages2_0.COLLECTION_TABLE_COMPOSITE_OVERRIDE_DEFAULT_JOIN_COLUMNS,
- buildOverrideDefaultJoinColumnHolder(),
+ buildOverrideDefaultJoinColumnModel(),
null
);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceUnitEditorPageDefinition2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceUnitEditorPageDefinition2_0.java
index 10a827711f..f0c647a89a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceUnitEditorPageDefinition2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceUnitEditorPageDefinition2_0.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Oracle. All rights reserved.
+ * 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.
@@ -12,8 +12,9 @@ package org.eclipse.jpt.jpa.ui.internal.jpa2.persistence;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.iterable.ListIterable;
+import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
@@ -30,24 +31,20 @@ public abstract class PersistenceUnitEditorPageDefinition2_0
}
public void buildContent(IManagedForm form, WidgetFactory widgetFactory, ResourceManager resourceManager, PropertyValueModel<JpaStructureNode> jpaRootStructureNodeModel) {
- this.buildEditorPageContent(form.getForm().getBody(), widgetFactory, resourceManager, new PersistenceUnitModel(jpaRootStructureNodeModel));
+ this.buildEditorPageContent(form.getForm().getBody(), widgetFactory, resourceManager, this.buildPersistenceUnitModel(jpaRootStructureNodeModel));
}
- protected abstract void buildEditorPageContent(Composite parent, WidgetFactory widgetFactory, ResourceManager resourceManager, PropertyValueModel<PersistenceUnit> persistenceUnitModel);
-
- protected static class PersistenceUnitModel
- extends ListPropertyValueModelAdapter<PersistenceUnit>
- {
- protected PersistenceUnitModel(PropertyValueModel<JpaStructureNode> jpaStructureNodeModel) {
- super(new PersistenceUnitListModel(jpaStructureNodeModel));
- }
+ protected PropertyValueModel<PersistenceUnit> buildPersistenceUnitModel(PropertyValueModel<JpaStructureNode> jpaStructureNodeModel) {
+ return ListValueModelTools.firstElementPropertyValueModel(this.buildPersistenceUnitListModel(jpaStructureNodeModel));
+ }
- @Override
- protected PersistenceUnit buildValue() {
- return (this.listModel.size() > 0) ? (PersistenceUnit) this.listModel.get(0) : null;
- }
+ protected ListValueModel<PersistenceUnit> buildPersistenceUnitListModel(PropertyValueModel<JpaStructureNode> jpaStructureNodeModel) {
+ return new PersistenceUnitListModel(jpaStructureNodeModel);
}
+ protected abstract void buildEditorPageContent(Composite parent, WidgetFactory widgetFactory, ResourceManager resourceManager, PropertyValueModel<PersistenceUnit> persistenceUnitModel);
+
+
/**
* Assume the JPA structure node is a persistence.
*/
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java
index 68ab5768c8..4aa46803b6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -48,7 +48,7 @@ public class JpaNavigatorItemContentProviderFactory
/**
* Delegate factories, keyed by JPA platform.
*/
- private HashMap<JpaPlatform, ItemTreeContentProvider.Factory> delegates = new HashMap<JpaPlatform, ItemTreeContentProvider.Factory>();
+ private HashMap<JpaPlatform, ItemTreeContentProvider.Factory> delegates = new HashMap<>();
public JpaNavigatorItemContentProviderFactory() {
@@ -94,15 +94,15 @@ public class JpaNavigatorItemContentProviderFactory
// ********** project **********
protected CollectionValueModel<JpaContextRoot> buildProjectChildrenModel(IProject project) {
- return new PropertyCollectionValueModelAdapter<JpaContextRoot>(this.buildProjectJpaContextRootModel(project));
+ return new PropertyCollectionValueModelAdapter<>(this.buildProjectJpaContextRootModel(project));
}
protected PropertyValueModel<JpaContextRoot> buildProjectJpaContextRootModel(IProject project) {
- return new TransformationPropertyValueModel<JpaProject, JpaContextRoot>(this.buildProjectJpaProjectModel(project), TransformerTools.nullCheck(JpaProject.CONTEXT_ROOT_TRANSFORMER));
+ return new TransformationPropertyValueModel<>(this.buildProjectJpaProjectModel(project), TransformerTools.nullCheck(JpaProject.CONTEXT_ROOT_TRANSFORMER));
}
protected PropertyValueModel<JpaProject> buildProjectJpaProjectModel(IProject project) {
- return (JpaProjectModel) project.getAdapter(JpaProjectModel.class);
+ return project.getAdapter(JpaProjectModel.class);
}
@@ -125,7 +125,7 @@ public class JpaNavigatorItemContentProviderFactory
}
protected ItemTreeContentProvider.Factory buildDelegate(JpaPlatform jpaPlatform) {
- JpaPlatformUi platformUI = (JpaPlatformUi) jpaPlatform.getAdapter(JpaPlatformUi.class);
+ JpaPlatformUi platformUI = jpaPlatform.getAdapter(JpaPlatformUi.class);
return (platformUI != null) ?
platformUI.getNavigatorFactoryProvider().getItemContentProviderFactory() :
NullItemTreeContentProviderFactory.instance();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/PersistenceUnitClassesComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/PersistenceUnitClassesComposite.java
index ef682c9bd8..8b5d04daeb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/PersistenceUnitClassesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/PersistenceUnitClassesComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.persistence;
+import java.util.Collection;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
@@ -25,13 +26,14 @@ import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.StringTools;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
import org.eclipse.jpt.common.utility.iterable.ListIterable;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
@@ -118,16 +120,16 @@ public class PersistenceUnitClassesComposite
@Override
public PropertyValueModel<Boolean> buildOptionalButtonEnabledModel(CollectionValueModel<ClassRef> selectedItemsModel) {
- return new CollectionPropertyValueModelAdapter<Boolean, ClassRef>(selectedItemsModel) {
- @Override
- protected Boolean buildValue() {
- if (this.collectionModel.size() == 1) {
- ClassRef classRef = this.collectionModel.iterator().next();
- return Boolean.valueOf(findType(classRef) != null);
+ return CollectionValueModelTools.propertyValueModel(selectedItemsModel, new TransformerAdapter<Collection<ClassRef>, Boolean>() {
+ @Override
+ public Boolean transform(Collection<ClassRef> collection) {
+ return Boolean.valueOf(this.transform_(collection));
}
- return Boolean.FALSE;
- }
- };
+ private boolean transform_(Collection<ClassRef> collection) {
+ return (collection.size() == 1) &&
+ (findType(collection.iterator().next()) != null);
+ }
+ });
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/AbstractNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/AbstractNavigatorItemContentProviderFactory.java
index 2fab995bfc..4f6b2dbc9b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/AbstractNavigatorItemContentProviderFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/AbstractNavigatorItemContentProviderFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 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.
@@ -18,10 +18,10 @@ import org.eclipse.jpt.common.ui.jface.ItemStructuredContentProvider;
import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.FilteringCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationListValueModel;
@@ -197,7 +197,7 @@ public abstract class AbstractNavigatorItemContentProviderFactory
// ********** persistence unit - specified mapping files **********
protected CollectionValueModel<MappingFile> buildPersistenceUnitNotNullSpecifiedMappingFilesModel(PersistenceUnit persistenceUnit) {
- return new FilteringCollectionValueModel<MappingFile>(
+ return ListValueModelTools.filter(
this.buildPersistenceUnitSpecifiedMappingFilesModel(persistenceUnit),
PredicateTools.<MappingFile>isNotNull()
);
@@ -286,7 +286,7 @@ public abstract class AbstractNavigatorItemContentProviderFactory
// ********** persistence unit - managed types **********
protected CollectionValueModel<JavaManagedType> buildPersistenceUnitNotNullJavaManagedTypesModel(PersistenceUnit persistenceUnit) {
- return new FilteringCollectionValueModel<JavaManagedType>(
+ return ListValueModelTools.filter(
this.buildPersistenceUnitJavaManagedTypesModel(persistenceUnit),
PredicateTools.<JavaManagedType>isNotNull()
);
@@ -365,7 +365,7 @@ public abstract class AbstractNavigatorItemContentProviderFactory
// ********** persistence unit - jar files **********
protected CollectionValueModel<JarFile> buildPersistenceUnitNotNullJarFilesModel(PersistenceUnit persistenceUnit) {
- return new FilteringCollectionValueModel<JarFile>(
+ return ListValueModelTools.filter(
this.buildPersistenceUnitJarFilesModel(persistenceUnit),
PredicateTools.<JarFile>isNotNull()
);
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 ae844d24df..f18827aad1 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -41,12 +41,14 @@ import org.eclipse.jpt.common.utility.internal.model.value.AspectCollectionValue
import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.BufferedModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CompositePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.DoublePropertyValueModel;
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.PredicatePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PluggablePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.SetCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SortedListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.StaticCollectionValueModel;
@@ -194,11 +196,11 @@ public class JpaProjectPropertiesPage
// ***** JPA project model
private PropertyValueModel<JpaProject> buildJpaProjectModel() {
- return new DoublePropertyValueModel<JpaProject>(this.buildJpaProjectModelModel());
+ return new DoublePropertyValueModel<>(this.buildJpaProjectModelModel());
}
private PropertyValueModel<PropertyValueModel<JpaProject>> buildJpaProjectModelModel() {
- return new TransformationPropertyValueModel<IProject, PropertyValueModel<JpaProject>>(this.projectModel, JPA_PROJECT_MODEL_TRANSFORMER);
+ return new TransformationPropertyValueModel<>(this.projectModel, JPA_PROJECT_MODEL_TRANSFORMER);
}
private static final Transformer<IProject, PropertyValueModel<JpaProject>> JPA_PROJECT_MODEL_TRANSFORMER = new JpaProjectModelTransformer();
@@ -208,18 +210,18 @@ public class JpaProjectPropertiesPage
{
@Override
protected PropertyValueModel<JpaProject> transform_(IProject project) {
- return (JpaProjectModel) project.getAdapter(JpaProjectModel.class);
+ return project.getAdapter(JpaProjectModel.class);
}
}
// ***** JPA project is not null model
private PropertyValueModel<Boolean> buildJpaProjectIsNotNullFlagModel() {
- return new PredicatePropertyValueModel<JpaProject>(this.jpaProjectModel, PredicateTools.isNotNull());
+ return new PredicatePropertyValueModel<>(this.jpaProjectModel, PredicateTools.isNotNull());
}
// ***** JPA platform config model
private BufferedModifiablePropertyValueModel<JpaPlatform.Config> buildJpaPlatformConfigModel() {
- return new BufferedModifiablePropertyValueModel<JpaPlatform.Config>(new JpaPlatformConfigModel(this.jpaProjectModel), this.trigger);
+ return new BufferedModifiablePropertyValueModel<>(new JpaPlatformConfigModel(this.jpaProjectModel), this.trigger);
}
private PropertyChangeListener buildJpaPlatformConfigListener(){
@@ -245,7 +247,7 @@ public class JpaProjectPropertiesPage
// ***** connection models
private BufferedModifiablePropertyValueModel<String> buildConnectionModel() {
- return new BufferedModifiablePropertyValueModel<String>(new ConnectionModel(this.jpaProjectModel), this.trigger);
+ return new BufferedModifiablePropertyValueModel<>(new ConnectionModel(this.jpaProjectModel), this.trigger);
}
private PropertyValueModel<ConnectionProfile> buildConnectionProfileModel() {
@@ -258,15 +260,19 @@ public class JpaProjectPropertiesPage
// ***** catalog models
private BufferedModifiablePropertyValueModel<Boolean> buildUserOverrideDefaultCatalogFlagModel() {
- return new BufferedModifiablePropertyValueModel<Boolean>(new UserOverrideDefaultCatalogFlagModel(this.jpaProjectModel), this.trigger);
+ return new BufferedModifiablePropertyValueModel<>(new UserOverrideDefaultCatalogFlagModel(this.jpaProjectModel), this.trigger);
}
private BufferedModifiablePropertyValueModel<String> buildUserOverrideDefaultCatalogModel() {
- return new BufferedModifiablePropertyValueModel<String>(new UserOverrideDefaultCatalogModel(this.jpaProjectModel), this.trigger);
+ return new BufferedModifiablePropertyValueModel<>(new UserOverrideDefaultCatalogModel(this.jpaProjectModel), this.trigger);
}
private ModifiablePropertyValueModel<String> buildDefaultCatalogModel() {
- return new DefaultModel(
+ return PropertyValueModelTools.modifiablePropertyValueModel(this.buildDefaultCatalogModelAdapterFactory());
+ }
+
+ private PluggableModifiablePropertyValueModel.Adapter.Factory<String> buildDefaultCatalogModelAdapterFactory() {
+ return new DefaultDatabaseComponentModelAdapter.Factory(
this.userOverrideDefaultCatalogFlagModel,
this.userOverrideDefaultCatalogModel,
this.buildDatabaseDefaultCatalogModel()
@@ -281,7 +287,7 @@ public class JpaProjectPropertiesPage
* Add the default catalog if it is not on the list from the database
*/
private ListValueModel<String> buildCatalogChoicesModel() {
- return new SortedListValueModelAdapter<String>(this.buildUnsortedCatalogChoicesModel(), STRING_COMPARATOR);
+ return new SortedListValueModelAdapter<>(this.buildUnsortedCatalogChoicesModel(), STRING_COMPARATOR);
}
/**
@@ -289,9 +295,9 @@ public class JpaProjectPropertiesPage
*/
@SuppressWarnings("unchecked")
private CollectionValueModel<String> buildUnsortedCatalogChoicesModel() {
- return new SetCollectionValueModel<String>(
+ return new SetCollectionValueModel<>(
CompositeCollectionValueModel.forModels(
- new PropertyCollectionValueModelAdapter<String>(this.defaultCatalogModel),
+ new PropertyCollectionValueModelAdapter<>(this.defaultCatalogModel),
this.buildDatabaseCatalogChoicesModel()
)
);
@@ -303,15 +309,19 @@ public class JpaProjectPropertiesPage
// ***** schema models
private BufferedModifiablePropertyValueModel<Boolean> buildUserOverrideDefaultSchemaFlagModel() {
- return new BufferedModifiablePropertyValueModel<Boolean>(new UserOverrideDefaultSchemaFlagModel(this.jpaProjectModel), this.trigger);
+ return new BufferedModifiablePropertyValueModel<>(new UserOverrideDefaultSchemaFlagModel(this.jpaProjectModel), this.trigger);
}
private BufferedModifiablePropertyValueModel<String> buildUserOverrideDefaultSchemaModel() {
- return new BufferedModifiablePropertyValueModel<String>(new UserOverrideDefaultSchemaModel(this.jpaProjectModel), this.trigger);
+ return new BufferedModifiablePropertyValueModel<>(new UserOverrideDefaultSchemaModel(this.jpaProjectModel), this.trigger);
}
private ModifiablePropertyValueModel<String> buildDefaultSchemaModel() {
- return new DefaultModel(
+ return PropertyValueModelTools.modifiablePropertyValueModel(this.buildDefaultSchemaModelAdapterFactory());
+ }
+
+ private PluggableModifiablePropertyValueModel.Adapter.Factory<String> buildDefaultSchemaModelAdapterFactory() {
+ return new DefaultDatabaseComponentModelAdapter.Factory(
this.userOverrideDefaultSchemaFlagModel,
this.userOverrideDefaultSchemaModel,
this.buildDatabaseDefaultSchemaModel()
@@ -326,14 +336,14 @@ public class JpaProjectPropertiesPage
* Add the default catalog if it is not on the list from the database
*/
private ListValueModel<String> buildSchemaChoicesModel() {
- return new SortedListValueModelAdapter<String>(this.buildUnsortedSchemaChoicesModel(), STRING_COMPARATOR);
+ return new SortedListValueModelAdapter<>(this.buildUnsortedSchemaChoicesModel(), STRING_COMPARATOR);
}
@SuppressWarnings("unchecked")
private CollectionValueModel<String> buildUnsortedSchemaChoicesModel() {
- return new SetCollectionValueModel<String>(
+ return new SetCollectionValueModel<>(
CompositeCollectionValueModel.forModels(
- new PropertyCollectionValueModelAdapter<String>(this.defaultSchemaModel),
+ new PropertyCollectionValueModelAdapter<>(this.defaultSchemaModel),
this.buildDatabaseSchemaChoicesModel()
)
);
@@ -345,32 +355,32 @@ public class JpaProjectPropertiesPage
// ***** discover/list annotated classes models
private BufferedModifiablePropertyValueModel<Boolean> buildDiscoverAnnotatedClassesModel() {
- return new BufferedModifiablePropertyValueModel<Boolean>(new DiscoverAnnotatedClassesModel(this.jpaProjectModel), this.trigger);
+ return new BufferedModifiablePropertyValueModel<>(new DiscoverAnnotatedClassesModel(this.jpaProjectModel), this.trigger);
}
/**
* The opposite of the "discover annotated classes" flag.
*/
private ModifiablePropertyValueModel<Boolean> buildListAnnotatedClassesModel() {
- return new TransformationModifiablePropertyValueModel<Boolean, Boolean>(this.discoverAnnotatedClassesModel, TransformerTools.notBooleanTransformer(), TransformerTools.notBooleanTransformer());
+ return new TransformationModifiablePropertyValueModel<>(this.discoverAnnotatedClassesModel, TransformerTools.notBooleanTransformer(), TransformerTools.notBooleanTransformer());
}
// ***** JPA 2.0 project flag
private PropertyValueModel<Boolean> buildJpa2_0ProjectFlagModel() {
- return new PredicatePropertyValueModel<JpaProject>(this.jpaProjectModel, IS_COMPATIBLE_WITH_JPA_2_0);
+ return new PredicatePropertyValueModel<>(this.jpaProjectModel, IS_COMPATIBLE_WITH_JPA_2_0);
}
private static final Predicate<JpaModel> IS_COMPATIBLE_WITH_JPA_2_0 = PredicateTools.nullCheck(new JpaModel.JpaVersionIsCompatibleWith(JpaProject2_0.FACET_VERSION_STRING));
// ***** metamodel models
private BufferedModifiablePropertyValueModel<String> buildMetamodelSourceFolderModel() {
- return new BufferedModifiablePropertyValueModel<String>(new MetamodelSourceFolderModel(this.jpaProjectModel), this.trigger);
+ return new BufferedModifiablePropertyValueModel<>(new MetamodelSourceFolderModel(this.jpaProjectModel), this.trigger);
}
private ListValueModel<String> buildJavaSourceFolderChoicesModel() {
// by default, ExtendedListValueModelWrapper puts a null at the top of the list
- return new ExtendedListValueModelWrapper<String>(
- new SortedListValueModelAdapter<String>(
+ return new ExtendedListValueModelWrapper<>(
+ new SortedListValueModelAdapter<>(
new JavaSourceFolderChoicesModel(this.jpaProjectModel),
STRING_COMPARATOR
)
@@ -418,7 +428,7 @@ public class JpaProjectPropertiesPage
@Override
protected LibraryInstallDelegate createLibraryInstallDelegate(IFacetedProject project, IProjectFacetVersion fv) {
- Map<String, Object> enablementVariables = new HashMap<String, Object>();
+ Map<String, Object> enablementVariables = new HashMap<>();
//TODO Ask Paul about these empty enablement variables - trying to reproduce Helios functionality
enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, ""); //$NON-NLS-1$
@@ -486,7 +496,7 @@ public class JpaProjectPropertiesPage
lid.setEnablementContextVariable(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, jpaPlatformID);
lid.setEnablementContextVariable(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, jpaPlatformConfig);
- ArrayList<JpaLibraryProviderInstallOperationConfig> jpaConfigs = new ArrayList<JpaLibraryProviderInstallOperationConfig>();
+ ArrayList<JpaLibraryProviderInstallOperationConfig> jpaConfigs = new ArrayList<>();
// add the currently selected one first
JpaLibraryProviderInstallOperationConfig currentJpaConfig = null;
LibraryProviderOperationConfig config = lid.getLibraryProviderOperationConfig();
@@ -574,8 +584,8 @@ public class JpaProjectPropertiesPage
* would be no JPA project!
*/
private ListValueModel<JpaPlatform.Config> buildJpaPlatformConfigChoicesModel() {
- return new SortedListValueModelAdapter<JpaPlatform.Config>(
- new SetCollectionValueModel<JpaPlatform.Config>(
+ return new SortedListValueModelAdapter<>(
+ new SetCollectionValueModel<>(
CompositeCollectionValueModel.forModels(
this.buildJpaPlatformConfigChoicesModels()
)
@@ -587,7 +597,7 @@ public class JpaProjectPropertiesPage
@SuppressWarnings("unchecked")
private CollectionValueModel<JpaPlatform.Config>[] buildJpaPlatformConfigChoicesModels() {
return new CollectionValueModel[] {
- new PropertyCollectionValueModelAdapter<JpaPlatform.Config>(this.jpaPlatformConfigModel),
+ new PropertyCollectionValueModelAdapter<>(this.jpaPlatformConfigModel),
this.buildEnabledJpaPlatformConfigsModel()
};
}
@@ -597,7 +607,7 @@ public class JpaProjectPropertiesPage
* JPA facet version.
*/
private CollectionValueModel<JpaPlatform.Config> buildEnabledJpaPlatformConfigsModel() {
- return new StaticCollectionValueModel<JpaPlatform.Config>(
+ return new StaticCollectionValueModel<>(
IterableTools.filter(
getJpaPlatformConfigs(),
new JpaPlatformConfigIsEnabled()
@@ -871,7 +881,7 @@ public class JpaProjectPropertiesPage
}
private JpaProject.Reference getJpaProjectReference() {
- return ((JpaProject.Reference) this.getProject().getAdapter(JpaProject.Reference.class));
+ return this.getProject().getAdapter(JpaProject.Reference.class);
}
@Override
@@ -972,7 +982,7 @@ public class JpaProjectPropertiesPage
JpaPlatform.Config jpaPlatformConfig = this.jpaPlatformConfigModel.getValue();
String jpaPlatformID = (jpaPlatformConfig == null) ? "" : jpaPlatformConfig.getId(); //$NON-NLS-1$
- Map<String, Object> enablementVariables = new HashMap<String, Object>();
+ Map<String, Object> enablementVariables = new HashMap<>();
enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, jpaPlatformID);
enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, this.jpaProjectModel.getValue().getJpaPlatform().getConfig());
@@ -1088,8 +1098,8 @@ public class JpaProjectPropertiesPage
*/
// by default, ExtendedListValueModelWrapper puts a null at the top of the list
private static final ListValueModel<String> CONNECTION_CHOICES_MODEL =
- new ExtendedListValueModelWrapper<String>(
- new SortedListValueModelAdapter<String>(
+ new ExtendedListValueModelWrapper<>(
+ new SortedListValueModelAdapter<>(
new ConnectionChoicesModel(),
STRING_COMPARATOR
)
@@ -1710,63 +1720,158 @@ public class JpaProjectPropertiesPage
* is the JPA project's user override default, otherwise the default is
* determined by the database.
*/
- static class DefaultModel
- extends CompositePropertyValueModel<String, Object>
- implements ModifiablePropertyValueModel<String>
+ static class DefaultDatabaseComponentModelAdapter
+ implements PluggableModifiablePropertyValueModel.Adapter<String>
{
- private final PropertyValueModel<Boolean> userOverrideDefaultFlagModel;
- private final ModifiablePropertyValueModel<String> userOverrideDefaultModel;
- private final PropertyValueModel<String> databaseDefaultModel;
-
- @SuppressWarnings("unchecked")
- DefaultModel(
- PropertyValueModel<Boolean> userOverrideDefaultFlagModel,
- ModifiablePropertyValueModel<String> userOverrideDefaultModel,
- PropertyValueModel<String> databaseDefaultModel
- ) {
- super(userOverrideDefaultFlagModel, userOverrideDefaultModel, databaseDefaultModel);
- this.userOverrideDefaultFlagModel = userOverrideDefaultFlagModel;
- this.userOverrideDefaultModel = userOverrideDefaultModel;
- this.databaseDefaultModel = databaseDefaultModel;
+ private final Factory factory;
+
+ private final PropertyChangeListener userOverrideDefaultFlagListener = new UserOverrideDefaultFlagListener();
+ /* CU private */ volatile boolean userOverrideDefaultFlag = false;
+
+ private final PropertyChangeListener userOverrideDefaultListener = new UserOverrideDefaultListener();
+ /* CU private */ volatile String userOverrideDefault = null;
+
+ private final PropertyChangeListener databaseDefaultListener = new DatabaseDefaultListener();
+ /* 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) {
+ super();
+ if (factory == null) {
+ throw new NullPointerException();
+ }
+ this.factory = factory;
+ if (listener == null) {
+ throw new NullPointerException();
+ }
+ this.listener = listener;
+ }
+
+ public String getValue() {
+ return this.value;
}
/**
- * If the checkbox has been unchecked, we need to clear out the JPA
- * project's user override.
+ * This will be called when the user makes a selection from the
+ * drop-down; which is possible only when the checkbox is checked
+ * (and the drop-down is enabled).
*/
- @Override
- protected void componentChanged(PropertyChangeEvent event) {
- super.componentChanged(event);
- if (event.getSource() == this.userOverrideDefaultFlagModel) {
- if ( ! this.userOverrideDefaultFlagIsSet()) {
- this.userOverrideDefaultModel.setValue(null);
- }
- }
+ public void setValue(String value) {
+ this.factory.userOverrideDefaultModel.setValue(value);
+ }
+
+ public void engageModel() {
+ this.factory.userOverrideDefaultFlagModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.userOverrideDefaultFlagListener);
+ this.factory.userOverrideDefaultModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.userOverrideDefaultListener);
+ this.factory.databaseDefaultModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.databaseDefaultListener);
+ this.value = this.buildValue();
+ }
+
+ public void disengageModel() {
+ this.value = null;
+ this.factory.databaseDefaultModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.databaseDefaultListener);
+ this.factory.userOverrideDefaultModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.userOverrideDefaultListener);
+ this.factory.userOverrideDefaultFlagModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.userOverrideDefaultFlagListener);
+ }
+
+ /* CU private */ void update() {
+ this.listener.valueChanged(this.value = this.buildValue());
}
/**
* If the checkbox is checked, return the user override from the JPA project;
* otherwise return the default from the database
*/
+ private String buildValue() {
+ return this.userOverrideDefaultFlag ? this.userOverrideDefault : this.databaseDefault;
+ }
+
@Override
- protected String buildValue() {
- return this.userOverrideDefaultFlagIsSet() ?
- this.userOverrideDefaultModel.getValue() :
- this.databaseDefaultModel.getValue();
+ public String toString() {
+ return ObjectTools.toString(this, this.value);
}
- /**
- * This will be called when the user makes a selection from the
- * drop-down; which is only possible when the checkbox is checked
- * (and the drop-down is enabled).
- */
- public void setValue(String value) {
- this.userOverrideDefaultModel.setValue(value);
- this.propertyChanged();
+
+ // ********** user override default flag listener **********
+
+ /* CU private */ class UserOverrideDefaultFlagListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DefaultDatabaseComponentModelAdapter.this.userOverrideDefaultFlagChanged(event);
+ }
+ }
+
+ /* CU private */ void userOverrideDefaultFlagChanged(PropertyChangeEvent event) {
+ Boolean newValue = (Boolean) event.getNewValue();
+ this.userOverrideDefaultFlag = (newValue != null) && newValue.booleanValue();
+ this.update();
+
+ // If the checkbox has been unchecked, we need to clear out the JPA project's user override.
+ if ( ! this.userOverrideDefaultFlag) {
+ this.factory.userOverrideDefaultModel.setValue(null);
+ }
}
- private boolean userOverrideDefaultFlagIsSet() {
- return flagIsSet(this.userOverrideDefaultFlagModel);
+
+ // ********** user override default listener **********
+
+ /* CU private */ class UserOverrideDefaultListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DefaultDatabaseComponentModelAdapter.this.userOverrideDefault = (String) event.getNewValue();
+ DefaultDatabaseComponentModelAdapter.this.update();
+ }
+ }
+
+
+ // ********** database default listener **********
+
+ /* CU private */ class DatabaseDefaultListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DefaultDatabaseComponentModelAdapter.this.databaseDefault = (String) event.getNewValue();
+ DefaultDatabaseComponentModelAdapter.this.update();
+ }
+ }
+
+
+ // ********** Factory **********
+
+ public static class Factory
+ implements PluggableModifiablePropertyValueModel.Adapter.Factory<String>
+ {
+ /* CU private */ final PropertyValueModel<Boolean> userOverrideDefaultFlagModel;
+ /* CU private */ final ModifiablePropertyValueModel<String> userOverrideDefaultModel;
+ /* CU private */ final PropertyValueModel<String> databaseDefaultModel;
+
+ public Factory(
+ PropertyValueModel<Boolean> userOverrideDefaultFlagModel,
+ ModifiablePropertyValueModel<String> userOverrideDefaultModel,
+ PropertyValueModel<String> databaseDefaultModel
+ ) {
+ super();
+ this.userOverrideDefaultFlagModel = userOverrideDefaultFlagModel;
+ this.userOverrideDefaultModel = userOverrideDefaultModel;
+ this.databaseDefaultModel = databaseDefaultModel;
+ }
+
+ public DefaultDatabaseComponentModelAdapter buildAdapter(PluggablePropertyValueModel.Adapter.Listener<String> listener) {
+ return new DefaultDatabaseComponentModelAdapter(this, listener);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this);
+ }
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java
index 4075498a62..6b5b3e8c15 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2016 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.structure;
+import java.util.ArrayList;
+import java.util.Collection;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jpt.common.ui.JptCommonUiImages;
@@ -16,11 +18,13 @@ 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.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.internal.model.value.CompositePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+import org.eclipse.jpt.common.utility.internal.model.value.ListValueModelTools;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.JpaContextModel;
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
@@ -109,7 +113,7 @@ public class PersistenceStructureItemLabelProviderFactory
}
protected static PropertyValueModel<ImageDescriptor> buildPersistenceUnitImageDescriptorModel(@SuppressWarnings("unused") PersistenceUnit persistenceUnit) {
- return new StaticPropertyValueModel<ImageDescriptor>(JptJpaUiImages.PERSISTENCE_UNIT);
+ return new StaticPropertyValueModel<>(JptJpaUiImages.PERSISTENCE_UNIT);
}
protected static PropertyValueModel<String> buildPersistenceUnitTextModel(PersistenceUnit persistenceUnit) {
@@ -163,7 +167,7 @@ public class PersistenceStructureItemLabelProviderFactory
protected PropertyValueModel<ImageDescriptor> buildMappingFileRefImageDescriptorModel(MappingFileRef mappingFileRef) {
- return new StaticPropertyValueModel<ImageDescriptor>(JptCommonUiImages.gray(JptJpaUiImages.MAPPING_FILE_REF, mappingFileRef.isDefault()));
+ return new StaticPropertyValueModel<>(JptCommonUiImages.gray(JptJpaUiImages.MAPPING_FILE_REF, mappingFileRef.isDefault()));
}
protected PropertyValueModel<String> buildMappingFileRefTextModel(MappingFileRef mappingFileRef) {
@@ -202,7 +206,7 @@ public class PersistenceStructureItemLabelProviderFactory
}
protected PropertyValueModel<ImageDescriptor> buildClassRefImageDescriptorModel(@SuppressWarnings("unused") ClassRef classRef) {
- return new StaticPropertyValueModel<ImageDescriptor>(JptJpaUiImages.CLASS_REF);
+ return new StaticPropertyValueModel<>(JptJpaUiImages.CLASS_REF);
}
protected PropertyValueModel<String> buildClassRefTextModel(ClassRef classRef) {
@@ -242,7 +246,7 @@ public class PersistenceStructureItemLabelProviderFactory
}
protected PropertyValueModel<ImageDescriptor> buildJarFileRefImageDescriptorModel(@SuppressWarnings("unused") JarFileRef jarFileRef) {
- return new StaticPropertyValueModel<ImageDescriptor>(JptJpaUiImages.JAR_FILE_REF);
+ return new StaticPropertyValueModel<>(JptJpaUiImages.JAR_FILE_REF);
}
protected PropertyValueModel<String> buildJarFileRefTextModel(JarFileRef jarFileRef) {
@@ -276,77 +280,53 @@ public class PersistenceStructureItemLabelProviderFactory
// ********** component description model **********
- @SuppressWarnings("unchecked")
public static PropertyValueModel<String> buildQuotedComponentDescriptionModel(JpaContextModel node, PropertyValueModel<String> nodeTextModel) {
return buildComponentDescriptionModel(node, true, nodeTextModel);
}
+ @SafeVarargs
public static PropertyValueModel<String> buildNonQuotedComponentDescriptionModel(JpaContextModel node, PropertyValueModel<String>... nodeTextModels) {
return buildComponentDescriptionModel(node, false, nodeTextModels);
}
+ @SafeVarargs
protected static PropertyValueModel<String> buildComponentDescriptionModel(JpaContextModel node, boolean quote, PropertyValueModel<String>... nodeTextModels) {
IResource nodeResource = node.getResource();
String nodePath = (nodeResource == null) ? null : nodeResource.getFullPath().makeRelative().toString();
- return new ComponentDescriptionModel(
- nodeTextModels,
- new PersistenceUnitTextModel(node.getPersistenceUnit()),
- nodePath,
- quote
- );
+ TransformerAdapter<Collection<String>, String> transformer = new ComponentDescriptionTransformer(nodePath, quote);
+
+ ArrayList<PropertyValueModel<String>> models = new ArrayList<>();
+ models.add(buildPersistenceUnitTextModel(node.getPersistenceUnit()));
+ CollectionTools.addAll(models, nodeTextModels);
+
+ return ListValueModelTools.compositePropertyValueModel(models, transformer);
}
- public static class ComponentDescriptionModel
- extends CompositePropertyValueModel<String, Object>
+
+ public static class ComponentDescriptionTransformer
+ extends TransformerAdapter<Collection<String>, String>
{
- protected final PropertyValueModel<String>[] nodeTextModels;
- protected final PropertyValueModel<String> persistenceUnitNameModel;
protected final String path;
protected final boolean quote;
- @SuppressWarnings("unchecked")
- ComponentDescriptionModel(
- PropertyValueModel<String> nodeTextModel,
- PropertyValueModel<String> persistenceUnitNameModel,
- String path,
- boolean quote
- ) {
- this(
- new PropertyValueModel[] {nodeTextModel},
- persistenceUnitNameModel,
- path,
- quote
- );
- }
-
- ComponentDescriptionModel(
- PropertyValueModel<String>[] nodeTextModels,
- PropertyValueModel<String> persistenceUnitNameModel,
- String path,
- boolean quote
- ) {
- super(ArrayTools.add(nodeTextModels, persistenceUnitNameModel));
- if (nodeTextModels.length < 1) {
- throw new IllegalArgumentException();
- }
- this.nodeTextModels = nodeTextModels;
- this.persistenceUnitNameModel = persistenceUnitNameModel;
+ ComponentDescriptionTransformer(String path, boolean quote) {
+ super();
this.path = path;
this.quote = quote;
}
@Override
- protected String buildValue() {
+ public String transform(Collection<String> models) {
StringBuilder sb = new StringBuilder();
- sb.append(this.persistenceUnitNameModel.getValue());
+ sb.append(IterableTools.first(models)); // persistence unit
sb.append('/');
if (this.quote) {
sb.append('\"');
}
- sb.append(this.nodeTextModels[0].getValue());
- for (int i = 1; i < this.nodeTextModels.length; i++) {
+ sb.append(IterableTools.get(models, 1)); // nodes
+ for (int i = 2; i < models.size(); i++) {
sb.append('/');
- sb.append(this.nodeTextModels[i].getValue());
+ sb.append(IterableTools.get(models, i));
}
if (this.quote) {
sb.append('\"');

Back to the top