2011-11-16 123 views
2

我的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); 
     } 
    } 
} 

在我的登录窗口中,应用程序检查用户权限,并启用或禁用视图,命令等与se CommandState的tEnabled方法。对于命令它工作正常,他们正在启用或禁用正确(我禁用他们以其他方式,但它工作正常,即使我禁用他们通过活动,以我所述的相同方式)。但是,当我尝试禁用视图和开放的角度来看,包含视图(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 

我试图调试我的申请,前打开我的观点whith那视图,我检查了我的CommandState源提供程序的currentState,并且所有图片都可以:所有变量值都正确并且myproject.view.input.active = DISABLED

任何人都可以说,为什么会抛出异常?感谢您的任何帮助,或任何想法。对不起,大柱和脏话

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

+0

听起来不像它与活动定义有任何关系。我们需要stacktrace以获得进一步的帮助... –

回答

3

的系统工作。一项活动可以使用户看不到视图或向导,但可以让他们有意识地显示它。

启用了的活动当元素也从视图注册表中删除视图时,因此用户无法故意显示它,即使他们想要。这是为了防止用户在RCP应用程序中打开管理视图。

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

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

+0

感谢您的回答!我仍然有一些问题,比我后面发布的 – Peter

+0

再次感谢。我以其他方式解决了我的问题。在我的“管理员”透视图的透视工厂中,我检查 - 是否存在此视图,并且仅在存在时才添加它。看起来我做了一些不必要的工作,但没有例外地正常工作! – Peter

+0

+100 for'具有enabledWhen元素的活动也将视图从视图注册表中移除,因此即使用户想要,用户也不能故意显示它。这是我永久隐藏我的观点所需的确切解决方案;这似乎是非常缺乏记录! – SpellingD