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 @Override
98 public String getHtml() {
99 StringBuffer html = new StringBuffer();
100 html.append("<div class=\"mgnlTreeMenuItem\" id=\""
101 + this.getId()
102 + "\" onclick=\""
103 + this.getJavascriptMenuName()
104 + ".hide();");
105 if (StringUtils.isNotEmpty(this.onclick)) {
106 html.append(this.onclick);
107 }
108
109 String label = this.getLabel();
110 if (StringUtils.isNotEmpty(this.getIcon())) {
111 label = "<img src=\""
112 + this.getIcon()
113 + "\" alt=\"\" /> <span style=\"position:relative;top:-3px\">"
114 + label
115 + "</span>";
116 }
117
118 html.append("\" onmouseover=\""
119 + this.getJavascriptMenuName()
120 + ".menuItemHighlight(this);\" onmouseout=\""
121 + this.getJavascriptMenuName()
122 + ".menuItemReset(this);\">"
123 + label
124 + "</div>");
125 return html.toString();
126 }
127
128 public String getIcon() {
129 return this.icon;
130 }
131
132 public void setIcon(String icon) {
133 this.icon = icon;
134 }
135
136 public String getJavascriptMenuName() {
137 return this.javascriptMenuName;
138 }
139
140 public void setJavascriptMenuName(String javascriptMenuName) {
141 this.javascriptMenuName = javascriptMenuName;
142 }
143 }