001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.ui.actions;
011:
012: import org.eclipse.core.runtime.Assert;
013:
014: import org.eclipse.jface.action.GroupMarker;
015: import org.eclipse.jface.action.IMenuManager;
016: import org.eclipse.jface.action.MenuManager;
017: import org.eclipse.jface.action.Separator;
018:
019: import org.eclipse.ui.IActionBars;
020: import org.eclipse.ui.IViewPart;
021: import org.eclipse.ui.IWorkbenchSite;
022: import org.eclipse.ui.actions.ActionContext;
023: import org.eclipse.ui.actions.ActionGroup;
024: import org.eclipse.ui.part.Page;
025: import org.eclipse.ui.texteditor.ITextEditorActionConstants;
026:
027: import org.eclipse.jdt.ui.PreferenceConstants;
028:
029: import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
030: import org.eclipse.jdt.internal.ui.search.SearchMessages;
031:
032: /**
033: * Action group that adds the Java search actions to a context menu and
034: * the global menu bar.
035: *
036: * <p>
037: * This class may be instantiated; it is not intended to be subclassed.
038: * </p>
039: *
040: * @since 2.0
041: */
042: public class JavaSearchActionGroup extends ActionGroup {
043:
044: private JavaEditor fEditor;
045:
046: private ReferencesSearchGroup fReferencesGroup;
047: private ReadReferencesSearchGroup fReadAccessGroup;
048: private WriteReferencesSearchGroup fWriteAccessGroup;
049: private DeclarationsSearchGroup fDeclarationsGroup;
050: private ImplementorsSearchGroup fImplementorsGroup;
051: private OccurrencesSearchGroup fOccurrencesGroup;
052:
053: /**
054: * Creates a new <code>JavaSearchActionGroup</code>. The group
055: * requires that the selection provided by the part's selection provider
056: * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
057: *
058: * @param part the view part that owns this action group
059: */
060: public JavaSearchActionGroup(IViewPart part) {
061: this (part.getViewSite());
062: }
063:
064: /**
065: * Creates a new <code>JavaSearchActionGroup</code>. The group
066: * requires that the selection provided by the page's selection provider
067: * is of type <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
068: *
069: * @param page the page that owns this action group
070: */
071: public JavaSearchActionGroup(Page page) {
072: this (page.getSite());
073: }
074:
075: /**
076: * Note: This constructor is for internal use only. Clients should not call this constructor.
077: * @param editor the Java editor
078: */
079: public JavaSearchActionGroup(JavaEditor editor) {
080: Assert.isNotNull(editor);
081: fEditor = editor;
082:
083: fReferencesGroup = new ReferencesSearchGroup(fEditor);
084: fReadAccessGroup = new ReadReferencesSearchGroup(fEditor);
085: fWriteAccessGroup = new WriteReferencesSearchGroup(fEditor);
086: fDeclarationsGroup = new DeclarationsSearchGroup(fEditor);
087: fImplementorsGroup = new ImplementorsSearchGroup(fEditor);
088: fOccurrencesGroup = new OccurrencesSearchGroup(fEditor);
089: }
090:
091: private JavaSearchActionGroup(IWorkbenchSite site) {
092: fReferencesGroup = new ReferencesSearchGroup(site);
093: fReadAccessGroup = new ReadReferencesSearchGroup(site);
094: fWriteAccessGroup = new WriteReferencesSearchGroup(site);
095: fDeclarationsGroup = new DeclarationsSearchGroup(site);
096: fImplementorsGroup = new ImplementorsSearchGroup(site);
097: fOccurrencesGroup = new OccurrencesSearchGroup(site);
098: }
099:
100: /*
101: * Method declared on ActionGroup.
102: */
103: public void setContext(ActionContext context) {
104: fReferencesGroup.setContext(context);
105: fDeclarationsGroup.setContext(context);
106: fImplementorsGroup.setContext(context);
107: fReadAccessGroup.setContext(context);
108: fWriteAccessGroup.setContext(context);
109: fOccurrencesGroup.setContext(context);
110: }
111:
112: /*
113: * Method declared on ActionGroup.
114: */
115: public void fillActionBars(IActionBars actionBar) {
116: super .fillActionBars(actionBar);
117: fReferencesGroup.fillActionBars(actionBar);
118: fDeclarationsGroup.fillActionBars(actionBar);
119: fImplementorsGroup.fillActionBars(actionBar);
120: fReadAccessGroup.fillActionBars(actionBar);
121: fWriteAccessGroup.fillActionBars(actionBar);
122: fOccurrencesGroup.fillActionBars(actionBar);
123: }
124:
125: /*
126: * Method declared on ActionGroup.
127: */
128: public void fillContextMenu(IMenuManager menu) {
129: super .fillContextMenu(menu);
130:
131: if (PreferenceConstants.getPreferenceStore().getBoolean(
132: PreferenceConstants.SEARCH_USE_REDUCED_MENU)) {
133: fReferencesGroup.fillContextMenu(menu);
134: fDeclarationsGroup.fillContextMenu(menu);
135:
136: if (fEditor == null) {
137: fImplementorsGroup.fillContextMenu(menu);
138: fReadAccessGroup.fillContextMenu(menu);
139: fWriteAccessGroup.fillContextMenu(menu);
140: }
141: } else {
142: IMenuManager target = menu;
143: IMenuManager searchSubMenu = null;
144: if (fEditor != null) {
145: String groupName = SearchMessages.group_search;
146: searchSubMenu = new MenuManager(groupName,
147: ITextEditorActionConstants.GROUP_FIND);
148: searchSubMenu.add(new GroupMarker(
149: ITextEditorActionConstants.GROUP_FIND));
150: target = searchSubMenu;
151: }
152:
153: fReferencesGroup.fillContextMenu(target);
154: fDeclarationsGroup.fillContextMenu(target);
155: fImplementorsGroup.fillContextMenu(target);
156: fReadAccessGroup.fillContextMenu(target);
157: fWriteAccessGroup.fillContextMenu(target);
158:
159: if (searchSubMenu != null) {
160: fOccurrencesGroup.fillContextMenu(target);
161: searchSubMenu.add(new Separator());
162: }
163:
164: // no other way to find out if we have added items.
165: if (searchSubMenu != null
166: && searchSubMenu.getItems().length > 2) {
167: menu.appendToGroup(
168: ITextEditorActionConstants.GROUP_FIND,
169: searchSubMenu);
170: }
171: }
172: }
173:
174: /*
175: * Method declared on ActionGroup.
176: */
177: public void dispose() {
178: fReferencesGroup.dispose();
179: fDeclarationsGroup.dispose();
180: fImplementorsGroup.dispose();
181: fReadAccessGroup.dispose();
182: fWriteAccessGroup.dispose();
183: fOccurrencesGroup.dispose();
184:
185: super.dispose();
186: }
187: }
|