Salome HOME
- Set up-to date functionality is implemented;
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / DocumentFacade.java
index 260b2a32e85fef47ec62ffd09abe8b9e25d84876..accc56b79e994100c74df290d1a9a453e3d7acbf 100644 (file)
@@ -10,7 +10,6 @@ import java.io.File;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
 
@@ -226,32 +225,32 @@ public class DocumentFacade implements HistoryFacade {
                        _display = State.deepopen;
                } else { // Opening the document
                        if (_uses == null) {
-                               List<Publication> relist = _me.getRelations(UsesRelation.class);
+                               List<Relation> relist = _me.value().getRelations(UsesRelation.class);
 
                                _uses = new ArrayList<DocumentFacade>(relist.size());
-                               for (Iterator<Publication> i = relist.iterator(); i.hasNext();) {
-                                       Publication used = i.next();
-                                       long index = used.getIndex();
-                                       DocumentFacade facade = _owner._docpres.get(index);
+                               for (Relation relation : relist) {
+                                       Document used = ((UsesRelation)relation).getTo();
+                                       
+                                       DocumentFacade facade = null;
+                                       
+                                       Publication publication = _me.getOwner().getPublication(used);
+                                       if(publication == null) {
+                                               publication = _me.getOwnerStudy().getPublication(used);
+                                       }
+                                       if(publication != null) {
+                                               facade = _owner._docpres.get(publication.getIndex());
+                                       }
+                                       
                                        if (facade == null) {
                                                facade = new DocumentFacade(_owner, used,
                                                                getProjectSettings(), getPublicationService(),
                                                                getApplicationSettings());
-                                               _owner._docpres.put(index, facade);
                                        }
                                        _uses.add(facade);
                                }
                        }
                        if (_exports == null) {
-                               List<Relation> relation = _mydoc
-                                               .getRelations(ConvertsRelation.class);
-
-                               _exports = new ArrayList<FileFacade>(relation.size());
-                               for (Iterator<Relation> i = relation.iterator(); i.hasNext();) {
-                                       ConvertsRelation export = (ConvertsRelation) i.next();
-                                       _exports.add(new FileFacade(export,
-                                                       getApplicationSettings()));
-                               }
+                               updateExports();
                        }
                        if (_history == null) {
                                if (_mydoc.getPreviousVersion() != null
@@ -263,6 +262,20 @@ public class DocumentFacade implements HistoryFacade {
                        _display = State.open;
                }
        }
+       
+       /**
+        * Update the list of export files.
+        */
+       private void updateExports() {
+               List<Relation> relations = _mydoc
+                               .getRelations(ConvertsRelation.class);
+
+               _exports = new ArrayList<FileFacade>(relations.size());
+               for (Relation rel : relations) {
+                       _exports.add(new FileFacade((ConvertsRelation)rel,
+                                       getApplicationSettings()));
+               }
+       }
 
        /**
         * Close the presentation tree partially.
@@ -509,7 +522,7 @@ public class DocumentFacade implements HistoryFacade {
                        _version = verstring.format(_version);
                _size = sizstring.format(_mydoc.getSourceFile().asFile().length() / 1000);
                _date = datstring.format(_mydoc.getLastModificationDate());
-
+               updateExports();
                // Refresh of the history in case of promotion
                if (_display == State.deepopen) {
                        _history.clear();
@@ -559,9 +572,9 @@ public class DocumentFacade implements HistoryFacade {
                                _sharing = "image.share.png";
                                _updated = "icon.hold.png";
                        }
-                       if (_me.isOutdated()) {
-                               _state = ProgressState.inWORK; // Overrides the document state
-                       }
+                       //if (_me.isOutdated()) {
+                       //      _state = ProgressState.inWORK; // Overrides the document state
+                       //}
                }
        }