]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/DisplayKnowledgeAction.java
Salome HOME
6e7d0324b2c1d70930110fd64d90db14844428ae
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / DisplayKnowledgeAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4
5 import org.splat.service.KnowledgeElementService;
6 import org.splat.service.dto.KnowledgeElementDTO;
7 import org.splat.som.Step;
8 import org.splat.wapp.Constants;
9
10 public class DisplayKnowledgeAction extends AbstractDisplayAction {
11
12         /**
13          * Serial version ID.
14          */
15         private static final long serialVersionUID = 8473504456981431762L;
16
17         /**
18          * Current knowledge element details.
19          */
20         protected transient OpenKnowledge _myknelm = null;
21
22         /**
23          * Injected knowledge element service.
24          */
25         private KnowledgeElementService _knowledgeElementService;
26         
27         /**
28          * Value of the menu property. 
29          * It can be: none, create, open, study, knowledge, sysadmin, help.
30          */
31         private String _menuProperty;
32         
33         /**
34          * Value of the title bar property. 
35          * It can be: study, knowledge.
36          */
37         private String _titleProperty;
38         
39         /**
40          * Value of the tool bar property. 
41          * It can be: none, standard, study, back.
42          */
43         private String _toolProperty;
44         
45         /**
46          * Value of the left menu property. 
47          * It can be: open, study, knowledge, scenario.
48          */
49         private String _leftMenuProperty;
50         
51         /**
52          * Property that indicates whether the current open study is editable or not.
53          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
54          * It is necessary for correct building the title bar.
55          */
56         private String _editDisabledProperty = "false";
57
58         // ==============================================================================================================================
59         // Action methods
60         // ==============================================================================================================================
61
62         public String doOpen() {
63                 _myknelm = getOpenKnowledge();
64                 if (_myindex == null) {
65                         if (_selection != null) { // Re-opening (refreshing) the currently open knowledge
66                                 KnowledgeElementDTO kelm = getKnowledgeElementService()
67                                                 .getKnowledgeElement(_myknelm.getIndex());
68                                 _myknelm = open(kelm); // Closes the previously open knowledge
69                                 _myknelm.setSelection(_selection);
70                         }
71                 } else {
72                         try { // Opening a knowledge from the search result
73                                 int index = Integer.valueOf(_myindex);
74                                 if (_myknelm != null && _myknelm.getIndex() == index) { // - The selected knowledge is currently open
75                                         _selection = _myknelm.getSelection(); // Current selection
76                                 } else { // - The selected knowledge is new
77                                         KnowledgeElementDTO kelm = getKnowledgeElementService()
78                                                         .getKnowledgeElement(index);
79                                         _myknelm = open(kelm);
80                                         _selection = _myknelm.getSelection(); // Default selection
81                                 }
82                         } catch (Exception error) {
83                                 LOG.error("Reason:", error);
84                                 return ERROR;
85                         }
86                 }
87                 getSession().put("menu.knowledge", _myknelm.getMenu());
88                 
89                 setMenuProperty(Constants.KNOWLEDGE_MENU);
90                 setTitleProperty(Constants.KNOWLEDGE_MENU);
91                 setToolProperty(Constants.NONE);
92                 setLeftMenuProperty(Constants.KNOWLEDGE_MENU);
93                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
94
95                 return SUCCESS;
96         }
97
98         public String doSelectStep() {
99                 _myknelm = getOpenKnowledge();
100
101                 if (_selection == null) { // Switch back to the current study
102                         _selection = _myknelm.getSelection();
103                 } else { // Selection of a step of current study
104                         _myknelm.setSelection(_selection);
105                 }
106                 
107                 setMenuProperty(Constants.KNOWLEDGE_MENU);
108                 setTitleProperty(Constants.KNOWLEDGE_MENU);
109                 setToolProperty(Constants.NONE);
110                 setLeftMenuProperty(Constants.KNOWLEDGE_MENU);
111                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
112                 
113                 return SUCCESS;
114         }
115
116         public String doSelectDocument() {
117                 Execute todo = Execute.valueOf(_action);
118                 _myknelm = getOpenKnowledge();
119                 if (todo == Execute.develop) {
120                         _myknelm.developDocument(_myindex);
121                 } else if (todo == Execute.reduce) {
122                         _myknelm.reduceHistory(_myindex);
123                 } else if (todo == Execute.reduceall) {
124                         _myknelm.reduceDocument(_myindex);
125                 }
126                 
127                 setMenuProperty(Constants.KNOWLEDGE_MENU);
128                 setTitleProperty(Constants.KNOWLEDGE_MENU);
129                 setToolProperty(Constants.NONE);
130                 setLeftMenuProperty(Constants.KNOWLEDGE_MENU);
131                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
132                 
133                 return SUCCESS;
134         }
135
136         public String doSelectKnowledge() {
137                 Execute todo = Execute.valueOf(_action);
138                 _myknelm = getOpenKnowledge();
139                 if (todo == Execute.develop) {
140                         _myknelm.developKnowledge(_myindex);
141                 } else if (todo == Execute.reduce) {
142                         _myknelm.reduceKnowledge(_myindex);
143                 }
144                 
145                 setMenuProperty(Constants.KNOWLEDGE_MENU);
146                 setTitleProperty(Constants.KNOWLEDGE_MENU);
147                 setToolProperty(Constants.NONE);
148                 setLeftMenuProperty(Constants.KNOWLEDGE_MENU);
149                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
150                 
151                 return SUCCESS;
152         }
153
154         public String doClose() {
155                 closeKnowledge();
156                 
157                 setMenuProperty(Constants.NONE);
158                 initializationScreenContext(_menuProperty);
159                 
160                 return SUCCESS;
161         }
162
163         // ==============================================================================================================================
164         // Getters
165         // ==============================================================================================================================
166
167         public List<DocumentFacade> getDocuments() {
168                 return _myknelm.getDisplayedDocuments();
169         }
170
171         public List<AbstractOpenObject.KnowledgeIterator> getKnowledges() {
172                 return _myknelm.getDisplayedKnowledges();
173         }
174
175         public List<SimulationContextFacade> getSimulationContexts() {
176                 return _myknelm.getDisplayedSimulationContexts();
177         }
178
179         public Step getSelectedStep() {
180                 return _myknelm.getSelectedStep();
181         }
182
183         @Override
184         public String getWriteAccess() {
185                 return "false";
186         }
187
188         /**
189          * Get the knowledgeElementService.
190          * 
191          * @return the knowledgeElementService
192          */
193         public KnowledgeElementService getKnowledgeElementService() {
194                 return _knowledgeElementService;
195         }
196
197         /**
198          * Set the knowledgeElementService.
199          * 
200          * @param knowledgeElementService
201          *            the knowledgeElementService to set
202          */
203         public void setKnowledgeElementService(
204                         final KnowledgeElementService knowledgeElementService) {
205                 _knowledgeElementService = knowledgeElementService;
206         }
207         
208         /**
209          * Get the menuProperty.
210          * @return the menuProperty
211          */
212         public String getMenuProperty() {
213                 return _menuProperty;
214         }
215
216         /**
217          * Set the menuProperty.
218          * @param menuProperty the menuProperty to set
219          */
220         public void setMenuProperty(final String menuProperty) {
221                 this._menuProperty = menuProperty;
222         }
223         
224         /**
225          * Get the _titleProperty.
226          * @return the _titleProperty
227          */
228         public String getTitleProperty() {
229                 return _titleProperty;
230         }
231
232         /**
233          * Set the _titleProperty.
234          * @param _titleProperty the titleProperty to set
235          */
236         public void setTitleProperty(final String titleProperty) {
237                 _titleProperty = titleProperty;
238         }
239
240         /**
241          * Get the _editDisabledProperty.
242          * @return the _editDisabledProperty
243          */
244         public final String getEditDisabledProperty() {
245                 return _editDisabledProperty;
246         }
247
248         /**
249          * Set the editDisabledProperty.
250          * @param editDisabledProperty the editDisabledProperty to set
251          */
252         public final void setEditDisabledProperty(final String editDisabledProperty) {
253                 this._editDisabledProperty = editDisabledProperty;
254         }
255
256         /**
257          * Get the toolProperty.
258          * @return the toolProperty
259          */
260         public String getToolProperty() {
261                 return _toolProperty;
262         }
263
264         /**
265          * Set the toolProperty.
266          * @param toolProperty the toolProperty to set
267          */
268         public void setToolProperty(final String toolProperty) {
269                 _toolProperty = toolProperty;
270         }
271         
272         /**
273          * Get the leftMenuProperty.
274          * @return the leftMenuProperty
275          */
276         public String getLeftMenuProperty() {
277                 return _leftMenuProperty;
278         }
279
280         /**
281          * Set the leftMenuProperty.
282          * @param leftMenuProperty the leftMenuProperty to set
283          */
284         public void setLeftMenuProperty(final String leftMenuProperty) {
285                 _leftMenuProperty = leftMenuProperty;
286         }
287 }