View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: DefaultActionBarContributor.java
13   * Created: 2007-00-00
14   * Author: cast
15   * $Id: DefaultActionBarContributor.java 2774 2009-04-22 13:56:23Z tmilos $
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   * Default {@link ActionBarContributor}.
41   *
42   * @author AGH CAST Team
43   */
44  public class DefaultActionBarContributor extends ActionBarContributor {
45  
46  	/**
47  	 * {@inheritDoc}
48  	 *
49  	 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
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  	 * {@inheritDoc}
65  	 *
66  	 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(org.eclipse.jface.action.IToolBarManager)
67  	 */
68  	@Override
69  	public void contributeToToolBar(IToolBarManager toolBarManager) {
70  		super.contributeToToolBar(toolBarManager);
71  		// toolBarManager.
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 	 * {@inheritDoc}
122 	 *
123 	 * @see org.eclipse.gef.ui.actions.ActionBarContributor#declareGlobalActionKeys()
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 }