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.text.MessageFormat;
19 import java.util.List;
20
21 import org.apache.wicket.Component;
22 import org.apache.wicket.markup.html.basic.Label;
23 import org.apache.wicket.markup.html.link.Link;
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.FederationProposal;
30 import com.gitblit.wicket.WicketUtils;
dd9ae7 31 import com.gitblit.wicket.pages.ReviewProposalPage;
831469 32
JM 33 public class FederationProposalsPanel extends BasePanel {
34
35     private static final long serialVersionUID = 1L;
36
37     private final boolean hasProposals;
38
39     public FederationProposalsPanel(String wicketId) {
40         super(wicketId);
41
42         final List<FederationProposal> list = GitBlit.self().getPendingFederationProposals();
43         hasProposals = list.size() > 0;
44         DataView<FederationProposal> dataView = new DataView<FederationProposal>("row",
45                 new ListDataProvider<FederationProposal>(list)) {
46             private static final long serialVersionUID = 1L;
47             private int counter;
48
49             @Override
50             protected void onBeforeRender() {
51                 super.onBeforeRender();
52                 counter = 0;
53             }
54
55             public void populateItem(final Item<FederationProposal> item) {
56                 final FederationProposal entry = item.getModelObject();
dd9ae7 57                 item.add(new LinkPanel("url", "list", entry.url, ReviewProposalPage.class,
831469 58                         WicketUtils.newTokenParameter(entry.token)));
JM 59                 item.add(WicketUtils.createDateLabel("received", entry.received, getTimeZone()));
60                 item.add(new Label("tokenType", entry.tokenType.name()));
dd9ae7 61                 item.add(new LinkPanel("token", "list", entry.token, ReviewProposalPage.class,
831469 62                         WicketUtils.newTokenParameter(entry.token)));
JM 63
64                 Link<Void> deleteLink = new Link<Void>("deleteProposal") {
65
66                     private static final long serialVersionUID = 1L;
67
68                     @Override
69                     public void onClick() {
70                         if (GitBlit.self().deletePendingFederationProposal(entry)) {
71                             list.remove(entry);
72                             info(MessageFormat.format("Proposal ''{0}'' deleted.", entry.name));
73                         } else {
74                             error(MessageFormat.format("Failed to delete proposal ''{0}''!",
75                                     entry.name));
76                         }
77                     }
78                 };
79                 deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
80                         "Delete proposal \"{0}\"?", entry.name)));
81                 item.add(deleteLink);
82                 WicketUtils.setAlternatingBackground(item, counter);
83                 counter++;
84             }
85         };
86         add(dataView);
87     }
88
89     public Component hideIfEmpty() {
90         return super.setVisible(hasProposals);
91     }
92 }