Salome HOME
Fix of wrong search results after logout.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / OpenStudy.java
index 1fef3115cc646acb4ac8688972acccf060d0c306..e6190801bf1d92edd4f670094ac5fc78ea7cc00d 100644 (file)
@@ -14,7 +14,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
 
-import org.apache.log4j.Logger;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
@@ -25,6 +24,7 @@ import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
 import org.splat.kernel.Do;
+import org.splat.log.AppLogger;
 import org.splat.manox.Toolbox;
 import org.splat.manox.Writer;
 import org.splat.service.DocumentService;
@@ -38,15 +38,22 @@ import org.splat.som.Step;
 import org.splat.som.StepRights;
 import org.splat.som.StudyRights;
 import org.splat.util.BeanHelper;
+import org.splat.wapp.Constants;
 import org.splat.wapp.ToolBar;
 
+/**
+ * Presentation of the currently open study.
+ */
 public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
 
        /**
         * Serial version ID.
         */
-       protected final static Logger LOGGER = org.splat.simer.Action.LOG;
+       protected final static AppLogger LOGGER = org.splat.simer.Action.LOG;
 
+       /**
+        * The currently open study.
+        */
        private transient Study _mystudy;
        /**
         * User rights on the open study.
@@ -98,7 +105,8 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                ResourceBundle custom = ResourceBundle.getBundle("som",
                                getApplicationSettings().getCurrentLocale());
                SimpleDateFormat datstring = new SimpleDateFormat(custom
-                               .getString("date.format"));
+                               .getString("date.format"), getApplicationSettings()
+                               .getCurrentLocale());
                Revision.Format verstring = new Revision.Format(getProjectSettings()
                                .getRevisionPattern());
 
@@ -128,9 +136,40 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                        // ProgressState state = mystudy.getProgressState();
                        // if (state == ProgressState.inCHECK) popup = getApplicationSettings().getPopupMenu("stapprovable");
                        // else if (state == ProgressState.APPROVED) popup = getApplicationSettings().getPopupMenu("stapproved");
-                       /* else */_popup = getApplicationSettings().getPopupMenu(
-                                       "steditable");
-                       _popup.setContext("study", new StudyRights(_cuser, _mystudy));
+                       /* else */
+
+                       if (_mystudy.getProgressState() == ProgressState.TEMPLATE) {
+                               if (_mystudy.isPublic()) {
+                                       _popup = getApplicationSettings().getPopupMenu(
+                                                       "steditableunmarkprivate");
+                               } else {
+                                       _popup = getApplicationSettings().getPopupMenu(
+                                                       "steditableunmarkpublic");
+                               }
+                       } else {
+
+                               if (_mystudy.isPublic()) {
+                                       _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");
+                                       }
+                               }
+
+                       }
+                       _popup.setContext(Constants.STUDY_MENU, new StudyRights(_cuser,
+                                       _mystudy));
                }
                _urightstudy = new StudyRights(_cuser, _mystudy);
                _urightstep = new StepRights(_cuser, _ustep);
@@ -146,10 +185,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
        // Getters
        // ==============================================================================================================================
 
+       @Override
        public String getAuthorName() {
                return _mystudy.getAuthor().toString();
        }
 
+       @Override
        public Long getIndex() {
                return _mystudy.getIndex();
        }
@@ -167,6 +208,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                _menu = aMenu;
        }
 
+       @Override
        public ProgressState getProgressState() {
                return _mystudy.getProgressState();
        }
@@ -179,10 +221,12 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                return getApplicationSettings().getModuleBar(getSelectedStep());
        }
 
+       @Override
        public String getReference() {
                return _mystudy.getReference();
        }
 
+       @Override
        public Publication getSelectedDocument() {
                return _selecdoc;
        }
@@ -199,15 +243,17 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                return _mystudy;
        }
 
+       @Override
        public String getTitle() {
                return _mystudy.getTitle();
        }
 
