Salome HOME
Update copyrights 2014.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / OpenStudy.java
index 901495af93ba1f777ce25c6fee101e8cef0175ae..50e3c30dd09733f79980fa71b37f5f182c9004ad 100644 (file)
@@ -3,7 +3,7 @@ package org.splat.simer;
 /**
  * 
  * @author    Daniel Brunier-Coulin
- * @copyright OPEN CASCADE 2012
+ * @copyright OPEN CASCADE 2012-2014
  */
 
 import java.io.File;
@@ -124,8 +124,10 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                                .getRevisionPattern());
 
                _cuser = user; // May be null if nobody connected
+               if(!study.equals(_mystudy)) {
+                       _selection = "0.1"; // Default selection
+               }
                _mystudy = study;
-               _selection = "0.1"; // Default selection
                _selecdoc = null;
 
                // Preparation of the display
@@ -133,11 +135,17 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                _credate = datstring.format(_mystudy.getDate());
                _lasdate = datstring.format(_mystudy.getLastModificationDate());
                _description = _mystudy.getDescription();
-               _involving = new ArrayList<Step>(1);
+               //_involving = new ArrayList<Step>(1);
                _context = new ArrayList<SimulationContextFacade>();
-               _ustep = getProjectElementService().getFirstStep(_mystudy);
-               _ustep.setActor(_cuser);
-               _involving.add(_ustep);
+               if (_selection.equals("0.1")) {
+                       _ustep = getProjectElementService().getFirstStep(_mystudy);
+               }
+               _ustep.setActor(_cuser);        
+               if ((_involving.isEmpty()) || (_involving.get(0).getOwnerStudy().getIndex()
+                               != _ustep.getOwnerStudy().getIndex())) {
+                       _involving.clear();
+                       _involving.add(_ustep);
+               }
                for (Iterator<SimulationContext> i = _ustep.getAllSimulationContexts()
                                .iterator(); i.hasNext();) {
                        _context.add(new SimulationContextFacade(i.next(),
@@ -165,19 +173,25 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                                        _popup = getApplicationSettings().getPopupMenu(
                                                        "steditablemarkprivate");
                                } else {
-                                       if (_mystudy.getProgressState() == ProgressState.inWORK) {
-                                               _popup = getApplicationSettings().getPopupMenu(
-                                                               "steditable");
-                                       } else if (_mystudy.getProgressState() == ProgressState.inDRAFT) {
-                                               _popup = getApplicationSettings().getPopupMenu(
-                                                               "streviewable");
-                                       } else if (_mystudy.getProgressState() == ProgressState.inCHECK) {
-                                               _popup = getApplicationSettings().getPopupMenu(
-                                                               "stapprovable");
-                                       } else { // APPROVED
-                                               _popup = getApplicationSettings().getPopupMenu(
-                                                               "steditablemarkpublic");
+                                       String key = null;
+                                       switch(_mystudy.getProgressState()) {
+                                               case inWORK:
+                                                       key = "steditable";
+                                                       break;
+                                               case inDRAFT:
+                                                       key = "streviewable";
+                                                       break;
+                                               case inCHECK:
+                                                       key = "stapprovable";
+                                                       break;
+                                               default: // APPROVED
+                                                       key = "steditablemarkpublic";
+                                                       break;
                                        }
+                                       if(Long.valueOf(getSelectedScenarioId()) != 0) {
+                                               key += "ScenarioSelected";
+                                       }
+                                       _popup = getApplicationSettings().getPopupMenu(key);
                                }
 
                        }
@@ -339,11 +353,17 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
         */
        @Override
        public String getType() {
-               /*
-                * RKV: return ResourceBundle.getBundle("labels", getApplicationSettings().getCurrentLocale()).getString( "label.study");
-                */
                return Constants.STUDY_MENU;
        }
+       
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.simer.AbstractOpenObject#getTypeName()
+        */
+       @Override
+       public String getTypeName() {
+               return ResourceBundle.getBundle("labels", getApplicationSettings().getCurrentLocale()).getString( "label.study");
+       }
 
        /**
         * Get the study version.
@@ -640,7 +660,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
        protected void update(final Publication doc) {
                DocumentFacade facade = _docpres.get(doc.getIndex());
                if (facade != null) {
-                       facade.refresh();
+                       _contents.remove(facade);
+                       facade = new DocumentFacade(this, doc,
+                                       getProjectSettings(), getPublicationService(),
+                                       getApplicationSettings());
+                       _docpres.put(doc.getIndex(), facade);
+                       _contents.add(facade);
                }
        }
 
@@ -822,4 +847,13 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
        public void setMystudy(final Study mystudy) {
                this._mystudy = mystudy;
        }
+
+       /**
+        * Update the current step.
+        *
+        */
+       public final void updateCurrentStep() {
+               setupPreviousToSelectedSteps();
+               _ustep = _involving.get(_involving.size() - 1);
+       }
 }
\ No newline at end of file