Salome HOME
Modifications to respect PMD rules.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / DisplayStudyStepAction.java
index b2d468c878facb70c850d7bfa2448c5da8eb4408..b0852f0d6ca3989a5d7fe1c6a72a80fd34212d34 100644 (file)
@@ -2,168 +2,263 @@ package org.splat.simer;
 
 import java.util.List;
 
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
 import org.splat.service.StudyService;
 import org.splat.som.StepRights;
-import org.splat.dal.bo.som.Study;
+import org.splat.wapp.Constants;
 import org.splat.wapp.PopupMenu;
 import org.splat.wapp.SimpleMenu;
 
+/**
+ * Presents the current open study information.
+ * @author Daniel Brunier-Coulin.
+ *
+ */
+public class DisplayStudyStepAction extends AbstractDisplayAction {
 
-public class DisplayStudyStepAction extends DisplayBaseAction {
+       /**
+        * Serial version ID.
+        */
+       private static final long serialVersionUID = 6467920934724352021L;
 
-       protected OpenStudy   mystudy = null;    // Presented study
+       /**
+        * Presented study.
+        */
+       protected transient OpenStudy _openStudy = null;
 
+       /**
+        * Injected study service.
+        */
        private StudyService _studyService;
+       
+       /**
+        * Value of the menu property. 
+        * It can be: none, create, open, study, knowledge, sysadmin, help.
+        */
+       private String _menuProperty;
+       
+       /**
+        * Value of the title bar property. 
+        * It can be: study, knowledge.
+        */
+       private String _titleProperty;
+       
+       /**
+        * Value of the tool bar property. 
+        * It can be: none, standard, study, back.
+        */
+       private String _toolProperty;
+       
+       /**
+        * Value of the left menu property. 
+        * It can be: open, study, knowledge, scenario.
+        */
+       private String _leftMenuProperty;
+       
+       /**
+        * Property that indicates whether the current open study is editable or not.
+        * On the screen it looks like pen on the status icon, pop-up menu also can be called.
+        * It is necessary for correct building the title bar.
+        */
+       private String _editDisabledProperty = "false";
 
-       private static final long serialVersionUID = 6467920934724352021L;
+       // ==============================================================================================================================
+       // Action methods
+       // ==============================================================================================================================
+
+       public String doOpen() {
+               Study study;
+               String res = SUCCESS;
+               _openStudy = getOpenStudy();
+               if (_myindex == null) {
+                       if (_selection == null) { // Opening a study just newed
+                               _selection = _openStudy.getSelection(); // Default selection
+                               study = _openStudy.getStudyObject();
+                       } else { // Re-opening (refreshing) the currently open study
+                               study = getStudyService().selectStudy(_openStudy.getIndex());
+                               _openStudy = open(study); // Closes the previously open study
+                               _openStudy.setSelection(_selection);
+                       }
+               } else {
+                       try { // Opening a study from the search result
+                               int index = Integer.valueOf(_myindex);
+                               if (_openStudy != null && _openStudy.getStudyObject() != null
+                                               && _openStudy.getIndex() == index) { // - The selected study is currently open
+                                       _selection = _openStudy.getSelection(); // Current selection
+                                       study = _openStudy.getStudyObject(); // Current Study object
+                                       // RKV:BEGIN: put in session if necessary
+                                       if (!getSession().containsKey("study.open")) {
+                                               open(study);
+                                       }
+                                       // RKV:END
+                               } else { // - The selected study is new
+                                       study = getStudyService().selectStudy(index);
+                                       _openStudy = open(study);
+                                       _selection = _openStudy.getSelection(); // Default selection
+                               }
+                       } catch (Exception error) {
+                               LOG.error("Reason:", error);
+                               res = ERROR;
+                       }
+               }
+               if (!ERROR.equals(res)){
+                       // Initialization of menus
+                       ProjectElement owner = _openStudy.getSelectedStep().getOwner();
+                       SimpleMenu menu = ApplicationSettings.getMenu("configuration");
+                       if (owner instanceof Scenario) {
+                               menu.enables(Constants.PROP_SCENARIO);
+                               menu.selects(Constants.PROP_SCENARIO);
+                       } else {
+                               menu.disables(Constants.PROP_SCENARIO);
+                               menu.selects("prop-general");
+                       }
+                       getSession().put("menu.study", _openStudy.getMenu());
+                       
+                       setMenuProperty(Constants.STUDY_MENU);
+                       setTitleProperty(Constants.STUDY_MENU);
+                       if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
+                               setToolProperty(Constants.STUDY_MENU);
+                       } else {
+                               setToolProperty(Constants.STANDARD_MENU);
+                       }
+                       
+                       setLeftMenuProperty(Constants.STUDY_MENU);
+       
+                       initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
+               }
+               return res;
+       }
+
+       public String doSelectStep() {
+
+               _openStudy = getOpenStudy();
+               if (_selection == null) { // Switch back to the current study
+                       _selection = _openStudy.getSelection();
+               } else { // Selection of a step of current study
+                       _openStudy.setSelection(_selection);
+               }
+               // Re-initialization of the properties menu according to the selected step
+               ProjectElement owner = _openStudy.getSelectedStep().getOwner();
+               SimpleMenu menu = ApplicationSettings.getMenu("configuration");
+               if (owner instanceof Scenario) {
+                       menu.enables(Constants.PROP_SCENARIO);
+                       menu.selects(Constants.PROP_SCENARIO);
+               } else {
+                       menu.disables(Constants.PROP_SCENARIO);
+                       menu.selects("prop-general");
+               }
+               
+               setMenuProperty(Constants.STUDY_MENU);
+               setTitleProperty(Constants.STUDY_MENU);
+               if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
+                       setToolProperty(Constants.STUDY_MENU);
+               } else {
+                       setToolProperty(Constants.STANDARD_MENU);
+               }
+               
+               setLeftMenuProperty(Constants.STUDY_MENU);
+               initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
+               
+               return SUCCESS;
+       }
+
+       public String doSelectDocument() {
+               _openStudy = getOpenStudy();
+               Execute todo = Execute.valueOf(_action);
+               if (todo == Execute.develop) {
+                       _openStudy.developDocument(_myindex);
+               } else if (todo == Execute.reduce) {
+                       _openStudy.reduceHistory(_myindex);
+               } else if (todo == Execute.reduceall) {
+                       _openStudy.reduceDocument(_myindex);
+               }
+               
+               setMenuProperty(Constants.STUDY_MENU);
+               setTitleProperty(Constants.STUDY_MENU);
+               if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
+                       setToolProperty(Constants.STUDY_MENU);
+               } else {
+                       setToolProperty(Constants.STANDARD_MENU);
+               }
+               setLeftMenuProperty(Constants.STUDY_MENU);
+               initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
+               
+               return SUCCESS;
+       }
+
+       public String doSelectKnowledge() {
+               _openStudy = getOpenStudy();
+               Execute todo = Execute.valueOf(_action);
+               if (todo == Execute.develop) {
+                       _openStudy.developKnowledge(_myindex);
+               } else if (todo == Execute.reduce) {
+                       _openStudy.reduceKnowledge(_myindex);
+               }
+               
+               setMenuProperty(Constants.STUDY_MENU);
+               setTitleProperty(Constants.STUDY_MENU);
+               if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
+                       setToolProperty(Constants.STUDY_MENU);
+               } else {
+                       setToolProperty(Constants.STANDARD_MENU);
+               }
+               setLeftMenuProperty(Constants.STUDY_MENU);
+               initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
+               
+               return SUCCESS;
+       }
+
+       public String doClose() {
+               closeStudy();
+               
+               setMenuProperty("none");
+               initializationScreenContext(_menuProperty);
+               
+               return SUCCESS;
+       }
+
+       // ==============================================================================================================================
+       // Getters
+       // ==============================================================================================================================
+
+       public String getAction() {
+               return _action;
+       }
+
+       public List<DocumentFacade> getDocuments() {
+               return _openStudy.getDisplayedDocuments();
+       }
+
+       public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
+               return _openStudy.getDisplayedKnowledges();
+       }
+
+       public List<SimulationContextFacade> getSimulationContexts() {
+               return _openStudy.getDisplayedSimulationContexts();
+       }
+
+       public PopupMenu getPopup() {
+               return _openStudy.getPopup();
+       }
+
+       public int getStepNumber() {
+               return _openStudy.getSelectedStep().getNumber();
+       }
+
+       public String getStepEnabled() {
+               return String.valueOf(_openStudy.isStepEnabled());
+       }
+
+       public StepRights getUserRights() {
+               return _openStudy.getSelectedStepRights();
+       }
 