+       @Override
        public String getType() {
                /*
                 * RKV: return ResourceBundle.getBundle("labels", getApplicationSettings().getCurrentLocale()).getString( "label.study");
                 */
-               return "study";
+               return Constants.STUDY_MENU;
        }
 
        public String getVersion() {
@@ -222,6 +268,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
        // Public services
        // ==============================================================================================================================
 
+       @Override
        public URL newTemplateBasedDocument(final String typename, final User author) {
                String filename = typename + ".xml"; // Only XML templates are writeable
                File template = new File(getRepositoryService().getTemplatePath()
@@ -258,7 +305,8 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                        ResourceBundle locale = ResourceBundle.getBundle("som",
                                        getApplicationSettings().getCurrentLocale());
                        SimpleDateFormat get = new SimpleDateFormat(locale
-                                       .getString("date.format"));
+                                       .getString("date.format"), getApplicationSettings()
+                                       .getCurrentLocale());
                        Writer tool = Toolbox.getWriter(credoc);
                        List<Step> slist = getInvolvedSteps();
                        for (Iterator<Step> i = slist.iterator(); i.hasNext();) {
@@ -272,7 +320,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                                }
                        }
                        tool.updateProperty("reference", medoc.getReference());
-                       tool.updateProperty("study", _mystudy.getTitle());
+                       tool.updateProperty(Constants.STUDY_MENU, _mystudy.getTitle());
                        tool.updateProperty("step", locale.getString(
                                        "folder.step." + step.getNumber()).replaceAll("''", "'"));
                        tool.updateProperty("author", author.getUsername().toUpperCase());
@@ -328,7 +376,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                                getApplicationSettings());
                boolean first = (_contents.size() == 0);
 
-               docpres.put(doc.getIndex(), facade);
+               _docpres.put(doc.getIndex(), facade);
                _contents.add(0, facade); // Prepend the new publication
                if (first) {
                        this.getMenu().refreshSelectedItem();
@@ -359,7 +407,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                        }
                }
                if (known != null) { // RKV:End
-                       knowpres.put(kelm.getIndex(), facade);
+                       _knowpres.put(kelm.getIndex(), facade);
                        known._list.add(facade); // Insert the new knowledge at the end of the corresponding knowledge type
                }
        }
@@ -381,8 +429,10 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                _cuser = user;
                _popup = null;
                if (getStudyService().isStaffedBy(_mystudy, _cuser)) {
-                       _popup = getApplicationSettings().getPopupMenu("steditable");
-                       _popup.setContext("study", new StudyRights(_cuser, _mystudy));
+                       _popup = getApplicationSettings().getPopupMenu(
+                                       "steditablemarkpublic");
+                       _popup.setContext(Constants.STUDY_MENU, new StudyRights(_cuser,
+                                       _mystudy));
                }
                // ustep = getProjectElementService().getFirstStep(mystudy);
                if (_ustep != null) {
@@ -418,7 +468,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                        }
                }
                if (known != null) { // RKV:End
-                       knowpres.remove(kelm.getIndex());
+                       _knowpres.remove(kelm.getIndex());
                        for (Iterator<KnowledgeElementFacade> i = known._list.iterator(); i
                                        .hasNext();) {
                                KnowledgeElementFacade facade = i.next();
@@ -433,14 +483,14 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
        }
 
        protected void update(final Publication doc) {
-               DocumentFacade facade = docpres.get(doc.getIndex());
+               DocumentFacade facade = _docpres.get(doc.getIndex());
                if (facade != null) {
                        facade.refresh();
                }
        }
 
        protected void update(final KnowledgeElementDTO kelm) {
-               KnowledgeElementFacade facade = knowpres.get(kelm.getIndex());
+               KnowledgeElementFacade facade = _knowpres.get(kelm.getIndex());
                if (facade != null) {
                        facade.refresh(kelm);
                }
@@ -488,10 +538,9 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices {
                step = getProjectElementService().getSteps(_mystudy);
                for (int i = step.length - 1; i > -1; i--) {
                        Step firstep = step[i];
-                       if (firstep.getNumber() > base) {
-                               continue;
+                       if (firstep.getNumber() <= base) {
+                               _involving.add(0, firstep);
                        }
-                       _involving.add(0, firstep);
                }
        }