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: package com.gwtext.client.core;
009:
010: import com.google.gwt.core.client.JavaScriptObject;
011:
012: /**
013: * Standard composite class that creates an ExtElement for every element in the collection.
014: */
015: public class CompositeElement extends BaseElement {
016:
017: /**
018: * Create a CompositeElement using a native element.
019: *
020: * @param jsObj native object
021: */
022: public CompositeElement(JavaScriptObject jsObj) {
023: super (jsObj);
024: }
025:
026: private static CompositeElement instance(JavaScriptObject jsObj) {
027: return new CompositeElement(jsObj);
028: }
029:
030: /**
031: * Adds elements to this composite.
032: *
033: * @param selector a CSS selector
034: * @return this
035: */
036: public native CompositeElement add(String selector) /*-{
037: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
038: ce.add(selector);
039: return this;
040: }-*/;
041:
042: /**
043: * Adds elements to this composite.
044: *
045: * @param element the elemetn to add
046: * @return this
047: */
048: public native CompositeElement add(ExtElement element) /*-{
049: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
050: ce.add(element);
051: return this;
052: }-*/;
053:
054: /**
055: * Removes all elements.
056: */
057: public native void clear() /*-{
058: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
059: ce.clear();
060: }-*/;
061:
062: /**
063: * Returns true if this composite contains the passed element.
064: *
065: * @param element true if containts element
066: */
067: public native void contains(ExtElement element) /*-{
068: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
069: var elJS = element.@com.gwtext.client.core.JsObject::getJsObj()();
070: return ce.contains(elJS);
071: }-*/;
072:
073: //todo each, fill, item
074:
075: /**
076: * Filters this composite to only elements that match the passed selector.
077: *
078: * @param selector a CSS selector
079: * @return this
080: */
081: public native CompositeElement filter(String selector) /*-{
082: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
083: ce.filter(selector);
084: return this;
085: }-*/;
086:
087: /**
088: * Returns the first Element
089: *
090: * @return the first element
091: */
092: public native ExtElement first() /*-{
093: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
094: var el = ce.first();
095: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
096: }-*/;
097:
098: /**
099: * Returns the number of elements in this composite.
100: *
101: * @return the element count
102: */
103: public native int getCount() /*-{
104: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
105: return ce.getCount();
106: }-*/;
107:
108: /**
109: * Position of the Element in the CompositeElement list.
110: *
111: * @param element the element
112: * @return index of element
113: */
114: public native int indexOf(ExtElement element) /*-{
115: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
116: var elJS = element.@com.gwtext.client.core.JsObject::getJsObj()();
117: return ce.indexOf(elJS);
118: }-*/;
119:
120: /**
121: * Returns the last Element.
122: *
123: * @return the last element
124: */
125: public native ExtElement last() /*-{
126: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
127: var el = ce.last();
128: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
129: }-*/;
130:
131: /**
132: * Removes the specified element.
133: *
134: * @param index element to remove
135: * @return this
136: */
137: public native CompositeElement removeElement(int index) /*-{
138: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
139: ce.removeElement(index);
140: return this;
141: }-*/;
142:
143: /**
144: * Removes the specified element.
145: *
146: * @param index element to remove
147: * @param removeDom true to also remove element from the document
148: * @return this
149: */
150: public native CompositeElement removeElement(int index,
151: boolean removeDom) /*-{
152: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
153: ce.removeElement(index, removeDom);
154: return this;
155: }-*/;
156:
157: /**
158: * Removes the specified element.
159: *
160: * @param element the element to remove
161: * @return this
162: */
163: public native CompositeElement removeElement(ExtElement element) /*-{
164: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
165: var elJS = element.@com.gwtext.client.core.JsObject::getJsObj()();
166: ce.removeElement(elJS);
167: return this;
168: }-*/;
169:
170: /**
171: * Removes the specified element.
172: *
173: * @param element the element to remove
174: * @param removeDom true to also remove element from the document
175: * @return this
176: */
177: public native CompositeElement removeElement(ExtElement element,
178: boolean removeDom) /*-{
179: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
180: var elJS = element.@com.gwtext.client.core.JsObject::getJsObj()();
181: ce.removeElement(elJS, removeDom);
182: return this;
183: }-*/;
184:
185: /**
186: * Replaces the specified element with the passed element.
187: *
188: * @param index the index of the element in this composite to replace
189: * @param replacement the element to replace with
190: * @return this
191: */
192: public native CompositeElement replaceElement(int index,
193: ExtElement replacement) /*-{
194: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
195: var replacementJS = replacement.@com.gwtext.client.core.JsObject::getJsObj()();
196: ce.replaceElement(index, replacementJS);
197: return this;
198: }-*/;
199:
200: /**
201: * Replaces the specified element with the passed element.
202: *
203: * @param index the index of the element in this composite to replace
204: * @param replacement the element to replace with
205: * @param removeDom true to remove and replace the element in the document too
206: * @return this
207: */
208: public native CompositeElement replaceElement(int index,
209: ExtElement replacement, boolean removeDom) /*-{
210: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
211: var replacementJS = replacement.@com.gwtext.client.core.JsObject::getJsObj()();
212: ce.replaceElement(index, replacementJS, removeDom);
213: return this;
214: }-*/;
215:
216: /**
217: * Replaces the specified element with the passed element.
218: *
219: * @param element the element in this composite to replace
220: * @param replacement the element to replace with
221: * @return this
222: */
223: public native CompositeElement replaceElement(ExtElement element,
224: ExtElement replacement) /*-{
225: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
226: var elJS = element.@com.gwtext.client.core.JsObject::getJsObj()();
227: var replacementJS = replacement.@com.gwtext.client.core.JsObject::getJsObj()();
228: ce.replaceElement(elJS, replacementJS);
229: return this;
230: }-*/;
231:
232: /**
233: * Replaces the specified element with the passed element.
234: *
235: * @param element the element in this composite to replace
236: * @param replacement the element to replace with
237: * @param removeDom true to remove and replace the element in the document too
238: * @return this
239: */
240: public native CompositeElement replaceElement(ExtElement element,
241: ExtElement replacement, boolean removeDom) /*-{
242: var ce = this.@com.gwtext.client.core.JsObject::getJsObj()();
243: var elJS = element.@com.gwtext.client.core.JsObject::getJsObj()();
244: var replacementJS = replacement.@com.gwtext.client.core.JsObject::getJsObj()();
245: ce.replaceElement(elJS, replacementJS, removeDom);
246: return this;
247: }-*/;
248: }
|