Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » SWTBot Drag and Drop - Tree to Editor(How to do drag and drop between non-widgets)
SWTBot Drag and Drop - Tree to Editor [message #1398877] Fri, 11 July 2014 18:37 Go to next message
Devin Nelson is currently offline Devin NelsonFriend
Messages: 4
Registered: June 2014
Junior Member
I need to perform a drag-and-drop operation as part of one of my tests for my RCP application. The dragged item is a node in a treeviewer and the target location is an editor.

I can't figure out how to do this with the provided drag-and-drop methods. I could create my own implementation if I could figure out how to control mouse position, but all of the methods calls I've found so far are private/protected. I did try and use treeItem.display to get/set cursor location but was hit with an Invlaid Thread Access exception.

Thanks in advance for any direction on this.
Re: SWTBot Drag and Drop - Tree to Editor [message #1403427 is a reply to message #1398877] Wed, 23 July 2014 15:38 Go to previous messageGo to next message
Devin Nelson is currently offline Devin NelsonFriend
Messages: 4
Registered: June 2014
Junior Member
Should have updated this a while back, but don't want to leave a thread hanging so I'll add my findings:

I ended up having to use reflection to get the canvas object from my viewer, and then was able to pass that into the dragAndDrop() method that SWTBot has for SWTBotTreeItems. Worked in a pinch, though you can't give it x/y-coordinates (like you can when bringing from the palette), so it is still not ideal.

SWTBotView view = gefBot.viewByTitle("My View");
SWTBotTree tree = view.bot().tree();
SWTBotTreeItem treeItem = tree.expandNode("Parent Node Name", targetNodeName);

SWTBotGefViewer viewer = editor.getSWTBotGefViewer();
SWTBotGefFigureCanvas canvas = null;

for (Field f : viewer.getClass().getDeclaredFields()) {
    if ("canvas".equals(f.getName())) {
        f.setAccessible(true);
        try {
            canvas = (SWTBotGefFigureCanvas) f.get(viewer);
        } catch (IllegalArgumentException e) {
            e.printStackTrace(); 
        } catch (IllegalAccessException e) {
            e.printStackTrace(); 
        }
    }
}

Assert.assertNotNull(canvas);
treeItem.dragAndDrop(canvas);

Re: SWTBot Drag and Drop - Tree to Editor [message #1403916 is a reply to message #1403427] Mon, 28 July 2014 14:59 Go to previous message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Hi,

Feel free to open a feature request and provide a patch if you want to
add some useful methods to the SWTBotGefViewer.
https://wiki.eclipse.org/SWTBot/Contributing

--
Mickael Istria
My job: http://www.jboss.org/tools
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria
Previous Topic:sync after AbstractSWTBot#pressShortcut() ?
Next Topic:"Missing feature org.eclipse.swtbot" with 2.2.1, but works with 2.0.1
Goto Forum:
  


Current Time: Fri Apr 26 18:07:58 GMT 2024

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

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

Back to the top