]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/CopyStudyAction.java
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 / CopyStudyAction.java
diff --git a/Workspace/Siman/src/org/splat/simer/CopyStudyAction.java b/Workspace/Siman/src/org/splat/simer/CopyStudyAction.java
new file mode 100644 (file)
index 0000000..1286f51
--- /dev/null
@@ -0,0 +1,201 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   19.03.2013
+ * @author         $Author$
+ * @version        $Revision$
+ * @copyright      OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.simer;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
+import org.splat.service.SearchService;
+import org.splat.service.dto.Proxy;
+import org.splat.service.dto.ScenarioDTO;
+import org.splat.service.dto.StudySearchFilterDTO;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.StepsConfigService;
+
+/**
+ * Create a new study from existing one.
+ * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class CopyStudyAction extends NewStudyAction {
+       /**
+        * Serial version ID.
+        */
+       private static final long serialVersionUID = -3733439553634251282L;
+       /**
+        * List of source studies.
+        */
+       private transient final Map<Long, String> _studies = new LinkedHashMap<Long, String>();
+       /**
+        * List of the selected source study scenarios.
+        */
+       private transient final Map<Long, String> _scenarios = new LinkedHashMap<Long, String>();
+       /**
+        * List of source studies steps.
+        */
+       private transient final Map<Integer, String> _steps = new LinkedHashMap<Integer, String>();
+       /**
+        * The selected source study id.
+        */
+       private long _fromStudyId = 0;
+       /**
+        * Injected search service.
+        */
+       private SearchService _searchService;
+       /**
+        * Injected StepsConfigService service.
+        */
+       private StepsConfigService _stepsConfigService;
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.simer.NewStudyAction#doCreate()
+        */
+       @Override
+       public String doCreate() throws InvalidPropertyException,
+                       MissedPropertyException, MultiplyDefinedException {
+               String res = super.doCreate();
+               if (SUCCESS.equals(res)) {
+                       // Copy content from the selected study
+               }
+               return res;
+       }
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.simer.NewStudyAction#doInitialize()
+        */
+       @Override
+       public String doInitialize() {
+               // Initialize contexts list, study title and menus.
+               super.doInitialize();
+               
+               // Initialize source studies list, scenarios list and steps list
+               
+               // Get visible studies
+               StudySearchFilterDTO filter = new StudySearchFilterDTO();
+               if (getConnectedUser() != null) {
+                       filter.setConnectedUserId(getConnectedUser().getIndex());
+               }
+               List<Proxy> studies = getSearchService().selectStudiesWhere(filter);
+               
+               // Fill the studies list
+               for (Proxy study: studies) {
+                       _studies.put(study.getIndex(), study.getTitle());
+               }
+               
+               // Fill lists of scenarios and steps according to the selected study
+               if (_fromStudyId > 0 && _studies.containsKey(_fromStudyId)) {
+                       // Get scenarios from the selected study
+                       List<ScenarioDTO> scens = getScenarioService().getStudyScenarios(_fromStudyId);
+                       for (ScenarioDTO scen: scens) {
+                               _scenarios.put(scen.getIndex(), scen.getTitle());
+                       }
+                       // Fill steps
+                       for (ProjectSettingsService.Step step: getStepsConfigService().getSteps()) {
+                               _steps.put(step.getNumber(), getText("folder.step." + step.getNumber()));
+                       }
+               }
+
+               return SUCCESS;
+       }
+
+       /**
+        * Get the studies.
+        * 
+        * @return the studies
+        */
+       public Map<Long, String> getStudies() {
+               return _studies;
+       }
+
+       /**
+        * Get the searchService.
+        * 
+        * @return the searchService
+        */
+       public SearchService getSearchService() {
+               return _searchService;
+       }
+
+       /**
+        * Set the searchService.
+        * 
+        * @param searchService
+        *            the searchService to set
+        */
+       public void setSearchService(final SearchService searchService) {
+               _searchService = searchService;
+       }
+
+       /**
+        * Get the scenarios.
+        * 
+        * @return the scenarios
+        */
+       public Map<Long, String> getScenarios() {
+               return _scenarios;
+       }
+
+       /**
+        * Get the steps.
+        * 
+        * @return the steps
+        */
+       public Map<Integer, String> getSteps() {
+               return _steps;
+       }
+
+       /**
+        * Get the fromStudyId.
+        * 
+        * @return the fromStudyId
+        */
+       public long getFromStudyId() {
+               return _fromStudyId;
+       }
+
+       /**
+        * Set the fromStudyId.
+        * 
+        * @param fromStudyId
+        *            the fromStudyId to set
+        */
+       public void setFromStudyId(final long fromStudyId) {
+               _fromStudyId = fromStudyId;
+       }
+
+       /**
+        * Get the stepsConfigService.
+        * 
+        * @return the stepsConfigService
+        */
+       public StepsConfigService getStepsConfigService() {
+               return _stepsConfigService;
+       }
+
+       /**
+        * Set the stepsConfigService.
+        * 
+        * @param stepsConfigService
+        *            the stepsConfigService to set
+        */
+       public void setStepsConfigService(
+                       final StepsConfigService stepsConfigService) {
+               _stepsConfigService = stepsConfigService;
+       }
+}