From 136ef465ce4ddd217e550bbe598258b5a967e846 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 18 Feb 2012 19:18:03 +0000 Subject: [PATCH] Improve user menu git-svn-id: https://svn.argeo.org/commons/trunk@5101 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../org.argeo.security.ui.rap/plugin.xml | 2 +- .../security/ui/rap/RapActionBarAdvisor.java | 114 +++++++++--------- .../security/ui/UserHomePerspective.java | 7 +- .../ui/commands/OpenHomePerspective.java | 24 ++++ 4 files changed, 88 insertions(+), 59 deletions(-) create mode 100644 security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenHomePerspective.java diff --git a/security/plugins/org.argeo.security.ui.rap/plugin.xml b/security/plugins/org.argeo.security.ui.rap/plugin.xml index cf2222a9f..cd8b601d8 100644 --- a/security/plugins/org.argeo.security.ui.rap/plugin.xml +++ b/security/plugins/org.argeo.security.ui.rap/plugin.xml @@ -112,7 +112,7 @@ diff --git a/security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/RapActionBarAdvisor.java b/security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/RapActionBarAdvisor.java index 68176dad2..f67ec0c07 100644 --- a/security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/RapActionBarAdvisor.java +++ b/security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/RapActionBarAdvisor.java @@ -1,5 +1,6 @@ package org.argeo.security.ui.rap; +import org.argeo.security.ui.commands.OpenHomePerspective; import org.argeo.security.ui.rap.commands.UserMenu; import org.eclipse.core.commands.Category; import org.eclipse.core.commands.Command; @@ -22,13 +23,13 @@ public class RapActionBarAdvisor extends ActionBarAdvisor { /** Null means anonymous */ private String username = null; -// private IAction logoutAction; -// private IWorkbenchAction openPerspectiveDialogAction; -// private IWorkbenchAction showViewMenuAction; -// private IWorkbenchAction preferences; -// private IWorkbenchAction saveAction; -// private IWorkbenchAction saveAllAction; -// private IWorkbenchAction closeAllAction; + // private IAction logoutAction; + // private IWorkbenchAction openPerspectiveDialogAction; + // private IWorkbenchAction showViewMenuAction; + // private IWorkbenchAction preferences; + // private IWorkbenchAction saveAction; + // private IWorkbenchAction saveAllAction; + // private IWorkbenchAction closeAllAction; public RapActionBarAdvisor(IActionBarConfigurer configurer, String username) { super(configurer); @@ -36,57 +37,58 @@ public class RapActionBarAdvisor extends ActionBarAdvisor { } protected void makeActions(IWorkbenchWindow window) { -// preferences = ActionFactory.PREFERENCES.create(window); -// register(preferences); -// openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG -// .create(window); -// register(openPerspectiveDialogAction); -// showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window); -// register(showViewMenuAction); -// -// // logout -// logoutAction = ActionFactory.QUIT.create(window); -// // logoutAction = createLogoutAction(); -// register(logoutAction); -// -// // Save semantics -// saveAction = ActionFactory.SAVE.create(window); -// register(saveAction); -// saveAllAction = ActionFactory.SAVE_ALL.create(window); -// register(saveAllAction); -// closeAllAction = ActionFactory.CLOSE_ALL.create(window); -// register(closeAllAction); + // preferences = ActionFactory.PREFERENCES.create(window); + // register(preferences); + // openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG + // .create(window); + // register(openPerspectiveDialogAction); + // showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window); + // register(showViewMenuAction); + // + // // logout + // logoutAction = ActionFactory.QUIT.create(window); + // // logoutAction = createLogoutAction(); + // register(logoutAction); + // + // // Save semantics + // saveAction = ActionFactory.SAVE.create(window); + // register(saveAction); + // saveAllAction = ActionFactory.SAVE_ALL.create(window); + // register(saveAllAction); + // closeAllAction = ActionFactory.CLOSE_ALL.create(window); + // register(closeAllAction); } protected void fillMenuBar(IMenuManager menuBar) { -// MenuManager fileMenu = new MenuManager("&File", -// IWorkbenchActionConstants.M_FILE); -// MenuManager editMenu = new MenuManager("&Edit", -// IWorkbenchActionConstants.M_EDIT); -// MenuManager windowMenu = new MenuManager("&Window", -// IWorkbenchActionConstants.M_WINDOW); -// -// menuBar.add(fileMenu); -// menuBar.add(editMenu); -// menuBar.add(windowMenu); -// // Add a group marker indicating where action set menus will appear. -// menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); -// -// // File -// fileMenu.add(saveAction); -// fileMenu.add(saveAllAction); -// fileMenu.add(closeAllAction); -// fileMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); -// fileMenu.add(new Separator()); -// fileMenu.add(logoutAction); -// -// // Edit -// editMenu.add(preferences); -// -// // Window -// windowMenu.add(openPerspectiveDialogAction); -// windowMenu.add(showViewMenuAction); + // MenuManager fileMenu = new MenuManager("&File", + // IWorkbenchActionConstants.M_FILE); + // MenuManager editMenu = new MenuManager("&Edit", + // IWorkbenchActionConstants.M_EDIT); + // MenuManager windowMenu = new MenuManager("&Window", + // IWorkbenchActionConstants.M_WINDOW); + // + // menuBar.add(fileMenu); + // menuBar.add(editMenu); + // menuBar.add(windowMenu); + // // Add a group marker indicating where action set menus will appear. + // menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); + // + // // File + // fileMenu.add(saveAction); + // fileMenu.add(saveAllAction); + // fileMenu.add(closeAllAction); + // fileMenu.add(new + // GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); + // fileMenu.add(new Separator()); + // fileMenu.add(logoutAction); + // + // // Edit + // editMenu.add(preferences); + // + // // Window + // windowMenu.add(openPerspectiveDialogAction); + // windowMenu.add(showViewMenuAction); } @Override @@ -104,14 +106,14 @@ public class RapActionBarAdvisor extends ActionBarAdvisor { if (userMenu.isDefined()) userMenu.undefine(); userMenu.define(username, "User menu actions", userMenus); - userMenu.setHandler(new UserMenu()); + userMenu.setHandler(new OpenHomePerspective()); // userToolbar.add(new UserMenuAction()); // coolBar.add(userToolbar); } else {// anonymous IToolBarManager userToolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); - //userToolbar.add(logoutAction); + // userToolbar.add(logoutAction); coolBar.add(userToolbar); } // IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT | diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/UserHomePerspective.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/UserHomePerspective.java index eb48d1d2d..329c1ade1 100644 --- a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/UserHomePerspective.java +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/UserHomePerspective.java @@ -5,16 +5,19 @@ import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; +/** Home perspective for the current user */ public class UserHomePerspective implements IPerspectiveFactory { + public final static String ID = "org.argeo.security.ui.userHomePerspective"; + public void createInitialLayout(IPageLayout layout) { String editorArea = layout.getEditorArea(); layout.setEditorAreaVisible(true); layout.setFixed(false); IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, - 0.65f, editorArea); + 0.30f, editorArea); left.addView(UserProfile.ID); -// left.addView(RolesView.ID); + // left.addView(RolesView.ID); } } diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenHomePerspective.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenHomePerspective.java new file mode 100644 index 000000000..53b0f01e7 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenHomePerspective.java @@ -0,0 +1,24 @@ +package org.argeo.security.ui.commands; + +import org.argeo.eclipse.ui.ErrorFeedback; +import org.argeo.security.ui.UserHomePerspective; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Default action of the user menu */ +public class OpenHomePerspective extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + try { + HandlerUtil.getActiveSite(event).getWorkbenchWindow() + .openPage(UserHomePerspective.ID, null); + } catch (WorkbenchException e) { + ErrorFeedback.show("Cannot open home perspective", e); + } + return null; + } + +} -- 2.30.2