comparison dwtx/jface/util/DelegatingDragAdapter.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 644f1334b451
children
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
13 module dwtx.jface.util.DelegatingDragAdapter; 13 module dwtx.jface.util.DelegatingDragAdapter;
14 14
15 import dwtx.jface.util.TransferDragSourceListener; 15 import dwtx.jface.util.TransferDragSourceListener;
16 import dwtx.jface.util.SafeRunnable; 16 import dwtx.jface.util.SafeRunnable;
17 17
18 import tango.util.collection.ArraySeq;
19 18
20 import dwt.dnd.DragSource; 19 import dwt.dnd.DragSource;
21 import dwt.dnd.DragSourceEvent; 20 import dwt.dnd.DragSourceEvent;
22 import dwt.dnd.DragSourceListener; 21 import dwt.dnd.DragSourceListener;
23 import dwt.dnd.Transfer; 22 import dwt.dnd.Transfer;
24 import dwt.dnd.TransferData; 23 import dwt.dnd.TransferData;
25 24
26 import dwt.dwthelper.utils; 25 import dwt.dwthelper.utils;
26 import dwtx.dwtxhelper.Collection;
27 27
28 /** 28 /**
29 * A <code>DelegatingDragAdapter</code> is a <code>DragSourceListener</code> that 29 * A <code>DelegatingDragAdapter</code> is a <code>DragSourceListener</code> that
30 * maintains and delegates to a set of {@link TransferDragSourceListener}s. Each 30 * maintains and delegates to a set of {@link TransferDragSourceListener}s. Each
31 * TransferDragSourceListener can then be implemented as if it were the 31 * TransferDragSourceListener can then be implemented as if it were the
91 * viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, dragAdapter.getTransfers(), dragAdapter); 91 * viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, dragAdapter.getTransfers(), dragAdapter);
92 * </pre></code> 92 * </pre></code>
93 * @since 3.0 93 * @since 3.0
94 */ 94 */
95 public class DelegatingDragAdapter : DragSourceListener { 95 public class DelegatingDragAdapter : DragSourceListener {
96 private ArraySeq!(Object) listeners; 96 private List listeners;
97 97
98 private ArraySeq!(Object) activeListeners; 98 private List activeListeners;
99 99
100 private TransferDragSourceListener currentListener; 100 private TransferDragSourceListener currentListener;
101 101
102 this(){ 102 this(){
103 listeners = new ArraySeq!(Object); 103 listeners = new ArrayList();
104 activeListeners = new ArraySeq!(Object); 104 activeListeners = new ArrayList();
105 } 105 }
106 106
107 /** 107 /**
108 * Adds the given <code>TransferDragSourceListener</code>. 108 * Adds the given <code>TransferDragSourceListener</code>.
109 * 109 *
110 * @param listener the new listener 110 * @param listener the new listener
111 */ 111 */
112 public void addDragSourceListener(TransferDragSourceListener listener) { 112 public void addDragSourceListener(TransferDragSourceListener listener) {
113 listeners.append(cast(Object)listener); 113 listeners.add(cast(Object)listener);
114 } 114 }
115 115
116 /** 116 /**
117 * The drop has successfully completed. This event is forwarded to the current 117 * The drop has successfully completed. This event is forwarded to the current
118 * drag listener. 118 * drag listener.
135 // there is a listener that can handle the drop, delegate the event 135 // there is a listener that can handle the drop, delegate the event
136 currentListener.dragFinished(event_); 136 currentListener.dragFinished(event_);
137 } else { 137 } else {
138 // The drag was canceled and currentListener was never set, so send the 138 // The drag was canceled and currentListener was never set, so send the
139 // dragFinished event to all the active listeners. 139 // dragFinished event to all the active listeners.
140 foreach( e; activeListeners ){ 140 Iterator iterator = activeListeners.iterator();
141 (cast(TransferDragSourceListener) e) 141 while (iterator.hasNext()) {
142 (cast(TransferDragSourceListener) iterator.next())
142 .dragFinished(event); 143 .dragFinished(event);
143 } 144 }
144 } 145 }
145 } 146 }
146 }); 147 });
185 */ 186 */
186 public void dragStart(DragSourceEvent event) { 187 public void dragStart(DragSourceEvent event) {
187 // if (Policy.DEBUG_DRAG_DROP) 188 // if (Policy.DEBUG_DRAG_DROP)
188 // System.out.println("Drag Start: " + toString()); //$NON-NLS-1$ 189 // System.out.println("Drag Start: " + toString()); //$NON-NLS-1$
189 bool doit = false; // true if any one of the listeners can handle the drag 190 bool doit = false; // true if any one of the listeners can handle the drag
190 auto transfers = new ArraySeq!(Object); 191 List transfers = new ArrayList(listeners.size());
191 transfers.capacity(listeners.size());
192 192
193 activeListeners.clear(); 193 activeListeners.clear();
194 for (int i = 0; i < listeners.size(); i++) { 194 for (int i = 0; i < listeners.size(); i++) {
195 TransferDragSourceListener listener = cast(TransferDragSourceListener) listeners 195 TransferDragSourceListener listener = cast(TransferDragSourceListener) listeners
196 .get(i); 196 .get(i);
205 public void run() { 205 public void run() {
206 listener_.dragStart(event_); 206 listener_.dragStart(event_);
207 } 207 }
208 }); 208 });
209 if (event.doit) { // the listener can handle this drag 209 if (event.doit) { // the listener can handle this drag
210 transfers.append(listener.getTransfer()); 210 transfers.add(listener.getTransfer());
211 activeListeners.append(cast(Object)listener); 211 activeListeners.add(cast(Object)listener);
212 } 212 }
213 doit |= event.doit; 213 doit |= event.doit;
214 } 214 }
215 215
216 if (doit) { 216 if (doit) {
241 * 241 *
242 * @return <code>true</code> if there are no <code>TransferDragSourceListeners</code> 242 * @return <code>true</code> if there are no <code>TransferDragSourceListeners</code>
243 * <code>false</code> otherwise. 243 * <code>false</code> otherwise.
244 */ 244 */
245 public bool isEmpty() { 245 public bool isEmpty() {
246 return listeners.drained(); 246 return listeners.isEmpty();
247 } 247 }
248 248
249 /** 249 /**
250 * Removes the given <code>TransferDragSourceListener</code>. 250 * Removes the given <code>TransferDragSourceListener</code>.
251 * Listeners should not be removed while a drag and drop operation is in progress. 251 * Listeners should not be removed while a drag and drop operation is in progress.
273 private void updateCurrentListener(DragSourceEvent event) { 273 private void updateCurrentListener(DragSourceEvent event) {
274 currentListener = null; 274 currentListener = null;
275 if (event.dataType is null) { 275 if (event.dataType is null) {
276 return; 276 return;
277 } 277 }
278 foreach( e; activeListeners ){ 278 Iterator iterator = activeListeners.iterator();
279 TransferDragSourceListener listener = cast(TransferDragSourceListener)e; 279 while (iterator.hasNext()) {
280 TransferDragSourceListener listener = cast(TransferDragSourceListener) iterator
281 .next();
280 282
281 if (listener.getTransfer().isSupportedType(event.dataType)) { 283 if (listener.getTransfer().isSupportedType(event.dataType)) {
282 // if (Policy.DEBUG_DRAG_DROP) 284 // if (Policy.DEBUG_DRAG_DROP)
283 // System.out.println("Current drag listener: " + listener); //$NON-NLS-1$ 285 // System.out.println("Current drag listener: " + listener); //$NON-NLS-1$
284 currentListener = listener; 286 currentListener = listener;