Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Create an DragSourceEvent
Create an DragSourceEvent [message #482928] Fri, 28 August 2009 15:01 Go to next message
Michelle Davidson is currently offline Michelle DavidsonFriend
Messages: 41
Registered: August 2009
Member
Hello,

is there a chance to generate a DragSourceEvent manual by code?

The problem is that the Constructor of the DragSourceEvent has a parameter of Type DNDEvent. But this class isn't visible. And so I can not instantiate a DNDEvent.

Or is ther another way to perform a drag and drop with some lines code?
Re: Create an DragSourceEvent [message #483207 is a reply to message #482928] Mon, 31 August 2009 15:07 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

This sounds like a strange thing to do since drag and drop is a user action,
like mouse down/up, key down/up, etc. In many ways the Clipboard provides a
similar function to drag and drop, but is invoked programmatically. Maybe
using Clipboard would be more appropriate? What is your app trying to do?

Grant


"Michelle Davidson" <michelle.davidson@gmx.de> wrote in message
news:h78rgu$nap$1@build.eclipse.org...
> Hello,
>
> is there a chance to generate a DragSourceEvent manual by code?
>
> The problem is that the Constructor of the DragSourceEvent has a parameter
of Type DNDEvent. But this class isn't visible. And so I can not instantiate
a DNDEvent.
>
> Or is ther another way to perform a drag and drop with some lines code?
Re: Create an DragSourceEvent [message #483509 is a reply to message #483207] Tue, 01 September 2009 19:54 Go to previous messageGo to next message
Michelle Davidson is currently offline Michelle DavidsonFriend
Messages: 41
Registered: August 2009
Member
In my application I have two trees. And between the trees I can drag a tree item to the other tree. That works fine.

Now I want to test the programm. Therefor I'm looking for a approac to make this drag and drop by code, such I can programm a mouse event or write text in a textfield or so on.
I thought, that i can do that by generating a dragsourceevent and a DropTargetEvent.

Is that the wrong approach and is there a chance to do that?
Re: Create an DragSourceEvent [message #483965 is a reply to message #483509] Thu, 03 September 2009 18:41 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
To make a test case of this you need to use display.post(). For an example
of this get the snippet at
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet91. java
and insert the code below between its "shell.open();" and
"while(!shell.isDisposed()) {" lines.

tree.getItem(0).setExpanded(true);
tree.getItem(0).getItem(0).setExpanded(true);

display.timerExec(2000, new Runnable() {
public void run() {
new Thread() {
Rectangle item1bounds, item2bounds;
public void run() {
display.syncExec(new Runnable() {
public void run() {
TreeItem item1 =
tree.getItem(0).getItem(0).getItem(0);
item1bounds = display.map(tree, null,
item1.getBounds());
TreeItem item2 =
tree.getItem(0).getItem(0).getItem(2);
item2bounds = display.map(tree, null,
item2.getBounds());
}
});
Event event = new Event();
event.type = SWT.MouseMove;
event.x = item1bounds.x + 20;
event.y = item1bounds.y + (item1bounds.height / 2);
display.post(event);

try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}

event = new Event();
event.type = SWT.MouseDown;
event.button = 1;
event.x = item1bounds.x + 20;
event.y = item1bounds.y + (item1bounds.height / 2);
display.post(event);

try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}

Point midway = new Point(item1bounds.x + 20, item1bounds.y +
((item2bounds.y - item1bounds.y) / 2));
event = new Event();
event.type = SWT.MouseMove;
event.x = midway.x;
event.y = midway.y;
display.post(event);

try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}

event = new Event();
event.type = SWT.MouseMove;
event.x = item2bounds.x + 20;
event.y = item2bounds.y + (item2bounds.height / 2);
display.post(event);

try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}

event = new Event();
event.type = SWT.MouseUp;
event.button = 1;
event.x = item2bounds.x + 20;
event.y = item2bounds.y + (item2bounds.height / 2);
display.post(event);
}
}.start();
}
});

HTH,
Grant


"Michelle Davidson" <michelle.davidson@gmx.de> wrote in message
news:h7ju5c$7es$1@build.eclipse.org...
> In my application I have two trees. And between the trees I can drag a
tree item to the other tree. That works fine.
>
> Now I want to test the programm. Therefor I'm looking for a approac to
make this drag and drop by code, such I can programm a mouse event or write
text in a textfield or so on.
> I thought, that i can do that by generating a dragsourceevent and a
DropTargetEvent.
>
> Is that the wrong approach and is there a chance to do that?
Previous Topic:display.getClientArea is incorrect (gtk)
Next Topic:Advice on OpenGL with SWT Needed
Goto Forum:
  


Current Time: Tue Apr 23 08:41:32 GMT 2024

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

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

Back to the top