Salome HOME
Create new scenario from existing one is improved
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditScenarioPropertiesAction.java
index 65a30e50b7ec9a866e3e980585706d6938cfa3da..5b38bedb5caabd8e9ffee203284961eac7fa952b 100644 (file)
 package org.splat.simer;
 
 import java.text.SimpleDateFormat;
+import java.util.Iterator;
+import java.util.List;
 import java.util.ResourceBundle;
 
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
+import org.splat.kernel.InvalidPropertyException;
 import org.splat.service.ProjectElementService;
 import org.splat.service.ScenarioService;
 import org.splat.som.Step;
 import org.splat.som.StepRights;
+import org.splat.wapp.Constants;
 
+/**
+ * Action for scenario properties modification.
+ */
 public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
 
-       private Scenario myscenario;
-       private String lasdate;
-       private String subject;
-       private ScenarioService _scenarioService;
-       private ProjectElementService _projectElementService;
-       
-       /**
-        * 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;
-       
        /**
-        * 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.
+        * Serial version ID.
         */
-       private String _editDisabledProperty = "false";
-       
+       private static final long serialVersionUID = 4964740932426016171L;
+
+       private transient Scenario _myscenario;
+       private transient String _lasdate;
+       private transient String _subject;
+
        /**
-        * Value of the tool bar property. 
-        * It can be: none, standard, study, back.
+        * Title of the selected scenario.
         */
-       private String _toolProperty;
-       
+       private String _selectedScenarioTitle;
+
        /**
-        * Value of the left menu property. 
-        * It can be: open, study, knowledge, scenario.
+        * The Scenario service.
         */
-       private String _leftMenuProperty;
+       private ScenarioService _scenarioService;
 
        /**
-        * Serial version ID.
+        * The PojectElement service.
         */
-       private static final long serialVersionUID = 4964740932426016171L;
+       private ProjectElementService _projectElementService;
 
        // ==============================================================================================================================
        // Action methods
        // ==============================================================================================================================
 
        public String doInitialize() {
-               // -----------------------------
                ResourceBundle label = ResourceBundle.getBundle("labels",
                                getApplicationSettings().getCurrentLocale());
                ResourceBundle custom = ResourceBundle.getBundle("som",
                                getApplicationSettings().getCurrentLocale());
-               SimpleDateFormat datstring = new SimpleDateFormat(
-                               custom.getString("date.format")); // Locale date display format
+               SimpleDateFormat datstring = new SimpleDateFormat(custom
+                               .getString("date.format"), getApplicationSettings()
+                               .getCurrentLocale()); // Locale date display format
                Step step;
 
-               mystudy = getOpenStudy();
-               step = mystudy.getSelectedStep();
-               myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
-               lasdate = datstring.format(myscenario.getLastModificationDate());
-               subject = label.getString("label.study") + " " + mystudy.getTitle();
-               
-               setMenuProperty("study");
-               setTitleProperty("study");
-               setEditDisabledProperty("true");
-               setToolProperty("back");
-               setLeftMenuProperty("open");
-        initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
+               _openStudy = getOpenStudy();
+               step = _openStudy.getSelectedStep();
+               _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
+               _lasdate = datstring.format(_myscenario.getLastModificationDate());
+               _subject = label.getString("label.study") + " " + _openStudy.getTitle();
+               _selectedScenarioTitle = _myscenario.getTitle();
+
+               initializationFullScreenContext(Constants.STUDY_MENU,
+                               Constants.STUDY_MENU, "true", "back", "open");
 
                return SUCCESS;
        }
 
