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.menu.event.CheckItemListener;
014:
015: /**
016: * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
017: */
018: public class CheckItem extends Item {
019:
020: /* private static JavaScriptObject configPrototype;
021:
022: static {
023: init();
024: }
025:
026: private static native void init()*//*-{
027: var c = new $wnd.Ext.menu.CheckItem();
028: @com.gwtext.client.widgets.menu.CheckItem::configPrototype = c.initialConfig;
029: }-*//*;
030:
031:
032: protected JavaScriptObject getConfigPrototype() {
033: return configPrototype;
034: }*/
035:
036: protected JavaScriptObject getConfigPrototype() {
037: return JavaScriptObjectHelper.createObject();
038: }
039:
040: /**
041: * Create a new CheckItem.
042: *
043: */
044: public CheckItem() {
045: }
046:
047: /**
048: * Create a new CheckItem.
049: *
050: * @param text the CheckItem text
051: */
052: public CheckItem(String text) {
053: setText(text);
054: }
055:
056: /**
057: * Create a new CheckItem.
058: *
059: * @param text the CheckItem text
060: * @param checked true for checked
061: */
062: public CheckItem(String text, boolean checked) {
063: super (text);
064: setChecked(checked);
065: }
066:
067: public CheckItem(JavaScriptObject jsObj) {
068: super (jsObj);
069: }
070:
071: protected native JavaScriptObject create(JavaScriptObject jsObj) /*-{
072: return new $wnd.Ext.menu.CheckItem(jsObj);
073: }-*/;
074:
075: private static CheckItem instance(JavaScriptObject jsObj) {
076: return new CheckItem(jsObj);
077: }
078:
079: /**
080: * Set the checked state of this item.
081: *
082: * @param checked the checked state
083: */
084: private native void setCheckedRendered(boolean checked) /*-{
085: var checkItem = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
086: checkItem.setChecked(checked);
087: }-*/;
088:
089: /**
090: * Add a CheckItemListener.
091: *
092: * @param listener the listener
093: */
094: public native void addListener(CheckItemListener listener)/*-{
095: this.@com.gwtext.client.widgets.menu.BaseItem::addListener(Lcom/gwtext/client/widgets/menu/event/BaseItemListener;)(listener);
096: var checkItemJ = this;
097:
098: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('beforecheckchange',
099: function(source, checked) {
100: return listener.@com.gwtext.client.widgets.menu.event.CheckItemListener::doBeforeCheckChange(Lcom/gwtext/client/widgets/menu/CheckItem;Z)(checkItemJ, checked);
101: }
102: );
103: this.@com.gwtext.client.widgets.Component::addListener(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)('checkchange',
104: function(source, checked) {
105: listener.@com.gwtext.client.widgets.menu.event.CheckItemListener::onCheckChange(Lcom/gwtext/client/widgets/menu/CheckItem;Z)(checkItemJ, checked);
106: }
107: );
108: }-*/;
109:
110: // --- config proeprties ---
111:
112: /**
113: * True to initialize this checkbox as checked (defaults to false). Note that if this checkbox is part of a radio group (group = true) only the last item in the group that is initialized with checked = true will be rendered as checked.
114: *
115: * @param checked true to set as checked
116: */
117: public void setChecked(boolean checked) {
118: if (!isRendered()) {
119: setAttribute("checked", checked, true);
120: } else {
121: setCheckedRendered(checked);
122: }
123:
124: }
125:
126: /**
127: * All check items with the same group name will automatically be grouped into a single-select radio button group (defaults to '').
128: *
129: * @param group the group name
130: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
131: */
132: public void setGroup(String group) throws IllegalStateException {
133: setAttribute("group", group, true);
134: }
135:
136: /**
137: * The default CSS class to use for radio group check items (defaults to "x-menu-group-item").
138: *
139: * @param groupClass the group CSS class
140: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
141: */
142: public void setGroupClass(String groupClass)
143: throws IllegalStateException {
144: setAttribute("groupClass", groupClass, true);
145: }
146:
147: /**
148: * The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item").
149: *
150: * @param itemCls the default CSS class to use for check items
151: */
152: public void setItemCls(String itemCls)
153: throws IllegalArgumentException {
154: setAttribute("itemCls", itemCls, true);
155: }
156: }
|