Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2002-08-09 14:54:39 +0000
committerDani Megert2002-08-09 14:54:39 +0000
commitb44621b08bd8a63d0d06bdec4777a5df45857842 (patch)
tree9ebff7587a5653da3a25b0c64c0f4f50af0d8de9
parent3d91ba55ac544f35f30a8c09b88eba37763ed2b0 (diff)
downloadeclipse.platform.text-b44621b08bd8a63d0d06bdec4777a5df45857842.tar.gz
eclipse.platform.text-b44621b08bd8a63d0d06bdec4777a5df45857842.tar.xz
eclipse.platform.text-b44621b08bd8a63d0d06bdec4777a5df45857842.zip
Fixed bug 13036: Search LabelProviders should not override getText()
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java55
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java7
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java9
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java52
4 files changed, 79 insertions, 44 deletions
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java
index 504673245..29907ba63 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java
@@ -6,42 +6,21 @@ package org.eclipse.search.internal.ui;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.jface.viewers.DecoratingLabelProvider;
-import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.search.ui.ISearchResultViewEntry;
-class SearchResultLabelProvider extends DecoratingLabelProvider {
+class SearchResultLabelProvider extends LabelProvider {
private static final String MATCHES_POSTFIX= " " + SearchMessages.getString("SearchResultView.matches") + ")"; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
- private static class MatchCountDecorator extends LabelProvider implements ILabelDecorator {
- /*
- * @see ILabelDecorator#decorateImage(Image, Object)
- */
- public Image decorateImage(Image image, Object element) {
- return null;
- }
-
- /*
- * @see ILabelDecorator#decorateText(String, Object)
- */
- public String decorateText(String text, Object element) {
- StringBuffer buf= new StringBuffer(text);
- int count= ((ISearchResultViewEntry)element).getMatchCount();
- if (count > 1) {
- buf.append(" ("); //$NON-NLS-1$
- buf.append(count);
- buf.append(MATCHES_POSTFIX);
- }
- return buf.toString();
- }
- }
+ private ILabelProvider fLabelProvider;
+
- SearchResultLabelProvider(ILabelProvider provider, ILabelDecorator decorator) {
- super(provider, new MatchCountDecorator());
+ SearchResultLabelProvider(ILabelProvider provider) {
+ fLabelProvider= provider;
}
public String getText(Object element) {
@@ -55,7 +34,29 @@ class SearchResultLabelProvider extends DecoratingLabelProvider {
return buf.toString();
}
+ public Image getImage(Object element) {
+ return fLabelProvider.getImage(element);
+ }
+
// Don't dispose since label providers are reused.
public void dispose() {
}
+
+ ILabelProvider getLabelProvider() {
+ return fLabelProvider;
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ super.addListener(listener);
+ fLabelProvider.addListener(listener);
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return fLabelProvider.isLabelProperty(element, property);
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ super.removeListener(listener);
+ fLabelProvider.removeListener(listener);
+ }
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java
index e709ce317..81496495d 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java
@@ -21,6 +21,7 @@ import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
@@ -146,10 +147,10 @@ public class SearchResultView extends ViewPart implements ISearchResultView {
if (fViewer == null)
return null;
IBaseLabelProvider labelProvider= fViewer.getLabelProvider();
- if (labelProvider instanceof SearchResultLabelProvider)
- return ((SearchResultLabelProvider)labelProvider).getLabelProvider();
- else
+ if (labelProvider == null)
return null;
+
+ return ((SearchResultLabelProvider)((DecoratingLabelProvider)labelProvider).getLabelProvider()).getLabelProvider();
}
private void setContextMenuContributor(final IContextMenuContributor contributor) {
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java
index 2f260f50d..807fc6f9b 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java
@@ -25,6 +25,8 @@ import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection;
@@ -91,7 +93,10 @@ public class SearchResultViewer extends TableViewer {
setUseHashlookup(true);
setContentProvider(new SearchResultContentProvider());
- setLabelProvider(new SearchResultLabelProvider(new FileLabelProvider(FileLabelProvider.SHOW_LABEL), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
+
+ ILabelDecorator decorator= PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
+ ILabelProvider labelProvider= new SearchResultLabelProvider(new FileLabelProvider(FileLabelProvider.SHOW_LABEL));
+ setLabelProvider(new DecoratingLabelProvider(labelProvider, decorator));
boolean hasSearch= SearchManager.getDefault().getCurrentSearch() != null;
@@ -365,7 +370,7 @@ public class SearchResultViewer extends TableViewer {
}
void internalSetLabelProvider(ILabelProvider provider) {
- setLabelProvider(new SearchResultLabelProvider(provider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
+ setLabelProvider(new DecoratingLabelProvider(new SearchResultLabelProvider(provider), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
}
/**
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java
index 9607ca234..186b14876 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java
@@ -11,8 +11,9 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.ILabelDecorator;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.model.WorkbenchLabelProvider;
@@ -22,7 +23,7 @@ import org.eclipse.search.ui.ISearchResultViewEntry;
import org.eclipse.search.internal.ui.SearchMessages;
-public class FileLabelProvider extends DecoratingLabelProvider {
+public class FileLabelProvider extends LabelProvider {
public static final int SHOW_LABEL= 1;
public static final int SHOW_LABEL_PATH= 2;
@@ -31,11 +32,15 @@ public class FileLabelProvider extends DecoratingLabelProvider {
private static final String fgSeparatorFormat= SearchMessages.getString("FileLabelProvider.dashSeparated"); //$NON-NLS-1$
+ private WorkbenchLabelProvider fLabelProvider;
+ private ILabelDecorator fDecorator;
+
private int fOrder;
private String[] fArgs= new String[2];
public FileLabelProvider(int orderFlag) {
- super(new WorkbenchLabelProvider(), getDecoratorManager());
+ fDecorator= PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
+ fLabelProvider= new WorkbenchLabelProvider();
fOrder= orderFlag;
}
@@ -58,7 +63,7 @@ public class FileLabelProvider extends DecoratingLabelProvider {
if (path.getDevice() == null)
path= path.makeRelative();
if (fOrder == SHOW_LABEL || fOrder == SHOW_LABEL_PATH) {
- text= getLabelProvider().getText(resource);
+ text= fLabelProvider.getText(resource);
if (path != null && fOrder == SHOW_LABEL_PATH) {
fArgs[0]= text;
fArgs[1]= path.toString();
@@ -71,17 +76,17 @@ public class FileLabelProvider extends DecoratingLabelProvider {
text= ""; //$NON-NLS-1$
if (fOrder == SHOW_PATH_LABEL) {
fArgs[0]= text;
- fArgs[1]= getLabelProvider().getText(resource);
+ fArgs[1]= fLabelProvider.getText(resource);
text= MessageFormat.format(fgSeparatorFormat, fArgs);
}
}
}
// Do the decoration
- if (getLabelDecorator() != null) {
- String decorated= getLabelDecorator().decorateText(text, element);
- if (decorated != null)
- return decorated;
+ if (fDecorator != null) {
+ String decoratedText= fDecorator.decorateText(text, resource);
+ if (decoratedText != null)
+ return decoratedText;
}
return text;
}
@@ -89,10 +94,33 @@ public class FileLabelProvider extends DecoratingLabelProvider {
public Image getImage(Object element) {
if (!(element instanceof ISearchResultViewEntry))
return null; //$NON-NLS-1$
- return super.getImage(((ISearchResultViewEntry) element).getResource());
+
+ IResource resource= ((ISearchResultViewEntry) element).getResource();
+ Image image= fLabelProvider.getImage(resource);
+ if (fDecorator != null) {
+ Image decoratedImage= fDecorator.decorateImage(image, resource);
+ if (decoratedImage != null)
+ return decoratedImage;
+ }
+ return image;
+ }
+
+ public void dispose() {
+ super.dispose();
+ fLabelProvider.dispose();
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return fLabelProvider.isLabelProperty(element, property);
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ super.removeListener(listener);
+ fLabelProvider.removeListener(listener);
}
- private static ILabelDecorator getDecoratorManager() {
- return PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
+ public void addListener(ILabelProviderListener listener) {
+ super.addListener(listener);
+ fLabelProvider.addListener(listener);
}
}

Back to the top