我正在尝试自定义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方法结束之前,它始终为null引用,因此如果没有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$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参与规则,这就是为什么您必须取消限制警告的原因。无法AboutDialog
正式修改。如果您想使用其他对话框,则应该编写自己的对话框。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句