我正在尝试自定义 Eclipse 3.8.1 上的“帮助”->“关于”菜单条目。我尝试了两种 3.x 友好的方法,因为 Eclipse 4.0 的工作方式不同。
---> 我尝试扩展 AboutAction 本身(org.eclipse.ui.internal.dialogs.AboutDialog),这样我就可以在 DialogArea 文本中添加一行,并在单击“许可证”按钮时添加一个可滚动的对话框 GUI。但是所有方法都在 API 中受到保护,我看到它说用户可以使用但不能覆盖(与 Dialog 类相同)
---> 我尝试扩展默认的 AbstractHandler ,并在执行方法中创建一个 Dialog 对象,我基本上想在其中一一添加我需要的所有内容。唯一的问题是我无法在执行方法中处理 Dialog 对象,因为它在执行方法结束之前仍然是空引用,因此我无法在没有 nullPointerException 困扰的情况下向其中添加内容。
---> 我还尝试添加 <property>
到plugin.xml本身。这似乎是 4.x 的功能。 “关于”菜单下的描述字段也无法在“关于”对话框文本区域中写入文本
@SuppressWarnings("restriction")
public class AboutActionStableHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException
{
helpDialog = new AboutDialog(HandlerUtil.getActiveShellChecked(event));
helpDialog.open();
//helpDialog.getDialogArea();
Shell aboutShell = helpDialog.getShell();
aboutShell.setLayout(new GridLayout());
Label version = new Label(aboutShell, SWT.NONE);
version.setText(Platform.getProduct().getDefiningBundle().getVersion().toString());
version.setLayoutData(GridDataBuilder.create().
grabExcessHorizontalSpace(true).
widthHint(500).
heightHint(5).
horizontalAlignment(SWT.FILL).build());
return null;
}
所以当我点击 about Gui 时,我最终得到了这个运行时错误
java.lang.NullPointerException
at com.magic.gui.commands.AboutActionStableHandler.execute(AboutActionStableHandler.java:28)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at com.magic.rcp.Application.start(Application.java:87)
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:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
最佳答案
调用helpDialog.open()
会显示对话框,并且在关闭对话框之前不会返回,而此时修改对话框已经为时已晚。
您可以调用helpDialog.create()
来创建对话框,然后再调用open()
。
但是 AboutDialog
是一个内部类,尝试修改它,就像这样违反了Eclipse API Rules of Engagement这就是为什么您必须取消限制警告。 AboutDialog
官方无法修改。如果您想要一个不同的对话框,您应该编写自己的对话框。
关于java - 如何在 Eclipse 3.8.1 RCP 应用程序中的帮助菜单下自定义“关于”条目的文本和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42162653/