Salome HOME
Modifications to respect PMD rules.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / DisplayStudyStepAction.java
index ff3b5de00120379c92b16776fb50378a7c36e39a..b0852f0d6ca3989a5d7fe1c6a72a80fd34212d34 100644 (file)
@@ -4,9 +4,10 @@ import java.util.List;
 
 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;
 
@@ -15,7 +16,7 @@ import org.splat.wapp.SimpleMenu;
  * @author Daniel Brunier-Coulin.
  *
  */
-public class DisplayStudyStepAction extends DisplayBaseAction {
+public class DisplayStudyStepAction extends AbstractDisplayAction {
 
        /**
         * Serial version ID.
@@ -25,7 +26,7 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
        /**
         * Presented study.
         */
-       protected OpenStudy mystudy = null;
+       protected transient OpenStudy _openStudy = null;
 
        /**
         * Injected study service.
@@ -50,6 +51,12 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
         */
        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.
@@ -63,14 +70,24 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
 
        public String doOpen() {
                Study study;
-               mystudy = getOpenStudy();
-               if (myindex != null)
+               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 (mystudy != null && mystudy.getStudyObject() != null
-                                               && mystudy.getIndex() == index) { // - The selected study is currently open
-                                       selection = mystudy.getSelection(); // Current selection
-                                       study = mystudy.getStudyObject(); // Current Study object
+                               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);
@@ -78,115 +95,117 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
                                        // RKV:END
                                } else { // - The selected study is new
                                        study = getStudyService().selectStudy(index);
-                                       mystudy = open(study);
-                                       selection = mystudy.getSelection(); // Default selection
+                                       _openStudy = open(study);
+                                       _selection = _openStudy.getSelection(); // Default selection
                                }
                        } catch (Exception error) {
-                               logger.error("Reason:", error);
-                               return ERROR;
+                               LOG.error("Reason:", error);
+                               res = 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());
-               
-               setMenuProperty("study");
-               setTitleProperty("study");
-               if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
-                       setToolProperty("study");
-               } else {
-                       setToolProperty("standard");
+               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);
                }
-
-               initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
-
-               return SUCCESS;
+               return res;
        }
 
        public String doSelectStep() {
 
-               mystudy = getOpenStudy();
-               if (selection == null) { // Switch back to the current study
-                       selection = mystudy.getSelection();
+               _openStudy = getOpenStudy();
+               if (_selection == null) { // Switch back to the current study
+                       _selection = _openStudy.getSelection();
                } else { // Selection of a step of current study
-                       mystudy.setSelection(selection);
+                       _openStudy.setSelection(_selection);
                }
                // Re-initialization of the properties menu according to the selected step
-               ProjectElement owner = mystudy.getSelectedStep().getOwner();
+               ProjectElement owner = _openStudy.getSelectedStep().getOwner();
                SimpleMenu menu = ApplicationSettings.getMenu("configuration");
                if (owner instanceof Scenario) {
-                       menu.enables("prop-scenario");
-                       menu.selects("prop-scenario");
+                       menu.enables(Constants.PROP_SCENARIO);
+                       menu.selects(Constants.PROP_SCENARIO);
                } else {
-                       menu.disables("prop-scenario");
+                       menu.disables(Constants.PROP_SCENARIO);
                        menu.selects("prop-general");
                }
                
-               setMenuProperty("study");
-               setTitleProperty("study");
-               if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
-                       setToolProperty("study");
+               setMenuProperty(Constants.STUDY_MENU);
+               setTitleProperty(Constants.STUDY_MENU);
+               if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
+                       setToolProperty(Constants.STUDY_MENU);
                } else {
-                       setToolProperty("standard");
+                       setToolProperty(Constants.STANDARD_MENU);
                }
-               initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+               
+               setLeftMenuProperty(Constants.STUDY_MENU);
+               initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
                
                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);
+               _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("study");
-               setTitleProperty("study");
-               if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
-                       setToolProperty("study");
+               setMenuProperty(Constants.STUDY_MENU);
+               setTitleProperty(Constants.STUDY_MENU);
+               if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
+                       setToolProperty(Constants.STUDY_MENU);
                } else {
-                       setToolProperty("standard");
+                       setToolProperty(Constants.STANDARD_MENU);
                }
-               initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+               setLeftMenuProperty(Constants.STUDY_MENU);
+               initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
                
                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);
+               _openStudy = getOpenStudy();
+               Execute todo = Execute.valueOf(_action);
+               if (todo == Execute.develop) {
+                       _openStudy.developKnowledge(_myindex);
+               } else if (todo == Execute.reduce) {
+                       _openStudy.reduceKnowledge(_myindex);
+               }
                
-               setMenuProperty("study");
-               setTitleProperty("study");
-               if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
-                       setToolProperty("study");
+               setMenuProperty(Constants.STUDY_MENU);
+               setTitleProperty(Constants.STUDY_MENU);
+               if (Constants.TRUE.equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
+                       setToolProperty(Constants.STUDY_MENU);
                } else {
-                       setToolProperty("standard");
+                       setToolProperty(Constants.STANDARD_MENU);
                }
-               initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
+               setLeftMenuProperty(Constants.STUDY_MENU);
+               initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
                
                return SUCCESS;
        }
@@ -205,39 +224,40 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
        // ==============================================================================================================================
 
        public String getAction() {
-               return action;
+               return _action;
        }
 
        public List<DocumentFacade> getDocuments() {
-               return mystudy.getDisplayedDocuments();
+               return _openStudy.getDisplayedDocuments();
        }
 
-       public List<OpenObject.KnowledgeIterator> getKnowledges() {
-               return mystudy.getDisplayedKnowledges();
+       public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
+               return _openStudy.getDisplayedKnowledges();
        }
 
        public List<SimulationContextFacade> getSimulationContexts() {
-               return mystudy.getDisplayedSimulationContexts();
+               return _openStudy.getDisplayedSimulationContexts();
        }
 
        public PopupMenu getPopup() {
-               return mystudy.getPopup();
+               return _openStudy.getPopup();
        }
 
        public int getStepNumber() {
-               return mystudy.getSelectedStep().getNumber();
+               return _openStudy.getSelectedStep().getNumber();
        }
 
        public String getStepEnabled() {
-               return String.valueOf(mystudy.isStepEnabled());
+               return String.valueOf(_openStudy.isStepEnabled());
        }
 
        public StepRights getUserRights() {
-               return mystudy.getSelectedStepRights();
+               return _openStudy.getSelectedStepRights();
        }
 
+       @Override
        public String getWriteAccess() {
-               return String.valueOf(mystudy.isOpenForWriting());
+               return String.valueOf(_openStudy.isOpenForWriting());
        }
 
        /**
@@ -255,7 +275,7 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
         * @param studyService
         *            the studyService to set
         */
-       public void setStudyService(StudyService studyService) {
+       public void setStudyService(final StudyService studyService) {
                _studyService = studyService;
        }
 
@@ -265,9 +285,9 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
         * @see org.splat.simer.Action#setOpenStudy(org.splat.simer.OpenStudy)
         */
        @Override
-       public void setOpenStudy(OpenStudy study) {
+       public void setOpenStudy(final OpenStudy study) {
                super.setOpenStudy(study);
-               mystudy = study;
+               _openStudy = study;
        }
        
        /**
@@ -282,7 +302,7 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
         * Set the menuProperty.
         * @param menuProperty the menuProperty to set
         */
-       public void setMenuProperty(String menuProperty) {
+       public void setMenuProperty(final String menuProperty) {
                this._menuProperty = menuProperty;
        }
        
@@ -298,7 +318,7 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
         * Set the _titleProperty.
         * @param _titleProperty the titleProperty to set
         */
-       public void setTitleProperty(String titleProperty) {
+       public void setTitleProperty(final String titleProperty) {
                _titleProperty = titleProperty;
        }
 
@@ -314,7 +334,7 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
         * Set the editDisabledProperty.
         * @param editDisabledProperty the editDisabledProperty to set
         */
-       public void setEditDisabledProperty(String editDisabledProperty) {
+       public void setEditDisabledProperty(final String editDisabledProperty) {
                _editDisabledProperty = editDisabledProperty;
        }
        
@@ -333,4 +353,20 @@ public class DisplayStudyStepAction extends DisplayBaseAction {
        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