-//  ==============================================================================================================================
-//  Action methods
-//  ==============================================================================================================================
-
-    public String doOpen () {
-//  -----------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-      Study        study;
-
-      mystudy = getOpenStudy();
-      if (myindex != null) try {                                // Opening a study from the search result
-       int index = Integer.valueOf(myindex);
-       if (mystudy != null && mystudy.getIndex() == index) {   // - The selected study is currently open
-          selection = mystudy.getSelection();                   // Current selection
-          study     = mystudy.getStudyObject();                 // Current Study object
-       } else {                                                // - The selected study is new
-         study     = getStudyService().selectStudy(index);
-         mystudy   = open(study);
-          selection = mystudy.getSelection();                   // Default selection
-       }
-      }
-      catch (Exception error) {
-       logger.error("Reason:", error);
-        return ERROR;
-      }
-      else if (selection == null) {                             // Opening a study just newed
-        selection = mystudy.getSelection();                     // Default selection
-        study     = mystudy.getStudyObject();
-      }
-      else {                                                    // Re-opening (refreshing) the currently open study
-           study     = getStudyService().selectStudy(mystudy.getIndex());
-        mystudy   = open(study);                                // Closes the previously open study
-        mystudy.setSelection(selection);
-      }
-//    Initialization of menus
-      ProjectElement  owner = mystudy.getSelectedStep().getOwner();
-      SimpleMenu      menu  = ApplicationSettings.getMenu("configuration");
-      if (owner instanceof Scenario) {
-        menu.enables("prop-scenario");
-       menu.selects("prop-scenario");
-      } else {
-        menu.disables("prop-scenario");
-        menu.selects("prop-general");
-      }
-      getSession().put("menu.study", mystudy.getMenu());
-
-      transax.commit();
-      return SUCCESS;
-    }
-    
-    public String doSelectStep () {
-//  -----------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-
-      mystudy = getOpenStudy();
-      if (selection == null) {     // Switch back to the current study
-        selection = mystudy.getSelection();
-      } else {                        // Selection of a step of current study
-        mystudy.setSelection(selection);
-      }
-//    Re-initialization of the properties menu according to the selected step
-      ProjectElement  owner = mystudy.getSelectedStep().getOwner();
-      SimpleMenu      menu  = ApplicationSettings.getMenu("configuration");
-      if (owner instanceof Scenario) {
-        menu.enables("prop-scenario");
-       menu.selects("prop-scenario");
-      } else {
-        menu.disables("prop-scenario");
-        menu.selects("prop-general");
-      }
-      transax.commit();
-      return SUCCESS;
-    }
-
-    public String doSelectDocument () {
-//  ---------------------------------
-      mystudy = getOpenStudy();
-
-      Execute  todo = Execute.valueOf(action);
-      if      (todo == Execute.develop)   mystudy.developDocument(myindex);
-      else if (todo == Execute.reduce)    mystudy.reduceHistory(myindex);
-      else if (todo == Execute.reduceall) mystudy.reduceDocument(myindex);
-      return SUCCESS;
-    }
-
-    public String doSelectKnowledge () {
-//  ----------------------------------
-      mystudy = getOpenStudy();
-
-      Execute  todo = Execute.valueOf(action);
-      if      (todo == Execute.develop)   mystudy.developKnowledge(myindex);
-      else if (todo == Execute.reduce)    mystudy.reduceKnowledge(myindex);
-      return SUCCESS;
-    }
-
-    public String doClose () {
-//  ------------------------
-      closeStudy();
-      return SUCCESS;
-    }
-//  ==============================================================================================================================
-//  Getters
-//  ==============================================================================================================================
-
-    public String getAction () {
-//  --------------------------
-      return action;
-    }
-    public List<DocumentFacade> getDocuments () {
-//  -------------------------------------------
-      return mystudy.getDisplayedDocuments();
-    }
-    public List<OpenObject.KnowledgeIterator> getKnowledges () {
-//  ----------------------------------------------------------
-      return mystudy.getDisplayedKnowledges();
-    }
-    public List<SimulationContextFacade> getSimulationContexts () {
-//  -------------------------------------------------------------
-      return mystudy.getDisplayedSimulationContexts();
-    }
-    public PopupMenu getPopup () {
-//  ----------------------------
-      return mystudy.getPopup();
-    }
-    public int getStepNumber () {
-//  ---------------------------
-      return mystudy.getSelectedStep().getNumber();
-    }
-    public String getStepEnabled () {
-//  -------------------------------
-      return String.valueOf(mystudy.isStepEnabled());
-    }
-    public StepRights getUserRights () {
-//  ----------------------------------
-      return mystudy.getSelectedStepRights();
-    }
-    public String getWriteAccess () {
-//  -------------------------------
-      return String.valueOf(mystudy.isOpenForWriting());
-    }
+       @Override
+       public String getWriteAccess() {
+               return String.valueOf(_openStudy.isOpenForWriting());
+       }
 
        /**
         * Get the studyService.
@@ -180,7 +275,98 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
         * @param studyService
         *            the studyService to set
         */
