]> source.dussan.org Git - gitblit.git/commitdiff
Overhaul menu item classes and add AdminMenuExtension point
authorJames Moger <james.moger@gitblit.com>
Mon, 21 Apr 2014 20:16:45 +0000 (16:16 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 5 May 2014 15:17:14 +0000 (11:17 -0400)
13 files changed:
src/main/java/com/gitblit/extensions/AdminMenuExtension.java [new file with mode: 0644]
src/main/java/com/gitblit/models/Menu.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
src/main/java/com/gitblit/wicket/PageRegistration.java
src/main/java/com/gitblit/wicket/pages/ActivityPage.java
src/main/java/com/gitblit/wicket/pages/DashboardPage.java
src/main/java/com/gitblit/wicket/pages/ProjectPage.java
src/main/java/com/gitblit/wicket/pages/ProjectsPage.java
src/main/java/com/gitblit/wicket/pages/RepositoriesPage.java
src/main/java/com/gitblit/wicket/pages/RootPage.java
src/main/java/com/gitblit/wicket/pages/UserPage.java
src/main/java/com/gitblit/wicket/panels/DropDownMenu.java
src/site/plugins_extensions.mkd

diff --git a/src/main/java/com/gitblit/extensions/AdminMenuExtension.java b/src/main/java/com/gitblit/extensions/AdminMenuExtension.java
new file mode 100644 (file)
index 0000000..8fe4288
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.extensions;
+
+import java.util.List;
+
+import ro.fortsoft.pf4j.ExtensionPoint;
+
+import com.gitblit.models.Menu.MenuItem;
+import com.gitblit.models.UserModel;
+
+/**
+ * Extension point to contribute administration menu items.
+ *
+ * @author James Moger
+ * @since 1.6.0
+ *
+ */
+public abstract class AdminMenuExtension implements ExtensionPoint {
+
+       /**
+        * @param user
+        * @since 1.6.0
+        * @return a list of menu items
+        */
+       public abstract List<MenuItem> getMenuItems(UserModel user);
+}
diff --git a/src/main/java/com/gitblit/models/Menu.java b/src/main/java/com/gitblit/models/Menu.java
new file mode 100644 (file)
index 0000000..7c949b3
--- /dev/null
@@ -0,0 +1,302 @@
+package com.gitblit.models;
+
+import java.io.Serializable;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebPage;
+
+import com.gitblit.utils.StringUtils;
+
+public class Menu {
+
+       /**
+        * A MenuItem for a drop down menu.
+        *
+        * @author James Moger
+        * @since 1.6.0
+        */
+       public abstract static class MenuItem implements Serializable {
+
+               private static final long serialVersionUID = 1L;
+
+               final String displayText;
+
+               MenuItem(String displayText) {
+                       this.displayText = displayText;
+               }
+
+               @Override
+               public int hashCode() {
+                       return displayText.hashCode();
+               }
+
+               @Override
+               public boolean equals(Object o) {
+                       if (o instanceof MenuItem) {
+                               return hashCode() == o.hashCode();
+                       }
+                       return false;
+               }
+
+               @Override
+               public String toString() {
+                       return displayText;
+               }
+       }
+
+       /**
+        * A divider for the menu.
+        *
+        * @since 1.6.0
+        */
+       public static class MenuDivider extends MenuItem {
+
+               private static final long serialVersionUID = 1L;
+
+               public MenuDivider() {
+                       super("");
+               }
+       }
+
+
+       /**
+        * A MenuItem for setting a parameter of the current url.
+        *
+        * @author James Moger
+        *
+        */
+       public static class ParameterMenuItem extends MenuItem {
+
+               private static final long serialVersionUID = 1L;
+
+               final PageParameters parameters;
+               final String parameter;
+               final String value;
+               final boolean isSelected;
+
+               /**
+                * @param displayText
+                */
+               public ParameterMenuItem(String displayText) {
+                       this(displayText, null, null, null);
+               }
+
+               /**
+                * @param displayText
+                * @param parameter
+                * @param value
+                */
+               public ParameterMenuItem(String displayText, String parameter, String value) {
+                       this(displayText, parameter, value, null);
+               }
+
+               /**
+                * @param displayText
+                * @param parameter
+                * @param value
+                */
+               public ParameterMenuItem(String displayText, String parameter, String value,
+                               PageParameters params) {
+                       super(displayText);
+                       this.parameter = parameter;
+                       this.value = value;
+
+                       if (params == null) {
+                               // no parameters specified
+                               parameters = new PageParameters();
+                               setParameter(parameter, value);
+                               isSelected = false;
+                       } else {
+                               parameters = new PageParameters(params);
+                               if (parameters.containsKey(parameter)) {
+                                       isSelected = params.getString(parameter).equals(value);
+                                       // set the new selection value
+                                       setParameter(parameter, value);
+                               } else {
+                                       // not currently selected
+                                       isSelected = false;
+                                       setParameter(parameter, value);
+                               }
+                       }
+               }
+
+               protected void setParameter(String parameter, String value) {
+                       if (!StringUtils.isEmpty(parameter)) {
+                               if (StringUtils.isEmpty(value)) {
+                                       this.parameters.remove(parameter);
+                               } else {
+                                       this.parameters.put(parameter, value);
+                               }
+                       }
+               }
+
+               public String formatParameter() {
+                       if (StringUtils.isEmpty(parameter) || StringUtils.isEmpty(value)) {
+                               return "";
+                       }
+                       return parameter + "=" + value;
+               }
+
+               public PageParameters getPageParameters() {
+                       return parameters;
+               }
+
+               public boolean isSelected() {
+                       return isSelected;
+               }
+
+               @Override
+               public int hashCode() {
+                       if (StringUtils.isEmpty(displayText)) {
+                               return value.hashCode() + parameter.hashCode();
+                       }
+                       return displayText.hashCode();
+               }
+
+               @Override
+               public boolean equals(Object o) {
+                       if (o instanceof MenuItem) {
+                               return hashCode() == o.hashCode();
+                       }
+                       return false;
+               }
+
+               @Override
+               public String toString() {
+                       if (StringUtils.isEmpty(displayText)) {
+                               return formatParameter();
+                       }
+                       return displayText;
+               }
+       }
+
+       /**
+        * Menu item for toggling a parameter.
+        *
+        */
+       public static class ToggleMenuItem extends ParameterMenuItem {
+
+               private static final long serialVersionUID = 1L;
+
+               /**
+                * @param displayText
+                * @param parameter
+                * @param value
+                */
+               public ToggleMenuItem(String displayText, String parameter, String value,
+                               PageParameters params) {
+                       super(displayText, parameter, value, params);
+                       if (isSelected) {
+                               // already selected, so remove this enables toggling
+                               parameters.remove(parameter);
+                       }
+               }
+       }
+
+       /**
+        * Menu item for linking to another Wicket page.
+        *
+        * @since 1.6.0
+        */
+       public static class PageLinkMenuItem extends MenuItem {
+
+               private static final long serialVersionUID = 1L;
+
+               private final Class<? extends WebPage> pageClass;
+
+               private final PageParameters params;
+
+               /**
+                * Page Link Item links to another page.
+                *
+                * @param displayText
+                * @param pageClass
+                * @since 1.6.0
+                */
+               public PageLinkMenuItem(String displayText, Class<? extends WebPage> pageClass) {
+                       this(displayText, pageClass, null);
+               }
+
+               /**
+                * Page Link Item links to another page.
+                *
+                * @param displayText
+                * @param pageClass
+                * @param params
+                * @since 1.6.0
+                */
+               public PageLinkMenuItem(String displayText, Class<? extends WebPage> pageClass, PageParameters params) {
+                       super(displayText);
+                       this.pageClass = pageClass;
+                       this.params = params;
+               }
+
+               /**
+                * @return the page class
+                * @since 1.6.0
+                */
+               public Class<? extends WebPage> getPageClass() {
+                       return pageClass;
+               }
+
+               /**
+                * @return the page parameters
+                * @since 1.6.0
+                */
+               public PageParameters getPageParameters() {
+                       return params;
+               }
+       }
+
+       /**
+        * Menu item to link to an external page.
+        *
+        * @since 1.6.0
+        */
+       public static class ExternalLinkMenuItem extends MenuItem {
+
+               private static final long serialVersionUID = 1L;
+
+               private final String href;
+
+               private final boolean newWindow;
+
+               /**
+                * External Link Item links to something else.
+                *
+                * @param displayText
+                * @param href
+                * @since 1.6.0
+                */
+               public ExternalLinkMenuItem(String displayText, String href) {
+                       this(displayText, href, false);
+               }
+
+               /**
+                * External Link Item links to something else.
+                *
+                * @param displayText
+                * @param href
+                * @since 1.6.0
+                */
+               public ExternalLinkMenuItem(String displayText, String href, boolean newWindow) {
+                       super(displayText);
+                       this.href = href;
+                       this.newWindow = newWindow;
+               }
+
+               /**
+                * @since 1.6.0
+                */
+               public String getHref() {
+                       return href;
+               }
+
+               /**
+                * @since 1.6.0
+                */
+               public boolean openInNewWindow() {
+                       return newWindow;
+               }
+       }
+}
index 0ed2ed59cb7b3237af695d2e9d51f3a08b29dc9d..2c83dd6c7be4a444d61a62305f948483a3d3bcb1 100644 (file)
@@ -680,3 +680,4 @@ gb.notifyChangedOpenTickets = send notification for changed open tickets
 gb.overdue = overdue
 gb.openMilestones = open milestones
 gb.closedMilestones = closed milestones
+gb.adminMenuItem = admin
index 1b98f2c7abafd4519c0eed1a67ed4c9484ed9c30..ff4a55b4414a8bb2b819289552548a400d58a8e7 100644 (file)
@@ -22,7 +22,7 @@ import java.util.List;
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.WebPage;\r
 \r
-import com.gitblit.utils.StringUtils;\r
+import com.gitblit.models.Menu.MenuItem;\r
 \r
 /**\r
  * Represents a page link registration for the topbar.\r
@@ -88,156 +88,12 @@ public class PageRegistration implements Serializable {
 \r
                private static final long serialVersionUID = 1L;\r
 \r
-               public final List<DropDownMenuItem> menuItems;\r
+               public final List<MenuItem> menuItems;\r
 \r
                public DropDownMenuRegistration(String translationKey, Class<? extends WebPage> pageClass) {\r
                        super(translationKey, pageClass);\r
-                       menuItems = new ArrayList<DropDownMenuItem>();\r
+                       menuItems = new ArrayList<MenuItem>();\r
                }\r
        }\r
 \r
-       /**\r
-        * A MenuItem for the DropDownMenu.\r
-        *\r
-        * @author James Moger\r
-        *\r
-        */\r
-       public static class DropDownMenuItem implements Serializable {\r
-\r
-               private static final long serialVersionUID = 1L;\r
-\r
-               final PageParameters parameters;\r
-               final String displayText;\r
-               final String parameter;\r
-               final String value;\r
-               final boolean isSelected;\r
-\r
-               /**\r
-                * Divider constructor.\r
-                */\r
-               public DropDownMenuItem() {\r
-                       this(null, null, null, null);\r
-               }\r
-\r
-               /**\r
-                * Standard Menu Item constructor.\r
-                *\r
-                * @param displayText\r
-                * @param parameter\r
-                * @param value\r
-                */\r
-               public DropDownMenuItem(String displayText, String parameter, String value) {\r
-                       this(displayText, parameter, value, null);\r
-               }\r
-\r
-               /**\r
-                * Standard Menu Item constructor that preserves aggregate parameters.\r
-                *\r
-                * @param displayText\r
-                * @param parameter\r
-                * @param value\r
-                */\r
-               public DropDownMenuItem(String displayText, String parameter, String value,\r
-                               PageParameters params) {\r
-                       this.displayText = displayText;\r
-                       this.parameter = parameter;\r
-                       this.value = value;\r
-\r
-                       if (params == null) {\r
-                               // no parameters specified\r
-                               parameters = new PageParameters();\r
-                               setParameter(parameter, value);\r
-                               isSelected = false;\r
-                       } else {\r
-                               parameters = new PageParameters(params);\r
-                               if (parameters.containsKey(parameter)) {\r
-                                       isSelected = params.getString(parameter).equals(value);\r
-                                       // set the new selection value\r
-                                       setParameter(parameter, value);\r
-                               } else {\r
-                                       // not currently selected\r
-                                       isSelected = false;\r
-                                       setParameter(parameter, value);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               protected void setParameter(String parameter, String value) {\r
-                       if (!StringUtils.isEmpty(parameter)) {\r
-                               if (StringUtils.isEmpty(value)) {\r
-                                       this.parameters.remove(parameter);\r
-                               } else {\r
-                                       this.parameters.put(parameter, value);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public String formatParameter() {\r
-                       if (StringUtils.isEmpty(parameter) || StringUtils.isEmpty(value)) {\r
-                               return "";\r
-                       }\r
-                       return parameter + "=" + value;\r
-               }\r
-\r
-               public PageParameters getPageParameters() {\r
-                       return parameters;\r
-               }\r
-\r
-               public boolean isDivider() {\r
-                       return displayText == null && value == null && parameter == null;\r
-               }\r
-\r
-               public boolean isSelected() {\r
-                       return isSelected;\r
-               }\r
-\r
-               @Override\r
-               public int hashCode() {\r
-                       if (isDivider()) {\r
-                               // divider menu item\r
-                               return super.hashCode();\r
-                       }\r
-                       if (StringUtils.isEmpty(displayText)) {\r
-                               return value.hashCode() + parameter.hashCode();\r
-                       }\r
-                       return displayText.hashCode();\r
-               }\r
-\r
-               @Override\r
-               public boolean equals(Object o) {\r
-                       if (o instanceof DropDownMenuItem) {\r
-                               return hashCode() == o.hashCode();\r
-                       }\r
-                       return false;\r
-               }\r
-\r
-               @Override\r
-               public String toString() {\r
-                       if (StringUtils.isEmpty(displayText)) {\r
-                               return formatParameter();\r
-                       }\r
-                       return displayText;\r
-               }\r
-       }\r
-\r
-       public static class DropDownToggleItem extends DropDownMenuItem {\r
-\r
-               private static final long serialVersionUID = 1L;\r
-\r
-               /**\r
-                * Toggle Menu Item constructor that preserves aggregate parameters.\r
-                *\r
-                * @param displayText\r
-                * @param parameter\r
-                * @param value\r
-                */\r
-               public DropDownToggleItem(String displayText, String parameter, String value,\r
-                               PageParameters params) {\r
-                       super(displayText, parameter, value, params);\r
-                       if (isSelected) {\r
-                               // already selected, so remove this enables toggling\r
-                               parameters.remove(parameter);\r
-                       }\r
-               }\r
-       }\r
 }
\ No newline at end of file
index f0e390dc3b598621a582ccb032cf6e81db593b1f..0870ff962fd57945ac00c10c6f4ad9f89a09db81 100644 (file)
@@ -31,6 +31,7 @@ import org.apache.wicket.markup.html.panel.Fragment;
 \r
 import com.gitblit.Keys;\r
 import com.gitblit.models.Activity;\r
+import com.gitblit.models.Menu.ParameterMenuItem;\r
 import com.gitblit.models.Metric;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.ActivityUtils;\r
@@ -38,7 +39,6 @@ import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.CacheControl;\r
 import com.gitblit.wicket.CacheControl.LastModified;\r
 import com.gitblit.wicket.PageRegistration;\r
-import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
 import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.charting.Chart;\r
@@ -153,7 +153,7 @@ public class ActivityPage extends RootPage {
 \r
                if (filters.menuItems.size() > 0) {\r
                        // Reset Filter\r
-                       filters.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));\r
+                       filters.menuItems.add(new ParameterMenuItem(getString("gb.reset")));\r
                }\r
                pages.add(filters);\r
        }\r
@@ -209,7 +209,7 @@ public class ActivityPage extends RootPage {
                }\r
                charts.addChart(chart);\r
 \r
-               // active repositories pie chart \r
+               // active repositories pie chart\r
                chart = charts.createPieChart("chartRepositories", getString("gb.activeRepositories"),\r
                                getString("gb.repository"), getString("gb.commits"));\r
                for (Metric metric : repositoryMetrics.values()) {\r
index 9853449eca91c37b737da06dafe6f5060999ff14..16b0b73400dec8ae5303716817b466ac8d102b49 100644 (file)
@@ -36,6 +36,7 @@ import org.eclipse.jgit.lib.Repository;
 \r
 import com.gitblit.Keys;\r
 import com.gitblit.models.DailyLogEntry;\r
+import com.gitblit.models.Menu.ParameterMenuItem;\r
 import com.gitblit.models.Metric;\r
 import com.gitblit.models.RefLogEntry;\r
 import com.gitblit.models.RepositoryCommit;\r
@@ -46,7 +47,6 @@ import com.gitblit.utils.RefLogUtils;
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebApp;\r
 import com.gitblit.wicket.PageRegistration;\r
-import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
 import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
 import com.gitblit.wicket.charting.Chart;\r
 import com.gitblit.wicket.charting.Charts;\r
@@ -152,7 +152,7 @@ public abstract class DashboardPage extends RootPage {
 \r
                if (menu.menuItems.size() > 0) {\r
                        // Reset Filter\r
-                       menu.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));\r
+                       menu.menuItems.add(new ParameterMenuItem(getString("gb.reset")));\r
                }\r
 \r
                pages.add(menu);\r
index b92282b415ad427f7da2f081e03a12acc905a2b9..6c8aa4f4a8e55aed7779deaa252ba084af4b21ba 100644 (file)
@@ -26,6 +26,9 @@ import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.link.ExternalLink;\r
 \r
 import com.gitblit.Keys;\r
+import com.gitblit.models.Menu.MenuDivider;\r
+import com.gitblit.models.Menu.MenuItem;\r
+import com.gitblit.models.Menu.ParameterMenuItem;\r
 import com.gitblit.models.ProjectModel;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
@@ -38,7 +41,6 @@ import com.gitblit.wicket.GitBlitWebApp;
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.GitblitRedirectException;\r
 import com.gitblit.wicket.PageRegistration;\r
-import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
 import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.FilterableRepositoryList;\r
@@ -172,7 +174,7 @@ public class ProjectPage extends DashboardPage {
 \r
                if (menu.menuItems.size() > 0) {\r
                        // Reset Filter\r
-                       menu.menuItems.add(new DropDownMenuItem(getString("gb.reset"), "p", WicketUtils.getProjectName(params)));\r
+                       menu.menuItems.add(new ParameterMenuItem(getString("gb.reset"), "p", WicketUtils.getProjectName(params)));\r
                }\r
 \r
                pages.add(menu);\r
@@ -202,8 +204,8 @@ public class ProjectPage extends DashboardPage {
                return null;\r
        }\r
 \r
-       protected List<DropDownMenuItem> getProjectsMenu() {\r
-               List<DropDownMenuItem> menu = new ArrayList<DropDownMenuItem>();\r
+       protected List<MenuItem> getProjectsMenu() {\r
+               List<MenuItem> menu = new ArrayList<MenuItem>();\r
                List<ProjectModel> projects = new ArrayList<ProjectModel>();\r
                for (ProjectModel model : getProjectModels()) {\r
                        if (!model.isUserProject()) {\r
@@ -230,11 +232,11 @@ public class ProjectPage extends DashboardPage {
                }\r
 \r
                for (ProjectModel project : projects) {\r
-                       menu.add(new DropDownMenuItem(project.getDisplayName(), "p", project.name));\r
+                       menu.add(new ParameterMenuItem(project.getDisplayName(), "p", project.name));\r
                }\r
                if (showAllProjects) {\r
-                       menu.add(new DropDownMenuItem());\r
-                       menu.add(new DropDownMenuItem("all projects", null, null));\r
+                       menu.add(new MenuDivider());\r
+                       menu.add(new ParameterMenuItem("all projects"));\r
                }\r
                return menu;\r
        }\r
index 77d4984693126ab1cc028633c42b370ab3290545..c404ae6146d28318c16b65b70ac852d0d5a4c601 100644 (file)
@@ -24,10 +24,10 @@ import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
 \r
 import com.gitblit.Keys;\r
+import com.gitblit.models.Menu.ParameterMenuItem;\r
 import com.gitblit.models.ProjectModel;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.PageRegistration;\r
-import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
 import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.LinkPanel;\r
@@ -128,7 +128,7 @@ public class ProjectsPage extends RootPage {
 \r
                if (menu.menuItems.size() > 0) {\r
                        // Reset Filter\r
-                       menu.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));\r
+                       menu.menuItems.add(new ParameterMenuItem(getString("gb.reset")));\r
                }\r
 \r
                pages.add(menu);\r
index f4ddf40286602ea0458a3a93c2c574db1aaae0f8..41fe057c0638113833c92c780d9f5d3b29569682 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.wicket.markup.html.basic.Label;
 import org.eclipse.jgit.lib.Constants;\r
 \r
 import com.gitblit.Keys;\r
+import com.gitblit.models.Menu.ParameterMenuItem;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.MarkdownUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -36,7 +37,6 @@ import com.gitblit.wicket.CacheControl;
 import com.gitblit.wicket.CacheControl.LastModified;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.PageRegistration;\r
-import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
 import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.RepositoriesPanel;\r
@@ -105,7 +105,7 @@ public class RepositoriesPage extends RootPage {
 \r
                if (menu.menuItems.size() > 0) {\r
                        // Reset Filter\r
-                       menu.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));\r
+                       menu.menuItems.add(new ParameterMenuItem(getString("gb.reset")));\r
                }\r
 \r
                pages.add(menu);\r
index c59c1892d00809beda3855ec3bafb5316572c2c3..b9055c13711109da79fdc849c695e6fde8aeae51 100644 (file)
@@ -47,6 +47,12 @@ import org.apache.wicket.protocol.http.WebResponse;
 \r
 import com.gitblit.Constants;\r
 import com.gitblit.Keys;\r
+import com.gitblit.extensions.AdminMenuExtension;\r
+import com.gitblit.models.Menu.MenuDivider;\r
+import com.gitblit.models.Menu.MenuItem;\r
+import com.gitblit.models.Menu.PageLinkMenuItem;\r
+import com.gitblit.models.Menu.ParameterMenuItem;\r
+import com.gitblit.models.Menu.ToggleMenuItem;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
@@ -54,8 +60,7 @@ import com.gitblit.utils.ModelUtils;
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.PageRegistration;\r
-import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
-import com.gitblit.wicket.PageRegistration.DropDownToggleItem;\r
+import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
 import com.gitblit.wicket.SessionlessForm;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.GravatarImage;\r
@@ -164,9 +169,6 @@ public abstract class RootPage extends BasePage {
                        add(new Label("userPanel").setVisible(false));\r
                }\r
 \r
-               boolean showRegistrations = app().federation().canFederate()\r
-                               && app().settings().getBoolean(Keys.web.showFederationRegistrations, false);\r
-\r
                // navigation links\r
                List<PageRegistration> pages = new ArrayList<PageRegistration>();\r
                if (!authenticateView || (authenticateView && isLoggedIn)) {\r
@@ -181,11 +183,29 @@ public abstract class RootPage extends BasePage {
                        if (allowLucene) {\r
                                pages.add(new PageRegistration("gb.search", LuceneSearchPage.class));\r
                        }\r
+\r
+                       UserModel user = GitBlitWebSession.get().getUser();\r
+\r
                        if (showAdmin) {\r
-                               pages.add(new PageRegistration("gb.users", UsersPage.class));\r
-                       }\r
-                       if (showAdmin || showRegistrations) {\r
-                               pages.add(new PageRegistration("gb.federation", FederationPage.class));\r
+                               // admin dropdown menu\r
+                               DropDownMenuRegistration adminMenu = new DropDownMenuRegistration("gb.adminMenuItem", MyDashboardPage.class);\r
+\r
+                               adminMenu.menuItems.add(new PageLinkMenuItem(getString("gb.users"), UsersPage.class));\r
+\r
+                               boolean showRegistrations = app().federation().canFederate()\r
+                                               && app().settings().getBoolean(Keys.web.showFederationRegistrations, false);\r
+                               if (showRegistrations) {\r
+                                       adminMenu.menuItems.add(new PageLinkMenuItem(getString("gb.federation"), FederationPage.class));\r
+                               }\r
+\r
+                               // allow plugins to contribute admin menu items\r
+                               List<AdminMenuExtension> extensions = app().plugins().getExtensions(AdminMenuExtension.class);\r
+                               for (AdminMenuExtension ext : extensions) {\r
+                                       adminMenu.menuItems.add(new MenuDivider());\r
+                                       adminMenu.menuItems.addAll(ext.getMenuItems(user));\r
+                               }\r
+\r
+                               pages.add(adminMenu);\r
                        }\r
 \r
                        if (!authenticateView || (authenticateView && isLoggedIn)) {\r
@@ -289,9 +309,9 @@ public abstract class RootPage extends BasePage {
 \r
        }\r
 \r
-       protected List<DropDownMenuItem> getRepositoryFilterItems(PageParameters params) {\r
+       protected List<com.gitblit.models.Menu.MenuItem> getRepositoryFilterItems(PageParameters params) {\r
                final UserModel user = GitBlitWebSession.get().getUser();\r
-               Set<DropDownMenuItem> filters = new LinkedHashSet<DropDownMenuItem>();\r
+               Set<MenuItem> filters = new LinkedHashSet<MenuItem>();\r
                List<RepositoryModel> repositories = getRepositoryModels();\r
 \r
                // accessible repositories by federation set\r
@@ -310,11 +330,11 @@ public abstract class RootPage extends BasePage {
                        List<String> sets = new ArrayList<String>(setMap.keySet());\r
                        Collections.sort(sets);\r
                        for (String set : sets) {\r
-                               filters.add(new DropDownToggleItem(MessageFormat.format("{0} ({1})", set,\r
+                               filters.add(new ToggleMenuItem(MessageFormat.format("{0} ({1})", set,\r
                                                setMap.get(set).get()), "set", set, params));\r
                        }\r
                        // divider\r
-                       filters.add(new DropDownMenuItem());\r
+                       filters.add(new MenuDivider());\r
                }\r
 \r
                // user's team memberships\r
@@ -322,11 +342,11 @@ public abstract class RootPage extends BasePage {
                        List<TeamModel> teams = new ArrayList<TeamModel>(user.teams);\r
                        Collections.sort(teams);\r
                        for (TeamModel team : teams) {\r
-                               filters.add(new DropDownToggleItem(MessageFormat.format("{0} ({1})", team.name,\r
+                               filters.add(new ToggleMenuItem(MessageFormat.format("{0} ({1})", team.name,\r
                                                team.repositories.size()), "team", team.name, params));\r
                        }\r
                        // divider\r
-                       filters.add(new DropDownMenuItem());\r
+                       filters.add(new MenuDivider());\r
                }\r
 \r
                // custom filters\r
@@ -337,18 +357,18 @@ public abstract class RootPage extends BasePage {
                        for (String expression : expressions) {\r
                                if (!StringUtils.isEmpty(expression)) {\r
                                        addedExpression = true;\r
-                                       filters.add(new DropDownToggleItem(null, "x", expression, params));\r
+                                       filters.add(new ToggleMenuItem(null, "x", expression, params));\r
                                }\r
                        }\r
                        // if we added any custom expressions, add a divider\r
                        if (addedExpression) {\r
-                               filters.add(new DropDownMenuItem());\r
+                               filters.add(new MenuDivider());\r
                        }\r
                }\r
-               return new ArrayList<DropDownMenuItem>(filters);\r
+               return new ArrayList<MenuItem>(filters);\r
        }\r
 \r
-       protected List<DropDownMenuItem> getTimeFilterItems(PageParameters params) {\r
+       protected List<MenuItem> getTimeFilterItems(PageParameters params) {\r
                // days back choices - additive parameters\r
                int daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);\r
                int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);\r
@@ -369,7 +389,7 @@ public abstract class RootPage extends BasePage {
                        clonedParams.put("db",  daysBack);\r
                }\r
 \r
-               List<DropDownMenuItem> items = new ArrayList<DropDownMenuItem>();\r
+               List<MenuItem> items = new ArrayList<MenuItem>();\r
                Set<Integer> choicesSet = new TreeSet<Integer>(app().settings().getIntegers(Keys.web.activityDurationChoices));\r
                if (choicesSet.isEmpty()) {\r
                         choicesSet.addAll(Arrays.asList(1, 3, 7, 14, 21, 28));\r
@@ -379,13 +399,13 @@ public abstract class RootPage extends BasePage {
                String lastDaysPattern = getString("gb.lastNDays");\r
                for (Integer db : choices) {\r
                        if (db == 1) {\r
-                               items.add(new DropDownMenuItem(getString("gb.time.today"), "db", db.toString(), clonedParams));\r
+                               items.add(new ParameterMenuItem(getString("gb.time.today"), "db", db.toString(), clonedParams));\r
                        } else {\r
                                String txt = MessageFormat.format(lastDaysPattern, db);\r
-                               items.add(new DropDownMenuItem(txt, "db", db.toString(), clonedParams));\r
+                               items.add(new ParameterMenuItem(txt, "db", db.toString(), clonedParams));\r
                        }\r
                }\r
-               items.add(new DropDownMenuItem());\r
+               items.add(new MenuDivider());\r
                return items;\r
        }\r
 \r
index a5d38d16c7392c2b12d72e15636dcf469b16ce0d..0767621c8cb0108b67665c107504a3cfeeabcf0e 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider;
 import org.eclipse.jgit.lib.PersonIdent;\r
 \r
 import com.gitblit.Keys;\r
+import com.gitblit.models.Menu.ParameterMenuItem;\r
 import com.gitblit.models.ProjectModel;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
@@ -37,7 +38,6 @@ import com.gitblit.wicket.GitBlitWebApp;
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.GitblitRedirectException;\r
 import com.gitblit.wicket.PageRegistration;\r
-import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
 import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.GravatarImage;\r
@@ -140,7 +140,7 @@ public class UserPage extends RootPage {
 \r
                if (menu.menuItems.size() > 0) {\r
                        // Reset Filter\r
-                       menu.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));\r
+                       menu.menuItems.add(new ParameterMenuItem(getString("gb.reset")));\r
                }\r
 \r
                pages.add(menu);\r
index d1a632e278a80c1a0553a95ec9c34d927792b48b..f561143d38733293f054a604b7af76bb223ed1f3 100644 (file)
@@ -21,7 +21,11 @@ import org.apache.wicket.markup.repeater.Item;
 import org.apache.wicket.markup.repeater.data.DataView;\r
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
 \r
-import com.gitblit.wicket.PageRegistration.DropDownMenuItem;\r
+import com.gitblit.models.Menu.MenuDivider;\r
+import com.gitblit.models.Menu.ExternalLinkMenuItem;\r
+import com.gitblit.models.Menu.MenuItem;\r
+import com.gitblit.models.Menu.PageLinkMenuItem;\r
+import com.gitblit.models.Menu.ParameterMenuItem;\r
 import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
@@ -33,26 +37,39 @@ public class DropDownMenu extends Panel {
                super(id);\r
 \r
                add(new Label("label", label).setRenderBodyOnly(true));\r
-               ListDataProvider<DropDownMenuItem> items = new ListDataProvider<DropDownMenuItem>(\r
+               ListDataProvider<MenuItem> items = new ListDataProvider<MenuItem>(\r
                                menu.menuItems);\r
-               DataView<DropDownMenuItem> view = new DataView<DropDownMenuItem>("menuItems", items) {\r
+               DataView<MenuItem> view = new DataView<MenuItem>("menuItems", items) {\r
                        private static final long serialVersionUID = 1L;\r
 \r
                        @Override\r
-                       public void populateItem(final Item<DropDownMenuItem> item) {\r
-                               DropDownMenuItem entry = item.getModelObject();\r
-                               if (entry.isDivider()) {\r
+                       public void populateItem(final Item<MenuItem> item) {\r
+                               MenuItem entry = item.getModelObject();\r
+                               if (entry instanceof PageLinkMenuItem) {\r
+                                       // link to another Wicket page\r
+                                       PageLinkMenuItem pageLink = (PageLinkMenuItem) entry;\r
+                                       item.add(new LinkPanel("menuItem", null, null, pageLink.toString(), pageLink.getPageClass(),\r
+                                                       pageLink.getPageParameters(), false).setRenderBodyOnly(true));\r
+                               } else if (entry instanceof ExternalLinkMenuItem) {\r
+                                       // link to a specified href\r
+                                       ExternalLinkMenuItem extLink = (ExternalLinkMenuItem) entry;\r
+                                       item.add(new LinkPanel("menuItem", null, extLink.toString(), extLink.getHref(),\r
+                                                       extLink.openInNewWindow()).setRenderBodyOnly(true));\r
+                               } else if (entry instanceof MenuDivider) {\r
+                                       // divider\r
                                        item.add(new Label("menuItem").setRenderBodyOnly(true));\r
                                        WicketUtils.setCssClass(item, "divider");\r
                                } else {\r
+                                       ParameterMenuItem parameter = (ParameterMenuItem) entry;\r
+                                       // parameter link for the current page\r
                                        String icon = null;\r
-                                       if (entry.isSelected()) {\r
+                                       if (parameter.isSelected()) {\r
                                                icon = "icon-ok";\r
                                        } else {\r
                                                icon = "icon-ok-white";\r
                                        }\r
                                        item.add(new LinkPanel("menuItem", icon, null, entry.toString(), menu.pageClass,\r
-                                                       entry.getPageParameters(), false).setRenderBodyOnly(true));\r
+                                                       parameter.getPageParameters(), false).setRenderBodyOnly(true));\r
                                }\r
                        }\r
                };\r
index e8b53d11914391e6bb06d84fca1cbd8967eb7bc9..684373e0f9b01fd7d6e7eb1d84ae933bd30bba78 100644 (file)
@@ -205,3 +205,29 @@ public class MyRequestFilter extends HttpRequestFilter {
 }
 ```
 
+### Admin Menu Items
+
+*SINCE 1.6.0*
+
+You can provide your own admin menu items by subclassing the *AdminMenuExtension* class.
+
+```java
+import java.util.Arrays;
+import java.util.List;
+import ro.fortsoft.pf4j.Extension;
+import com.gitblit.extensions.AdminMenuExtension;
+import com.gitblit.models.Menu.ExternalLinkMenuItem;
+import com.gitblit.models.Menu.MenuItem;
+import com.gitblit.models.UserModel;
+
+@Extension
+public class MyAdminMenuContributor extends AdminMenuExtension {
+
+    @Override
+    public List<MenuItem> getMenuItems(UserModel user) {
+        return Arrays.asList((MenuItem) new ExternalLinkMenuItem("Github", String.format("https://github.com/%s", user.username));
+    }
+}
+```
+
+