blob: ddc8ead3e1a196b6f17ad6292e86aa96d2624566 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.search.internal.ui.util;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.swt.graphics.Image;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.resources.IResource;
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;
import org.eclipse.search.internal.ui.SearchMessages;
import org.eclipse.search.ui.ISearchResultViewEntry;
/**
* @deprecated Old search view
*/
@Deprecated
public class FileLabelProvider extends LabelProvider {
public static final int SHOW_LABEL= 1;
public static final int SHOW_LABEL_PATH= 2;
public static final int SHOW_PATH_LABEL= 3;
public static final int SHOW_PATH= 4;
private static final String fgSeparatorFormat= SearchMessages.FileLabelProvider_dashSeparated;
private WorkbenchLabelProvider fLabelProvider;
private ILabelDecorator fDecorator;
private int fOrder;
private Object[] fArgs= new String[2];
public FileLabelProvider(int orderFlag) {
fDecorator= PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
fLabelProvider= new WorkbenchLabelProvider();
fOrder= orderFlag;
}
public void setOrder(int orderFlag) {
fOrder= orderFlag;
}
@Override
public String getText(Object element) {
if (!(element instanceof ISearchResultViewEntry))
return ""; //$NON-NLS-1$
IResource resource= ((ISearchResultViewEntry) element).getResource();
String text= null;
if (resource == null || !resource.exists())
text= SearchMessages.SearchResultView_removed_resource;
else {
IPath path= resource.getFullPath().removeLastSegments(1);
if (path.getDevice() == null)
path= path.makeRelative();
if (fOrder == SHOW_LABEL || fOrder == SHOW_LABEL_PATH) {
text= fLabelProvider.getText(resource);
if (path != null && fOrder == SHOW_LABEL_PATH) {
fArgs[0]= text;
fArgs[1]= path.toString();
text= MessageFormat.format(fgSeparatorFormat, fArgs);
}
} else {
if (path != null)
text= path.toString();
else
text= ""; //$NON-NLS-1$
if (fOrder == SHOW_PATH_LABEL) {
fArgs[0]= text;
fArgs[1]= fLabelProvider.getText(resource);
text= MessageFormat.format(fgSeparatorFormat, fArgs);
}
}
}
// Do the decoration
if (fDecorator != null) {
String decoratedText= fDecorator.decorateText(text, resource);
if (decoratedText != null)
return decoratedText;
}
return text;
}
@Override
public Image getImage(Object element) {
if (!(element instanceof ISearchResultViewEntry))
return null;
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;
}
@Override
public void dispose() {
super.dispose();
fLabelProvider.dispose();
}
@Override
public boolean isLabelProperty(Object element, String property) {
return fLabelProvider.isLabelProperty(element, property);
}
@Override
public void removeListener(ILabelProviderListener listener) {
super.removeListener(listener);
fLabelProvider.removeListener(listener);
}
@Override
public void addListener(ILabelProviderListener listener) {
super.addListener(listener);
fLabelProvider.addListener(listener);
}
}
|