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
.cms
.ui
.workbench
.rap
;
18 import org
.argeo
.cms
.auth
.CurrentUser
;
19 import org
.argeo
.cms
.ui
.workbench
.commands
.OpenHomePerspective
;
20 import org
.eclipse
.core
.commands
.Category
;
21 import org
.eclipse
.core
.commands
.Command
;
22 import org
.eclipse
.jface
.action
.ICoolBarManager
;
23 import org
.eclipse
.jface
.action
.IMenuManager
;
24 import org
.eclipse
.jface
.action
.IToolBarManager
;
25 import org
.eclipse
.jface
.action
.ToolBarManager
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.ui
.IWorkbenchWindow
;
28 import org
.eclipse
.ui
.actions
.ActionFactory
;
29 import org
.eclipse
.ui
.actions
.ActionFactory
.IWorkbenchAction
;
30 import org
.eclipse
.ui
.application
.ActionBarAdvisor
;
31 import org
.eclipse
.ui
.application
.IActionBarConfigurer
;
32 import org
.eclipse
.ui
.commands
.ICommandService
;
34 /** Eclipse rap specific action bar advisor */
35 public class RapActionBarAdvisor
extends ActionBarAdvisor
{
36 private final static String ID_BASE
= SecureRapActivator
.ID
;
37 // private final static Log log = LogFactory
38 // .getLog(SecureActionBarAdvisor.class);
40 /** Null means anonymous */
41 private String username
= null;
43 // private IAction logoutAction;
44 // private IWorkbenchAction openPerspectiveDialogAction;
45 // private IWorkbenchAction showViewMenuAction;
46 // private IWorkbenchAction preferences;
47 private IWorkbenchAction saveAction
;
48 private IWorkbenchAction saveAllAction
;
50 // private IWorkbenchAction closeAllAction;
52 public RapActionBarAdvisor(IActionBarConfigurer configurer
, String username
) {
54 this.username
= username
;
57 protected void makeActions(IWorkbenchWindow window
) {
58 // preferences = ActionFactory.PREFERENCES.create(window);
59 // register(preferences);
60 // openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
62 // register(openPerspectiveDialogAction);
63 // showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
64 // register(showViewMenuAction);
67 // logoutAction = ActionFactory.QUIT.create(window);
68 // // logoutAction = createLogoutAction();
69 // register(logoutAction);
72 saveAction
= ActionFactory
.SAVE
.create(window
);
74 saveAllAction
= ActionFactory
.SAVE_ALL
.create(window
);
75 register(saveAllAction
);
76 // closeAllAction = ActionFactory.CLOSE_ALL.create(window);
77 // register(closeAllAction);
81 protected void fillMenuBar(IMenuManager menuBar
) {
82 // MenuManager fileMenu = new MenuManager("&File",
83 // IWorkbenchActionConstants.M_FILE);
84 // MenuManager editMenu = new MenuManager("&Edit",
85 // IWorkbenchActionConstants.M_EDIT);
86 // MenuManager windowMenu = new MenuManager("&Window",
87 // IWorkbenchActionConstants.M_WINDOW);
89 // menuBar.add(fileMenu);
90 // menuBar.add(editMenu);
91 // menuBar.add(windowMenu);
92 // // Add a group marker indicating where action set menus will appear.
93 // menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
96 // fileMenu.add(saveAction);
97 // fileMenu.add(saveAllAction);
98 // fileMenu.add(closeAllAction);
100 // GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
101 // fileMenu.add(new Separator());
102 // fileMenu.add(logoutAction);
105 // editMenu.add(preferences);
108 // windowMenu.add(openPerspectiveDialogAction);
109 // windowMenu.add(showViewMenuAction);
113 protected void fillCoolBar(ICoolBarManager coolBar
) {
114 // Add a command which label is the display name of the current
116 if (username
!= null) {
117 ICommandService cmdService
= (ICommandService
) getActionBarConfigurer()
118 .getWindowConfigurer().getWorkbenchConfigurer()
119 .getWorkbench().getService(ICommandService
.class);
120 Category userMenus
= cmdService
.getCategory(ID_BASE
+ ".userMenus");
121 if (!userMenus
.isDefined())
122 userMenus
.define("User Menus", "User related menus");
123 Command userMenu
= cmdService
.getCommand(ID_BASE
124 + ".userMenuCommand");
125 if (userMenu
.isDefined())
127 userMenu
.define(CurrentUser
.getDisplayName(), "User menu actions",
129 // userMenu.define(username, "User menu actions", userMenus);
131 userMenu
.setHandler(new OpenHomePerspective());
133 // userToolbar.add(new UserMenuAction());
134 // coolBar.add(userToolbar);
136 IToolBarManager userToolbar
= new ToolBarManager(SWT
.FLAT
138 // userToolbar.add(logoutAction);
139 coolBar
.add(userToolbar
);
141 // IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT |
143 // saveToolbar.add(saveAction);
144 // saveToolbar.add(saveAllAction);
145 // coolBar.add(saveToolbar);
148 // class UserMenuAction extends Action implements IWorkbenchAction {
150 // public UserMenuAction() {
151 // super(username, IAction.AS_DROP_DOWN_MENU);
152 // // setMenuCreator(new UserMenu());
156 // public String getId() {
157 // return "org.argeo.cms.ui.workbench.rap.userMenu";
161 // public void dispose() {
166 // class UserMenu implements IMenuCreator {
167 // private Menu menu;
169 // public Menu getMenu(Control parent) {
170 // Menu menu = new Menu(parent);
171 // addActionToMenu(menu, logoutAction);
175 // private void addActionToMenu(Menu menu, IAction action) {
176 // ActionContributionItem item = new ActionContributionItem(action);
177 // item.fill(menu, -1);
180 // public void dispose() {
181 // if (menu != null) {
186 // public Menu getMenu(Menu parent) {
193 // protected IAction createLogoutAction() {
194 // Subject subject = Subject.getSubject(AccessController.getContext());
195 // final String username = subject.getPrincipals().iterator().next()
198 // IAction logoutAction = new Action() {
199 // public String getId() {
200 // return SecureRapActivator.ID + ".logoutAction";
203 // public String getText() {
204 // return "Logout " + username;
207 // public void run() {
209 // // Subject subject = SecureRapActivator.getLoginContext()
211 // // String subjectStr = subject.toString();
212 // // subject.getPrincipals().clear();
213 // // SecureRapActivator.getLoginContext().logout();
214 // // log.info(subjectStr + " logged out");
215 // // } catch (LoginException e) {
216 // // log.error("Error when logging out", e);
218 // // SecureEntryPoint.logout(username);
219 // // PlatformUI.getWorkbench().close();
221 // // RWT.getRequest().getSession().setMaxInactiveInterval(1);
222 // // } catch (Exception e) {
223 // // if (log.isTraceEnabled())
224 // // log.trace("Error when invalidating session", e);
229 // return logoutAction;