简体   繁体   English

Eclipse插件创建信息对话框错误

[英]Eclipse plugin creates information dialog error

I have made menu item in project explorer, where the user can right click on any java project and then select "pop menu" from the context menu. 我已经在项目浏览器中创建了菜单项,用户可以在其中右键单击任何Java项目,然后从上下文菜单中选择“弹出菜单”。 The problem is the when I click on that it gives me a information dialog box that says "the chosen operation is not currently available" it should actually show the hello world dialog box but it doesn't. 问题是,当我单击它时,它会给我一个信息对话框,提示“所选的操作当前不可用”,它实际上应该显示hello world对话框,但实际上没有。 Can anybody see the problem in my code: 谁能在我的代码中看到问题:

This for plugin.xml: 对于plugin.xml:

<plugin>
   <extension
     point="org.eclipse.ui.popupMenus">
     <objectContribution
        id ="org.eclipse.ui.examples.project"
        objectClass="org.eclipse.core.resources.IProject">
        <action id="org.eclipse.ui.examples.project.action1"
            label = "popup menu"
            menubarPath = "additions"
            class = "org.eclipse.examples.HelloWorld"
            definitonId = "org.eclipse.ui.examples.project.action1"
            enablesFor ="1">
        </action>
     </objectContribution>

This is the code for helloworld.java file: 这是helloworld.java文件的代码:

public class HelloWorld implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
public void run(IAction action) {
    MessageDialog.openInformation(
        window.getShell(),
        "HelloWorld",
        "Hello, Eclipse world");
}.....

You probably need to specify 您可能需要指定

 adaptable="true"

as part of the objectContribution : 作为objectContribution一部分:

 <objectContribution
    id ="org.eclipse.ui.examples.project"
    objectClass="org.eclipse.core.resources.IProject"
    adaptable="true">

This is because most user interface objects do not implement the workspace objects such as IProject directly. 这是因为大多数用户界面对象并不直接实现工作区对象,例如IProject Instead they provide an 'adapter' to convert to the object, you must specify the 'adaptable' attribute to make the menu code look for the adapter. 相反,它们提供了一个“适配器”以转换为对象,您必须指定“ adaptable”属性以使菜单代码寻找适配器。

Note: The org.eclipse.ui.popupMenus is now deprecated. 注意:现在不建议使用org.eclipse.ui.popupMenus

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM