Skip to content
Commits on Source (1)
......@@ -23,6 +23,10 @@
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.jface.databinding</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.databinding.beans</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.ui.forms</artifactId>
......
/**
* Copyright(C) 2013 Patrik Dufresne Service Logiciel <info@patrikdufresne.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.patrikdufresne.jface.databinding.viewers;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Arrays;
import java.util.Date;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.Observables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.internal.databinding.ConverterValueProperty;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.swt.DisplayRealm;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
......@@ -39,16 +37,58 @@ import org.eclipse.swt.widgets.Table;
*/
public class ColumnSupportTableViewerExample {
public class MyModel {
protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
public int counter;
public MyModel(int counter) {
public Date time;
public MyModel(int counter, Date time) {
this.counter = counter;
this.time = time;
}
@Override
public String toString() {
/**
* Java bean function.
*
* @param listener
* The PropertyChangeListener to be added
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
this.changeSupport.addPropertyChangeListener(listener);
}
public int getCounter() {
return this.counter;
}
public String getName() {
return "Item " + this.counter;
}
public Date getTime() {
return this.time;
}
/**
* Java bean function.
*
* @param listener
* The PropertyChangeListener to be removed
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
this.changeSupport.removePropertyChangeListener(listener);
}
public void setCounter(int counter) {
this.changeSupport.firePropertyChange("counter", this.counter, this.counter = counter);
}
public void setTime(Date time) {
this.changeSupport.firePropertyChange("time", this.time, this.time = time);
}
}
/**
......@@ -56,7 +96,7 @@ public class ColumnSupportTableViewerExample {
*/
public static void main(String[] args) {
final Display display = new Display();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
Realm.runWithDefault(DisplayRealm.getRealm(display), new Runnable() {
@Override
public void run() {
Shell shell = new Shell(display);
......@@ -72,38 +112,22 @@ public class ColumnSupportTableViewerExample {
}
public ColumnSupportTableViewerExample(final Composite comp) {
DataBindingContext dbc = new DataBindingContext();
final TableViewer v = new TableViewer(new Table(comp, SWT.BORDER));
ObservableListContentProvider olcp = new ObservableListContentProvider();
v.setContentProvider(olcp);
v.setContentProvider(new ObservableListContentProvider());
v.getTable().setHeaderVisible(true);
MyModel[] model = createModel();
IObservableList list = Observables.staticObservableList(Arrays.asList(model));
v.setInput(list);
ColumnSupport.create(v, "Column 1", olcp.getKnownElements(), new ConverterValueProperty(new Converter(MyModel.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
})).setPixelLayoutData(100).setResizable(true).setMoveable(false);
ColumnSupport.create(v, "Column 2", olcp.getKnownElements(), new ConverterValueProperty(new Converter(MyModel.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
})).setWeightLayoutData(1, 10).setResizable(true).setMoveable(false);
ColumnSupport.create(v, "Column 3", olcp.getKnownElements(), new ConverterValueProperty(new Converter(MyModel.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject;
}
})).setWeightLayoutData(1, 10).setResizable(false).setMoveable(false);
ColumnSupport.create(v, "Name", MyModel.class, "name").setPixelLayoutData(100).addTextEditingSupport(dbc);
ColumnSupport.create(v, "Counter", MyModel.class, "counter").setWeightLayoutData(1, 10).addTextEditingSupport(dbc);
ColumnSupport.create(v, "Time", MyModel.class, "time").setWeightLayoutData(1, 10).addTextEditingSupport(dbc);
v.getTable().setLinesVisible(true);
v.setInput(Observables.staticObservableList(Arrays.asList(model)));
}
private MyModel[] createModel() {
MyModel[] elements = new MyModel[10];
for (int i = 0; i < 10; i++) {
elements[i] = new MyModel(i);
elements[i] = new MyModel(i, new Date());
}
return elements;
}
......
......@@ -15,14 +15,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.jface.databinding</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.databinding.beans</artifactId>
</dependency>
<dependency>
<groupId>com.patrikdufresne</groupId>
<artifactId>managers</artifactId>
......
......@@ -36,10 +36,14 @@ import org.eclipse.core.databinding.observable.set.AbstractObservableSet;
import org.eclipse.core.databinding.observable.set.ComputedSet;
import org.eclipse.core.databinding.observable.set.ISetChangeListener;
import org.eclipse.core.databinding.observable.set.SetDiff;
import org.eclipse.core.databinding.property.value.IValueProperty;
import org.eclipse.core.databinding.util.Policy;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.TableViewer;
import com.patrikdufresne.jface.databinding.viewers.ColumnSupport;
import com.patrikdufresne.managers.IManager;
import com.patrikdufresne.managers.IManagerObserver;
import com.patrikdufresne.managers.ManagedObject;
import com.patrikdufresne.managers.ManagerEvent;
......@@ -65,8 +69,8 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
/**
* Inner class that implements interfaces that we don't want to expose as public API. Each interface could have been
* implemented using a separate anonymous class, but we combine them here to reduce the memory overhead and number
* of classes.
* implemented using a separate anonymous class, but we combine them here to reduce the memory overhead and number of
* classes.
*
* <p>
* The IChangeListener is attached to every dependency.
......@@ -107,7 +111,7 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
* Return a map with the default events to listen to.
*
* @param elementType
* the element type
* the element type
* @return the map
*/
private static Map<Class, Integer> defaultEvents(Class<? extends ManagedObject> elementType) {
......@@ -125,13 +129,10 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
/** True if dirty */
protected boolean dirty = true;
/** The element type of this observable */
private Class<? extends ManagedObject> elementType;
/** List of manager event to listen to */
private Map<Class, Integer> events;
private Managers managers;
private IManager manager;
private PrivateInterface privateInterface = new PrivateInterface();
......@@ -143,10 +144,12 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
* This computed set will listen to default manager events and has no dependencies.
*
* @param managers
* the managers
* the managers
* @param elementType
* the element type
* the element type
* @deprecated please use {@link ManagedObjectComputedSet(IManager)} instead.
*/
@Deprecated
public ManagedObjectComputedSet(Managers managers, Class<? extends ManagedObject> elementType) {
this(managers, elementType, defaultEvents(elementType), null);
}
......@@ -156,13 +159,14 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
* manager events.
*
* @param managers
* the managers
* the managers
* @param elementType
* the element type
* the element type
* @param dependencies
* list of observable dependencies or null
*
* list of observable dependencies or null
* @deprecated please use {@link ManagedObjectComputedSet(IManager, IObservable[])} instead.
*/
@Deprecated
public ManagedObjectComputedSet(Managers managers, Class<? extends ManagedObject> elementType, IObservable[] dependencies) {
this(managers, elementType, defaultEvents(elementType), dependencies);
}
......@@ -173,13 +177,14 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
*
*
* @param managers
* the managers
* the managers
* @param elementType
* the element type
* the element type
* @param events
* the list of manager event to listen to
*
* the list of manager event to listen to
* @deprecated please use {@link ManagedObjectComputedSet(IManager, Map)} instead.
*/
@Deprecated
public ManagedObjectComputedSet(Managers managers, Class<? extends ManagedObject> elementType, Map<Class, Integer> events) {
this(managers, elementType, events, null);
}
......@@ -188,14 +193,16 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
* Create a new observable list from a manager.
*
* @param managers
* the managers to use
* the managers to use
* @param elementType
* The element type of this observable
* The element type of this observable
* @param events
* the list of manager event to listen to
* the list of manager event to listen to
* @param dependencies
* the list of observable dependencies.
* the list of observable dependencies.
* @deprecated please use {@link ManagedObjectComputedSet(IManager, Map, IObservable[])} instead.
*/
@Deprecated
public ManagedObjectComputedSet(Managers managers, Class<? extends ManagedObject> elementType, Map<Class, Integer> events, IObservable[] dependencies) {
this(Realm.getDefault(), managers, elementType, events, dependencies);
}
......@@ -204,29 +211,105 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
* Create a new observable list from a manager.
*
* @param realm
* the realm
* the realm
* @param managers
* the managers to use
* the managers to use
* @param elementType
* The element type of this observable
* The element type of this observable
* @param events
* the list of manager event to listen to
* the list of manager event to listen to
* @param dependencies
* the list of observable dependencies.
* the list of observable dependencies.
* @deprecated please use {@link ManagedObjectComputedSet(Realm, IManager, Map, IObservable[])} instead.
*/
@Deprecated
public ManagedObjectComputedSet(
Realm realm,
Managers managers,
Class<? extends ManagedObject> elementType,
Map<Class, Integer> events,
IObservable[] dependencies) {
this(realm, managers.getManagerForClass(elementType), events, dependencies);
}
/**
* Default constructor to create an observable computed set for the managers and element type specified.
* <p>
* This computed set will listen to default manager events and has no dependencies.
*
* @param manager
* the manager
*/
public ManagedObjectComputedSet(IManager manager) {
this(manager, defaultEvents(manager.objectClass()), null);
}
/**
* Create an observable set for the managers and element type specified. This computed set will listen to default
* manager events.
*
* @param manager
* the manager
* @param elementType
* the element type
* @param dependencies
* list of observable dependencies or null
*
*/
public ManagedObjectComputedSet(IManager manager, IObservable[] dependencies) {
this(manager, defaultEvents(manager.objectClass()), dependencies);
}
/**
* Create an observable set for the managers and element type specified. This computed set will listen to the
* <code>events</code> specified.
*
*
* @param manager
* the manager
* @param events
* the list of manager event to listen to
*
*/
public ManagedObjectComputedSet(IManager manager, Map<Class, Integer> events) {
this(manager, events, null);
}
/**
* Create a new observable list from a manager.
*
* @param manager
* the manager to use
* @param events
* the list of manager event to listen to
* @param dependencies
* the list of observable dependencies.
*/
public ManagedObjectComputedSet(IManager manager, Map<Class, Integer> events, IObservable[] dependencies) {
this(Realm.getDefault(), manager, events, dependencies);
}
/**
* Create a new observable list from a manager.
*
* @param realm
* the realm
* @param managers
* the managers to use
* @param elementType
* The element type of this observable
* @param events
* the list of manager event to listen to
* @param dependencies
* the list of observable dependencies.
*/
public ManagedObjectComputedSet(Realm realm, IManager manager, Map<Class, Integer> events, IObservable[] dependencies) {
super(realm);
if (managers == null || elementType == null) {
throw new IllegalArgumentException();
if (manager == null) {
throw new IllegalArgumentException("manager can't be null");
}
ObservableTracker.observableCreated(this);
this.managers = managers;
this.elementType = elementType;
this.manager = manager;
this.events = events;
this.dependencies = dependencies;
}
......@@ -304,7 +387,7 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
if (!isDisposed()) {
stopListening();
lastListenerRemoved();
this.managers = null;
this.manager = null;
this.dependencies = null;
this.privateInterface = null;
}
......@@ -351,13 +434,13 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
/**
* Query the database.
* <p>
* Sub classes may override this function to query the database using something else then list(). The collection
* return by this function must already be filtered according to {@link #doSelect(Object)}.
* Sub classes may override this function to query the database using something else then list(). The collection return
* by this function must already be filtered according to {@link #doSelect(Object)}.
*
* @return a collection
*/
protected Collection doList() throws ManagerException {
return getManagers().getManagerForClass(this.elementType).list();
return this.manager.list();
}
/**
......@@ -366,7 +449,7 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
* Subclasses should override this function if it's override {@link #doIterator()}.
*
* @param element
* the element to check
* the element to check
* @return True if the element should be selected
*/
protected boolean doSelect(Object element) {
......@@ -385,14 +468,9 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
// return false;
if (getClass() != obj.getClass()) return false;
ManagedObjectComputedSet other = (ManagedObjectComputedSet) obj;
if (this.managers == null) {
if (other.managers != null) return false;
} else if (!this.managers.equals(other.managers)) return false;
if (this.elementType == null) {
if (other.elementType != null) return false;
} else if (!this.elementType.equals(other.elementType)) return false;
if (this.manager == null) {
if (other.manager != null) return false;
} else if (!this.manager.equals(other.manager)) return false;
return true;
}
......@@ -401,7 +479,7 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
*/
@Override
public Object getElementType() {
return this.elementType;
return this.manager.objectClass();
}
/**
......@@ -411,7 +489,7 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
*/
@Override
public Managers getManagers() {
return this.managers;
return this.manager.getManagers();
}
final Set getSet() {
......@@ -434,7 +512,7 @@ public class ManagedObjectComputedSet extends AbstractObservableSet implements I
getterCalled();
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.managers.hashCode();
result = prime * result + this.manager.hashCode();
return result;
}
......
/**
* Copyright (C) 2019 Patrik Dufresne Service Logiciel <info@patrikdufresne.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package com.patrikdufresne.managers.databinding;
import java.util.Set;
import org.eclipse.core.databinding.observable.IObservableCollection;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.databinding.observable.set.ISetChangeListener;
import org.eclipse.core.databinding.observable.set.SetChangeEvent;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.databinding.viewers.IViewerUpdater;
import org.eclipse.jface.internal.databinding.viewers.ObservableCollectionContentProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import com.patrikdufresne.managers.IManager;
import com.patrikdufresne.managers.ManagerException;
public class ManagerContentProvider implements IStructuredContentProvider {
private ObservableCollectionContentProvider impl;
private static class Impl extends ObservableCollectionContentProvider implements ISetChangeListener {
protected Impl(IViewerUpdater explicitViewerUpdater) {
super(explicitViewerUpdater);
}
@Override
protected void checkInput(Object input) {
Assert.isTrue(input instanceof IObservableSet, "This content provider only works with input of type IObservableSet"); //$NON-NLS-1$
}
@Override
protected void addCollectionChangeListener(IObservableCollection collection) {
((IObservableSet) collection).addSetChangeListener(this);
}
@Override
protected void removeCollectionChangeListener(IObservableCollection collection) {
((IObservableSet) collection).removeSetChangeListener(this);
}
@Override
public void handleSetChange(SetChangeEvent event) {
if (isViewerDisposed()) return;
Set removals = event.diff.getRemovals();
Set additions = event.diff.getAdditions();
knownElements.addAll(additions);
if (realizedElements != null) realizedElements.removeAll(removals);
viewerUpdater.remove(removals.toArray());
viewerUpdater.add(additions.toArray());
if (realizedElements != null) realizedElements.addAll(additions);
knownElements.removeAll(removals);
}
}
/**
* Constructs an ObservableSetContentProvider. Must be called from the display thread.
*/
public ManagerContentProvider() {
this(null);
}
/**
* Constructs an ObservableSetContentProvider with the given viewer updater. Must be called from the display thread.
*
* @param viewerUpdater
* the viewer updater to use when elements are added or removed from the input observable set.
* @since 1.3
*/
public ManagerContentProvider(IViewerUpdater viewerUpdater) {
impl = new Impl(viewerUpdater);
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
Assert.isTrue(newInput == null || newInput instanceof IManager, "This content provider only works with input of type IManager"); //$NON-NLS-1$
impl.inputChanged(viewer, null, newInput == null ? null : new ManagedObjectComputedSet((IManager) newInput));
}
@Override
public Object[] getElements(Object inputElement) {
return impl.getElements(inputElement);
}
/**
* Disposes of this content provider. This is called by the viewer when a content provider is replaced, or when the
* viewer itself is disposed.
* <p>
* The viewer should not be updated during this call, as it is in the process of being disposed.
* </p>
* <p>
* <em>Note:</em> Data binding content providers become unusable on disposal.
* </p>
*/
@Override
public void dispose() {
impl.dispose();
}
/**
* Returns the set of elements known to this content provider. Label providers may track this set if they need to be
* notified about additions before the viewer sees the added element, and notified about removals after the element was
* removed from the viewer. This is intended for use by label providers, as it will always return the items that need
* labels.
*
* @return unmodifiable set of items that will need labels
*/
public IObservableSet getKnownElements() {
return impl.getKnownElements();
}
/**
* Returns the set of known elements which have been realized in the viewer. Clients may track this set in order to
* perform custom actions on elements while they are known to be present in the viewer.
*
* @return the set of known elements which have been realized in the viewer.
* @since 1.3
*/
public IObservableSet getRealizedElements() {
return impl.getRealizedElements();
}
}
/**
* Copyright (C) 2019 Patrik Dufresne Service Logiciel <info@patrikdufresne.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package com.patrikdufresne.managers.databinding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateListStrategy;
import org.eclipse.core.databinding.UpdateSetStrategy;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import com.patrikdufresne.managers.Managers;
/**
* Specialised data binding context for managers.
*
* @author Patrik Dufresne
*
*/
public class ManagerDataBindingContext extends DataBindingContext {
private Managers managers;
/**
* Create a data binding context for the given managers.
*
* @param managers
* the managers used for persistance.
*/
public ManagerDataBindingContext(Managers managers) {
this.managers = managers;
}
/**
* Returns an update value strategy to be used for copying values from the from value to the to value. Clients may
* override.
*
* @param fromValue
* @param toValue
* @return a update value strategy
*/
@Override
protected <T, M> UpdateValueStrategy<T, M> createTargetToModelUpdateValueStrategy(IObservableValue<T> fromValue, IObservableValue<M> toValue) {
return new ManagerUpdateValueStrategy(managers);
}
/**
* @param targetObservableList
* @param modelObservableList
* @return an update list strategy
*/
@Override
protected <T, M> UpdateListStrategy<T, M> createTargetToModelUpdateListStrategy(
IObservableList<T> targetObservableList,
IObservableList<M> modelObservableList) {
return new ManagerUpdateListStrategy(managers);
}
/**
* @param targetObservableSet
* @param modelObservableSet
* @return a default set update strategy
*/
@Override
protected <T, M> UpdateSetStrategy<T, M> createTargetToModelUpdateSetStrategy(IObservableSet<T> targetObservableSet, IObservableSet<M> modelObservableSet) {
return new ManagerUpdateSetStrategy(managers);
}
}
......@@ -21,7 +21,6 @@ import org.eclipse.core.databinding.UpdateSetStrategy;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
......@@ -38,83 +37,6 @@ import com.patrikdufresne.managers.Managers;
*/
public class ManagerUpdateSetStrategy extends UpdateSetStrategy {
/**
* Create an update strategy to persists the managed object of an observable
* value.
*
* @param managers
* the managers instance to be used to persist the
* {@link ManagedObject}.
*
* @return a new update set strategy
*/
public static ManagerUpdateSetStrategy persistObservableValue(Managers managers, final IObservableValue observableValue) {
return persistObservableValue(managers, true, UpdateValueStrategy.POLICY_UPDATE, observableValue);
}
/**
* Create an update strategy to persists the managed object of an observable
* value.
*
* @param managers
* the managers instance to be used to persist the
* {@link ManagedObject}.
*
* @param updatePolicy
* one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST},
* {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE}
*
* @return a new update set strategy
*/
public static ManagerUpdateSetStrategy persistObservableValue(Managers managers, int updatePolicy, final IObservableValue observableValue) {
return persistObservableValue(managers, true, updatePolicy, observableValue);
}
/**
* Create an update strategy to persists the managed object of an observable
* value.
*
* @param managers
* the managers instance to be used to persist the
* {@link ManagedObject}.
* @param provideDefaults
* if <code>true</code>, default validators and a default
* converter will be provided based on the observable value's
* type.
* @param updatePolicy
* one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST},
* {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE}
*
* @return a new update set strategy
*/
public static ManagerUpdateSetStrategy persistObservableValue(
Managers managers,
boolean provideDefaults,
int updatePolicy,
final IObservableValue observableValue) {
if (observableValue == null) {
throw new IllegalArgumentException();
}
// Create an anonymous class overriding the findManagedObject method to
// provide the value of the observable.
return new ManagerUpdateSetStrategy(managers, provideDefaults, updatePolicy) {
/**
* This implementation return the value of the observable if it
* contains a ManagedObject
*/
@Override
protected ManagedObject findManagedObject(IObservable target) {
if (observableValue != null && !observableValue.isDisposed() && observableValue.getValue() instanceof ManagedObject) {
return (ManagedObject) observableValue.getValue();
}
return null;
}
};
}
private Managers managers;
/**
......
......@@ -37,83 +37,6 @@ import com.patrikdufresne.managers.Managers;
*/
public class ManagerUpdateValueStrategy extends UpdateValueStrategy {
/**
* Create an update strategy to persists the managed object of an observable
* value.
*
* @param managers
* the managers instance to be used to persist the
* {@link ManagedObject}.
*
* @return a new update set strategy
*/
public static ManagerUpdateValueStrategy persistObservableValue(Managers managers, final IObservableValue observableValue) {
return persistObservableValue(managers, true, UpdateValueStrategy.POLICY_UPDATE, observableValue);
}
/**
* Create an update strategy to persists the managed object of an observable
* value.
*
* @param managers
* the managers instance to be used to persist the
* {@link ManagedObject}.
*
* @param updatePolicy
* one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST},
* {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE}
*
* @return a new update set strategy
*/
public static ManagerUpdateValueStrategy persistObservableValue(Managers managers, int updatePolicy, final IObservableValue observableValue) {
return persistObservableValue(managers, true, updatePolicy, observableValue);
}
/**
* Create an update strategy to persists the managed object of an observable
* value.
*
* @param managers
* the managers instance to be used to persist the
* {@link ManagedObject}.
* @param provideDefaults
* if <code>true</code>, default validators and a default
* converter will be provided based on the observable value's
* type.
* @param updatePolicy
* one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST},
* {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE}
*
* @return a new update set strategy
*/
public static ManagerUpdateValueStrategy persistObservableValue(
Managers managers,
boolean provideDefaults,
int updatePolicy,
final IObservableValue observableValue) {
if (observableValue == null) {
throw new IllegalArgumentException();
}
// Create an anonymous class overriding the findManagedObject method to
// provide the value of the observable.
return new ManagerUpdateValueStrategy(managers, provideDefaults, updatePolicy) {
/**
* This implementation return the value of the observable if it
* contains a ManagedObject
*/
@Override
protected ManagedObject findManagedObject(IObservable target) {
if (observableValue != null && !observableValue.isDisposed() && observableValue.getValue() instanceof ManagedObject) {
return (ManagedObject) observableValue.getValue();
}
return null;
}
};
}
private Managers managers;
/**
......@@ -173,7 +96,7 @@ public class ManagerUpdateValueStrategy extends UpdateValueStrategy {
/**
* This implementation sets the observable value and if the observable is
* associated to a ManagedObject, this class will persiste the data into the
* associated to a ManagedObject, this class will persist the data into the
* manager.
*/
@Override
......