All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.event.swt.XMADropTargetAdapter Maven / Gradle / Ivy

/*
 * @(#) $Id: XMADropTargetAdapter.java 2605 2008-06-20 13:21:29Z gub $
 *
 * Copyright 2004/2005 by SPARDAT Sparkassen-Datendienst Ges.m.b.H.,
 * A-1110 Wien, Geiselbergstr.21-25.
 * All rights reserved.
 *
 */
package at.spardat.xma.event.swt;

import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;

import at.spardat.xma.page.IDialogPage;
import at.spardat.xma.page.PageClient;

/**
 * DropTargetAdapter for DropTargetListener.
 * It wraps event-disabling code of XMA around your event handling code.
 * (see package description)
 *
 * The javadoc comments of the impl methods are copied from org.eclipse.swt.dnd.DropTargetListener
 */
public class XMADropTargetAdapter implements DropTargetListener {

    PageClient page;

    /**
    *
    * @param page The page containing the widget on which you want to listen for events.
    */
    public XMADropTargetAdapter(PageClient page) {
        this.page=page;
    }

    /**
     * Returns the page passed to the contructor
     */
    public PageClient getPage() {
        return page;
    }

    /**
     * The cursor has entered the drop target boundaries.
     *
     * 

The following fields in the DropTargetEvent apply: *

    *
  • (in)widget *
  • (in)time *
  • (in)x *
  • (in)y *
  • (in)dataTypes *
  • (in,out)currentDataType *
  • (in)operations *
  • (in,out)detail *
  • (in,out)feedback *

* *

The operation value is determined by the modifier keys pressed by the user. * If no keys are pressed the event.detail field is set to DND.DROP_DEFAULT. * If the application does not set the event.detail to something other * than DND.DROP_DEFAULT the operation will be set to the platform defined standard * default.

* *

The currentDataType is determined by the first transfer agent specified in * setTransfer() that matches a data type provided by the drag source.

* *

It is possible to get a DragEnter event when the drag source does not provide any matching data. * In this case, the default operation is DND.DROP_NONE and the currentDataType is null.

* *

The application can change the operation that will be performed by modifying the * detail field but the choice must be one of the values in the operations * field or DND.DROP_NONE.

* *

The application can also change the type of data being requested by * modifying the currentDataTypes field but the value must be one of the values * in the dataTypes list.

* * @param event the information associated with the drag enter event * * @see DropTargetEvent */ public void dragEnterImpl(DropTargetEvent event) { } /** * The method called by SWT whenever the corresponding event happends. * To not overload this method, overload {@link #dragEnterImpl(DropTargetEvent)} * instead. * @param event The event send by SWT. */ final public void dragEnter(DropTargetEvent event) { if(!page.isEventsEnabled()) return; IDialogPage dialog = page.getDialogPage(); try { dialog.setEventsEnabled(false); dragEnterImpl(event); } catch (Exception exc) { page.showException(exc); } finally { dialog.setEventsEnabled(true); } } /** * The cursor has left the drop target boundaries OR the drop has been cancelled OR the data * is about to be dropped. * *

The following fields in the DropTargetEvent apply: *

    *
  • (in)widget *
  • (in)time *
  • (in)x *
  • (in)y *
  • (in)dataTypes *
  • (in)currentDataType *
  • (in)operations *
  • (in)detail *

* * @param event the information associated with the drag leave event * * @see DropTargetEvent */ public void dragLeaveImpl(DropTargetEvent event) { } /** * The method called by SWT whenever the corresponding event happends. * To not overload this method, overload {@link #dragLeaveImpl(DropTargetEvent)} * instead. * @param event The event send by SWT. */ final public void dragLeave(DropTargetEvent event) { if(!page.isEventsEnabled()) return; IDialogPage dialog = page.getDialogPage(); try { dialog.setEventsEnabled(false); dragLeaveImpl(event); } catch (Exception exc) { page.showException(exc); } finally { dialog.setEventsEnabled(true); } } /** * The operation being performed has changed (usually due to the user changing the selected modifier key(s) * while dragging). * *

The following fields in the DropTargetEvent apply: *

    *
  • (in)widget *
  • (in)time *
  • (in)x *
  • (in)y *
  • (in)dataTypes *
  • (in,out)currentDataType *
  • (in)operations *
  • (in,out)detail *
  • (in,out)feedback *

* *

The operation value is determined by the modifier keys pressed by the user. * If no keys are pressed the event.detail field is set to DND.DROP_DEFAULT. * If the application does not set the event.detail to something other than * DND.DROP_DEFAULT the operation will be set to the platform defined standard default.

* *

The currentDataType value is determined by the value assigned to * currentDataType in previous dragEnter and dragOver calls.

* *

The application can change the operation that will be performed by modifying the * detail field but the choice must be one of the values in the operations * field.

* *

The application can also change the type of data being requested by modifying * the currentDataTypes field but the value must be one of the values in the * dataTypes list.

* * @param event the information associated with the drag operation changed event * * @see DropTargetEvent */ public void dragOperationChangedImpl(DropTargetEvent event) { } /** * The method called by SWT whenever the corresponding event happends. * To not overload this method, overload {@link #dragOperationChangedImpl(DropTargetEvent)} * instead. * @param event The event send by SWT. */ final public void dragOperationChanged(DropTargetEvent event) { if(!page.isEventsEnabled()) return; IDialogPage dialog = page.getDialogPage(); try { dialog.setEventsEnabled(false); dragOperationChangedImpl(event); } catch (Exception exc) { page.showException(exc); } finally { dialog.setEventsEnabled(true); } } /** * The data is being dropped. The data field contains java format of the data being dropped. * To determine the type of the data object, refer to the documentation for the Transfer subclass * specified in event.currentDataType. * *

The following fields in DropTargetEvent apply: *

    *
  • (in)widget *
  • (in)time *
  • (in)x *
  • (in)y *
  • (in,out)detail *
  • (in)currentDataType *
  • (in)data *

* *

The application can refuse to perform the drop operation by setting the detail * field to DND.DROP_NONE.

* * @param event the information associated with the drop event * * @see DropTargetEvent */ public void dropImpl(DropTargetEvent event) { } /** * The method called by SWT whenever the corresponding event happends. * To not overload this method, overload {@link #dropImpl(DropTargetEvent)} * instead. * @param event The event send by SWT. */ final public void drop(DropTargetEvent event) { if(!page.isEventsEnabled()) return; IDialogPage dialog = page.getDialogPage(); try { dialog.setEventsEnabled(false); dropImpl(event); } catch (Exception exc) { page.showException(exc); } finally { dialog.setEventsEnabled(true); } } /** * The drop is about to be performed. * The drop target is given a last chance to change the nature of the drop. * *

The following fields in the DropTargetEvent apply: *

    *
  • (in)widget *
  • (in)time *
  • (in)x *
  • (in)y *
  • (in)dataTypes *
  • (in,out)currentDataType *
  • (in)operations *
  • (in,out)detail *

* *

The application can veto the drop by setting the event.detail field to * DND.DROP_NONE.

* *

The application can change the operation that will be performed by modifying the * detail field but the choice must be one of the values in the * operations field.

* *

The application can also change the type of data being requested by modifying the * currentDataTypes field but the value must be one of the values in the < * code>dataTypes list.

* * @param event the information associated with the drop accept event * * @see DropTargetEvent */ public void dropAcceptImpl(DropTargetEvent event) { } /** * The method called by SWT whenever the corresponding event happends. * To not overload this method, overload {@link #dropAcceptImpl(DropTargetEvent)} * instead. * @param event The event send by SWT. */ final public void dropAccept(DropTargetEvent event) { if(!page.isEventsEnabled()) return; IDialogPage dialog = page.getDialogPage(); try { dialog.setEventsEnabled(false); dropAcceptImpl(event); } catch (Exception exc) { page.showException(exc); } finally { dialog.setEventsEnabled(true); } } /** * The cursor is moving over the drop target. * This method is not overwritten by the XMADropTargetAdapter as it is called so often. * *

The following fields in the DropTargetEvent apply: *

    *
  • (in)widget *
  • (in)time *
  • (in)x *
  • (in)y *
  • (in)dataTypes *
  • (in,out)currentDataType *
  • (in)operations *
  • (in,out)detail *
  • (in,out)feedback *

* *

The operation value is determined by the value assigned to * currentDataType in previous dragEnter and dragOver calls.

* *

The currentDataType value is determined by the value assigned to * currentDataType in previous dragEnter and dragOver calls.

* *

The application can change the operation that will be performed by modifying the * detail field but the choice must be one of the values in the operations * field.

* *

The application can also change the type of data being requested by modifying the * currentDataTypes field but the value must be one of the values in the * dataTypes list.

* *

NOTE: At this point the data field is null. On some platforms, it is possible * to obtain the data being transferred before the transfer occurs but in most platforms this is * not possible. On those platforms where the data is available, the application can access the * data as follows:

* *

     * public void dragOver(DropTargetEvent event) {
     *       TextTransfer textTransfer = TextTransfer.getInstance();
     *       String data = (String)textTransfer.nativeToJava(event.currentDataType);
     *       if (data != null) {
     *           System.out.println("Data to be dropped is (Text)"+data);
     *       }
     * };
     * 
* * @param event the information associated with the drag over event * * @see DropTargetEvent */ public void dragOver(DropTargetEvent event) { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy