Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Setting a new value in a treeItem.cell
Setting a new value in a treeItem.cell [message #516374] Tue, 23 February 2010 19:06 Go to next message
Paul N is currently offline Paul NFriend
Messages: 3
Registered: February 2010
Location: St. Louis, MO
Junior Member
As part of my test I'd like to alter a value in a cell in a tree. In this case the tree is contained in the Eclipse properties view. I can locate the property whose value I need to change, but have not been able to find an appropriate method for setting that value.

It's entirely possible I've overlooked something obvious. Embarrassed

Thanks,
Paul
Re: Setting a new value in a treeItem.cell [message #516387 is a reply to message #516374] Tue, 23 February 2010 19:54 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Paul N wrote:
> As part of my test I'd like to alter a value in a cell in a tree. In
> this case the tree is contained in the Eclipse properties view. I can
> locate the property whose value I need to change, but have not been able
> to find an appropriate method for setting that value.
>
> It's entirely possible I've overlooked something obvious. :blush:
> Thanks,
> Paul

It depends: how would a real user do it? With my experience with the
property view, the user would need to click on the required cell for a
cell editor to appear (usually a Text control, or CCombo), enter the
text then press enter. Well then, do the same thing with SWTBot:

SWTBotTreeItem item = tree.getTreeItem("text");
item.click(1); // Click the second column
Text widget = bot.widget(widgetOfType(Text.class), tree.widget); // get
the cell editor
SWTBotText text = new SWTBotText(widget, null);
text.setText("newText"); // set the text
text.pressShortcut(KeyStroke.getInstance(SWT.CR)); // Close the cell editor

If your user doesn't have to do that for whatever reason, you might need
something different. But always, the first to ask yourself is: what a
real user would do? When you get the answer, modeling that using SWTBot
is usually pretty straightforward.

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Setting a new value in a treeItem.cell [message #516409 is a reply to message #516387] Tue, 23 February 2010 20:50 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Pascal Gelinas wrote:
> Paul N wrote:
>> As part of my test I'd like to alter a value in a cell in a tree. In
>> this case the tree is contained in the Eclipse properties view. I can
>> locate the property whose value I need to change, but have not been
>> able to find an appropriate method for setting that value.
>>
>> It's entirely possible I've overlooked something obvious. :blush:
>> Thanks,
>> Paul
>
> It depends: how would a real user do it? With my experience with the
> property view, the user would need to click on the required cell for a
> cell editor to appear (usually a Text control, or CCombo), enter the
> text then press enter. Well then, do the same thing with SWTBot:
>
> SWTBotTreeItem item = tree.getTreeItem("text");
> item.click(1); // Click the second column
> Text widget = bot.widget(widgetOfType(Text.class), tree.widget); // get
> the cell editor
> SWTBotText text = new SWTBotText(widget, null);
> text.setText("newText"); // set the text
> text.pressShortcut(KeyStroke.getInstance(SWT.CR)); // Close the cell editor
>
> If your user doesn't have to do that for whatever reason, you might need
> something different. But always, the first to ask yourself is: what a
> real user would do? When you get the answer, modeling that using SWTBot
> is usually pretty straightforward.
>
> Hope this helps.

Oops, it would seem that clicking on a specific collumn on a tree item
is not supported in SWTBot. This is an extension we have here and I
forgot to double check that. However, there is Bug 293501 open for that
purpose. But still, this thing is not enough. I just tried that patch
and the cell editor doesn't open. I'll pop in a comment about that.

In the mean time, you can do this:

Create a subclass of SWTBotTreeItem called SwtBotTreeItemExtension and
add this constructor and method:

private final Tree mParentTree;

/**
* @throws WidgetNotFoundException if the widget is
<code>null</code> or
* widget has been disposed.
*/
public SwtBotTreeItemExtension(final TreeItem treeItem,
SelfDescribing selfDescribing)
{
super(treeItem, selfDescribing);
mParentTree = syncExec(new WidgetResult<Tree>()
{
public Tree run()
{
return treeItem.getParent();
}
});
}

/**
* Click on the specified column
*
* @param columnIndex the column index to click on
* @return this
* @throws IndexOutOfBoundsException if columnIndex is greater then the
* number of column of the underlying widget or
columnIndex < 0
*/
public void click(final int columnIndex)
{
int columnCount = new SWTBotTree(mParentTree).columnCount();
if (columnIndex < 0 || columnIndex > columnCount)
{
throw new IndexOutOfBoundsException("Index should be
between 0 and "
+ columnCount
+ ". Passed value is: "
+ columnIndex);
}

// Get the center point of the cell at the specified column
Point point = syncExec(new Result<Point>()
{
public Point run()
{
Rectangle bounds = widget.getBounds(columnIndex);
int x = bounds.x + (bounds.width / 2);
int y = bounds.y + (bounds.height / 2);
return display.map(mParentTree, null, x, y);
}
});

// For this method to work correctly, we need to use
Display.post() because otherwise the cell editor associated
// with the item might not open.
click(point.x, point.y, true);
}

this should do the trick.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Setting a new value in a treeItem.cell [message #516414 is a reply to message #516409] Tue, 23 February 2010 21:02 Go to previous message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Pascal Gelinas wrote:
>
> Oops, it would seem that clicking on a specific collumn on a tree item
> is not supported in SWTBot. This is an extension we have here and I
> forgot to double check that. However, there is Bug 293501 open for that
> purpose. But still, this thing is not enough. I just tried that patch
> and the cell editor doesn't open. I'll pop in a comment about that.
>

The patch in the bug is valid, silly me. I had a small difference that I
didn't saw. Sorry for the confusion...

--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Previous Topic:Problems with SWTBot and Spring-Context
Next Topic:Problem with Testlistener in headless Mode
Goto Forum:
  


Current Time: Fri Mar 29 09:32:47 GMT 2024

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

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

Back to the top