【问题标题】:RCP application activitiesRCP 应用活动
【发布时间】:2011-11-16 09:42:40
【问题描述】:

我的 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,一切似乎都正常:所有变量值都是正确的并且 myproject.view.input.active = DISABLED

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

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

【问题讨论】:

  • 听起来与活动定义没有任何关系。我们需要堆栈跟踪以获得进一步的帮助...

标签: java eclipse-plugin eclipse-rcp


【解决方案1】:

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

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

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

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

【讨论】:

  • 感谢您的回答!我还有一些问题,比我以后发布的更多
  • 再次感谢。我以其他方式解决了我的问题。在我的“管理员”透视图的透视图工厂中,我检查 - 是否存在此视图,并且仅在存在时添加它。看起来我做了一些不必要的工作,但工作正常,无一例外!
  • +100 表示An activity with an enabledWhen element removes the view from the view registry as well, so the user cannot deliberately show it, even if they wanted to.。这是我永久隐藏视图所需的确切解决方案;这似乎没有充分的记录!
猜你喜欢
  • 2017-10-29
  • 1970-01-01
  • 2014-12-21
  • 1970-01-01
  • 2010-09-09
  • 1970-01-01
  • 2022-01-13
  • 2021-04-23
相关资源
最近更新 更多