--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+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;
+ }
+ }
+}
gb.overdue = overdue
gb.openMilestones = open milestones
gb.closedMilestones = closed milestones
+gb.adminMenuItem = admin
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
\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
\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
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
\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
}\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
\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
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
\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
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
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
\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
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
}\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
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
\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
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
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
\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
\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
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
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
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
\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
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
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
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
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
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
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
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
\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
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
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
}
```
+### 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));
+ }
+}
+```
+
+