]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/NewScenarioAction.java
Salome HOME
Actions menu properties are refactored, unnecessary code is removed.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / NewScenarioAction.java
index e93a67d1e11a3452a2a301c5986e264f740db364..d750428009595c3c60544c01d9c0834cfa86a8b5 100644 (file)
@@ -11,18 +11,18 @@ import org.splat.dal.bo.som.Study;
 import org.splat.service.ProjectElementService;
 import org.splat.service.ScenarioService;
 import org.splat.som.Step;
+import org.splat.wapp.Constants;
 import org.splat.wapp.Menu;
 
-
 public class NewScenarioAction extends Action {
 
-       private  OpenStudy        mystudy;
-       private  List<Scenario>   myscene;
-       private  String           mytitle;
-    private  String           selection;
-    private  long              scindex;
-    private  int              bastep;
-    private  ToDo             action;
+       private transient OpenStudy _mystudy;
+       private transient List<Scenario> _myscene;
+       private String _title;
+       private String _selection;
+       private transient long _scindex;
+       private transient int _bastep;
+       private transient ToDo _action;
        /**
         * Injected scenario service.
         */
@@ -32,210 +32,180 @@ public class NewScenarioAction extends Action {
         */
        private ProjectElementService _projectElementService;
        private Menu _menu;
-       
-       /**
-        * 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";
 
        /**
         * Serial version ID.
         */
        private static final long serialVersionUID = -5586724442986956861L;
 
-    protected enum  ToDo { cancel, save };
-
-//  ==============================================================================================================================
-//  Action methods
-//  ==============================================================================================================================
-
-    public String doInitialize () {
-//  -----------------------------    
-                     mystudy = getOpenStudy();
-      Study          study   = mystudy.getStudyObject();
-      Scenario[]     scene   = study.getScenarii();
-      Scenario       base    = scene[scene.length-1];   // Default base scenario
-      ResourceBundle locale  = ResourceBundle.getBundle("labels", getApplicationSettings().getCurrentLocale());
-
-      myscene   = Arrays.asList(scene);
-      scindex   = base.getIndex();
-      mytitle   = locale.getString("label.scenario") + " " + String.valueOf(scene.length+1);
-      bastep    = getProjectElementService().getFirstStep(base).getNumber();      // Better use the last current step ?
-      selection = scindex + "." + bastep;
-      action    = null;
-      
-//RKV      Menu menu = new NewScenarioMenu(study);
-      Menu menu = ((NewScenarioMenu)getMenu()).init(study); //RKV
-      menu.selects(selection);
-      getSession().put("menu.scenario", menu);
-      
-      setMenuProperty("study");
-      setTitleProperty("study");
-      setEditDisabledProperty("true");
-      setToolProperty("none");
-      setLeftMenuProperty("scenario");
-      initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
-      
-      setActionType("focus");
-               
-      return SUCCESS;
-    }
-
-    public String doSelectStep () {
-//  -----------------------------
-                 mystudy = getOpenStudy();
-      Study      study   = mystudy.getStudyObject();
-      Scenario[] scene   = study.getScenarii();
-
-      myscene   = Arrays.asList(scene);
-      bastep    = getProjectElementService().getFirstStep(scene[0]).getNumber();  // All scenarios have the same first step number
-      action    = null;
-        
-      getMenu("scenario").selects(selection);
-      
-      setMenuProperty("study");
-      setTitleProperty("study");
-      setEditDisabledProperty("true");
-      setToolProperty("none");
-      setLeftMenuProperty("scenario");
-      initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
-      
-      setActionType("none");
-      
-      return SUCCESS;
-    }
-
-    public String doCreate () {
-//  -------------------------
-      if (action == ToDo.cancel) return "cancel";
-
-//      Session      session   = Database.getCurSession();
-//       Transaction  transax   = session.beginTransaction();  
-         try {        mystudy   = getOpenStudy();
-                   selection = getMenu("scenario").getSelection();
-        Study      study     = mystudy.getStudyObject();
-        String[]   parse     = selection.split("\\x2E");
-        int        scindex   = Integer.valueOf(parse[0]);
-        int        number    = Integer.valueOf(parse[1]);
-
-        Scenario[] scene     = study.getScenarii(); 
-        Scenario   bascene   = scene[0];
-        for (int i=1; i<scene.length; i++) {
-          bascene = scene[i];
-          if (bascene.getIndex() == scindex) break;
-        }
-        Step[]              step  = null;        
-        Scenario.Properties sprop = new Scenario.Properties().setManager(getConnectedUser()).setTitle(mytitle).setInsertAfter(bascene);
-
-        bastep = getProjectElementService().getFirstStep(bascene).getNumber();
-        if (this.sharesStep()) {
-          step = getProjectElementService().getSteps(bascene);
-          sprop.setBaseStep(step[number-bastep]);
-        }
-        bascene = getScenarioService().addScenario(study, sprop);
-//        transax.commit();
-
-//      Update of the display
-        if (step != null) for (int i=0; i<number-bastep+1; i++) {
-          List<Publication>  contents = step[i].getAllDocuments();
-          for (Iterator<Publication> j=contents.iterator(); j.hasNext(); ) mystudy.update(j.next());
-        }
-        mystudy.setSelection(bascene.getIndex() + "." + number);
-        getSession().remove("menu.scenario");
-           return SUCCESS;
-         }
-      catch (RuntimeException saverror) {
-        LOG.error("Reason:", saverror);
-        
-        setMenuProperty("study");
-        setTitleProperty("study");
-               setToolProperty("standard");
-               setLeftMenuProperty("study");
-               initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
-               
-        return ERROR;
-      }
-         catch (Exception error) {
-        return INPUT;
-      }
-    }
-
-//  ==============================================================================================================================
-//  Getters and setters
-//  ==============================================================================================================================
-
-    public List<Scenario> getScenarii () {
-//  ------------------------------------
-      return myscene;
-    }
-    public long getSelectedScenarioIndex () {
-//  --------------------------------------
-      return scindex;
-    }
-    public String getSelection () {
-//  -----------------------------
-      return selection;
-    }
-    public String getSharedStep () {
-//  -------------------------------
-      String[] parse = selection.split("\\x2E");
-      return   parse[1];
-    }
-    public String getTitle () {
-//  -------------------------
-      return mytitle;
-    }
-
-    public void setCancel (final boolean cancel) {
-//  --------------------------------------
-      action = ToDo.cancel;
-    }
-    public void setSave (final boolean save) {
-//  ----------------------------------
-      action = ToDo.save;
-    }
-    public void setSelectedScenario (final String index) {
-//  ----------------------------------------------
-      scindex = Integer.valueOf(index);
-    }
-    public void setSelection (final String step) {
-//  --------------------------------------
-      selection = step;
-    }
-    public void setTitle (final String title) {
-//  -----------------------------------
-      mytitle = title;
-    }
-    public Boolean sharesStep () {
-//  ----------------------------
-      return (Integer.valueOf(getSharedStep()) > bastep);
-    }
+       protected enum ToDo {
+               cancel, save
+       };
+
+       // ==============================================================================================================================
+       // Action methods
+       // ==============================================================================================================================
+
+       public String doInitialize() {
+               _mystudy = getOpenStudy();
+               Study study = _mystudy.getStudyObject();
+               Scenario[] scene = study.getScenarii();
+               Scenario base = scene[scene.length - 1]; // Default base scenario
+               ResourceBundle locale = ResourceBundle.getBundle("labels",
+                               getApplicationSettings().getCurrentLocale());
+
+               _myscene = Arrays.asList(scene);
+               _scindex = base.getIndex();
+               _title = locale.getString("label.scenario") + " "
+                               + String.valueOf(scene.length + 1);
+               _bastep = getProjectElementService().getFirstStep(base).getNumber(); // Better use the last current step ?
+               _selection = _scindex + "." + _bastep;
+               _action = null;
+
+               // RKV Menu menu = new NewScenarioMenu(study);
+               Menu menu = ((NewScenarioMenu) getMenu()).init(study); // RKV
+               menu.selects(_selection);
+               getSession().put("menu.scenario", menu);
+
+               initializationFullScreenContext(Constants.STUDY_MENU,
+                               Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+                               Constants.SCENARIO_MENU);
+
+               setActionType("focus");
+
+               return SUCCESS;
+       }
+
+       public String doSelectStep() {
+               _mystudy = getOpenStudy();
+               Study study = _mystudy.getStudyObject();
+               Scenario[] scene = study.getScenarii();
+
+               _myscene = Arrays.asList(scene);
+               _bastep = getProjectElementService().getFirstStep(scene[0]).getNumber(); // All scenarios have the same first step number
+               _action = null;
+
+               getMenu("scenario").selects(_selection);
+
+               initializationFullScreenContext(Constants.STUDY_MENU,
+                               Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+                               Constants.SCENARIO_MENU);
+
+               setActionType("none");
+
+               return SUCCESS;
+       }
+
+       public String doCreate() {
+               if (_action == ToDo.cancel) {
+                       return "cancel";
+               }
+
+               try {
+                       _mystudy = getOpenStudy();
+                       _selection = getMenu("scenario").getSelection();
+                       Study study = _mystudy.getStudyObject();
+                       String[] parse = _selection.split("\\x2E");
+                       int scindex = Integer.valueOf(parse[0]);
+                       int number = Integer.valueOf(parse[1]);
+
+                       Scenario[] scene = study.getScenarii();
+                       Scenario bascene = scene[0];
+                       for (int i = 1; i < scene.length; i++) {
+                               bascene = scene[i];
+                               if (bascene.getIndex() == scindex) {
+                                       break;
+                               }
+                       }
+                       Step[] step = null;
+                       Scenario.Properties sprop = new Scenario.Properties().setManager(
+                                       getConnectedUser()).setTitle(_title)
+                                       .setInsertAfter(bascene);
+
+                       _bastep = getProjectElementService().getFirstStep(bascene)
+                                       .getNumber();
+                       if (this.sharesStep()) {
+                               step = getProjectElementService().getSteps(bascene);
+                               sprop.setBaseStep(step[number - _bastep]);
+                       }
+                       bascene = getScenarioService().addScenario(study, sprop);
+                       // transax.commit();
+
+                       // Update of the display
+                       if (step != null) {
+                               for (int i = 0; i < number - _bastep + 1; i++) {
+                                       List<Publication> contents = step[i].getAllDocuments();
+                                       for (Iterator<Publication> j = contents.iterator(); j
+                                                       .hasNext();) {
+                                               _mystudy.update(j.next());
+                                       }
+                               }
+                       }
+                       _mystudy.setSelection(bascene.getIndex() + "." + number);
+                       getSession().remove("menu.scenario");
+                       return SUCCESS;
+               } catch (RuntimeException saverror) {
+                       LOG.error("Reason:", saverror);
+
+                       initializationFullScreenContext(Constants.STUDY_MENU,
+                                       Constants.STUDY_MENU, Constants.FALSE,
+                                       Constants.STANDARD_MENU, Constants.STUDY_MENU);
+
+                       return ERROR;
+               } catch (Exception error) {
+                       return INPUT;
+               }
+       }
+
+       // ==============================================================================================================================
+       // Getters and setters
+       // ==============================================================================================================================
+
+       public List<Scenario> getScenarii() {
+               return _myscene;
+       }
+
+       public long getSelectedScenarioIndex() {
+               return _scindex;
+       }
+
+       public String getSelection() {
+               return _selection;
+       }
+
+       public String getSharedStep() {
+               String[] parse = _selection.split("\\x2E");
+               return parse[1];
+       }
+
+       public String getTitle() {
+               return _title;
+       }
+
+       public void setCancel(final boolean cancel) {
+               _action = ToDo.cancel;
+       }
+
+       public void setSave(final boolean save) {
+               _action = ToDo.save;
+       }
+
+       public void setSelectedScenario(final String index) {
+               _scindex = Integer.valueOf(index);
+       }
+
+       public void setSelection(final String step) {
+               _selection = step;
+       }
+
+       public void setTitle(final String title) {
+               _title = title;
+       }
+
+       public Boolean sharesStep() {
+               return (Integer.valueOf(getSharedStep()) > _bastep);
+       }
+
        /**
         * Get the projectElementService.
         * 
@@ -258,6 +228,7 @@ public class NewScenarioAction extends Action {
 
        /**
         * Get the menu.
+        * 
         * @return the menu
         */
        public Menu getMenu() {
@@ -266,7 +237,9 @@ public class NewScenarioAction extends Action {
 
        /**
         * Set the menu.
-        * @param menu the menu to set
+        * 
+        * @param menu
+        *            the menu to set
         */
        public void setMenu(final Menu menu) {
                _menu = menu;
@@ -274,6 +247,7 @@ public class NewScenarioAction extends Action {
 
        /**
         * Get the scenarioService.
+        * 
         * @return the scenarioService
         */
        public ScenarioService getScenarioService() {
@@ -282,89 +256,11 @@ public class NewScenarioAction extends Action {
 
        /**
         * Set the scenarioService.
-        * @param scenarioService the scenarioService to set
+        * 
+        * @param scenarioService
+        *            the scenarioService to set
         */
        public void setScenarioService(final ScenarioService scenarioService) {
                _scenarioService = scenarioService;
        }
-       
-       /**
-        * 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