KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > search > JavaSearchResultPage


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.internal.ui.search;
12
13 import java.util.HashMap JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IAdaptable;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IMarker;
20
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.dnd.DND;
23 import org.eclipse.swt.dnd.Transfer;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Item;
26 import org.eclipse.swt.widgets.Table;
27 import org.eclipse.swt.widgets.Tree;
28
29 import org.eclipse.jface.action.Action;
30 import org.eclipse.jface.action.IMenuManager;
31 import org.eclipse.jface.action.IToolBarManager;
32 import org.eclipse.jface.action.MenuManager;
33 import org.eclipse.jface.action.Separator;
34 import org.eclipse.jface.util.TransferDragSourceListener;
35 import org.eclipse.jface.viewers.ILabelProvider;
36 import org.eclipse.jface.viewers.IStructuredSelection;
37 import org.eclipse.jface.viewers.ITreeContentProvider;
38 import org.eclipse.jface.viewers.OpenEvent;
39 import org.eclipse.jface.viewers.StructuredViewer;
40 import org.eclipse.jface.viewers.TableViewer;
41 import org.eclipse.jface.viewers.TreeViewer;
42 import org.eclipse.jface.viewers.Viewer;
43 import org.eclipse.jface.viewers.ViewerComparator;
44
45 import org.eclipse.ui.IActionBars;
46 import org.eclipse.ui.IEditorPart;
47 import org.eclipse.ui.IMemento;
48 import org.eclipse.ui.IPageLayout;
49 import org.eclipse.ui.PartInitException;
50 import org.eclipse.ui.actions.ActionContext;
51 import org.eclipse.ui.dialogs.PreferencesUtil;
52 import org.eclipse.ui.part.IPageSite;
53 import org.eclipse.ui.part.IShowInTargetList;
54 import org.eclipse.ui.part.ResourceTransfer;
55 import org.eclipse.ui.texteditor.ITextEditor;
56
57 import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
58
59 import org.eclipse.ui.ide.IDE;
60
61 import org.eclipse.search.ui.IContextMenuConstants;
62 import org.eclipse.search.ui.ISearchResultViewPart;
63 import org.eclipse.search.ui.NewSearchUI;
64 import org.eclipse.search.ui.text.AbstractTextSearchResult;
65 import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
66 import org.eclipse.search.ui.text.Match;
67
68 import org.eclipse.jdt.core.IClassFile;
69 import org.eclipse.jdt.core.ICompilationUnit;
70 import org.eclipse.jdt.core.IMember;
71 import org.eclipse.jdt.core.JavaModelException;
72
73 import org.eclipse.jdt.internal.corext.util.Messages;
74
75 import org.eclipse.jdt.ui.JavaUI;
76 import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
77 import org.eclipse.jdt.ui.search.IMatchPresentation;
78
79 import org.eclipse.jdt.internal.ui.JavaPlugin;
80 import org.eclipse.jdt.internal.ui.JavaPluginImages;
81 import org.eclipse.jdt.internal.ui.actions.CopyQualifiedNameAction;
82 import org.eclipse.jdt.internal.ui.dnd.JdtViewerDragAdapter;
83 import org.eclipse.jdt.internal.ui.dnd.ResourceTransferDragAdapter;
84 import org.eclipse.jdt.internal.ui.packageview.SelectionTransferDragAdapter;
85 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
86 import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager;
87 import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
88 import org.eclipse.jdt.internal.ui.viewsupport.ProblemTableViewer;
89 import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer;
90
91 public class JavaSearchResultPage extends AbstractTextSearchViewPage implements IAdaptable {
92     
93     public static class DecoratorIgnoringViewerSorter extends ViewerComparator {
94
95         private final ILabelProvider fLabelProvider;
96
97         public DecoratorIgnoringViewerSorter(ILabelProvider labelProvider) {
98             fLabelProvider= labelProvider;
99         }
100         
101         public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
102             String JavaDoc name1= fLabelProvider.getText(e1);
103             String JavaDoc name2= fLabelProvider.getText(e2);
104             if (name1 == null)
105                 name1 = "";//$NON-NLS-1$
106
if (name2 == null)
107                 name2 = "";//$NON-NLS-1$
108
return getComparator().compare(name1, name2);
109         }
110     }
111
112         
113     private static final int DEFAULT_ELEMENT_LIMIT = 1000;
114     private static final String JavaDoc FALSE = "FALSE"; //$NON-NLS-1$
115
private static final String JavaDoc TRUE = "TRUE"; //$NON-NLS-1$
116
private static final String JavaDoc KEY_GROUPING= "org.eclipse.jdt.search.resultpage.grouping"; //$NON-NLS-1$
117
private static final String JavaDoc KEY_SORTING= "org.eclipse.jdt.search.resultpage.sorting"; //$NON-NLS-1$
118
private static final String JavaDoc KEY_LIMIT_ENABLED= "org.eclipse.jdt.search.resultpage.limit_enabled"; //$NON-NLS-1$
119
private static final String JavaDoc KEY_LIMIT= "org.eclipse.jdt.search.resultpage.limit"; //$NON-NLS-1$
120

