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.form;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.google.gwt.user.client.Element;
013: import com.gwtext.client.core.EventObject;
014:
015: //http://extjs.com/forum/showthread.php?t=3613&highlight=triggerfield
016: /**
017: * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
018: * The trigger has no default action, so you mustimplement the trigger click handler by overriding {@link #onTriggerClick(com.gwtext.client.core.EventObject)}.
019: * You can create a TriggerField directly, as it renders exactly like a combobox for which you can provide a custom implementation.
020: *
021: */
022: public abstract class TriggerField extends TextField {
023:
024: /**
025: * Construct a new TriggerField.
026: */
027: public TriggerField() {
028: }
029:
030: public TriggerField(JavaScriptObject jsObj) {
031: super (jsObj);
032: }
033:
034: protected void initComponent() {
035: super .initComponent();
036: setup(this , getJsObj());
037: }
038:
039: protected native Element getElement(JavaScriptObject jsObj) /*-{
040: //for trigger fields, we want the text area as well as the trigger button to be treated as the element
041: //unit
042: var extEl = jsObj.wrap;
043: if(extEl == null || extEl === undefined) {
044: return null;
045: }
046: var el = extEl.dom;
047: if(el == null || el === undefined) {
048: return null;
049: } else {
050: //There's an inconsistency in Ext where most elements have the property 'el' set to Ext's Element
051: //with the exception of Menu->Item, Menu->Separator, Menu->TextItem, Toolbar.Item and subclasses
052: //(Toolbar.Separator, Toolbar.Spacer, Toolbar.TextItem) where the 'el' property is set to
053: //the DOM element itself. Therefore retruning 'el' if 'el' is not Ext's Element. See details in issue 39.
054: return el.dom || el ;
055: }
056: }-*/;
057:
058: private native void setup(TriggerField triggerField,
059: JavaScriptObject jsObj) /*-{
060: jsObj.onTriggerClick = function(event) {
061: var e = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(event);
062: triggerField.@com.gwtext.client.widgets.form.TriggerField::onTriggerClick(Lcom/gwtext/client/core/EventObject;)(e);
063: }
064: }-*/;
065:
066: protected native JavaScriptObject create(JavaScriptObject jsObj) /*-{
067: return new $wnd.Ext.form.TriggerField(jsObj);
068: }-*/;
069:
070: /**
071: * Abstract method that must be implmented for custom trigger field behavior.
072: *
073: * @param event the event object
074: */
075: protected abstract void onTriggerClick(EventObject event);
076:
077: // config properties ---
078: public String getXType() {
079: return "trigger";
080: }
081:
082: /**
083: * True to hide the trigger element and display only the base text field (defaults to false).
084: *
085: * @param hideTrigger true to hide trigger
086: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
087: */
088: public void setHideTrigger(boolean hideTrigger)
089: throws IllegalStateException {
090: setAttribute("hideTrigger", hideTrigger, true);
091: }
092:
093: /**
094: * A CSS class to apply to the trigger.
095: *
096: * @param triggerClass the trigger CSS class.
097: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
098: */
099: public void setTriggerClass(String triggerClass)
100: throws IllegalStateException {
101: setAttribute("triggerClass", triggerClass, true);
102: }
103: }
|