KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > ui > SearchResultViewer


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.search.internal.ui;
15
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collections JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import org.eclipse.core.resources.IMarker;
22 import org.eclipse.core.resources.IResource;
23
24 import org.eclipse.core.runtime.Assert;
25 import org.eclipse.core.runtime.IAdaptable;
26 import org.eclipse.core.runtime.IPath;
27 import org.eclipse.jface.action.IAction;
28 import org.eclipse.jface.action.IMenuListener;
29 import org.eclipse.jface.action.IMenuManager;
30 import org.eclipse.jface.action.IToolBarManager;
31 import org.eclipse.jface.action.MenuManager;
32 import org.eclipse.jface.action.Separator;
33 import org.eclipse.jface.viewers.IBaseLabelProvider;
34 import org.eclipse.jface.viewers.ILabelProvider;
35 import org.eclipse.jface.viewers.IOpenListener;
36 import org.eclipse.jface.viewers.ISelection;
37 import org.eclipse.jface.viewers.ISelectionChangedListener;
38 import org.eclipse.jface.viewers.IStructuredSelection;
39 import org.eclipse.jface.viewers.LabelProviderChangedEvent;
40 import org.eclipse.jface.viewers.OpenEvent;
41 import org.eclipse.jface.viewers.SelectionChangedEvent;
42 import org.eclipse.jface.viewers.StructuredSelection;
43 import org.eclipse.jface.viewers.TableViewer;
44 import org.eclipse.search.internal.ui.util.FileLabelProvider;
45 import org.eclipse.search.ui.IActionGroupFactory;
46 import org.eclipse.search.ui.IContextMenuConstants;
47 import org.eclipse.search.ui.IContextMenuContributor;
48 import org.eclipse.search.ui.ISearchResultViewEntry;
49 import org.eclipse.search.ui.SearchUI;
50 import org.eclipse.swt.SWT;
51 import org.eclipse.swt.events.DisposeEvent;
52 import org.eclipse.swt.events.KeyAdapter;
53 import org.eclipse.swt.events.KeyEvent;
54 import org.eclipse.swt.graphics.Color;
55 import org.eclipse.swt.widgets.Composite;
56 import org.eclipse.swt.widgets.Item;
57 import org.eclipse.swt.widgets.Menu;
58 import org.eclipse.swt.widgets.Table;
59 import org.eclipse.swt.widgets.TableItem;
60 import org.eclipse.swt.widgets.Widget;
61 import org.eclipse.ui.IActionBars;
62 import org.eclipse.ui.IMemento;
63 import org.eclipse.ui.actions.ActionContext;
64 import org.eclipse.ui.actions.ActionFactory;
65 import org.eclipse.ui.actions.ActionGroup;
66 import org.eclipse.ui.PlatformUI;
67
68
69 /**
70  * A special viewer to present search results. The viewer implements an
71  * optimized adding and removing strategy. Furthermore it manages
72  * contributions for search result types. For example the viewer's context
73  * menu differs if the search result has been generated by a text or
74  * a java search.
75  * @deprecated old search
76  */

77 public class SearchResultViewer extends TableViewer {
78     
79     private SearchResultView fOuterPart;
80     private ShowNextResultAction fShowNextResultAction;
81     private ShowPreviousResultAction fShowPreviousResultAction;
82     private GotoMarkerAction fGotoMarkerActionProxy;
83     private SearchAgainAction fSearchAgainAction;
84     private RemoveResultAction fRemoveSelectedMatchesAction;
85     private RemoveAllResultsAction fRemoveAllResultsAction;
86     private SortDropDownAction fSortDropDownAction;
87     private SearchDropDownAction fSearchDropDownAction;
88     private CopyToClipboardAction fCopyToClipboardAction;
89     private int fMarkerToShow;
90     private boolean fHandleSelectionChangedEvents= true;
91     private ISelection fLastSelection;
92     private boolean fCurrentMatchRemoved= false;
93     private Color fPotentialMatchFgColor;
94     private ActionGroup fActionGroup;
95     private IContextMenuContributor fContextMenuContributor;
96     private IAction fGotoMarkerAction;
97     
98     private ResourceToItemsMapper fResourceToItemsMapper;
99     private String JavaDoc fCurrentPageId= null;
100     
101     public SearchResultViewer(SearchResultView outerPart, Composite parent) {
102         super(new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
103
104         fResourceToItemsMapper= new ResourceToItemsMapper(this);
105         
106         fOuterPart= outerPart;
107         Assert.isNotNull(fOuterPart);
108
109         if (SearchPreferencePage.arePotentialMatchesEmphasized())
110             fPotentialMatchFgColor= new Color(SearchPlugin.getActiveWorkbenchShell().getDisplay(), SearchPreferencePage.getPotentialMatchForegroundColor());
111         
112         setUseHashlookup(true);
113         setContentProvider(new SearchResultContentProvider());
114
115         ILabelProvider labelProvider= new SearchResultLabelProvider(new FileLabelProvider(FileLabelProvider.SHOW_LABEL));
116         setLabelProvider(labelProvider);
117         
118         Search currentSearch= SearchManager.getDefault().getCurrentSearch();
119         boolean hasSearch= currentSearch != null;
120         boolean hasSearchOperation= currentSearch != null && currentSearch.getOperation() != null;
121
122         fShowNextResultAction= new ShowNextResultAction(this);
123         fShowNextResultAction.setEnabled(false);
124         fShowPreviousResultAction= new ShowPreviousResultAction(this);
125         fShowPreviousResultAction.setEnabled(false);
126         fGotoMarkerActionProxy= new GotoMarkerAction(this);
127         fGotoMarkerActionProxy.setEnabled(false);
128         fRemoveSelectedMatchesAction= new RemoveResultAction(this, false);
129         fRemoveSelectedMatchesAction.setEnabled(false);
130         fRemoveAllResultsAction= new RemoveAllResultsAction();
131         fRemoveAllResultsAction.setEnabled(false);
132         fSearchAgainAction= new SearchAgainAction();
133         fSearchAgainAction.setEnabled(hasSearchOperation);
134         fSortDropDownAction = new SortDropDownAction(this);
135         fSortDropDownAction.setEnabled(getItemCount() > 0);
136         fSearchDropDownAction= new SearchDropDownAction();
137         fSearchDropDownAction.setEnabled(hasSearch);
138         fCopyToClipboardAction= new CopyToClipboardAction(this);
139
140         addSelectionChangedListener(
141             new ISelectionChangedListener() {
142                 public void selectionChanged(SelectionChangedEvent event) {
143                     if (fLastSelection == null || !fLastSelection.equals(event.getSelection())) {
144                         fLastSelection= event.getSelection();
145                         handleSelectionChanged();
146                     }
147                 }
148             }
149         );
150
151         addOpenListener(new IOpenListener() {
152             public void open(OpenEvent event) {
153                 showResult();
154             }
155         });
156         
157         MenuManager menuMgr= new MenuManager("#PopUp"); //$NON-NLS-1$
158
menuMgr.setRemoveAllWhenShown(true);
159         menuMgr.addMenuListener(
160             new IMenuListener() {
161                 public void menuAboutToShow(IMenuManager mgr) {
162                     SearchPlugin.createStandardGroups(mgr);
163                     fillContextMenu(mgr);
164                 }
165             });
166         Menu menu= menuMgr.createContextMenu(getTable());
167         getTable().setMenu(menu);
168         
169         // Register menu
170
fOuterPart.getSite().registerContextMenu(menuMgr, this);
171         
172         IActionBars actionBars= fOuterPart.getViewSite().getActionBars();
173         if (actionBars != null) {
174             actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fShowNextResultAction);
175             actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fShowPreviousResultAction);
176         }
177
178         fOuterPart.getSite().setSelectionProvider(this);
179     }
180     
181     void init() {
182         Search search= SearchManager.getDefault().getCurrentSearch();
183         if (search != null) {
184             setGotoMarkerAction(search.getGotoMarkerAction());
185             setContextMenuTarget(search.getContextMenuContributor());
186             setActionGroupFactory(null);
187             setActionGroupFactory(search.getActionGroupFactory());
188             setPageId(search.getPageId());
189             setInput(search.getResults());
190         }
191     }
192
193     protected void doUpdateItem(Widget item, Object JavaDoc element, boolean fullMap) {
194         super.doUpdateItem(item, element, fullMap);
195         if (((SearchResultViewEntry)element).isPotentialMatch()) {
196             TableItem ti = (TableItem) item;
197             ti.setForeground(fPotentialMatchFgColor);
198         }
199     }
200     
201     private void handleSelectionChanged() {
202         int selectionCount= getSelectedEntriesCount();
203         boolean hasSingleSelection= selectionCount == 1;
204         boolean hasElements= getItemCount() > 0;
205         fShowNextResultAction.setEnabled(hasSingleSelection || (hasElements && selectionCount == 0));
206         fShowPreviousResultAction.setEnabled(hasSingleSelection || (hasElements && selectionCount == 0));
207         fGotoMarkerActionProxy.setEnabled(hasSingleSelection);
208         fRemoveSelectedMatchesAction.setEnabled(selectionCount > 0);
209
210         if (fHandleSelectionChangedEvents) {
211             fMarkerToShow= -1;
212             fCurrentMatchRemoved= false;
213         } else
214             fHandleSelectionChangedEvents= true;
215
216         updateStatusLine();
217     }
218
219     void updateStatusLine() {
220         boolean hasSingleSelection= getSelectedEntriesCount() == 1;
221         String JavaDoc location= ""; //$NON-NLS-1$
222
if (hasSingleSelection) {
223             ISearchResultViewEntry entry= (ISearchResultViewEntry)getTable().getItem(getTable().getSelectionIndex()).getData();
224             IPath path= entry.getResource().getFullPath();
225             if (path != null)
226                 location= path.makeRelative().toString();
227         }
228         setStatusLineMessage(location);
229     }
230
231     void enableActions() {
232         /*
233          * Note: The check before each set operation reduces flickering
234          */

235         boolean state= getItemCount() > 0;
236         if (state != fShowNextResultAction.isEnabled())
237             fShowNextResultAction.setEnabled(state);
238         if (state != fShowPreviousResultAction.isEnabled())
239             fShowPreviousResultAction.setEnabled(state);
240         if (state != fSortDropDownAction.isEnabled())
241             fSortDropDownAction.setEnabled(state);
242         if (state != fRemoveAllResultsAction.isEnabled())
243             fRemoveAllResultsAction.setEnabled(state);
244
245         Search currentSearch= SearchManager.getDefault().getCurrentSearch();
246         state= currentSearch != null;
247         boolean operationState= currentSearch != null && currentSearch.getOperation() != null;
248         if (state != fSearchDropDownAction.isEnabled())
249             fSearchDropDownAction.setEnabled(state);
250         if (operationState != fSearchAgainAction.isEnabled())
251             fSearchAgainAction.setEnabled(operationState);
252
253         state= !getSelection().isEmpty();
254         if (state != fGotoMarkerActionProxy.isEnabled())
255             fGotoMarkerActionProxy.setEnabled(state);
256         if (state != fRemoveSelectedMatchesAction.isEnabled())
257             fRemoveSelectedMatchesAction.setEnabled(state);
258     }
259
260
261     protected void inputChanged(Object JavaDoc input, Object JavaDoc oldInput) {
262         fLastSelection= null;
263         getTable().removeAll();
264         super.inputChanged(input, oldInput);
265         fMarkerToShow= -1;
266         fCurrentMatchRemoved= false;
267         updateTitle();
268         enableActions();
269         if (getItemCount() > 0)
270             selectResult(0);
271
272         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), SearchPlugin.getDefault().getSearchViewHelpContextId());
273     }
274
275     protected int getSelectedEntriesCount() {
276         ISelection s= getSelection();
277         if (s == null || s.isEmpty() || !(s instanceof IStructuredSelection))
278             return 0;
279         IStructuredSelection selection= (IStructuredSelection)s;
280         return selection.size();
281     }
282
283     //--- Contribution management -----------------------------------------------
284

