commit | author | age
|
9e5bee
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
package com.gitblit.wicket;
|
|
17 |
|
|
18 |
import java.io.Serializable;
|
31bcbe
|
19 |
import java.util.ArrayList;
|
JM |
20 |
import java.util.List;
|
9e5bee
|
21 |
|
JM |
22 |
import org.apache.wicket.PageParameters;
|
31bcbe
|
23 |
import org.apache.wicket.markup.html.WebPage;
|
9e5bee
|
24 |
|
31bcbe
|
25 |
import com.gitblit.utils.StringUtils;
|
9e5bee
|
26 |
|
JM |
27 |
/**
|
|
28 |
* Represents a page link registration for the topbar.
|
|
29 |
*
|
|
30 |
* @author James Moger
|
|
31 |
*
|
|
32 |
*/
|
|
33 |
public class PageRegistration implements Serializable {
|
|
34 |
private static final long serialVersionUID = 1L;
|
|
35 |
|
|
36 |
public final String translationKey;
|
31bcbe
|
37 |
public final Class<? extends WebPage> pageClass;
|
9e5bee
|
38 |
public final PageParameters params;
|
JM |
39 |
|
31bcbe
|
40 |
public PageRegistration(String translationKey, Class<? extends WebPage> pageClass) {
|
9e5bee
|
41 |
this(translationKey, pageClass, null);
|
JM |
42 |
}
|
|
43 |
|
31bcbe
|
44 |
public PageRegistration(String translationKey, Class<? extends WebPage> pageClass,
|
9e5bee
|
45 |
PageParameters params) {
|
JM |
46 |
this.translationKey = translationKey;
|
|
47 |
this.pageClass = pageClass;
|
|
48 |
this.params = params;
|
|
49 |
}
|
31bcbe
|
50 |
|
JM |
51 |
/**
|
|
52 |
* Represents a DropDownMenu for the topbar
|
|
53 |
*
|
|
54 |
* @author James Moger
|
|
55 |
*
|
|
56 |
*/
|
|
57 |
public static class DropDownMenuRegistration extends PageRegistration {
|
|
58 |
|
|
59 |
private static final long serialVersionUID = 1L;
|
|
60 |
|
|
61 |
public final List<DropDownMenuItem> menuItems;
|
|
62 |
|
|
63 |
public DropDownMenuRegistration(String translationKey, Class<? extends WebPage> pageClass) {
|
|
64 |
super(translationKey, pageClass);
|
|
65 |
menuItems = new ArrayList<DropDownMenuItem>();
|
|
66 |
}
|
|
67 |
}
|
|
68 |
|
|
69 |
/**
|
|
70 |
* A MenuItem for the DropDownMenu.
|
|
71 |
*
|
|
72 |
* @author James Moger
|
|
73 |
*
|
|
74 |
*/
|
|
75 |
public static class DropDownMenuItem implements Serializable {
|
|
76 |
|
|
77 |
private static final long serialVersionUID = 1L;
|
|
78 |
|
|
79 |
final String displayText;
|
|
80 |
final String parameter;
|
|
81 |
final String value;
|
|
82 |
|
|
83 |
/**
|
|
84 |
* Divider constructor.
|
|
85 |
*/
|
|
86 |
public DropDownMenuItem() {
|
|
87 |
displayText = null;
|
|
88 |
parameter = null;
|
|
89 |
value = null;
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Standard Menu Item constructor.
|
|
94 |
*
|
|
95 |
* @param displayText
|
|
96 |
* @param parameter
|
|
97 |
* @param value
|
|
98 |
*/
|
|
99 |
public DropDownMenuItem(String displayText, String parameter, String value) {
|
|
100 |
this.displayText = displayText;
|
|
101 |
this.parameter = parameter;
|
|
102 |
this.value = value;
|
|
103 |
}
|
|
104 |
|
|
105 |
public String formatParameter() {
|
|
106 |
if (StringUtils.isEmpty(parameter) || StringUtils.isEmpty(value)) {
|
|
107 |
return "";
|
|
108 |
}
|
|
109 |
return parameter + "=" + value;
|
|
110 |
}
|
|
111 |
|
|
112 |
public boolean isDivider() {
|
|
113 |
return displayText == null && value == null && parameter == null;
|
|
114 |
}
|
|
115 |
|
|
116 |
@Override
|
|
117 |
public int hashCode() {
|
|
118 |
if (isDivider()) {
|
|
119 |
// divider menu item
|
|
120 |
return super.hashCode();
|
|
121 |
}
|
|
122 |
if (StringUtils.isEmpty(displayText)) {
|
|
123 |
return value.hashCode() + parameter.hashCode();
|
|
124 |
}
|
|
125 |
return displayText.hashCode();
|
|
126 |
}
|
|
127 |
|
|
128 |
@Override
|
|
129 |
public boolean equals(Object o) {
|
|
130 |
if (o instanceof DropDownMenuItem) {
|
|
131 |
return hashCode() == o.hashCode();
|
|
132 |
}
|
|
133 |
return false;
|
|
134 |
}
|
|
135 |
|
|
136 |
@Override
|
|
137 |
public String toString() {
|
|
138 |
if (StringUtils.isEmpty(displayText)) {
|
|
139 |
return formatParameter();
|
|
140 |
}
|
|
141 |
return displayText;
|
|
142 |
}
|
|
143 |
}
|
9e5bee
|
144 |
} |