diff options
author | tle | 2010-07-12 01:25:34 +0000 |
---|---|---|
committer | tle | 2010-07-12 01:25:34 +0000 |
commit | 594cdb9a3ebac478f4cedf3e4f7e603ea0986be7 (patch) | |
tree | 3b65d4215f6d3fb6ee1e05f0875ade7d8d24c196 | |
parent | e90055ba993d87bc97ee24c8381468afa0a55fa5 (diff) | |
download | webtools.dali-594cdb9a3ebac478f4cedf3e4f7e603ea0986be7.tar.gz webtools.dali-594cdb9a3ebac478f4cedf3e4f7e603ea0986be7.tar.xz webtools.dali-594cdb9a3ebac478f4cedf3e4f7e603ea0986be7.zip |
294670 - More helpful UI for validation group persistence.xml properties
14 files changed, 1767 insertions, 302 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java index b1af233b21..8641a9ead4 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java @@ -9,7 +9,9 @@ *******************************************************************************/ package org.eclipse.jpt.core.internal.context.persistence; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; @@ -17,6 +19,7 @@ import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; import org.eclipse.jpt.utility.internal.ReflectionTools; +import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.jpt.utility.internal.model.AbstractModel; /** @@ -30,6 +33,7 @@ public abstract class AbstractPersistenceUnitProperties extends AbstractModel // key = PersistenceUnit property key; value = property id private Map<String, String> propertyNames; + public static final String PROPERTY_VALUE_DELIMITER = ","; //$NON-NLS-1$ private static final long serialVersionUID = 1L; // ********** constructors / initialization ********** @@ -81,10 +85,7 @@ public abstract class AbstractPersistenceUnitProperties extends AbstractModel public JpaProject getJpaProject() { return this.persistenceUnit.getJpaProject(); } - - private Map<String, String> propertyNames() { - return this.propertyNames; - } + /** * Adds property names key/value pairs, used by the methods: itemIsProperty * and propertyIdFor. @@ -159,12 +160,6 @@ public abstract class AbstractPersistenceUnitProperties extends AbstractModel } } - private void putPersistenceUnitProperty(String key, String keySuffix, Object value, boolean allowDuplicates) { - String persistenceUnitKey = (keySuffix == null) ? key : key + keySuffix; - String stringValue = (value == null) ? null : value.toString(); - this.getPersistenceUnit().setProperty(persistenceUnitKey, stringValue, allowDuplicates); - } - /** * Removes a persistenceUnit property. * @@ -367,17 +362,60 @@ public abstract class AbstractPersistenceUnitProperties extends AbstractModel this.putPersistenceUnitProperty(key, keySuffix, getPropertyStringValueOf(newValue), allowDuplicate); } + // ****** get/set CompositeValue convenience methods ******* + /** + * Returns the String values of the given Property from the PersistenceXml. + */ + protected List<String> getCompositeValue(String persistenceUnitKey) { + String values = this.getStringValue(persistenceUnitKey); + return this.extractCompositeValue(values); + } + + /** + * Put into persistenceUnit properties. If the property already exists, + * it appends the given value at the end of the property value. + * + * @param key + * @param valueToAppend + */ + protected void putPropertyCompositeValue(String key, String valueToAppend) { + String persistenceUnitKey = this.persistenceUnitKeyOf(key); + + String persistenceUnitValue = this.buildCompositeValue( + this.getStringValue(persistenceUnitKey), valueToAppend); + + this.putPersistenceUnitProperty(persistenceUnitKey, null, persistenceUnitValue, false); + } + + /** + * Removes a value from a property with composite values. + * If the resulting value is empty, the property is removed from the persistenceUnit. + * + * @param key - + * property name + * @param valueToRemove - + * value to remove from the property + */ + protected void removePropertyCompositeValue(String key, String valueToRemove) { + String persistenceUnitKey = this.persistenceUnitKeyOf(key); + + String persistenceUnitValue = this.removeValueFrom( + this.getStringValue(persistenceUnitKey), valueToRemove.trim()); + + this.putPersistenceUnitProperty(persistenceUnitKey, null, persistenceUnitValue, false); + } + // ****** Static methods ******* public static Boolean getBooleanValueOf(String puStringValue) { - if (puStringValue == null) { + if (StringTools.stringIsEmpty(puStringValue)) { return null; } return Boolean.valueOf(puStringValue); } public static Integer getIntegerValueOf(String puStringValue) { - if (puStringValue == null) { + if (StringTools.stringIsEmpty(puStringValue)) { return null; } return Integer.valueOf(puStringValue); @@ -409,4 +447,61 @@ public abstract class AbstractPersistenceUnitProperties extends AbstractModel return value.toString(); } + // ********** internal methods ********** + + private Map<String, String> propertyNames() { + return this.propertyNames; + } + + private void putPersistenceUnitProperty(String key, String keySuffix, Object value, boolean allowDuplicates) { + String persistenceUnitKey = (keySuffix == null) ? key : key + keySuffix; + String stringValue = (value == null) ? null : value.toString(); + this.getPersistenceUnit().setProperty(persistenceUnitKey, stringValue, allowDuplicates); + } + + private String buildCompositeValue(String value, String valueToAppend) { + if((StringTools.stringIsEmpty(valueToAppend)) ) { + return value; + } + return (StringTools.stringIsEmpty(value)) ? + valueToAppend : + (value + PROPERTY_VALUE_DELIMITER + valueToAppend); + } + + protected List<String> extractCompositeValue(String compositeValue) { + if(StringTools.stringIsEmpty(compositeValue)) { + return new ArrayList<String>(0); + } + String[] values = compositeValue.split(PROPERTY_VALUE_DELIMITER); + List<String> results = new ArrayList<String>(values.length); + for(String value : values) { + results.add(value.trim()); + } + return results; + } + + private String removeValueFrom(String compositeValue, String valueToRemove) { + if((StringTools.stringIsEmpty(valueToRemove))) { + return compositeValue; + } + String[] values = compositeValue.split(PROPERTY_VALUE_DELIMITER); + ArrayList<String> results = new ArrayList<String>(values.length); + + for(String value : values) { + if(value.trim().equals(valueToRemove)) { + continue; + } + results.add(value); + } + if(results.isEmpty()) { + return null; + } + StringBuilder sb = new StringBuilder(values.length); + for(String value : results) { + sb.append(value).append(PROPERTY_VALUE_DELIMITER); + } + sb.deleteCharAt(sb.length() - 1); // remove the last delimiter + return sb.toString(); + } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/GenericOptions2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/GenericOptions2_0.java index d9f70492b3..1d73540371 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/GenericOptions2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/GenericOptions2_0.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. +* Copyright (c) 2009, 2010 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,12 +9,15 @@ *******************************************************************************/ package org.eclipse.jpt.core.internal.jpa2.context.persistence.options; +import java.util.List; +import java.util.ListIterator; import java.util.Map; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnitProperties; import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; import org.eclipse.jpt.core.jpa2.context.persistence.options.JpaOptions2_0; +import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; /** * JPA 2.0 options @@ -25,10 +28,9 @@ public class GenericOptions2_0 extends AbstractPersistenceUnitProperties // ********** GenericConnection properties ********** private Integer lockTimeout; private Integer queryTimeout; - private String validationGroupPrePersist; - private String validationGroupPreUpdate; - private String validationGroupPreRemove; - + private List<String> validationGroupPrePersists; + private List<String> validationGroupPreUpdates; + private List<String> validationGroupPreRemoves; // ********** constructors ********** public GenericOptions2_0(PersistenceUnit parent) { @@ -47,12 +49,9 @@ public class GenericOptions2_0 extends AbstractPersistenceUnitProperties this.getIntegerValue(PERSISTENCE_QUERY_TIMEOUT); // ValidationMode is initialized with the persistence unit element - this.validationGroupPrePersist = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST); - this.validationGroupPreUpdate = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE); - this.validationGroupPreRemove = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE); + this.validationGroupPrePersists = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST); + this.validationGroupPreUpdates = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE); + this.validationGroupPreRemoves = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE); } // ********** behavior ********** @@ -65,13 +64,13 @@ public class GenericOptions2_0 extends AbstractPersistenceUnitProperties this.queryTimeoutChanged(newValue); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST)) { - this.validationGroupPrePersistChanged(newValue); + this.validationGroupPrePersistsChanged(); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE)) { - this.validationGroupPreUpdateChanged(newValue); + this.validationGroupPreUpdatesChanged(); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE)) { - this.validationGroupPreRemoveChanged(newValue); + this.validationGroupPreRemovesChanged(); } } @@ -83,13 +82,13 @@ public class GenericOptions2_0 extends AbstractPersistenceUnitProperties this.queryTimeoutChanged(null); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST)) { - this.validationGroupPrePersistChanged(null); + this.validationGroupPrePersistsChanged(); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE)) { - this.validationGroupPreUpdateChanged(null); + this.validationGroupPreUpdatesChanged(); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE)) { - this.validationGroupPreRemoveChanged(null); + this.validationGroupPreRemovesChanged(); } } @@ -170,70 +169,169 @@ public class GenericOptions2_0 extends AbstractPersistenceUnitProperties return DEFAULT_QUERY_TIMEOUT; } + // ********** ValidationGroupPrePersists ********** + public ListIterator<String> validationGroupPrePersists(){ + return new CloneListIterator<String>(this.validationGroupPrePersists); + } + + public int validationGroupPrePersistsSize(){ + return this.validationGroupPrePersists.size(); + } - // ********** ValidationGroupPrePersist ********** - public String getValidationGroupPrePersist() { - return this.validationGroupPrePersist; + public boolean validationGroupPrePersistExists(String validationGroupPrePersistClassName) { + for (String validationGroupPrePersist : this.validationGroupPrePersists) { + if(validationGroupPrePersist.equals(validationGroupPrePersistClassName)) { + return true; + } + } + return false; } + + public String addValidationGroupPrePersist(String newPrePersistClassName){ - public void setValidationGroupPrePersist(String newValidationGroupPrePersist) { - String old = this.validationGroupPrePersist; - this.validationGroupPrePersist = newValidationGroupPrePersist; - this.putProperty(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, newValidationGroupPrePersist); - this.firePropertyChanged(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, old, newValidationGroupPrePersist); + if( ! this.validationGroupPrePersistExists(newPrePersistClassName)) { + this.validationGroupPrePersists.add(newPrePersistClassName); + this.putPropertyCompositeValue(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, newPrePersistClassName); + this.fireListChanged(VALIDATION_GROUP_PRE_PERSIST_LIST, this.validationGroupPrePersists); + return newPrePersistClassName; + } + return null; } + + public void removeValidationGroupPrePersist(String className){ - private void validationGroupPrePersistChanged(String newValue) { - String old = this.validationGroupPrePersist; - this.validationGroupPrePersist = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, old, newValue); + if(this.removeValidationGroupPrePersist_(className) != null) { + this.removePropertyCompositeValue(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, className); + this.fireListChanged(VALIDATION_GROUP_PRE_PERSIST_LIST, this.validationGroupPrePersists); + } } + + private String removeValidationGroupPrePersist_(String className){ - public String getDefaultValidationGroupPrePersist() { - return DEFAULT_VALIDATION_GROUP_PRE_PERSIST; + for ( ListIterator<String> i = this.validationGroupPrePersists(); i.hasNext();) { + String validationGroupPrePersist = i.next(); + if(validationGroupPrePersist.equals(className)) { + this.validationGroupPrePersists.remove(validationGroupPrePersist); + return validationGroupPrePersist; + } + } + return null; } - // ********** ValidationGroupPreUpdate ********** - public String getValidationGroupPreUpdate() { - return this.validationGroupPreUpdate; + private void validationGroupPrePersistsChanged() { + this.validationGroupPrePersists = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST); + this.fireListChanged(VALIDATION_GROUP_PRE_PERSIST_LIST, this.validationGroupPrePersists); } - public void setValidationGroupPreUpdate(String newValidationGroupPreUpdate) { - String old = this.validationGroupPreUpdate; - this.validationGroupPreUpdate = newValidationGroupPreUpdate; - this.putProperty(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, newValidationGroupPreUpdate); - this.firePropertyChanged(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, old, newValidationGroupPreUpdate); + // ********** ValidationGroupPreUpdates ********** + + public ListIterator<String> validationGroupPreUpdates(){ + return new CloneListIterator<String>(this.validationGroupPreUpdates); + } + + public int validationGroupPreUpdatesSize(){ + return this.validationGroupPreUpdates.size(); } - private void validationGroupPreUpdateChanged(String newValue) { - String old = this.validationGroupPreUpdate; - this.validationGroupPreUpdate = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, old, newValue); + public boolean validationGroupPreUpdateExists(String validationGroupPreUpdateClassName) { + + for (String validationGroupPreUpdate : this.validationGroupPreUpdates) { + if(validationGroupPreUpdate.equals(validationGroupPreUpdateClassName)) { + return true; + } + } + return false; } - public String getDefaultValidationGroupPreUpdate() { - return DEFAULT_VALIDATION_GROUP_PRE_UPDATE; + public String addValidationGroupPreUpdate(String newPreUpdateClassName){ + + if( ! this.validationGroupPreUpdateExists(newPreUpdateClassName)) { + this.validationGroupPreUpdates.add(newPreUpdateClassName); + this.putPropertyCompositeValue(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, newPreUpdateClassName); + this.fireListChanged(VALIDATION_GROUP_PRE_UPDATE_LIST, this.validationGroupPreUpdates); + return newPreUpdateClassName; + } + return null; } + + public void removeValidationGroupPreUpdate(String className){ - // ********** ValidationGroupPreRemove ********** - public String getValidationGroupPreRemove() { - return this.validationGroupPreRemove; + if(this.removeValidationGroupPreUpdate_(className) != null) { + this.removePropertyCompositeValue(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, className); + this.fireListChanged(VALIDATION_GROUP_PRE_UPDATE_LIST, this.validationGroupPreUpdates); + } } + + private String removeValidationGroupPreUpdate_(String className){ - public void setValidationGroupPreRemove(String newValidationGroupPreRemove) { - String old = this.validationGroupPreRemove; - this.validationGroupPreRemove = newValidationGroupPreRemove; - this.putProperty(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, newValidationGroupPreRemove); - this.firePropertyChanged(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, old, newValidationGroupPreRemove); + for(ListIterator<String> i = this.validationGroupPreUpdates(); i.hasNext();) { + String validationGroupPreUpdate = i.next(); + if(validationGroupPreUpdate.equals(className)) { + this.validationGroupPreUpdates.remove(validationGroupPreUpdate); + return validationGroupPreUpdate; + } + } + return null; } - private void validationGroupPreRemoveChanged(String newValue) { - String old = this.validationGroupPreRemove; - this.validationGroupPreRemove = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, old, newValue); + private void validationGroupPreUpdatesChanged() { + this.validationGroupPreUpdates = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE); + this.fireListChanged(VALIDATION_GROUP_PRE_UPDATE_LIST, this.validationGroupPreUpdates); + } + + // ********** ValidationGroupPreRemoves ********** + + public ListIterator<String> validationGroupPreRemoves(){ + return new CloneListIterator<String>(this.validationGroupPreRemoves); + } + + public int validationGroupPreRemovesSize(){ + return this.validationGroupPreRemoves.size(); + } + + public boolean validationGroupPreRemoveExists(String validationGroupPreRemoveClassName) { + + for (String validationGroupPreRemove : this.validationGroupPreRemoves) { + if(validationGroupPreRemove.equals(validationGroupPreRemoveClassName)) { + return true; + } + } + return false; + } + + public String addValidationGroupPreRemove(String newPreRemoveClassName){ + + if( ! this.validationGroupPreRemoveExists(newPreRemoveClassName)) { + this.validationGroupPreRemoves.add(newPreRemoveClassName); + this.putPropertyCompositeValue(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, newPreRemoveClassName); + this.fireListChanged(VALIDATION_GROUP_PRE_REMOVE_LIST, this.validationGroupPreRemoves); + return newPreRemoveClassName; + } + return null; + } + + public void removeValidationGroupPreRemove(String className){ + + if(this.removeValidationGroupPreRemove_(className) != null) { + this.removePropertyCompositeValue(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, className); + this.fireListChanged(VALIDATION_GROUP_PRE_REMOVE_LIST, this.validationGroupPreRemoves); + } + } + + private String removeValidationGroupPreRemove_(String className){ + + for(ListIterator<String> i = this.validationGroupPreRemoves(); i.hasNext();) { + String validationGroupPreRemove = i.next(); + if(validationGroupPreRemove.equals(className)) { + this.validationGroupPreRemoves.remove(validationGroupPreRemove); + return validationGroupPreRemove; + } + } + return null; } - public String getDefaultValidationGroupPreRemove() { - return DEFAULT_VALIDATION_GROUP_PRE_REMOVE; + private void validationGroupPreRemovesChanged() { + this.validationGroupPreRemoves = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE); + this.fireListChanged(VALIDATION_GROUP_PRE_REMOVE_LIST, this.validationGroupPreRemoves); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/NullOptions2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/NullOptions2_0.java index a09768382a..de1c93dd74 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/NullOptions2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/NullOptions2_0.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. +* Copyright (c) 2009, 2010 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,10 +9,13 @@ *******************************************************************************/ package org.eclipse.jpt.core.internal.jpa2.context.persistence.options; +import java.util.ListIterator; import java.util.Map; + import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnitProperties; import org.eclipse.jpt.core.jpa2.context.persistence.options.JpaOptions2_0; +import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; /** * JPA 2.0 options @@ -83,42 +86,67 @@ public class NullOptions2_0 extends AbstractPersistenceUnitProperties } - // ********** ValidationGroupPrePersist ********** - public String getValidationGroupPrePersist() { - return null; + // ********** ValidationGroupPrePersists ********** + public ListIterator<String> validationGroupPrePersists() { + return EmptyListIterator.instance(); } - - public void setValidationGroupPrePersist(String newValidationGroupPrePersist) { + + public int validationGroupPrePersistsSize() { + return 0; + } + + public boolean validationGroupPrePersistExists(String validationGroupPrePersistClassName) { + return false; + } + + public String addValidationGroupPrePersist(String newValidationGroupPrePersistClassName) { throw new UnsupportedOperationException(); } - - public String getDefaultValidationGroupPrePersist() { - return DEFAULT_VALIDATION_GROUP_PRE_PERSIST; + + public void removeValidationGroupPrePersist(String validationGroupPrePersistClassName) { + throw new UnsupportedOperationException(); } - // ********** ValidationGroupPreUpdate ********** - public String getValidationGroupPreUpdate() { - return null; + // ********** ValidationGroupPreUpdates ********** + public ListIterator<String> validationGroupPreUpdates() { + return EmptyListIterator.instance(); } - - public void setValidationGroupPreUpdate(String newValidationGroupPreUpdate) { + + public int validationGroupPreUpdatesSize() { + return 0; + } + + public boolean validationGroupPreUpdateExists(String validationGroupPreUpdateClassName) { + return false; + } + + public String addValidationGroupPreUpdate(String newValidationGroupPreUpdateClassName) { throw new UnsupportedOperationException(); } - - public String getDefaultValidationGroupPreUpdate() { - return DEFAULT_VALIDATION_GROUP_PRE_UPDATE; + + public void removeValidationGroupPreUpdate(String validationGroupPreUpdateClassName) { + throw new UnsupportedOperationException(); } - // ********** ValidationGroupPreRemove ********** - public String getValidationGroupPreRemove() { - return null; + // ********** ValidationGroupPreRemoves ********** + public ListIterator<String> validationGroupPreRemoves() { + return EmptyListIterator.instance(); } - - public void setValidationGroupPreRemove(String newValidationGroupPreRemove) { + + public int validationGroupPreRemovesSize() { + return 0; + } + + public boolean validationGroupPreRemoveExists(String validationGroupPreRemoveClassName) { + return false; + } + + public String addValidationGroupPreRemove(String newValidationGroupPreRemoveClassName) { throw new UnsupportedOperationException(); } - - public String getDefaultValidationGroupPreRemove() { - return DEFAULT_VALIDATION_GROUP_PRE_REMOVE; + + public void removeValidationGroupPreRemove(String validationGroupPreRemoveClassName) { + throw new UnsupportedOperationException(); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/persistence/options/JpaOptions2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/persistence/options/JpaOptions2_0.java index 469a7b2f41..7399b3773b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/persistence/options/JpaOptions2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/persistence/options/JpaOptions2_0.java @@ -9,6 +9,8 @@ *******************************************************************************/ package org.eclipse.jpt.core.jpa2.context.persistence.options; +import java.util.ListIterator; + import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; /** @@ -40,28 +42,33 @@ public interface JpaOptions2_0 static final String PERSISTENCE_QUERY_TIMEOUT = "javax.persistence.query.timeout"; //$NON-NLS-1$ static final Integer DEFAULT_QUERY_TIMEOUT = Integer.valueOf(5); - String getDefaultValidationGroupPrePersist(); - String getValidationGroupPrePersist(); - void setValidationGroupPrePersist(String newValidationGroupPrePersist); + ListIterator<String> validationGroupPrePersists(); + int validationGroupPrePersistsSize(); + boolean validationGroupPrePersistExists(String validationGroupPrePersistClassName); + String addValidationGroupPrePersist(String newValidationGroupPrePersistClassName); + void removeValidationGroupPrePersist(String validationGroupPrePersistClassName); + static final String VALIDATION_GROUP_PRE_PERSIST_LIST = "validationGroupPrePersists"; //$NON-NLS-1$ static final String VALIDATION_GROUP_PRE_PERSIST_PROPERTY = "validationGroupPrePersist"; //$NON-NLS-1$ // Property key static final String PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST = "javax.persistence.validation.group.pre-persist"; //$NON-NLS-1$ - static final String DEFAULT_VALIDATION_GROUP_PRE_PERSIST = "Default"; //$NON-NLS-1$ - String getDefaultValidationGroupPreUpdate(); - String getValidationGroupPreUpdate(); - void setValidationGroupPreUpdate(String newValidationGroupPreUpdate); + ListIterator<String> validationGroupPreUpdates(); + int validationGroupPreUpdatesSize(); + boolean validationGroupPreUpdateExists(String validationGroupPreUpdateClassName); + String addValidationGroupPreUpdate(String newValidationGroupPreUpdateClassName); + void removeValidationGroupPreUpdate(String validationGroupPreUpdateClassName); + static final String VALIDATION_GROUP_PRE_UPDATE_LIST = "validationGroupPreUpdates"; //$NON-NLS-1$ static final String VALIDATION_GROUP_PRE_UPDATE_PROPERTY = "validationGroupPreUpdate"; //$NON-NLS-1$ // Property key static final String PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE = "javax.persistence.validation.group.pre-update"; //$NON-NLS-1$ - static final String DEFAULT_VALIDATION_GROUP_PRE_UPDATE = "Default"; //$NON-NLS-1$ - String getDefaultValidationGroupPreRemove(); - String getValidationGroupPreRemove(); - void setValidationGroupPreRemove(String newValidationGroupPreRemove); + ListIterator<String> validationGroupPreRemoves(); + int validationGroupPreRemovesSize(); + boolean validationGroupPreRemoveExists(String validationGroupPreRemoveClassName); + String addValidationGroupPreRemove(String newValidationGroupPreRemoveClassName); + void removeValidationGroupPreRemove(String validationGroupPreRemoveClassName); + static final String VALIDATION_GROUP_PRE_REMOVE_LIST = "validationGroupPreRemoves"; //$NON-NLS-1$ static final String VALIDATION_GROUP_PRE_REMOVE_PROPERTY = "validationGroupPreRemove"; //$NON-NLS-1$ // Property key static final String PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE = "javax.persistence.validation.group.pre-remove"; //$NON-NLS-1$ - static final String DEFAULT_VALIDATION_GROUP_PRE_REMOVE = ""; //$NON-NLS-1$ - } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/persistence/options/EclipseLinkOptions2_0.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/persistence/options/EclipseLinkOptions2_0.java index 7eafd2c02b..c15c672a0a 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/persistence/options/EclipseLinkOptions2_0.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/persistence/options/EclipseLinkOptions2_0.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. +* Copyright (c) 2009, 2010 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,11 +9,14 @@ *******************************************************************************/ package org.eclipse.jpt.eclipselink.core.internal.v2_0.context.persistence.options; +import java.util.List; +import java.util.ListIterator; import java.util.Map; import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.options.EclipseLinkOptions; import org.eclipse.jpt.eclipselink.core.v2_0.context.persistence.options.Options2_0; +import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; /** * EclipseLinkOptions2_0 @@ -24,10 +27,9 @@ public class EclipseLinkOptions2_0 extends EclipseLinkOptions // ********** GenericConnection properties ********** private Integer lockTimeout; private Integer queryTimeout; - private String validationGroupPrePersist; - private String validationGroupPreUpdate; - private String validationGroupPreRemove; - + private List<String> validationGroupPrePersists; + private List<String> validationGroupPreUpdates; + private List<String> validationGroupPreRemoves; // ********** constructors ********** public EclipseLinkOptions2_0(PersistenceUnit2_0 parent) { @@ -48,12 +50,9 @@ public class EclipseLinkOptions2_0 extends EclipseLinkOptions this.getIntegerValue(PERSISTENCE_QUERY_TIMEOUT); // ValidationMode is initialized with the persistence unit element - this.validationGroupPrePersist = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST); - this.validationGroupPreUpdate = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE); - this.validationGroupPreRemove = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE); + this.validationGroupPrePersists = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST); + this.validationGroupPreUpdates = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE); + this.validationGroupPreRemoves = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE); } // ********** behavior ********** @@ -69,13 +68,13 @@ public class EclipseLinkOptions2_0 extends EclipseLinkOptions this.queryTimeoutChanged(newValue); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST)) { - this.validationGroupPrePersistChanged(newValue); + this.validationGroupPrePersistsChanged(); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE)) { - this.validationGroupPreUpdateChanged(newValue); + this.validationGroupPreUpdatesChanged(); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE)) { - this.validationGroupPreRemoveChanged(newValue); + this.validationGroupPreRemovesChanged(); } } @@ -90,13 +89,13 @@ public class EclipseLinkOptions2_0 extends EclipseLinkOptions this.queryTimeoutChanged(null); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST)) { - this.validationGroupPrePersistChanged(null); + this.validationGroupPrePersistsChanged(); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE)) { - this.validationGroupPreUpdateChanged(null); + this.validationGroupPreUpdatesChanged(); } else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE)) { - this.validationGroupPreRemoveChanged(null); + this.validationGroupPreRemovesChanged(); } } @@ -180,70 +179,172 @@ public class EclipseLinkOptions2_0 extends EclipseLinkOptions } - // ********** ValidationGroupPrePersist ********** - public String getValidationGroupPrePersist() { - return this.validationGroupPrePersist; + // ********** ValidationGroupPrePersists ********** + + public ListIterator<String> validationGroupPrePersists(){ + return new CloneListIterator<String>(this.validationGroupPrePersists); + } + + public int validationGroupPrePersistsSize(){ + return this.validationGroupPrePersists.size(); + } + + public boolean validationGroupPrePersistExists(String validationGroupPrePersistClassName) { + + for (String validationGroupPrePersist : this.validationGroupPrePersists) { + if(validationGroupPrePersist.equals(validationGroupPrePersistClassName)) { + return true; + } + } + return false; } - public void setValidationGroupPrePersist(String newValidationGroupPrePersist) { - String old = this.validationGroupPrePersist; - this.validationGroupPrePersist = newValidationGroupPrePersist; - this.putProperty(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, newValidationGroupPrePersist); - this.firePropertyChanged(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, old, newValidationGroupPrePersist); + public String addValidationGroupPrePersist(String newPrePersistClassName){ + + if( ! this.validationGroupPrePersistExists(newPrePersistClassName)) { + this.validationGroupPrePersists.add(newPrePersistClassName); + this.putPropertyCompositeValue(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, newPrePersistClassName); + this.fireListChanged(VALIDATION_GROUP_PRE_PERSIST_LIST, this.validationGroupPrePersists); + return newPrePersistClassName; + } + return null; } + + public void removeValidationGroupPrePersist(String className){ - private void validationGroupPrePersistChanged(String newValue) { - String old = this.validationGroupPrePersist; - this.validationGroupPrePersist = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, old, newValue); + if(this.removeValidationGroupPrePersist_(className) != null) { + this.removePropertyCompositeValue(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, className); + this.fireListChanged(VALIDATION_GROUP_PRE_PERSIST_LIST, this.validationGroupPrePersists); + } + } + + private String removeValidationGroupPrePersist_(String className){ + + for ( ListIterator<String> i = this.validationGroupPrePersists(); i.hasNext();) { + String validationGroupPrePersist = i.next(); + if(validationGroupPrePersist.equals(className)) { + this.validationGroupPrePersists.remove(validationGroupPrePersist); + return validationGroupPrePersist; + } + } + return null; + } + + private void validationGroupPrePersistsChanged() { + this.validationGroupPrePersists = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST); + this.fireListChanged(VALIDATION_GROUP_PRE_PERSIST_LIST, this.validationGroupPrePersists); + } + + // ********** ValidationGroupPreUpdates ********** + + public ListIterator<String> validationGroupPreUpdates(){ + return new CloneListIterator<String>(this.validationGroupPreUpdates); + } + + public int validationGroupPreUpdatesSize(){ + return this.validationGroupPreUpdates.size(); } - public String getDefaultValidationGroupPrePersist() { - return DEFAULT_VALIDATION_GROUP_PRE_PERSIST; + public boolean validationGroupPreUpdateExists(String validationGroupPreUpdateClassName) { + + for (String validationGroupPreUpdate : this.validationGroupPreUpdates) { + if(validationGroupPreUpdate.equals(validationGroupPreUpdateClassName)) { + return true; + } + } + return false; } - // ********** ValidationGroupPreUpdate ********** - public String getValidationGroupPreUpdate() { - return this.validationGroupPreUpdate; + public String addValidationGroupPreUpdate(String newPreUpdateClassName){ + + if( ! this.validationGroupPreUpdateExists(newPreUpdateClassName)) { + this.validationGroupPreUpdates.add(newPreUpdateClassName); + this.putPropertyCompositeValue(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, newPreUpdateClassName); + this.fireListChanged(VALIDATION_GROUP_PRE_UPDATE_LIST, this.validationGroupPreUpdates); + return newPreUpdateClassName; + } + return null; } + + public void removeValidationGroupPreUpdate(String className){ - public void setValidationGroupPreUpdate(String newValidationGroupPreUpdate) { - String old = this.validationGroupPreUpdate; - this.validationGroupPreUpdate = newValidationGroupPreUpdate; - this.putProperty(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, newValidationGroupPreUpdate); - this.firePropertyChanged(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, old, newValidationGroupPreUpdate); + if(this.removeValidationGroupPreUpdate_(className) != null) { + this.removePropertyCompositeValue(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, className); + this.fireListChanged(VALIDATION_GROUP_PRE_UPDATE_LIST, this.validationGroupPreUpdates); + } } + + private String removeValidationGroupPreUpdate_(String className){ - private void validationGroupPreUpdateChanged(String newValue) { - String old = this.validationGroupPreUpdate; - this.validationGroupPreUpdate = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, old, newValue); + for(ListIterator<String> i = this.validationGroupPreUpdates(); i.hasNext();) { + String validationGroupPreUpdate = i.next(); + if(validationGroupPreUpdate.equals(className)) { + this.validationGroupPreUpdates.remove(validationGroupPreUpdate); + return validationGroupPreUpdate; + } + } + return null; } - public String getDefaultValidationGroupPreUpdate() { - return DEFAULT_VALIDATION_GROUP_PRE_UPDATE; + private void validationGroupPreUpdatesChanged() { + this.validationGroupPreUpdates = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE); + this.fireListChanged(VALIDATION_GROUP_PRE_UPDATE_LIST, this.validationGroupPreUpdates); } - // ********** ValidationGroupPreRemove ********** - public String getValidationGroupPreRemove() { - return this.validationGroupPreRemove; + // ********** ValidationGroupPreRemoves ********** + + public ListIterator<String> validationGroupPreRemoves(){ + return new CloneListIterator<String>(this.validationGroupPreRemoves); } + + public int validationGroupPreRemovesSize(){ + return this.validationGroupPreRemoves.size(); + } + + public boolean validationGroupPreRemoveExists(String validationGroupPreRemoveClassName) { - public void setValidationGroupPreRemove(String newValidationGroupPreRemove) { - String old = this.validationGroupPreRemove; - this.validationGroupPreRemove = newValidationGroupPreRemove; - this.putProperty(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, newValidationGroupPreRemove); - this.firePropertyChanged(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, old, newValidationGroupPreRemove); + for (String validationGroupPreRemove : this.validationGroupPreRemoves) { + if(validationGroupPreRemove.equals(validationGroupPreRemoveClassName)) { + return true; + } + } + return false; } - private void validationGroupPreRemoveChanged(String newValue) { - String old = this.validationGroupPreRemove; - this.validationGroupPreRemove = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, old, newValue); + public String addValidationGroupPreRemove(String newPreRemoveClassName){ + + if( ! this.validationGroupPreRemoveExists(newPreRemoveClassName)) { + this.validationGroupPreRemoves.add(newPreRemoveClassName); + this.putPropertyCompositeValue(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, newPreRemoveClassName); + this.fireListChanged(VALIDATION_GROUP_PRE_REMOVE_LIST, this.validationGroupPreRemoves); + return newPreRemoveClassName; + } + return null; } + + public void removeValidationGroupPreRemove(String className){ - public String getDefaultValidationGroupPreRemove() { - return DEFAULT_VALIDATION_GROUP_PRE_REMOVE; + if(this.removeValidationGroupPreRemove_(className) != null) { + this.removePropertyCompositeValue(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, className); + this.fireListChanged(VALIDATION_GROUP_PRE_REMOVE_LIST, this.validationGroupPreRemoves); + } } + private String removeValidationGroupPreRemove_(String className){ + + for(ListIterator<String> i = this.validationGroupPreRemoves(); i.hasNext();) { + String validationGroupPreRemove = i.next(); + if(validationGroupPreRemove.equals(className)) { + this.validationGroupPreRemoves.remove(validationGroupPreRemove); + return validationGroupPreRemove; + } + } + return null; + } + + private void validationGroupPreRemovesChanged() { + this.validationGroupPreRemoves = this.getCompositeValue(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE); + this.fireListChanged(VALIDATION_GROUP_PRE_REMOVE_LIST, this.validationGroupPreRemoves); + } + } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties index b71d2951c5..580d720fbf 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties @@ -339,6 +339,8 @@ PersistenceXmlOptionsTab_miscellaneousSectionDescription = Configure the miscell PersistenceXmlOptionsTab_temporalMutableLabel = Temporal mutable PersistenceXmlOptionsTab_temporalMutableLabelDefault = Temporal mutable ({0}) +PersistenceXmlOptionsTab_noName=<name not set> + TargetDatabaseComposite_attunity = Attunity TargetDatabaseComposite_auto = Auto TargetDatabaseComposite_cloudscape = Cloudscape diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkUiMessages.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkUiMessages.java index 90a37382a8..21c65dd354 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkUiMessages.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkUiMessages.java @@ -368,9 +368,10 @@ public class EclipseLinkUiMessages { public static String TargetDatabaseComposite_sqlserver; public static String TargetDatabaseComposite_sybase; public static String TargetDatabaseComposite_timesten; - - public static String PersistenceXmlOptionsTab_targetServerLabel; + public static String PersistenceXmlOptionsTab_targetServerLabel; + public static String PersistenceXmlOptionsTab_noName; + public static String TargetServerComposite_none; public static String TargetServerComposite_oc4j; public static String TargetServerComposite_sunas9; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/v2_0/persistence/options/ValidationConfigurationComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/v2_0/persistence/options/ValidationConfigurationComposite.java index 2ec755330b..4aa350f80b 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/v2_0/persistence/options/ValidationConfigurationComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/v2_0/persistence/options/ValidationConfigurationComposite.java @@ -9,15 +9,41 @@ *******************************************************************************/ package org.eclipse.jpt.eclipselink.ui.internal.v2_0.persistence.options; +import java.util.ListIterator; + +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.search.IJavaSearchScope; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.ui.IJavaElementSearchConstants; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.window.Window; import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; import org.eclipse.jpt.eclipselink.core.v2_0.context.persistence.options.Options2_0; +import org.eclipse.jpt.eclipselink.ui.JptEclipseLinkUiPlugin; +import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; +import org.eclipse.jpt.ui.internal.JptUiMessages; import org.eclipse.jpt.ui.internal.jpa2.persistence.JptUiPersistence2_0Messages; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; import org.eclipse.jpt.ui.internal.widgets.Pane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; +import org.eclipse.jpt.utility.model.value.ListValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.SelectionDialog; +import org.eclipse.ui.progress.IProgressService; /** * ValidationConfigurationComposite @@ -45,84 +71,312 @@ public class ValidationConfigurationComposite extends Pane<Options2_0> // ValidationMode new ValidationModeComposite(this, this.buildPersistenceUnit2_0Holder(), parent); - // GroupPrePersist - this.addLabeledText( - parent, - JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPrePersistLabel, - this.buildValidationGroupPrePersistHolder() - ); + // ValidationGroupPrePersist + this.addGroupPrePersistListPane(parent); // ValidationGroupPreUpdate - this.addLabeledText( - parent, - JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPreUpdateLabel, - this.buildValidationGroupPreUpdateHolder() - ); + this.addGroupPreUpdateListPane(parent); // ValidationGroupPreRemove - this.addLabeledText( - parent, - JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPreRemoveLabel, - this.buildValidationGroupPreRemoveHolder() - ); + this.addGroupPreRemoveListPane(parent); } + + // ********** ValidationGroupPrePersists ********** - private PropertyValueModel<PersistenceUnit2_0> buildPersistenceUnit2_0Holder() { - return new TransformationPropertyValueModel<Options2_0, PersistenceUnit2_0>(this.getSubjectHolder()) { + private void addGroupPrePersistListPane(Composite parent) { + + this.addLabeledComposite(parent, + JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPrePersistLabel, + this.addPrePersistListPane(parent), + null // TODO Help + ); + } + + private AddRemoveListPane<Options2_0> addPrePersistListPane(Composite parent) { + + // List pane + AddRemoveListPane<Options2_0> listPane = new AddRemoveListPane<Options2_0>( + this, + parent, + this.buildPrePersistAdapter(), + this.buildPrePersistListHolder(), + this.buildSelectedItemHolder(), + this.buildLabelProvider() + ) + { @Override - protected PersistenceUnit2_0 transform_(Options2_0 value) { - return (PersistenceUnit2_0) value.getPersistenceUnit(); + protected void initializeTable(Table table) { + super.initializeTable(table); + + Composite container = table.getParent(); + GridData gridData = (GridData) container.getLayoutData(); + gridData.heightHint = 75; } }; + return listPane; } - private WritablePropertyValueModel<String> buildValidationGroupPrePersistHolder() { - return new PropertyAspectAdapter<Options2_0, String>(this.getSubjectHolder(), Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY) { + private Adapter buildPrePersistAdapter() { + return new AddRemoveListPane.AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + addPrePersistClass(listSelectionModel); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + for (Object item : listSelectionModel.selectedValues()) { + getSubject().removeValidationGroupPrePersist((String) item); + } + } + }; + } + + private ListValueModel<String> buildPrePersistListHolder() { + return new ListAspectAdapter<Options2_0, String>(getSubjectHolder(), Options2_0.VALIDATION_GROUP_PRE_PERSIST_LIST) { + @Override + protected ListIterator<String> listIterator_() { + return subject.validationGroupPrePersists(); + } + @Override - protected String buildValue_() { - return this.subject.getValidationGroupPrePersist(); + protected int size_() { + return subject.validationGroupPrePersistsSize(); + } + }; + } + + private void addPrePersistClass(ObjectListSelectionModel listSelectionModel) { + + IType type = this.chooseType(); + + if (type != null) { + String className = type.getFullyQualifiedName('$'); + if( ! this.getSubject().validationGroupPrePersistExists(className)) { + + String classRef = this.getSubject().addValidationGroupPrePersist(className); + listSelectionModel.setSelectedValue(classRef); } + } + } + + // ********** ValidationGroupPreUpdates ********** + + private void addGroupPreUpdateListPane(Composite parent) { + this.addLabeledComposite(parent, + JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPreUpdateLabel, + this.addPreUpdateListPane(parent), + null // TODO Help + ); + } + + private AddRemoveListPane<Options2_0> addPreUpdateListPane(Composite parent) { + + // List pane + AddRemoveListPane<Options2_0> listPane = new AddRemoveListPane<Options2_0>( + this, + parent, + this.buildPreUpdateAdapter(), + this.buildPreUpdateListHolder(), + this.buildSelectedItemHolder(), + this.buildLabelProvider() + ) + { @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; + protected void initializeTable(Table table) { + super.initializeTable(table); + + Composite container = table.getParent(); + GridData gridData = (GridData) container.getLayoutData(); + gridData.heightHint = 75; + } + }; + return listPane; + } + + private Adapter buildPreUpdateAdapter() { + return new AddRemoveListPane.AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + addPreUpdateClass(listSelectionModel); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + for (Object item : listSelectionModel.selectedValues()) { + getSubject().removeValidationGroupPreUpdate((String) item); } - this.subject.setValidationGroupPrePersist(value); } }; } - private WritablePropertyValueModel<String> buildValidationGroupPreUpdateHolder() { - return new PropertyAspectAdapter<Options2_0, String>(this.getSubjectHolder(), Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY) { + private ListValueModel<String> buildPreUpdateListHolder() { + return new ListAspectAdapter<Options2_0, String>(getSubjectHolder(), Options2_0.VALIDATION_GROUP_PRE_UPDATE_LIST) { + @Override + protected ListIterator<String> listIterator_() { + return subject.validationGroupPreUpdates(); + } + @Override - protected String buildValue_() { - return this.subject.getValidationGroupPreUpdate(); + protected int size_() { + return subject.validationGroupPreUpdatesSize(); + } + }; + } + + private void addPreUpdateClass(ObjectListSelectionModel listSelectionModel) { + + IType type = this.chooseType(); + + if (type != null) { + String className = type.getFullyQualifiedName('$'); + if( ! this.getSubject().validationGroupPreUpdateExists(className)) { + + String classRef = this.getSubject().addValidationGroupPreUpdate(className); + listSelectionModel.setSelectedValue(classRef); } + } + } + + // ********** ValidationGroupPreRemoves ********** + + private void addGroupPreRemoveListPane(Composite parent) { + this.addLabeledComposite(parent, + JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPreRemoveLabel, + this.addPreRemoveListPane(parent), + null // TODO Help + ); + } + + private AddRemoveListPane<Options2_0> addPreRemoveListPane(Composite parent) { + + // List pane + AddRemoveListPane<Options2_0> listPane = new AddRemoveListPane<Options2_0>( + this, + parent, + this.buildPreRemoveAdapter(), + this.buildPreRemoveListHolder(), + this.buildSelectedItemHolder(), + this.buildLabelProvider() + ) + { @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; + protected void initializeTable(Table table) { + super.initializeTable(table); + + Composite container = table.getParent(); + GridData gridData = (GridData) container.getLayoutData(); + gridData.heightHint = 75; + } + }; + return listPane; + } + + private Adapter buildPreRemoveAdapter() { + return new AddRemoveListPane.AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + addPreRemoveClass(listSelectionModel); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + for (Object item : listSelectionModel.selectedValues()) { + getSubject().removeValidationGroupPreRemove((String) item); } - this.subject.setValidationGroupPreUpdate(value); } }; } - private WritablePropertyValueModel<String> buildValidationGroupPreRemoveHolder() { - return new PropertyAspectAdapter<Options2_0, String>(this.getSubjectHolder(), Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY) { + private ListValueModel<String> buildPreRemoveListHolder() { + return new ListAspectAdapter<Options2_0, String>(getSubjectHolder(), Options2_0.VALIDATION_GROUP_PRE_REMOVE_LIST) { @Override - protected String buildValue_() { - return this.subject.getValidationGroupPreRemove(); + protected ListIterator<String> listIterator_() { + return subject.validationGroupPreRemoves(); + } + + @Override + protected int size_() { + return subject.validationGroupPreRemovesSize(); + } + }; + } + + private void addPreRemoveClass(ObjectListSelectionModel listSelectionModel) { + + IType type = this.chooseType(); + + if (type != null) { + String className = type.getFullyQualifiedName('$'); + if( ! this.getSubject().validationGroupPreRemoveExists(className)) { + + String classRef = this.getSubject().addValidationGroupPreRemove(className); + listSelectionModel.setSelectedValue(classRef); } + } + } + + + // ********** Private methods ********** + + private ILabelProvider buildLabelProvider() { + return new LabelProvider() { @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; + public String getText(Object element) { + String name = (String) element; + + if (name == null) { + name = EclipseLinkUiMessages.PersistenceXmlOptionsTab_noName; } - this.subject.setValidationGroupPreRemove(value); + return name; + } + }; + } + + /** + * Prompts the user the Open Type dialog. + * + * @return Either the selected type or <code>null</code> if the user + * canceled the dialog + */ + private IType chooseType() { + IJavaProject javaProject = this.getSubject().getJpaProject().getJavaProject(); + IJavaElement[] elements = new IJavaElement[] { javaProject }; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements); + IProgressService service = PlatformUI.getWorkbench().getProgressService(); + SelectionDialog typeSelectionDialog; + + try { + typeSelectionDialog = JavaUI.createTypeDialog( + getShell(), + service, + scope, + IJavaElementSearchConstants.CONSIDER_CLASSES, + false, + "" + ); + } + catch (JavaModelException e) { + JptEclipseLinkUiPlugin.log(e); + return null; + } + + typeSelectionDialog.setTitle(JptUiMessages.ClassChooserPane_dialogTitle); + typeSelectionDialog.setMessage(JptUiMessages.ClassChooserPane_dialogMessage); + + if (typeSelectionDialog.open() == Window.OK) { + return (IType) typeSelectionDialog.getResult()[0]; + } + + return null; + } + + private WritablePropertyValueModel<String> buildSelectedItemHolder() { + return new SimplePropertyValueModel<String>(); + } + + private PropertyValueModel<PersistenceUnit2_0> buildPersistenceUnit2_0Holder() { + return new TransformationPropertyValueModel<Options2_0, PersistenceUnit2_0>(this.getSubjectHolder()) { + @Override + protected PersistenceUnit2_0 transform_(Options2_0 value) { + return (PersistenceUnit2_0) value.getPersistenceUnit(); } }; } diff --git a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence2_0.properties b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence2_0.properties index 7603cf1293..49a4408d61 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence2_0.properties +++ b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence2_0.properties @@ -23,6 +23,7 @@ GenericPersistenceUnit2_0ConnectionTab_title = Connection GenericPersistenceUnit2_0OptionsComposite_miscellaneousSectionTitle = Miscellaneous Options GenericPersistenceUnit2_0OptionsComposite_miscellaneousSectionDescription = Configure the miscellaneous options. GenericPersistenceUnit2_0OptionsTab_title = Options +GenericPersistenceUnit2_0OptionsTab_noName = <name not set> JdbcConnectionPropertiesComposite_populateFromConnectionHyperLink = Populate from connection... JdbcConnectionPropertiesComposite_driverLabel = Driver: diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/persistence/JptUiPersistence2_0Messages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/persistence/JptUiPersistence2_0Messages.java index 351aaa6639..8616ad41c7 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/persistence/JptUiPersistence2_0Messages.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/persistence/JptUiPersistence2_0Messages.java @@ -29,6 +29,7 @@ public class JptUiPersistence2_0Messages public static String GenericPersistenceUnit2_0OptionsComposite_miscellaneousSectionTitle; public static String GenericPersistenceUnit2_0OptionsComposite_miscellaneousSectionDescription; public static String GenericPersistenceUnit2_0OptionsTab_title; + public static String GenericPersistenceUnit2_0OptionsTab_noName; public static String JdbcConnectionPropertiesComposite_ConnectionDialog_Message; public static String JdbcConnectionPropertiesComposite_ConnectionDialog_Title; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/persistence/options/ValidationConfigurationComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/persistence/options/ValidationConfigurationComposite.java index 3e944bd0b7..f4bb341b6f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/persistence/options/ValidationConfigurationComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jpa2/persistence/options/ValidationConfigurationComposite.java @@ -9,14 +9,40 @@ *******************************************************************************/ package org.eclipse.jpt.ui.internal.jpa2.persistence.options; +import java.util.ListIterator; + +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.search.IJavaSearchScope; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.ui.IJavaElementSearchConstants; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.window.Window; import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; import org.eclipse.jpt.core.jpa2.context.persistence.options.JpaOptions2_0; +import org.eclipse.jpt.ui.JptUiPlugin; +import org.eclipse.jpt.ui.internal.JptUiMessages; import org.eclipse.jpt.ui.internal.jpa2.persistence.JptUiPersistence2_0Messages; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; import org.eclipse.jpt.ui.internal.widgets.Pane; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; +import org.eclipse.jpt.utility.model.value.ListValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.SelectionDialog; +import org.eclipse.ui.progress.IProgressService; /** * ValidationConfigurationComposite @@ -46,86 +72,314 @@ public class ValidationConfigurationComposite extends Pane<JpaOptions2_0> // ValidationMode new ValidationModeComposite(this, this.buildPersistenceUnit2_0Holder(), parent); - - // GroupPrePersist - this.addLabeledText( - parent, - JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPrePersistLabel, - this.buildValidationGroupPrePersistHolder() - ); + + // ValidationGroupPrePersist + this.addGroupPrePersistListPane(parent); // ValidationGroupPreUpdate - this.addLabeledText( - parent, - JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPreUpdateLabel, - this.buildValidationGroupPreUpdateHolder() - ); + this.addGroupPreUpdateListPane(parent); // ValidationGroupPreRemove - this.addLabeledText( - parent, - JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPreRemoveLabel, - this.buildValidationGroupPreRemoveHolder() - ); + this.addGroupPreRemoveListPane(parent); } + + // ********** ValidationGroupPrePersists ********** - private PropertyValueModel<PersistenceUnit2_0> buildPersistenceUnit2_0Holder() { - return new PropertyAspectAdapter<JpaOptions2_0, PersistenceUnit2_0>(this.getSubjectHolder()) { + private void addGroupPrePersistListPane(Composite parent) { + + this.addLabeledComposite(parent, + JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPrePersistLabel, + this.addPrePersistListPane(parent), + null // TODO Help + ); + } + + private AddRemoveListPane<JpaOptions2_0> addPrePersistListPane(Composite parent) { + + // List pane + AddRemoveListPane<JpaOptions2_0> listPane = new AddRemoveListPane<JpaOptions2_0>( + this, + parent, + this.buildPrePersistAdapter(), + this.buildPrePersistListHolder(), + this.buildSelectedItemHolder(), + this.buildLabelProvider() + ) + { @Override - protected PersistenceUnit2_0 buildValue_() { - return (PersistenceUnit2_0) this.subject.getPersistenceUnit(); + protected void initializeTable(Table table) { + super.initializeTable(table); + + Composite container = table.getParent(); + GridData gridData = (GridData) container.getLayoutData(); + gridData.heightHint = 75; + } + }; + return listPane; + } + + private Adapter buildPrePersistAdapter() { + return new AddRemoveListPane.AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + addPrePersistClass(listSelectionModel); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + for (Object item : listSelectionModel.selectedValues()) { + getSubject().removeValidationGroupPrePersist((String) item); + } } }; } - private WritablePropertyValueModel<String> buildValidationGroupPrePersistHolder() { - return new PropertyAspectAdapter<JpaOptions2_0, String>(this.getSubjectHolder(), JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY) { + private ListValueModel<String> buildPrePersistListHolder() { + return new ListAspectAdapter<JpaOptions2_0, String>(getSubjectHolder(), JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST) { @Override - protected String buildValue_() { - return this.subject.getValidationGroupPrePersist(); + protected ListIterator<String> listIterator_() { + return subject.validationGroupPrePersists(); } @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; + protected int size_() { + return subject.validationGroupPrePersistsSize(); + } + }; + } + + private void addPrePersistClass(ObjectListSelectionModel listSelectionModel) { + + IType type = this.chooseType(); + + if (type != null) { + String className = type.getFullyQualifiedName('$'); + if( ! this.getSubject().validationGroupPrePersistExists(className)) { + + String classRef = this.getSubject().addValidationGroupPrePersist(className); + listSelectionModel.setSelectedValue(classRef); + } + } + } + + // ********** ValidationGroupPreUpdates ********** + + private void addGroupPreUpdateListPane(Composite parent) { + + this.addLabeledComposite(parent, + JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPreUpdateLabel, + this.addPreUpdateListPane(parent), + null // TODO Help + ); + } + + private AddRemoveListPane<JpaOptions2_0> addPreUpdateListPane(Composite parent) { + + // List pane + AddRemoveListPane<JpaOptions2_0> listPane = new AddRemoveListPane<JpaOptions2_0>( + this, + parent, + this.buildPreUpdateAdapter(), + this.buildPreUpdateListHolder(), + this.buildSelectedItemHolder(), + this.buildLabelProvider() + ) + { + @Override + protected void initializeTable(Table table) { + super.initializeTable(table); + + Composite container = table.getParent(); + GridData gridData = (GridData) container.getLayoutData(); + gridData.heightHint = 75; + } + }; + return listPane; + } + + private Adapter buildPreUpdateAdapter() { + return new AddRemoveListPane.AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + addPreUpdateClass(listSelectionModel); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + for (Object item : listSelectionModel.selectedValues()) { + getSubject().removeValidationGroupPreUpdate((String) item); } - this.subject.setValidationGroupPrePersist(value); } }; } - private WritablePropertyValueModel<String> buildValidationGroupPreUpdateHolder() { - return new PropertyAspectAdapter<JpaOptions2_0, String>(this.getSubjectHolder(), JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY) { + private ListValueModel<String> buildPreUpdateListHolder() { + return new ListAspectAdapter<JpaOptions2_0, String>(getSubjectHolder(), JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST) { @Override - protected String buildValue_() { - return this.subject.getValidationGroupPreUpdate(); + protected ListIterator<String> listIterator_() { + return subject.validationGroupPreUpdates(); } @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; + protected int size_() { + return subject.validationGroupPreUpdatesSize(); + } + }; + } + + private void addPreUpdateClass(ObjectListSelectionModel listSelectionModel) { + + IType type = this.chooseType(); + + if (type != null) { + String className = type.getFullyQualifiedName('$'); + if( ! this.getSubject().validationGroupPreUpdateExists(className)) { + + String classRef = this.getSubject().addValidationGroupPreUpdate(className); + listSelectionModel.setSelectedValue(classRef); + } + } + } + + // ********** ValidationGroupPreRemoves ********** + + private void addGroupPreRemoveListPane(Composite parent) { + + this.addLabeledComposite(parent, + JptUiPersistence2_0Messages.ValidationConfigurationComposite_groupPreRemoveLabel, + this.addPreRemoveListPane(parent), + null // TODO Help + ); + } + + private AddRemoveListPane<JpaOptions2_0> addPreRemoveListPane(Composite parent) { + + // List pane + AddRemoveListPane<JpaOptions2_0> listPane = new AddRemoveListPane<JpaOptions2_0>( + this, + parent, + this.buildPreRemoveAdapter(), + this.buildPreRemoveListHolder(), + this.buildSelectedItemHolder(), + this.buildLabelProvider() + ) + { + @Override + protected void initializeTable(Table table) { + super.initializeTable(table); + + Composite container = table.getParent(); + GridData gridData = (GridData) container.getLayoutData(); + gridData.heightHint = 75; + } + }; + return listPane; + } + + private Adapter buildPreRemoveAdapter() { + return new AddRemoveListPane.AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + addPreRemoveClass(listSelectionModel); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + for (Object item : listSelectionModel.selectedValues()) { + getSubject().removeValidationGroupPreRemove((String) item); } - this.subject.setValidationGroupPreUpdate(value); } }; } - private WritablePropertyValueModel<String> buildValidationGroupPreRemoveHolder() { - return new PropertyAspectAdapter<JpaOptions2_0, String>(this.getSubjectHolder(), JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY) { + private ListValueModel<String> buildPreRemoveListHolder() { + return new ListAspectAdapter<JpaOptions2_0, String>(getSubjectHolder(), JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST) { + @Override + protected ListIterator<String> listIterator_() { + return subject.validationGroupPreRemoves(); + } + + @Override + protected int size_() { + return subject.validationGroupPreRemovesSize(); + } + }; + } + + private void addPreRemoveClass(ObjectListSelectionModel listSelectionModel) { + + IType type = this.chooseType(); + + if (type != null) { + String className = type.getFullyQualifiedName('$'); + if( ! this.getSubject().validationGroupPreRemoveExists(className)) { + + String classRef = this.getSubject().addValidationGroupPreRemove(className); + listSelectionModel.setSelectedValue(classRef); + } + } + } + + + // ********** Private methods ********** + + private PropertyValueModel<PersistenceUnit2_0> buildPersistenceUnit2_0Holder() { + return new PropertyAspectAdapter<JpaOptions2_0, PersistenceUnit2_0>(this.getSubjectHolder()) { @Override - protected String buildValue_() { - return this.subject.getValidationGroupPreRemove(); + protected PersistenceUnit2_0 buildValue_() { + return (PersistenceUnit2_0) this.subject.getPersistenceUnit(); } + }; + } + + private ILabelProvider buildLabelProvider() { + return new LabelProvider() { @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; + public String getText(Object element) { + String name = (String) element; + + if (name == null) { + name = JptUiPersistence2_0Messages.GenericPersistenceUnit2_0OptionsTab_noName; } - this.subject.setValidationGroupPreRemove(value); + return name; } }; } + + /** + * Prompts the user the Open Type dialog. + * + * @return Either the selected type or <code>null</code> if the user + * canceled the dialog + */ + private IType chooseType() { + IJavaProject javaProject = this.getSubject().getJpaProject().getJavaProject(); + IJavaElement[] elements = new IJavaElement[] { javaProject }; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements); + IProgressService service = PlatformUI.getWorkbench().getProgressService(); + SelectionDialog typeSelectionDialog; + + try { + typeSelectionDialog = JavaUI.createTypeDialog( + getShell(), + service, + scope, + IJavaElementSearchConstants.CONSIDER_CLASSES, + false, + "" + ); + } + catch (JavaModelException e) { + JptUiPlugin.log(e); + return null; + } + + typeSelectionDialog.setTitle(JptUiMessages.ClassChooserPane_dialogTitle); + typeSelectionDialog.setMessage(JptUiMessages.ClassChooserPane_dialogMessage); + + if (typeSelectionDialog.open() == Window.OK) { + return (IType) typeSelectionDialog.getResult()[0]; + } + + return null; + } + + private WritablePropertyValueModel<String> buildSelectedItemHolder() { + return new SimplePropertyValueModel<String>(); + } }
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTestCase.java index 2417931e9f..d22ed80877 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTestCase.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTestCase.java @@ -9,6 +9,8 @@ *******************************************************************************/ package org.eclipse.jpt.core.tests.internal.context.persistence; +import java.util.Iterator; + import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnitProperties; @@ -78,6 +80,13 @@ public abstract class PersistenceUnitTestCase extends ContextModelTestCase return AbstractPersistenceUnitProperties.getPropertyStringValueOf(value); } + protected <E> E getFirstElement(Iterator<E> iterator) { + if(iterator.hasNext()) { + return iterator.next(); + } + return null; + } + /** * Put into persistenceUnit properties. Do not allows to put duplicate entry. * diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java index 792714b239..4682c5f035 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. +* Copyright (c) 2009, 2010 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,8 +9,17 @@ *******************************************************************************/ package org.eclipse.jpt.core.tests.internal.jpa2.context.persistence; +import java.util.ListIterator; + import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; import org.eclipse.jpt.core.jpa2.context.persistence.options.JpaOptions2_0; +import org.eclipse.jpt.utility.model.event.ListAddEvent; +import org.eclipse.jpt.utility.model.event.ListChangeEvent; +import org.eclipse.jpt.utility.model.event.ListClearEvent; +import org.eclipse.jpt.utility.model.event.ListMoveEvent; +import org.eclipse.jpt.utility.model.event.ListRemoveEvent; +import org.eclipse.jpt.utility.model.event.ListReplaceEvent; +import org.eclipse.jpt.utility.model.listener.ListChangeListener; import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; /** @@ -20,6 +29,9 @@ import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests { private JpaOptions2_0 options; + private ListChangeEvent prePersistEvent; + private ListChangeEvent preUpdateEvent; + private ListChangeEvent preRemoveEvent; public static final String LOCK_TIMEOUT_KEY = JpaOptions2_0.PERSISTENCE_LOCK_TIMEOUT; public static final Integer LOCK_TIMEOUT_TEST_VALUE = 100; @@ -59,6 +71,11 @@ public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests this.options.addPropertyChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, propertyChangeListener); this.options.addPropertyChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, propertyChangeListener); + ListChangeListener validationGroupListChangeListener = this.buildValidationGroupListChangeListener(); + this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST, validationGroupListChangeListener); + this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST, validationGroupListChangeListener); + this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST, validationGroupListChangeListener); + this.clearEvent(); } @@ -76,9 +93,9 @@ public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests this.persistenceUnitSetProperty(QUERY_TIMEOUT_KEY, QUERY_TIMEOUT_TEST_VALUE.toString()); this.persistenceUnitSetProperty("misc.property.3", "value.3"); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE.toString()); + this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); + this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); + this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); } @Override @@ -93,17 +110,23 @@ public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests modelValue = this.options.getLockTimeout(); else if (propertyName.equals(JpaOptions2_0.QUERY_TIMEOUT_PROPERTY)) modelValue = this.options.getQueryTimeout(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - modelValue = this.options.getValidationGroupPrePersist(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - modelValue = this.options.getValidationGroupPreUpdate(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - modelValue = this.options.getValidationGroupPreRemove(); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) { + ListIterator<String> iterator = this.options.validationGroupPrePersists(); + modelValue = this.getFirstElement(iterator); + } + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) { + ListIterator<String> iterator = this.options.validationGroupPreUpdates(); + modelValue = this.getFirstElement(iterator); + } + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) { + ListIterator<String> iterator = this.options.validationGroupPreRemoves(); + modelValue = this.getFirstElement(iterator); + } else this.throwMissingDefinition("getProperty", propertyName); return modelValue; } - + @Override protected void setProperty(String propertyName, Object newValue) throws Exception { if (propertyName.equals(JpaOptions2_0.LOCK_TIMEOUT_PROPERTY)) @@ -111,11 +134,11 @@ public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests else if (propertyName.equals(JpaOptions2_0.QUERY_TIMEOUT_PROPERTY)) this.options.setQueryTimeout((Integer) newValue); else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.setValidationGroupPrePersist((String) newValue); + this.options.addValidationGroupPrePersist((String) newValue); else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.setValidationGroupPreUpdate((String) newValue); + this.options.addValidationGroupPreUpdate((String) newValue); else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.setValidationGroupPreRemove((String) newValue); + this.options.addValidationGroupPreRemove((String) newValue); else this.throwMissingDefinition("setProperty", propertyName); } @@ -161,14 +184,32 @@ public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests this.verifyModelInitialized( VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); - this.verifySetProperty( + this.verifySetValidationGroupProperty( + JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); } public void testAddRemoveValidationGroupPrePersist() throws Exception { - this.verifyAddRemoveProperty( + this.verifyAddRemoveValidationGroupProperty( + JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, + VALIDATION_GROUP_PRE_PERSIST_KEY, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); + } + + public void testAddValidationGroupPrePersistCompositeValue() throws Exception { + this.verifyAddCompositeValue( + JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, + VALIDATION_GROUP_PRE_PERSIST_KEY, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); + } + + public void testRemoveValidationGroupPrePersistCompositeValue() throws Exception { + this.verifyRemoveCompositeValue( + JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); @@ -179,14 +220,32 @@ public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests this.verifyModelInitialized( VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); - this.verifySetProperty( + this.verifySetValidationGroupProperty( + JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); } public void testAddRemoveValidationGroupPreUpdate() throws Exception { - this.verifyAddRemoveProperty( + this.verifyAddRemoveValidationGroupProperty( + JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, + VALIDATION_GROUP_PRE_UPDATE_KEY, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); + } + + public void testAddValidationGroupPreUpdateCompositeValue() throws Exception { + this.verifyAddCompositeValue( + JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, + VALIDATION_GROUP_PRE_UPDATE_KEY, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); + } + + public void testRemoveValidationGroupPreUpdateCompositeValue() throws Exception { + this.verifyRemoveCompositeValue( + JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); @@ -197,17 +256,265 @@ public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests this.verifyModelInitialized( VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); - this.verifySetProperty( + this.verifySetValidationGroupProperty( + JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); } public void testAddRemoveValidationGroupPreRemove() throws Exception { - this.verifyAddRemoveProperty( + this.verifyAddRemoveValidationGroupProperty( + JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, + VALIDATION_GROUP_PRE_REMOVE_KEY, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); + } + + public void testAddValidationGroupPreRemoveCompositeValue() throws Exception { + this.verifyAddCompositeValue( + JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, + VALIDATION_GROUP_PRE_REMOVE_KEY, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); + } + + public void testRemoveValidationGroupPreRemoveCompositeValue() throws Exception { + this.verifyRemoveCompositeValue( + JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); } + + // ********** ValidationGroups list ********** + public void testValidationGroupsList() throws Exception { + this.verifyListEvents( + JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2, + JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST); + + this.verifyListEvents( + JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2, + JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST); + + this.verifyListEvents( + JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2, + JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST); + } + + // ********** override ********** + + @Override + protected void clearEvent() { + super.clearEvent(); + this.prePersistEvent = null; + this.preUpdateEvent = null; + this.preRemoveEvent = null; + } + + // ****** convenience methods ******* + + // ********** verify ValidationGroup property ********** + protected void verifySetValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { + // Replace + this.persistenceUnitSetProperty(key, testValue2, true); + this.propertiesTotal++; + this.verifyPutValidationGroupProperty(propertyName, testValue1); + } + + @SuppressWarnings("unused") + protected void verifyAddRemoveValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { + assertTrue(this.validationGroupValueExists(propertyName, (String)testValue1)); + // Remove + this.clearEvent(); + --this.propertiesTotal; + --this.modelPropertiesSize; + this.getPersistenceUnit().removeProperty(key, (String)testValue1); + assertFalse(this.validationGroupValueExists(propertyName, (String)testValue1)); + assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); + + // Add original Property + ++this.propertiesTotal; + ++this.modelPropertiesSize; + this.persistenceUnitSetProperty(key, testValue1, true); + this.verifyPutValidationGroupProperty(propertyName, testValue1); + } + + protected void verifyAddCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { + String stringTestValue1 = (String)testValue1; + String stringTestValue2 = (String)testValue2; + assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); + assertEquals(this.getValidationGroupSize(propertyName), 1); + this.addValidationGroupValue(propertyName, stringTestValue2); + assertEquals(this.getValidationGroupSize(propertyName), 2); + + assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); + assertTrue(this.validationGroupValueExists(propertyName, stringTestValue2)); + + String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); + assertTrue(propertyValue.indexOf(stringTestValue1) != -1); + assertTrue(propertyValue.indexOf(stringTestValue2) != -1); + } + + protected void verifyRemoveCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { + String stringTestValue1 = (String)testValue1; + String stringTestValue2 = (String)testValue2; + assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); + assertEquals(this.getValidationGroupSize(propertyName), 1); + this.addValidationGroupValue(propertyName, stringTestValue2); + assertEquals(this.getValidationGroupSize(propertyName), 2); + + this.removeValidationGroupValue(propertyName, stringTestValue2); + assertEquals(this.getValidationGroupSize(propertyName), 1); + assertFalse(this.validationGroupValueExists(propertyName, stringTestValue2)); + String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); + assertTrue(propertyValue.indexOf(stringTestValue1) != -1); + assertTrue(propertyValue.indexOf(stringTestValue2) == -1); + + this.removeValidationGroupValue(propertyName, stringTestValue2); + assertEquals(this.getValidationGroupSize(propertyName), 1); + + this.removeValidationGroupValue(propertyName, stringTestValue1); + assertEquals(this.getValidationGroupSize(propertyName), 0); + assertFalse(this.validationGroupValueExists(propertyName, stringTestValue1)); + + assertNull(this.getPersistenceUnit().getProperty(key)); + } + + protected void verifyListEvents(String propertyName, String testValue, String listName) throws Exception { + // add + this.clearEvent(); + this.addValidationGroupValue(propertyName, testValue); + + // verify event received + assertNotNull("No Event Fired.", this.getEventFor(propertyName)); + // verify event for the expected property + assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); + + // remove + this.clearEvent(); + + this.removeValidationGroupValue(propertyName, testValue); + // verify event received + assertNotNull("No Event Fired.", this.getEventFor(propertyName)); + // verify event for the expected property + assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); + } + protected void verifyPutValidationGroupProperty(String propertyName, Object expectedValue) throws Exception { + // verify event received + assertNotNull("No Event Fired.", this.getEventFor(propertyName)); + // verify event value + assertTrue(this.validationGroupValueExists(propertyName, (String) expectedValue)); + return; + } + + // ********** internal method ********** + + private ListChangeListener buildValidationGroupListChangeListener() { + return new ListChangeListener() { + public void itemsAdded(ListAddEvent e) { + Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void itemsRemoved(ListRemoveEvent e) { + Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void itemsReplaced(ListReplaceEvent e) { + Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void itemsMoved(ListMoveEvent e) { + Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void listCleared(ListClearEvent e) { + Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void listChanged(ListChangeEvent e) { + + Generic2_0OptionsTests.this.validationGroupChanged(e); + } + }; + } + + private void validationGroupChanged(ListChangeEvent e) { + String listName = e.getListName(); + + if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST)) + this.prePersistEvent = e; + else if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST)) + this.preUpdateEvent = e; + else if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST)) + this.preRemoveEvent = e; + else + this.throwUnsupportedOperationException(e); + } + + private void addValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { + if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + this.options.addValidationGroupPrePersist(propertyValue); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + this.options.addValidationGroupPreUpdate(propertyValue); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + this.options.addValidationGroupPreRemove(propertyValue); + else + this.throwMissingDefinition("addValidationGroupValue", propertyName); + } + + private void removeValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { + if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + this.options.removeValidationGroupPrePersist(propertyValue); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + this.options.removeValidationGroupPreUpdate(propertyValue); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + this.options.removeValidationGroupPreRemove(propertyValue); + else + this.throwMissingDefinition("removeValidationGroupValue", propertyName); + } + + private boolean validationGroupValueExists(String propertyName, String propertyValue) throws NoSuchFieldException { + boolean result = false; + if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + result = this.options.validationGroupPrePersistExists(propertyValue); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + result = this.options.validationGroupPreUpdateExists(propertyValue); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + result = this.options.validationGroupPreRemoveExists(propertyValue); + else + this.throwMissingDefinition("verifyValidationGroupValueExists", propertyName); + return result; + } + + private int getValidationGroupSize(String propertyName) throws NoSuchFieldException { + int result = 0; + if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + result = this.options.validationGroupPrePersistsSize(); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + result = this.options.validationGroupPreUpdatesSize(); + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + result = this.options.validationGroupPreRemovesSize(); + else + this.throwMissingDefinition("verifyValidationGroupSize", propertyName); + return result; + } + + private ListChangeEvent getEventFor(String propertyName) throws NoSuchFieldException { + ListChangeEvent event = null; + if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + event = this.prePersistEvent; + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + event = this.preUpdateEvent; + else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + event = this.preRemoveEvent; + else + this.throwMissingDefinition("getEventFor", propertyName); + return event; + } + } diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0OptionsTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0OptionsTests.java index af783777a8..15b0573e2f 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0OptionsTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0OptionsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. +* Copyright (c) 2009, 2010 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,8 +9,17 @@ *******************************************************************************/ package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.persistence; +import java.util.ListIterator; + import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; import org.eclipse.jpt.eclipselink.core.v2_0.context.persistence.options.Options2_0; +import org.eclipse.jpt.utility.model.event.ListAddEvent; +import org.eclipse.jpt.utility.model.event.ListChangeEvent; +import org.eclipse.jpt.utility.model.event.ListClearEvent; +import org.eclipse.jpt.utility.model.event.ListMoveEvent; +import org.eclipse.jpt.utility.model.event.ListRemoveEvent; +import org.eclipse.jpt.utility.model.event.ListReplaceEvent; +import org.eclipse.jpt.utility.model.listener.ListChangeListener; import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; /** @@ -19,6 +28,9 @@ import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTestCase { private Options2_0 options; + private ListChangeEvent prePersistEvent; + private ListChangeEvent preUpdateEvent; + private ListChangeEvent preRemoveEvent; public static final String LOCK_TIMEOUT_KEY = Options2_0.PERSISTENCE_LOCK_TIMEOUT; public static final Integer LOCK_TIMEOUT_TEST_VALUE = 100; @@ -27,7 +39,7 @@ public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTes public static final String QUERY_TIMEOUT_KEY = Options2_0.PERSISTENCE_QUERY_TIMEOUT; public static final Integer QUERY_TIMEOUT_TEST_VALUE = 100; public static final Integer QUERY_TIMEOUT_TEST_VALUE_2 = 200; - + public static final String VALIDATION_GROUP_PRE_PERSIST_KEY = Options2_0.PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST; public static final String VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE = "test_pre-persist_group"; public static final String VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2 = "test_2_pre-persist_group"; @@ -58,6 +70,11 @@ public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTes this.options.addPropertyChangeListener(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, propertyChangeListener); this.options.addPropertyChangeListener(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, propertyChangeListener); + ListChangeListener validationGroupListChangeListener = this.buildValidationGroupListChangeListener(); + this.options.addListChangeListener(Options2_0.VALIDATION_GROUP_PRE_PERSIST_LIST, validationGroupListChangeListener); + this.options.addListChangeListener(Options2_0.VALIDATION_GROUP_PRE_UPDATE_LIST, validationGroupListChangeListener); + this.options.addListChangeListener(Options2_0.VALIDATION_GROUP_PRE_REMOVE_LIST, validationGroupListChangeListener); + this.clearEvent(); } @@ -71,13 +88,13 @@ public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTes this.modelPropertiesSize = this.modelPropertiesSizeOriginal; // Initializes PersistenceUnit properties - this.persistenceUnitSetProperty("misc.property.1", "value.1"); this.persistenceUnitSetProperty(LOCK_TIMEOUT_KEY, LOCK_TIMEOUT_TEST_VALUE.toString()); this.persistenceUnitSetProperty(QUERY_TIMEOUT_KEY, QUERY_TIMEOUT_TEST_VALUE.toString()); + this.persistenceUnitSetProperty("misc.property.3", "value.3"); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE.toString()); + this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); + this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); + this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); } @Override @@ -92,17 +109,23 @@ public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTes modelValue = this.options.getLockTimeout(); else if (propertyName.equals(Options2_0.QUERY_TIMEOUT_PROPERTY)) modelValue = this.options.getQueryTimeout(); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - modelValue = this.options.getValidationGroupPrePersist(); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - modelValue = this.options.getValidationGroupPreUpdate(); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - modelValue = this.options.getValidationGroupPreRemove(); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) { + ListIterator<String> iterator = this.options.validationGroupPrePersists(); + modelValue = this.getFirstElement(iterator); + } + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) { + ListIterator<String> iterator = this.options.validationGroupPreUpdates(); + modelValue = this.getFirstElement(iterator); + } + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) { + ListIterator<String> iterator = this.options.validationGroupPreRemoves(); + modelValue = this.getFirstElement(iterator); + } else this.throwMissingDefinition("getProperty", propertyName); return modelValue; } - + @Override protected void setProperty(String propertyName, Object newValue) throws Exception { if (propertyName.equals(Options2_0.LOCK_TIMEOUT_PROPERTY)) @@ -110,11 +133,11 @@ public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTes else if (propertyName.equals(Options2_0.QUERY_TIMEOUT_PROPERTY)) this.options.setQueryTimeout((Integer) newValue); else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.setValidationGroupPrePersist((String) newValue); + this.options.addValidationGroupPrePersist((String) newValue); else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.setValidationGroupPreUpdate((String) newValue); + this.options.addValidationGroupPreUpdate((String) newValue); else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.setValidationGroupPreRemove((String) newValue); + this.options.addValidationGroupPreRemove((String) newValue); else this.throwMissingDefinition("setProperty", propertyName); } @@ -160,14 +183,32 @@ public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTes this.verifyModelInitialized( VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); - this.verifySetProperty( + this.verifySetValidationGroupProperty( + Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); } public void testAddRemoveValidationGroupPrePersist() throws Exception { - this.verifyAddRemoveProperty( + this.verifyAddRemoveValidationGroupProperty( + Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, + VALIDATION_GROUP_PRE_PERSIST_KEY, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); + } + + public void testAddValidationGroupPrePersistCompositeValue() throws Exception { + this.verifyAddCompositeValue( + Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, + VALIDATION_GROUP_PRE_PERSIST_KEY, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); + } + + public void testRemoveValidationGroupPrePersistCompositeValue() throws Exception { + this.verifyRemoveCompositeValue( + Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); @@ -178,14 +219,32 @@ public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTes this.verifyModelInitialized( VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); - this.verifySetProperty( + this.verifySetValidationGroupProperty( + Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); } public void testAddRemoveValidationGroupPreUpdate() throws Exception { - this.verifyAddRemoveProperty( + this.verifyAddRemoveValidationGroupProperty( + Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, + VALIDATION_GROUP_PRE_UPDATE_KEY, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); + } + + public void testAddValidationGroupPreUpdateCompositeValue() throws Exception { + this.verifyAddCompositeValue( + Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, + VALIDATION_GROUP_PRE_UPDATE_KEY, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); + } + + public void testRemoveValidationGroupPreUpdateCompositeValue() throws Exception { + this.verifyRemoveCompositeValue( + Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); @@ -196,17 +255,265 @@ public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTes this.verifyModelInitialized( VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); - this.verifySetProperty( + this.verifySetValidationGroupProperty( + Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); } public void testAddRemoveValidationGroupPreRemove() throws Exception { - this.verifyAddRemoveProperty( + this.verifyAddRemoveValidationGroupProperty( + Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); } + + public void testAddValidationGroupPreRemoveCompositeValue() throws Exception { + this.verifyAddCompositeValue( + Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, + VALIDATION_GROUP_PRE_REMOVE_KEY, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); + } + + public void testRemoveValidationGroupPreRemoveCompositeValue() throws Exception { + this.verifyRemoveCompositeValue( + Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, + VALIDATION_GROUP_PRE_REMOVE_KEY, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); + } + + // ********** ValidationGroups list ********** + public void testValidationGroupsList() throws Exception { + this.verifyListEvents( + Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, + VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2, + Options2_0.VALIDATION_GROUP_PRE_PERSIST_LIST); + + this.verifyListEvents( + Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, + VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2, + Options2_0.VALIDATION_GROUP_PRE_UPDATE_LIST); + + this.verifyListEvents( + Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, + VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2, + Options2_0.VALIDATION_GROUP_PRE_REMOVE_LIST); + } + + // ********** override ********** + + @Override + protected void clearEvent() { + super.clearEvent(); + this.prePersistEvent = null; + this.preUpdateEvent = null; + this.preRemoveEvent = null; + } + + // ****** convenience methods ******* + + // ********** verify ValidationGroup property ********** + protected void verifySetValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { + // Replace + this.persistenceUnitSetProperty(key, testValue2, true); + this.propertiesTotal++; + this.verifyPutValidationGroupProperty(propertyName, testValue1); + } + + @SuppressWarnings("unused") + protected void verifyAddRemoveValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { + assertTrue(this.validationGroupValueExists(propertyName, (String)testValue1)); + // Remove + this.clearEvent(); + --this.propertiesTotal; + --this.modelPropertiesSize; + this.getPersistenceUnit().removeProperty(key, (String)testValue1); + assertFalse(this.validationGroupValueExists(propertyName, (String)testValue1)); + assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); + + // Add original Property + ++this.propertiesTotal; + ++this.modelPropertiesSize; + this.persistenceUnitSetProperty(key, testValue1, true); + this.verifyPutValidationGroupProperty(propertyName, testValue1); + } + + protected void verifyAddCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { + String stringTestValue1 = (String)testValue1; + String stringTestValue2 = (String)testValue2; + assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); + assertEquals(this.getValidationGroupSize(propertyName), 1); + this.addValidationGroupValue(propertyName, stringTestValue2); + assertEquals(this.getValidationGroupSize(propertyName), 2); + + assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); + assertTrue(this.validationGroupValueExists(propertyName, stringTestValue2)); + + String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); + assertTrue(propertyValue.indexOf(stringTestValue1) != -1); + assertTrue(propertyValue.indexOf(stringTestValue2) != -1); + } + + protected void verifyRemoveCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { + String stringTestValue1 = (String)testValue1; + String stringTestValue2 = (String)testValue2; + assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); + assertEquals(this.getValidationGroupSize(propertyName), 1); + this.addValidationGroupValue(propertyName, stringTestValue2); + assertEquals(this.getValidationGroupSize(propertyName), 2); + + this.removeValidationGroupValue(propertyName, stringTestValue2); + assertEquals(this.getValidationGroupSize(propertyName), 1); + assertFalse(this.validationGroupValueExists(propertyName, stringTestValue2)); + String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); + assertTrue(propertyValue.indexOf(stringTestValue1) != -1); + assertTrue(propertyValue.indexOf(stringTestValue2) == -1); + + this.removeValidationGroupValue(propertyName, stringTestValue2); + assertEquals(this.getValidationGroupSize(propertyName), 1); + + this.removeValidationGroupValue(propertyName, stringTestValue1); + assertEquals(this.getValidationGroupSize(propertyName), 0); + assertFalse(this.validationGroupValueExists(propertyName, stringTestValue1)); + + assertNull(this.getPersistenceUnit().getProperty(key)); + } + + protected void verifyListEvents(String propertyName, String testValue, String listName) throws Exception { + // add + this.clearEvent(); + this.addValidationGroupValue(propertyName, testValue); + + // verify event received + assertNotNull("No Event Fired.", this.getEventFor(propertyName)); + // verify event for the expected property + assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); + + // remove + this.clearEvent(); + + this.removeValidationGroupValue(propertyName, testValue); + // verify event received + assertNotNull("No Event Fired.", this.getEventFor(propertyName)); + // verify event for the expected property + assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); + } + + protected void verifyPutValidationGroupProperty(String propertyName, Object expectedValue) throws Exception { + // verify event received + assertNotNull("No Event Fired.", this.getEventFor(propertyName)); + // verify event value + assertTrue(this.validationGroupValueExists(propertyName, (String) expectedValue)); + return; + } + + // ********** internal method ********** + + private ListChangeListener buildValidationGroupListChangeListener() { + return new ListChangeListener() { + public void itemsAdded(ListAddEvent e) { + EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void itemsRemoved(ListRemoveEvent e) { + EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void itemsReplaced(ListReplaceEvent e) { + EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void itemsMoved(ListMoveEvent e) { + EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void listCleared(ListClearEvent e) { + EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); + } + + public void listChanged(ListChangeEvent e) { + + EclipseLink2_0OptionsTests.this.validationGroupChanged(e); + } + }; + } + + private void validationGroupChanged(ListChangeEvent e) { + String listName = e.getListName(); + + if (listName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_LIST)) + this.prePersistEvent = e; + else if (listName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_LIST)) + this.preUpdateEvent = e; + else if (listName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_LIST)) + this.preRemoveEvent = e; + else + this.throwUnsupportedOperationException(e); + } + + private void addValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { + if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + this.options.addValidationGroupPrePersist(propertyValue); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + this.options.addValidationGroupPreUpdate(propertyValue); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + this.options.addValidationGroupPreRemove(propertyValue); + else + this.throwMissingDefinition("addValidationGroupValue", propertyName); + } + + private void removeValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { + if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + this.options.removeValidationGroupPrePersist(propertyValue); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + this.options.removeValidationGroupPreUpdate(propertyValue); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + this.options.removeValidationGroupPreRemove(propertyValue); + else + this.throwMissingDefinition("removeValidationGroupValue", propertyName); + } + + private boolean validationGroupValueExists(String propertyName, String propertyValue) throws NoSuchFieldException { + boolean result = false; + if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + result = this.options.validationGroupPrePersistExists(propertyValue); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + result = this.options.validationGroupPreUpdateExists(propertyValue); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + result = this.options.validationGroupPreRemoveExists(propertyValue); + else + this.throwMissingDefinition("verifyValidationGroupValueExists", propertyName); + return result; + } + + private int getValidationGroupSize(String propertyName) throws NoSuchFieldException { + int result = 0; + if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + result = this.options.validationGroupPrePersistsSize(); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + result = this.options.validationGroupPreUpdatesSize(); + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + result = this.options.validationGroupPreRemovesSize(); + else + this.throwMissingDefinition("verifyValidationGroupSize", propertyName); + return result; + } + private ListChangeEvent getEventFor(String propertyName) throws NoSuchFieldException { + ListChangeEvent event = null; + if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) + event = this.prePersistEvent; + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) + event = this.preUpdateEvent; + else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) + event = this.preRemoveEvent; + else + this.throwMissingDefinition("getEventFor", propertyName); + return event; + } + } |