0

Good Morning all (or afternoon or evening respectively),

I am trying to build a SWTBot test that drags a node from a Tree Viewer into a diagram editor (using Graphiti, don't think that matters). The node to be dragged is in it's own view, not in the toolbar, so the standard way of doing it won't work:

SWTBotGefEditor editor = gefBot.gefEditor(editorName);
editor.activateTool(functionName);
editor.drag(20, 20, 20, 20);

I also saw that TreeItem has a dragAndDrop function, but unless I'm wrong (totally possible), I think that only works when dragging to another tree.

Is there a way to drag directly from a tree to a diagram editor?

BiggPlanet
  • 77
  • 1
  • 12

2 Answers2

0

There are a number of dragging schemes which are not yet implemented in SWTBot. I do not know whether your case is part of them. I know I had to create my own utilities for dragging table rows, which otherwise used an empty intended-for-replacement method. Therefore I think you should dig into SWTBot code to see whether you find such an empty method.

S. Cambon
  • 560
  • 3
  • 9
  • Thanks for the suggestion. I did dig into their code, but couldn't find anything that fit my needs exactly. Doesn't mean it wasn't there, just that I couldn't find it myself... Ended up using reflection, as I'll note in my follow on post – BiggPlanet Jul 23 '14 at 15:29
0

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);
BiggPlanet
  • 77
  • 1
  • 12