KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > search > ResultPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved.
3  * This program and the accompanying materials are made available under the
4  * terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * Contributors: IBM Corporation - initial API and implementation
8  ******************************************************************************/

9 package org.eclipse.help.ui.internal.search;
10 import org.eclipse.help.internal.base.*;
11 import org.eclipse.help.internal.search.*;
12 import org.eclipse.help.ui.internal.ide.*;
13 import org.eclipse.jface.action.*;
14 import org.eclipse.jface.viewers.*;
15 import org.eclipse.search.ui.*;
16 import org.eclipse.search.ui.text.*;
17 import org.eclipse.swt.custom.*;
18 import org.eclipse.ui.*;
19 public class ResultPage extends AbstractTextSearchViewPage {
20     final int SORT_BY_SCORE = 0;
21     final int SORT_BY_TITLE = 1;
22     private ResultTableContentProvider contentProvider;
23     private SortAction currentSortAction;
24     private SortAction sortByScoreAction;
25     private SortAction sortByTitleAction;
26     public ResultPage() {
27         super(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT);
28         sortByScoreAction = new SortAction(HelpIdeResources
29                 .getString("HelpSearchResultPage.score"), this, SORT_BY_SCORE); //$NON-NLS-1$
30
sortByTitleAction = new SortAction(HelpIdeResources
31                 .getString("HelpSearchResultPage.title"), this, SORT_BY_TITLE); //$NON-NLS-1$
32
currentSortAction = sortByScoreAction;
33     }
34     protected void showMatch(Match match, int currentOffset, int currentLength,
35             boolean activate) throws PartInitException {
36         // TODO - honor activate flag (ref bug 51345)
37
Object JavaDoc element = match.getElement();
38         try {
39             final SearchHit hit = (SearchHit) element;
40             HelpSearchQuery query = (HelpSearchQuery) ((HelpSearchResult) getInput())
41                     .getQuery();
42             final String JavaDoc urlQuery = query.getQueryData().toURLQuery();
43             BusyIndicator.showWhile(null, new Runnable JavaDoc() {
44                 public void run() {
45                     try {
46                         BaseHelpSystem.getHelpDisplay().displaySearch(urlQuery,
47                                 hit.getHref(), false);
48                     } catch (Exception JavaDoc e) {
49                     }
50                 }
51             });
52         } catch (Exception JavaDoc e) {
53         }
54     }
55     protected void elementsChanged(Object JavaDoc[] objects) {
56         if (contentProvider != null)
57             contentProvider.elementsChanged(objects);
58     }
59     protected void clear() {
60         if (contentProvider != null)
61             contentProvider.clear();
62     }
63     protected void configureTreeViewer(TreeViewer viewer) {
64         throw new IllegalStateException JavaDoc(this.getClass().getName()
65                 + " doesn't support tree mode."); //$NON-NLS-1$
66
}
67     protected void configureTableViewer(TableViewer viewer) {
68         viewer.setSorter(new SorterByScore());
69         viewer.setLabelProvider(new ResultTableLabelProvider());
70         contentProvider = new ResultTableContentProvider();
71         viewer.setContentProvider(contentProvider);
72     }
73     protected void fillContextMenu(IMenuManager mgr) {
74         super.fillContextMenu(mgr);
75         addSortActions(mgr);
76     }
77     private void addSortActions(IMenuManager mgr) {
78         if (getLayout() != FLAG_LAYOUT_FLAT)
79             return;
80         MenuManager sortMenu = new MenuManager(HelpIdeResources
81                 .getString("HelpSearchResultPage.sortBy")); //$NON-NLS-1$
82
sortMenu.add(sortByScoreAction);
83         sortMenu.add(sortByTitleAction);
84         sortByScoreAction.setChecked(currentSortAction == sortByScoreAction);
85         sortByTitleAction.setChecked(currentSortAction == sortByTitleAction);
86         mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenu);
87     }
88     public void setSortOrder(SortAction action) {
89         currentSortAction = action;
90         StructuredViewer viewer = getViewer();
91         if (action.getSortOrder() == SORT_BY_SCORE) {
92             viewer.setSorter(new SorterByScore());
93         } else {
94             viewer.setSorter(new SorterByTitle());
95         }
96     }
97 }
Popular Tags