org.eclipse.swt.dnd.DropTargetEvent Java Examples

The following examples show how to use org.eclipse.swt.dnd.DropTargetEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: nebula   Author: eclipse   File: GridDropTargetEffect.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * This implementation of <code>dragLeave</code> provides a default drag under effect
 * for the feedback specified in <code>event.feedback</code>.
 * 
 * For additional information see <code>DropTargetAdapter.dragLeave</code>.
 * 
 * Subclasses that override this method should call <code>super.dragLeave(event)</code>
 * to get the default drag under effect implementation.
 *
 * @param event  the information associated with the drag leave event
 * 
 * @see DropTargetAdapter
 * @see DropTargetEvent
 */
public void dragLeave(DropTargetEvent event) {
	if (selectedCell != null)
	{
		deselect(selectedCell);
		selectedCell = null;
	}
	if (insertCell != null)
	{
		setInsertMark(null, false);
		insertCell = null;
	}
	expandBeginTime = 0;
	expandItem = null;
	scrollBeginTime = 0;
	scrollItem = null;
}
 
Example #2
Source Project: nebula   Author: eclipse   File: XViewerCustDialogDragDrop.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void performHiddenTableTextDrop(DropTargetEvent event) {

   String droppedIds = (String) event.data;

   List<XViewerColumn> droppedVisibleTableXCols = new ArrayList<>();
   List<XViewerColumn> orderCols =
      (List<XViewerColumn>) xViewerCustomizeDialog.visibleColTable.getViewer().getInput();
   for (XViewerColumn xCol : orderCols) {
      if (droppedIds.contains(xCol.getId())) {
         droppedVisibleTableXCols.add(xCol);
      }
   }

   xViewerCustomizeDialog.moveFromVisibleToHidden(droppedVisibleTableXCols);
}
 
Example #3
Source Project: ADT_Frontend   Author: abapGit   File: AbapGitStagingView.java    License: MIT License 6 votes vote down vote up
private void addDragAndDropSupport(TreeViewer viewer, final boolean unstaged) {
	viewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK,
			new Transfer[] { LocalSelectionTransfer.getTransfer(), LocalSelectionTransfer.getTransfer() },
			new StagingDragListener(viewer, ArrayContentProvider.getInstance(), unstaged));

	viewer.addDropSupport(DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK, new Transfer[] { LocalSelectionTransfer.getTransfer() },
			new DropTargetAdapter() {
				public void drop(DropTargetEvent event) {
					event.detail = DND.DROP_COPY;
					if (event.data instanceof IStructuredSelection) {
						IStructuredSelection selection = (IStructuredSelection) event.data;
						if (selection instanceof StagingDragSelection
								&& ((StagingDragSelection) selection).isFromUnstaged() == unstaged) {
							return;
						}
						if (((StagingDragSelection) selection).isFromUnstaged()) {
							stageSelectedObjects(selection);
						} else {
							unstageSelectedObjects(selection);
						}
					}
				}
			});
}
 
Example #4
Source Project: neoscada   Author: eclipse   File: DropAdapterExtension.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Collection<?> getDragSource ( final DropTargetEvent event )
{
    final ItemTransfer itemTransfer = ItemTransfer.getInstance ();
    if ( itemTransfer.isSupportedType ( event.currentDataType ) )
    {
        if ( IS_MOTIF )
        {
            return null;
        }

        final Object object = itemTransfer.nativeToJava ( event.currentDataType );
        return object == null ? null : extractDragSource ( object );
    }
    else
    {
        return super.getDragSource ( event );
    }
}
 
Example #5
Source Project: neoscada   Author: eclipse   File: DropAdapterExtension.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Collection<?> getDragSource ( final DropTargetEvent event )
{
    // Check whether the current data type can be transfered locally.
    //
    final ItemTransfer itemTransfer = ItemTransfer.getInstance ();
    if ( itemTransfer.isSupportedType ( event.currentDataType ) )
    {
        // Motif kludge: we would get something random instead of null.
        //
        if ( IS_MOTIF )
        {
            return null;
        }

        // Transfer the data and, if non-null, extract it.
        //
        final Object object = itemTransfer.nativeToJava ( event.currentDataType );
        return object == null ? null : extractDragSource ( object );
    }
    else
    {
        return super.getDragSource ( event );
    }
}
 
Example #6
Source Project: tmxeditor8   Author: heartsome   File: GridDropTargetEffect.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * This implementation of <code>dragLeave</code> provides a default drag under effect
 * for the feedback specified in <code>event.feedback</code>.
 * 
 * For additional information see <code>DropTargetAdapter.dragLeave</code>.
 * 
 * Subclasses that override this method should call <code>super.dragLeave(event)</code>
 * to get the default drag under effect implementation.
 *
 * @param event  the information associated with the drag leave event
 * 
 * @see DropTargetAdapter
 * @see DropTargetEvent
 */
public void dragLeave(DropTargetEvent event) {
	if (selectedCell != null)
	{
		deselect(selectedCell);
		selectedCell = null;
	}
	if (insertCell != null)
	{
		setInsertMark(null, false);
		insertCell = null;
	}
	expandBeginTime = 0;
	expandItem = null;
	scrollBeginTime = 0;
	scrollItem = null;
}
 
Example #7
Source Project: tracecompass   Author: tracecompass   File: FilterDropTargetAdapter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void drop(DropTargetEvent event) {
    ITmfFilterTreeNode treeNodeToDrop = FilterEditUtils.getTransferredTreeNode();
    if (event.item instanceof TreeItem) {
        Object data = event.item.getData();
        if (data instanceof ITmfFilterTreeNode) {
            ITmfFilterTreeNode node = (ITmfFilterTreeNode) data;
            if (node.getValidChildren().contains(treeNodeToDrop.getNodeName())) {
                treeNodeToDrop = treeNodeToDrop.clone();
                node.addChild(treeNodeToDrop);
                fViewer.refresh();
                fViewer.setSelection(treeNodeToDrop, true);
                return;
            }
        }
    } else { // accept only TmfFilterNode
        if (TmfFilterNode.NODE_NAME.equals(treeNodeToDrop.getNodeName())) {
            ITmfFilterTreeNode root = fViewer.getInput();
            treeNodeToDrop = treeNodeToDrop.clone();
            root.addChild(treeNodeToDrop);
            fViewer.refresh();
            fViewer.setSelection(treeNodeToDrop, true);
            return;
        }
    }
}
 
Example #8
Source Project: statecharts   Author: Yakindu   File: ExampleDropTargetListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private boolean dropTargetIsValid(DropTargetEvent e, boolean isDrop) {
	if (URLTransfer.getInstance().isSupportedType(e.currentDataType)) {
		// on Windows, we get the URL already during drag operations...
		// FIXME find a way to check the URL early on other platforms,
		// too...
		if (isDrop || Util.isWindows()) {
			if (e.data == null && !extractEventData(e)) {
				// ... but if we don't, it's no problem, unless this is
				// already
				// the final drop event
				return !isDrop;
			}
			final String url = getUrl(e.data);
			if (!ExampleURLHandler.isValidExample(url)) {
				return false;
			}
		}
		return true;
	}
	return false;
}
 
Example #9
Source Project: statecharts   Author: Yakindu   File: ExampleDropTargetListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void drop(DropTargetEvent event) {
	if (!URLTransfer.getInstance().isSupportedType(event.currentDataType)) {
		return;
	}
	final String url = getUrl(event.data);

	if (ExampleURLHandler.isValidExample(url)) {
		DropTarget source = (DropTarget) event.getSource();
		Display display = source.getDisplay();
		display.asyncExec(new Runnable() {
			public void run() {
				proceedInstallation(url);
			}
		});
	}
}
 
