Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How can you enable a cell editor in a tree viewer with multiple columns?(I am not able to enable a viewer editor on a tree viewer)
icon5.gif  How can you enable a cell editor in a tree viewer with multiple columns? [message #489467] Sat, 03 October 2009 14:25 Go to next message
Dan O'Connor is currently offline Dan O'Connor
Messages: 4
Registered: October 2009
Junior Member
Hi...

I have a dialog that I would like to test with SWTBot automation. The dialog contains a TreeViewer which has two columns. The tree viewer has two CellEditors associated with it. When the user clicks on the first column a TextEditor becomes available and when the user clicks on the second column a ComboEditor becomes available.

However I cannot find an API in SWTBot to click on the second column in the treeviewer??
I am retrieving the rows in the table as SWTBotTreeItem objects. When I invoke the treeItem.click() method it always clicks on the first column in the treeviewer.
I tried overriding this behavior by creating my own TreeItem wrapper object which extends SWTBotTreeItem. I added a new click method that allows the user to specify the column that should be clicked:

public SWTBotTreeItem click(int columnToClick){
assertEnabled();
Rectangle cellBounds = syncExec(new Result<Rectangle>() {
public Rectangle run() {
Rectangle r = widget.getBounds();
return r;
}
});

int x = (cellBounds.width / (this.numberOfTreeColumns + 1)) * (columnToClick + 1);
clickXY(cellBounds.x + x, cellBounds.y + (cellBounds.height / 2));
return this;
}

When this object is first constructed the caller has to specify the number of columns in the TreeViewer (numberofTreeColumns).
When calling the click method the user has to specify which column should be clicked on.
Unfortunately this code is not working, even with the code above the click seems to happen on the first column always.. I am not sure if the widget.getBounds call is only returning the size of the first cell?

Does anyone have any experience with this? Any information is greatly appreciated.

Thanks.




Re: How can you enable a cell editor in a tree viewer with multiple columns? [message #489753 is a reply to message #489467] Mon, 05 October 2009 19:05 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
Dan O'Connor wrote:
> Hi...
>
> I have a dialog that I would like to test with SWTBot automation. The
> dialog contains a TreeViewer which has two columns. The tree viewer has
> two CellEditors associated with it. When the user clicks on the first
> column a TextEditor becomes available and when the user clicks on the
> second column a ComboEditor becomes available.
>
> However I cannot find an API in SWTBot to click on the second column in
> the treeviewer??

There is no API in SWTBot for the moment to click on a specific column.
I've run into the exact same problem and I've done my own extension to
SWTBotTreeItem which works very well. I have provided the code as a
patch on bugzilla[1], which also include support for CellEditor. It was
ruled out that this implementation is too bound to specific cell editor
(Text and CCombo). Still, I think it could fix the problem you are having.

p.s.: I seem to have messed up the attachement on that bug... it is
supposed to be a zip file but it has been detected as text/plain...

[1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=282408
Re: How can you enable a cell editor in a tree viewer with multiple columns? [message #489760 is a reply to message #489753] Mon, 05 October 2009 19:29 Go to previous message
Dan O'Connor is currently offline Dan O'Connor
Messages: 4
Registered: October 2009
Junior Member
Thanks for the response. I actually figured out over the weekend that there is a TreeItem api to get the bounds for a particular Cell. Here is what I implemented:

/**
*
*/
package com.............

import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundExcep tion;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;

/**
* @author doconnor
*
*/
public class SWTBotTreeItemExt extends SWTBotTreeItem {
/**
*
* @param treeItem - A SWTBotTreeItem object from which we can get a TreeItem widget
* @throws WidgetNotFoundException
*/
public SWTBotTreeItemExt(SWTBotTreeItem treeItem)
throws WidgetNotFoundException {
super(treeItem.widget);
}

/**
* Overrides the behavior of {@link SWTBotTreeItem#click()} such that this method now
* calls {@link SWTBotTreeItemExt#click(int)} with an index of 0
* This method will click on the first column cell
*/
@Override
public SWTBotTreeItem click() {
return click(0);
}

/**
* @param column - Index of the column on which the caller wants to click
* @return
*
* Clicks on the current TreeItem in the column specified by <code>column</code>
*/
public SWTBotTreeItem click(final int column){
assertEnabled();
Rectangle cellBounds = syncExec(new Result<Rectangle>() {
public Rectangle run() {
Rectangle r = widget.getBounds(column);
return r;
}
});

int x = (cellBounds.width / 2);
clickXY(cellBounds.x + x, cellBounds.y + (cellBounds.height / 2));
return this;
}

public String getText(int column){
return cell(column);
}
}


This seems to work fine. It is then up to the caller to find the editor that is created
Previous Topic:Get imagefilename with swtbot
Next Topic:Usage of Screen/Page Pattern (Helperbots)
Goto Forum:
  


Current Time: Sat Oct 25 11:22:29 GMT 2014

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

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