Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Stupid (hopefully easy) drag and drop question
Stupid (hopefully easy) drag and drop question [message #436588] Thu, 20 May 2004 03:47 Go to next message
Mark Victory is currently offline Mark VictoryFriend
Messages: 133
Registered: July 2009
Senior Member
I am implementing drag and drop in some tree based views.

There are essentially two potential drop states when dragging over an item
in my tree:

1. Cannot drop DND.DROP_NONE
2. Drop based on the state of the control key press - Either DND.DROP_MOVE
or DND.DROP_COPY

In my implementation, If I ever set the drop event.detail to DND.DROP_NONE
in my dragOver method then it never get's set back when dragging over an
item that is OK to drop on.

Does my code have to check the state of the ctrl key and set the
event.detail to DND.DROP_MOVE or DND.DROP_COPY appropriately? Seems like
the drag and drop machinery should be able to do that. I tried setting to
DND.DROP_DEFAULT but that always results in a DND.DROP_MOVE even if the ctrl
key is down, indicating it should be DND.DROP_COPYing.

Any ideas,
Mark
Re: Stupid (hopefully easy) drag and drop question [message #436643 is a reply to message #436588] Fri, 21 May 2004 13:11 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Please post your code showing the problem.

The event.detail field only gets changed if the user presses a key. If you
have set it to DND.DROP_NONE then as you move the mouse, it will stay as
DND.DROP_NONE.

When the user presses or releases a key, you will get the
dragOperationChanged notification. In that event callback the event.detail
field is set to match the current user key combination. Note that if the
user has Ctrl down and you do not support DND.DROP_COPY, then the
event.detail will be DND.DROP_NONE. You should not be checking for specific
keys because the meaning of the keys differs from platform to platform.

See:

http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.h tml

"Mark Victory" <MVictory@us.ibm.com> wrote in message
news:c8h8s4$7ck$1@eclipse.org...
> I am implementing drag and drop in some tree based views.
>
> There are essentially two potential drop states when dragging over an item
> in my tree:
>
> 1. Cannot drop DND.DROP_NONE
> 2. Drop based on the state of the control key press - Either
DND.DROP_MOVE
> or DND.DROP_COPY
>
> In my implementation, If I ever set the drop event.detail to DND.DROP_NONE
> in my dragOver method then it never get's set back when dragging over an
> item that is OK to drop on.
>
> Does my code have to check the state of the ctrl key and set the
> event.detail to DND.DROP_MOVE or DND.DROP_COPY appropriately? Seems like
> the drag and drop machinery should be able to do that. I tried setting to
> DND.DROP_DEFAULT but that always results in a DND.DROP_MOVE even if the
ctrl
> key is down, indicating it should be DND.DROP_COPYing.
>
> Any ideas,
> Mark
>
>
Re: Stupid (hopefully easy) drag and drop question [message #436797 is a reply to message #436643] Mon, 24 May 2004 15:15 Go to previous messageGo to next message
Mark Victory is currently offline Mark VictoryFriend
Messages: 133
Registered: July 2009
Senior Member
Hi Veronika,

Here's my code - just the drop listener.

target.addDropListener (new DropTargetAdapter() {
public void dragOver(DropTargetEvent event)
{
ModelElement destEle = (ModelElement)event.item.getData();

//Different feedback based on the type of object dragged over
if (destEle.getType() == IModelElement.TYPE_BLOCK)
event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL |
DND.FEEDBACK_SELECT;
else
event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL |
DND.FEEDBACK_INSERT_BEFORE;


//********************************************************** ************
//Below is where the problem lies. I want the ELSE clause to set the
detail to be
//whatever the operation should be based on the key state - either
Copy or Move
//If I don't do the event.detail = DND.DROP_DEFAULT then the detail
will never be
//other than DND.DROP_NONE if it was ever set to DND.DROP_NONE
farther down in the code.
//I'm sure I'm just missing something obvious
//********************************************************** ************
//If the drag is from a particular view (favorites) then we ONLY copy
from there.
LocalSelectionTransfer lst = (LocalSelectionTransfer)types[0];
MTTransfer transfer = (MTTransfer)lst.getSelection();
if (transfer.getSource() == MTTransfer.FAVORITES)
event.detail = DND.DROP_COPY;
else
event.detail = DND.DROP_DEFAULT;


//Don't allow self dropping or dropping on successors as this causes a
recursive structure
StructuredSelection sourceSel = (StructuredSelection)transfer.getData();

//Iterate over all the selected items to see if the destination is valid
Iterator iter = sourceSel.iterator();
while (iter.hasNext())
{
ModelElement ele = (ModelElement)iter.next();
//Don't allow dropping if the item dragged over is an ancestor of the
item being dragged
if (ele.isAncestorOf(destEle))
{
event.detail = DND.DROP_NONE;
return;
}

}

}
"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:c8kuo8$die$1@eclipse.org...
> Please post your code showing the problem.
>
> The event.detail field only gets changed if the user presses a key. If
you
> have set it to DND.DROP_NONE then as you move the mouse, it will stay as
> DND.DROP_NONE.
>
> When the user presses or releases a key, you will get the
> dragOperationChanged notification. In that event callback the
event.detail
> field is set to match the current user key combination. Note that if the
> user has Ctrl down and you do not support DND.DROP_COPY, then the
> event.detail will be DND.DROP_NONE. You should not be checking for
specific
> keys because the meaning of the keys differs from platform to platform.
>
> See:
>
> http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.h tml
>
> "Mark Victory" <MVictory@us.ibm.com> wrote in message
> news:c8h8s4$7ck$1@eclipse.org...
> > I am implementing drag and drop in some tree based views.
> >
> > There are essentially two potential drop states when dragging over an
item
> > in my tree:
> >
> > 1. Cannot drop DND.DROP_NONE
> > 2. Drop based on the state of the control key press - Either
> DND.DROP_MOVE
> > or DND.DROP_COPY
> >
> > In my implementation, If I ever set the drop event.detail to
DND.DROP_NONE
> > in my dragOver method then it never get's set back when dragging over an
> > item that is OK to drop on.
> >
> > Does my code have to check the state of the ctrl key and set the
> > event.detail to DND.DROP_MOVE or DND.DROP_COPY appropriately? Seems
like
> > the drag and drop machinery should be able to do that. I tried setting
to
> > DND.DROP_DEFAULT but that always results in a DND.DROP_MOVE even if the
> ctrl
> > key is down, indicating it should be DND.DROP_COPYing.
> >
> > Any ideas,
> > Mark
> >
> >
>
>
Re: Stupid (hopefully easy) drag and drop question [message #436843 is a reply to message #436797] Tue, 25 May 2004 19:49 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
You are not using DND.DROP_DEFAULT correctly. It does not mean, perform the
the default operation for the current key state. It means perform the
operation that occurs when no modifier keys are pressed. The application is
not supposed to set the DND.DROP_DEFAULT into the event.detail field.
Instead, it is supposed to receive an event with the detail field set to
DND.DROP_DEFAULT and it should then change the value of event.detail to what
the application wants the default operation to be (usually DND.DROP_MOVE or
DND.DROP_COPY - if teh application does nothing, it will be set to
DND.DROP_MOVE).

If you want to change the operation depending on what target you are over,
then you will need to remember what the current key operation is in the
dragOperationChanged event:

target.addDropListener (new DropTargetAdapter() {
int currentOp = DND.DROP_NONE;
public void dragEnter(DropTargetEvent event) {
currentOp = event.detail;
}
public void dragOver(DropTargetEvent event) {
if (transfer.getSource() == MTTransfer.FAVORITES)
event.detail = DND.DROP_COPY; // this is a bit bogus - you
should really check that the current op is COPY or DEFAULT - if the current
op is MOVE and you don't support MOVE, you should set the event.detail to
NONE
else
event.detail = currentOp;
}
public void dragOperationChanged(DropTargetEvent event) {
currentOp = event.detail;
}
}


"Mark Victory" <MVictory@us.ibm.com> wrote in message
news:c8t2mf$kd7$1@eclipse.org...
> Hi Veronika,
>
> Here's my code - just the drop listener.
>
> target.addDropListener (new DropTargetAdapter() {
> public void dragOver(DropTargetEvent event)
> {
> ModelElement destEle = (ModelElement)event.item.getData();
>
> //Different feedback based on the type of object dragged over
> if (destEle.getType() == IModelElement.TYPE_BLOCK)
> event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL |
> DND.FEEDBACK_SELECT;
> else
> event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL |
> DND.FEEDBACK_INSERT_BEFORE;
>
>
>
//********************************************************** ************
> //Below is where the problem lies. I want the ELSE clause to set the
> detail to be
> //whatever the operation should be based on the key state - either
> Copy or Move
> //If I don't do the event.detail = DND.DROP_DEFAULT then the
detail
> will never be
> //other than DND.DROP_NONE if it was ever set to DND.DROP_NONE
> farther down in the code.
> //I'm sure I'm just missing something obvious
>
//********************************************************** ************
> //If the drag is from a particular view (favorites) then we ONLY copy
> from there.
> LocalSelectionTransfer lst = (LocalSelectionTransfer)types[0];
> MTTransfer transfer = (MTTransfer)lst.getSelection();
> if (transfer.getSource() == MTTransfer.FAVORITES)
> event.detail = DND.DROP_COPY;
> else
> event.detail = DND.DROP_DEFAULT;
>
>
> //Don't allow self dropping or dropping on successors as this causes a
> recursive structure
> StructuredSelection sourceSel =
(StructuredSelection)transfer.getData();
>
> //Iterate over all the selected items to see if the destination is
valid
> Iterator iter = sourceSel.iterator();
> while (iter.hasNext())
> {
> ModelElement ele = (ModelElement)iter.next();
> //Don't allow dropping if the item dragged over is an ancestor of the
> item being dragged
> if (ele.isAncestorOf(destEle))
> {
> event.detail = DND.DROP_NONE;
> return;
> }
>
> }
>
> }
> "Veronika Irvine" <veronika_irvine@oti.com> wrote in message
> news:c8kuo8$die$1@eclipse.org...
> > Please post your code showing the problem.
> >
> > The event.detail field only gets changed if the user presses a key. If
> you
> > have set it to DND.DROP_NONE then as you move the mouse, it will stay as
> > DND.DROP_NONE.
> >
> > When the user presses or releases a key, you will get the
> > dragOperationChanged notification. In that event callback the
> event.detail
> > field is set to match the current user key combination. Note that if
the
> > user has Ctrl down and you do not support DND.DROP_COPY, then the
> > event.detail will be DND.DROP_NONE. You should not be checking for
> specific
> > keys because the meaning of the keys differs from platform to platform.
> >
> > See:
> >
> > http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.h tml
> >
> > "Mark Victory" <MVictory@us.ibm.com> wrote in message
> > news:c8h8s4$7ck$1@eclipse.org...
> > > I am implementing drag and drop in some tree based views.
> > >
> > > There are essentially two potential drop states when dragging over an
> item
> > > in my tree:
> > >
> > > 1. Cannot drop DND.DROP_NONE
> > > 2. Drop based on the state of the control key press - Either
> > DND.DROP_MOVE
> > > or DND.DROP_COPY
> > >
> > > In my implementation, If I ever set the drop event.detail to
> DND.DROP_NONE
> > > in my dragOver method then it never get's set back when dragging over
an
> > > item that is OK to drop on.
> > >
> > > Does my code have to check the state of the ctrl key and set the
> > > event.detail to DND.DROP_MOVE or DND.DROP_COPY appropriately? Seems
> like
> > > the drag and drop machinery should be able to do that. I tried
setting
> to
> > > DND.DROP_DEFAULT but that always results in a DND.DROP_MOVE even if
the
> > ctrl
> > > key is down, indicating it should be DND.DROP_COPYing.
> > >
> > > Any ideas,
> > > Mark
> > >
> > >
> >
> >
>
>
Re: Stupid (hopefully easy) drag and drop question [message #436949 is a reply to message #436843] Wed, 26 May 2004 14:50 Go to previous message
Mark Victory is currently offline Mark VictoryFriend
Messages: 133
Registered: July 2009
Senior Member
Thanks Veronika,

I contemplated doing something like that but I was hoping that the DND
mechanism would do the "remembering" for me.

Thanks again,
Mark

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:c907hr$iac$1@eclipse.org...
> You are not using DND.DROP_DEFAULT correctly. It does not mean, perform
the
> the default operation for the current key state. It means perform the
> operation that occurs when no modifier keys are pressed. The application
is
> not supposed to set the DND.DROP_DEFAULT into the event.detail field.
> Instead, it is supposed to receive an event with the detail field set to
> DND.DROP_DEFAULT and it should then change the value of event.detail to
what
> the application wants the default operation to be (usually DND.DROP_MOVE
or
> DND.DROP_COPY - if teh application does nothing, it will be set to
> DND.DROP_MOVE).
>
> If you want to change the operation depending on what target you are over,
> then you will need to remember what the current key operation is in the
> dragOperationChanged event:
>
> target.addDropListener (new DropTargetAdapter() {
> int currentOp = DND.DROP_NONE;
> public void dragEnter(DropTargetEvent event) {
> currentOp = event.detail;
> }
> public void dragOver(DropTargetEvent event) {
> if (transfer.getSource() == MTTransfer.FAVORITES)
> event.detail = DND.DROP_COPY; // this is a bit bogus - you
> should really check that the current op is COPY or DEFAULT - if the
current
> op is MOVE and you don't support MOVE, you should set the event.detail to
> NONE
> else
> event.detail = currentOp;
> }
> public void dragOperationChanged(DropTargetEvent event) {
> currentOp = event.detail;
> }
> }
>
>
> "Mark Victory" <MVictory@us.ibm.com> wrote in message
> news:c8t2mf$kd7$1@eclipse.org...
> > Hi Veronika,
> >
> > Here's my code - just the drop listener.
> >
> > target.addDropListener (new DropTargetAdapter() {
> > public void dragOver(DropTargetEvent event)
> > {
> > ModelElement destEle = (ModelElement)event.item.getData();
> >
> > //Different feedback based on the type of object dragged over
> > if (destEle.getType() == IModelElement.TYPE_BLOCK)
> > event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL |
> > DND.FEEDBACK_SELECT;
> > else
> > event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL |
> > DND.FEEDBACK_INSERT_BEFORE;
> >
> >
> >
> //********************************************************** ************
> > //Below is where the problem lies. I want the ELSE clause to set
the
> > detail to be
> > //whatever the operation should be based on the key state -
either
> > Copy or Move
> > //If I don't do the event.detail = DND.DROP_DEFAULT then the
> detail
> > will never be
> > //other than DND.DROP_NONE if it was ever set to DND.DROP_NONE
> > farther down in the code.
> > //I'm sure I'm just missing something obvious
> >
> //********************************************************** ************
> > //If the drag is from a particular view (favorites) then we ONLY
copy
> > from there.
> > LocalSelectionTransfer lst = (LocalSelectionTransfer)types[0];
> > MTTransfer transfer = (MTTransfer)lst.getSelection();
> > if (transfer.getSource() == MTTransfer.FAVORITES)
> > event.detail = DND.DROP_COPY;
> > else
> > event.detail = DND.DROP_DEFAULT;
> >
> >
> > //Don't allow self dropping or dropping on successors as this causes
a
> > recursive structure
> > StructuredSelection sourceSel =
> (StructuredSelection)transfer.getData();
> >
> > //Iterate over all the selected items to see if the destination is
> valid
> > Iterator iter = sourceSel.iterator();
> > while (iter.hasNext())
> > {
> > ModelElement ele = (ModelElement)iter.next();
> > //Don't allow dropping if the item dragged over is an ancestor of
the
> > item being dragged
> > if (ele.isAncestorOf(destEle))
> > {
> > event.detail = DND.DROP_NONE;
> > return;
> > }
> >
> > }
> >
> > }
> > "Veronika Irvine" <veronika_irvine@oti.com> wrote in message
> > news:c8kuo8$die$1@eclipse.org...
> > > Please post your code showing the problem.
> > >
> > > The event.detail field only gets changed if the user presses a key.
If
> > you
> > > have set it to DND.DROP_NONE then as you move the mouse, it will stay
as
> > > DND.DROP_NONE.
> > >
> > > When the user presses or releases a key, you will get the
> > > dragOperationChanged notification. In that event callback the
> > event.detail
> > > field is set to match the current user key combination. Note that if
> the
> > > user has Ctrl down and you do not support DND.DROP_COPY, then the
> > > event.detail will be DND.DROP_NONE. You should not be checking for
> > specific
> > > keys because the meaning of the keys differs from platform to
platform.
> > >
> > > See:
> > >
> > > http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.h tml
> > >
> > > "Mark Victory" <MVictory@us.ibm.com> wrote in message
> > > news:c8h8s4$7ck$1@eclipse.org...
> > > > I am implementing drag and drop in some tree based views.
> > > >
> > > > There are essentially two potential drop states when dragging over
an
> > item
> > > > in my tree:
> > > >
> > > > 1. Cannot drop DND.DROP_NONE
> > > > 2. Drop based on the state of the control key press - Either
> > > DND.DROP_MOVE
> > > > or DND.DROP_COPY
> > > >
> > > > In my implementation, If I ever set the drop event.detail to
> > DND.DROP_NONE
> > > > in my dragOver method then it never get's set back when dragging
over
> an
> > > > item that is OK to drop on.
> > > >
> > > > Does my code have to check the state of the ctrl key and set the
> > > > event.detail to DND.DROP_MOVE or DND.DROP_COPY appropriately? Seems
> > like
> > > > the drag and drop machinery should be able to do that. I tried
> setting
> > to
> > > > DND.DROP_DEFAULT but that always results in a DND.DROP_MOVE even if
> the
> > > ctrl
> > > > key is down, indicating it should be DND.DROP_COPYing.
> > > >
> > > > Any ideas,
> > > > Mark
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Previous Topic:Select events not generated on Mac - 3.0M9
Next Topic:Generic Context Menus for StyledText Control
Goto Forum:
  


Current Time: Sat Sep 21 03:03:27 GMT 2024

Powered by FUDForum. Page generated in 0.03785 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top