121     private static final String JavaDoc GROUP_GROUPING= "org.eclipse.jdt.search.resultpage.grouping"; //$NON-NLS-1$
122
private static final String JavaDoc GROUP_FILTERING = "org.eclipse.jdt.search.resultpage.filtering"; //$NON-NLS-1$
123

124     private NewSearchViewActionGroup fActionGroup;
125     private JavaSearchContentProvider fContentProvider;
126     private int fCurrentSortOrder;
127     private SortAction fSortByNameAction;
128     private SortAction fSortByParentName;
129     private SortAction fSortByPathAction;
130     
131     private GroupAction fGroupTypeAction;
132     private GroupAction fGroupFileAction;
133     private GroupAction fGroupPackageAction;
134     private GroupAction fGroupProjectAction;
135     
136     private SelectionDispatchAction fCopyQualifiedNameAction;
137     
138     private SortingLabelProvider fSortingLabelProvider;
139     
140     private int fCurrentGrouping;
141     
142     private static final String JavaDoc[] SHOW_IN_TARGETS= new String JavaDoc[] { JavaUI.ID_PACKAGES , IPageLayout.ID_RES_NAV };
143     public static final IShowInTargetList SHOW_IN_TARGET_LIST= new IShowInTargetList() {
144         public String JavaDoc[] getShowInTargetIds() {
145             return SHOW_IN_TARGETS;
146         }
147     };
148     
149     private JavaSearchEditorOpener fEditorOpener= new JavaSearchEditorOpener();
150
151     public JavaSearchResultPage() {
152         fCopyQualifiedNameAction= null;
153         
154         initSortActions();
155         initGroupingActions();
156         setElementLimit(new Integer JavaDoc(DEFAULT_ELEMENT_LIMIT));
157     }
158         
159     private void initSortActions() {
160         fSortByNameAction= new SortAction(SearchMessages.JavaSearchResultPage_sortByName, this, SortingLabelProvider.SHOW_ELEMENT_CONTAINER);
161         fSortByPathAction= new SortAction(SearchMessages.JavaSearchResultPage_sortByPath, this, SortingLabelProvider.SHOW_PATH);
162         fSortByParentName= new SortAction(SearchMessages.JavaSearchResultPage_sortByParentName, this, SortingLabelProvider.SHOW_CONTAINER_ELEMENT);
163     }
164
165     private void initGroupingActions() {
166         fGroupProjectAction= new GroupAction(SearchMessages.JavaSearchResultPage_groupby_project, SearchMessages.JavaSearchResultPage_groupby_project_tooltip, this, LevelTreeContentProvider.LEVEL_PROJECT);
167         JavaPluginImages.setLocalImageDescriptors(fGroupProjectAction, "prj_mode.gif"); //$NON-NLS-1$
168
fGroupPackageAction= new GroupAction(SearchMessages.JavaSearchResultPage_groupby_package, SearchMessages.JavaSearchResultPage_groupby_package_tooltip, this, LevelTreeContentProvider.LEVEL_PACKAGE);
169         JavaPluginImages.setLocalImageDescriptors(fGroupPackageAction, "package_mode.gif"); //$NON-NLS-1$
170
fGroupFileAction= new GroupAction(SearchMessages.JavaSearchResultPage_groupby_file, SearchMessages.JavaSearchResultPage_groupby_file_tooltip, this, LevelTreeContentProvider.LEVEL_FILE);
171         JavaPluginImages.setLocalImageDescriptors(fGroupFileAction, "file_mode.gif"); //$NON-NLS-1$
172
fGroupTypeAction= new GroupAction(SearchMessages.JavaSearchResultPage_groupby_type, SearchMessages.JavaSearchResultPage_groupby_type_tooltip, this, LevelTreeContentProvider.LEVEL_TYPE);
173         JavaPluginImages.setLocalImageDescriptors(fGroupTypeAction, "type_mode.gif"); //$NON-NLS-1$
174
}
175
176     public void setViewPart(ISearchResultViewPart part) {
177         super.setViewPart(part);
178         fActionGroup= new NewSearchViewActionGroup(part);
179     }
180     
181     public void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
182         IEditorPart editor;
183         try {
184             editor= fEditorOpener.openMatch(match);
185         } catch (JavaModelException e) {
186             throw new PartInitException(e.getStatus());
187         }
188         
189         if (editor != null && activate)
190             editor.getEditorSite().getPage().activate(editor);
191         Object JavaDoc element= match.getElement();
192         if (editor instanceof ITextEditor) {
193             ITextEditor textEditor= (ITextEditor) editor;
194             textEditor.selectAndReveal(offset, length);
195         } else if (editor != null){
196             if (element instanceof IFile) {
197                 IFile file= (IFile) element;
198                 showWithMarker(editor, file, offset, length);
199             }
200         } else {
201             JavaSearchResult result= (JavaSearchResult) getInput();
202             IMatchPresentation participant= result.getSearchParticpant(element);
203             if (participant != null)
204                 participant.showMatch(match, offset, length, activate);
205         }
206     }
207     
208     private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException {
209         try {
210             IMarker marker= file.createMarker(NewSearchUI.SEARCH_MARKER);
211             HashMap JavaDoc attributes= new HashMap JavaDoc(4);
212             attributes.put(IMarker.CHAR_START, new Integer JavaDoc(offset));
213             attributes.put(IMarker.CHAR_END, new Integer JavaDoc(offset + length));
214             marker.setAttributes(attributes);
215             IDE.gotoMarker(editor, marker);
216             marker.delete();
217         } catch (CoreException e) {
218             throw new PartInitException(SearchMessages.JavaSearchResultPage_error_marker, e);
219         }
220     }
221     
222     private SelectionDispatchAction getCopyQualifiedNameAction() {
223         if (fCopyQualifiedNameAction == null) {
224             fCopyQualifiedNameAction= new CopyQualifiedNameAction(getSite());
225         }
226         return fCopyQualifiedNameAction;
227     }
228
229     protected void fillContextMenu(IMenuManager mgr) {
230         super.fillContextMenu(mgr);
231         addSortActions(mgr);
232
233         mgr.appendToGroup(IContextMenuConstants.GROUP_EDIT, getCopyQualifiedNameAction());
234
235         fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
236         fActionGroup.fillContextMenu(mgr);
237     }
238     
239     private void addSortActions(IMenuManager mgr) {
240         if (getLayout() != FLAG_LAYOUT_FLAT)
241             return;
242         MenuManager sortMenu= new MenuManager(SearchMessages.JavaSearchResultPage_sortBylabel);
243         sortMenu.add(fSortByNameAction);
244         sortMenu.add(fSortByPathAction);
245         sortMenu.add(fSortByParentName);
246         
247         fSortByNameAction.setChecked(fCurrentSortOrder == fSortByNameAction.getSortOrder());
248         fSortByPathAction.setChecked(fCurrentSortOrder == fSortByPathAction.getSortOrder());
249         fSortByParentName.setChecked(fCurrentSortOrder == fSortByParentName.getSortOrder());
250         
251         mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenu);
252     }
253     
254     protected void fillToolbar(IToolBarManager tbm) {
255         super.fillToolbar(tbm);
256         
257         IActionBars actionBars = getSite().getActionBars();
258         if (actionBars != null) {
259             actionBars.setGlobalActionHandler(CopyQualifiedNameAction.ACTION_HANDLER_ID, getCopyQualifiedNameAction());
260         }
261         
262         if (getLayout() != FLAG_LAYOUT_FLAT)
263             addGroupActions(tbm);
264     }
265         
266     private void addGroupActions(IToolBarManager mgr) {
267         mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, new Separator(GROUP_GROUPING));
268         mgr.appendToGroup(GROUP_GROUPING, fGroupProjectAction);
269         mgr.appendToGroup(GROUP_GROUPING, fGroupPackageAction);
270         mgr.appendToGroup(GROUP_GROUPING, fGroupFileAction);
271         mgr.appendToGroup(GROUP_GROUPING, fGroupTypeAction);
272         
273         updateGroupingActions();
274     }
275
276
277     private void updateGroupingActions() {
278         fGroupProjectAction.setChecked(fCurrentGrouping == LevelTreeContentProvider.LEVEL_PROJECT);
279         fGroupPackageAction.setChecked(fCurrentGrouping == LevelTreeContentProvider.LEVEL_PACKAGE);
280         fGroupFileAction.setChecked(fCurrentGrouping == LevelTreeContentProvider.LEVEL_FILE);
281         fGroupTypeAction.setChecked(fCurrentGrouping == LevelTreeContentProvider.LEVEL_TYPE);
282     }
283
284
285     public void dispose() {
286         fActionGroup.dispose();
287         super.dispose();
288     }
289     
290     protected void elementsChanged(Object JavaDoc[] objects) {
291         if (fContentProvider != null)
292             fContentProvider.elementsChanged(objects);
293     }
294
295     protected void clear() {
296         if (fContentProvider != null)
297             fContentProvider.clear();
298     }
299     
300     private void addDragAdapters(StructuredViewer viewer) {
301         Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance() };
302         int ops= DND.DROP_COPY | DND.DROP_LINK;
303         
304         TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] {
305             new SelectionTransferDragAdapter(viewer),
306             new ResourceTransferDragAdapter(viewer)
307         };
308         
309         viewer.addDragSupport(ops, transfers, new JdtViewerDragAdapter(viewer, dragListeners));
310     }
311
312     protected void configureTableViewer(TableViewer viewer) {
313         viewer.setUseHashlookup(true);
314         fSortingLabelProvider= new SortingLabelProvider(this);
315         viewer.setLabelProvider(new DecoratingJavaLabelProvider(fSortingLabelProvider, false));
316         fContentProvider=new JavaSearchTableContentProvider(this);
317         viewer.setContentProvider(fContentProvider);
318         viewer.setComparator(new DecoratorIgnoringViewerSorter(fSortingLabelProvider));
319         setSortOrder(fCurrentSortOrder);
320         addDragAdapters(viewer);
321     }
322
323     protected void configureTreeViewer(TreeViewer viewer) {
324         PostfixLabelProvider postfixLabelProvider= new PostfixLabelProvider(this);
325         viewer.setUseHashlookup(true);
326         viewer.setComparator(new DecoratorIgnoringViewerSorter(postfixLabelProvider));
327         viewer.setLabelProvider(new DecoratingJavaLabelProvider(postfixLabelProvider, false));
328         fContentProvider= new LevelTreeContentProvider(this, fCurrentGrouping);
329         viewer.setContentProvider(fContentProvider);
330         addDragAdapters(viewer);
331     }
332     
333     protected TreeViewer createTreeViewer(Composite parent) {
334         ProblemTreeViewer problemTreeViewer= new ProblemTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
335         ColoredViewersManager.install(problemTreeViewer);
336         return problemTreeViewer;
337     }
338     
339     protected TableViewer createTableViewer(Composite parent) {
340         ProblemTableViewer problemTableViewer= new ProblemTableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
341         ColoredViewersManager.install(problemTableViewer);
342         return problemTableViewer;
343     }
344     
345     void setSortOrder(int order) {
346         if (fSortingLabelProvider != null) {
347             fCurrentSortOrder= order;
348             StructuredViewer viewer= getViewer();
349             //viewer.getControl().setRedraw(false);
350
fSortingLabelProvider.setOrder(order);
351             //viewer.getControl().setRedraw(true);
352
viewer.refresh();
353             getSettings().put(KEY_SORTING, fCurrentSortOrder);
354         }
355     }
356
357     public void init(IPageSite site) {
358         super.init(site);
359         IMenuManager menuManager = site.getActionBars().getMenuManager();
360         menuManager.insertBefore(IContextMenuConstants.GROUP_PROPERTIES, new Separator(GROUP_FILTERING));
361         fActionGroup.fillActionBars(site.getActionBars());
362         menuManager.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, new Action(SearchMessages.JavaSearchResultPage_preferences_label) {
363             public void run() {
364                 String JavaDoc pageId= "org.eclipse.search.preferences.SearchPreferencePage"; //$NON-NLS-1$
365
PreferencesUtil.createPreferenceDialogOn(JavaPlugin.getActiveWorkbenchShell(), pageId, null, null).open();
366             }
367         });
368     }
369
370     /**
371      * Precondition here: the viewer must be showing a tree with a LevelContentProvider.
372      * @param grouping
373      */

374     void setGrouping(int grouping) {
375         fCurrentGrouping= grouping;
376         StructuredViewer viewer= getViewer();
377         LevelTreeContentProvider cp= (LevelTreeContentProvider) viewer.getContentProvider();
378         cp.setLevel(grouping);
379         updateGroupingActions();
380         getSettings().put(KEY_GROUPING, fCurrentGrouping);
381         getViewPart().updateLabel();
382     }
383     
384     protected StructuredViewer getViewer() {
385         // override so that it's visible in the package.
386
return super.getViewer();
387     }
388     
389     /* (non-Javadoc)
390      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#restoreState(org.eclipse.ui.IMemento)
391      */

392     public void restoreState(IMemento memento) {
393         super.restoreState(memento);
394         
395         int sortOrder= SortingLabelProvider.SHOW_ELEMENT_CONTAINER;
396         int grouping= LevelTreeContentProvider.LEVEL_PACKAGE;
397         int elementLimit= DEFAULT_ELEMENT_LIMIT;
398         
399         try {
400             sortOrder= getSettings().getInt(KEY_SORTING);
401         } catch (NumberFormatException JavaDoc e) {
402         }
403         try {
404             grouping= getSettings().getInt(KEY_GROUPING);
405         } catch (NumberFormatException JavaDoc e) {
406         }
407         if (FALSE.equals(getSettings().get(KEY_LIMIT_ENABLED))) {
408             elementLimit= -1;
409         } else {
410             try {
411                 elementLimit= getSettings().getInt(KEY_LIMIT);
412             } catch (NumberFormatException JavaDoc e) {
413             }
414         }
415         if (memento != null) {
416             Integer JavaDoc value= memento.getInteger(KEY_GROUPING);
417             if (value != null)
418                 grouping= value.intValue();
419             value= memento.getInteger(KEY_SORTING);
420             if (value != null)
421                 sortOrder= value.intValue();
422             boolean limitElements= !FALSE.equals(memento.getString(KEY_LIMIT_ENABLED));
423             value= memento.getInteger(KEY_LIMIT);
424             if (value != null)
425                 elementLimit= limitElements ? value.intValue() : -1;
426         }
427         
428         fCurrentGrouping= grouping;
429         fCurrentSortOrder= sortOrder;
430         setElementLimit(new Integer JavaDoc(elementLimit));
431     }
432
433     /* (non-Javadoc)
434      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#saveState(org.eclipse.ui.IMemento)
435      */

