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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.itmill.toolkit.terminal.gwt.client.ui;
/*
* Copyright 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
// COPIED HERE DUE package privates in GWT
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.UIObject;
/**
* A widget that can be placed in a
* {@link com.google.gwt.user.client.ui.MenuBar}. Menu items can either fire a
* {@link com.google.gwt.user.client.Command} when they are clicked, or open a
* cascading sub-menu.
*
* @deprecated
*/
public class MenuItem extends UIObject implements HasHTML {
private static final String DEPENDENT_STYLENAME_SELECTED_ITEM = "selected";
private Command command;
private MenuBar parentMenu, subMenu;
/**
* Constructs a new menu item that fires a command when it is selected.
*
* @param text
* the item's text
* @param cmd
* the command to be fired when it is selected
*/
public MenuItem(String text, Command cmd) {
this(text, false);
setCommand(cmd);
}
/**
* Constructs a new menu item that fires a command when it is selected.
*
* @param text
* the item's text
* @param asHTML
* <code>true</code> to treat the specified text as html
* @param cmd
* the command to be fired when it is selected
*/
public MenuItem(String text, boolean asHTML, Command cmd) {
this(text, asHTML);
setCommand(cmd);
}
/**
* Constructs a new menu item that cascades to a sub-menu when it is
* selected.
*
* @param text
* the item's text
* @param subMenu
* the sub-menu to be displayed when it is selected
*/
public MenuItem(String text, MenuBar subMenu) {
this(text, false);
setSubMenu(subMenu);
}
/**
* Constructs a new menu item that cascades to a sub-menu when it is
* selected.
*
* @param text
* the item's text
* @param asHTML
* <code>true</code> to treat the specified text as html
* @param subMenu
* the sub-menu to be displayed when it is selected
*/
public MenuItem(String text, boolean asHTML, MenuBar subMenu) {
this(text, asHTML);
setSubMenu(subMenu);
}
MenuItem(String text, boolean asHTML) {
setElement(DOM.createTD());
setSelectionStyle(false);
if (asHTML) {
setHTML(text);
} else {
setText(text);
}
setStyleName("gwt-MenuItem");
}
/**
* Gets the command associated with this item.
*
* @return this item's command, or <code>null</code> if none exists
*/
public Command getCommand() {
return command;
}
public String getHTML() {
return DOM.getInnerHTML(getElement());
}
/**
* Gets the menu that contains this item.
*
* @return the parent menu, or <code>null</code> if none exists.
*/
public MenuBar getParentMenu() {
return parentMenu;
}
/**
* Gets the sub-menu associated with this item.
*
* @return this item's sub-menu, or <code>null</code> if none exists
*/
public MenuBar getSubMenu() {
return subMenu;
}
public String getText() {
return DOM.getInnerText(getElement());
}
/**
* Sets the command associated with this item.
*
* @param cmd
* the command to be associated with this item
*/
public void setCommand(Command cmd) {
command = cmd;
}
public void setHTML(String html) {
DOM.setInnerHTML(getElement(), html);
}
/**
* Sets the sub-menu associated with this item.
*
* @param subMenu
* this item's new sub-menu
*/
public void setSubMenu(MenuBar subMenu) {
this.subMenu = subMenu;
}
public void setText(String text) {
DOM.setInnerText(getElement(), text);
}
void setParentMenu(MenuBar parentMenu) {
this.parentMenu = parentMenu;
}
void setSelectionStyle(boolean selected) {
if (selected) {
addStyleDependentName(DEPENDENT_STYLENAME_SELECTED_ITEM);
} else {
removeStyleDependentName(DEPENDENT_STYLENAME_SELECTED_ITEM);
}
}
}
|