Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 335858

Summary: Direct edit not working
Product: [Technology] SWTBot Reporter: Tim Kaiser <tim.kaiser>
Component: GEFBotAssignee: Project Inbox <swtbot-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mariot.chauvin
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

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