Salome HOME
6342b7be3979032dfc3f08d1e5bd8c3f69667277
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / MenuAction.java
1 package org.splat.simer;
2
3 import org.splat.wapp.SimpleMenu;
4
5 /**
6  * Menu selection action.
7  */
8 public class MenuAction extends Action {
9         /**
10          * Serial version ID.
11          */
12         private static final long serialVersionUID = 5904292225286579036L;
13
14         /**
15          * Current menu.
16          */
17         private String _menu;
18         /**
19          * Selected item.
20          */
21         private String _item;
22
23         // ==============================================================================================================================
24         // Action methods
25         // ==============================================================================================================================
26
27         /**
28          * Activate the menu and select the menu item.
29          * 
30          * @return the selected menu item
31          */
32         public String doSelectItem() {
33                 SimpleMenu menu = getApplicationSettings().getMenu(_menu);
34
35                 if (_item == null) { // Switch back to the menu, keeping the last selection
36                         getSession().put("menu.open", menu); // Activates the menu
37                         if (menu != null) {
38                                 _item = menu.getSelection();
39                                 if (_item == null) { // Select default menu item if nothing has been selected
40                                         _item = menu.getDefaultSelection();
41                                         menu.selects(_item);
42                                 }
43                         }
44                 } else { // Selection of another menu item
45                         menu.selects(_item);
46                 }
47                 return _item;
48         }
49
50         // ==============================================================================================================================
51         // Getters and setters
52         // ==============================================================================================================================
53
54         /**
55          * Get selected menu item.
56          * @return the selected menu item
57          */
58         public String getItem() {
59                 return _item;
60         }
61
62         /**
63          * Get current menu name. 
64          * @return the menu name
65          */
66         public String getMenu() {
67                 return _menu;
68         }
69
70         /**
71          * Set current menu name.
72          * @param name the menu name
73          */
74         public void setMenu(final String name) {
75                 this._menu = name;
76         }
77
78         /**
79          * Set the selected menu item.
80          * @param item the selected item
81          */
82         public void setItem(final String item) {
83                 this._item = item;
84         }
85 }