gpt4 book ai didi

java - RCP 应用 Activity

转载 作者:行者123 更新时间:2023-12-04 06:07:48 25 4
gpt4 key购买 nike

我的 RCP 应用程序有问题。

首先,我在我的 plugin.xml 中定义了一个 Activity :

<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 方法检查用户权限,并启用或禁用 View 、命令等。对于它工作正常的命令,它们正在正确启用或禁用(我以其他方式禁用它们,但即使我通过 Activity 禁用它们,它也能正常工作,就像我描述的那样)。但是,当我尝试禁用包含该 View (myproject.view.input)的 View 和打开透视图时,它会在没有该 View 的情况下打开,但也会引发异常:
!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

我尝试调试我的应用程序,在打开我的 View 之前,我检查了我的 CommandState 源提供程序的 currentState,一切似乎都正常:所有变量值都是正确的,并且 myproject.view.input.active = DISABLED

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

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

最佳答案

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

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

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

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

关于java - RCP 应用 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8149512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com