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.
Asked
Active
Viewed 1,724 times
2
-
1Are you asking how to add things to a context menu or how to show a view? Are you using an Eclipse 4 RCP with an application model or Eclipse 3.x compatibility mode. – greg-449 Oct 09 '13 at 17:54
-
how to show a view using Eclipse 4 but with the menu action! – epock Oct 10 '13 at 14:04
-
Sorry in Eclipse RCP 4.x the views = the parts! – epock Oct 11 '13 at 09:32
-
So you want to open an `MPart` from a context menu? – greg-449 Oct 11 '13 at 09:37
1 Answers
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