From 4fc3e796b34d25899d60153f2975ead68588a105 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 27 Dec 2011 17:34:52 -0500
Subject: [PATCH] Added some descriptive subheadings to edit pages

---
 src/com/gitblit/wicket/PageRegistration.java |  105 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 101 insertions(+), 4 deletions(-)

diff --git a/src/com/gitblit/wicket/PageRegistration.java b/src/com/gitblit/wicket/PageRegistration.java
index ac00fb5..f7ddcc5 100644
--- a/src/com/gitblit/wicket/PageRegistration.java
+++ b/src/com/gitblit/wicket/PageRegistration.java
@@ -16,10 +16,13 @@
 package com.gitblit.wicket;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebPage;
 
-import com.gitblit.wicket.pages.BasePage;
+import com.gitblit.utils.StringUtils;
 
 /**
  * Represents a page link registration for the topbar.
@@ -31,17 +34,111 @@
 	private static final long serialVersionUID = 1L;
 
 	public final String translationKey;
-	public final Class<? extends BasePage> pageClass;
+	public final Class<? extends WebPage> pageClass;
 	public final PageParameters params;
 
-	public PageRegistration(String translationKey, Class<? extends BasePage> pageClass) {
+	public PageRegistration(String translationKey, Class<? extends WebPage> pageClass) {
 		this(translationKey, pageClass, null);
 	}
 
-	public PageRegistration(String translationKey, Class<? extends BasePage> pageClass,
+	public PageRegistration(String translationKey, Class<? extends WebPage> pageClass,
 			PageParameters params) {
 		this.translationKey = translationKey;
 		this.pageClass = pageClass;
 		this.params = params;
 	}
+
+	/**
+	 * Represents a DropDownMenu for the topbar
+	 * 
+	 * @author James Moger
+	 * 
+	 */
+	public static class DropDownMenuRegistration extends PageRegistration {
+
+		private static final long serialVersionUID = 1L;
+
+		public final List<DropDownMenuItem> menuItems;
+
+		public DropDownMenuRegistration(String translationKey, Class<? extends WebPage> pageClass) {
+			super(translationKey, pageClass);
+			menuItems = new ArrayList<DropDownMenuItem>();
+		}
+	}
+
+	/**
+	 * A MenuItem for the DropDownMenu.
+	 * 
+	 * @author James Moger
+	 * 
+	 */
+	public static class DropDownMenuItem implements Serializable {
+
+		private static final long serialVersionUID = 1L;
+
+		final String displayText;
+		final String parameter;
+		final String value;
+
+		/**
+		 * Divider constructor.
+		 */
+		public DropDownMenuItem() {
+			displayText = null;
+			parameter = null;
+			value = null;
+		}
+
+		/**
+		 * Standard Menu Item constructor.
+		 * 
+		 * @param displayText
+		 * @param parameter
+		 * @param value
+		 */
+		public DropDownMenuItem(String displayText, String parameter, String value) {
+			this.displayText = displayText;
+			this.parameter = parameter;
+			this.value = value;
+		}
+
+		public String formatParameter() {
+			if (StringUtils.isEmpty(parameter) || StringUtils.isEmpty(value)) {
+				return "";
+			}
+			return parameter + "=" + value;
+		}
+
+		public boolean isDivider() {
+			return displayText == null && value == null && parameter == null;
+		}
+
+		@Override
+		public int hashCode() {
+			if (isDivider()) {
+				// divider menu item
+				return super.hashCode();
+			}
+			if (StringUtils.isEmpty(displayText)) {
+				return value.hashCode() + parameter.hashCode();
+			}
+			return displayText.hashCode();
+		}
+
+		@Override
+		public boolean equals(Object o) {
+			if (o instanceof DropDownMenuItem) {
+				return hashCode() == o.hashCode();
+			}
+			return false;
+		}
+
+		@Override
+		public String toString() {
+			if (StringUtils.isEmpty(displayText)) {
+				return formatParameter();
+			}
+			return displayText;
+		}
+	}
 }
\ No newline at end of file

--
Gitblit v1.9.1