commit | author | age
|
f13c4c
|
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 |
*/
|
1f9dae
|
16 |
package com.gitblit.wicket.panels;
|
5fe7df
|
17 |
|
JM |
18 |
import org.apache.wicket.PageParameters;
|
1e47ab
|
19 |
import org.apache.wicket.behavior.SimpleAttributeModifier;
|
5fe7df
|
20 |
import org.apache.wicket.markup.html.WebPage;
|
JM |
21 |
import org.apache.wicket.markup.html.basic.Label;
|
|
22 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
11924d
|
23 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
5fe7df
|
24 |
import org.apache.wicket.markup.html.link.Link;
|
JM |
25 |
import org.apache.wicket.markup.html.panel.Panel;
|
|
26 |
import org.apache.wicket.model.IModel;
|
|
27 |
import org.apache.wicket.model.Model;
|
|
28 |
|
3cc6e2
|
29 |
import com.gitblit.utils.StringUtils;
|
JM |
30 |
import com.gitblit.wicket.WicketUtils;
|
|
31 |
|
5fe7df
|
32 |
public class LinkPanel extends Panel {
|
JM |
33 |
|
|
34 |
private static final long serialVersionUID = 1L;
|
|
35 |
|
1e47ab
|
36 |
private final IModel<String> labelModel;
|
5fe7df
|
37 |
|
2a7306
|
38 |
public LinkPanel(String wicketId, String linkCssClass, String label,
|
JM |
39 |
Class<? extends WebPage> clazz) {
|
3cc6e2
|
40 |
this(wicketId, null, linkCssClass, new Model<String>(label), clazz, null, false);
|
87cc1e
|
41 |
}
|
2a7306
|
42 |
|
JM |
43 |
public LinkPanel(String wicketId, String linkCssClass, String label,
|
|
44 |
Class<? extends WebPage> clazz, PageParameters parameters) {
|
3cc6e2
|
45 |
this(wicketId, null, linkCssClass, new Model<String>(label), clazz, parameters, false);
|
797322
|
46 |
}
|
JM |
47 |
|
|
48 |
public LinkPanel(String wicketId, String linkCssClass, String label,
|
|
49 |
Class<? extends WebPage> clazz, PageParameters parameters, boolean newWindow) {
|
3cc6e2
|
50 |
this(wicketId, null, linkCssClass, new Model<String>(label), clazz, parameters, newWindow);
|
JM |
51 |
}
|
|
52 |
|
|
53 |
public LinkPanel(String wicketId, String bootstrapIcon, String linkCssClass, String label,
|
|
54 |
Class<? extends WebPage> clazz, PageParameters parameters, boolean newWindow) {
|
|
55 |
this(wicketId, bootstrapIcon, linkCssClass, new Model<String>(label), clazz, parameters, newWindow);
|
1e47ab
|
56 |
}
|
JM |
57 |
|
2a7306
|
58 |
public LinkPanel(String wicketId, String linkCssClass, IModel<String> model,
|
JM |
59 |
Class<? extends WebPage> clazz, PageParameters parameters) {
|
3cc6e2
|
60 |
this(wicketId, null, linkCssClass, model, clazz, parameters, false);
|
797322
|
61 |
}
|
JM |
62 |
|
3cc6e2
|
63 |
public LinkPanel(String wicketId, String bootstrapIcon, String linkCssClass, IModel<String> model,
|
797322
|
64 |
Class<? extends WebPage> clazz, PageParameters parameters, boolean newWindow) {
|
5fe7df
|
65 |
super(wicketId);
|
1e47ab
|
66 |
this.labelModel = model;
|
JM |
67 |
Link<Void> link = null;
|
5fe7df
|
68 |
if (parameters == null) {
|
1e47ab
|
69 |
link = new BookmarkablePageLink<Void>("link", clazz);
|
5fe7df
|
70 |
} else {
|
1e47ab
|
71 |
link = new BookmarkablePageLink<Void>("link", clazz, parameters);
|
5fe7df
|
72 |
}
|
797322
|
73 |
if (newWindow) {
|
JM |
74 |
link.add(new SimpleAttributeModifier("target", "_blank"));
|
|
75 |
}
|
5fe7df
|
76 |
if (linkCssClass != null) {
|
1e47ab
|
77 |
link.add(new SimpleAttributeModifier("class", linkCssClass));
|
3cc6e2
|
78 |
}
|
JM |
79 |
Label icon = new Label("icon");
|
|
80 |
if (StringUtils.isEmpty(bootstrapIcon)) {
|
|
81 |
link.add(icon.setVisible(false));
|
|
82 |
} else {
|
|
83 |
WicketUtils.setCssClass(icon, bootstrapIcon);
|
|
84 |
link.add(icon);
|
155bf7
|
85 |
}
|
62cec2
|
86 |
link.add(new Label("label", labelModel).setRenderBodyOnly(true));
|
5fe7df
|
87 |
add(link);
|
JM |
88 |
}
|
|
89 |
|
11924d
|
90 |
public LinkPanel(String wicketId, String linkCssClass, String label, String href) {
|
JM |
91 |
this(wicketId, linkCssClass, label, href, false);
|
|
92 |
}
|
|
93 |
|
|
94 |
public LinkPanel(String wicketId, String linkCssClass, String label, String href,
|
|
95 |
boolean newWindow) {
|
|
96 |
super(wicketId);
|
|
97 |
this.labelModel = new Model<String>(label);
|
|
98 |
ExternalLink link = new ExternalLink("link", href);
|
|
99 |
if (newWindow) {
|
|
100 |
link.add(new SimpleAttributeModifier("target", "_blank"));
|
|
101 |
}
|
|
102 |
if (linkCssClass != null) {
|
|
103 |
link.add(new SimpleAttributeModifier("class", linkCssClass));
|
|
104 |
}
|
3cc6e2
|
105 |
link.add(new Label("icon").setVisible(false));
|
11924d
|
106 |
link.add(new Label("label", labelModel));
|
JM |
107 |
add(link);
|
|
108 |
}
|
|
109 |
|
5fe7df
|
110 |
}
|