Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringPropertyValueModel.java')
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringPropertyValueModel.java86
1 files changed, 31 insertions, 55 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringPropertyValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringPropertyValueModel.java
index 2d5e192bd9..6ac16b63e7 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringPropertyValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/FilteringPropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 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,34 +9,30 @@
******************************************************************************/
package org.eclipse.jpt.utility.internal.model.value;
-import org.eclipse.jpt.utility.internal.BidiFilter;
+import org.eclipse.jpt.utility.internal.Filter;
import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
/**
* A <code>FilteringPropertyValueModel</code> wraps another
- * <code>PropertyValueModel</code> and uses a <code>BidiFilter</code>
+ * <code>PropertyValueModel</code> and uses a <code>Filter</code>
* to determine when the wrapped value is to be returned by calls
- * to <code>value()</code> and modified by calls to
- * <code>setValue(Object)</code>
+ * to <code>value()</code>.
* <p>
- * As an alternative to building a <code>BidiFilter</code>, a subclass
+ * As an alternative to building a <code>Filter</code>, a subclass
* of <code>FilteringPropertyValueModel</code> can override the
- * <code>accept(Object)</code> and <code>reverseAccept(Object)</code>
- * methods.
+ * <code>accept(Object)</code> method.
* <p>
* One, possibly undesirable, side-effect of using this value model is that
* it must return *something* as the value. The default behavior is
* to return <code>null</code> whenever the wrapped value is not "accepted",
* which can be configured and/or overridden.
- * <p>
- * Likewise, if an incoming value is not "reverseAccepted", *nothing* will passed
- * through to the wrapped value holder, not even <code>null</code>.
*/
-public class FilteringPropertyValueModel
- extends PropertyValueModelWrapper
+public class FilteringPropertyValueModel<T>
+ extends PropertyValueModelWrapper<T>
+ implements PropertyValueModel<T>
{
- private final BidiFilter filter;
- private final Object defaultValue;
+ protected final Filter<T> filter;
+ protected final T defaultValue;
// ********** constructors **********
@@ -45,25 +41,25 @@ public class FilteringPropertyValueModel
* Construct a property value model with the specified nested
* property value model and a disabled filter.
* Use this constructor if you want to override the
- * <code>accept(Object)</code> and <code>reverseAccept(Object)</code>
- * methods instead of building a <code>BidiFilter</code>.
+ * <code>accept(Object)</code>
+ * method instead of building a <code>Filter</code>.
* The default value will be <code>null</code>.
*/
- public FilteringPropertyValueModel(PropertyValueModel valueHolder) {
- this(valueHolder, BidiFilter.Disabled.instance(), null);
+ public FilteringPropertyValueModel(PropertyValueModel<? extends T> valueHolder) {
+ this(valueHolder, Filter.Disabled.<T>instance(), null);
}
/**
* Construct a property value model with the specified nested
* property value model, specified default value, and a disabled filter.
* Use this constructor if you want to override the
- * <code>accept(Object)</code> and <code>reverseAccept(Object)</code>
- * methods instead of building a <code>BidiFilter</code>
+ * <code>accept(Object)</code>
+ * method instead of building a <code>Filter</code>
* <em>and</em> you need to specify
* a default value other than <code>null</code>.
*/
- public FilteringPropertyValueModel(PropertyValueModel valueHolder, Object defaultValue) {
- this(valueHolder, BidiFilter.Disabled.instance(), defaultValue);
+ public FilteringPropertyValueModel(PropertyValueModel<? extends T> valueHolder, T defaultValue) {
+ this(valueHolder, Filter.Disabled.<T>instance(), defaultValue);
}
/**
@@ -71,7 +67,7 @@ public class FilteringPropertyValueModel
* property value model and filter.
* The default value will be <code>null</code>.
*/
- public FilteringPropertyValueModel(PropertyValueModel valueHolder, BidiFilter filter) {
+ public FilteringPropertyValueModel(PropertyValueModel<? extends T> valueHolder, Filter<T> filter) {
this(valueHolder, filter, null);
}
@@ -79,26 +75,17 @@ public class FilteringPropertyValueModel
* Construct an property value model with the specified nested
* property value model, filter, and default value.
*/
- public FilteringPropertyValueModel(PropertyValueModel valueHolder, BidiFilter filter, Object defaultValue) {
+ public FilteringPropertyValueModel(PropertyValueModel<? extends T> valueHolder, Filter<T> filter, T defaultValue) {
super(valueHolder);
this.filter = filter;
this.defaultValue = defaultValue;
}
- // ********** ValueModel implementation **********
-
- public Object value() {
- return this.filterValue(this.valueHolder.value());
- }
-
-
// ********** PropertyValueModel implementation **********
- public void setValue(Object value) {
- if (this.reverseAccept(value)) {
- this.valueHolder.setValue(value);
- }
+ public T value() {
+ return this.filterValue(this.valueHolder.value());
}
@@ -107,8 +94,10 @@ public class FilteringPropertyValueModel
@Override
protected void valueChanged(PropertyChangeEvent e) {
// filter the values before propagating the change event
- Object oldValue = this.filterValue(e.oldValue());
- Object newValue = this.filterValue(e.newValue());
+ @SuppressWarnings("unchecked")
+ Object oldValue = this.filterValue((T) e.oldValue());
+ @SuppressWarnings("unchecked")
+ Object newValue = this.filterValue((T) e.newValue());
this.firePropertyChanged(VALUE, oldValue, newValue);
}
@@ -119,7 +108,7 @@ public class FilteringPropertyValueModel
* If the specified value is "accepted" simply return it,
* otherwise return the default value.
*/
- protected Object filterValue(Object value) {
+ protected T filterValue(T value) {
return this.accept(value) ? value : this.defaultValue();
}
@@ -130,31 +119,18 @@ public class FilteringPropertyValueModel
* from the nested property value model
* <p>
* This method can be overridden by a subclass as an
- * alternative to building a <code>BidiFilter</code>.
+ * alternative to building a <code>Filter</code>.
*/
- protected boolean accept(Object value) {
+ protected boolean accept(T value) {
return this.filter.accept(value);
}
/**
- * Return whether the <code>FilteringPropertyValueModel</code>
- * should pass through the specified value to the nested
- * property value model in a call to the
- * <code>setValue(Object)</code> method
- * <p>
- * This method can be overridden by a subclass as an
- * alternative to building a <code>BidiFilter</code>.
- */
- protected boolean reverseAccept(Object value) {
- return this.filter.reverseAccept(value);
- }
-
- /**
* Return the object that should be returned if
* the nested value was rejected by the filter.
* The default is <code>null</code>.
*/
- protected Object defaultValue() {
+ protected T defaultValue() {
return this.defaultValue;
}

Back to the top