KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search2 > internal > ui > SearchView


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  * Michael Fraenkel (fraenkel@us.ibm.com) - contributed a fix for:
11  * o New search view sets incorrect title
12  * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=60966)
13  *******************************************************************************/

14 package org.eclipse.search2.internal.ui;
15
16 import com.ibm.icu.text.MessageFormat;
17 import java.util.HashMap JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23
24 import org.eclipse.osgi.util.NLS;
25
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.graphics.Image;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Tree;
31
32 import org.eclipse.jface.action.GroupMarker;
33 import org.eclipse.jface.action.IMenuManager;
34 import org.eclipse.jface.action.IToolBarManager;
35 import org.eclipse.jface.action.MenuManager;
36 import org.eclipse.jface.action.Separator;
37 import org.eclipse.jface.viewers.ISelection;
38
39 import org.eclipse.ui.IMemento;
40 import org.eclipse.ui.IPropertyListener;
41 import org.eclipse.ui.IViewSite;
42 import org.eclipse.ui.IWorkbenchActionConstants;
43 import org.eclipse.ui.IWorkbenchPart;
44 import org.eclipse.ui.IWorkbenchPartSite;
45 import org.eclipse.ui.PartInitException;
46 import org.eclipse.ui.PlatformUI;
47 import org.eclipse.ui.actions.ActionFactory;
48 import org.eclipse.ui.actions.ContributionItemFactory;
49 import org.eclipse.ui.keys.IBindingService;
50 import org.eclipse.ui.part.IPage;
51 import org.eclipse.ui.part.IPageBookViewPage;
52 import org.eclipse.ui.part.IPageSite;
53 import org.eclipse.ui.part.IShowInSource;
54 import org.eclipse.ui.part.Page;
55 import org.eclipse.ui.part.PageBook;
56 import org.eclipse.ui.part.PageBookView;
57 import org.eclipse.ui.part.ShowInContext;
58 import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
59
60 import org.eclipse.search.ui.IContextMenuConstants;
61 import org.eclipse.search.ui.IQueryListener;
62 import org.eclipse.search.ui.ISearchQuery;
63 import org.eclipse.search.ui.ISearchResult;
64 import org.eclipse.search.ui.ISearchResultPage;
65 import org.eclipse.search.ui.ISearchResultViewPart;
66
67 import org.eclipse.search.internal.ui.ISearchHelpContextIds;
68 import org.eclipse.search.internal.ui.SearchPlugin;
69
70 public class SearchView extends PageBookView implements ISearchResultViewPart, IQueryListener {
71     
72     private static final String JavaDoc MEMENTO_TYPE= "view"; //$NON-NLS-1$
73
private static final String JavaDoc MEMENTO_KEY_IS_PINNED= "isPinned"; //$NON-NLS-1$
74
private static final String JavaDoc MEMENTO_KEY_LAST_ACTIVATION= "org.eclipse.search.lastActivation"; //$NON-NLS-1$
75
private static final String JavaDoc MEMENTO_KEY_RESTORE= "org.eclipse.search.restore"; //$NON-NLS-1$
76
private HashMap JavaDoc fPartsToPages;
77     private HashMap JavaDoc fPagesToParts;
78     private HashMap JavaDoc fSearchViewStates;
79     private SearchPageRegistry fSearchViewPageService;
80     private SearchHistoryDropDownAction fSearchesDropDownAction;
81     private ISearchResult fCurrentSearch;
82     private DummyPart fDefaultPart;
83     private SearchAgainAction fSearchAgainAction;
84     private CancelSearchAction fCancelAction;
85     private PinSearchViewAction fPinSearchViewAction;
86     
87     private IMemento fPageState;
88     private boolean fIsPinned;
89     private int fActivationCount= 0;
90     private String JavaDoc fDefaultPartName;
91     
92     /**
93      * Creates the groups and separators for the search view's context menu
94      *
95      * @param menu the context menu
96      */

97     public static void createContextMenuGroups(IMenuManager menu) {
98         menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
99         menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
100         menu.add(new GroupMarker(IContextMenuConstants.GROUP_OPEN));
101         menu.add(new Separator(IContextMenuConstants.GROUP_SHOW));
102         menu.add(new Separator(IContextMenuConstants.GROUP_EDIT));
103         menu.add(new GroupMarker(IContextMenuConstants.GROUP_REMOVE_MATCHES));
104         menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
105         menu.add(new GroupMarker(IContextMenuConstants.GROUP_GENERATE));
106         menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
107         menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
108         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
109         menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
110         menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
111     }
112     
113     /**
114      * Creates the groups and separators for the search view's context menu
115      *
116      * @param menu the context menu
117      */

118     private static void createViewMenuGroups(IMenuManager menu) {
119         menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
120         menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
121         menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
122         menu.add(new GroupMarker(IContextMenuConstants.GROUP_OPEN));
123         menu.add(new Separator(IContextMenuConstants.GROUP_SHOW));
124         menu.add(new Separator(IContextMenuConstants.GROUP_EDIT));
125         menu.add(new GroupMarker(IContextMenuConstants.GROUP_REMOVE_MATCHES));
126         menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
127         menu.add(new GroupMarker(IContextMenuConstants.GROUP_GENERATE));
128         menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
129         menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
130         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
131         menu.add(new Separator(IContextMenuConstants.GROUP_FILTERING));
132         menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
133     }
134
135     /**
136      * Creates the groups and separators for the search view's
137      * tool bar
138      *
139      * @param toolbar the toolbar
140      */

141     public static void createToolBarGroups(IToolBarManager toolbar) {
142         toolbar.add(new Separator(IContextMenuConstants.GROUP_NEW));
143         toolbar.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
144         toolbar.add(new GroupMarker(IContextMenuConstants.GROUP_OPEN));
145         toolbar.add(new Separator(IContextMenuConstants.GROUP_SHOW));
146         toolbar.add(new Separator(IContextMenuConstants.GROUP_BUILD));
147         toolbar.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
148         toolbar.add(new Separator(IContextMenuConstants.GROUP_EDIT));
149         toolbar.add(new GroupMarker(IContextMenuConstants.GROUP_REMOVE_MATCHES));
150         toolbar.add(new GroupMarker(IContextMenuConstants.GROUP_GENERATE));
151         toolbar.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
152         toolbar.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
153         toolbar.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
154         toolbar.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
155     }
156
157     static class DummyPart implements IWorkbenchPart {
158         private int fLastActivation= 0;
159         public void setLastActivation(int lastActivation) {
160             fLastActivation= lastActivation;
161         }
162         public int getLastActivation() {
163             return fLastActivation;
164         }
165         public void addPropertyListener(IPropertyListener listener) {/*dummy*/}
166         public void createPartControl(Composite parent) {/*dummy*/}
167         public void dispose() {/*dummy*/}
168         public IWorkbenchPartSite getSite() { return null; }
169         public String JavaDoc getTitle() { return null; }
170         public Image getTitleImage() { return null; }
171         public String JavaDoc getTitleToolTip() { return null; }
172         public void removePropertyListener(IPropertyListener listener) {/*dummy*/}
173         public void setFocus() {/*dummy*/}
174         public Object JavaDoc getAdapter(Class JavaDoc adapter) { return null; }
175     }
176
177     class EmptySearchView extends Page implements ISearchResultPage {
178         Control fControl;
179         private String JavaDoc fId;
180
181         public void createControl(Composite parent) {
182             fControl= new Tree(parent, SWT.NONE);
183             //fControl.setText(SearchMessages.getString("SearchView.empty.message")); //$NON-NLS-1$
184
}
185
186         public Control getControl() {
187             return fControl;
188         }
189
190         public void setFocus() {
191             if (fControl != null)
192                 fControl.setFocus();
193         }
194
195         /* (non-Javadoc)
196          * @see org.eclipse.search2.ui.ISearchResultsPage#setInput(org.eclipse.search2.ui.ISearchResult, java.lang.Object)
197          */

198         public void setInput(ISearchResult search, Object JavaDoc viewState) {
199             // do nothing
200
}
201
202         /* (non-Javadoc)
203          * @see org.eclipse.search2.ui.ISearchResultsPage#setViewPart(org.eclipse.search2.ui.ISearchResultView)
204          */

205         public void setViewPart(ISearchResultViewPart part) {
206             // do nothing
207
}
208
209         public Object JavaDoc getUIState() {
210             // empty implementation
211
return null;
212         }
213
214     
215         public void init(IPageSite pageSite) {
216             super.init(pageSite);
217             getSite().setSelectionProvider(null);
218             // add something to avoid the empty menu
219
IMenuManager menuManager= pageSite.getActionBars().getMenuManager();
220             menuManager.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, new OpenSearchPreferencesAction());
221         }
222
223         /* (non-Javadoc)
224          * @see org.eclipse.search.ui.ISearchResultPage#saveState(org.eclipse.ui.IMemento)
225          */

226         public void saveState(IMemento memento) {
227             // do nothing
228

229         }
230
231         /* (non-Javadoc)
232          * @see org.eclipse.search.ui.ISearchResultPage#restoreState(org.eclipse.ui.IMemento)
233          */

234         public void restoreState(IMemento memento) {
235             // do nothing
236
}
237
238         /* (non-Javadoc)
239          * @see org.eclipse.search.ui.ISearchResultPage#setID(java.lang.String)
240          */

241         public void setID(String JavaDoc id) {
242             fId= id;
243         }
244
245         /* (non-Javadoc)
246          * @see org.eclipse.search.ui.ISearchResultPage#getID()
247         &nb