1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.gui.control;
35
36 import java.util.ArrayList;
37 import java.util.List;
38
39 import org.apache.commons.lang.StringUtils;
40 import info.magnolia.cms.i18n.Messages;
41
42 import javax.servlet.http.HttpServletRequest;
43
44
45
46
47
48 public class ContextMenuItem extends ControlImpl {
49
50 public static ContextMenuItem getRefreshMenuItem(Tree tree, Messages msgs, HttpServletRequest request) {
51 ContextMenuItem menuRefresh = new ContextMenuItem("refresh");
52 menuRefresh.setLabel(msgs.get("tree.menu.refresh"));
53 menuRefresh.setIcon(request.getContextPath() + "/.resources/icons/16/refresh.gif");
54 menuRefresh.setOnclick(tree.getJavascriptTree() + ".refresh();");
55 return menuRefresh;
56 }
57
58 private String icon;
59
60 private String onclick;
61
62 private String javascriptMenuName;
63
64 private List javascriptConditions = new ArrayList();
65
66 public ContextMenuItem() {
67 }
68
69 public ContextMenuItem(String name) {
70 this.setName(name);
71 }
72
73 public void setOnclick(String s) {
74 this.onclick = s;
75 }
76
77 public String getOnclick() {
78 return this.onclick;
79 }
80
81
82
83
84 public void addJavascriptCondition(String methodName) {
85 this.javascriptConditions.add(methodName);
86 }
87
88 public List getJavascriptConditions() {
89 return this.javascriptConditions;
90 }
91
92 public String getJavascriptCondition(int index) {
93 return (String) this.javascriptConditions.get(index);
94 }
95
96
97 public String getHtml() {
98 StringBuffer html = new StringBuffer();
99 html.append("<div class=\"mgnlTreeMenuItem\" id=\""
100 + this.getId()
101 + "\" onclick=\""
102 + this.getJavascriptMenuName()
103 + ".hide();");
104 if (StringUtils.isNotEmpty(this.onclick)) {
105 html.append(this.onclick);
106 }
107
108 String label = this.getLabel();
109 if (StringUtils.isNotEmpty(this.getIcon())) {
110 label = "<img src=\""
111 + this.getIcon()
112 + "\" alt=\"\" /> <span style=\"position:relative;top:-3px\">"
113 + label
114 + "</span>";
115 }
116
117 html.append("\" onmouseover=\""
118 + this.getJavascriptMenuName()
119 + ".menuItemHighlight(this);\" onmouseout=\""
120 + this.getJavascriptMenuName()
121 + ".menuItemReset(this);\">"
122 + label
123 + "</div>");
124 return html.toString();
125 }
126
127 public String getIcon() {
128 return this.icon;
129 }
130
131 public void setIcon(String icon) {
132 this.icon = icon;
133 }
134
135 public String getJavascriptMenuName() {
136 return this.javascriptMenuName;
137 }
138
139 public void setJavascriptMenuName(String javascriptMenuName) {
140 this.javascriptMenuName = javascriptMenuName;
141 }
142 }