Author: tchemit Date: 2008-02-18 23:03:19 +0000 (Mon, 18 Feb 2008) New Revision: 1095 Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java Log: am?\195?\169lioration mecanisme de synch Modified: 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 2008-02-18 23:02:54 UTC (rev 1094) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DataEntityModel.java 2008-02-18 23:03:19 UTC (rev 1095) @@ -21,14 +21,11 @@ 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.entities.metadata.Version; 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 * @@ -46,31 +43,26 @@ /** la version de l'élément sélectionné */ protected Version version; - /** flag pour indiquer si on veut avoir le resultat */ - protected Boolean result; + /** le type de l'entity encapsulée */ + protected transient EntityHelper.Type type; - protected EntityHelper.Type type; - /** l'objet selectionne */ - protected DataEntity data; + protected transient DataEntity data; - /** l'objet selectionne */ - protected MetaData meta; + /** les meta du le selectionne */ + protected transient MetaData meta; /** l'objet selectionne ou son le */ - protected LoggableElement le; + protected transient LoggableElement le; - /** support pourles changements des propriétés */ - protected PropertyChangeSupport changeSupport; - private static final long serialVersionUID = 7391453280198510606L; + private static final long serialVersionUID = -6047191988584875688L; - public boolean isRemote() { return remote != null && remote; } - public boolean isResult() { - return result != null && result; + public boolean isResult() { + return type != null && type == EntityHelper.Type.Result; } public String getUuid() { @@ -82,6 +74,7 @@ } public MetaData getMeta() { + //TODO should seek meta if null... return meta; } @@ -92,34 +85,17 @@ if (le != null) { return le; } + resetData(); + // acquire it le = StorageServiceHelper.getElement(context, isRemote(), uuid, version.toString()); - if (le == null) { - type = null; - data = null; - } else { + if (le != null) { meta = le.getMetaData(); } 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/> @@ -136,21 +112,22 @@ return data; } + // always reset thoses values, before recomputing them + resetData(); + // 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()) { + meta = le.getMetaData(); return data = le; } if (isResult()) { @@ -160,21 +137,69 @@ throw new IllegalStateException("can not find DataEntity for " + this + " and le:" + le); } - public void synch(boolean remote, String uuid, Version version) { + public void synch(EntityTreeNode node) { + if (node == null) { + synch(remote, null, null); + return; + } + if (node.isResult()) { + EntityTreeNode parent = (EntityTreeNode) node.getParent(); + LoggableElement selectedElement = parent.getLoggableElement(); + synch(node.isRemote(), selectedElement); + setType(EntityHelper.Type.Result); + setData((DataEntity) node.get()); + } else { + synch(node.isRemote(), node.getLoggableElement()); + } + } + + public void synch(Boolean remote, LoggableElement le) { + if (le == null) { + synch(remote, (MetaData) null); + } else { + synch(remote, le.getMetaData()); + } + setLe(le); + } + + public void synch(Boolean remote, MetaData data) { + if (data == null) { + synch(remote, null, null); + } else { + synch(remote, data.getUuid(), data.getVersion()); + EntityHelper.Type type = EntityHelper.Type.valueOf(data.getType()); + setType(type); + } + setMeta(data); + } + + 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 setLe(LoggableElement le) { + this.le = le; } - public void setResult(Boolean result) { - this.result = result; + public void setData(DataEntity data) { + this.data = data; } + public void setMeta(MetaData meta) { + this.meta = meta; + } + + public void setType(EntityHelper.Type type) { + this.type = type; + } + + public void setRemote(boolean remote) { + this.remote = remote; + } + public void setUuid(String uuid) { this.uuid = uuid; } @@ -187,73 +212,34 @@ remote = null; uuid = null; version = null; - result = null; + resetData(); + } + + protected void resetData() { le = null; type = null; data = null; + meta = null; } @Override public String toString() { String s = super.toString(); - return s.substring(s.indexOf('@')) + "<remote:" + remote + ", uuid:" + uuid + - ", version:" + version + ", result:" + result + ", type:" + + return s.substring(s.lastIndexOf('.')+1) + "<remote:" + remote + ", uuid:" + uuid + + ", version:" + version + ", result:" + isResult() + ", type:" + type + ">"; } + public DataEntityModel cloneSafe() { + try { + return clone(); + } catch (CloneNotSupportedException e) { + return null; + } + } + @Override public DataEntityModel clone() throws CloneNotSupportedException { return (DataEntityModel) super.clone(); } - - 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