blob: 97502705b6ac4853272ae41084268efaf52dd420 (
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
|
/*******************************************************************************
* Copyright (c) 2002, 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.cview;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.internal.ui.viewsupport.StandardCElementLabelProvider;
import org.eclipse.cdt.ui.CElementImageDescriptor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
/*
* CViewLabelProvider
*/
public class CViewLabelProvider extends StandardCElementLabelProvider {
/**
* @param flags
* @param adormentProviders
*/
public CViewLabelProvider(int textFlags, int imageFlags) {
super(textFlags, imageFlags);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText(Object element) {
if (element instanceof IncludeReferenceProxy) {
IIncludeReference ref = ((IncludeReferenceProxy)element).getReference();
IPath location = ref.getPath();
IContainer[] containers = ref.getCModel().getWorkspace().getRoot().findContainersForLocation(location);
if (containers.length > 0) {
return containers[0].getFullPath().makeRelative().toString();
}
} else if (element instanceof IIncludeReference) {
IIncludeReference ref = (IIncludeReference)element;
Object parent = ref.getParent();
if (parent instanceof IIncludeReference) {
IPath p = ref.getPath();
IPath parentLocation = ((IIncludeReference)parent).getPath();
if (parentLocation.isPrefixOf(p)) {
p = p.setDevice(null);
p = p.removeFirstSegments(parentLocation.segmentCount());
}
return p.toString();
}
} else if (element instanceof ITranslationUnit) {
ITranslationUnit unit = (ITranslationUnit)element;
Object parent = unit.getParent();
if (parent instanceof IIncludeReference) {
IPath p = unit.getPath();
IPath parentLocation = ((IIncludeReference)parent).getPath();
if (parentLocation.isPrefixOf(p)) {
p = p.setDevice(null);
p = p.removeFirstSegments(parentLocation.segmentCount());
}
return p.toString();
}
}
return super.getText(element);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
public Image getImage(Object element) {
if (element instanceof IncludeReferenceProxy) {
IIncludeReference reference = ((IncludeReferenceProxy)element).getReference();
IPath path = reference.getPath();
IContainer container = reference.getCModel().getWorkspace().getRoot().getContainerForLocation(path);
if (container != null && container.isAccessible()) {
ImageDescriptor desc = CElementImageProvider.getImageDescriptor(ICElement.C_PROJECT);
desc = new CElementImageDescriptor(desc, 0, CElementImageProvider.SMALL_SIZE);
return CUIPlugin.getImageDescriptorRegistry().get(desc);
}
} else if (element instanceof IIncludeReference) {
ImageDescriptor desc = CElementImageProvider.getImageDescriptor(ICElement.C_CCONTAINER);
desc = new CElementImageDescriptor(desc, 0, CElementImageProvider.SMALL_SIZE);
return CUIPlugin.getImageDescriptorRegistry().get(desc);
}
return super.getImage(element);
}
}
|