如何实现类似于Eclipse提供的Override / Implement的小部件?

时间:2012-01-09 19:36:01

标签: eclipse eclipse-plugin eclipse-pde

我想执行一些操作并显示与Eclipse提供的Override Implemet窗口类似的窗口。

我发现this post但我仍然在努力。

我创建了动作:

   <objectContribution
            id="Test.objectContribution1"
            objectClass="org.eclipse.core.resources.IProject">

            <action
               label="MyView"
               retarget="true"
               menubarPath="addition"
               class="test.plugin.popup.actions.MyViewAction"
               id="test.plugin.popup.actions.MyViewAction"
               >
         </action>

我刚刚复制了OverrideMethodsAction Eclipse类并将其重命名为MyViewAction。 当我点击我的新动作时,我得到了例外:

    !ENTRY org.eclipse.libra.facet 4 0 2012-01-09 14:50:54.635
    !MESSAGE startup class must implement org.eclipse.ui.IStartup

    !ENTRY org.eclipse.ui 4 4 2012-01-09 14:51:03.052
    !MESSAGE Could not create action delegate for id: test.plugin.popup.actions.MyViewAction

    !ENTRY org.eclipse.equinox.registry 4 1 2012-01-09 14:51:03.053
    !MESSAGE Plug-in "test" was unable to instantiate class 

    test.plugin.popup.actions.MyViewAction.
        !STACK 0
        java.lang.InstantiationException: test.plugin.popup.actions.MyViewAction
            at java.lang.Class.newInstance0(Class.java:357)
            at java.lang.Class.newInstance(Class.java:325)
            at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:184)
            at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
            at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
            at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
            at org.eclipse.ui.internal.WorkbenchPlugin$1.run(WorkbenchPlugin.java:268)
            at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
            at org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java:264)
            at org.eclipse.ui.internal.PluginAction.createDelegate(PluginAction.java:122)
            at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:223)
            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:3588)
            at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3209)
            at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
            at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
            at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
            at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
            at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
            at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
            at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
            at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
            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:344)
            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:622)
            at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
            at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
            at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

我不知道还能做什么或在哪里看。

由于

编辑:

我无法添加无参数构造函数。我不知道怎么做。

我再次开始,我将GenerateToStringAction,GenerateMethodAbstractAction和SelectionDispatchAction类复制到我的项目中,并将它们重命名为GenerateToStringActionAG,GenerateMethodAbstractActionAG和SelectionDispatchActionAG。

当我点击我的动作时,我期待看到GenerateToString()窗口,但我得到了:

java.lang.ClassNotFoundException: test.plugin.popup.actions.GenerateToStringActionAG
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1207)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:174)
    at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
    at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
    at org.eclipse.ui.internal.WorkbenchPlugin$1.run(WorkbenchPlugin.java:268)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java:264)
    at org.eclipse.ui.internal.PluginAction.createDelegate(PluginAction.java:122)
    at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:223)
    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:3588)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3209)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
    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:344)
    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:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

我认为我的方式非常错误。

1 个答案:

答案 0 :(得分:0)

你的班级test.plugin.popup.actions.MyViewAction需要一个无参数的构造函数。

虽然我们在此,但您可能需要查看this answer