1 package org
.argeo
.security
.ui
.rap
;
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
;
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);
23 /** Null means anonymous */
24 private String username
= null;
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;
34 public RapActionBarAdvisor(IActionBarConfigurer configurer
, String username
) {
36 this.username
= username
;
39 protected void makeActions(IWorkbenchWindow window
) {
40 // preferences = ActionFactory.PREFERENCES.create(window);
41 // register(preferences);
42 // openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
44 // register(openPerspectiveDialogAction);
45 // showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
46 // register(showViewMenuAction);
49 // logoutAction = ActionFactory.QUIT.create(window);
50 // // logoutAction = createLogoutAction();
51 // register(logoutAction);
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);
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);
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));
78 // fileMenu.add(saveAction);
79 // fileMenu.add(saveAllAction);
80 // fileMenu.add(closeAllAction);
82 // GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
83 // fileMenu.add(new Separator());
84 // fileMenu.add(logoutAction);
87 // editMenu.add(preferences);
90 // windowMenu.add(openPerspectiveDialogAction);
91 // windowMenu.add(showViewMenuAction);
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");
104 Command userMenu
= cmdService
.getCommand(ID_BASE
105 + ".userMenuCommand");
106 if (userMenu
.isDefined())
108 userMenu
.define(username
, "User menu actions", userMenus
);
109 userMenu
.setHandler(new OpenHomePerspective());
111 // userToolbar.add(new UserMenuAction());
112 // coolBar.add(userToolbar);
114 IToolBarManager userToolbar
= new ToolBarManager(SWT
.FLAT
116 // userToolbar.add(logoutAction);
117 coolBar
.add(userToolbar
);
119 // IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT |
121 // saveToolbar.add(saveAction);
122 // saveToolbar.add(saveAllAction);
123 // coolBar.add(saveToolbar);
126 // class UserMenuAction extends Action implements IWorkbenchAction {
128 // public UserMenuAction() {
129 // super(username, IAction.AS_DROP_DOWN_MENU);
130 // // setMenuCreator(new UserMenu());
134 // public String getId() {
135 // return "org.argeo.security.ui.rap.userMenu";
139 // public void dispose() {
144 // class UserMenu implements IMenuCreator {
145 // private Menu menu;
147 // public Menu getMenu(Control parent) {
148 // Menu menu = new Menu(parent);
149 // addActionToMenu(menu, logoutAction);
153 // private void addActionToMenu(Menu menu, IAction action) {
154 // ActionContributionItem item = new ActionContributionItem(action);
155 // item.fill(menu, -1);
158 // public void dispose() {
159 // if (menu != null) {
164 // public Menu getMenu(Menu parent) {
171 // protected IAction createLogoutAction() {
172 // Subject subject = Subject.getSubject(AccessController.getContext());
173 // final String username = subject.getPrincipals().iterator().next()
176 // IAction logoutAction = new Action() {
177 // public String getId() {
178 // return SecureRapActivator.ID + ".logoutAction";
181 // public String getText() {
182 // return "Logout " + username;
185 // public void run() {
187 // // Subject subject = SecureRapActivator.getLoginContext()
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);
196 // // SecureEntryPoint.logout(username);
197 // // PlatformUI.getWorkbench().close();
199 // // RWT.getRequest().getSession().setMaxInactiveInterval(1);
200 // // } catch (Exception e) {
201 // // if (log.isTraceEnabled())
202 // // log.trace("Error when invalidating session", e);
207 // return logoutAction;