]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/RapActionBarAdvisor.java
Improve user menu
[lgpl/argeo-commons.git] / security / plugins / org.argeo.security.ui.rap / src / main / java / org / argeo / security / ui / rap / RapActionBarAdvisor.java
1 package org.argeo.security.ui.rap;
2
3 import org.argeo.security.ui.commands.OpenHomePerspective;
4 import org.argeo.security.ui.rap.commands.UserMenu;
5 import org.eclipse.core.commands.Category;
6 import org.eclipse.core.commands.Command;
7 import org.eclipse.jface.action.ICoolBarManager;
8 import org.eclipse.jface.action.IMenuManager;
9 import org.eclipse.jface.action.IToolBarManager;
10 import org.eclipse.jface.action.ToolBarManager;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.ui.IWorkbenchWindow;
13 import org.eclipse.ui.application.ActionBarAdvisor;
14 import org.eclipse.ui.application.IActionBarConfigurer;
15 import org.eclipse.ui.commands.ICommandService;
16
17 /** Eclipse rap specific action bar advisor */
18 public class RapActionBarAdvisor extends ActionBarAdvisor {
19 private final static String ID_BASE = "org.argeo.security.ui.rap";
20 // private final static Log log = LogFactory
21 // .getLog(SecureActionBarAdvisor.class);
22
23 /** Null means anonymous */
24 private String username = null;
25
26 // private IAction logoutAction;
27 // private IWorkbenchAction openPerspectiveDialogAction;
28 // private IWorkbenchAction showViewMenuAction;
29 // private IWorkbenchAction preferences;
30 // private IWorkbenchAction saveAction;
31 // private IWorkbenchAction saveAllAction;
32 // private IWorkbenchAction closeAllAction;
33
34 public RapActionBarAdvisor(IActionBarConfigurer configurer, String username) {
35 super(configurer);
36 this.username = username;
37 }
38
39 protected void makeActions(IWorkbenchWindow window) {
40 // preferences = ActionFactory.PREFERENCES.create(window);
41 // register(preferences);
42 // openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
43 // .create(window);
44 // register(openPerspectiveDialogAction);
45 // showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
46 // register(showViewMenuAction);
47 //
48 // // logout
49 // logoutAction = ActionFactory.QUIT.create(window);
50 // // logoutAction = createLogoutAction();
51 // register(logoutAction);
52 //
53 // // Save semantics
54 // saveAction = ActionFactory.SAVE.create(window);
55 // register(saveAction);
56 // saveAllAction = ActionFactory.SAVE_ALL.create(window);
57 // register(saveAllAction);
58 // closeAllAction = ActionFactory.CLOSE_ALL.create(window);
59 // register(closeAllAction);
60
61 }
62
63 protected void fillMenuBar(IMenuManager menuBar) {
64 // MenuManager fileMenu = new MenuManager("&File",
65 // IWorkbenchActionConstants.M_FILE);
66 // MenuManager editMenu = new MenuManager("&Edit",
67 // IWorkbenchActionConstants.M_EDIT);
68 // MenuManager windowMenu = new MenuManager("&Window",
69 // IWorkbenchActionConstants.M_WINDOW);
70 //
71 // menuBar.add(fileMenu);
72 // menuBar.add(editMenu);
73 // menuBar.add(windowMenu);
74 // // Add a group marker indicating where action set menus will appear.
75 // menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
76 //
77 // // File
78 // fileMenu.add(saveAction);
79 // fileMenu.add(saveAllAction);
80 // fileMenu.add(closeAllAction);
81 // fileMenu.add(new
82 // GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
83 // fileMenu.add(new Separator());
84 // fileMenu.add(logoutAction);
85 //
86 // // Edit
87 // editMenu.add(preferences);
88 //
89 // // Window
90 // windowMenu.add(openPerspectiveDialogAction);
91 // windowMenu.add(showViewMenuAction);
92 }
93
94 @Override
95 protected void fillCoolBar(ICoolBarManager coolBar) {
96 if (username != null) {
97 ICommandService cmdService = (ICommandService) getActionBarConfigurer()
98 .getWindowConfigurer().getWorkbenchConfigurer()
99 .getWorkbench().getService(ICommandService.class);
100 Category userMenus = cmdService.getCategory(ID_BASE + ".userMenus");
101 if (!userMenus.isDefined())
102 userMenus.define("User Menus", "User related menus");
103
104 Command userMenu = cmdService.getCommand(ID_BASE
105 + ".userMenuCommand");
106 if (userMenu.isDefined())
107 userMenu.undefine();
108 userMenu.define(username, "User menu actions", userMenus);
109 userMenu.setHandler(new OpenHomePerspective());
110
111 // userToolbar.add(new UserMenuAction());
112 // coolBar.add(userToolbar);
113 } else {// anonymous
114 IToolBarManager userToolbar = new ToolBarManager(SWT.FLAT
115 | SWT.RIGHT);
116 // userToolbar.add(logoutAction);
117 coolBar.add(userToolbar);
118 }
119 // IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT |
120 // SWT.RIGHT);
121 // saveToolbar.add(saveAction);
122 // saveToolbar.add(saveAllAction);
123 // coolBar.add(saveToolbar);
124 }
125
126 // class UserMenuAction extends Action implements IWorkbenchAction {
127 //
128 // public UserMenuAction() {
129 // super(username, IAction.AS_DROP_DOWN_MENU);
130 // // setMenuCreator(new UserMenu());
131 // }
132 //
133 // @Override
134 // public String getId() {
135 // return "org.argeo.security.ui.rap.userMenu";
136 // }
137 //
138 // @Override
139 // public void dispose() {
140 // }
141 //
142 // }
143
144 // class UserMenu implements IMenuCreator {
145 // private Menu menu;
146 //
147 // public Menu getMenu(Control parent) {
148 // Menu menu = new Menu(parent);
149 // addActionToMenu(menu, logoutAction);
150 // return menu;
151 // }
152 //
153 // private void addActionToMenu(Menu menu, IAction action) {
154 // ActionContributionItem item = new ActionContributionItem(action);
155 // item.fill(menu, -1);
156 // }
157 //
158 // public void dispose() {
159 // if (menu != null) {
160 // menu.dispose();
161 // }
162 // }
163 //
164 // public Menu getMenu(Menu parent) {
165 // // Not use
166 // return null;
167 // }
168 //
169 // }
170
171 // protected IAction createLogoutAction() {
172 // Subject subject = Subject.getSubject(AccessController.getContext());
173 // final String username = subject.getPrincipals().iterator().next()
174 // .getName();
175 //
176 // IAction logoutAction = new Action() {
177 // public String getId() {
178 // return SecureRapActivator.ID + ".logoutAction";
179 // }
180 //
181 // public String getText() {
182 // return "Logout " + username;
183 // }
184 //
185 // public void run() {
186 // // try {
187 // // Subject subject = SecureRapActivator.getLoginContext()
188 // // .getSubject();
189 // // String subjectStr = subject.toString();
190 // // subject.getPrincipals().clear();
191 // // SecureRapActivator.getLoginContext().logout();
192 // // log.info(subjectStr + " logged out");
193 // // } catch (LoginException e) {
194 // // log.error("Error when logging out", e);
195 // // }
196 // // SecureEntryPoint.logout(username);
197 // // PlatformUI.getWorkbench().close();
198 // // try {
199 // // RWT.getRequest().getSession().setMaxInactiveInterval(1);
200 // // } catch (Exception e) {
201 // // if (log.isTraceEnabled())
202 // // log.trace("Error when invalidating session", e);
203 // // }
204 // }
205 //
206 // };
207 // return logoutAction;
208 // }
209
210 }