1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
package org.asyrinx.brownie.tapestry.components.link;
|
9
|
|
|
10
|
|
import java.util.HashMap;
|
11
|
|
import java.util.Iterator;
|
12
|
|
import java.util.Map;
|
13
|
|
|
14
|
|
import org.apache.commons.beanutils.BeanUtils;
|
15
|
|
import org.apache.commons.beanutils.PropertyUtils;
|
16
|
|
import org.apache.tapestry.ApplicationRuntimeException;
|
17
|
|
import org.apache.tapestry.IMarkupWriter;
|
18
|
|
import org.apache.tapestry.IRequestCycle;
|
19
|
|
import org.apache.tapestry.IScript;
|
20
|
|
import org.apache.tapestry.components.ILinkComponent;
|
21
|
|
import org.apache.tapestry.html.Body;
|
22
|
|
import org.apache.tapestry.link.ILinkRenderer;
|
23
|
|
import org.asyrinx.brownie.core.collection.MapTree;
|
24
|
|
import org.asyrinx.brownie.tapestry.util.ValueTagWriter;
|
25
|
|
|
26
|
|
|
27
|
|
|
28
|
|
|
29
|
|
public class SubWindowListRowRenderer extends AbstractLinkRowRenderer {
|
30
|
|
|
31
|
|
public static final ILinkRenderer SHARED_INSTANCE = new SubWindowListRowRenderer();
|
32
|
|
|
33
|
|
|
34
|
|
|
35
|
|
|
36
|
0
|
public SubWindowListRowRenderer() {
|
37
|
0
|
super("SubWindowListRowRenderer.script");
|
38
|
|
}
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
0
|
protected void checkBeforeRender(IRequestCycle cycle,
|
45
|
|
ILinkComponent linkComponent) {
|
46
|
0
|
super.checkBeforeRender(cycle, linkComponent);
|
47
|
0
|
if (!(linkComponent instanceof ISubWindowListRow))
|
48
|
0
|
throw new ApplicationRuntimeException(
|
49
|
|
"must-be-implemented-ISubWindowListRow", this, null, null);
|
50
|
0
|
if (getParameters(linkComponent) == null)
|
51
|
0
|
throw new ApplicationRuntimeException(
|
52
|
|
"must-has-getParameters-method", this, null, null);
|
53
|
|
}
|
54
|
|
|
55
|
|
public static final String SYM_METHOD_CLICK_ROW = "clickLinkRowMethodName";
|
56
|
|
|
57
|
|
public static final String SYM_METHOD_MOSUE_OVER_ROW = "mouseOverLinkRowMethodName";
|
58
|
|
|
59
|
|
public static final String SYM_METHOD_MOSUE_OUT_ROW = "mouseOutLinkRowMethodName";
|
60
|
|
|
61
|
|
public static final String SYM_SELECT_BG_COLOR = "selectBgColor";
|
62
|
|
|
63
|
|
public static final String SYM_SELECT_STYLE_CLASS = "selectStyleClass";
|
64
|
|
|
65
|
|
public static final String SYM_RENDERER = "renderer";
|
66
|
|
|
67
|
|
private static final String SCRIPT_ADD_FLAG_KEY = DirectLinkRow.class
|
68
|
|
.getName()
|
69
|
|
+ ".added.javascript";
|
70
|
|
|
71
|
0
|
protected String getScriptId() {
|
72
|
0
|
return SCRIPT_ADD_FLAG_KEY + "." + this.hashCode();
|
73
|
|
}
|
74
|
|
|
75
|
|
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
0
|
protected void addScript(IRequestCycle cycle, IScript script, Body body) {
|
80
|
0
|
if (cycle.getAttribute(getScriptId()) != null)
|
81
|
0
|
return;
|
82
|
0
|
cycle.setAttribute(getScriptId(), new int[0]);
|
83
|
0
|
final Map symbols = new HashMap();
|
84
|
0
|
symbols.put(SYM_RENDERER, this);
|
85
|
0
|
symbols.put(SYM_METHOD_CLICK_ROW, CLICK_LINK_ROW_METHOD_NAME);
|
86
|
0
|
symbols.put(SYM_METHOD_MOSUE_OVER_ROW, MOSUE_OVER_LINK_ROW_METHOD_NAME);
|
87
|
0
|
symbols.put(SYM_METHOD_MOSUE_OUT_ROW, MOSUE_OUT_LINK_ROW_METHOD_NAME);
|
88
|
0
|
symbols.put(SYM_SELECT_BG_COLOR, getSelectBgColor());
|
89
|
0
|
symbols.put(SYM_SELECT_STYLE_CLASS, getSelectStyleClass());
|
90
|
0
|
script.execute(cycle, body, symbols);
|
91
|
|
}
|
92
|
|
|
93
|
|
|
94
|
|
|
95
|
|
|
96
|
|
|
97
|
|
|
98
|
0
|
protected void renderBody(IMarkupWriter bodyWriter, IRequestCycle cycle,
|
99
|
|
ILinkComponent linkComponent) {
|
100
|
0
|
final ISubWindowListRow subWindowListRow = (ISubWindowListRow) linkComponent;
|
101
|
0
|
final Map options = subWindowListRow.getReturnOptions();
|
102
|
0
|
final Object parameters = getParameters(linkComponent);
|
103
|
0
|
final MapTree mapTree = new MapTree();
|
104
|
0
|
final Iterator iterator = options.keySet().iterator();
|
105
|
|
|
106
|
0
|
while (iterator.hasNext()) {
|
107
|
0
|
final String propName = String.valueOf(iterator.next());
|
108
|
0
|
final String targetObj = String.valueOf(options.get(propName));
|
109
|
0
|
final String value = getPropValue(parameters, propName);
|
110
|
0
|
mapTree.put("link." + propName + ".targetObj", targetObj);
|
111
|
0
|
mapTree.put("link." + propName + ".value", value);
|
112
|
|
}
|
113
|
0
|
final ValueTagWriter tagWriter = new ValueTagWriter(bodyWriter);
|
114
|
0
|
tagWriter.getExtraAttributes().put("style", "display:none");
|
115
|
0
|
tagWriter.addProperties(mapTree.getRoot());
|
116
|
|
}
|
117
|
|
|
118
|
0
|
public String getPropValue(Object params, String propName) {
|
119
|
0
|
if (params instanceof Map) {
|
120
|
0
|
final Map paramMap = (Map) params;
|
121
|
0
|
return String.valueOf(paramMap.get(propName));
|
122
|
|
} else {
|
123
|
0
|
try {
|
124
|
0
|
return BeanUtils.getProperty(params, propName);
|
125
|
|
} catch (Exception e) {
|
126
|
0
|
return "";
|
127
|
|
}
|
128
|
|
}
|
129
|
|
}
|
130
|
|
|
131
|
0
|
protected Object getParameters(ILinkComponent linkComponent) {
|
132
|
0
|
try {
|
133
|
0
|
return PropertyUtils.getProperty(linkComponent, "parameters");
|
134
|
|
} catch (Exception e) {
|
135
|
0
|
return null;
|
136
|
|
}
|
137
|
|
}
|
138
|
|
|
139
|
|
}
|