Class DelegatingDropAdapter
- All Implemented Interfaces:
- EventListener,- DropTargetListener,- SWTEventListener
DelegatingDropAdapter is a DropTargetListener
 that maintains and delegates to a set of TransferDropTargetListeners.
 Each TransferDropTargetListener can then be implemented as if it
 were the DropTarget's only DropTargetListener.
 
 On dragEnter, dragOperationChanged,
 dragOver and drop, a current listener is
 obtained from the set of all TransferDropTargetListeners. The
 current listener is the first listener to return true for
 TransferDropTargetListener.isEnabled(DropTargetEvent). The current
 listener is forwarded all DropTargetEvents until some other
 listener becomes the current listener, or the drop terminates.
 
 After adding all TransferDropTargetListeners to the
 DelegatingDropAdapter the combined set of Transfers
 should be set in the SWT DropTarget.
 #getTransfers() provides the set of Transfer types
 of all TransferDropTargetListeners.
 
 The following example snippet shows a DelegatingDropAdapter with
 two TransferDropTargetListeners. One supports dropping resources
 and demonstrates how a listener can be disabled in the isEnabled method. The
 other listener supports text transfer.
 
 
                final TreeViewer viewer = new TreeViewer(shell, SWT.NONE);
                DelegatingDropAdapter dropAdapter = new DelegatingDropAdapter();
                dropAdapter.addDropTargetListener(new TransferDropTargetListener() {
                        public Transfer getTransfer() {
                                return ResourceTransfer.getInstance();
                        }
                        public boolean isEnabled(DropTargetEvent event) {
                                // disable drop listener if there is no viewer selection
                                if (viewer.getSelection().isEmpty())
                                        return false;
                                return true;
                        }
                        public void dragEnter(DropTargetEvent event) {}
                        public void dragLeave(DropTargetEvent event) {}
                        public void dragOperationChanged(DropTargetEvent event) {}
                        public void dragOver(DropTargetEvent event) {}
                        public void drop(DropTargetEvent event) {
                                if (event.data == null)
                                        return;
                                IResource[] resources = (IResource[]) event.data;
                                if (event.detail == DND.DROP_COPY) {
                                        // copy resources
                                } else {
                                        // move resources
                                }
                        }
                        public void dropAccept(DropTargetEvent event) {}
                });
                dropAdapter.addDropTargetListener(new TransferDropTargetListener() {
                        public Transfer getTransfer() {
                                return TextTransfer.getInstance();
                        }
                        public boolean isEnabled(DropTargetEvent event) {
                                return true;
                        }
                        public void dragEnter(DropTargetEvent event) {}
                        public void dragLeave(DropTargetEvent event) {}
                        public void dragOperationChanged(DropTargetEvent event) {}
                        public void dragOver(DropTargetEvent event) {}
                        public void drop(DropTargetEvent event) {
                                if (event.data == null)
                                        return;
                                System.out.println(event.data);
                        }
                        public void dropAccept(DropTargetEvent event) {}
                });
                viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, dropAdapter.getTransfers(), dropAdapter);
 
 - Since:
- 3.0
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds the givenTransferDropTargetListener.voiddragEnter(DropTargetEvent event) The cursor has entered the drop target boundaries.voiddragLeave(DropTargetEvent event) The cursor has left the drop target boundaries.voidThe operation being performed has changed (usually due to the user changing a drag modifier key while dragging).voiddragOver(DropTargetEvent event) The cursor is moving over the drop target.voiddrop(DropTargetEvent event) Forwards this event to the current listener, if there is one.voiddropAccept(DropTargetEvent event) Forwards this event to the current listener if there is one.Transfer[]Returns the combined set ofTransfertypes of allTransferDropTargetListeners.booleanisEmpty()Returnstrueif there are no listeners to delegate events to.voidRemoves the givenTransferDropTargetListener.
- 
Constructor Details- 
DelegatingDropAdapterpublic DelegatingDropAdapter()
 
- 
- 
Method Details- 
addDropTargetListenerAdds the givenTransferDropTargetListener.- Parameters:
- listener- the new listener
 
- 
dragEnterThe cursor has entered the drop target boundaries. The current listener is updated, and#dragEnter()is forwarded to the current listener.- Specified by:
- dragEnterin interface- DropTargetListener
- Parameters:
- event- the drop target event
- See Also:
 
- 
dragLeaveThe cursor has left the drop target boundaries. The event is forwarded to the current listener.- Specified by:
- dragLeavein interface- DropTargetListener
- Parameters:
- event- the drop target event
- See Also:
 
- 
dragOperationChangedThe operation being performed has changed (usually due to the user changing a drag modifier key while dragging). Updates the current listener and forwards this event to that listener.- Specified by:
- dragOperationChangedin interface- DropTargetListener
- Parameters:
- event- the drop target event
- See Also:
 
- 
dragOverThe cursor is moving over the drop target. Updates the current listener and forwards this event to that listener. If no listener can handle the drag operation theevent.detailfield is set toDND.DROP_NONEto indicate an invalid drop.- Specified by:
- dragOverin interface- DropTargetListener
- Parameters:
- event- the drop target event
- See Also:
 
- 
dropForwards this event to the current listener, if there is one. Sets the current listener tonullafterwards.- Specified by:
- dropin interface- DropTargetListener
- Parameters:
- event- the drop target event
- See Also:
 
- 
dropAcceptForwards this event to the current listener if there is one.- Specified by:
- dropAcceptin interface- DropTargetListener
- Parameters:
- event- the drop target event
- See Also:
 
- 
getTransfersReturns the combined set ofTransfertypes of allTransferDropTargetListeners.- Returns:
- the combined set of Transfertypes
 
- 
isEmptypublic boolean isEmpty()Returnstrueif there are no listeners to delegate events to.- Returns:
- trueif there are no- TransferDropTargetListeners- falseotherwise
 
- 
removeDropTargetListenerRemoves the givenTransferDropTargetListener. Listeners should not be removed while a drag and drop operation is in progress.- Parameters:
- listener- the listener to remove
 
 
-