no

How to Open a View Using Command in Eclipse Rcp

Objective: 1.) To execute an eclipse rcp command in code 2.) To open an eclipse rcp view in command Most of the time you will just use t...

Objective:
1.) To execute an eclipse rcp command in code
2.) To open an eclipse rcp view in command

Most of the time you will just use the extension tab in the plugin.xml but for those who chose to implement in code here's how they're done:

Solution:
1.) By consulting the eclipse-rcp documentation, this is how I done it:
//execute command
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IViewPart view = window.getActivePage().findView("your.view.class.id");
IHandlerService service = (IHandlerService) view.getSite().getService(IHandlerService.class);
service.executeCommand("your.application.command.id", null);
Please take note of the findView and executeCommand parameters, which are IDs.

2.) Opening an eclipse-rcp view in code:
//open view
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
 //any view in your application
 window.getActivePage().showView(you.view.class.id); 
} catch (PartInitException e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
}

Related

java-eclipse-rcp 4119257421947031396

Post a Comment Default Comments

2 comments

Samuel Kroslak said...

great, that helped, thanks!

Anonymous said...

The brown Text is difficult to spot on the brown background :P

item