如何关闭Eclipse e4 Part,当Preferences窗口打开时

时间:2016-05-12 03:11:58

标签: eclipse-plugin eclipse-rcp e4

当我打开首选项并更新配置时,我需要关闭“旧”部分。但我遇到了一个问题。 Eclipse抛出一个异常,告诉我它没有激活Window!

我该怎么办?

!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)

1 个答案:

答案 0 :(得分:2)

您似乎正在使用应用程序EPartService尝试关闭部件。当对话框打开时,这将不起作用,因为没有应用程序部件服务所需的活动窗口。

相反,您需要使用顶级窗口的零件服务。使用以下内容获取此信息:

@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);