Salome HOME
New study creation is fixed. Search page is also accessible now.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SimulationContextFacade.java
1 package org.splat.simer;
2
3 import java.util.Iterator;
4 import java.util.List;
5 import java.util.ResourceBundle;
6
7 import org.splat.dal.bo.som.ProgressState;
8 import org.splat.service.technical.ProjectSettingsService;
9 import org.splat.dal.bo.som.SimulationContext;
10 import org.splat.dal.bo.som.SimulationContextType;
11 import org.splat.wapp.PopupMenu;
12
13
14 public class SimulationContextFacade {
15
16     private SimulationContext  my;
17     private String             name;
18     private int                step;
19     private ProgressState      state;
20     private PopupMenu          popup;
21
22 //  ==============================================================================================================================
23 //  Constructor
24 //  ==============================================================================================================================
25
26     public SimulationContextFacade (SimulationContext represented, List<ProjectSettingsService.Step> allSteps) {
27 //  --------------------------------------------------------------
28       my    = represented;
29       popup = ApplicationSettings.getPopupMenu("scontext");
30
31       SimulationContextType type = my.getType();
32       for (Iterator<ProjectSettingsService.Step> i=allSteps.iterator(); i.hasNext(); ) {
33         ProjectSettingsService.Step   next = i.next();
34         if (!type.isAttachedTo(next)) continue;
35         step = next.getNumber();
36         break;
37       }
38       state = my.getProgressState();                     // inCHECK or APPROVED
39       name  = type.getName();
40       if (type.isApproved()) {
41         name = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale()).getString("type.context." + name);
42       } else {
43         state  = ProgressState.inDRAFT;
44       }
45     }
46
47 //  ==============================================================================================================================
48 //  Getters
49 //  ==============================================================================================================================
50
51     public String getEditIcon () {
52 //  ----------------------------
53       return "icon.ed" + state + ".png";
54     }
55     public String getIndex () {
56 //  -------------------------
57       return String.valueOf(my.getIndex());
58     }
59     public PopupMenu getPopup () {
60 //  ----------------------------
61       popup.setContext("scontext", this);     // Cannot be done at construction because pop-ups are shared
62       return popup;
63     }
64     public String getStateIcon () {
65 //  -----------------------------
66       return "icon." + state + ".png";
67     }
68     public String getStepNumber () {
69 //  ------------------------------
70       return String.valueOf(step);
71     }
72     public String getTypeName () {
73 //  ----------------------------
74       return  name;
75     }
76     public String getValue () {
77 //  -------------------------
78       return  my.getValue();
79     }
80
81     public boolean isApproved () {
82 //  ----------------------------
83       return (state == ProgressState.APPROVED);
84     }
85     public boolean isEditable () {
86 //  ----------------------------
87       return !my.isShared();
88     }
89     public boolean isFacadeOf (SimulationContext represented) {
90 //  ---------------------------------------------------------
91       return  my.equals(represented);
92     }
93 }