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.panels;
|
|
17 |
|
|
18 |
import java.util.List;
|
|
19 |
|
|
20 |
import org.apache.wicket.Component;
|
|
21 |
import org.apache.wicket.markup.html.panel.Panel;
|
|
22 |
import org.apache.wicket.markup.repeater.Item;
|
|
23 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
24 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
25 |
|
|
26 |
import com.gitblit.wicket.PageRegistration;
|
31bcbe
|
27 |
import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;
|
9e5bee
|
28 |
import com.gitblit.wicket.WicketUtils;
|
JM |
29 |
import com.gitblit.wicket.pages.BasePage;
|
|
30 |
|
|
31 |
public class NavigationPanel extends Panel {
|
|
32 |
|
|
33 |
private static final long serialVersionUID = 1L;
|
|
34 |
|
31bcbe
|
35 |
public NavigationPanel(String id, final Class<? extends BasePage> pageClass,
|
JM |
36 |
List<PageRegistration> registeredPages) {
|
9e5bee
|
37 |
super(id);
|
31bcbe
|
38 |
|
JM |
39 |
ListDataProvider<PageRegistration> refsDp = new ListDataProvider<PageRegistration>(
|
|
40 |
registeredPages);
|
9e5bee
|
41 |
DataView<PageRegistration> refsView = new DataView<PageRegistration>("navLink", refsDp) {
|
JM |
42 |
private static final long serialVersionUID = 1L;
|
|
43 |
|
|
44 |
public void populateItem(final Item<PageRegistration> item) {
|
|
45 |
PageRegistration entry = item.getModelObject();
|
31bcbe
|
46 |
if (entry instanceof DropDownMenuRegistration) {
|
JM |
47 |
// drop down menu
|
|
48 |
DropDownMenuRegistration reg = (DropDownMenuRegistration) entry;
|
|
49 |
Component c = new DropDownMenu("link", getString(entry.translationKey), reg);
|
|
50 |
item.add(c);
|
|
51 |
WicketUtils.setCssClass(item, "menu");
|
|
52 |
} else {
|
|
53 |
// standard page link
|
|
54 |
Component c = new LinkPanel("link", null, getString(entry.translationKey),
|
|
55 |
entry.pageClass, entry.params);
|
|
56 |
if (entry.pageClass.equals(pageClass)) {
|
|
57 |
WicketUtils.setCssClass(item, "active");
|
|
58 |
}
|
|
59 |
item.add(c);
|
9e5bee
|
60 |
}
|
JM |
61 |
}
|
|
62 |
};
|
|
63 |
add(refsView);
|
|
64 |
}
|
|
65 |
} |