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 |
|
77c38a
|
18 |
import java.io.OutputStream;
|
PM |
19 |
import java.util.concurrent.Callable;
|
|
20 |
|
8198d2
|
21 |
import org.apache.wicket.Component;
|
5fe7df
|
22 |
import org.apache.wicket.PageParameters;
|
1e47ab
|
23 |
import org.apache.wicket.behavior.SimpleAttributeModifier;
|
5fe7df
|
24 |
import org.apache.wicket.markup.html.WebPage;
|
JM |
25 |
import org.apache.wicket.markup.html.basic.Label;
|
|
26 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
11924d
|
27 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
5fe7df
|
28 |
import org.apache.wicket.markup.html.link.Link;
|
JM |
29 |
import org.apache.wicket.markup.html.panel.Panel;
|
|
30 |
import org.apache.wicket.model.IModel;
|
|
31 |
import org.apache.wicket.model.Model;
|
77c38a
|
32 |
import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
|
PM |
33 |
import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
|
|
34 |
import org.apache.wicket.util.resource.IResourceStream;
|
5fe7df
|
35 |
|
77c38a
|
36 |
import com.gitblit.models.UserModel;
|
3cc6e2
|
37 |
import com.gitblit.utils.StringUtils;
|
77c38a
|
38 |
import com.gitblit.wicket.GitBlitWebSession;
|
3cc6e2
|
39 |
import com.gitblit.wicket.WicketUtils;
|
JM |
40 |
|
5fe7df
|
41 |
public class LinkPanel extends Panel {
|
JM |
42 |
|
|
43 |
private static final long serialVersionUID = 1L;
|
|
44 |
|
1e47ab
|
45 |
private final IModel<String> labelModel;
|
5fe7df
|
46 |
|
2a7306
|
47 |
public LinkPanel(String wicketId, String linkCssClass, String label,
|
JM |
48 |
Class<? extends WebPage> clazz) {
|
3cc6e2
|
49 |
this(wicketId, null, linkCssClass, new Model<String>(label), clazz, null, false);
|
87cc1e
|
50 |
}
|
2a7306
|
51 |
|
JM |
52 |
public LinkPanel(String wicketId, String linkCssClass, String label,
|
|
53 |
Class<? extends WebPage> clazz, PageParameters parameters) {
|
3cc6e2
|
54 |
this(wicketId, null, linkCssClass, new Model<String>(label), clazz, parameters, false);
|
797322
|
55 |
}
|
JM |
56 |
|
|
57 |
public LinkPanel(String wicketId, String linkCssClass, String label,
|
|
58 |
Class<? extends WebPage> clazz, PageParameters parameters, boolean newWindow) {
|
3cc6e2
|
59 |
this(wicketId, null, linkCssClass, new Model<String>(label), clazz, parameters, newWindow);
|
JM |
60 |
}
|
|
61 |
|
|
62 |
public LinkPanel(String wicketId, String bootstrapIcon, String linkCssClass, String label,
|
|
63 |
Class<? extends WebPage> clazz, PageParameters parameters, boolean newWindow) {
|
|
64 |
this(wicketId, bootstrapIcon, linkCssClass, new Model<String>(label), clazz, parameters, newWindow);
|
1e47ab
|
65 |
}
|
JM |
66 |
|
2a7306
|
67 |
public LinkPanel(String wicketId, String linkCssClass, IModel<String> model,
|
JM |
68 |
Class<? extends WebPage> clazz, PageParameters parameters) {
|
3cc6e2
|
69 |
this(wicketId, null, linkCssClass, model, clazz, parameters, false);
|
797322
|
70 |
}
|
JM |
71 |
|
3cc6e2
|
72 |
public LinkPanel(String wicketId, String bootstrapIcon, String linkCssClass, IModel<String> model,
|
797322
|
73 |
Class<? extends WebPage> clazz, PageParameters parameters, boolean newWindow) {
|
5fe7df
|
74 |
super(wicketId);
|
1e47ab
|
75 |
this.labelModel = model;
|
JM |
76 |
Link<Void> link = null;
|
5fe7df
|
77 |
if (parameters == null) {
|
1e47ab
|
78 |
link = new BookmarkablePageLink<Void>("link", clazz);
|
5fe7df
|
79 |
} else {
|
1e47ab
|
80 |
link = new BookmarkablePageLink<Void>("link", clazz, parameters);
|
5fe7df
|
81 |
}
|
797322
|
82 |
if (newWindow) {
|
JM |
83 |
link.add(new SimpleAttributeModifier("target", "_blank"));
|
|
84 |
}
|
5fe7df
|
85 |
if (linkCssClass != null) {
|
1e47ab
|
86 |
link.add(new SimpleAttributeModifier("class", linkCssClass));
|
3cc6e2
|
87 |
}
|
JM |
88 |
Label icon = new Label("icon");
|
|
89 |
if (StringUtils.isEmpty(bootstrapIcon)) {
|
|
90 |
link.add(icon.setVisible(false));
|
|
91 |
} else {
|
|
92 |
WicketUtils.setCssClass(icon, bootstrapIcon);
|
|
93 |
link.add(icon);
|
155bf7
|
94 |
}
|
62cec2
|
95 |
link.add(new Label("label", labelModel).setRenderBodyOnly(true));
|
5fe7df
|
96 |
add(link);
|
JM |
97 |
}
|
|
98 |
|
11924d
|
99 |
public LinkPanel(String wicketId, String linkCssClass, String label, String href) {
|
JM |
100 |
this(wicketId, linkCssClass, label, href, false);
|
|
101 |
}
|
|
102 |
|
|
103 |
public LinkPanel(String wicketId, String linkCssClass, String label, String href,
|
|
104 |
boolean newWindow) {
|
|
105 |
super(wicketId);
|
|
106 |
this.labelModel = new Model<String>(label);
|
|
107 |
ExternalLink link = new ExternalLink("link", href);
|
|
108 |
if (newWindow) {
|
|
109 |
link.add(new SimpleAttributeModifier("target", "_blank"));
|
|
110 |
}
|
|
111 |
if (linkCssClass != null) {
|
|
112 |
link.add(new SimpleAttributeModifier("class", linkCssClass));
|
|
113 |
}
|
3cc6e2
|
114 |
link.add(new Label("icon").setVisible(false));
|
11924d
|
115 |
link.add(new Label("label", labelModel));
|
JM |
116 |
add(link);
|
|
117 |
}
|
699e71
|
118 |
|
77c38a
|
119 |
public LinkPanel(String wicketId, String linkCssClass, String label, Link<?> link) {
|
PM |
120 |
super(wicketId);
|
|
121 |
|
|
122 |
this.labelModel = new Model<String>(label);
|
|
123 |
|
|
124 |
if (linkCssClass != null) {
|
|
125 |
link.add(new SimpleAttributeModifier("class", linkCssClass));
|
|
126 |
}
|
|
127 |
|
|
128 |
link.add(new Label("icon").setVisible(false));
|
|
129 |
link.add(new Label("label", labelModel));
|
|
130 |
add(link);
|
|
131 |
}
|
|
132 |
|
8198d2
|
133 |
public void setNoFollow() {
|
JM |
134 |
Component c = get("link");
|
|
135 |
c.add(new SimpleAttributeModifier("rel", "nofollow"));
|
|
136 |
}
|
11924d
|
137 |
|
51ef46
|
138 |
public void setTooltip(String tooltip) {
|
JM |
139 |
Component c = get("link");
|
|
140 |
c.add(new SimpleAttributeModifier("title", tooltip));
|
|
141 |
}
|
|
142 |
|
5fe7df
|
143 |
}
|