1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2003, 2008 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.ui.internal.navigator;
|
12
|
|
13
|
import org.eclipse.core.runtime.Assert;
|
14
|
import org.eclipse.jface.viewers.ILabelProvider;
|
15
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
16
|
import org.eclipse.osgi.util.NLS;
|
17
|
import org.eclipse.ui.navigator.ICommonLabelProvider;
|
18
|
import org.eclipse.ui.navigator.IDescriptionProvider;
|
19
|
|
20
|
/**
|
21
|
*
|
22
|
* @since 3.2
|
23
|
*
|
24
|
*/
|
25
|
public final class NavigatorContentServiceDescriptionProvider implements
|
26
|
IDescriptionProvider {
|
27
|
|
28
|
private final NavigatorContentService contentService;
|
29
|
|
30
|
/**
|
31
|
* Creates a description provider that targets the given service.
|
32
|
*
|
33
|
* @param aContentService
|
34
|
* The content service associated with this provider.
|
35
|
*/
|
36
|
public NavigatorContentServiceDescriptionProvider(
|
37
|
NavigatorContentService aContentService) {
|
38
|
Assert.isNotNull(aContentService);
|
39
|
contentService = aContentService;
|
40
|
}
|
41
|
|
42
|
public String getDescription(Object anElement) {
|
43
|
|
44
|
Object target;
|
45
|
|
46
|
if (anElement instanceof IStructuredSelection) {
|
47
|
|
48
|
IStructuredSelection structuredSelection = (IStructuredSelection) anElement;
|
49
|
if (structuredSelection.size() > 1) {
|
50
|
return getDefaultStatusBarMessage(structuredSelection.size());
|
51
|
}
|
52
|
target = structuredSelection.getFirstElement();
|
53
|
} else {
|
54
|
target = anElement;
|
55
|
}
|
56
|
String message = null;
|
57
|
ILabelProvider[] providers = contentService
|
58
|
.findRelevantLabelProviders(target);
|
59
|
if (providers.length == 0) {
|
60
|
return getDefaultStatusBarMessage(0);
|
61
|
}
|
62
|
for (int i = 0; i < providers.length && (message == null || message.length() == 0); i++) {
|
63
|
if (providers[i] instanceof ICommonLabelProvider) {
|
64
|
message = ((ICommonLabelProvider) providers[i])
|
65
|
.getDescription(target);
|
66
|
}
|
67
|
}
|
68
|
message = (message != null) ? message : getDefaultStatusBarMessage(1);
|
69
|
return message;
|
70
|
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* @param aSize
|
75
|
* The number of items selected.
|
76
|
* @return A string of the form "# items selected"
|
77
|
*/
|
78
|
protected final String getDefaultStatusBarMessage(int aSize) {
|
79
|
return NLS.bind(
|
80
|
CommonNavigatorMessages.Navigator_statusLineMultiSelect,
|
81
|
new Object[] { new Integer(aSize) });
|
82
|
|
83
|
}
|
84
|
|
85
|
}
|