285
286     protected boolean enableRemoveMatchMenuItem() {
287         if (getSelectedEntriesCount() != 1)
288             return false;
289         Table table= getTable();
290         int index= table.getSelectionIndex();
291         SearchResultViewEntry entry= null;
292         if (index > -1)
293             entry= (SearchResultViewEntry)table.getItem(index).getData();
294         return (entry != null && entry.getMatchCount() > 1);
295             
296     }
297     
298     void fillContextMenu(IMenuManager menu) {
299         ISelection selection= getSelection();
300         
301         if (fActionGroup != null) {
302             ActionContext context= new ActionContext(selection);
303             context.setInput(getInput());
304             fActionGroup.setContext(context);
305             fActionGroup.fillContextMenu(menu);
306             fActionGroup.setContext(null);
307         }
308         
309         if (fContextMenuContributor != null)
310             fContextMenuContributor.fill(menu, this);
311         
312         if (!selection.isEmpty()) {
313             menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, fCopyToClipboardAction);
314             menu.appendToGroup(IContextMenuConstants.GROUP_GOTO, fGotoMarkerActionProxy);
315             if (enableRemoveMatchMenuItem())
316                 menu.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, new RemoveMatchAction(this));
317             menu.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, new RemoveResultAction(this, true));
318
319             if (isPotentialMatchSelected())
320                 menu.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, new RemovePotentialMatchesAction(fOuterPart.getViewSite()));
321         }
322
323         // If we have elements
324
if (getItemCount() > 0)
325             menu.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, new RemoveAllResultsAction());
326     
327         menu.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, fSearchAgainAction);
328         if (getItemCount() > 0) {
329             fSortDropDownAction= fSortDropDownAction.renew();
330             if (fSortDropDownAction.getSorterCount() > 1)
331                 menu.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, fSortDropDownAction);
332         }
333     }
334
335     private boolean isPotentialMatchSelected() {
336         if (getSelectedEntriesCount() == 0)
337             return false;
338
339         Iterator JavaDoc iter= Collections.EMPTY_LIST.iterator();
340         ISelection selection= getSelection();
341         if (selection instanceof IStructuredSelection)
342             iter= ((IStructuredSelection)selection).iterator();
343
344         while (iter.hasNext()) {
345             Object JavaDoc entry= iter.next();
346             if (entry instanceof ISearchResultViewEntry) {
347                 IMarker marker= ((ISearchResultViewEntry)entry).getSelectedMarker();
348                 if (marker != null && marker.getAttribute(SearchUI.POTENTIAL_MATCH, false))
349                     return true;
350             }
351         }
352
353         return false;
354     }
355
356     IAction getGotoMarkerAction() {
357         // null as return value is covered (no action will take place)
358
return fGotoMarkerAction;
359     }
360
361     void setGotoMarkerAction(IAction gotoMarkerAction) {
362         fGotoMarkerAction= gotoMarkerAction;
363     }
364
365
366     void setContextMenuTarget(IContextMenuContributor contributor) {
367         fContextMenuContributor= contributor;
368     }
369
370     void setActionGroupFactory(IActionGroupFactory groupFactory) {
371         IActionBars actionBars= fOuterPart.getViewSite().getActionBars();
372         if (fActionGroup != null) {
373             fActionGroup.dispose();
374             fActionGroup= null;
375         }
376             
377         if (groupFactory != null) {
378             fActionGroup= groupFactory.createActionGroup(fOuterPart);
379             if (actionBars != null)
380                 fActionGroup.fillActionBars(actionBars);
381         }
382         if (actionBars != null)
383             actionBars.updateActionBars();
384     }
385
386     void setPageId(String JavaDoc pageId) {
387         if (fCurrentPageId != null && fCurrentPageId.equals(pageId))
388             return;
389
390         fCurrentPageId= pageId;
391         ILabelProvider labelProvider= fOuterPart.getLabelProvider(pageId);
392         if (labelProvider != null)
393             internalSetLabelProvider(labelProvider);
394         fSortDropDownAction.setPageId(pageId);
395     }
396     
397     void fillToolBar(IToolBarManager tbm) {
398         tbm.add(fShowNextResultAction);
399         tbm.add(fShowPreviousResultAction);
400 // tbm.add(fGotoMarkerAction); see bug 15275
401
tbm.add(fRemoveSelectedMatchesAction);
402         tbm.add(fRemoveAllResultsAction);
403         tbm.add(new Separator());
404         tbm.add(new OpenSearchDialogAction());
405         tbm.add(fSearchDropDownAction);
406         
407         // need to hook F5 to table
408
getTable().addKeyListener(new KeyAdapter() {
409             public void keyReleased(KeyEvent e) {
410                 if (e.keyCode == SWT.F5) {
411                     fSearchAgainAction.run();
412                     return; // performance
413
}
414                 if (e.character == SWT.DEL) {
415                     new RemoveResultAction(SearchResultViewer.this, true).run();
416                     return; // performance
417
}
418             }
419         });
420     }
421
422     int getItemCount() {
423         return SearchManager.getDefault().getCurrentItemCount();
424     }
425
426     void internalSetLabelProvider(ILabelProvider provider) {
427         setLabelProvider(new SearchResultLabelProvider(provider));
428     }
429
430     /**
431      * Makes the first marker of the current result entry
432      * visible in an editor. If no result
433      * is visible, this method does nothing.
434      */

