2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.security
.ui
.rap
;
18 import org
.argeo
.security
.ui
.commands
.OpenHomePerspective
;
19 import org
.eclipse
.core
.commands
.Category
;
20 import org
.eclipse
.core
.commands
.Command
;
21 import org
.eclipse
.jface
.action
.ICoolBarManager
;
22 import org
.eclipse
.jface
.action
.IMenuManager
;
23 import org
.eclipse
.jface
.action
.IToolBarManager
;
24 import org
.eclipse
.jface
.action
.ToolBarManager
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.ui
.IWorkbenchWindow
;
27 import org
.eclipse
.ui
.actions
.ActionFactory
;
28 import org
.eclipse
.ui
.actions
.ActionFactory
.IWorkbenchAction
;
29 import org
.eclipse
.ui
.application
.ActionBarAdvisor
;
30 import org
.eclipse
.ui
.application
.IActionBarConfigurer
;
31 import org
.eclipse
.ui
.commands
.ICommandService
;
33 /** Eclipse rap specific action bar advisor */
34 public class RapActionBarAdvisor
extends ActionBarAdvisor
{
35 private final static String ID_BASE
= "org.argeo.security.ui.rap";
36 // private final static Log log = LogFactory
37 // .getLog(SecureActionBarAdvisor.class);
39 /** Null means anonymous */
40 private String username
= null;
42 // private IAction logoutAction;
43 // private IWorkbenchAction openPerspectiveDialogAction;
44 // private IWorkbenchAction showViewMenuAction;
45 // private IWorkbenchAction preferences;
46 private IWorkbenchAction saveAction
;
47 private IWorkbenchAction saveAllAction
;
49 // private IWorkbenchAction closeAllAction;
51 public RapActionBarAdvisor(IActionBarConfigurer configurer
, String username
) {
53 this.username
= username
;
56 protected void makeActions(IWorkbenchWindow window
) {
57 // preferences = ActionFactory.PREFERENCES.create(window);
58 // register(preferences);
59 // openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
61 // register(openPerspectiveDialogAction);
62 // showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
63 // register(showViewMenuAction);
66 // logoutAction = ActionFactory.QUIT.create(window);
67 // // logoutAction = createLogoutAction();
68 // register(logoutAction);
71 saveAction
= ActionFactory
.SAVE
.create(window
);
73 saveAllAction
= ActionFactory
.SAVE_ALL
.create(window
);
74 register(saveAllAction
);
75 // closeAllAction = ActionFactory.CLOSE_ALL.create(window);
76 // register(closeAllAction);
80 protected void fillMenuBar(IMenuManager menuBar
) {
81 // MenuManager fileMenu = new MenuManager("&File",
82 // IWorkbenchActionConstants.M_FILE);
83 // MenuManager editMenu = new MenuManager("&Edit",
84 // IWorkbenchActionConstants.M_EDIT);
85 // MenuManager windowMenu = new MenuManager("&Window",
86 // IWorkbenchActionConstants.M_WINDOW);
88 // menuBar.add(fileMenu);
89 // menuBar.add(editMenu);
90 // menuBar.add(windowMenu);
91 // // Add a group marker indicating where action set menus will appear.
92 // menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
95 // fileMenu.add(saveAction);
96 // fileMenu.add(saveAllAction);
97 // fileMenu.add(closeAllAction);
99 // GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
100 // fileMenu.add(new Separator());
101 // fileMenu.add(logoutAction);
104 // editMenu.add(preferences);
107 // windowMenu.add(openPerspectiveDialogAction);
108 // windowMenu.add(showViewMenuAction);
112 protected void fillCoolBar(ICoolBarManager coolBar
) {
113 if (username
!= null) {
114 ICommandService cmdService
= (ICommandService
) getActionBarConfigurer()
115 .getWindowConfigurer().getWorkbenchConfigurer()
116 .getWorkbench().getService(ICommandService
.class);
117 Category userMenus
= cmdService
.getCategory(ID_BASE
+ ".userMenus");
118 if (!userMenus
.isDefined())
119 userMenus
.define("User Menus", "User related menus");
121 Command userMenu
= cmdService
.getCommand(ID_BASE
122 + ".userMenuCommand");
123 if (userMenu
.isDefined())
125 userMenu
.define(username
, "User menu actions", userMenus
);
126 userMenu
.setHandler(new OpenHomePerspective());
128 // userToolbar.add(new UserMenuAction());
129 // coolBar.add(userToolbar);
131 IToolBarManager userToolbar
= new ToolBarManager(SWT
.FLAT
133 // userToolbar.add(logoutAction);
134 coolBar
.add(userToolbar
);
136 // IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT |
138 // saveToolbar.add(saveAction);
139 // saveToolbar.add(saveAllAction);
140 // coolBar.add(saveToolbar);
143 // class UserMenuAction extends Action implements IWorkbenchAction {
145 // public UserMenuAction() {
146 // super(username, IAction.AS_DROP_DOWN_MENU);
147 // // setMenuCreator(new UserMenu());
151 // public String getId() {
152 // return "org.argeo.security.ui.rap.userMenu";
156 // public void dispose() {
161 // class UserMenu implements IMenuCreator {
162 // private Menu menu;
164 // public Menu getMenu(Control parent) {
165 // Menu menu = new Menu(parent);
166 // addActionToMenu(menu, logoutAction);
170 // private void addActionToMenu(Menu menu, IAction action) {
171 // ActionContributionItem item = new ActionContributionItem(action);
172 // item.fill(menu, -1);
175 // public void dispose() {
176 // if (menu != null) {
181 // public Menu getMenu(Menu parent) {
188 // protected IAction createLogoutAction() {
189 // Subject subject = Subject.getSubject(AccessController.getContext());
190 // final String username = subject.getPrincipals().iterator().next()
193 // IAction logoutAction = new Action() {
194 // public String getId() {
195 // return SecureRapActivator.ID + ".logoutAction";
198 // public String getText() {
199 // return "Logout " + username;
202 // public void run() {
204 // // Subject subject = SecureRapActivator.getLoginContext()
206 // // String subjectStr = subject.toString();
207 // // subject.getPrincipals().clear();
208 // // SecureRapActivator.getLoginContext().logout();
209 // // log.info(subjectStr + " logged out");
210 // // } catch (LoginException e) {
211 // // log.error("Error when logging out", e);
213 // // SecureEntryPoint.logout(username);
214 // // PlatformUI.getWorkbench().close();
216 // // RWT.getRequest().getSession().setMaxInactiveInterval(1);
217 // // } catch (Exception e) {
218 // // if (log.isTraceEnabled())
219 // // log.trace("Error when invalidating session", e);
224 // return logoutAction;