]> git.argeo.org Git - lgpl/argeo-commons.git/blob - rap/RapActionBarAdvisor.java
Prepare next development cycle
[lgpl/argeo-commons.git] / rap / RapActionBarAdvisor.java
1 package org.argeo.security.ui.rap;
2
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;
15
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);
21
22 /** Null means anonymous */
23 private String username = null;
24
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;
32
33 public RapActionBarAdvisor(IActionBarConfigurer configurer, String username) {
34 super(configurer);
35 this.username = username;
36 }
37
38 protected void makeActions(IWorkbenchWindow window) {
39 // preferences = ActionFactory.PREFERENCES.create(window);
40 // register(preferences);
41 // openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
42 // .create(window);
43 // register(openPerspectiveDialogAction);
44 // showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
45 // register(showViewMenuAction);
46 //
47 // // logout
48 // logoutAction = ActionFactory.QUIT.create(window);
49 // // logoutAction = createLogoutAction();
50 // register(logoutAction);
51 //
52 // // Save semantics
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);
59
60 }
61
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);
69 //
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));
75 //
76 // // File
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);
83 //
84 // // Edit
85 // editMenu.add(preferences);
86 //
87 // // Window
88 // windowMenu.add(openPerspectiveDialogAction);
89 // windowMenu.add(showViewMenuAction);
90 }
91
92 @Override
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");
101
102 Command userMenu = cmdService.getCommand(ID_BASE
103 + ".userMenuCommand");
104 if (userMenu.isDefined())
105 userMenu.undefine();
106 userMenu.define(username, "User menu actions", userMenus);
107 userMenu.setHandler(new UserMenu());
108
109 // userToolbar.add(new UserMenuAction());
110 // coolBar.add(userToolbar);
111 } else {// anonymous
112 IToolBarManager userToolbar = new ToolBarManager(SWT.FLAT
113 | SWT.RIGHT);
114 //userToolbar.add(logoutAction);
115 coolBar.add(userToolbar);
116 }
117 // IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT |
118 // SWT.RIGHT);
119 // saveToolbar.add(saveAction);
120 // saveToolbar.add(saveAllAction);
121 // coolBar.add(saveToolbar);
122 }
123
124 // class UserMenuAction extends Action implements IWorkbenchAction {
125 //
126 // public UserMenuAction() {
127 // super(username, IAction.AS_DROP_DOWN_MENU);
128 // // setMenuCreator(new UserMenu());
129 // }
130 //
131 // @Override
132 // public String getId() {
133 // return "org.argeo.security.ui.rap.userMenu";
134 // }
135 //
136 // @Override
137 // public void dispose() {
138 // }
139 //
140 // }
141
142 // class UserMenu implements IMenuCreator {
143 // private Menu menu;
144 //
145 // public Menu getMenu(Control parent) {
146 // Menu menu = new Menu(parent);
147 // addActionToMenu(menu, logoutAction);
148 // return menu;
149 // }
150 //
151 // private void addActionToMenu(Menu menu, IAction action) {
152 // ActionContributionItem item = new ActionContributionItem(action);
153 // item.fill(menu, -1);
154 // }
155 //
156 // public void dispose() {
157 // if (menu != null) {
158 // menu.dispose();
159 // }
160 // }
161 //
162 // public Menu getMenu(Menu parent) {
163 // // Not use
164 // return null;
165 // }
166 //
167 // }
168
169 // protected IAction createLogoutAction() {
170 // Subject subject = Subject.getSubject(AccessController.getContext());
171 // final String username = subject.getPrincipals().iterator().next()
172 // .getName();
173 //
174 // IAction logoutAction = new Action() {
175 // public String getId() {
176 // return SecureRapActivator.ID + ".logoutAction";
177 // }
178 //
179 // public String getText() {
180 // return "Logout " + username;
181 // }
182 //
183 // public void run() {
184 // // try {
185 // // Subject subject = SecureRapActivator.getLoginContext()
186 // // .getSubject();
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);
193 // // }
194 // // SecureEntryPoint.logout(username);
195 // // PlatformUI.getWorkbench().close();
196 // // try {
197 // // RWT.getRequest().getSession().setMaxInactiveInterval(1);
198 // // } catch (Exception e) {
199 // // if (log.isTraceEnabled())
200 // // log.trace("Error when invalidating session", e);
201 // // }
202 // }
203 //
204 // };
205 // return logoutAction;
206 // }
207
208 }