Salome HOME
Modifications to respect PMD rules.
[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.dal.bo.som.SimulationContext;
9 import org.splat.dal.bo.som.SimulationContextType;
10 import org.splat.service.technical.ProjectSettingsService;
11 import org.splat.wapp.PopupMenu;
12
13 public class SimulationContextFacade {
14
15         private final SimulationContext _my;
16         private String _name;
17         private int _step;
18         private ProgressState _state;
19         private final PopupMenu _popup;
20
21         // ==============================================================================================================================
22         // Constructor
23         // ==============================================================================================================================
24
25         public SimulationContextFacade(final SimulationContext represented,
26                         final List<ProjectSettingsService.Step> allSteps) {
27                 _my = represented;
28                 _popup = ApplicationSettings.getPopupMenu("scontext");
29
30                 SimulationContextType type = _my.getType();
31                 for (Iterator<ProjectSettingsService.Step> i = allSteps.iterator(); i
32                                 .hasNext();) {
33                         ProjectSettingsService.Step next = i.next();
34                         if (!type.isAttachedTo(next)) {
35                                 continue;
36                         }
37                         _step = next.getNumber();
38                         break;
39                 }
40                 _state = _my.getProgressState(); // inCHECK or APPROVED
41                 _name = type.getName();
42                 if (type.isApproved()) {
43                         _name = ResourceBundle.getBundle("som",
44                                         ApplicationSettings.getCurrentLocale()).getString(
45                                         "type.context." + _name);
46                 } else {
47                         _state = ProgressState.inDRAFT;
48                 }
49         }
50
51         // ==============================================================================================================================
52         // Getters
53         // ==============================================================================================================================
54
55         public String getEditIcon() {
56
57                 return "icon.ed" + _state + ".png";
58         }
59
60         public String getIndex() {
61                 return String.valueOf(_my.getIndex());
62         }
63
64         public PopupMenu getPopup() {
65
66                 _popup.setContext("scontext", this); // Cannot be done at construction because pop-ups are shared
67                 return _popup;
68         }
69
70         public String getStateIcon() {
71                 return "icon." + _state + ".png";
72         }
73
74         public String getStepNumber() {
75                 return String.valueOf(_step);
76         }
77
78         public String getTypeName() {
79                 return _name;
80         }
81
82         public String getValue() {
83                 return _my.getValue();
84         }
85
86         public boolean isApproved() {
87                 return (_state == ProgressState.APPROVED);
88         }
89
90         public boolean isEditable() {
91                 return !_my.isShared();
92         }
93
94         public boolean isFacadeOf(final SimulationContext represented) {
95                 return _my.equals(represented);
96         }
97 }