1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.editor;
19
20 import org.eclipse.draw2d.PositionConstants;
21 import org.eclipse.gef.editparts.ZoomManager;
22 import org.eclipse.gef.ui.actions.ActionBarContributor;
23 import org.eclipse.gef.ui.actions.AlignmentRetargetAction;
24 import org.eclipse.gef.ui.actions.GEFActionConstants;
25 import org.eclipse.gef.ui.actions.ZoomComboContributionItem;
26 import org.eclipse.gef.ui.actions.ZoomInRetargetAction;
27 import org.eclipse.gef.ui.actions.ZoomOutRetargetAction;
28 import org.eclipse.jface.action.IMenuManager;
29 import org.eclipse.jface.action.IToolBarManager;
30 import org.eclipse.jface.action.Separator;
31 import org.eclipse.ui.IWorkbenchWindow;
32 import org.eclipse.ui.actions.ActionFactory;
33 import org.eclipse.ui.actions.RetargetAction;
34
35 import pl.edu.agh.cast.editor.action.FitZoomAction;
36 import pl.edu.agh.cast.editor.action.FitZoomRetargetAction;
37 import pl.edu.agh.cast.ui.advisor.ApplicationActionBarAdvisor;
38
39
40
41
42
43
44 public class DefaultActionBarContributor extends ActionBarContributor {
45
46
47
48
49
50
51 @Override
52 public void contributeToMenu(IMenuManager menuManager) {
53 super.contributeToMenu(menuManager);
54
55 IMenuManager editMenu = menuManager.findMenuUsingPath(ApplicationActionBarAdvisor.M_EDIT);
56 editMenu.appendToGroup(ApplicationActionBarAdvisor.M_EDIT_UNDOREDO, getAction(ActionFactory.UNDO.getId()));
57 editMenu.appendToGroup(ApplicationActionBarAdvisor.M_EDIT_UNDOREDO, getAction(ActionFactory.REDO.getId()));
58
59 editMenu.appendToGroup(ApplicationActionBarAdvisor.M_EDIT_COPYPASTE, getAction(ActionFactory.DELETE.getId()));
60
61 }
62
63
64
65
66
67
68 @Override
69 public void contributeToToolBar(IToolBarManager toolBarManager) {
70 super.contributeToToolBar(toolBarManager);
71
72
73 toolBarManager.add(new Separator(ApplicationActionBarAdvisor.M_EDIT_COPYPASTE));
74 toolBarManager.add(new Separator(ApplicationActionBarAdvisor.M_EDIT_FIND));
75
76 toolBarManager.add(new Separator(ApplicationActionBarAdvisor.M_DIAGRAM_EXPORT));
77 toolBarManager.add(new Separator(ApplicationActionBarAdvisor.M_DIAGRAM_LAYOUT));
78
79 toolBarManager.add(new Separator(ApplicationActionBarAdvisor.M_VIEW_ALIGN_HORIZONTAL));
80 toolBarManager.add(getAction(GEFActionConstants.ALIGN_LEFT));
81 toolBarManager.add(getAction(GEFActionConstants.ALIGN_CENTER));
82 toolBarManager.add(getAction(GEFActionConstants.ALIGN_RIGHT));
83
84 toolBarManager.add(new Separator(ApplicationActionBarAdvisor.M_VIEW_ALIGN_VERTICAL));
85 toolBarManager.add(getAction(GEFActionConstants.ALIGN_TOP));
86 toolBarManager.add(getAction(GEFActionConstants.ALIGN_MIDDLE));
87 toolBarManager.add(getAction(GEFActionConstants.ALIGN_BOTTOM));
88
89 toolBarManager.add(new Separator(ApplicationActionBarAdvisor.M_VIEW_ZOOM));
90 String[] zoomStrings = new String[] { ZoomManager.FIT_ALL, ZoomManager.FIT_HEIGHT, ZoomManager.FIT_WIDTH };
91 toolBarManager.add(new ZoomComboContributionItem(getPage(), zoomStrings));
92
93 toolBarManager.add(getAction(GEFActionConstants.ZOOM_IN));
94 toolBarManager.add(getAction(GEFActionConstants.ZOOM_OUT));
95 toolBarManager.add(getAction(FitZoomAction.ID));
96 }
97
98 @Override
99 protected void buildActions() {
100 addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
101 addRetargetAction(new AlignmentRetargetAction(PositionConstants.CENTER));
102 addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
103 addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
104 addRetargetAction(new AlignmentRetargetAction(PositionConstants.MIDDLE));
105 addRetargetAction(new AlignmentRetargetAction(PositionConstants.BOTTOM));
106
107 addRetargetAction(new ZoomInRetargetAction());
108 addRetargetAction(new ZoomOutRetargetAction());
109 addRetargetAction(new FitZoomRetargetAction());
110
111 IWorkbenchWindow workbenchWindow = getPage().getWorkbenchWindow();
112 addRetargetAction((RetargetAction)ActionFactory.UNDO.create(workbenchWindow));
113 addRetargetAction((RetargetAction)ActionFactory.REDO.create(workbenchWindow));
114 addRetargetAction((RetargetAction)ActionFactory.COPY.create(workbenchWindow));
115 addRetargetAction((RetargetAction)ActionFactory.PASTE.create(workbenchWindow));
116 addRetargetAction((RetargetAction)ActionFactory.DELETE.create(workbenchWindow));
117
118 }
119
120
121
122
123
124
125 @Override
126 public void declareGlobalActionKeys() {
127 addGlobalActionKey(ActionFactory.UNDO.getId());
128 addGlobalActionKey(ActionFactory.REDO.getId());
129 addGlobalActionKey(ActionFactory.COPY.getId());
130 addGlobalActionKey(ActionFactory.PASTE.getId());
131 addGlobalActionKey(ActionFactory.DELETE.getId());
132 }
133
134 }