简体   繁体   中英

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. 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. Can anybody see the problem in my code:

This for 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:

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
    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. 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.

Note: The org.eclipse.ui.popupMenus is now deprecated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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