Example #10
Source Project: APICloud-Studio   Author: apicloudcom   File: AbstractThemeableEditor.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void drop(DropTargetEvent event)
{
	if (event.data instanceof SnippetElement)
	{
		SnippetElement snippet = (SnippetElement) event.data;
		CommandResult commandResult = CommandExecutionUtils.executeCommand(snippet, InvocationType.MENU,
				AbstractThemeableEditor.this);
		if (commandResult == null)
		{
			BundleElement bundle = snippet.getOwningBundle();
			String bundleName = (bundle == null) ? "Unknown bundle" : bundle.getDisplayName(); //$NON-NLS-1$
			IdeLog.logError(CommonEditorPlugin.getDefault(),
					MessageFormat.format("Error executing command {0} in bundle {1}. Command returned null.", //$NON-NLS-1$
							snippet.getDisplayName(), bundleName), IDebugScopes.DRAG_DROP);
		}
		else
		{
			CommandExecutionUtils.processCommandResult(snippet, commandResult, AbstractThemeableEditor.this);
			AbstractThemeableEditor.this.setFocus();
		}
	}
}
 
Example #11
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: JdtViewerDropAdapter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void dragOver(DropTargetEvent event) {
       //use newly revealed item as target if scrolling occurs
       Object target = determineTarget(event);

       //set the location feedback
       int oldLocation = currentLocation;
       currentLocation = determineLocation(event);
       setFeedback(event, currentLocation);

       //see if anything has really changed before doing validation.
       if (target != currentTarget || currentLocation != oldLocation) {
           currentTarget = target;
           doDropValidation(event);
       }
   }
 
Example #12
Source Project: birt   Author: eclipse   File: LibraryTemplateTransferDropTargetListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public void dragOver( DropTargetEvent event )
	{
		super.dragOver( event );
		if ( getTargetEditPart( ) == null )
		{
			event.detail = DND.DROP_NONE;
			return;
		}

//		if ( getTargetEditPart( ).getModel( ) instanceof LibraryHandle )
//		{
//			List list = getTargetEditPart( ).getChildren( );
//			if ( list.size( ) > 0 && !( list.get( 0 ) instanceof EmptyEditPart ) )
//			{
//				event.detail = DND.DROP_NONE;
//			}
//		}

	}
 
Example #13
Source Project: translationstudio8   Author: heartsome   File: GridDropTargetEffect.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * This implementation of <code>dragLeave</code> provides a default drag under effect
 * for the feedback specified in <code>event.feedback</code>.
 * 
 * For additional information see <code>DropTargetAdapter.dragLeave</code>.
 * 
 * Subclasses that override this method should call <code>super.dragLeave(event)</code>
 * to get the default drag under effect implementation.
 *
 * @param event  the information associated with the drag leave event
 * 
 * @see DropTargetAdapter
 * @see DropTargetEvent
 */
public void dragLeave(DropTargetEvent event) {
	if (selectedCell != null)
	{
		deselect(selectedCell);
		selectedCell = null;
	}
	if (insertCell != null)
	{
		setInsertMark(null, false);
		insertCell = null;
	}
	expandBeginTime = 0;
	expandItem = null;
	scrollBeginTime = 0;
	scrollItem = null;
}
 
Example #14
Source Project: tmxeditor8   Author: heartsome   File: TmxEditorViewer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
	parent.setLayout(new FillLayout());
	this.container = parent;
	CellEditorGlobalActionHanlder.getInstance().setIActionBars(getViewSite().getActionBars());
	DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY);
	Transfer[] tfs = new Transfer[] { FileTransfer.getInstance() };
	target.setTransfer(tfs);
	target.addDropListener(new DropTargetAdapter() {
		@Override
		public void drop(DropTargetEvent event) {
			Object o = event.data;
			if (o instanceof String[]) {
				String[] s = (String[]) o;
				if (s.length == 0 && s[0] == null || s[0].length() == 0) {
					return;
				}
				File f = new File(s[0]);
				if (f.exists() && f.isFile()) {
					open(f);
				}
			}
		}
	});
}
 
Example #15
Source Project: hop   Author: project-hop   File: TabFolderReorder.java    License: Apache License 2.0 5 votes vote down vote up
private void moveTabs( CTabFolder folder, DropTargetEvent event ) {
  Point point = folder.toControl( folder.getDisplay().getCursorLocation() );
  CTabItem item = folder.getItem( new Point( point.x, point.y ) );
  if ( item != null && dragItem != null ) {
    Control dragControl = dragItem.getControl();
    String dragText = dragItem.getText();
    Image dragImage = dragItem.getImage();
    String dragToolTip = dragItem.getToolTipText();
    boolean dragShowClose = dragItem.getShowClose();
    Object dragData = dragItem.getData();

    dragItem.setText( item.getText() );
    dragItem.setImage( item.getImage() );
    dragItem.setToolTipText( item.getToolTipText() );
    dragItem.setData( item.getData() );
    dragItem.setShowClose( item.getShowClose() );
    dragItem.setControl( item.getControl() );

    item.setText( dragText );
    item.setImage( dragImage );
    item.setToolTipText( dragToolTip );
    item.setData( dragData );
    item.setShowClose( dragShowClose );
    item.setControl( dragControl );

    folder.setSelection( item );
  }
}
 
