1

I am writing a new command for my eclipse RCP that should perform one task if one part is active, and other task if other task is active (eg. copy command that copies files if project explorer is active or copies text if text editor is active). I was thinking of having 2 handlers for one command (one defined in fragment.e4xmi of one plugin and other handler in fragment.e4xmi of another plugin). Is this doable?

On this page http://www.vogella.com/tutorials/EclipseRCP/article.html#importantmodelelement_examples it says that:

Each command can have only one valid handler for a given scope. The Eclipse framework selects the handler most specific to the model element.

For example, if you have two handlers for the "Copy" command, one for the window and another one for the part then the runtime selects the handlers closest to model element which is currently selected by the user.

Is it possible to have 2 handlers for one command in e4?

deckard cain
  • 497
  • 10
  • 24

1 Answers1

1

If you mean two handlers being called for one invocation of the command the answer is No.

As the reference you quote says the handler closest to the current model element is chosen.

For multiple handlers applying to different parts put each handler in the Handlers list for the part you want it to apply to. This can be in a fragment or the main e4xmi file.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • I didn't mean one command executing two handlers at once, but invoking one of those handler's execute method based on which part is active. – deckard cain Aug 10 '16 at 20:33
  • Well the quote you gave tells you about that. I have added some clarification to the my answer. – greg-449 Aug 10 '16 at 20:40
  • Tried what you suggested, adding handlers to the handlers list for the parts, but that did not do the trick :(. I can only see my command enabled for one part only. – deckard cain Aug 10 '16 at 20:58
  • btw, one of the parts is actually not a part described in the fragment file but an FXEditor defined inside plugin.xml. Any ideas on how to add handler to that editor? Programmatically perhaps? – deckard cain Aug 10 '16 at 21:18