KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > ui > actions > GenerateActionGroup


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.ui.actions;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.Assert;
18
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.action.IMenuManager;
21 import org.eclipse.jface.action.MenuManager;
22 import org.eclipse.jface.action.Separator;
23 import org.eclipse.jface.commands.ActionHandler;
24 import org.eclipse.jface.viewers.ISelection;
25 import org.eclipse.jface.viewers.ISelectionChangedListener;
26 import org.eclipse.jface.viewers.ISelectionProvider;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28
29 import org.eclipse.ui.IActionBars;
30 import org.eclipse.ui.IViewPart;
31 import org.eclipse.ui.IWorkbenchSite;
32 import org.eclipse.ui.actions.ActionGroup;
33 import org.eclipse.ui.actions.AddBookmarkAction;
34 import org.eclipse.ui.handlers.IHandlerActivation;
35 import org.eclipse.ui.handlers.IHandlerService;
36 import org.eclipse.ui.part.Page;
37 import org.eclipse.ui.texteditor.IUpdate;
38 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
39
40 import org.eclipse.ui.ide.IDEActionFactory;
41
42 import org.eclipse.jdt.ui.IContextMenuConstants;
43
44 import org.eclipse.jdt.internal.ui.actions.ActionMessages;
45 import org.eclipse.jdt.internal.ui.actions.AddTaskAction;
46 import org.eclipse.jdt.internal.ui.actions.AllCleanUpsAction;
47 import org.eclipse.jdt.internal.ui.actions.FindBrokenNLSKeysAction;
48 import org.eclipse.jdt.internal.ui.actions.JDTQuickMenuAction;
49 import org.eclipse.jdt.internal.ui.actions.MultiSortMembersAction;
50 import org.eclipse.jdt.internal.ui.javaeditor.AddImportOnSelectionAction;
51 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
52
53 /**
54  * Action group that adds the source and generate actions to a part's context
55  * menu and installs handlers for the corresponding global menu actions.
56  *
57  * <p>
58  * This class may be instantiated; it is not intended to be subclassed.
59  * </p>
60  *
61  * @since 2.0
62  */

63 public class GenerateActionGroup extends ActionGroup {
64     
65     /**
66      * Pop-up menu: id of the source sub menu (value <code>org.eclipse.jdt.ui.source.menu</code>).
67      *
68      * @since 3.0
69      */

70     public static final String JavaDoc MENU_ID= "org.eclipse.jdt.ui.source.menu"; //$NON-NLS-1$
71

72     /**
73      * Pop-up menu: id of the import group of the source sub menu (value
74      * <code>importGroup</code>).
75      *
76      * @since 3.0
77      */

78     public static final String JavaDoc GROUP_IMPORT= "importGroup"; //$NON-NLS-1$
79

80     /**
81      * Pop-up menu: id of the generate group of the source sub menu (value
82      * <code>generateGroup</code>).
83      *
84      * @since 3.0
85      */

86     public static final String JavaDoc GROUP_GENERATE= "generateGroup"; //$NON-NLS-1$
87

88     /**
89      * Pop-up menu: id of the code group of the source sub menu (value
90      * <code>codeGroup</code>).
91      *
92      * @since 3.0
93      */

94     public static final String JavaDoc GROUP_CODE= "codeGroup"; //$NON-NLS-1$
95

96     /**
97      * Pop-up menu: id of the externalize group of the source sub menu (value
98      * <code>externalizeGroup</code>).
99      *
100      * TODO: Make API
101      */

102     private static final String JavaDoc GROUP_EXTERNALIZE= "externalizeGroup"; //$NON-NLS-1$
103

104     /**
105      * Pop-up menu: id of the comment group of the source sub menu (value
106      * <code>commentGroup</code>).
107      *
108      * TODO: Make API
109      */

110     private static final String JavaDoc GROUP_COMMENT= "commentGroup"; //$NON-NLS-1$
111

112     /**
113      * Pop-up menu: id of the edit group of the source sub menu (value
114      * <code>editGroup</code>).
115      *
116      * TODO: Make API
117      */

118     private static final String JavaDoc GROUP_EDIT= "editGroup"; //$NON-NLS-1$
119

120     private CompilationUnitEditor fEditor;
121     private IWorkbenchSite fSite;
122     private String JavaDoc fGroupName= IContextMenuConstants.GROUP_REORGANIZE;
123     private List JavaDoc fRegisteredSelectionListeners;
124     
125     private AddImportOnSelectionAction fAddImport;
126     private OverrideMethodsAction fOverrideMethods;
127     private GenerateHashCodeEqualsAction fHashCodeEquals;
128     private AddGetterSetterAction fAddGetterSetter;
129     private AddDelegateMethodsAction fAddDelegateMethods;
130     private AddUnimplementedConstructorsAction fAddUnimplementedConstructors;
131     private GenerateNewConstructorUsingFieldsAction fGenerateConstructorUsingFields;
132     private AddJavaDocStubAction fAddJavaDocStub;
133     private AddBookmarkAction fAddBookmark;
134     private AddTaskAction fAddTaskAction;
135     private ExternalizeStringsAction fExternalizeStrings;
136     private AllCleanUpsAction fCleanUp;
137     private FindBrokenNLSKeysAction fFindNLSProblems;
138     
139     private OrganizeImportsAction fOrganizeImports;
140     private MultiSortMembersAction fSortMembers;
141     private FormatAllAction fFormatAll;
142     
143     private static final String JavaDoc QUICK_MENU_ID= "org.eclipse.jdt.ui.edit.text.java.source.quickMenu"; //$NON-NLS-1$
144

145     private class SourceQuickAccessAction extends JDTQuickMenuAction {
146         public SourceQuickAccessAction(CompilationUnitEditor editor) {
147             super(editor, QUICK_MENU_ID);
148         }
149         protected void fillMenu(IMenuManager menu) {
150             fillQuickMenu(menu);
151         }
152     }
153     
154     private JDTQuickMenuAction fQuickAccessAction;
155     private IHandlerActivation fQuickAccessHandlerActivation;
156     private IHandlerService fHandlerService;
157
158     /**
159      * Note: This constructor is for internal use only. Clients should not call this constructor.
160      * @param editor the compilation unit editor
161      * @param groupName the group name to add the action to
162      */

163     public GenerateActionGroup(CompilationUnitEditor editor, String JavaDoc groupName) {
164         fSite= editor.getSite();
165         fEditor= editor;
166         fGroupName= groupName;
167                 
168         fAddImport= new AddImportOnSelectionAction(editor);
169         fAddImport.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_IMPORT);
170         fAddImport.update();
171         editor.setAction("AddImport", fAddImport); //$NON-NLS-1$
172

173         fOrganizeImports= new OrganizeImportsAction(editor);
174         fOrganizeImports.setActionDefinitionId(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS);
175         editor.setAction("OrganizeImports", fOrganizeImports); //$NON-NLS-1$
176

177         fSortMembers= new MultiSortMembersAction(editor);
178         fSortMembers.setActionDefinitionId(IJavaEditorActionDefinitionIds.SORT_MEMBERS);
179         editor.setAction("SortMembers", fSortMembers); //$NON-NLS-1$
180

181         fOverrideMethods= new OverrideMethodsAction(editor);
182         fOverrideMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.OVERRIDE_METHODS);
183         editor.setAction("OverrideMethods", fOverrideMethods); //$NON-NLS-1$
184

185         fAddGetterSetter= new AddGetterSetterAction(editor);
186         fAddGetterSetter.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_GETTER_SETTER);
187         editor.setAction("AddGetterSetter", fAddGetterSetter); //$NON-NLS-1$
188

189         fAddDelegateMethods= new AddDelegateMethodsAction(editor);
190         fAddDelegateMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_DELEGATE_METHODS);
191         editor.setAction("AddDelegateMethods", fAddDelegateMethods); //$NON-NLS-1$
192

