]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/search/TextSearchLabelProvider.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / search / TextSearchLabelProvider.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2009 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 org.eclipse.jface.viewers.LabelProvider;
14 import org.eclipse.jface.viewers.StyledCellLabelProvider;
15 import org.eclipse.jface.viewers.StyledString;
16
17 import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
18
19 import org.eclipse.jdt.internal.corext.util.Messages;
20
21
22 public abstract class TextSearchLabelProvider extends LabelProvider {
23
24         private AbstractTextSearchViewPage fPage;
25
26         public TextSearchLabelProvider(AbstractTextSearchViewPage page) {
27                 fPage= page;
28         }
29
30         public AbstractTextSearchViewPage getPage() {
31                 return fPage;
32         }
33
34         protected final StyledString getColoredLabelWithCounts(Object element, StyledString coloredName) {
35                 String name= coloredName.getString();
36                 String decorated= getLabelWithCounts(element, name);
37                 if (decorated.length() > name.length()) {
38                         StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.COUNTER_STYLER, coloredName);
39                 }
40                 return coloredName;
41         }
42
43         protected final String getLabelWithCounts(Object element, String elementName) {
44                 int matchCount= fPage.getInput().getMatchCount(element);
45                 if (matchCount < 2)
46                         return elementName;
47
48                 return Messages.format(SearchMessages.TextSearchLabelProvider_matchCountFormat, new String[] { elementName, String.valueOf(matchCount)});
49         }
50 }