01: /*******************************************************************************
02: * Copyright (c) 2003, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.navigator;
11:
12: import org.eclipse.core.runtime.Assert;
13: import org.eclipse.jface.viewers.ILabelProvider;
14: import org.eclipse.jface.viewers.IStructuredSelection;
15: import org.eclipse.osgi.util.NLS;
16: import org.eclipse.ui.navigator.ICommonLabelProvider;
17: import org.eclipse.ui.navigator.IDescriptionProvider;
18:
19: /**
20: *
21: * <p>
22: * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
23: * part of a work in progress. There is a guarantee neither that this API will
24: * work nor that it will remain the same. Please do not use this API without
25: * consulting with the Platform/UI team.
26: * </p>
27: *
28: * @since 3.2
29: *
30: */
31: public final class NavigatorContentServiceDescriptionProvider implements
32: IDescriptionProvider {
33:
34: private final NavigatorContentService contentService;
35:
36: /**
37: * Creates a description provider that targets the given service.
38: *
39: * @param aContentService
40: * The content service associated with this provider.
41: */
42: public NavigatorContentServiceDescriptionProvider(
43: NavigatorContentService aContentService) {
44: Assert.isNotNull(aContentService);
45: contentService = aContentService;
46: }
47:
48: public String getDescription(Object anElement) {
49:
50: Object target;
51:
52: if (anElement instanceof IStructuredSelection) {
53:
54: IStructuredSelection structuredSelection = (IStructuredSelection) anElement;
55: if (structuredSelection.size() > 1) {
56: return getDefaultStatusBarMessage(structuredSelection
57: .size());
58: }
59: target = structuredSelection.getFirstElement();
60: } else {
61: target = anElement;
62: }
63: String message = null;
64: ILabelProvider[] providers = contentService
65: .findRelevantLabelProviders(target);
66: if (providers.length == 0) {
67: return getDefaultStatusBarMessage(0);
68: }
69: for (int i = 0; i < providers.length
70: && (message == null || message.length() == 0); i++) {
71: if (providers[i] instanceof ICommonLabelProvider) {
72: message = ((ICommonLabelProvider) providers[i])
73: .getDescription(target);
74: }
75: }
76: message = (message != null) ? message
77: : getDefaultStatusBarMessage(1);
78: return message;
79:
80: }
81:
82: /**
83: * @param aSize
84: * The number of items selected.
85: * @return A string of the form "# items selected"
86: */
87: protected final String getDefaultStatusBarMessage(int aSize) {
88: return NLS
89: .bind(
90: CommonNavigatorMessages.Navigator_statusLineMultiSelect,
91: new Object[] { new Integer(aSize) });
92:
93: }
94:
95: }
|