Example #16
Source Project: nebula   Author: eclipse   File: XViewerCustomizeDialog.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void performHiddenTableTextDrop(DropTargetEvent event) {

   String droppedIds = (String) event.data;

   List<XViewerColumn> droppedVisibleTableXCols = new ArrayList<>();
   List<XViewerColumn> orderCols = (List<XViewerColumn>) visibleColTable.getViewer().getInput();
   for (XViewerColumn xCol : orderCols) {
      if (droppedIds.contains(xCol.getId())) {
         droppedVisibleTableXCols.add(xCol);
      }
   }

   moveFromVisibleToHidden(droppedVisibleTableXCols);
}
 
Example #17
Source Project: nebula   Author: eclipse   File: XViewerCustDialogDragDrop.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Drag should only be from visible table
 */
public void performHiddenTableDragOver(DropTargetEvent event) {
   if (!TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
      event.detail = DND.DROP_NONE;
      return;
   }
   // Only allow drag from visibleColTable
   if (event.widget != xViewerCustomizeDialog.visibleColTable) {
      return;
   }

   event.detail = DND.DROP_MOVE;
}
 
Example #18
Source Project: tracecompass   Author: tracecompass   File: FilterDropTargetAdapter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void dropAccept(DropTargetEvent event) {
    ITmfFilterTreeNode treeNodeToDrop = null;
    if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
        treeNodeToDrop = FilterEditUtils.getTransferredTreeNode();
    }
    if (treeNodeToDrop == null) {
        // should never occur
        event.detail = DND.DROP_NONE;
        return;
    }
    if (event.item instanceof TreeItem) {
        Object data = event.item.getData();
        if (data instanceof ITmfFilterTreeNode) {
            ITmfFilterTreeNode node = (ITmfFilterTreeNode) data;
            if (node.getValidChildren().contains(treeNodeToDrop.getNodeName())) {
                if (isAncestor(treeNodeToDrop, node) && event.detail != DND.DROP_COPY) {
                    // do nothing in this case
                    event.detail = DND.DROP_NONE;
                }
                return;
            }
        }
    } else { // accept only TmfFilterNode
        if (!TmfFilterNode.NODE_NAME.equals(treeNodeToDrop.getNodeName())) {
            event.detail = DND.DROP_NONE;
        }
        return;
    }
    event.detail = DND.DROP_NONE;
    return;
}
 
Example #19
Source Project: statecharts   Author: Yakindu   File: ExampleDropTargetListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void setDropOperation(DropTargetEvent e) {
	int allowedOperations = e.operations;
	for (int op : PREFERRED_DROP_OPERATIONS) {
		if ((allowedOperations & op) != 0) {
			e.detail = op;
			return;
		}
	}
	e.detail = allowedOperations;
}
 
Example #20
Source Project: statecharts   Author: Yakindu   File: ExampleDropTargetListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private boolean extractEventData(DropTargetEvent e) {
	TransferData transferData = e.currentDataType;
	if (transferData != null) {
		Object data = URLTransfer.getInstance().nativeToJava(transferData);
		if (data != null && getUrl(data) != null) {
			e.data = data;
			return true;
		}
	}
	return false;
}
 
