KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jface.action.GroupMarker;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.MenuManager;
18 import org.eclipse.jface.action.Separator;
19
20 import org.eclipse.ui.IActionBars;
21 import org.eclipse.ui.IViewPart;
22 import org.eclipse.ui.IWorkbenchSite;
23 import org.eclipse.ui.actions.ActionContext;
24 import org.eclipse.ui.actions.ActionGroup;
25 import org.eclipse.ui.part.Page;
26 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
27
28 import org.eclipse.jdt.ui.PreferenceConstants;
29
30 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
31 import org.eclipse.jdt.internal.ui.search.SearchMessages;
32
33 /**
34  * Action group that adds the Java search actions to a context menu and
35  * the global menu bar.
36  *
37  * <p>
38  * This class may be instantiated; it is not intended to be subclassed.
39  * </p>
40  *
41  * @since 2.0
42  */

43 public class JavaSearchActionGroup extends ActionGroup {
44
45     private JavaEditor fEditor;
46
47     private ReferencesSearchGroup fReferencesGroup;
48     private ReadReferencesSearchGroup fReadAccessGroup;
49     private WriteReferencesSearchGroup fWriteAccessGroup;
50     private DeclarationsSearchGroup fDeclarationsGroup;
51     private ImplementorsSearchGroup fImplementorsGroup;
52     private OccurrencesSearchGroup fOccurrencesGroup;
53     
54     
55     /**
56      * Creates a new <code>JavaSearchActionGroup</code>. The group
57      * requires that the selection provided by the part's selection provider
58      * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
59      *
60      * @param part the view part that owns this action group
61      */

62     public JavaSearchActionGroup(IViewPart part) {
63         this(part.getViewSite());
64     }
65     
66     /**
67      * Creates a new <code>JavaSearchActionGroup</code>. The group
68      * requires that the selection provided by the page's selection provider
69      * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
70      *
71      * @param page the page that owns this action group
72      */

73     public JavaSearchActionGroup(Page page) {
74         this(page.getSite());
75     }
76
77     /**
78      * Note: This constructor is for internal use only. Clients should not call this constructor.
79      * @param editor the Java editor
80      */

81     public JavaSearchActionGroup(JavaEditor editor) {
82         Assert.isNotNull(editor);
83         fEditor= editor;
84         
85         fReferencesGroup= new ReferencesSearchGroup(fEditor);
86         fReadAccessGroup= new ReadReferencesSearchGroup(fEditor);
87         fWriteAccessGroup= new WriteReferencesSearchGroup(fEditor);
88         fDeclarationsGroup= new DeclarationsSearchGroup(fEditor);
89         fImplementorsGroup= new ImplementorsSearchGroup(fEditor);
90         fOccurrencesGroup= new OccurrencesSearchGroup(fEditor);
91     }
92
93     private JavaSearchActionGroup(IWorkbenchSite site) {
94         fReferencesGroup= new ReferencesSearchGroup(site);
95         fReadAccessGroup= new ReadReferencesSearchGroup(site);
96         fWriteAccessGroup= new WriteReferencesSearchGroup(site);
97         fDeclarationsGroup= new DeclarationsSearchGroup(site);
98         fImplementorsGroup= new ImplementorsSearchGroup(site);
99         fOccurrencesGroup= new OccurrencesSearchGroup(site);
100     }
101
102     /*
103      * Method declared on ActionGroup.
104      */

105     public void setContext(ActionContext context) {
106         fReferencesGroup.setContext(context);
107         fDeclarationsGroup.setContext(context);
108         fImplementorsGroup.setContext(context);
109         fReadAccessGroup.setContext(context);
110         fWriteAccessGroup.setContext(context);
111         fOccurrencesGroup.setContext(context);
112     }
113
114     /*
115      * Method declared on ActionGroup.
116      */

117     public void fillActionBars(IActionBars actionBar) {
118         super.fillActionBars(actionBar);
119         fReferencesGroup.fillActionBars(actionBar);
120         fDeclarationsGroup.fillActionBars(actionBar);
121         fImplementorsGroup.fillActionBars(actionBar);
122         fReadAccessGroup.fillActionBars(actionBar);
123         fWriteAccessGroup.fillActionBars(actionBar);
124         fOccurrencesGroup.fillActionBars(actionBar);
125     }
126     
127     /*
128      * Method declared on ActionGroup.
129      */

130     public void fillContextMenu(IMenuManager menu) {
131         super.fillContextMenu(menu);
132         
133         if(PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.SEARCH_USE_REDUCED_MENU)) {
134             fReferencesGroup.fillContextMenu(menu);
135             fDeclarationsGroup.fillContextMenu(menu);
136
137             if (fEditor == null) {
138                 fImplementorsGroup.fillContextMenu(menu);
139                 fReadAccessGroup.fillContextMenu(menu);
140                 fWriteAccessGroup.fillContextMenu(menu);
141             }
142         } else {
143             IMenuManager target= menu;
144             IMenuManager searchSubMenu= null;
145             if (fEditor != null) {
146                 String JavaDoc groupName= SearchMessages.group_search;
147                 searchSubMenu= new MenuManager(groupName, ITextEditorActionConstants.GROUP_FIND);
148                 searchSubMenu.add(new GroupMarker(ITextEditorActionConstants.GROUP_FIND));
149                 target= searchSubMenu;
150             }
151             
152             fReferencesGroup.fillContextMenu(target);
153             fDeclarationsGroup.fillContextMenu(target);
154             fImplementorsGroup.fillContextMenu(target);
155             fReadAccessGroup.fillContextMenu(target);
156             fWriteAccessGroup.fillContextMenu(target);
157             
158             if (searchSubMenu != null) {
159                 fOccurrencesGroup.fillContextMenu(target);
160                 searchSubMenu.add(new Separator());
161             }
162             
163             // no other way to find out if we have added items.
164
if (searchSubMenu != null && searchSubMenu.getItems().length > 2) {
165                 menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, searchSubMenu);
166             }
167         }
168     }
169
170     /*
171      * Method declared on ActionGroup.
172      */

173     public void dispose() {
174         fReferencesGroup.dispose();
175         fDeclarationsGroup.dispose();
176         fImplementorsGroup.dispose();
177         fReadAccessGroup.dispose();
178         fWriteAccessGroup.dispose();
179         fOccurrencesGroup.dispose();
180
181         super.dispose();
182     }
183 }
184
Popular Tags