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

Bug 315254

Summary: Create New infector from within project fails for DEU_0
Product: [Technology] STEM Reporter: James Kaufman <jhkauf>
Component: AnalysisAssignee: Stefan Edlund <sedlund>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:

Description James Kaufman CLA 2010-06-01 12:50:54 EDT
To reproduce, 
Create a model and scenario for DEU_0
Try to create an infector within the project
you will see exception

!ENTRY org.eclipse.stem.ui 4 0 2010-06-01 09:48:46.997
!MESSAGE 
!STACK 0
java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:421)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
	at org.eclipse.stem.ui.widgets.LocationPickerDialog.reinit(LocationPickerDialog.java:304)
	at org.eclipse.stem.ui.widgets.LocationPickerDialog$1.handleEvent(LocationPickerDialog.java:106)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3543)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1250)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1273)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1079)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3441)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3100)
	at org.eclipse.stem.ui.widgets.LocationPickerDialog.open(LocationPickerDialog.java:279)
	at org.eclipse.stem.ui.wizards.InfectorDefinitionComposite$1.widgetSelected(InfectorDefinitionComposite.java:266)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3543)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1250)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1273)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1079)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3441)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3100)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
	at org.eclipse.jface.window.Window.open(Window.java:801)
	at org.eclipse.stem.ui.wizards.NewInfectorWizard$NewInfectorWizardCommandHandler.execute(NewInfectorWizard.java:334)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:294)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
	at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:770)
	at org.eclipse.ui.menus.CommandContributionItem.access$10(CommandContributionItem.java:756)
	at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:746)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3543)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1250)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1273)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1079)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3441)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3100)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.stem.core.common.presentation.CoreEditorAdvisor$Application.start(CoreEditorAdvisor.java:410)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:3884)
	at org.eclipse.swt.SWT.error(SWT.java:3799)
	at org.eclipse.swt.SWT.error(SWT.java:3770)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:619)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:463)
	at org.eclipse.swt.widgets.Text.setText(Text.java:1787)
	at org.eclipse.stem.ui.widgets.ISOKeyPicker.setISOKeys(ISOKeyPicker.java:119)
	at org.eclipse.stem.ui.widgets.LocationPickerDialog$8.run(LocationPickerDialog.java:296)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Root exception:
org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:3884)
	at org.eclipse.swt.SWT.error(SWT.java:3799)
	at org.eclipse.swt.SWT.error(SWT.java:3770)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:619)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:463)
	at org.eclipse.swt.widgets.Text.setText(Text.java:1787)
	at org.eclipse.stem.ui.widgets.ISOKeyPicker.setISOKeys(ISOKeyPicker.java:119)
	at org.eclipse.stem.ui.widgets.LocationPickerDialog$8.run(LocationPickerDialog.java:296)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Comment 1 James Kaufman CLA 2010-06-01 17:06:30 EDT
Stefan,
Matt helped me investigate this.
The new infector creation actually succeeds - it just throws the exception above. 
The problem is caused by
LocationPickerDialog.reinit() line 288
In the case of picking from keys inside the project, the reinit method tries to start
an IRunnableWithProgress
this makes the following code in the IsoKeyPicker unhappy
public void setISOKeys(final Object[] isoKeys) {
		filteredList.setElements(isoKeys);
		text.setText("");  <<<<<<<<<<<<<<<<<<<<< different thread??
	} // setISOKeys

IF I comment out the  IRunnableWithProgress code and just keep the logic  in the LocationPickerDialog.reinit()  method then
everything runs fine, but we won't have the progress monitor for really big graphs.
Not sure what the best solution is. I did not check in any changes but the following might be the fix.

public void reinit() {
		if(selectGlobal)
			isoKeyPicker0.setISOKeys(GeographicNames.getSubISOKeys(
				GeographicMapper.EARTH_ALPHA3_ISO_KEY, -1));
		else {
			//IRunnableWithProgress getKeys = new IRunnableWithProgress() {
	        //    public void run(IProgressMonitor progress) {
	            //	progress.beginTask(Messages.getString("NLocPickerWiz.gettingLocations"), 100);   	
	        		isoKeyPicker0.setISOKeys(LocationUtility.getKeys(project, 0, null).toArray());
	            //	progress.worked(100);
	            //	progress.done();
	           // }
			//};
			
//			IRunnableContext context = new ProgressMonitorDialog(shell);
//			try {
//				context.run(true, true, getKeys);
//			} catch(Exception e) {
//				Activator.logError(e.getMessage(), e);
//			}
			
		}
Comment 2 Stefan Edlund CLA 2010-06-08 19:08:05 EDT
Good catch. I added a 

this.getDisplay().syncExec(new Runnable() {
			public void run() {
				text.setText("");
			}
		});
		
around the setText method and I think that should fix it and still keep the progress bar for large projects.
Comment 3 James Kaufman CLA 2011-07-18 19:44:26 EDT
Complete