KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.text.*;
11
12 import org.eclipse.help.internal.search.*;
13 import org.eclipse.help.ui.internal.ide.*;
14 import org.eclipse.jface.resource.*;
15 import org.eclipse.jface.viewers.*;
16 import org.eclipse.swt.graphics.*;
17 public class ResultTableLabelProvider extends LabelProvider {
18     private static final ImageDescriptor IMAGE_DSCR_TOPIC = ImageDescriptor
19             .createFromURL(HelpIdeResources
20                     .getImagePath(IHelpIdeConstants.IMAGE_FILE_TOPIC));
21     static ImageRegistry imgRegistry = null;
22     ResultTableLabelProvider() {
23         super();
24         if (imgRegistry == null) {
25             imgRegistry = HelpIdePlugin.getDefault().getImageRegistry();
26             imgRegistry
27                     .put(IHelpIdeConstants.IMAGE_KEY_TOPIC, IMAGE_DSCR_TOPIC);
28         }
29     }
30     public String JavaDoc getText(Object JavaDoc o) {
31         if (o instanceof SearchHit) {
32             SearchHit searchHit = (SearchHit) o;
33             // Use Score percentage and label as topic label
34
float score = searchHit.getScore();
35             NumberFormat percentFormat = NumberFormat.getPercentInstance();
36             String JavaDoc scoreString = percentFormat.format(score);
37             return scoreString + " " + searchHit.getLabel(); //$NON-NLS-1$
38
}
39         return super.getText(o);
40     }
41     public Image getImage(Object JavaDoc o) {
42         if (o instanceof SearchHit)
43             return imgRegistry.get(IHelpIdeConstants.IMAGE_KEY_TOPIC);
44         return super.getImage(o);
45     }
46 }
Popular Tags