KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > ui > actions > TextSearchGroup


1 /*******************************************************************************
2  * Copyright (c) 2006 Wind River Systems 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  * Markus Schorn - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.search.ui.actions;
13
14 import org.eclipse.jface.action.GroupMarker;
15 import org.eclipse.jface.action.IMenuManager;
16 import org.eclipse.jface.action.MenuManager;
17 import org.eclipse.jface.action.Separator;
18
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IWorkbenchActionConstants;
21 import org.eclipse.ui.actions.ActionGroup;
22 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
23
24 import org.eclipse.search2.internal.ui.SearchMessages;
25 import org.eclipse.search2.internal.ui.text2.FindInFileActionDelegate;
26 import org.eclipse.search2.internal.ui.text2.FindInProjectActionDelegate;
27 import org.eclipse.search2.internal.ui.text2.FindInRecentScopeActionDelegate;
28 import org.eclipse.search2.internal.ui.text2.FindInWorkingSetActionDelegate;
29 import org.eclipse.search2.internal.ui.text2.FindInWorkspaceActionDelegate;
30
31 /**
32  * Action group that adds a sub-menu with text search actions to a context menu.
33  *
34  * @since 3.2
35  */

36 public class TextSearchGroup extends ActionGroup {
37     
38     private static final String JavaDoc CTX_MENU_ID= "org.eclipse.search.text.ctxmenu"; //$NON-NLS-1$
39

40     private String JavaDoc fAppendToGroup= ITextEditorActionConstants.GROUP_FIND;
41     private String JavaDoc fMenuText= SearchMessages.TextSearchGroup_submenu_text;
42     private FindInRecentScopeActionDelegate[] fActions;
43
44     /**
45      * Constructs a TextSearchGroup for adding actions to the context menu
46      * of the editor provided. The editor will be accessed for the purpose of
47      * determining the search string.
48      */

49     public TextSearchGroup(IEditorPart editor) {
50         createActions(editor);
51     }
52
53     /**
54      * Changes the text that is used for the submenu. The default is
55      * "Search Text".
56      */

57     public void setMenuText(String JavaDoc text) {
58         fMenuText= text;
59     }
60
61     /**
62      * Changes the group where the submenu is appended to. The default is
63      * ITextEditorActionConstants.GROUP_FIND.
64      */

65     public void setAppendToGroup(String JavaDoc groupID) {
66         fAppendToGroup= groupID;
67     }
68
69     private void createActions(IEditorPart editor) {
70         fActions= new FindInRecentScopeActionDelegate[] {
71                 new FindInWorkspaceActionDelegate(), new FindInProjectActionDelegate(), new FindInFileActionDelegate(), new FindInWorkingSetActionDelegate()};
72         for (int i= 0; i < fActions.length; i++) {
73             FindInRecentScopeActionDelegate action= fActions[i];
74             action.setActiveEditor(action, editor);
75         }
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
80      */

81     public void fillContextMenu(IMenuManager menu) {
82         MenuManager textSearchMM= new MenuManager(fMenuText, CTX_MENU_ID);
83         int i=0;
84         for (i= 0; i < fActions.length-1; i++) {
85             textSearchMM.add(fActions[i]);
86         }
87         textSearchMM.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
88         textSearchMM.add(new Separator());
89         textSearchMM.add(fActions[i]);
90
91         menu.appendToGroup(fAppendToGroup, textSearchMM);
92     }
93 }
94
Popular Tags