KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > control > ContextMenuItem


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.control;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.apache.commons.lang.StringUtils;
19
20
21 /**
22  * @author Vinzenz Wyser
23  * @version 2.0
24  */

25 public class ContextMenuItem extends ControlSuper {
26
27     private String JavaDoc icon;
28
29     private String JavaDoc onclick;
30
31     private String JavaDoc javascriptMenuName;
32
33     private List JavaDoc javascriptConditions = new ArrayList JavaDoc();
34
35     public ContextMenuItem() {
36     }
37
38     public void setOnclick(String JavaDoc s) {
39         this.onclick = s;
40     }
41
42     public String JavaDoc getOnclick() {
43         return this.onclick;
44     }
45
46     /**
47      * Must be a object with a method test(): addJavascriptCondition("new MyCondition()").
48      */

49     public void addJavascriptCondition(String JavaDoc methodName) {
50         this.javascriptConditions.add(methodName);
51     }
52
53     public List JavaDoc getJavascriptConditions() {
54         return this.javascriptConditions;
55     }
56
57     public String JavaDoc getJavascriptCondition(int index) {
58         return (String JavaDoc) this.javascriptConditions.get(index);
59     }
60
61     // todo: icons
62
public String JavaDoc getHtml() {
63         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
64         html.append("<div class=\"mgnlTreeMenuItem\" id=\"" //$NON-NLS-1$
65
+ this.getId() + "\" onclick=\"" //$NON-NLS-1$
66
+ this.getJavascriptMenuName() + ".hide();"); //$NON-NLS-1$
67
if (StringUtils.isNotEmpty(this.onclick)) {
68             html.append(this.onclick);
69         }
70
71         String JavaDoc label = this.getLabel();
72         if (StringUtils.isNotEmpty(this.getIcon())) {
73             label = "<img SRC=\"" //$NON-NLS-1$
74
+ this.getIcon() + "\"> <span style=\"position:relative;top:-3px\">" //$NON-NLS-1$
75
+ label + "</span>"; //$NON-NLS-1$
76
}
77
78         html.append("\" onmouseover=\"" //$NON-NLS-1$
79
+ this.getJavascriptMenuName() + ".menuItemHighlight(this);\" onmouseout=\"" //$NON-NLS-1$
80
+ this.getJavascriptMenuName() + ".menuItemReset(this);\">" //$NON-NLS-1$
81
+ label + "</div>"); //$NON-NLS-1$
82
return html.toString();
83     }
84
85     public String JavaDoc getIcon() {
86         return this.icon;
87     }
88
89     public void setIcon(String JavaDoc icon) {
90         this.icon = icon;
91     }
92
93     public String JavaDoc getJavascriptMenuName() {
94         return this.javascriptMenuName;
95     }
96
97     public void setJavascriptMenuName(String JavaDoc javascriptMenuName) {
98         this.javascriptMenuName = javascriptMenuName;
99     }
100 }
101
Popular Tags