193         fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(editor);
194         fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS);
195         editor.setAction("AddUnimplementedConstructors", fAddUnimplementedConstructors); //$NON-NLS-1$
196

197         fGenerateConstructorUsingFields= new GenerateNewConstructorUsingFieldsAction(editor);
198         fGenerateConstructorUsingFields.setActionDefinitionId(IJavaEditorActionDefinitionIds.GENERATE_CONSTRUCTOR_USING_FIELDS);
199         editor.setAction("GenerateConstructorUsingFields", fGenerateConstructorUsingFields); //$NON-NLS-1$
200

201         fHashCodeEquals= new GenerateHashCodeEqualsAction(editor);
202         fHashCodeEquals.setActionDefinitionId(IJavaEditorActionDefinitionIds.GENERATE_HASHCODE_EQUALS);
203         editor.setAction("GenerateHashCodeEquals", fHashCodeEquals); //$NON-NLS-1$
204

205         fAddJavaDocStub= new AddJavaDocStubAction(editor);
206         fAddJavaDocStub.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_JAVADOC_COMMENT);
207         editor.setAction("AddJavadocComment", fAddJavaDocStub); //$NON-NLS-1$
208

209         fCleanUp= new AllCleanUpsAction(editor);
210         fCleanUp.setActionDefinitionId(IJavaEditorActionDefinitionIds.CLEAN_UP);
211         editor.setAction("CleanUp", fCleanUp); //$NON-NLS-1$
212

213         fExternalizeStrings= new ExternalizeStringsAction(editor);
214         fExternalizeStrings.setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTERNALIZE_STRINGS);
215         editor.setAction("ExternalizeStrings", fExternalizeStrings); //$NON-NLS-1$
216

217         installQuickAccessAction();
218     }
219     
220     /**
221      * Creates a new <code>GenerateActionGroup</code>. The group
222      * requires that the selection provided by the page's selection provider
223      * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
224      *
225      * @param page the page that owns this action group
226      */

227     public GenerateActionGroup(Page page) {
228         this(page.getSite());
229     }
230
231     /**
232      * Creates a new <code>GenerateActionGroup</code>. The group
233      * requires that the selection provided by the part's selection provider
234      * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
235      *
236      * @param part the view part that owns this action group
237      */

238     public GenerateActionGroup(IViewPart part) {
239         this(part.getSite());
240     }
241     
242     private GenerateActionGroup(IWorkbenchSite site) {
243         fSite= site;
244         ISelectionProvider provider= fSite.getSelectionProvider();
245         ISelection selection= provider.getSelection();
246         
247         fOverrideMethods= new OverrideMethodsAction(site);
248         fOverrideMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.OVERRIDE_METHODS);
249         
250         fAddGetterSetter= new AddGetterSetterAction(site);
251         fAddGetterSetter.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_GETTER_SETTER);
252         
253         fAddDelegateMethods= new AddDelegateMethodsAction(site);
254         fAddDelegateMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_DELEGATE_METHODS);
255         
256         fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(site);
257         fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS);
258         
259         fGenerateConstructorUsingFields= new GenerateNewConstructorUsingFieldsAction(site);
260         fGenerateConstructorUsingFields.setActionDefinitionId(IJavaEditorActionDefinitionIds.GENERATE_CONSTRUCTOR_USING_FIELDS);
261
262         fHashCodeEquals= new GenerateHashCodeEqualsAction(site);
263         fHashCodeEquals.setActionDefinitionId(IJavaEditorActionDefinitionIds.GENERATE_HASHCODE_EQUALS);
264
265         fAddJavaDocStub= new AddJavaDocStubAction(site);
266         fAddJavaDocStub.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_JAVADOC_COMMENT);
267         
268         fAddBookmark= new AddBookmarkAction(site.getShell());
269         fAddBookmark.setActionDefinitionId(IWorkbenchActionDefinitionIds.ADD_BOOKMARK);
270         
271         // context-menu only -> no action definition ids
272

