001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008:
009: package com.gwtext.client.widgets.menu;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.gwtext.client.util.JavaScriptObjectHelper;
013: import com.gwtext.client.widgets.Component;
014: import com.gwtext.client.widgets.menu.event.BaseItemListener;
015:
016: //todo - only reason non abstract because menu item click event returns a base item and need to instanticte
017:
018: //node baselem return null for getEl()
019: /**
020: * The base class for all items that render into menus. BaseItem provides default rendering, activated state management
021: * and base configuration options shared by all menu components.
022: */
023: public class BaseItem extends Component {
024:
025: public BaseItem() {
026: }
027:
028: public BaseItem(JavaScriptObject jsObj) {
029: super (jsObj);
030: }
031:
032: protected JavaScriptObject getConfigPrototype() {
033: return null;
034: }
035:
036: //todo2 -- ext 2 doesnt have xtype for base item so need this
037: private static BaseItem instance(JavaScriptObject jsObj) {
038: return new BaseItem(jsObj);
039: }
040:
041: /**
042: * Adda BaseItem listener.
043: *
044: * @param listener the listener
045: */
046: public native void addListener(BaseItemListener listener)/*-{
047: this.@com.gwtext.client.widgets.Component::addListener(Lcom/gwtext/client/widgets/event/ComponentListener;)(listener);
048: var baseItemJ = this;
049:
050: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('activate',
051: function(source) {
052: return listener.@com.gwtext.client.widgets.menu.event.BaseItemListener::onActivate(Lcom/gwtext/client/widgets/menu/BaseItem;)(baseItemJ);
053: }
054: );
055:
056: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('click',
057: function(source, event) {
058: var e = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(event);
059: return listener.@com.gwtext.client.widgets.menu.event.BaseItemListener::onClick(Lcom/gwtext/client/widgets/menu/BaseItem;Lcom/gwtext/client/core/EventObject;)(baseItemJ, e);
060: }
061: );
062:
063: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('deactivate',
064: function(source) {
065: return listener.@com.gwtext.client.widgets.menu.event.BaseItemListener::onDeactivate(Lcom/gwtext/client/widgets/menu/BaseItem;)(baseItemJ);
066: }
067: );
068: }-*/;
069:
070: protected JavaScriptObject create(JavaScriptObject config) {
071: throw new IllegalArgumentException("must be overridden");
072: }
073:
074: // --- config properties ---
075:
076: /**
077: * The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
078: *
079: * @param activeClass the active CSS class
080: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
081: */
082: public void setActiveClass(String activeClass)
083: throws IllegalStateException {
084: setAttribute("activeClass", activeClass, true);
085: }
086:
087: /**
088: * The CSS class to use when the item becomes activated.
089: *
090: * @return the CSS class to use when the item becomes activated
091: */
092: public String getActiveClass() {
093: return JavaScriptObjectHelper.getAttribute(config,
094: "activeClass");
095: }
096:
097: /**
098: * True if this item can be visually activated (defaults to false)
099: *
100: * @param canActivate true if can be activated
101: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
102: */
103: public void setCanActivate(boolean canActivate)
104: throws IllegalStateException {
105: setAttribute("canActivate", canActivate, true);
106: }
107:
108: /**
109: * True if this item can be visually activated (defaults to false).
110: *
111: * @return true if this item can be visually activated (defaults to false)
112: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
113: */
114: public boolean isCanActivate() throws IllegalStateException {
115: return JavaScriptObjectHelper.getAttributeAsBoolean(config,
116: "canActivate");
117: }
118:
119: /**
120: * Length of time in milliseconds to wait before hiding after a click (defaults to 100).
121: *
122: * @param hideDelay the hide delay
123: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
124: */
125: public void setHideDelay(int hideDelay)
126: throws IllegalStateException {
127: setAttribute("hideDelay", hideDelay, true);
128: }
129:
130: /**
131: * Length of time in milliseconds to wait before hiding after a click (defaults to 100).
132: *
133: * @return the hide delay
134: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
135: */
136: public int getHideDelay() throws IllegalStateException {
137: return JavaScriptObjectHelper.getAttributeAsInt(config,
138: "hideDelay");
139: }
140:
141: /**
142: * Length of time in milliseconds to wait before showing a hidden item after a click (defaults to 100)
143: *
144: * @param showDelay the show delay
145: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
146: */
147: public void setShowDelay(int showDelay)
148: throws IllegalStateException {
149: setAttribute("showDelay", showDelay, true);
150: }
151:
152: /**
153: * Length of time in milliseconds to wait before showing a hidden item after a click (defaults to 100).
154: *
155: * @return the show delay
156: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
157: */
158: public int getShowDelay() throws IllegalStateException {
159: return JavaScriptObjectHelper.getAttributeAsInt(config,
160: "showDelay");
161: }
162:
163: /**
164: * True to hide the containing menu after this item is clicked (defaults to true).
165: *
166: * @param hideOnClick true to hide on click
167: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
168: */
169: public void setHideOnClick(boolean hideOnClick)
170: throws IllegalStateException {
171: setAttribute("hideOnClick", hideOnClick, true);
172: }
173:
174: /**
175: * True to hide the containing menu after this item is clicked (defaults to true).
176: *
177: * @return true to hide on click
178: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
179: */
180: public boolean isHideOnClick() throws IllegalStateException {
181: return JavaScriptObjectHelper.getAttributeAsBoolean(config,
182: "hideOnClick");
183: }
184:
185: //todo 2.0, not in docs, should it be here?
186: public void setIcon(String icon) {
187: setAttribute("icon", icon, true);
188: }
189: }
|