You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/01/08 01:25:33 UTC

[2/9] isis git commit: ISIS-990: small refactoring so that if UserProfileService returns null, then defaults back to using the current user name.

ISIS-990: small refactoring so that if UserProfileService returns null, then defaults back to using the current user name.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/a41e5568
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/a41e5568
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/a41e5568

Branch: refs/heads/master
Commit: a41e5568c1881f79c9b0fac3269e4d84d9ae26ad
Parents: b78c07f
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Wed Jan 7 20:25:17 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Wed Jan 7 20:25:17 2015 +0000

----------------------------------------------------------------------
 .../viewer/wicket/ui/pages/PageAbstract.java    | 36 +++++++++++++-------
 .../services/userprof/UserProfileService.java   | 21 +++---------
 2 files changed, 27 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/a41e5568/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
index 94b3378..d1dd681 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
@@ -97,10 +97,6 @@ import org.apache.isis.viewer.wicket.ui.util.CssClassAppender;
  */
 public abstract class PageAbstract extends WebPage implements ActionPromptProvider {
 
-    public static final String TERTIARY_MENU_BAR = "tertiaryMenuBar";
-    public static final String SECONDARY_MENU_BAR = "secondaryMenuBar";
-    public static final String PRIMARY_MENU_BAR = "primaryMenuBar";
-    public static final String USER_NAME = "userName";
     private static Logger LOG = LoggerFactory.getLogger(PageAbstract.class);
 
     private static final long serialVersionUID = 1L;
@@ -111,8 +107,17 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
     private static final JavaScriptResourceReference JQUERY_LIVEQUERY_JS = new JavaScriptResourceReference(PageAbstract.class, "jquery.livequery.js");
     private static final JavaScriptResourceReference JQUERY_ISIS_WICKET_VIEWER_JS = new JavaScriptResourceReference(PageAbstract.class, "jquery.isis.wicket.viewer.js");
     
+    // not to be confused with the bootstrap theme...
+    // is simply a CSS class derived from the application's name
     private static final String ID_THEME = "theme";
+
     private static final String ID_BOOKMARKED_PAGES = "bookmarks";
+    private static final String ID_PRIMARY_MENU_BAR = "primaryMenuBar";
+    private static final String ID_SECONDARY_MENU_BAR = "secondaryMenuBar";
+    private static final String ID_TERTIARY_MENU_BAR = "tertiaryMenuBar";
+    private static final String ID_USER_NAME = "userName";
+    private static final String ID_ABOUT_LINK = "aboutLink";
+    private static final String ID_ABOUT_MESSAGE = "aboutMessage";
 
     private static final String ID_ACTION_PROMPT_MODAL_WINDOW = "actionPromptModalWindow";
     
@@ -120,10 +125,10 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
     
     public static final String ID_MENU_LINK = "menuLink";
 
+    // the bootstrap theme
     private static final String ID_THEME_PICKER = "themePicker";
     private static final String ID_BREADCRUMBS = "breadcrumbs";
 
-
     /**
      * This is a bit hacky, but best way I've found to pass an exception over to the WicketSignInPage
      * if there is a problem rendering this page.
@@ -305,22 +310,27 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
 
     private void addUserName(final MarkupContainer themeDiv) {
         final UserProfileService userProfileService = getUserProfileService();
-        final Label userName = new Label(USER_NAME, userProfileService.userProfileName());
+        final Label userName = new Label(ID_USER_NAME, userProfileService.userProfileName());
         themeDiv.add(userName);
     }
 
     private UserProfileService getUserProfileService() {
         final UserProfileService userProfileService = lookupService(UserProfileService.class);
-        final String userProfileName = getAuthenticationSession().getUserName();
-        return userProfileService != null ? userProfileService: new UserProfileService.Default(userProfileName);
+        return new UserProfileService() {
+            @Override
+            public String userProfileName() {
+                final String userProfileName = userProfileService != null ? userProfileService.userProfileName() : null;
+                return userProfileName != null? userProfileName: getAuthenticationSession().getUserName();
+            }
+        };
     }
 
 
     private void addAboutLink(final MarkupContainer themeDiv) {
-        final BookmarkablePageLink<Void> aboutLink = new BookmarkablePageLink<>("aboutLink", AboutPage.class);
+        final BookmarkablePageLink<Void> aboutLink = new BookmarkablePageLink<>(ID_ABOUT_LINK, AboutPage.class);
         themeDiv.add(aboutLink);
 
-        final Label aboutLabel = new Label("aboutMessage", new ResourceModel("aboutLabel"));
+        final Label aboutLabel = new Label(ID_ABOUT_MESSAGE, new ResourceModel("aboutLabel"));
         aboutLink.add(aboutLabel);
         addDevModeWarning(aboutLink);
     }
@@ -358,9 +368,9 @@ public abstract class PageAbstract extends WebPage implements ActionPromptProvid
     }
 
     private void addServiceActionMenuBars(final MarkupContainer container) {
-        addMenuBar(container, PRIMARY_MENU_BAR, DomainServiceLayout.MenuBar.PRIMARY);
-        addMenuBar(container, SECONDARY_MENU_BAR, DomainServiceLayout.MenuBar.SECONDARY);
-        addMenuBar(container, TERTIARY_MENU_BAR, DomainServiceLayout.MenuBar.TERTIARY);
+        addMenuBar(container, ID_PRIMARY_MENU_BAR, DomainServiceLayout.MenuBar.PRIMARY);
+        addMenuBar(container, ID_SECONDARY_MENU_BAR, DomainServiceLayout.MenuBar.SECONDARY);
+        addMenuBar(container, ID_TERTIARY_MENU_BAR, DomainServiceLayout.MenuBar.TERTIARY);
     }
 
     private void addMenuBar(final MarkupContainer container, final String id, final DomainServiceLayout.MenuBar menuBar) {

http://git-wip-us.apache.org/repos/asf/isis/blob/a41e5568/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java b/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java
index 216c5ad..6759ca5 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/userprof/UserProfileService.java
@@ -33,24 +33,11 @@ public interface UserProfileService {
     /**
      * Used as the menu name of the {@link org.apache.isis.applib.annotation.DomainServiceLayout.MenuBar#TERTIARY tertiary}
      * &quot;Me&quot; menu bar.
+     *
+     * <p>
+     *     If returns <tt>null</tt>, then the current user name is used instead.
+     * </p>
      */
     @Programmatic
     String userProfileName();
-
-    /**
-     * Default implementation (instantiated internally by the framework if no
-     * other implementation has been registered).
-     */
-    public static class Default implements UserProfileService {
-        private final String userProfileName;
-
-        public Default(final String userProfileName) {
-            this.userProfileName = userProfileName;
-        }
-
-        @Override
-        public String userProfileName() {
-            return userProfileName;
-        }
-    }
 }