1 | package de.ugoe.cs.swe.exercises; |
---|
2 | |
---|
3 | import org.eclipse.jface.action.IMenuManager; |
---|
4 | import org.eclipse.jface.action.MenuManager; |
---|
5 | import org.eclipse.ui.IWorkbenchWindow; |
---|
6 | import org.eclipse.ui.actions.ActionFactory; |
---|
7 | import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; |
---|
8 | import org.eclipse.ui.application.ActionBarAdvisor; |
---|
9 | import org.eclipse.ui.application.IActionBarConfigurer; |
---|
10 | |
---|
11 | /** |
---|
12 | * An action bar advisor is responsible for creating, adding, and disposing of |
---|
13 | * the actions added to a workbench window. Each window will be populated with |
---|
14 | * new actions. |
---|
15 | */ |
---|
16 | public class ApplicationActionBarAdvisor extends ActionBarAdvisor { |
---|
17 | |
---|
18 | // Actions - important to allocate these only in makeActions, and then use |
---|
19 | // them |
---|
20 | // in the fill methods. This ensures that the actions aren't recreated |
---|
21 | // when fillActionBars is called with FILL_PROXY. |
---|
22 | private IWorkbenchAction exitAction; |
---|
23 | private IWorkbenchAction aboutAction; |
---|
24 | |
---|
25 | public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { |
---|
26 | super(configurer); |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | @Override |
---|
32 | protected void makeActions(final IWorkbenchWindow window) { |
---|
33 | // Creates the actions and registers them. |
---|
34 | // Registering is needed to ensure that key bindings work. |
---|
35 | // The corresponding commands keybindings are defined in the plugin.xml |
---|
36 | // file. |
---|
37 | // Registering also provides automatic disposal of the actions when |
---|
38 | // the window is closed. |
---|
39 | |
---|
40 | exitAction = ActionFactory.QUIT.create(window); |
---|
41 | register(exitAction); |
---|
42 | aboutAction = ActionFactory.ABOUT.create(window); |
---|
43 | aboutAction.setText("About"); |
---|
44 | register(aboutAction); |
---|
45 | } |
---|
46 | |
---|
47 | @Override |
---|
48 | protected void fillMenuBar(IMenuManager menuBar) { |
---|
49 | MenuManager fileMenu = new MenuManager("&File"); |
---|
50 | menuBar.add(fileMenu); |
---|
51 | fileMenu.add(aboutAction); |
---|
52 | fileMenu.add(exitAction); |
---|
53 | |
---|
54 | //MenuManager helpMenu = new MenuManager("&Help"); |
---|
55 | //menuBar.add(helpMenu); |
---|
56 | |
---|
57 | } |
---|
58 | |
---|
59 | } |
---|