James Moger
2011-11-18 309c55b5a9670e7c327ad8d4e5d94b8af840d00f
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;
27 import com.gitblit.wicket.WicketUtils;
28 import com.gitblit.wicket.pages.BasePage;
29
30 public class NavigationPanel extends Panel {
31
32     private static final long serialVersionUID = 1L;
33
34     public NavigationPanel(String id, final Class<? extends BasePage> pageClass, List<PageRegistration> registeredPages) {
35         super(id);
36                 
37         ListDataProvider<PageRegistration> refsDp = new ListDataProvider<PageRegistration>(registeredPages);
38         DataView<PageRegistration> refsView = new DataView<PageRegistration>("navLink", refsDp) {
39             private static final long serialVersionUID = 1L;
40
41             public void populateItem(final Item<PageRegistration> item) {
42                 PageRegistration entry = item.getModelObject();
43                 Component c = new LinkPanel("link", null, getString(entry.translationKey), entry.pageClass, entry.params);
44                 if (entry.pageClass.equals(pageClass)) {
45                     WicketUtils.setCssClass(item, "active");
46                 }
47                 item.add(c);
48             }
49         };
50         add(refsView);
51     }
52 }