1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.contrib.link; |
16 |
|
|
17 |
|
import org.apache.hivemind.service.BodyBuilder; |
18 |
|
import org.apache.tapestry.IRequestCycle; |
19 |
|
import org.apache.tapestry.PageRenderSupport; |
20 |
|
import org.apache.tapestry.TapestryUtils; |
21 |
|
import org.apache.tapestry.components.ILinkComponent; |
22 |
|
import org.apache.tapestry.engine.ILink; |
23 |
|
import org.apache.tapestry.link.DefaultLinkRenderer; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
public class PopupLinkRenderer extends DefaultLinkRenderer |
32 |
|
{ |
33 |
|
|
34 |
|
private String _windowName; |
35 |
|
|
36 |
|
private String _features; |
37 |
|
|
38 |
|
public PopupLinkRenderer() |
39 |
0 |
{ |
40 |
0 |
} |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public PopupLinkRenderer(String windowName, String features) |
51 |
0 |
{ |
52 |
0 |
_windowName = windowName; |
53 |
0 |
_features = features; |
54 |
0 |
} |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
protected String constructURL(ILinkComponent component, IRequestCycle cycle) |
61 |
|
{ |
62 |
0 |
if (cycle.isRewinding()) { |
63 |
0 |
return null; |
64 |
|
} |
65 |
|
|
66 |
0 |
String anchor = component.getAnchor(); |
67 |
0 |
ILink link = component.getLink(cycle); |
68 |
|
|
69 |
0 |
String url = link.getURL(anchor, true); |
70 |
|
|
71 |
0 |
PageRenderSupport support = TapestryUtils.getPageRenderSupport(cycle, component); |
72 |
|
|
73 |
0 |
String functionName = support.getUniqueString("popup_window"); |
74 |
|
|
75 |
0 |
BodyBuilder builder = new BodyBuilder(); |
76 |
|
|
77 |
0 |
builder.addln("{0}=function()", functionName); |
78 |
0 |
builder.begin(); |
79 |
0 |
builder.add( |
80 |
|
"var newWindow = window.open({0}, {1}, {2});", |
81 |
|
TapestryUtils.enquote(url), |
82 |
|
TapestryUtils.enquote(getWindowName()), |
83 |
|
TapestryUtils.enquote(getFeatures())); |
84 |
0 |
builder.add("newWindow.focus();"); |
85 |
0 |
builder.end(); |
86 |
0 |
builder.addln(";"); |
87 |
|
|
88 |
0 |
support.addBodyScript(component, builder.toString()); |
89 |
|
|
90 |
0 |
return "javascript:" + functionName + "();"; |
91 |
|
} |
92 |
|
|
93 |
|
public String getWindowName() |
94 |
|
{ |
95 |
0 |
return _windowName; |
96 |
|
} |
97 |
|
|
98 |
|
public void setWindowName(String windowName) |
99 |
|
{ |
100 |
0 |
_windowName = windowName; |
101 |
0 |
} |
102 |
|
|
103 |
|
public String getFeatures() |
104 |
|
{ |
105 |
0 |
return _features; |
106 |
|
} |
107 |
|
|
108 |
|
public void setFeatures(String features) |
109 |
|
{ |
110 |
0 |
_features = features; |
111 |
0 |
} |
112 |
|
} |