Improve user menu
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 18 Feb 2012 19:18:03 +0000 (19:18 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 18 Feb 2012 19:18:03 +0000 (19:18 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5101 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

security/plugins/org.argeo.security.ui.rap/plugin.xml
security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/RapActionBarAdvisor.java
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/UserHomePerspective.java
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenHomePerspective.java [new file with mode: 0644]

index cf2222a9f47c1f9d655fdfe898d543b32f59dd93..cd8b601d85f306effbe4199e44c0db96814d740d 100644 (file)
       </command>
       <command
             id="org.argeo.security.ui.rap.mainMenuCommand"
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+            defaultHandler="org.argeo.security.ui.commands.OpenHomePerspective"
             name="Main">
       </command>
     </extension>
index 68176dad2940ffb4057f807760ee730079a4d195..f67ec0c07f099279a379ee9657260ac43d790232 100644 (file)
@@ -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 |
index eb48d1d2d96dc0321b6c205ed8e5ffc53ff32fa7..329c1ade1dd864879fa9f4fcf8b4246e121963fa 100644 (file)
@@ -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 (file)
index 0000000..53b0f01
--- /dev/null
@@ -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;
+       }
+
+}