/**
* GRANITE DATA SERVICES
* Copyright (C) 2006-2015 GRANITE DATA SERVICES S.A.S.
*
* This file is part of the Granite Data Services Platform.
*
* ***
*
* Community License: GPL 3.0
*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* This file 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ***
*
* Available Commercial License: GraniteDS SLA 1.0
*
* This is the appropriate option if you are creating proprietary
* applications and you are not prepared to distribute and share the
* source code of your application under the GPL v3 license.
*
* Please visit http://www.granitedataservices.com/license for more
* details.
*/
package org.granite.client.persistence.collection.observable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
import org.granite.binding.collection.ObservableListWrapper;
import org.granite.client.persistence.Loader;
import org.granite.client.persistence.collection.PersistentCollection;
import org.granite.client.persistence.collection.PersistentList;
import org.granite.client.persistence.collection.UnsafePersistentCollection;
/**
* @author William DRAI
*/
public class ObservablePersistentList<E> extends ObservableListWrapper<E> implements UnsafePersistentCollection<List<E>> {
private static final long serialVersionUID = 1L;
private final PersistentList<E> persistentList;
public ObservablePersistentList() {
super(new PersistentList<E>());
this.persistentList = (PersistentList<E>)getWrappedObservable();
}
public ObservablePersistentList(PersistentList<E> persistentList) {
super(persistentList);
this.persistentList = persistentList;
}
@Override
public PersistentList<E> internalPersistentCollection() {
return persistentList;
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
internalPersistentCollection().writeExternal(out);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
internalPersistentCollection().readExternal(in);
}
@Override
public boolean wasInitialized() {
return internalPersistentCollection().wasInitialized();
}
@Override
public void uninitialize() {
internalPersistentCollection().uninitialize();
}
@Override
public void initialize(List<E> list, final Initializer<List<E>> initializer) {
internalPersistentCollection().initialize(list, initializer != null ? initializer : new Initializer<List<E>>() {
@Override
public void initialize(List<E> list) {
addAll(list);
}
});
}
@Override
public void initializing() {
internalPersistentCollection().initializing();
}
@Override
public PersistentCollection<List<E>> clone(boolean uninitialize) {
return internalPersistentCollection().clone(uninitialize);
}
@Override
public Loader<List<E>> getLoader() {
return internalPersistentCollection().getLoader();
}
@Override
public void setLoader(Loader<List<E>> loader) {
internalPersistentCollection().setLoader(loader);
}
@Override
public boolean isDirty() {
return internalPersistentCollection().isDirty();
}
@Override
public void dirty() {
internalPersistentCollection().dirty();
}
@Override
public void clearDirty() {
internalPersistentCollection().clearDirty();
}
@Override
public void addListener(ChangeListener<List<E>> listener) {
internalPersistentCollection().addListener(listener);
}
@Override
public void removeListener(ChangeListener<List<E>> listener) {
internalPersistentCollection().removeListener(listener);
}
@Override
public void addListener(InitializationListener<List<E>> listener) {
internalPersistentCollection().addListener(listener);
}
@Override
public void removeListener(InitializationListener<List<E>> listener) {
internalPersistentCollection().removeListener(listener);
}
@Override
public void withInitialized(InitializationCallback<List<E>> callback) {
internalPersistentCollection().withInitialized(callback);
}
}