Salome HOME
<jsp:param ... > parameters are removed from the title bar
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / Action.java
1 package org.splat.simer;
2
3 import java.util.Map;
4 import java.util.Comparator;
5 import java.util.ResourceBundle;
6
7 import javax.security.auth.login.LoginContext;
8 import javax.servlet.http.HttpServletRequest;
9
10 import com.opensymphony.xwork2.ActionSupport;
11
12 import org.apache.struts2.ServletActionContext;
13 import org.apache.struts2.interceptor.ServletRequestAware;
14 import org.apache.struts2.interceptor.SessionAware;
15 import org.apache.log4j.Logger;
16 import org.splat.dal.bo.kernel.User;
17 import org.splat.som.ApplicationRights;
18 import org.splat.dal.bo.som.KnowledgeElement;
19 import org.splat.dal.bo.som.SimulationContextType;
20 import org.splat.dal.bo.som.Study;
21 import org.splat.dal.bo.som.DocumentType;
22 import org.splat.wapp.Menu;
23
24
25 public class Action extends ActionSupport implements ServletRequestAware, SessionAware {
26
27         private   Map<String, Object>  session;
28         private   String               mercode;
29         private OpenStudy _openStudy;
30         private OpenKnowledge _openKnowledge;
31         
32         /**
33          * MenuBarSettings bean.
34          */
35         private MenuBarSettings _menuBarSettings;
36         
37         /**
38          * TitleBarSettings bean.
39          */
40         private TitleBarSettings _titleBarSettings;
41
42         private HttpServletRequest  request;
43
44         /**
45          * Serial version ID.
46          */
47         private   static final long    serialVersionUID = -895295026709526501L;
48         /**
49          * Action logger.
50          */
51     protected static final Logger  logger           = Logger.getLogger(Action.class);
52
53     public class DocumentTypeComparator implements Comparator<DocumentType> {
54 //  -----------------------------------------------------------------------
55       public int compare(DocumentType t1, DocumentType t2)
56       {
57         ResourceBundle       locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
58         String               name1  = t1.getName();
59         if (t1.isApproved()) name1  = locale.getString("type.document." + name1);
60         String               name2  = t2.getName();
61         if (t2.isApproved()) name2  = locale.getString("type.document." + name2);
62
63         return name1.compareToIgnoreCase(name2);
64       }
65     }
66     public class ContextTypeComparator  implements Comparator<SimulationContextType> {
67 //  --------------------------------------------------------------------------------
68       public int compare(SimulationContextType t1, SimulationContextType t2)
69       {
70         ResourceBundle       locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
71         String               name1  = t1.getName();
72         if (t1.isApproved()) name1  = locale.getString("type.context." + name1);
73         String               name2  = t2.getName();
74         if (t2.isApproved()) name2  = locale.getString("type.context." + name2);
75
76         return name1.compareToIgnoreCase(name2);
77       }
78     }
79
80 //  ==============================================================================================================================
81 //  Session services
82 //  ==============================================================================================================================
83
84     protected void closeKnowledge () {
85 //  --------------------------------
86       OpenObject open = (OpenObject)session.remove("knowledge.open");
87       if (open != null) {
88         if (session.get("study.open") == null) open.clearFacades();      // For eventually reopening the knowledge from a fresh context
89       }
90     }
91     protected void closeStudy () {
92 //  ----------------------------
93       OpenObject open = (OpenObject)session.remove("study.open");
94       if (open != null) {
95         if (session.get("knowledge.open") == null) open.clearFacades();  // For eventually reopening the study from a fresh context
96       }
97     }
98     protected void connect (LoginContext context, User user) {
99 //  --------------------------------------------------------
100       OpenStudy  open = getOpenStudy();
101       if (open != null) {
102           open.changeUser(user);
103       }
104       session.put("user.rights", new ApplicationRights(user) );
105       session.put("login.context", context);                             // For executing the deconnection, when requested
106     }
107     protected void disconnect () {
108 //  ----------------------------
109       OpenStudy  open = getOpenStudy();
110       if (open != null) {
111           open.changeUser(null);
112       }
113       session.put("user.rights", new ApplicationRights(null) );          // Disables user rights
114       session.remove("login.context");
115     }
116     protected User getConnectedUser () {
117 //  ----------------------------------
118       ApplicationRights  rights = (ApplicationRights)session.get("user.rights");
119       return rights.getUser();                                           // May be null
120     }
121     protected Menu getMenu (String name) {
122 //  ------------------------------------
123       return (Menu)session.get("menu." + name);
124     }
125     public void setOpenKnowledge (OpenKnowledge kelm) {
126         _openKnowledge = kelm;
127       }
128     protected OpenKnowledge getOpenKnowledge () {
129 //      _openKnowledge = (OpenKnowledge)session.get("knowledge.open");               // May be null
130         return _openKnowledge;
131     }
132     public void setOpenStudy (OpenStudy aStudy) {
133       _openStudy = aStudy;
134     }
135     public OpenStudy getOpenStudy () {
136 //      _openStudy = (OpenStudy)session.get("study.open");
137           return _openStudy;                       // May be null
138         }
139     protected OpenKnowledge open (KnowledgeElement kelm) {
140 //  ----------------------------------------------------
141       OpenKnowledge open = _openKnowledge.open(kelm);
142
143       closeKnowledge();   // Just in case
144           session.put("knowledge.open", open);
145           return open;
146     }
147     protected OpenStudy open (Study study) {
148 //  --------------------------------------
149           OpenStudy open = _openStudy.open(getConnectedUser(), study);         // The connected user may be null
150
151       closeStudy();       // Just in case
152           session.put("study.open", open);
153           return open;
154     }
155     
156     /**
157      * Initialization the Context for menubar.
158      */
159     public void initializationContext() {
160         getMenuBarSettings().initializeInitialMenuProperties();
161         
162         if (session.get("study.open") == null) {
163                 getMenuBarSettings().setIsStudyNull(true);
164         } else {
165                 getMenuBarSettings().setIsStudyNull(false);
166         }
167         
168         if (session.get("knowledge.open") == null) {
169                 getMenuBarSettings().setIsKnowledgeNull(true);
170         } else {
171                 getMenuBarSettings().setIsKnowledgeNull(false);
172         }
173         
174         ApplicationRights userRights  = (ApplicationRights)session.get("user.rights");
175         
176         if (userRights.canCreateStudy()) {
177                 getMenuBarSettings().setCanUserCreateStudy(true);
178         } else {
179                 getMenuBarSettings().setCanUserCreateStudy(false);
180         }
181         
182         if (userRights.canManageDatabase()) {
183                 getMenuBarSettings().setCanUserManageDatabase(true);
184         } else {
185                 getMenuBarSettings().setCanUserManageDatabase(false);
186         } 
187         
188     }
189     
190     /**
191      * Initialization the Context for Menu Bar and Tool Bar.
192      * 
193      * @param titleProperty - The title of the open study/knowledge.
194      * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
195      */
196     public void initializationContext(final String titleProperty, final String editDisabledProperty) {
197         
198         initializationContext();
199         
200         OpenObject entity = (OpenObject)session.get(titleProperty + ".open");
201         
202         getTitleBarSettings().setProgressState(entity.getProgressState().toString());
203         getTitleBarSettings().setSelectionState(entity.getSelection());
204         getTitleBarSettings().setEntryType(entity.getType());
205         getTitleBarSettings().setEntryTitle(entity.getTitle());
206         getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
207     }
208     
209     /**
210          * Initialization of the screen context for menu bar.
211          * 
212          * @param menuProperty - the property of the menu bar.
213          */
214         public void initializationScreenContext(final String menuProperty) {
215                 
216                 initializationContext();
217                 getMenuBarSettings().intializeMenuBar(menuProperty);
218         }
219         
220         /**
221          * Initialization of the screen context for menu bar and tool bar.
222          * 
223          * @param menuProperty - the property of the menu bar.
224          * @param titleProperty - The title of the open study/knowledge.
225      * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
226          */
227         public void initializationScreenContext(final String menuProperty, 
228                         final String titleProperty, final String editDisabledProperty) {
229                 
230                 initializationContext(titleProperty, editDisabledProperty);
231                 getMenuBarSettings().intializeMenuBar(menuProperty);
232         }
233 //  ==============================================================================================================================
234 //  Getters and setters
235 //  ==============================================================================================================================
236     
237         public void setServletRequest (HttpServletRequest request) {
238                 this.request = request;
239         }
240         
241         public HttpServletRequest getServletRequest() {
242                 return request;
243         }
244
245     public String getErrorCode () {
246 //  -----------------------------
247       return mercode;
248     }
249     public Map<String, Object> getSession () {
250 //  ----------------------------------------
251       return session;
252     }
253
254     public void setErrorCode (String code) {
255 //  --------------------------------------
256       this.mercode = code;
257     }
258         public void setSession (Map<String, Object> session) {
259 //  ----------------------------------------------------                
260           this.session = session;
261         }
262         
263         /**
264          * Get the menuBarSettings.
265          * @return the menuBarSettings
266          */
267         public MenuBarSettings getMenuBarSettings() {
268                 return _menuBarSettings;
269         }
270
271         /**
272          * Set the menuBarSettings.
273          * @param menuBarSettings the menuBarSettings to set
274          */
275         public void setMenuBarSettings(final MenuBarSettings menuBarSettings) {
276                 _menuBarSettings = menuBarSettings;
277         }
278         
279         /**
280          * Get the _titleBarSettings.
281          * @return the _titleBarSettings
282          */
283         public TitleBarSettings getTitleBarSettings() {
284                 return _titleBarSettings;
285         }
286         /**
287          * Set the titleBarSettings.
288          * @param titleBarSettings the titleBarSettings to set
289          */
290         public void setTitleBarSettings(TitleBarSettings titleBarSettings) {
291                 _titleBarSettings = titleBarSettings;
292         }
293 }