436     public void saveState(IMemento memento) {
437         super.saveState(memento);
438         memento.putInteger(KEY_GROUPING, fCurrentGrouping);
439         memento.putInteger(KEY_SORTING, fCurrentSortOrder);
440         int limit= getElementLimit().intValue();
441         if (limit != -1)
442             memento.putString(KEY_LIMIT_ENABLED, TRUE);
443         else
444             memento.putString(KEY_LIMIT_ENABLED, FALSE);
445         memento.putInteger(KEY_LIMIT, limit);
446     }
447         
448     private boolean isQueryRunning() {
449         AbstractTextSearchResult result= getInput();
450         if (result != null) {
451             return NewSearchUI.isQueryRunning(result.getQuery());
452         }
453         return false;
454     }
455
456     public String JavaDoc getLabel() {
457         String JavaDoc label= super.getLabel();
458         AbstractTextSearchResult input= getInput();
459         if (input != null && input.getActiveMatchFilters() != null && input.getActiveMatchFilters().length > 0) {
460             if (isQueryRunning()) {
461                 String JavaDoc message= SearchMessages.JavaSearchResultPage_filtered_message;
462                 return Messages.format(message, new Object JavaDoc[] { label });
463             
464             } else {
465                 int filteredOut= input.getMatchCount() - getFilteredMatchCount();
466                 String JavaDoc message= SearchMessages.JavaSearchResultPage_filteredWithCount_message;
467                 return Messages.format(message, new Object JavaDoc[] { label, String.valueOf(filteredOut) });
468             }
469         }
470         return label;
471     }
472
473     private int getFilteredMatchCount() {
474         StructuredViewer viewer= getViewer();
475         if (viewer instanceof TreeViewer) {
476             ITreeContentProvider tp= (ITreeContentProvider) viewer.getContentProvider();
477             return getMatchCount(tp, getRootElements((TreeViewer) getViewer()));
478         } else {
479             return getMatchCount((TableViewer) viewer);
480         }
481     }
482     
483     private Object JavaDoc[] getRootElements(TreeViewer viewer) {
484         Tree t= viewer.getTree();
485         Item[] roots= t.getItems();
486         Object JavaDoc[] elements= new Object JavaDoc[roots.length];
487         for (int i = 0; i < elements.length; i++) {
488             elements[i]= roots[i].getData();
489         }
490         return elements;
491     }
492     
493     private Object JavaDoc[] getRootElements(TableViewer viewer) {
494         Table t= viewer.getTable();
495         Item[] roots= t.getItems();
496         Object JavaDoc[] elements= new Object JavaDoc[roots.length];
497         for (int i = 0; i < elements.length; i++) {
498             elements[i]= roots[i].getData();
499         }
500         return elements;
501     }
502
503
504     private int getMatchCount(ITreeContentProvider cp, Object JavaDoc[] elements) {
505         int count= 0;
506         for (int j = 0; j < elements.length; j++) {
507             count+= getDisplayedMatchCount(elements[j]);
508             Object JavaDoc[] children = cp.getChildren(elements[j]);
509             count+= getMatchCount(cp, children);
510         }
511         return count;
512     }
513     
514     private int getMatchCount(TableViewer viewer) {
515         Object JavaDoc[] elements= getRootElements(viewer);
516         int count= 0;
517         for (int i = 0; i < elements.length; i++) {
518             count+= getDisplayedMatchCount(elements[i]);
519         }
520         return count;
521     }
522
523
524     /* (non-Javadoc)
525      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
526      */