273         fAddTaskAction= new AddTaskAction(site);
274         fAddTaskAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.ADD_TASK);
275         
276         fExternalizeStrings= new ExternalizeStringsAction(site);
277         fExternalizeStrings.setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTERNALIZE_STRINGS);
278         
279         fFindNLSProblems= new FindBrokenNLSKeysAction(site);
280         fFindNLSProblems.setActionDefinitionId(FindBrokenNLSKeysAction.FIND_BROKEN_NLS_KEYS_ACTION_ID);
281         
282         fOrganizeImports= new OrganizeImportsAction(site);
283         fOrganizeImports.setActionDefinitionId(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS);
284         
285         fSortMembers= new MultiSortMembersAction(site);
286         fSortMembers.setActionDefinitionId(IJavaEditorActionDefinitionIds.SORT_MEMBERS);
287         
288         fFormatAll= new FormatAllAction(site);
289         fFormatAll.setActionDefinitionId(IJavaEditorActionDefinitionIds.FORMAT);
290         
291         fCleanUp= new AllCleanUpsAction(site);
292         fCleanUp.setActionDefinitionId(IJavaEditorActionDefinitionIds.CLEAN_UP);
293
294         
295         fOverrideMethods.update(selection);
296         fAddGetterSetter.update(selection);
297         fAddDelegateMethods.update(selection);
298         fAddUnimplementedConstructors.update(selection);
299         fGenerateConstructorUsingFields.update(selection);
300         fHashCodeEquals.update(selection);
301         fAddJavaDocStub.update(selection);
302         fExternalizeStrings.update(selection);
303         fFindNLSProblems.update(selection);
304         fCleanUp.update(selection);
305         fAddTaskAction.update(selection);
306         fOrganizeImports.update(selection);
307         fSortMembers.update(selection);
308         fFormatAll.update(selection);
309         if (selection instanceof IStructuredSelection) {
310             IStructuredSelection ss= (IStructuredSelection)selection;
311             fAddBookmark.selectionChanged(ss);
312         } else {
313             fAddBookmark.setEnabled(false);
314         }
315         
316         registerSelectionListener(provider, fOverrideMethods);
317         registerSelectionListener(provider, fAddGetterSetter);
318         registerSelectionListener(provider, fAddDelegateMethods);
319         registerSelectionListener(provider, fAddUnimplementedConstructors);
320         registerSelectionListener(provider, fGenerateConstructorUsingFields);
321         registerSelectionListener(provider, fHashCodeEquals);
322         registerSelectionListener(provider, fAddJavaDocStub);
323         registerSelectionListener(provider, fAddBookmark);
324         registerSelectionListener(provider, fExternalizeStrings);
325         registerSelectionListener(provider, fFindNLSProblems);
326         registerSelectionListener(provider, fOrganizeImports);
327         registerSelectionListener(provider, fFormatAll);
328         registerSelectionListener(provider, fSortMembers);
329         registerSelectionListener(provider, fAddTaskAction);
330         registerSelectionListener(provider, fCleanUp);
331         
332         installQuickAccessAction();
333     }
334     
335     private void installQuickAccessAction() {
336         fHandlerService= (IHandlerService)fSite.getService(IHandlerService.class);
337         if (fHandlerService != null) {
338             fQuickAccessAction= new SourceQuickAccessAction(fEditor);
339             fQuickAccessHandlerActivation= fHandlerService.activateHandler(fQuickAccessAction.getActionDefinitionId(), new ActionHandler(fQuickAccessAction));
340         }
341     }
342     
343     private void registerSelectionListener(ISelectionProvider provider, ISelectionChangedListener listener) {
344         if (fRegisteredSelectionListeners == null)
345             fRegisteredSelectionListeners= new ArrayList JavaDoc(20);
346         provider.addSelectionChangedListener(listener);
347         fRegisteredSelectionListeners.add(listener);
348     }
349     
350     /*
351      * The state of the editor owning this action group has changed.
352      * This method does nothing if the group's owner isn't an
353      * editor.
354      */

