James Moger
2012-10-22 eba89539a29deba954035056437279088c3e047b
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;
11924d 28 import com.gitblit.wicket.PageRegistration.OtherPageLink;
9e5bee 29 import com.gitblit.wicket.WicketUtils;
JM 30 import com.gitblit.wicket.pages.BasePage;
31
32 public class NavigationPanel extends Panel {
33
34     private static final long serialVersionUID = 1L;
35
31bcbe 36     public NavigationPanel(String id, final Class<? extends BasePage> pageClass,
JM 37             List<PageRegistration> registeredPages) {
9e5bee 38         super(id);
31bcbe 39
JM 40         ListDataProvider<PageRegistration> refsDp = new ListDataProvider<PageRegistration>(
41                 registeredPages);
9e5bee 42         DataView<PageRegistration> refsView = new DataView<PageRegistration>("navLink", refsDp) {
JM 43             private static final long serialVersionUID = 1L;
44
45             public void populateItem(final Item<PageRegistration> item) {
46                 PageRegistration entry = item.getModelObject();
11924d 47                 if (entry instanceof OtherPageLink) {
JM 48                     // other link
49                     OtherPageLink link = (OtherPageLink) entry;
50                     Component c = new LinkPanel("link", null, getString(entry.translationKey), link.url);
3cc6e2 51                     c.setRenderBodyOnly(true);
11924d 52                     item.add(c);
JM 53                 } else if (entry instanceof DropDownMenuRegistration) {
31bcbe 54                     // drop down menu
JM 55                     DropDownMenuRegistration reg = (DropDownMenuRegistration) entry;
56                     Component c = new DropDownMenu("link", getString(entry.translationKey), reg);
3cc6e2 57                     c.setRenderBodyOnly(true);
31bcbe 58                     item.add(c);
3cc6e2 59                     WicketUtils.setCssClass(item, "dropdown");
31bcbe 60                 } else {
JM 61                     // standard page link
62                     Component c = new LinkPanel("link", null, getString(entry.translationKey),
63                             entry.pageClass, entry.params);
3cc6e2 64                     c.setRenderBodyOnly(true);
31bcbe 65                     if (entry.pageClass.equals(pageClass)) {
JM 66                         WicketUtils.setCssClass(item, "active");
67                     }
68                     item.add(c);
9e5bee 69                 }
JM 70             }
71         };
72         add(refsView);
73     }
74 }