James Moger
2012-02-16 3cc6e2de29a0fa33dd585e938e1614a6dd5f9755
commit | author | age
831469 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.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.apache.wicket.Component;
23 import org.apache.wicket.markup.html.basic.Label;
24 import org.apache.wicket.markup.repeater.Item;
25 import org.apache.wicket.markup.repeater.data.DataView;
26 import org.apache.wicket.markup.repeater.data.ListDataProvider;
27
28 import com.gitblit.GitBlit;
29 import com.gitblit.models.FederationModel;
30 import com.gitblit.wicket.WicketUtils;
31 import com.gitblit.wicket.pages.FederationRegistrationPage;
32
33 public class FederationRegistrationsPanel extends BasePanel {
34
35     private static final long serialVersionUID = 1L;
36
37     private final boolean hasRegistrations;
38
39     public FederationRegistrationsPanel(String wicketId) {
40         super(wicketId);
41
42         final List<FederationModel> list = new ArrayList<FederationModel>(GitBlit.self()
43                 .getFederationRegistrations());
44         list.addAll(GitBlit.self().getFederationResultRegistrations());
45         Collections.sort(list);
46         hasRegistrations = list.size() > 0;
47         DataView<FederationModel> dataView = new DataView<FederationModel>("row",
48                 new ListDataProvider<FederationModel>(list)) {
49             private static final long serialVersionUID = 1L;
50             private int counter;
51
52             @Override
53             protected void onBeforeRender() {
54                 super.onBeforeRender();
55                 counter = 0;
56             }
57
58             public void populateItem(final Item<FederationModel> item) {
59                 final FederationModel entry = item.getModelObject();
60                 item.add(new LinkPanel("url", "list", entry.url, FederationRegistrationPage.class,
61                         WicketUtils.newRegistrationParameter(entry.url, entry.name)));
62                 item.add(WicketUtils.getPullStatusImage("statusIcon", entry.getLowestStatus()));
63                 item.add(new LinkPanel("name", "list", entry.name,
64                         FederationRegistrationPage.class, WicketUtils.newRegistrationParameter(
65                                 entry.url, entry.name)));
66
67                 item.add(WicketUtils.getRegistrationImage("typeIcon", entry, this));
68
69                 item.add(WicketUtils.createDateLabel("lastPull", entry.lastPull, getTimeZone()));
70                 item.add(WicketUtils
71                         .createTimestampLabel("nextPull", entry.nextPull, getTimeZone()));
72                 item.add(new Label("frequency", entry.frequency));
73                 WicketUtils.setAlternatingBackground(item, counter);
74                 counter++;
75             }
76         };
77         add(dataView);
78     }
79
80     public Component hideIfEmpty() {
81         return super.setVisible(hasRegistrations);
82     }
83 }