我正在尝试自定义Eclipse 3.8.1上的Help-> About菜单项。我尝试了两种3.x友好方法,因为Eclipse 4.0的工作方式不同。
--->我尝试扩展AboutAction本身(org.eclipse.ui.internal.dialogs.AboutDialog),这样我就可以在DialogArea Text中添加一行,并在单击License按钮时添加一个可滚动的Dialog Gui。但是所有方法都受到保护。 API我看到它说用户可以使用但不能覆盖(与Dialog类相同)
--->我尝试扩展默认的AbstractHandler,在execute方法中我创建了一个Dialog对象,我基本上想要逐个添加所有需要的东西。唯一的问题是我无法处理execute方法中的Dialog对象,因为它在execute方法结束之前仍然是一个空引用,因此如果没有nullPointerException使我烦恼,我就无法添加它。
---&GT;我还尝试将<property>
添加到plugin.xml本身。这似乎是一个4.x功能。 about菜单下的description字段也无法在About对话框文本区域中写入文本
@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)
答案 0 :(得分:1)
调用helpDialog.create()
会显示该对话框,直到它被修改时才会关闭。
您可以致电open()
创建对话框,稍后再致电AboutDialog
。
但是 AboutDialog
是内部类,试图修改它,因为这违反了Eclipse API Rules of Engagement这就是为什么你不得不压制限制警告。 trix_editor
无法正式修改。如果你想要一个不同的对话框,你应该写自己的对话框。