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.dd;
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: import com.gwtext.client.core.Function;
015: import com.gwtext.client.core.JsObject;
016: import com.gwtext.client.core.Paddings;
017: import com.gwtext.client.util.JavaScriptObjectHelper;
018: import com.gwtext.client.widgets.Component;
019:
020: public class DragDrop extends JsObject {
021: static {
022: init();
023: }
024:
025: private static native void init() /*-{
026: $wnd.Ext.dd.DragDrop.prototype.ddJ=null;
027:
028: $wnd.Ext.dd.DragDrop.prototype.startDrag = function(x, y) {
029: var ddJ = this.ddJ;
030: if(ddJ != null) ddJ.@com.gwtext.client.dd.DragDrop::startDrag(II)(x,y);
031: }
032:
033: $wnd.Ext.dd.DragDrop.prototype.endDrag = function(e) {
034: var ddJ = this.ddJ;
035: if(ddJ != null) {
036: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
037: ddJ.@com.gwtext.client.dd.DragDrop::endDrag(Lcom/gwtext/client/core/EventObject;)(eJ);
038: }
039: }
040:
041: $wnd.Ext.dd.DragDrop.prototype.onDrag = function(e) {
042: var ddJ = this.ddJ;
043: if(ddJ != null) {
044: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
045: ddJ.@com.gwtext.client.dd.DragDrop::onDrag(Lcom/gwtext/client/core/EventObject;)(eJ);
046: }
047: }
048:
049: $wnd.Ext.dd.DragDrop.prototype.onDragDrop = function(e, id) {
050: var ddJ = this.ddJ;
051: if(ddJ != null) {
052: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
053: if(typeof id == 'string') {
054: ddJ.@com.gwtext.client.dd.DragDrop::onDragDrop(Lcom/gwtext/client/core/EventObject;Ljava/lang/String;)(eJ, id);
055: } else {
056: var items = @com.gwtext.client.dd.DragDrop::convertToDragDropArray(Lcom/google/gwt/core/client/JavaScriptObject;)(id);
057: ddJ.@com.gwtext.client.dd.DragDrop::onDragDrop(Lcom/gwtext/client/core/EventObject;[Lcom/gwtext/client/dd/DragDrop;)(eJ, items);
058: }
059: }
060: }
061:
062: $wnd.Ext.dd.DragDrop.prototype.onDragEnter = function(e, id) {
063: var ddJ = this.ddJ;
064: if(ddJ != null) {
065: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
066: if(typeof id == 'string') {
067: ddJ.@com.gwtext.client.dd.DragDrop::onDragEnter(Lcom/gwtext/client/core/EventObject;Ljava/lang/String;)(eJ, id);
068: } else {
069: var items = @com.gwtext.client.dd.DragDrop::convertToDragDropArray(Lcom/google/gwt/core/client/JavaScriptObject;)(id);
070: ddJ.@com.gwtext.client.dd.DragDrop::onDragEnter(Lcom/gwtext/client/core/EventObject;[Lcom/gwtext/client/dd/DragDrop;)(eJ, items);
071: }
072: }
073: }
074:
075: $wnd.Ext.dd.DragDrop.prototype.onDragOut = function(e, id) {
076: var ddJ = this.ddJ;
077: if(ddJ != null) {
078: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
079: if(typeof id == 'string') {
080: ddJ.@com.gwtext.client.dd.DragDrop::onDragOut(Lcom/gwtext/client/core/EventObject;Ljava/lang/String;)(eJ, id);
081: } else {
082: var items = @com.gwtext.client.dd.DragDrop::convertToDragDropArray(Lcom/google/gwt/core/client/JavaScriptObject;)(id);
083: ddJ.@com.gwtext.client.dd.DragDrop::onDragOut(Lcom/gwtext/client/core/EventObject;[Lcom/gwtext/client/dd/DragDrop;)(eJ, items);
084: }
085: }
086: }
087:
088: $wnd.Ext.dd.DragDrop.prototype.onDragOver = function(e, id) {
089: var ddJ = this.ddJ;
090: if(ddJ != null) {
091: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
092: if(typeof id == 'string') {
093: ddJ.@com.gwtext.client.dd.DragDrop::onDragOver(Lcom/gwtext/client/core/EventObject;Ljava/lang/String;)(eJ, id);
094: } else {
095: var items = @com.gwtext.client.dd.DragDrop::convertToDragDropArray(Lcom/google/gwt/core/client/JavaScriptObject;)(id);
096: ddJ.@com.gwtext.client.dd.DragDrop::onDragOver(Lcom/gwtext/client/core/EventObject;[Lcom/gwtext/client/dd/DragDrop;)(eJ, items);
097: }
098: }
099: }
100:
101: $wnd.Ext.dd.DragDrop.prototype.onInvalidDrop = function(e) {
102: var ddJ = this.ddJ;
103: if(ddJ != null) {
104: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
105: ddJ.@com.gwtext.client.dd.DragDrop::onInvalidDrop(Lcom/gwtext/client/core/EventObject;)(eJ);
106: }
107: }
108:
109: $wnd.Ext.dd.DragDrop.prototype.onMouseDown = function(e) {
110: var ddJ = this.ddJ;
111: if(ddJ != null) {
112: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
113: ddJ.@com.gwtext.client.dd.DragDrop::onMouseDown(Lcom/gwtext/client/core/EventObject;)(eJ);
114: }
115: }
116:
117: $wnd.Ext.dd.DragDrop.prototype.onMouseUp = function(e) {
118: var ddJ = this.ddJ;
119: if(ddJ != null) {
120: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(e);
121: ddJ.@com.gwtext.client.dd.DragDrop::onMouseUp(Lcom/gwtext/client/core/EventObject;)(eJ);
122: }
123: }
124: }-*/;
125:
126: public DragDrop(JavaScriptObject jsObj) {
127: super (jsObj);
128: }
129:
130: public DragDrop(String id) {
131: this (id, null);
132: }
133:
134: public DragDrop(final Component component) {
135: this (component, null);
136: }
137:
138: public DragDrop(String id, String sGroup) {
139: this (id, sGroup, null);
140: }
141:
142: public DragDrop(Component component, String sGroup) {
143: this (component, null, null);
144: }
145:
146: public DragDrop(String id, String sGroup, DragDropConfig config) {
147: jsObj = create(id, sGroup, config == null ? null : config
148: .getJsObj());
149: setLocalRef(jsObj, this );
150: onAvailable();
151: }
152:
153: public DragDrop(Element element, String sGroup,
154: DragDropConfig config) {
155: jsObj = create(element, sGroup, config == null ? null : config
156: .getJsObj());
157: setLocalRef(jsObj, this );
158: onAvailable();
159: }
160:
161: public DragDrop(final Component component, final String sGroup,
162: final DragDropConfig config) {
163: if (component.isRendered()) {
164: jsObj = create(component.getId(), sGroup,
165: config == null ? null : config.getJsObj());
166: setLocalRef(jsObj, this );
167: onAvailable();
168: } else {
169: component.addListener("render", new Function() {
170: public void execute() {
171: jsObj = create(component.getId(), sGroup,
172: config == null ? null : config.getJsObj());
173: setLocalRef(jsObj, DragDrop.this );
174: onAvailable();
175: }
176: });
177: }
178: }
179:
180: private native void setLocalRef(JavaScriptObject dd,
181: DragDrop dragDrop) /*-{
182: dd.ddJ = dragDrop;
183: }-*/;
184:
185: protected native JavaScriptObject create(String id, String sGroup,
186: JavaScriptObject config)/*-{
187: return new $wnd.Ext.dd.DragDrop(id, sGroup, config);
188: }-*/;
189:
190: protected native JavaScriptObject create(Element element,
191: String sGroup, JavaScriptObject config)/*-{
192: return new $wnd.Ext.dd.DragDrop(element, sGroup, config);
193: }-*/;
194:
195: private static DragDrop instance(JavaScriptObject jsObj) {
196: return new DragDrop(jsObj);
197: }
198:
199: public native boolean isAvailable() /*-{
200: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
201: return dd.available;
202: }-*/;
203:
204: public String[] getGroups() {
205: JavaScriptObject nativeArray = doGetGroups();
206: String[] rtn = null;
207:
208: if (nativeArray != null) {
209: rtn = new String[JavaScriptObjectHelper
210: .getJavaScriptObjectArraySize(nativeArray)];
211:
212: for (int i = 0; i < rtn.length; i++) {
213: rtn[i] = JavaScriptObjectHelper
214: .getStringValueFromJavaScriptObjectArray(
215: nativeArray, i);
216: }
217: }
218: return rtn;
219: }
220:
221: private native JavaScriptObject doGetGroups() /*-{
222: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
223: var groups = dd.groups;
224: var group;
225: var arr = @com.gwtext.client.util.JavaScriptObjectHelper::createJavaScriptArray()();
226: for(group in groups) {
227: arr.push(group);
228: }
229: return arr;
230: }-*/;
231:
232: public native boolean hasOuterHandles() /*-{
233: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
234: return dd.hasOuterHandles;
235: }-*/;
236:
237: public native String getId() /*-{
238: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
239: return dd.id;
240: }-*/;
241:
242: public String[] getInvalidHandleClasses() {
243: return JavaScriptObjectHelper.getAttributeAsStringArray(jsObj,
244: "invalidHandleClasses");
245: }
246:
247: public native String getInvalidHandleTypes() /*-{
248: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
249: return dd.invalidHandleTypes;
250: }-*/;
251:
252: public native boolean isMaintainOffset() /*-{
253: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
254: var mo = dd.maintainOffset;
255: return (mo === undefined || mo == null) ? false : mo;
256: }-*/;
257:
258: public native boolean isPrimaryButtonOnly() /*-{
259: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
260: return dd.primaryButtonOnly;
261: }-*/;
262:
263: public int[] getXTicks() {
264: return JavaScriptObjectHelper.getAttributeAsIntArray(jsObj,
265: "xTicks");
266: }
267:
268: public int[] getYTicks() {
269: return JavaScriptObjectHelper.getAttributeAsIntArray(jsObj,
270: "yTicks");
271: }
272:
273: public native void addInvalidHandleClass(String cssClass) /*-{
274: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
275: dd.addInvalidHandleClass(cssClass);
276: }-*/;
277:
278: public native void addInvalidHandleId(String id) /*-{
279: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
280: dd.addInvalidHandleId(id);
281: }-*/;
282:
283: public native void addInvalidHandleType(String tagName) /*-{
284: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
285: dd.addInvalidHandleType(tagName);
286: }-*/;
287:
288: public native void addToGroup(String sGroup) /*-{
289: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
290: dd.addToGroup(sGroup);
291: }-*/;
292:
293: public native void applyConfig() /*-{
294: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
295: dd.applyConfig();
296: }-*/;
297:
298: public native void clearConstraints() /*-{
299: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
300: dd.clearConstraints();
301: }-*/;
302:
303: public native void clearTicks() /*-{
304: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
305: dd.clearTicks();
306: }-*/;
307:
308: public void endDrag(EventObject e) {
309:
310: }
311:
312: public native Element getDragEl() /*-{
313: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
314: return dd.getDragEl();
315: }-*/;
316:
317: public native Element getEl() /*-{
318: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
319: return dd.getEl();
320: }-*/;
321:
322: public native void init(String id, String sGroup,
323: DragDropConfig config) /*-{
324: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
325: var cfg = config.@com.gwtext.client.core.JsObject::getJsObj()();
326: dd.init(id, sGroup, cfg);
327: }-*/;
328:
329: public native void initTarget(String id, String sGroup,
330: DragDropConfig config) /*-{
331: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
332: var cfg = config.@com.gwtext.client.core.JsObject::getJsObj()();
333: dd.initTarget(id, sGroup, cfg);
334: }-*/;
335:
336: public native boolean isLocked() /*-{
337: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
338: return dd.isLocked();
339: }-*/;
340:
341: public native boolean isTarget() /*-{
342: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
343: return dd.isTarget();
344: }-*/;
345:
346: public native boolean isValidHandleChild(Element element) /*-{
347: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
348: return dd.isValidHandleChild(element);
349: }-*/;
350:
351: public native void lock() /*-{
352: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
353: dd.lock();
354: }-*/;
355:
356: public void onAvailable() {
357: }
358:
359: public void onDrag(EventObject e) {
360:
361: }
362:
363: private static DragDrop[] convertToDragDropArray(
364: JavaScriptObject nativeArray) {
365: JavaScriptObject[] itemsJ = JavaScriptObjectHelper
366: .toArray(nativeArray);
367: DragDrop[] items = new DragDrop[itemsJ.length];
368: for (int i = 0; i < itemsJ.length; i++) {
369: JavaScriptObject dd = itemsJ[i];
370: items[i] = new DragDrop(dd);
371: }
372: return items;
373: }
374:
375: public void onDragDrop(EventObject e, String id) {
376:
377: }
378:
379: public void onDragDrop(EventObject e, DragDrop[] items) {
380:
381: }
382:
383: public void onDragEnter(EventObject e, String id) {
384:
385: }
386:
387: public void onDragEnter(EventObject e, DragDrop[] items) {
388:
389: }
390:
391: public void onDragOut(EventObject e, String id) {
392:
393: }
394:
395: public void onDragOut(EventObject e, DragDrop[] items) {
396:
397: }
398:
399: public void onDragOver(EventObject e, String id) {
400:
401: }
402:
403: public void onDragOver(EventObject e, DragDrop[] items) {
404:
405: }
406:
407: public void onInvalidDrop(EventObject e) {
408:
409: }
410:
411: public void onMouseDown(EventObject e) {
412:
413: }
414:
415: public void onMouseUp(EventObject e) {
416:
417: }
418:
419: public native Paddings getPadding() /*-{
420: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
421: var padding = dd.padding;
422: return @com.gwtext.client.core.Paddings::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(padding);
423: }-*/;
424:
425: public native void removeFromGroup(String sGroup) /*-{
426: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
427: dd.removeFromGroup(sGroup);
428: }-*/;
429:
430: public native void removeInvalidHandleClass(String cssClass) /*-{
431: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
432: dd.removeInvalidHandleClass(cssClass);
433: }-*/;
434:
435: public native void removeInvalidHandleId(String id) /*-{
436: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
437: dd.removeInvalidHandleId(id);
438: }-*/;
439:
440: public native void removeInvalidHandleType(String tagName) /*-{
441: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
442: dd.removeInvalidHandleType(tagName);
443: }-*/;
444:
445: public native void resetConstraints(boolean maintainOffset) /*-{
446: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
447: dd.resetConstraints(maintainOffset);
448: }-*/;
449:
450: public native void setDragElId(String id) /*-{
451: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
452: dd.setDragElId(id);
453: }-*/;
454:
455: public native void setHandleElId(String id) /*-{
456: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
457: dd.setHandleElId(id);
458: }-*/;
459:
460: //in doc but missing from code?
461: /*public native void setInitialPosition(int diffX, int diffY) *//*-{
462: var dd = this .@com.gwtext.client.core.JsObject::getJsObj()();
463: dd.setInitialPosition(diffX, diffY);
464: }-*//*;*/
465:
466: public native void setOuterHandleElId(String id) /*-{
467: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
468: dd.setOuterHandleElId(id);
469: }-*/;
470:
471: public native void setPadding(int iUp, int iDown, int iBottom,
472: int iLeft) /*-{
473: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
474: dd.setPadding(iUp, iDown, iBottom, iLeft);
475: }-*/;
476:
477: public native void setXConstraint(int iLeft, int iRight,
478: int iTickSize) /*-{
479: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
480: dd.setXConstraint(iLeft, iRight, iTickSize);
481: }-*/;
482:
483: public native void setYConstraint(int iUp, int iDown, int iTickSize) /*-{
484: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
485: dd.setYConstraint(iUp, iDown, iTickSize);
486: }-*/;
487:
488: public void startDrag(int x, int y) {
489: }
490:
491: public native String toString() /*-{
492: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
493: return dd.toString();
494: }-*/;
495:
496: public native void unlock() /*-{
497: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
498: dd.unlock();
499: }-*/;
500:
501: public native void unreg() /*-{
502: var dd = this.@com.gwtext.client.core.JsObject::getJsObj()();
503: dd.unreg();
504: }-*/;
505: }
|