r1040 - trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model
Author: tchemit Date: 2008-02-17 15:53:04 +0000 (Sun, 17 Feb 2008) New Revision: 1040 Added: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java Log: introduction d'un modele de selection d'entity Added: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java 2008-02-17 15:53:04 UTC (rev 1040) @@ -0,0 +1,251 @@ +/* +* ##% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit, Gabriel Landais +* +* This program 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 2 +* 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.ui.swing.model; + +import fr.cemagref.simexplorer.is.entities.EntityHelper; +import fr.cemagref.simexplorer.is.entities.data.DataEntity; +import fr.cemagref.simexplorer.is.entities.data.ExplorationData; +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.ui.SimExplorerContext; +import fr.cemagref.simexplorer.is.ui.StorageServiceHelper; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +/** + * Le model d'un meta sélectionné dans un onglet + * + * @author chemit + * @see DataEntity + */ +public class DataEntityModel implements java.io.Serializable { + + /** flag pour savoir si la source est remote ou non */ + protected Boolean remote; + + /** l'uuid de l'élément sélectionné */ + protected String uuid; + + /** la version de l'élément sélectionné */ + protected Version version; + + /** flag pour indiquer si on veut avoir le resultat */ + protected Boolean result; + + protected EntityHelper.Type type; + + /** l'objet selectionne */ + protected DataEntity data; + + /** l'objet selectionne */ + protected MetaData meta; + + /** l'objet selectionne ou son le */ + protected LoggableElement le; + + /** support pourles changements des propriétés */ + protected PropertyChangeSupport changeSupport; + private static final long serialVersionUID = 7391453280198510606L; + + + public boolean isRemote() { + return remote != null && remote; + } + + public boolean isResult() { + return result != null && result; + } + + public String getUuid() { + return uuid; + } + + public Version getVersion() { + return version; + } + + public MetaData getMeta() { + return meta; + } + + public LoggableElement getLe(SimExplorerContext context) { + if (uuid == null || version == null || remote == null) { + return null; + } + if (le != null) { + return le; + } + // acquire it + le = StorageServiceHelper.getElement(context, isRemote(), uuid, version.toString()); + + if (le == null) { + type = null; + data = null; + } + return le; + } + + public void setMeta(MetaData meta) { + this.meta = meta; + } + + public void setLe(LoggableElement le) { + this.le = le; + } + + public void setData(DataEntity data) { + this.data = data; + } + + public void setType(EntityHelper.Type type) { + this.type = type; + } + + /** + * Getter of selected real object (LoggableElement or Result). + * <p/> + * Will call the correct StorageService if data is not present + * + * @param context the application context + * @return the object selected + */ + public DataEntity get(SimExplorerContext context) { + if (uuid == null || version == null || remote == null) { + return null; + } + if (data != null) { + return data; + } + + // acquire loggableElement + le = getLe(context); + + if (le == null) { + type = null; + data = null; + result=null; + return null; + } + // compute type of data + type = EntityHelper.Type.valueOf(le.getMetaData().getType()); + setResult(EntityHelper.Type.Result == type); + + // compute real data selected + if (type.isLe()) { + return data = le; + } + if (isResult()) { + return data = ((ExplorationData) le).getResult(); + } + //TODO Do the other cases + throw new IllegalStateException("can not find DataEntity for " + this + " and le:" + le); + } + + public void synch(boolean remote, String uuid, Version version) { + reset(); + setRemote(remote); + setUuid(uuid); + setVersion(version); + } + + public void setRemote(boolean remote) { + this.remote = remote; + } + + public void setResult(Boolean result) { + this.result = result; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setVersion(Version version) { + this.version = version; + } + + public void reset() { + remote = null; + uuid = null; + version = null; + result = null; + le = null; + type = null; + data = null; + } + + @Override + public String toString() { + return super.toString() + "<remote:" + remote + ", uuid:" + uuid + + ", version:" + version + ", result:" + result + ", type:" + + type + ">"; + } + + public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + if (listener == null) { + return; + } + if (changeSupport == null) { + changeSupport = new PropertyChangeSupport(this); + } + changeSupport.addPropertyChangeListener(propertyName, listener); + } + + public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { + if (listener == null) { + return; + } + if (changeSupport == null) { + changeSupport = new PropertyChangeSupport(this); + } + changeSupport.addPropertyChangeListener(listener); + } + + public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { + if (listener == null || changeSupport == null) { + return; + } + changeSupport.removePropertyChangeListener(listener); + } + + public synchronized void removePropertyChangeListeners() { + if (changeSupport == null) { + return; + } + for (PropertyChangeListener listener : getPropertyChangeListeners()) { + changeSupport.removePropertyChangeListener(listener); + } + } + + public synchronized PropertyChangeListener[] getPropertyChangeListeners() { + if (changeSupport == null) { + return new PropertyChangeListener[0]; + } + return changeSupport.getPropertyChangeListeners(); + } + + public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + if (changeSupport == null || (oldValue == null && newValue == null) || + (oldValue != null && oldValue.equals(newValue))) { + return; + } + changeSupport.firePropertyChange(propertyName, oldValue, newValue); + } +} \ No newline at end of file
participants (1)
-
tchemit@users.labs.libre-entreprise.org