|
|
|
Re: Create an DragSourceEvent [message #483965 is a reply to message #483509] |
Thu, 03 September 2009 18:41 |
Grant Gayed 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?
|
|
|
Powered by
FUDForum. Page generated in 0.03213 seconds