001: package net.refractions.udig.internal.ui;
002:
003: import net.refractions.udig.ui.UDIGDropTargetListener;
004:
005: import org.eclipse.jface.viewers.ISelection;
006: import org.eclipse.jface.viewers.ISelectionChangedListener;
007: import org.eclipse.jface.viewers.ISelectionProvider;
008: import org.eclipse.jface.viewers.StructuredSelection;
009: import org.eclipse.swt.dnd.DropTargetAdapter;
010: import org.eclipse.swt.dnd.DropTargetEvent;
011:
012: public class UDIGControlDropListener extends DropTargetAdapter
013: implements UDIGDropTargetListener {
014:
015: UDIGDropHandler handler;
016: private IDropTargetProvider destinationProvider;
017:
018: public UDIGControlDropListener(
019: IDropTargetProvider destinationProvider) {
020: handler = new UDIGDropHandler();
021: if (destinationProvider == null)
022: destinationProvider = new NullProvider();
023: this .destinationProvider = destinationProvider;
024: }
025:
026: private void initHandler(DropTargetEvent event) {
027: handler.setTarget(destinationProvider.getTarget(event));
028: }
029:
030: public void dragEnter(DropTargetEvent event) {
031: initHandler(event);
032: handler.dragEnter(event);
033: }
034:
035: public void dragOperationChanged(DropTargetEvent event) {
036: initHandler(event);
037: handler.dragOperationChanged(event);
038: }
039:
040: @Override
041: public void dragLeave(DropTargetEvent event) {
042: initHandler(event);
043: handler.dragLeave(event);
044: }
045:
046: @Override
047: public void dragOver(DropTargetEvent event) {
048: initHandler(event);
049: handler.dragOver(event);
050: }
051:
052: @Override
053: public void dropAccept(DropTargetEvent event) {
054: initHandler(event);
055: handler.dropAccept(event);
056: }
057:
058: public void drop(DropTargetEvent event) {
059: initHandler(event);
060: handler.drop(event);
061: }
062:
063: public UDIGDropHandler getHandler() {
064: return handler;
065: }
066:
067: /**
068: * Returns nulls
069: * @author jones
070: * @since 1.0.0
071: */
072: public static class NullProvider implements ISelectionProvider,
073: IDropTargetProvider {
074:
075: public void addSelectionChangedListener(
076: ISelectionChangedListener listener) {
077: }
078:
079: public ISelection getSelection() {
080: return new StructuredSelection();
081: }
082:
083: public void removeSelectionChangedListener(
084: ISelectionChangedListener listener) {
085: }
086:
087: public void setSelection(ISelection selection) {
088: }
089:
090: public Object getTarget(DropTargetEvent event) {
091: return null;
092: }
093:
094: }
095:
096: public IDropTargetProvider getDropTargetProvider() {
097: return destinationProvider;
098: }
099:
100: public void setDropTargetProvider(IDropTargetProvider newProvider) {
101: destinationProvider = newProvider;
102: }
103: }
|