2

I'm working for a short time on the libraries of eclipse 4.x someone could tell me how can I open a view through from the context menu? Thank you in advance.

greg-449
  • 109,219
  • 232
  • 102
  • 145
epock
  • 21
  • 4

1 Answers1

1

To show a part anywhere you should define a command in the application model and a handler for the command. To show a part in the handler use:

@Execute
public void execute(EPartService partService)
{
  MPart mpart = partService.showPart(part id, PartState.ACTIVATE);
}

In the application Part definition for your part add a Popup Menu to the Menus section. In the popup menu define a HandledMenuItem for your command.

To register the popup menu as the context menu for a control (tree, table etc) use:

@Inject
private EMenuService;

...

menuService.registerContextMenu(control, menu id); 
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thanks a lot.... Works!!!!! :D Could you tell me where I can find some material on Eclipse 4.x ? It is very hard for me!!! – epock Oct 11 '13 at 13:14
  • This is the best intro: http://www.vogella.com/articles/EclipseRCP/article.html There is also an e-book by the same author (extended version of the tutorial) – greg-449 Oct 11 '13 at 13:26
  • Sorry..... another question.... :) If I wanted to pass parameters during the creation of the part. How do I do? – epock Oct 17 '13 at 14:47
  • The `MPart` returned by `showView` has a `getObject()` method which give you your class for the part. So you call methods on the class or run Injection on the class. – greg-449 Oct 21 '13 at 09:26
  • Greg.... sorry.... can you write an example of use of Injection? Sorry but for me is the first time!!! thx :) – epock Oct 23 '13 at 14:28
  • Have a look at my second answer to this question: http://stackoverflow.com/questions/19535342/how-to-implement-save-as-functionality-for-our-part – greg-449 Oct 23 '13 at 14:58