In this quick note I show you how to add actions to the menu bar and cool bar of your Eclipse RCP application.
First you need to create your own class that extends class ActionBarAdvisor - for example:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
...
}
Second you need to define a makeActions method in which you define your application's actions - for example the below snippet creates an exitAction which is a workbench supplied action that represents the act of closing the application:
protected void makeActions(IWorkbenchWindow window) { exitAction = ActionFactory.QUIT.create(window); register(exitAction); ... }
Third you need to create your menu bar, add menu items to it and add your newly created actions through the fillMenuBar method - for example:
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager fileMenu = new MenuManager("&File", "file");
fileMenu.add(exitAction);
menuBar.add(fileMenu);
...
}
Lastly to create a cool bar you need to supply a fillCoolBar method - for example:
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolBar = new ToolBarManager(coolBar.getStyle());
coolBar.add(toolBar);
toolBar.add(exitAction);
...
}
This is a basic skeleton but I hope you have grabed the idea.
Until next time...
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire