Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335858 - Direct edit not working
Summary: Direct edit not working
Status: RESOLVED FIXED
Alias: None
Product: SWTBot
Classification: Technology
Component: GEFBot (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-31 10:38 EST by Tim Kaiser CLA
Modified: 2011-02-20 11:51 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Kaiser CLA 2011-01-31 10:38:24 EST
While trying to do a direct edit,
not only the text field ready for direct editing
is considered but also other text fields which
are parented by the shell of the active workbench page.

Call stack fragment:
org.eclipse.swtbot.swt.finder.SWTBot(org.eclipse.swtbot.swt.finder.SWTBotFactory).widgets(org.hamcrest.Matcher<T>, org.eclipse.swt.widgets.Widget) line: 268	
org.eclipse.swtbot.swt.finder.SWTBot(org.eclipse.swtbot.swt.finder.SWTBotFactory).widgets(org.hamcrest.Matcher<T>) line: 277	
org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefViewer.directEditType(java.lang.String) line: 277	
org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor.directEditType(java.lang.String) line: 178	

I modified the following method to make it work:

public void directEditType(String text) throws WidgetNotFoundException {

		/*
		 * we use 'bot()' and not 'bot' to scope the widget search to the editor. Otherwise if another widget of the
		 * same type is present in the workspace and is found first, the code after will fail.
		 */

		/* by using SWTBot#widgets() we get the added benefit of an implicit wait condition. */
		List<? extends Text> controls = bot().widgets(widgetOfType(Text.class), canvas.widget);
		if (controls.size() == 1) {
			final Text textControl = controls.get(0);
			canvas.typeText(textControl, text);
		} else {
			throw new WidgetNotFoundException(String.format(
					"Expected to find one text control, but found %s.  Is the editor in direct-edit mode?", controls.size()));
		}
	}

I think it is important to narrow the search of Text widgets to the supplied canvas:
List<? extends Text> controls = bot().widgets(widgetOfType(Text.class), canvas.widget);

Otherwise additional text fields are found and the direct edit does not work.

Best, Tim
Comment 1 Tim Kaiser CLA 2011-01-31 10:40:43 EST
it can be reproduced if the error log view with the text field
"type filter text" is open....
Comment 2 Mariot Chauvin CLA 2011-01-31 11:11:03 EST
(In reply to comment #1)
> it can be reproduced if the error log view with the text field
> "type filter text" is open....

Thanks for reporting, I will have a look asap
Comment 3 Mariot Chauvin CLA 2011-02-20 11:51:46 EST
Fixed on master.
Commit 78c5ad8e1ece16f04630fc5701e2c407ec6828b0