355     /**
356      * Note: This method is for internal use only. Clients should not call this method.
357      */

358     public void editorStateChanged() {
359         Assert.isTrue(isEditorOwner());
360     }
361
362     /* (non-Javadoc)
363      * Method declared in ActionGroup
364      */

365     public void fillActionBars(IActionBars actionBar) {
366         super.fillActionBars(actionBar);
367         setGlobalActionHandlers(actionBar);
368     }
369     
370     /* (non-Javadoc)
371      * Method declared in ActionGroup
372      */

373     public void fillContextMenu(IMenuManager menu) {
374         super.fillContextMenu(menu);
375         String JavaDoc menuText= ActionMessages.SourceMenu_label;
376         if (fQuickAccessAction != null) {
377             menuText= fQuickAccessAction.addShortcut(menuText);
378         }
379         IMenuManager subMenu= new MenuManager(menuText, MENU_ID);
380         int added= 0;
381         if (isEditorOwner()) {
382             added= fillEditorSubMenu(subMenu);
383         } else {
384             added= fillViewSubMenu(subMenu);
385         }
386         if (added > 0)
387             menu.appendToGroup(fGroupName, subMenu);
388     }
389
390     private void fillQuickMenu(IMenuManager menu) {
391         if (isEditorOwner()) {
392             fillEditorSubMenu(menu);
393         } else {
394             fillViewSubMenu(menu);
395         }
396     }
397     
398     private int fillEditorSubMenu(IMenuManager source) {
399         int added= 0;
400         source.add(new Separator(GROUP_COMMENT));
401         added+= addEditorAction(source, "ToggleComment"); //$NON-NLS-1$
402
added+= addEditorAction(source, "AddBlockComment"); //$NON-NLS-1$
403
added+= addEditorAction(source, "RemoveBlockComment"); //$NON-NLS-1$
404
added+= addAction(source, fAddJavaDocStub);
405         source.add(new Separator(GROUP_EDIT));
406         added+= addEditorAction(source, "Indent"); //$NON-NLS-1$
407
added+= addEditorAction(source, "Format"); //$NON-NLS-1$
408
source.add(new Separator(GROUP_IMPORT));
409         added+= addAction(source, fAddImport);
410         added+= addAction(source, fOrganizeImports);
411         added+= addAction(source, fSortMembers);
412         added+= addAction(source, fCleanUp);
413         source.add(new Separator(GROUP_GENERATE));
414         added+= addAction(source, fOverrideMethods);
415         added+= addAction(source, fAddGetterSetter);
416         added+= addAction(source, fAddDelegateMethods);
417         added+= addAction(source, fHashCodeEquals);
418         added+= addAction(source, fGenerateConstructorUsingFields);
419         added+= addAction(source, fAddUnimplementedConstructors);
420         source.add(new Separator(GROUP_CODE));
421         source.add(new Separator(GROUP_EXTERNALIZE));
422         added+= addAction(source, fExternalizeStrings);
423         return added;
424     }
425
426     private int fillViewSubMenu(IMenuManager source) {
427         int added= 0;
428         source.add(new Separator(GROUP_COMMENT));
429         added+= addAction(source, fAddJavaDocStub);
430         source.add(new Separator(GROUP_EDIT));
431         added+= addAction(source, fFormatAll);
432         source.add(new Separator(GROUP_IMPORT));
433         added+= addAction(source, fAddImport);
434         added+= addAction(source, fOrganizeImports);
435         added+= addAction(source, fSortMembers);
436         added+= addAction(source, fCleanUp);
437         source.add(new Separator(GROUP_GENERATE));
438         added+= addAction(source, fOverrideMethods);
439         added+= addAction(source, fAddGetterSetter);
440         added+= addAction(source, fAddDelegateMethods);
441         added+= addAction(source, fHashCodeEquals);
442         added+= addAction(source, fGenerateConstructorUsingFields);
443         added+= addAction(source, fAddUnimplementedConstructors);
444         source.add(new Separator(GROUP_CODE));
445         source.add(new Separator(GROUP_EXTERNALIZE));
446         added+= addAction(source, fExternalizeStrings);
447         added+= addAction(source, fFindNLSProblems);
448         return added;
449     }
450
451     /* (non-Javadoc)
452      * Method declared in ActionGroup
453      */

