1 package org.splat.simer;
3 import java.util.Arrays;
6 import org.splat.dal.bo.som.ProjectElement;
7 import org.splat.dal.bo.som.SimulationContext;
8 import org.splat.dal.bo.som.SimulationContextType;
9 import org.splat.service.SimulationContextService;
10 import org.splat.service.SimulationContextTypeService;
11 import org.splat.service.StepService;
12 import org.splat.service.StudyService;
13 import org.splat.som.Step;
14 import org.splat.dal.bo.som.Study;
16 public class EditSimulationContextAction extends DisplayStudyStepAction {
18 private List<SimulationContextType> contype = null;
19 private List<SimulationContext> contelm = null;
20 private String selectype = null; // Context type, if selected
21 private String newtype = null; // Context type, if newed
22 private SimulationContextType type = null; // Corresponding context type object
23 private String value = null; // Context value
25 * Injected study service.
27 private StudyService _studyService;
29 * Injected step service.
31 private StepService _stepService;
33 * Injected simulation context service.
35 private SimulationContextService _simulationContextService;
37 * Injected simulation context type service.
39 private SimulationContextTypeService _simulationContextTypeService;
42 * Value of the menu property.
43 * It can be: none, create, open, study, knowledge, sysadmin, help.
45 private String _menuProperty;
48 * Value of the title bar property.
49 * It can be: study, knowledge.
51 private String _titleProperty;
54 * Property that indicates whether the current open study is editable or not.
55 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
56 * It is necessary for correct building the title bar.
58 private String _editDisabledProperty = "false";
60 private static final long serialVersionUID = -641719644024601042L;
62 // ==============================================================================================================================
64 // ==============================================================================================================================
66 public String doInitialize() {
68 mystudy = getOpenStudy();
69 contype = getInvolvedContexts();
71 setMenuProperty("study");
72 setTitleProperty("study");
73 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
75 if (contype.isEmpty())
81 public String doSelectContext() {
82 mystudy = getOpenStudy();
84 setMenuProperty("study");
85 setTitleProperty("study");
86 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
88 int typid = Integer.valueOf(selectype);
92 SimulationContext.Properties cprop = new SimulationContext.Properties();
93 type = getSimulationContextService().selectType(typid);
94 newtype = type.getName();
95 contype = getInvolvedContexts();
96 contelm = getSimulationContextService()
97 .selectSimulationContextsWhere(cprop.setType(type));
102 public String doCreateContext() {
103 // --------------------------------
105 mystudy = getOpenStudy();
107 setMenuProperty("study");
108 setTitleProperty("study");
109 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
111 if (newtype.length() == 0 || value.length() == 0)
114 Step step = mystudy.getSelectedStep();
115 ProjectElement owner = step.getOwner();
117 SimulationContext.Properties cprop = new SimulationContext.Properties();
118 SimulationContext contex = null;
119 type = getSimulationContextTypeService().createType(newtype,
121 cprop.setType(type).setValue(value);
122 if (owner instanceof Study)
123 contex = getStudyService().addProjectContext(((Study) owner),
124 cprop); // Re-indexes knowledges and the study
126 contex = getStepService().addSimulationContext(step, cprop); // Re-indexes knowledges only
130 } catch (RuntimeException saverror) {
131 logger.error("Reason:", saverror);
133 } catch (Exception error) {
138 public String doDeleteContext() {
140 setMenuProperty("study");
141 setTitleProperty("study");
142 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
145 mystudy = getOpenStudy();
147 Step step = mystudy.getSelectedStep();
148 ProjectElement owner = step.getOwner();
149 SimulationContext context = step.getSimulationContext(Integer
151 if (owner instanceof Study)
153 .removeProjectContext(((Study) owner), context); // Re-indexes knowledges and the study
155 getStepService().removeSimulationContext(step, context); // Re-indexes knowledges only
157 mystudy.remove(context);
159 } catch (RuntimeException saverror) {
160 logger.error("Reason:", saverror);
165 public String doSetContext() {
166 // -----------------------------
167 String[] input = value.split(",");
168 // Session connex = Database.getCurSession();
169 // Transaction transax = connex.beginTransaction();
171 setMenuProperty("study");
172 setTitleProperty("study");
173 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
176 mystudy = getOpenStudy();
178 Step step = mystudy.getSelectedStep();
179 ProjectElement owner = step.getOwner();
180 SimulationContext contex = null;
182 if (input.length == 1
183 || (input.length == 2 && input[1].equals(" "))) {
184 // Setting an existing simulation context identified by value (input = rid," ")
185 int valid = Integer.valueOf(input[0]);
186 contex = getSimulationContextService().selectSimulationContext(
188 if (owner instanceof Study)
190 .addProjectContext(((Study) owner), contex);
192 getStepService().addSimulationContext(step, contex);
194 // Setting a new simulation context value (input = 0,"new context value")
195 int typid = Integer.valueOf(selectype);
196 SimulationContext.Properties cprop = new SimulationContext.Properties();
197 cprop.setType(getSimulationContextService().selectType(typid))
198 .setValue(input[1].trim());
199 if (owner instanceof Study)
200 contex = getStudyService().addProjectContext(
201 ((Study) owner), cprop); // Re-indexes knowledges and the study
203 contex = getStepService().addSimulationContext(step, cprop); // Re-indexes knowledges only
206 contype = getInvolvedContexts();
210 } catch (RuntimeException saverror) {
211 logger.error("Reason:", saverror);
213 } catch (Exception error) {
219 // ==============================================================================================================================
220 // Getters and setters
221 // ==============================================================================================================================
223 public SimulationContextType getContextType() {
224 // ----------------------------------------------
228 public String getContextName() {
229 // -------------------------------
233 // public List<SimulationContextFacade> getSimulationContexts () {
234 // -------------------------------------------------------
235 // return mystudy.getSelectedStep().getAllSimulationContexts();
237 public List<SimulationContextType> getSimulationContextTypes() {
238 // ---------------------------------------------------------------
242 public List<SimulationContext> getSimulationContextValues() {
243 // ------------------------------------------------------------
247 public void setContextType(String type) {
248 // ----------------------------------------
249 this.selectype = type;
252 public void setContextValue(String value) {
253 // -----------------------------------------
257 public void setNewType(String name) {
258 // ------------------------------------
262 // ==============================================================================================================================
264 // ==============================================================================================================================
266 private List<SimulationContextType> getInvolvedContexts() {
267 // ----------------------------------------------------------
268 SimulationContextType.Properties sprop = new SimulationContextType.Properties()
269 .setStep(mystudy.getSelectedStep().getStep());
270 List<SimulationContextType> contype = getSimulationContextService()
271 .selectTypesWhere(sprop);
273 if (!contype.isEmpty()) {
274 // Ordering by alphabetical order of localized context types
275 SimulationContextType[] types = contype
276 .toArray(new SimulationContextType[contype.size()]);
277 ContextTypeComparator compare = new ContextTypeComparator();
278 boolean state = types[0].isApproved();
281 while (to < types.length - 1) {
283 if (types[to].isApproved() == state)
287 Arrays.sort(types, from, to, compare);
292 Arrays.sort(types, from, to + 1, compare);
293 contype = Arrays.asList(types);
299 * Get the studyService.
301 * @return the studyService
303 public StudyService getStudyService() {
304 return _studyService;
308 * Set the studyService.
310 * @param studyService
311 * the studyService to set
313 public void setStudyService(StudyService studyService) {
314 _studyService = studyService;
318 * Get the simulationContextService.
320 * @return the simulationContextService
322 public SimulationContextService getSimulationContextService() {
323 return _simulationContextService;
327 * Set the simulationContextService.
329 * @param simulationContextService
330 * the simulationContextService to set
332 public void setSimulationContextService(
333 SimulationContextService simulationContextService) {
334 _simulationContextService = simulationContextService;
338 * Get the simulationContextTypeService.
339 * @return the simulationContextTypeService
341 public SimulationContextTypeService getSimulationContextTypeService() {
342 return _simulationContextTypeService;
346 * Set the simulationContextTypeService.
347 * @param simulationContextTypeService the simulationContextTypeService to set
349 public void setSimulationContextTypeService(
350 SimulationContextTypeService simulationContextTypeService) {
351 _simulationContextTypeService = simulationContextTypeService;
355 * Get the stepService.
357 * @return the stepService
359 public StepService getStepService() {
364 * Set the stepService.
367 * the stepService to set
369 public void setStepService(StepService stepService) {
370 _stepService = stepService;
374 * Get the menuProperty.
375 * @return the menuProperty
377 public String getMenuProperty() {
378 return _menuProperty;
382 * Set the menuProperty.
383 * @param menuProperty the menuProperty to set
385 public void setMenuProperty(String menuProperty) {
386 this._menuProperty = menuProperty;
390 * Get the _titleProperty.
391 * @return the _titleProperty
393 public String getTitleProperty() {
394 return _titleProperty;
398 * Set the _titleProperty.
399 * @param _titleProperty the titleProperty to set
401 public void setTitleProperty(String titleProperty) {
402 _titleProperty = titleProperty;
406 * Get the editDisabledProperty.
407 * @return the editDisabledProperty
409 public final String getEditDisabledProperty() {
410 return _editDisabledProperty;
414 * Set the editDisabledProperty.
415 * @param editDisabledProperty the editDisabledProperty to set
417 public final void setEditDisabledProperty(String editDisabledProperty) {
418 _editDisabledProperty = editDisabledProperty;