Salome HOME
The draft of the "Copy from existing study" action is added. The YACS step is introdu...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / NewStudyAction.java
index 95fd4cbfd00c9a6f6c52b21a64ac479ff17aeb3d..4a7e0a97d9d5f859d72962fc6256ae70cf157fae 100644 (file)
@@ -68,7 +68,7 @@ public class NewStudyAction extends Action {
                ResourceBundle locale = ResourceBundle.getBundle("labels",
                                getApplicationSettings().getCurrentLocale());
                _title = locale.getString("label.study") + " "
-                               + String.valueOf(number + 1);
+                               + (number + 1);
 
                initializationFullScreenContext(Constants.CREATE_MENU, Constants.NONE,
                                Constants.OPEN);
@@ -89,11 +89,9 @@ public class NewStudyAction extends Action {
         */
        public String doCreate() throws InvalidPropertyException,
                        MissedPropertyException, MultiplyDefinedException {
+               String res = SUCCESS;
                String[] input = _projectContext.split(",");
                int valid = Integer.valueOf(input[0]);
-               String value = ""; // input[1] if exists
-
-               Study.Properties sprop = new Study.Properties();
 
                // Check arguments and creation of the study
                if (valid == -1) {
@@ -102,59 +100,68 @@ public class NewStudyAction extends Action {
                                        .selectType("product");
                        _contelm = getSimulationContextService()
                                        .selectSimulationContextsWhere(cprop.setType(product));
-                       return INPUT; // Title empty, simply wait for input without error message
-               }
-               if (valid == 0) {
-                       value = input[1].trim();
-                       if (value.length() == 0) {
-                               initializationScreenContext(Constants.CREATE_MENU);
-                               return INPUT; // No need to reinitialize the list of existing products
+                       // Title empty, simply wait for input without error message
+                       res = INPUT;
+               } else {
+                       String value; // input[1] if exists
+                       if (valid == 0) {
+                               value = input[1].trim();
+                               if (value.length() == 0) {
+                                       initializationScreenContext(Constants.CREATE_MENU);
+                                       // No need to reinitialize the list of existing products
+                                       res = INPUT;
+                               }
+                       } else {
+                               value = "";
                        }
-               }
-               sprop.setTitle(_title).setManager(getConnectedUser());
-               sprop.checkValidity();
-               sprop.disableCheck();
-               try {
-                       // Addition of a default scenario
-                       ResourceBundle locale = ResourceBundle.getBundle("labels",
-                                       getApplicationSettings().getCurrentLocale());
-                       Scenario.Properties oprop = new Scenario.Properties();
-                       oprop.setTitle(locale.getString("label.scenario") + " 1");
+                       if (SUCCESS.equals(res)) {
+                               Study.Properties sprop = new Study.Properties();
 
-                       // Addition of the entered project context
-                       SimulationContext.Properties cprop = new SimulationContext.Properties();
-                       
-                       SimulationContextType product = getSimulationContextService()
-                                       .selectType("product");
-                       
-                       SimulationContext testContext = getSimulationContextService().selectSimulationContext(product, value);
-                       
-                       if (valid == 0) { // Input of new project context
-                               if (testContext == null) {
-                               cprop.setType(
-                                               getSimulationContextService().selectType("product"))
-                                               .setValue(value);
-                               } else {
-                                       cprop.setIndex(testContext.getIndex());
+                               sprop.setTitle(_title).setManager(getConnectedUser());
+                               sprop.checkValidity();
+                               sprop.disableCheck();
+                               try {
+                                       // Addition of a default scenario
+                                       ResourceBundle locale = ResourceBundle.getBundle("labels",
+                                                       getApplicationSettings().getCurrentLocale());
+                                       Scenario.Properties oprop = new Scenario.Properties();
+                                       oprop.setTitle(locale.getString("label.scenario") + " 1");
+               
+                                       // Addition of the entered project context
+                                       SimulationContext.Properties cprop = new SimulationContext.Properties();
+                                       if (valid == 0) { // Input of new project context
+                                               SimulationContextType product = getSimulationContextService()
+                                                               .selectType("product");
+                                               
+                                               SimulationContext testContext = getSimulationContextService().selectSimulationContext(product, value);
+                                               
+                                               if (testContext == null) {
+                                               cprop.setType(
+                                                               getSimulationContextService().selectType("product"))
+                                                               .setValue(value);
+                                               } else {
+                                                       cprop.setIndex(testContext.getIndex());
+                                               }
+                                       } else { // Selection of existing project context
+                                               cprop.setIndex(valid);
+                                       }
+                                       Study study = getScenarioService().createStudy(sprop, oprop, cprop);
+                                       // Update of the session
+                                       number += 1;
+                                       open(study); // Opens the study,
+               
+                                       initializationFullScreenContext(Constants.STUDY_MENU,
+                                                       Constants.NONE, Constants.OPEN);
+               
+                               } catch (Exception error) {
+                                       LOG.error("Unable to save the study, reason:", error);
+                                       setErrorCode("message.error.newstudy");
+                                       initializationScreenContext(Constants.NONE);
+                                       res = ERROR;
                                }
-                       } else { // Selection of existing project context
-                               cprop.setIndex(valid);
                        }
-                       Study study = getScenarioService().createStudy(sprop, oprop, cprop);
-                       // Update of the session
-                       number += 1;
-                       open(study); // Opens the study,
-
-                       initializationFullScreenContext(Constants.STUDY_MENU,
-                                       Constants.NONE, Constants.OPEN);
-
-                       return SUCCESS;
-               } catch (Exception error) {
-                       LOG.error("Unable to save the study, reason:", error);
-                       setErrorCode("message.error.newstudy");
-                       initializationScreenContext(Constants.NONE);
-                       return ERROR;
                }
+               return res;
        }
        
        /**
@@ -168,12 +175,9 @@ public class NewStudyAction extends Action {
                if( LOG.isDebugEnabled() ) {
                        LOG.debug("--- validate");
                }
-               com.opensymphony.xwork2.ActionContext context = 
-                       com.opensymphony.xwork2.ActionContext.getContext();
-               
                if( LOG.isDebugEnabled() ) {
                        LOG.debug("======> MKA test");
-                       LOG.debug(context.getName());
+                       LOG.debug(com.opensymphony.xwork2.ActionContext.getContext().getName());
                }
        }