454     public void dispose() {
455         if (fRegisteredSelectionListeners != null) {
456             ISelectionProvider provider= fSite.getSelectionProvider();
457             for (Iterator JavaDoc iter= fRegisteredSelectionListeners.iterator(); iter.hasNext();) {
458                 ISelectionChangedListener listener= (ISelectionChangedListener) iter.next();
459                 provider.removeSelectionChangedListener(listener);
460             }
461         }
462         if (fQuickAccessHandlerActivation != null && fHandlerService != null) {
463             fHandlerService.deactivateHandler(fQuickAccessHandlerActivation);
464         }
465         fEditor= null;
466         fCleanUp.dispose();
467         super.dispose();
468     }
469     
470     private void setGlobalActionHandlers(IActionBars actionBar) {
471         actionBar.setGlobalActionHandler(JdtActionConstants.ADD_IMPORT, fAddImport);
472         actionBar.setGlobalActionHandler(JdtActionConstants.OVERRIDE_METHODS, fOverrideMethods);
473         actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_GETTER_SETTER, fAddGetterSetter);
474         actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_DELEGATE_METHODS, fAddDelegateMethods);
475         actionBar.setGlobalActionHandler(JdtActionConstants.ADD_CONSTRUCTOR_FROM_SUPERCLASS, fAddUnimplementedConstructors);
476         actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_CONSTRUCTOR_USING_FIELDS, fGenerateConstructorUsingFields);
477         actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_HASHCODE_EQUALS, fHashCodeEquals);
478         actionBar.setGlobalActionHandler(JdtActionConstants.ADD_JAVA_DOC_COMMENT, fAddJavaDocStub);
479         actionBar.setGlobalActionHandler(JdtActionConstants.EXTERNALIZE_STRINGS, fExternalizeStrings);
480         actionBar.setGlobalActionHandler(JdtActionConstants.CLEAN_UP, fCleanUp);
481         actionBar.setGlobalActionHandler(FindBrokenNLSKeysAction.ACTION_HANDLER_ID, fFindNLSProblems);
482         actionBar.setGlobalActionHandler(JdtActionConstants.ORGANIZE_IMPORTS, fOrganizeImports);
483         actionBar.setGlobalActionHandler(JdtActionConstants.SORT_MEMBERS, fSortMembers);
484         if (!isEditorOwner()) {
485             // editor provides its own implementation of these actions.
486
actionBar.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), fAddBookmark);
487             actionBar.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), fAddTaskAction);
488             actionBar.setGlobalActionHandler(JdtActionConstants.FORMAT, fFormatAll);
489         }
490     }
491     
492     private int addAction(IMenuManager menu, IAction action) {
493         if (action != null && action.isEnabled()) {
494             menu.add(action);
495             return 1;
496         }
497         return 0;
498     }
499     
500     private int addEditorAction(IMenuManager menu, String JavaDoc actionID) {
501         if (fEditor == null)
502             return 0;
503         IAction action= fEditor.getAction(actionID);
504         if (action == null)
505             return 0;
506         if (action instanceof IUpdate)
507             ((IUpdate)action).update();
508         if (action.isEnabled()) {
509             menu.add(action);
510             return 1;
511         }
512         return 0;
513     }
514     
515     private boolean isEditorOwner() {
516         return fEditor != null;
517     }
518 }
519
Popular Tags