blob: 3b017e62d754b5867b8c9d822256cc4956caeedc (
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
|
/*****************************************************************************
* Copyright (c) 2011, 2016 Atos Origin Integration, Christian W. Damus, 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:
* Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation
* Christian W. Damus - bug 485220
*
*****************************************************************************/
package org.eclipse.papyrus.infra.onefile.ui.providers;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
import org.eclipse.papyrus.infra.onefile.model.ISubResourceFile;
import org.eclipse.papyrus.infra.ui.util.PapyrusImageUtils;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PlatformUI;
/**
* Label Provider for Papyrus Model Elements
*
* @author tristan.faure@atosorigin.com
*
*/
public class PapyrusLabelProvider implements ILabelProvider {
private ImageRegistry images = new ImageRegistry(JFaceResources.getResources());
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
images.dispose();
}
public boolean isLabelProperty(Object element, String property) {
return true;
}
public void removeListener(ILabelProviderListener listener) {
}
public Image getImage(Object element) {
if (element instanceof IPapyrusFile) {
return PapyrusImageUtils.getDefaultIcon();
}
if (element instanceof ISubResourceFile) {
IFile file = ((ISubResourceFile) element).getFile();
String ext = file.getFileExtension();
Image image = images.get(ext);
if (image == null) {
ImageDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(file.getName());
images.put(ext, desc);
}
return images.get(ext);
}
return null;
}
public String getText(Object element) {
if (element instanceof IPapyrusFile) {
IPapyrusFile papyFile = (IPapyrusFile) element;
return papyFile.getText();
}
if (element instanceof ISubResourceFile) {
return ((ISubResourceFile) element).getText();
}
if (element instanceof IResource) {
return ((IResource) element).getName();
}
return null;
}
}
|