435     public void showResult() {
436         Table table= getTable();
437         if (!canDoShowResult(table))
438             return;
439
440
441         int index= table.getSelectionIndex();
442         if (index < 0)
443             return;
444         SearchResultViewEntry entry= (SearchResultViewEntry)getTable().getItem(index).getData();
445
446
447         fMarkerToShow= 0;
448         fCurrentMatchRemoved= false;
449         entry.setSelectedMarkerIndex(0);
450         openCurrentSelection();
451     }
452
453
454     /**
455      * Makes the next result (marker) visible in an editor. If no result
456      * is visible, this method makes the first result visible.
457      */

458     public void showNextResult() {
459         Table table= getTable();
460         if (!canDoShowResult(table))
461             return;
462
463         int index= table.getSelectionIndex();
464         SearchResultViewEntry entry= null;
465         if (index > -1)
466             entry= (SearchResultViewEntry)table.getItem(index).getData();
467
468         if (fCurrentMatchRemoved)
469             fCurrentMatchRemoved= false;
470         else
471             fMarkerToShow++;
472         if (entry == null || fMarkerToShow >= entry.getMatchCount()) {
473             // move selection
474
if (index == -1) {
475                 index= 0;
476             } else {
477                 index++;
478                 if (index >= table.getItemCount())
479                     index= 0;
480             }
481             fMarkerToShow= 0;
482             entry= (SearchResultViewEntry)getTable().getItem(index).getData();
483             selectResult(index);
484         }
485         entry.setSelectedMarkerIndex(fMarkerToShow);
486         openCurrentSelection();
487         updateStatusLine();
488     }
489
490
491     /**
492      * Makes the previous result (marker) visible. If there isn't any
493      * visible result, this method makes the last result visible.
494      */

