如何为 Eclipse 3.8.1 RCP 应用程序中帮助菜单下的关于条目自定义文本和按钮
How to customize text and buttons for the About entry under the Help Menu in a Eclipse 3.8.1 RCP application
我正在尝试自定义 Eclipse 3.8.1 上的“帮助”->“关于”菜单条目。我尝试了两种 3.x 友好的方法,因为 Eclipse 4.0 的工作方式不同。
---> 我尝试扩展 AboutAction 本身 (org.eclipse.ui.internal.dialogs.AboutDialog),这样我就可以在 DialogArea 文本中添加一行,并在许可按钮 clicked.But 时添加一个可滚动的对话框 Gui方法在 API 中受到保护 我看到它说用户可以使用但不能覆盖(与对话框相同 class)
---> 我尝试扩展默认的 AbstractHandler 并在执行方法中创建一个 Dialog 对象,我基本上想在其中一一添加所有我需要的东西。唯一的问题是我无法在 execute 方法中处理 Dialog 对象,因为它在 execute 方法结束之前仍然是空引用,所以我无法在没有 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;
}
所以当我点击关于 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(CommandContributionItem.java:815)
at org.eclipse.ui.menus.CommandContributionItem.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(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench.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()
会显示对话框,但不会 return 直到关闭才修改它。
您可以调用 helpDialog.create()
来创建对话框,然后再调用 open()
。
但是 AboutDialog
是一个内部 class 试图像这样修改它违反了 Eclipse API Rules of Engagement 这就是为什么你不得不抑制限制警告。 AboutDialog
官方是没办法修改的。如果你想要一个不同的对话,你真的应该写你自己的对话。
我正在尝试自定义 Eclipse 3.8.1 上的“帮助”->“关于”菜单条目。我尝试了两种 3.x 友好的方法,因为 Eclipse 4.0 的工作方式不同。
---> 我尝试扩展 AboutAction 本身 (org.eclipse.ui.internal.dialogs.AboutDialog),这样我就可以在 DialogArea 文本中添加一行,并在许可按钮 clicked.But 时添加一个可滚动的对话框 Gui方法在 API 中受到保护 我看到它说用户可以使用但不能覆盖(与对话框相同 class)
---> 我尝试扩展默认的 AbstractHandler 并在执行方法中创建一个 Dialog 对象,我基本上想在其中一一添加所有我需要的东西。唯一的问题是我无法在 execute 方法中处理 Dialog 对象,因为它在 execute 方法结束之前仍然是空引用,所以我无法在没有 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;
}
所以当我点击关于 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(CommandContributionItem.java:815)
at org.eclipse.ui.menus.CommandContributionItem.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(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench.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()
会显示对话框,但不会 return 直到关闭才修改它。
您可以调用 helpDialog.create()
来创建对话框,然后再调用 open()
。
但是 AboutDialog
是一个内部 class 试图像这样修改它违反了 Eclipse API Rules of Engagement 这就是为什么你不得不抑制限制警告。 AboutDialog
官方是没办法修改的。如果你想要一个不同的对话,你真的应该写你自己的对话。