RCP应用程序活动

时间:2011-11-16 09:42:40

标签: java eclipse-plugin eclipse-rcp

我的RCP应用程序出现问题。

首先,我在plugin.xml中定义了一个活动:

<extension
     point="org.eclipse.ui.activities">
  <activity
        id="myproject.view.input.activity"
        name="myproject.view.input.activity">
     <enabledWhen>
        <with
              variable="myproject.view.input.active">
           <equals
                 value="ENABLED">
           </equals>
        </with>
     </enabledWhen>
  </activity>
  <activityPatternBinding
        activityId="myproject.view.input.activity"
        pattern="myproject.gui/myproject.view.input">
  </activityPatternBinding>

然后我定义了我的SourceProvider:

<extension
     point="org.eclipse.ui.services">
  <sourceProvider
        provider="myproject.util.CommandState">
     <variable
           name="myproject.view.input.active"
           priorityLevel="workbench">
     </variable>

最后,我的CommandState类:

public class CommandState extends AbstractSourceProvider {

    public final static String OUTPUT_VIEW = "myproject.view.input.active";
    // then goes some others variables, i just skip them
    // ....

    public final static String [] ACTIONS = {OUTPUT_VIEW /*and all others variables*/};

    public final static String ENABLED = "ENABLED";
    public final static String DISENABLED = "DISENABLED";

    private final Map <String, String> currentState = new HashMap <String, String> ();

    @Override
    public void dispose() {
    }

    @Override
    public String[] getProvidedSourceNames() {
        return ACTIONS;
    }

    @Override
    public Map <String, String> getCurrentState() {
        return currentState;
    }

    public void setEnabled(boolean enabled, String [] commands) {
        String value = enabled ? ENABLED : DISENABLED;
        for (String command : commands) {
            currentState.put(command, value);
            fireSourceChanged(ISources.WORKBENCH, command, value);
        }
    }
}

在我的登录窗口中,应用程序检查用户权限,并使用CommandState的setEnabled方法启用或禁用视图,命令等。对于命令它工作正常,它们正确启用或禁用(我以其他方式禁用它们,但它工作正常,即使我通过活动禁用它们,就像我描述的那样)。但是当我尝试禁用视图和打开透视图时,它包含该视图(myproject.view.input),它在没有该视图的情况下打开,但也会抛出异常:

!ENTRY org.eclipse.ui 4 4 2011-11-16 15:54:43.284
!MESSAGE Exception in org.eclipse.ui.internal.PageLayout.addView: org.eclipse.ui.PartInitException: Could not create view: myproject.view.input

!ENTRY org.eclipse.ui 4 4 2011-11-16 15:54:43.321
!MESSAGE Exception in org.eclipse.ui.internal.PageLayout.addView: org.eclipse.ui.PartInitException: Could not create view: myproject.view.input
!STACK 1
org.eclipse.ui.PartInitException: Could not create view: myproject.view.input
    at org.eclipse.ui.internal.ViewFactory.createView(ViewFactory.java:158)
    at org.eclipse.ui.internal.LayoutHelper.createView(LayoutHelper.java:162)
    at org.eclipse.ui.internal.PageLayout.createView(PageLayout.java:543)
    at org.eclipse.ui.internal.PageLayout.addView(PageLayout.java:416)
    at org.eclipse.ui.internal.PageLayout.addStandaloneView(PageLayout.java:894)
    at org.eclipse.ui.internal.registry.PerspectiveExtensionReader.processView(PerspectiveExtensionReader.java:295)
    at org.eclipse.ui.internal.registry.PerspectiveExtensionReader.processExtension(PerspectiveExtensionReader.java:118)
    at org.eclipse.ui.internal.registry.PerspectiveExtensionReader.readElement(PerspectiveExtensionReader.java:355)
    at org.eclipse.ui.internal.registry.RegistryReader.readElements(RegistryReader.java:144)
    at org.eclipse.ui.internal.registry.RegistryReader.readExtension(RegistryReader.java:155)
    at org.eclipse.ui.internal.registry.RegistryReader.readRegistry(RegistryReader.java:176)
    at org.eclipse.ui.internal.registry.PerspectiveExtensionReader.extendLayout(PerspectiveExtensionReader.java:82)
    at org.eclipse.ui.internal.Perspective.loadPredefinedPersp(Perspective.java:818)
    at org.eclipse.ui.internal.Perspective.createPresentation(Perspective.java:270)
    at org.eclipse.ui.internal.Perspective.<init>(Perspective.java:156)
    at org.eclipse.ui.internal.tweaklets.Workbench3xImplementation.createPerspective(Workbench3xImplementation.java:55)
    at org.eclipse.ui.internal.WorkbenchPage.createPerspective(WorkbenchPage.java:1672)
    at org.eclipse.ui.internal.WorkbenchPage.busySetPerspective(WorkbenchPage.java:1034)
    at org.eclipse.ui.internal.WorkbenchPage.access$16(WorkbenchPage.java:1025)
    at org.eclipse.ui.internal.WorkbenchPage$19.run(WorkbenchPage.java:3715)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.setPerspective(WorkbenchPage.java:3713)
    at org.eclipse.ui.handlers.ShowPerspectiveHandler.openPerspective(ShowPerspectiveHandler.java:146)
    at org.eclipse.ui.handlers.ShowPerspectiveHandler.openOther(ShowPerspectiveHandler.java:118)
    at org.eclipse.ui.handlers.ShowPerspectiveHandler.execute(ShowPerspectiveHandler.java:57)
    at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
    at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
    at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:178)
    at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
    at org.eclipse.ui.actions.PerspectiveMenu.runOther(PerspectiveMenu.java:376)
    at org.eclipse.ui.actions.PerspectiveMenu$3.runWithEvent(PerspectiveMenu.java:130)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3161)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at myproject.arm.demo.Application.start(Application.java:28)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    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:369)
    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:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1384)
!SUBENTRY 1 org.eclipse.ui 4 0 2011-11-16 15:54:43.322
!MESSAGE Could not create view: myproject.view.input

我尝试调试我的应用程序,然后在打开我的视图之前,我检查了我的CommandState源提供程序的currentState,并且所有的seeme都没问题:所有变量值都是正确的,myproject.view.input.active = DISABLED

有人可以说,为什么会抛出异常?感谢您的帮助或任何想法。对不起大的帖子和糟糕的语言

*已编辑:已添加完整的堆栈跟踪

1 个答案:

答案 0 :(得分:3)

系统正在运行。活动可以使用户看不到视图或向导,但可以选择故意显示它。

带有 enabledWhen 元素的活动也会从视图注册表中删除视图,因此用户无法刻意显示它,即使他们想要这样做。这是为了防止用户在RCP应用中打开管理员视图。

您已将视图添加到您的透视图中,如果您的活动被禁用,就好像该视图定义不存在一样。

您应该将该视图添加为视图占位符,或者添加到管理透视图中。如果用户使用管理员角色登录,则可以显示视图或选择管理员角度。