495     public void showPreviousResult() {
496         fCurrentMatchRemoved= false;
497         Table table= getTable();
498         if (!canDoShowResult(table))
499             return;
500                 
501         int index= table.getSelectionIndex();
502         SearchResultViewEntry entry;
503
504
505         fMarkerToShow--;
506         if (fMarkerToShow >= 0)
507             entry= (SearchResultViewEntry)getTable().getItem(getTable().getSelectionIndex()).getData();
508         else {
509             // move selection
510
int count= table.getItemCount();
511             if (index == -1) {
512                 index= count - 1;
513             } else {
514                 index--;
515                 if (index < 0)
516                     index= count - 1;
517             }
518             entry= (SearchResultViewEntry)getTable().getItem(index).getData();
519             fMarkerToShow= entry.getMatchCount() - 1;
520             selectResult(index);
521         }
522         entry.setSelectedMarkerIndex(fMarkerToShow);
523         openCurrentSelection();
524         updateStatusLine();
525     }
526     
527     private boolean canDoShowResult(Table table) {
528         if (table == null || getItemCount() == 0)
529             return false;
530         return true;
531     }
532         
533     private void selectResult(int index) {
534         fHandleSelectionChangedEvents= false;
535         Object JavaDoc element= getElementAt(index);
536         if (element != null)
537             setSelection(new StructuredSelection(getElementAt(index)), true);
538         else
539             setSelection(StructuredSelection.EMPTY);
540     }
541
542     private void openCurrentSelection() {
543         IAction action= getGotoMarkerAction();
544         if (action != null)
545             action.run();
546     }
547
548     /**
549      * Updates the foreground color for potential matches.
550      */