Example #21
Source Project: LogViewer   Author: anb0s   File: LogViewer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void createPartControl(Composite parent) {
    //viewer
    this.parent = parent;
    documentListener = new ViewDocumentListener();
    tabfolder = new TabFolder(parent,0);
    tabfolder.addSelectionListener(new TabSelectionListener());
    viewer = new LogFileViewer(tabfolder,SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);

    // DnD
    DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
    target.setTransfer(new Transfer[] {FileTransfer.getInstance(), TextTransfer.getInstance()});
    target.addDropListener (new DropTargetAdapter() {
        public void dragEnter(DropTargetEvent e) {
            if (e.detail == DND.DROP_NONE)
                e.detail = DND.DROP_COPY;
        }
        public void drop(DropTargetEvent event) {
            if (event.data == null || ((String[])event.data).length < 1) {
                event.detail = DND.DROP_NONE;
                return;
            }
            //File file = new File(((String[])event.data)[0]);
            if (!checkAndOpenFile(LogFileType.LOGFILE_SYSTEM_FILE,((String[])event.data)[0], null, false))
                event.detail = DND.DROP_NONE;
        }
    });

    // fill the menues
    makeActions();
    hookContextMenu();
    contributeToActionBars();
    openAllLastOpenFiles();
}
 
Example #22
Source Project: gama   Author: gama-platform   File: NavigatorDropAssistant.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public IStatus handleDrop(final CommonDropAdapter adapter, final DropTargetEvent event, final Object target) {
	if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
		final String[] files = (String[]) event.data;
		if (files != null && files.length > 0) {
			PasteAction.handlePaste(files);
			return Status.OK_STATUS;
		}
	} else if (ResourceTransfer.getInstance().isSupportedType(event.currentDataType)) {

	}
	return Status.CANCEL_STATUS;
}
 
Example #23
Source Project: APICloud-Studio   Author: apicloudcom   File: AbstractThemeableEditor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void dragOver(DropTargetEvent event)
{
	if (event.data instanceof SnippetElement)
	{
		event.feedback |= DND.FEEDBACK_SCROLL;
	}
}
 
Example #24
Source Project: APICloud-Studio   Author: apicloudcom   File: AbstractThemeableEditor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void dragEnter(DropTargetEvent event)
{
	if (event.data instanceof SnippetElement)
	{
		event.detail = DND.DROP_COPY;
	}
}
 
Example #25
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: FileTransferDropAdapter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isEnabled(DropTargetEvent event) {
	Object target= event.item != null ? event.item.getData() : null;
	if (target == null)
		return false;
	return target instanceof IJavaElement || target instanceof IResource;
}
 
Example #26
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: WorkingSetDropAdapter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isEnabled(DropTargetEvent event) {
	Object target= event.item != null ? event.item.getData() : null;
	if (target == null)
		return false;
	ISelection selection= LocalSelectionTransfer.getInstance().getSelection();
	if (!isValidSelection(selection)) {
		return false;
	}
	if (!isValidTarget(target))
		return false;

	initializeState(target, selection);
	return true;
}
 
Example #27
/**
 * {@inheritDoc}
 */
public boolean isEnabled(DropTargetEvent event) {
	Object target= event.item != null ? event.item.getData() : null;
	if (target == null)
		return false;
	return target instanceof IJavaElement || target instanceof IResource;
}
 
Example #28
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: ViewerInputDropAdapter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Object determineTarget(DropTargetEvent event) {
	if (event.item == null)
		return super.determineTarget(event);

	Point coordinates= getViewer().getControl().toControl(new Point(event.x, event.y));
	Rectangle bounds= getBounds((Item) event.item);
	if (coordinates.x < bounds.x - ITEM_MARGIN_LEFT || coordinates.x >= bounds.x + bounds.width + ITEM_MARGIN_RIGTH) {
		event.item= null; // too far away
		return null;
	}

	return super.determineTarget(event);
}
 
Example #29
Source Project: birt   Author: eclipse   File: ReportTemplateTransferDropTargetListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void dragOver( DropTargetEvent event )
{
	super.dragOver( event );
	if ( !handleValidateDrag( TemplateTransfer.getInstance( ).getTemplate( ) ) )
	{
		event.detail = DND.DROP_NONE;
	}
}
 
Example #30
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: JdtViewerDropAdapter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void drop(DropTargetEvent event) {
       currentLocation = determineLocation(event);

       //perform the drop behavior
       if (!performDrop(event.data)) {
           event.detail = DND.DROP_NONE;
       }
       currentOperation = event.detail;
   }