1 /*
2 * Created on Jan 19, 2004
3 *
4 * Copyright (C) 2004 Sean Ruff
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20 package org.un4gvn.editorviewer.internal.action;
21
22 import org.eclipse.jface.action.Action;
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.action.IMenuManager;
25 import org.eclipse.jface.action.MenuManager;
26 import org.eclipse.jface.action.Separator;
27 import org.eclipse.ui.IActionBars;
28 import org.eclipse.ui.IWorkbenchActionConstants;
29 import org.un4gvn.editorviewer.internal.EditorViewerPlugin;
30 import org.un4gvn.editorviewer.internal.Messages;
31 import org.un4gvn.editorviewer.internal.ui.EditorViewer;
32
33 /***
34 * Adds view menus to switch between flat,semi-flat,structured, and type layout.
35 * <p>
36 * @author Sean Ruff
37 */
38
39 public class LayoutActionGroup extends MultiActionGroup {
40
41 /***
42 * EditorViewer instance for callback methods
43 */
44 private EditorViewer _viewer = null;
45
46
47 /***
48 * Constructor
49 * @param viewer
50 * @param layoutMode
51 */
52 public LayoutActionGroup(EditorViewer viewer, int layoutMode) {
53 super(createActions(viewer), layoutMode);
54 _viewer = viewer;
55 }
56
57 /***
58 * Fill the action bars with the submenu and actions
59 */
60 public void fillActionBars(IActionBars actionBars) {
61 super.fillActionBars(actionBars);
62 contributeToViewMenu(actionBars.getMenuManager());
63 }
64
65 /***
66 * Contribute the submenu and actions to the MenuManager
67 * @param viewMenu MenuManager to modify
68 */
69 private void contributeToViewMenu(IMenuManager viewMenu) {
70 viewMenu.add(new Separator());
71
72 // Create layout sub menu
73 IMenuManager layoutSubMenu= new MenuManager(Messages.getString("LayoutActionGroup.0")); //$NON-NLS-1$
74 final String layoutGroupName= Messages.getString("LayoutActionGroup.1"); //$NON-NLS-1$
75 Separator marker= new Separator(layoutGroupName);
76
77 viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
78 viewMenu.add(marker);
79 viewMenu.appendToGroup(layoutGroupName, layoutSubMenu);
80 viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS+Messages.getString("LayoutActionGroup.2"))); //$NON-NLS-1$
81 addActions(layoutSubMenu);
82 }
83
84 /***
85 * Create a list of actions to add to the new menu
86 * @param viewer
87 * @return IAction[]
88 */
89 private static IAction[] createActions(EditorViewer viewer) {
90
91 EditorViewerPlugin plugin = EditorViewerPlugin.getInstance();
92
93 IAction hierLayoutAction = new LayoutAction(viewer, EditorViewerPlugin.HIERARCHICAL_MODE);
94 hierLayoutAction.setText(Messages.getString("LayoutActionGroup.3")); //$NON-NLS-1$
95 hierLayoutAction.setToolTipText(Messages.getString("LayoutActionGroup.4")); //$NON-NLS-1$
96 hierLayoutAction.setDescription(Messages.getString("LayoutActionGroup.5")); //$NON-NLS-1$
97 hierLayoutAction.setImageDescriptor(plugin.getImageDescriptor(Messages.getString("LayoutActionGroup.6"))); //$NON-NLS-1$
98
99 IAction semiFlatLayoutAction = new LayoutAction(viewer, EditorViewerPlugin.SEMI_FLAT_MODE);
100 semiFlatLayoutAction.setText(Messages.getString("LayoutActionGroup.11")); //$NON-NLS-1$
101 semiFlatLayoutAction.setToolTipText(Messages.getString("LayoutActionGroup.12")); //$NON-NLS-1$
102 semiFlatLayoutAction.setDescription(Messages.getString("LayoutActionGroup.13")); //$NON-NLS-1$
103 semiFlatLayoutAction.setImageDescriptor(plugin.getImageDescriptor(Messages.getString("LayoutActionGroup.14"))); //$NON-NLS-1$
104
105 IAction flatLayoutAction = new LayoutAction(viewer, EditorViewerPlugin.FLAT_MODE);
106 flatLayoutAction.setText(Messages.getString("LayoutActionGroup.7")); //$NON-NLS-1$
107 flatLayoutAction.setToolTipText(Messages.getString("LayoutActionGroup.8")); //$NON-NLS-1$
108 flatLayoutAction.setDescription(Messages.getString("LayoutActionGroup.9")); //$NON-NLS-1$
109 flatLayoutAction.setImageDescriptor(plugin.getImageDescriptor(Messages.getString("LayoutActionGroup.10"))); //$NON-NLS-1$
110
111 IAction typeLayoutAction = new LayoutAction(viewer, EditorViewerPlugin.TYPE_MODE);
112 typeLayoutAction.setText(Messages.getString("LayoutActionGroup.15")); //$NON-NLS-1$
113 typeLayoutAction.setToolTipText(Messages.getString("LayoutActionGroup.16")); //$NON-NLS-1$
114 typeLayoutAction.setDescription(Messages.getString("LayoutActionGroup.17")); //$NON-NLS-1$
115 typeLayoutAction.setImageDescriptor(plugin.getImageDescriptor(Messages.getString("LayoutActionGroup.18"))); //$NON-NLS-1$
116
117 //NOTE: the value of the LayoutMode parameter (second param) suppliedto each LayoutAction instance
118 //must match the position within the following returned array
119 // Example since EditorViewerPlugin.HIERARCHICAL_MODE == 0 then it must be the first element in the array
120 return new IAction[]{ hierLayoutAction, semiFlatLayoutAction, flatLayoutAction, typeLayoutAction};
121 }
122 }
123
124 /***
125 * Action class which will run the appropriate action
126 * depending on it's supplied layoutMode flag
127 * @author nbk4bsx
128 * @since Jan 12, 2004
129 *
130 */
131 class LayoutAction extends Action implements IAction {
132
133 /***
134 * Mode for this action
135 */
136 private int _mode;
137
138 /***
139 * EditorViewer for callbacks
140 */
141 private EditorViewer _viewer;
142
143 /***
144 * Create a new LayoutAction with the specified layoutMode
145 * @param viewer
146 * @param layoutMode
147 */
148 public LayoutAction(EditorViewer viewer, int layoutMode) {
149 _mode = layoutMode;
150 _viewer = viewer;
151 }
152
153 /***
154 * @see org.eclipse.jface.action.IAction#run()
155 */
156 public void run() {
157 _viewer.setLayoutMode(_mode);
158 }
159 }
This page was automatically generated by Maven