551     void updatedPotentialMatchFgColor() {
552         if (fPotentialMatchFgColor != null)
553             fPotentialMatchFgColor.dispose();
554         fPotentialMatchFgColor= null;
555         if (SearchPreferencePage.arePotentialMatchesEmphasized())
556             fPotentialMatchFgColor= new Color(SearchPlugin.getActiveWorkbenchShell().getDisplay(), SearchPreferencePage.getPotentialMatchForegroundColor());
557         refresh();
558     }
559
560     /**
561      * Update the title
562      */

563     protected void updateTitle() {
564         boolean hasCurrentSearch= SearchManager.getDefault().getCurrentSearch() != null;
565         String JavaDoc title;
566         if (hasCurrentSearch) {
567             String JavaDoc description= SearchManager.getDefault().getCurrentSearch().getFullDescription();
568             title= Messages.format(SearchMessages.SearchResultView_titleWithDescription, description);
569         } else
570             title= SearchMessages.SearchResultView_title;
571         if (title == null || !title.equals(fOuterPart.getContentDescription()))
572             fOuterPart.setContentDescription(title);
573     }
574
575     /**
576      * Clear the title
577      */

578     protected void clearTitle() {
579         String JavaDoc title= SearchMessages.SearchResultView_title;
580         if (!title.equals(fOuterPart.getContentDescription()))
581             fOuterPart.setContentDescription(title);
582     }
583
584     /**
585      * Sets the message text to be displayed on the status line.
586      * The image on the status line is cleared.
587      */

588     private void setStatusLineMessage(String JavaDoc message) {
589         fOuterPart.getViewSite().getActionBars().getStatusLineManager().setMessage(message);
590     }
591
592
593     protected void handleDispose(DisposeEvent event) {
594         fLastSelection= null;
595         Menu menu= getTable().getMenu();
596         if (menu != null)
597             menu.dispose();
598         if (fPotentialMatchFgColor != null)
599             fPotentialMatchFgColor.dispose();
600         if (fActionGroup != null) {
601             fActionGroup.dispose();
602             fActionGroup= null;
603         }
604         super.handleDispose(event);
605     }
606
607     //--- Change event handling -------------------------------------------------
608