527     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
528         if (IShowInTargetList.class.equals(adapter)) {
529             return SHOW_IN_TARGET_LIST;
530         }
531         return null;
532     }
533     
534     protected void handleOpen(OpenEvent event) {
535         Object JavaDoc firstElement= ((IStructuredSelection)event.getSelection()).getFirstElement();
536         if (firstElement instanceof ICompilationUnit ||
537                 firstElement instanceof IClassFile ||
538                 firstElement instanceof IMember) {
539             if (getDisplayedMatchCount(firstElement) == 0) {
540                 try {
541                     fEditorOpener.openElement(firstElement);
542                 } catch (CoreException e) {
543                     ExceptionHandler.handle(e, getSite().getShell(), SearchMessages.JavaSearchResultPage_open_editor_error_title, SearchMessages.JavaSearchResultPage_open_editor_error_message);
544                 }
545                 return;
546             }
547         }
548         super.handleOpen(event);
549     }
550
551     public void setElementLimit(Integer JavaDoc elementLimit) {
552         super.setElementLimit(elementLimit);
553         int limit= elementLimit.intValue();
554         getSettings().put(KEY_LIMIT, limit);
555         getSettings().put(KEY_LIMIT_ENABLED, limit != -1 ? TRUE : FALSE);
556     }
557 }
558
Popular Tags