1 package org
.argeo
.security
.ui
.rap
;
3 import org
.argeo
.security
.ui
.rap
.commands
.UserMenu
;
4 import org
.eclipse
.core
.commands
.Category
;
5 import org
.eclipse
.core
.commands
.Command
;
6 import org
.eclipse
.jface
.action
.ICoolBarManager
;
7 import org
.eclipse
.jface
.action
.IMenuManager
;
8 import org
.eclipse
.jface
.action
.IToolBarManager
;
9 import org
.eclipse
.jface
.action
.ToolBarManager
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.ui
.IWorkbenchWindow
;
12 import org
.eclipse
.ui
.application
.ActionBarAdvisor
;
13 import org
.eclipse
.ui
.application
.IActionBarConfigurer
;
14 import org
.eclipse
.ui
.commands
.ICommandService
;
16 /** Eclipse rap specific action bar advisor */
17 public class RapActionBarAdvisor
extends ActionBarAdvisor
{
18 private final static String ID_BASE
= "org.argeo.security.ui.rap";
19 // private final static Log log = LogFactory
20 // .getLog(SecureActionBarAdvisor.class);
22 /** Null means anonymous */
23 private String username
= null;
25 // private IAction logoutAction;
26 // private IWorkbenchAction openPerspectiveDialogAction;
27 // private IWorkbenchAction showViewMenuAction;
28 // private IWorkbenchAction preferences;
29 // private IWorkbenchAction saveAction;
30 // private IWorkbenchAction saveAllAction;
31 // private IWorkbenchAction closeAllAction;
33 public RapActionBarAdvisor(IActionBarConfigurer configurer
, String username
) {
35 this.username
= username
;
38 protected void makeActions(IWorkbenchWindow window
) {
39 // preferences = ActionFactory.PREFERENCES.create(window);
40 // register(preferences);
41 // openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
43 // register(openPerspectiveDialogAction);
44 // showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
45 // register(showViewMenuAction);
48 // logoutAction = ActionFactory.QUIT.create(window);
49 // // logoutAction = createLogoutAction();
50 // register(logoutAction);
53 // saveAction = ActionFactory.SAVE.create(window);
54 // register(saveAction);
55 // saveAllAction = ActionFactory.SAVE_ALL.create(window);
56 // register(saveAllAction);
57 // closeAllAction = ActionFactory.CLOSE_ALL.create(window);
58 // register(closeAllAction);
62 protected void fillMenuBar(IMenuManager menuBar
) {
63 // MenuManager fileMenu = new MenuManager("&File",
64 // IWorkbenchActionConstants.M_FILE);
65 // MenuManager editMenu = new MenuManager("&Edit",
66 // IWorkbenchActionConstants.M_EDIT);
67 // MenuManager windowMenu = new MenuManager("&Window",
68 // IWorkbenchActionConstants.M_WINDOW);
70 // menuBar.add(fileMenu);
71 // menuBar.add(editMenu);
72 // menuBar.add(windowMenu);
73 // // Add a group marker indicating where action set menus will appear.
74 // menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
77 // fileMenu.add(saveAction);
78 // fileMenu.add(saveAllAction);
79 // fileMenu.add(closeAllAction);
80 // fileMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
81 // fileMenu.add(new Separator());
82 // fileMenu.add(logoutAction);
85 // editMenu.add(preferences);
88 // windowMenu.add(openPerspectiveDialogAction);
89 // windowMenu.add(showViewMenuAction);
93 protected void fillCoolBar(ICoolBarManager coolBar
) {
94 if (username
!= null) {
95 ICommandService cmdService
= (ICommandService
) getActionBarConfigurer()
96 .getWindowConfigurer().getWorkbenchConfigurer()
97 .getWorkbench().getService(ICommandService
.class);
98 Category userMenus
= cmdService
.getCategory(ID_BASE
+ ".userMenus");
99 if (!userMenus
.isDefined())
100 userMenus
.define("User Menus", "User related menus");
102 Command userMenu
= cmdService
.getCommand(ID_BASE
103 + ".userMenuCommand");
104 if (userMenu
.isDefined())
106 userMenu
.define(username
, "User menu actions", userMenus
);
107 userMenu
.setHandler(new UserMenu());
109 // userToolbar.add(new UserMenuAction());
110 // coolBar.add(userToolbar);
112 IToolBarManager userToolbar
= new ToolBarManager(SWT
.FLAT
114 //userToolbar.add(logoutAction);
115 coolBar
.add(userToolbar
);
117 // IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT |
119 // saveToolbar.add(saveAction);
120 // saveToolbar.add(saveAllAction);
121 // coolBar.add(saveToolbar);
124 // class UserMenuAction extends Action implements IWorkbenchAction {
126 // public UserMenuAction() {
127 // super(username, IAction.AS_DROP_DOWN_MENU);
128 // // setMenuCreator(new UserMenu());
132 // public String getId() {
133 // return "org.argeo.security.ui.rap.userMenu";
137 // public void dispose() {
142 // class UserMenu implements IMenuCreator {
143 // private Menu menu;
145 // public Menu getMenu(Control parent) {
146 // Menu menu = new Menu(parent);
147 // addActionToMenu(menu, logoutAction);
151 // private void addActionToMenu(Menu menu, IAction action) {
152 // ActionContributionItem item = new ActionContributionItem(action);
153 // item.fill(menu, -1);
156 // public void dispose() {
157 // if (menu != null) {
162 // public Menu getMenu(Menu parent) {
169 // protected IAction createLogoutAction() {
170 // Subject subject = Subject.getSubject(AccessController.getContext());
171 // final String username = subject.getPrincipals().iterator().next()
174 // IAction logoutAction = new Action() {
175 // public String getId() {
176 // return SecureRapActivator.ID + ".logoutAction";
179 // public String getText() {
180 // return "Logout " + username;
183 // public void run() {
185 // // Subject subject = SecureRapActivator.getLoginContext()
187 // // String subjectStr = subject.toString();
188 // // subject.getPrincipals().clear();
189 // // SecureRapActivator.getLoginContext().logout();
190 // // log.info(subjectStr + " logged out");
191 // // } catch (LoginException e) {
192 // // log.error("Error when logging out", e);
194 // // SecureEntryPoint.logout(username);
195 // // PlatformUI.getWorkbench().close();
197 // // RWT.getRequest().getSession().setMaxInactiveInterval(1);
198 // // } catch (Exception e) {
199 // // if (log.isTraceEnabled())
200 // // log.trace("Error when invalidating session", e);
205 // return logoutAction;