0

I have a menu which has a label bound to a command.

Lets say:

plugin.xml

<menu label="Settings">
         <command 
            commandId="prototype.standalone.MainDirectory"
            label="Main">
         </command>
</menu>

public class MainDirectory extends AbstractHandler {
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
         // How can I call from here all my business methods from my main View. 
         // Do I have to use DI? If yes, can you give me an easy example related to this snippet?     
         return null;
    }
}

As asked in the comment. How can I call my methods? Because if I never instantiate an MainDirectory so I also can not just pass Objects from my createControls - I think that I have to use Dependency Injection but I don't know how. Can someone give me an example or an other solution

Edit: Or is it maybe possible to add a Listener to the menu Item? Would make all much easier. Didn't found anything

Michael Brenndoerfer
  • 3,483
  • 2
  • 39
  • 50

2 Answers2

0

Seems to be the easiest way not to create the menu with org.eclipse.ui.menu instead just use the basic SWT Menu and add it to the frame - I anyway have a standalone application, so the eclipse menu would be an overkill

Michael Brenndoerfer
  • 3,483
  • 2
  • 39
  • 50
0

You should also have below in your plugin.xml

<extension point="org.eclipse.ui.commands">
  <command
        defaultHandler="your MainDirectory class path"
        id="prototype.standalone.MainDirectory"
        name="My Label">
  </command>
</extension>
Baz
  • 36,440
  • 11
  • 68
  • 94
Raghav
  • 53
  • 7