Salome HOME
Vasily has fixed the following bug :
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / VersionDocumentAction.java
index 90fe6d9ccdb7fd71f72be758c2e1720f9ef0299c..90733644a26a13fa2c333d2f464ab4891df951f6 100644 (file)
@@ -5,6 +5,7 @@ import java.io.FileNotFoundException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
 
@@ -64,8 +65,9 @@ public class VersionDocumentAction extends BaseUploadDocumentAction {
                File upfile = commonInitialize(Constants.TRUE);
 
                _mystudy = getOpenStudy();
+               _mystudy.updateCurrentStep();
                _defuses = new ArrayList<Document>();
-
+               
                Publication tag = _mystudy.getSelectedStep().getDocument(
                                Integer.valueOf(_index));
                Document doc = tag.value();
@@ -79,33 +81,45 @@ public class VersionDocumentAction extends BaseUploadDocumentAction {
                                setupDefaultUses(_deftype);
                        }
                        // Add additional documents used by the current version
-                       for (Relation usesRel: doc.getRelations(UsesRelation.class)) {
+                       for (Relation usesRel : doc.getRelations(UsesRelation.class)) {
                                Document used = (Document) usesRel.getTo();
-                               if (!_defuses.contains(used)) {
-                                       _defuses.add(used);
+                               Document lastVersion = getPublicationService().getLastVersion(used, tag.getOwner());
+                               if (lastVersion != null && !_defuses.contains(lastVersion)) {
+                                       _defuses.add(lastVersion);
                                }
                        }
                        // Avoid recursive using of the document
                        if (_defuses.contains(doc)) {
                                _defuses.remove(doc);
                        }
+                       
+                       // Avoid using of documents dependent on the current version of the document being versioned
+                       // (This case is possible only if both documents belong to the step of the same Project Element)
+                       for(Iterator<Document> document = _defuses.iterator(); document.hasNext(); ) {
+                               Publication pub = tag.getOwner().getPublication(document.next());
+                               if(pub != null && pub.getRelations(UsesRelation.class).contains(tag)) {
+                                       document.remove();
+                               }
+                       }
+                       
                        // Setup dependencies
                        _usedby.addAll(tag.getRelations(UsedByRelation.class));
 
                        // Initialize applicable states list
-                       if(tag.value().getProgressState() == ProgressState.EXTERN) {
+                       if (tag.value().getProgressState() == ProgressState.EXTERN) {
                                _documentStates.add(ProgressState.EXTERN);
                        } else {
-                       _documentStates.add(ProgressState.inWORK);
-                       if (_deftype != null) {
-                               // Check if the validation cycle of the document type can has a review state
-                               ValidationCycle cycle = getStudyService().getValidationCycleOf(
-                                               _mystudy.getMystudy(), _deftype);
-                               if ((cycle != null) && cycle.enables(ValidationStep.REVIEW)) {
-                                       _documentStates.add(ProgressState.inDRAFT);
+                               _documentStates.add(ProgressState.inWORK);
+                               if (_deftype != null) {
+                                       // Check if the validation cycle of the document type can has a review state
+                                       ValidationCycle cycle = getStudyService()
+                                                       .getValidationCycleOf(_mystudy.getMystudy(),
+                                                                       _deftype);
+                                       if ((cycle != null) && cycle.enables(ValidationStep.REVIEW)) {
+                                               _documentStates.add(ProgressState.inDRAFT);
+                                       }
                                }
                        }
-                       }
                } else {
                        if (!(Constants.NONE.equals(getToolProperty()))) {
                                initializationFullScreenContext(Constants.STUDY_MENU,
@@ -203,8 +217,7 @@ public class VersionDocumentAction extends BaseUploadDocumentAction {
                                                _state, aDate, listDocuses, _docusedby);
 
                                // Update of the open study
-                               _mystudy.setSelection(_mystudy.getSelection()); // Rebuilds the presentation
-                               // TODO: Look is an optimization is possible (for example by updating the presentation of versioned document)
+                               refreshStudy();
 
                                res = SUCCESS;
                        } catch (FileNotFoundException error) {