609     /**
610      * Handle a single add.
611      */

612     protected void handleAddMatch(ISearchResultViewEntry entry) {
613         insert(entry, -1);
614     }
615
616     /**
617      * Handle a single remove.
618      */

619     protected void handleRemoveMatch(ISearchResultViewEntry entry) {
620         Widget item= findItem(entry);
621         if (entry.getMatchCount() == 0)
622             remove(entry);
623         else
624             updateItem(item, entry);
625         updateStatusLine();
626     }
627
628     /**
629      * Handle remove all.
630      */

631     protected void handleRemoveAll() {
632         setContextMenuTarget(null);
633         setActionGroupFactory(null);
634         setInput(null);
635     }
636
637     /**
638      * Handle an update of an entry.
639      */

640     protected void handleUpdateMatch(ISearchResultViewEntry entry, boolean matchRemoved) {
641         Widget item= findItem(entry);
642         updateItem(item, entry);
643         if (matchRemoved && getSelectionFromWidget().contains(entry))
644             fCurrentMatchRemoved= true;
645     }
646
647     //--- Persistency -------------------------------------------------
648

649     void restoreState(IMemento memento) {
650         fSortDropDownAction.restoreState(memento);
651     }
652     
653     void saveState(IMemento memento) {
654         fSortDropDownAction.saveState(memento);
655     }
656
657     /*
658      * @see ContentViewer#handleLabelProviderChanged(LabelProviderChangedEvent)
659      */

660     protected void handleLabelProviderChanged(LabelProviderChangedEvent event) {
661         Object JavaDoc[] changed= event.getElements();
662         if (changed != null && !fResourceToItemsMapper.isEmpty()) {
663             ArrayList JavaDoc others= new ArrayList JavaDoc(changed.length);
664             for (int i= 0; i < changed.length; i++) {
665                 Object JavaDoc curr= changed[i];
666                 if (curr instanceof IResource)
667                     fResourceToItemsMapper.resourceChanged((IResource) curr);
668                 else if (curr instanceof IAdaptable) {
669                     IResource resource= (IResource)((IAdaptable)curr).getAdapter(IResource.class);
670                     if (resource != null)
671                         fResourceToItemsMapper.resourceChanged(resource);
672                 } else
673                     others.add(curr);
674             }
675             if (others.isEmpty()) {
676                 return;
677             }
678             event= new LabelProviderChangedEvent((IBaseLabelProvider) event.getSource(), others.toArray());
679         }
680         super.handleLabelProviderChanged(event);
681     }
682
683     /*
684      * @see StructuredViewer#mapElement(Object, Widget)
685      */

686     protected void mapElement(Object JavaDoc element, Widget item) {
687         super.mapElement(element, item);
688         if (item instanceof Item) {
689             fResourceToItemsMapper.addToMap(element, (Item)item);
690         }
691     }
692
693     /*
694      * @see StructuredViewer#unmapElement(Object, Widget)
695      */

696     protected void unmapElement(Object JavaDoc element, Widget item) {
697         if (item instanceof Item) {
698             fResourceToItemsMapper.removeFromMap(element, (Item)item);
699         }
700         super.unmapElement(element, item);
701     }
702
703     /*
704      * @see StructuredViewer#unmapAllElements()
705      */

706     protected void unmapAllElements() {
707         fResourceToItemsMapper.clearMap();
708         super.unmapAllElements();
709     }
710     
711     protected void internalRefresh(Object JavaDoc element, boolean updateLabels) {
712         // see bug 44891
713
getTable().setRedraw(false);
714         super.internalRefresh(element, updateLabels);
715         getTable().setRedraw(true);
716     }
717
718     void handleAllSearchesRemoved() {
719         setContextMenuTarget(null);
720         setActionGroupFactory(null);
721         setInput(null);
722         fSearchDropDownAction.clear();
723     }
724
725 }
726
Popular Tags