invocationTargetException et ouverture de Shell
Bonjour la liste,
J'éxécute une mini application RCP. J'utilise un objet Wizard (org.eclipse.jface.wizard.Wizard).
Le code de ma classe Wizard est le suivant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public class ReservationWizard extends Wizard {
...
public void addPages() {
addPage(new FrontPage());
addPage(new CustomerInfoPage());
addPage(new PaymentInfoPage());
}
public boolean performFinish() {
...
try {
// puts the data into a database ...
getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
monitor.beginTask("Store data", 100);
monitor.worked(40);
// store data here ...
System.out.println(data);
WidgetTest test = new WidgetTest();
Shell shell = test.getShell();
shell.open();
Thread.sleep(2000);
monitor.done();
}
});
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
//Display.getCurrent().dispose();
return true;
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#performCancel()
*/
public boolean performCancel() {
...
}
} |
Une fois cliqué sur le bouton Finish, j'ouvre un shell. Le code de ce shell est le suivant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| public class WidgetTest {
Shell topLevelShell = null;
public WidgetTest(){
topLevelShell = new Shell();
topLevelShell.setText("TopLevel.LigneTitre");
topLevelShell.setLayout(new GridLayout());
Button btnOpen = new Button(topLevelShell,SWT.PUSH);
btnOpen.setText("Ouvrir");
btnOpen.addSelectionListener(new SelectionListener(){
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
@Override
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
System.out.println("Bienvenue à Libreville");
}
});
}
public Shell getShell(){
return topLevelShell;
}
} |
Mais seulement lors de l'exécution, quand je clique sur "Finish", j'ai l'erreur
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:415)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:934)
at wizardtest.handler.ReservationWizard.performFinish(ReservationWizard.java:75)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:742)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
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.Widget.sendEvent(Widget.java:1158)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3401)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3033)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at wizardtest.handler.WizardHandler.execute(WizardHandler.java:19)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:281)
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:247)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:619)
at org.eclipse.ui.menus.CommandContributionItem.access$10(CommandContributionItem.java:605)
at org.eclipse.ui.menus.CommandContributionItem$4.handleEvent(CommandContributionItem.java:595)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3401)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3033)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at wizardtest.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
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:386)
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:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3777)
at org.eclipse.swt.SWT.error(SWT.java:3695)
at org.eclipse.swt.SWT.error(SWT.java:3666)
at org.eclipse.swt.widgets.Widget.error(Widget.java:446)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:254)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:245)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:199)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:138)
at wizardtest.handler.WidgetTest.<init>(WidgetTest.java:19)
at wizardtest.handler.ReservationWizard$1.run(ReservationWizard.java:84)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121) |
Si quelqu'un a une explication ou bien les pistes pour remédier à la situation, merci beaucoup d'avance.