1
/*******************************************************************************
2
* Copyright (c) 2000, 2010 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
9
* IBM Corporation - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.ui.viewsupport;
14
import org.eclipse.cdt.core.model.ICElement;
15
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
17
import org.eclipse.cdt.internal.ui.CUIMessages;
18
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.jface.action.IStatusLineManager;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.ISelectionChangedListener;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.SelectionChangedEvent;
25
import org.eclipse.osgi.util.NLS;
28
* Add the <code>StatusBarUpdater</code> to your ViewPart to have the statusbar
29
* describing the selected elements.
31
public class StatusBarUpdater implements ISelectionChangedListener {
33
private final long LABEL_FLAGS= CElementLabels.DEFAULT_QUALIFIED | CElementLabels.ROOT_POST_QUALIFIED | CElementLabels.APPEND_ROOT_PATH |
34
CElementLabels.M_PARAMETER_TYPES | CElementLabels.M_APP_RETURNTYPE | CElementLabels.M_EXCEPTIONS |
35
CElementLabels.F_APP_TYPE_SIGNATURE;
37
private IStatusLineManager fStatusLineManager;
39
public StatusBarUpdater(IStatusLineManager statusLineManager) {
40
fStatusLineManager= statusLineManager;
44
* @see ISelectionChangedListener#selectionChanged
46
public void selectionChanged(SelectionChangedEvent event) {
47
String statusBarMessage= formatMessage(event.getSelection());
48
fStatusLineManager.setMessage(statusBarMessage);
52
protected String formatMessage(ISelection sel) {
53
if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
54
IStructuredSelection selection= (IStructuredSelection) sel;
56
int nElements= selection.size();
58
return NLS.bind(CUIMessages.StatusBarUpdater_num_elements_selected, String.valueOf(nElements));
60
Object elem= selection.getFirstElement();
61
if (elem instanceof ICElement) {
62
return formatCElementMessage((ICElement) elem);
63
} else if (elem instanceof IResource) {
64
return formatResourceMessage((IResource) elem);
67
return ""; //$NON-NLS-1$
70
private String formatCElementMessage(ICElement element) {
71
return CElementLabels.getElementLabel(element, LABEL_FLAGS);
74
private String formatResourceMessage(IResource element) {
75
IContainer parent= element.getParent();
76
if (parent != null && parent.getType() != IResource.ROOT)
77
return element.getName() + CElementLabels.CONCAT_STRING + parent.getFullPath().makeRelative().toString();
78
return element.getName();