-       public String doCheckin() {
+       /**
+        * Mark the scenario as checked in.
+        * 
+        * @return SUCCESS
+        * @throws InvalidPropertyException
+        *             if scenario is not found in the database
+        */
+       public String doCheckin() throws InvalidPropertyException {
                Step step;
 
-               mystudy = getOpenStudy();
-               selection = mystudy.getSelection();
-               step = mystudy.getSelectedStep();
-               myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
+               _openStudy = getOpenStudy();
+               _selection = _openStudy.getSelection();
+               step = _openStudy.getSelectedStep();
+               _myscenario = (Scenario) step.getOwner(); // The selected step belong to a scenario
+
+               getScenarioService().checkin(_myscenario.getIndex());
+               // TODO: Do it in the business service after moving to DTO instead of id parameter
+               // or reread the scenario.
+               _myscenario.setUser(null);
 
-               getScenarioService().checkin(myscenario);
+               _openStudy.getMenu().refreshGivenStepItem(
+                               getProjectElementService().getFirstStep(_myscenario)); // For updating the scenario icon
 
-               mystudy.getMenu().refreshGivenStepItem(
-                               getProjectElementService().getFirstStep(myscenario)); // For updating the scenario icon
-               
-               setMenuProperty("study");
-               if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
-                       setToolProperty("study");
+               if ("true".equals(getWriteAccess())
+                               && getUserRights().canCreateDocument()) {
+                       setToolProperty(Constants.STUDY_MENU);
                } else {
-                       setToolProperty("standard");
+                       setToolProperty(Constants.STANDARD_MENU);
                }
-               setLeftMenuProperty("study");
-               initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
+               initializationFullScreenContext(Constants.STUDY_MENU,
+                               getToolProperty(), Constants.STUDY_MENU);
 
-               
+               return SUCCESS;
+       }
+
+       /**
+        * Rename the scenario functionality.
+        * 
+        * @return SUCCESS
+        */
+       public String doEditScenarioTitle() {
+               OpenStudy openStudy = getOpenStudy();
+               Study study = openStudy.getStudyObject();
+               List<Scenario> scenarios = study.getScenariiList();
+               Iterator<Scenario> iter = scenarios.iterator();
+               for (; iter.hasNext();) {
+                       Scenario scenario = iter.next();
+                       if (openStudy.getSelectedScenarioId().equals(
+                                       String.valueOf(scenario.getIndex()))) {
+                               scenario.setTitle(getSelectedScenarioTitle());
+                               _scenarioService.renameScenario(scenario);
+                       }
+               }
+
+               _myindex = null;
+               _selection = _openStudy.getSelection(); //actually, value doesn't matter, it just has to be not null
+               doOpen();
                return SUCCESS;
        }
 
@@ -114,37 +135,54 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
        // Getters
        // ==============================================================================================================================
 
+       /**
+        * Get current scenario editor or author if the scenario is not checked out.
+        * 
+        * @return the scenario editor or author
+        */
        public User getAuthor() {
-               // ------------------------
-               if (myscenario.isCheckedout())
-                       return myscenario.getUser();
-               else
-                       return myscenario.getAuthor();
+               User author;
+               if (_myscenario.isCheckedout()) {
+                       author = _myscenario.getUser();
+               } else {
+                       author = _myscenario.getAuthor();
+               }
+               return author;
        }
 
        public String getLastModificationDate() {
-               // ----------------------------------------
-               return lasdate;
+               return _lasdate;
        }
 
        public StepRights getSelectedStep() {
-               // ------------------------------------
-               return mystudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
+               return _openStudy.getSelectedStepRights(); // Forget about the step as only step enabling is tested
        }
 
        public String getSubject() {
-               // ---------------------------
-               return subject;
+               return _subject;
        }
 
-       public String getTitle() {
-               // -------------------------
-               return myscenario.getTitle();
+       public boolean isCheckedout() {
+               return _myscenario.isCheckedout();
        }
 
-       public boolean isCheckedout() {
-               // ------------------------------
-               return myscenario.isCheckedout();
+       /**
+        * Get the selectedScenarioTitle.
+        * 
+        * @return the selectedScenarioTitle
+        */
+       public String getSelectedScenarioTitle() {
+               return _selectedScenarioTitle;
+       }
+
+       /**
+        * Set the selectedScenarioTitle.
+        * 
+        * @param selectedScenarioTitle
+        *            the selectedScenarioTitle to set
+        */
+       public void setSelectedScenarioTitle(final String selectedScenarioTitle) {
+               _selectedScenarioTitle = selectedScenarioTitle;
        }
 
        /**
@@ -162,7 +200,7 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
         * @param scenarioService
         *            the scenarioService to set
         */
-       public void setScenarioService(ScenarioService scenarioService) {
+       public void setScenarioService(final ScenarioService scenarioService) {
                _scenarioService = scenarioService;
        }
 
@@ -182,87 +220,7 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction {
         *            the projectElementService to set
         */
        public void setProjectElementService(
-                       ProjectElementService projectElementService) {
+                       final ProjectElementService projectElementService) {
                _projectElementService = projectElementService;
        }
-       
-       /**
-        * Get the menuProperty.
-        * @return the menuProperty
-        */
-       public String getMenuProperty() {
-               return _menuProperty;
-       }
-
-       /**
-        * Set the menuProperty.
-        * @param menuProperty the menuProperty to set
-        */
-       public void setMenuProperty(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(String titleProperty) {
-               _titleProperty = titleProperty;
-       }
-
-       /**
-        * Get the editDisabledProperty.
-        * @return the editDisabledProperty
-        */
-       public final String getEditDisabledProperty() {
-               return _editDisabledProperty;
-       }
-
-       /**
-        * Set the editDisabledProperty.
-        * @param editDisabledProperty the editDisabledProperty to set
-        */
-       public final void setEditDisabledProperty(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