Bug 235136 - [DND] ViewerDropAdapter is not supporting new URLTransfer
Summary: [DND] ViewerDropAdapter is not supporting new URLTransfer
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2008-06-02 09:51 EDT by Benjamin Pasero CLA
Modified: 2021-10-07 16:42 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Pasero CLA 2008-06-02 09:51:12 EDT
Eclipse 3.4 RC1

I tried using the ViewerDropAdapter for my TreeViewer together with the new URLTransfer in SWT since 3.4. I was not able to get a valid DND feedback for some reason. See the following snippet as example:

/*******************************************************************************
 * Copyright (c) 2006 Tom Schindl and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tom Schindl - initial API and implementation
 *******************************************************************************/

package org.eclipse.jface.snippets.viewers;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.swt.dnd.URLTransfer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import java.util.ArrayList;

/**
 * A simple TreeViewer to demonstrate usage
 *
 * @author Tom Schindl <tom.schindl@bestsolution.at>
 */
public class Snippet002TreeViewer {
  private class MyContentProvider implements ITreeContentProvider {

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
     */
    public Object[] getElements(Object inputElement) {
      return ((MyModel) inputElement).child.toArray();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
     */
    public void dispose() {

    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
     */
    public Object[] getChildren(Object parentElement) {
      return getElements(parentElement);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
     */
    public Object getParent(Object element) {
      if (element == null) {
        return null;
      }

      return ((MyModel) element).parent;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
     */
    public boolean hasChildren(Object element) {
      return ((MyModel) element).child.size() > 0;
    }

  }

  public class MyModel {
    public MyModel parent;
    public ArrayList child = new ArrayList();
    public int counter;

    public MyModel(int counter, MyModel parent) {
      this.parent = parent;
      this.counter = counter;
    }

    public String toString() {
      String rv = "Item ";
      if (parent != null) {
        rv = parent.toString() + ".";
      }

      rv += counter;

      return rv;
    }
  }

  public Snippet002TreeViewer(Shell shell) {
    final TreeViewer v = new TreeViewer(shell);
    v.setLabelProvider(new LabelProvider());
    v.setContentProvider(new MyContentProvider());
    v.setInput(createModel());

    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
    v.addDropSupport(operations, new Transfer[] { URLTransfer.getInstance() }, new ViewerDropAdapter(v) {
      public boolean performDrop(Object data) {
        return true;
      }

      public boolean validateDrop(Object target, int operation, TransferData transferType) {
        return true;
      }

      public void dragEnter(DropTargetEvent e) {
        super.dragEnter(e);

//        if (e.detail == DND.DROP_NONE)
//          e.detail = DND.DROP_LINK;
      }
    });
  }

  private MyModel createModel() {

    MyModel root = new MyModel(0, null);
    root.counter = 0;

    MyModel tmp;
    for (int i = 1; i < 10; i++) {
      tmp = new MyModel(i, root);
      root.child.add(tmp);
      for (int j = 1; j < i; j++) {
        tmp.child.add(new MyModel(j, tmp));
      }
    }

    return root;
  }

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    new Snippet002TreeViewer(shell);
    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }

    display.dispose();
  }
}


It only works when I override dragEnter() to set the detail accordingly.
Comment 1 Kim Horne CLA 2008-06-02 12:44:32 EDT
Not sure if this should be SWT or not.
Comment 2 Eric Moffatt CLA 2008-06-02 14:39:40 EDT
Ben, do you know where the ViewerDropAdapter is broken ? A quick look indicates that 'doDropValidation' will only show 'lastValidOperation' but then only if it's -not- DROP_NONE....this seems suspicious.

I'm going to mark this one 'helpwanted' so if you track it down and attach a patch I'd be glad to review it...the current implementation seems a bit flakey to me, I think we're trying to 'abstract away' too much. For my money 'validateDrop' shouldn't return a boolean, it should return the event.detail...

Comment 3 Benjamin Pasero CLA 2008-06-03 02:00:11 EDT
Hi Eric,
hmm looking more into this, this does not seem to be a bug in Eclipse at all. It seems the detail field of the DropTargetEvent is DND.DROP_NONE when dragging a link from IE to the Snippet. However, dragging a link from Firefox to the Snippet correctly shows the feedback. Maybe this should be moved to SWT for a comment.
Comment 4 Eric Moffatt CLA 2008-06-03 15:17:47 EDT
Steve, do you know of any differences between the drag source as generated by IE vs FireFox ??
Comment 5 Steve Northover CLA 2008-06-03 15:21:36 EDT
Duong, do you know the answer?
Comment 6 Duong Nguyen CLA 2008-06-03 18:24:53 EDT
When an item is dragged over the drop target, SWT checks to see if the allowed operations (copy, move, link) is available in the drop target (intersection of the operations). If there is no common operation, the operation will be DND.DROP_NONE.

So, IE and Firefox can specify different operations that will affect the drop target.
Comment 7 Duong Nguyen CLA 2008-06-03 18:26:05 EDT
I forgot to mention that the allowed operations are specified by the source.
Comment 8 Eric Moffatt CLA 2008-06-03 19:03:23 EDT
Doung, I just ran the code with a breakpoint on the 'dragEnter' (Line 133).

When I drag a file from FFox the BP fires, from IE...not.

I also put a BP at line 59 of DNDListener (DBD.DragEner handler) and it doesn't fire. Any idea why?

I don't think it's a mis-match in the operations, the adapter registers to use all three 'standard' ops (MOVE, COPY & LINK).

My guess is that IE doesn't actually generate the transferType that URLTransfer needs.


Comment 9 Eclipse Webmaster CLA 2019-09-06 16:10:46 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 10 Eclipse Genie CLA 2021-10-07 16:42:43 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.