-       public void setStudyService(StudyService studyService) {
+       public void setStudyService(final StudyService studyService) {
                _studyService = studyService;
        }
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
+        */
+       @Override
+       public void setOpenStudy(final OpenStudy study) {
+               super.setOpenStudy(study);
+               _openStudy = study;
+       }
+       
+       /**
+        * Get the menuProperty.
+        * @return the menuProperty
+        */
+       public String getMenuProperty() {
+               return _menuProperty;
+       }
+
+       /**
+        * Set the menuProperty.
+        * @param menuProperty the menuProperty to set
+        */
+       public void setMenuProperty(final String menuProperty) {
+               this._menuProperty = menuProperty;
+       }
+       
+       /**
+        * Get the _titleProperty.
+        * @return the _titleProperty
+        */
+       public String getTitleProperty() {
+               return _titleProperty;
+       }
+
+       /**
+        * Set the _titleProperty.
+        * @param _titleProperty the titleProperty to set
+        */
+       public void setTitleProperty(final String titleProperty) {
+               _titleProperty = titleProperty;
+       }
+
+       /**
+        * Get the editDisabledProperty.
+        * @return the editDisabledProperty
+        */
+       public String getEditDisabledProperty() {
+               return _editDisabledProperty;
+       }
+
+       /**
+        * Set the editDisabledProperty.
+        * @param editDisabledProperty the editDisabledProperty to set
+        */
+       public void setEditDisabledProperty(final String editDisabledProperty) {
+               _editDisabledProperty = editDisabledProperty;
+       }
+       
+       /**
+        * Get the toolProperty.
+        * @return the toolProperty
+        */
+       public String getToolProperty() {
+               return _toolProperty;
+       }
+
+       /**
+        * Set the toolProperty.
+        * @param toolProperty the toolProperty to set
+        */
+       public void setToolProperty(final String toolProperty) {
+               _toolProperty = toolProperty;
+       }
+       
+       /**
+        * Get the leftMenuProperty.
+        * @return the leftMenuProperty
+        */
+       public String getLeftMenuProperty() {
+               return _leftMenuProperty;
+       }
+
+       /**
+        * Set the leftMenuProperty.
+        * @param leftMenuProperty the leftMenuProperty to set
+        */
+       public void setLeftMenuProperty(final String leftMenuProperty) {
+               _leftMenuProperty = leftMenuProperty;
+       }
 }
\ No newline at end of file