Reputation: 59
When I open Preferences and update config I need close "old" Part. But I encounter a problem. Eclipse throws an exception that tells me it does not active Window!
What should I do?
!STACK 0
java.lang.IllegalStateException: Application does not have an active window
at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.getActiveWindowService(ApplicationPartServiceImpl.java:43)
at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.hidePart(ApplicationPartServiceImpl.java:142)
at cn.oge.kdm.proapp.application.analysis.platform.preference.editor.PlatformAddressPreferencePage$5.widgetSelected(PlatformAddressPreferencePage.java:313)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:827)
at org.eclipse.jface.window.Window.open(Window.java:803)
at org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.open(WorkbenchPreferenceDialog.java:211)
at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:63)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
Upvotes: 1
Views: 261
Reputation: 111142
It looks like you are using the Application EPartService
to try and close a part. This will not work when a dialog is open as there is no active window which the application part service needs.
Instead you need to use the part service for the top level window. Get this using something like:
@Inject
EModelService modelService;
@Inject
MApplication application;
MWindow window = (MWindow)modelService.find("id of your top level window", application);
EPartService partService = window.getContext().get(EPartService.class);
Upvotes: 2