| | |
| | | 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.
|
| | |
| | | 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;
|
| | | }
|
| | | }
|
| | | } |