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
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.ide.eclipse.adt.internal.project;
import com.android.SdkConstants;
import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
/**
* A {@link ILabelDecorator} associated with an org.eclipse.ui.decorators extension.
* This is used to add android icons in some special folders in the package explorer.
*/
public class FolderDecorator implements ILightweightLabelDecorator {
private ImageDescriptor mDescriptor;
public FolderDecorator() {
mDescriptor = AdtPlugin.getImageDescriptor("/icons/android_project.png"); //$NON-NLS-1$
}
@Override
public void decorate(Object element, IDecoration decoration) {
if (element instanceof IFolder) {
IFolder folder = (IFolder)element;
// get the project and make sure this is an android project
IProject project = folder.getProject();
if (project == null || !project.exists() || !folder.exists()) {
return;
}
try {
if (project.hasNature(AdtConstants.NATURE_DEFAULT)) {
// check the folder is directly under the project.
if (folder.getParent().getType() == IResource.PROJECT) {
String name = folder.getName();
if (name.equals(SdkConstants.FD_ASSETS)) {
doDecoration(decoration, null);
} else if (name.equals(SdkConstants.FD_RESOURCES)) {
doDecoration(decoration, null);
} else if (name.equals(SdkConstants.FD_GEN_SOURCES)) {
doDecoration(decoration, " [Generated Java Files]");
} else if (name.equals(SdkConstants.FD_NATIVE_LIBS)) {
doDecoration(decoration, null);
} else if (name.equals(SdkConstants.FD_OUTPUT)) {
doDecoration(decoration, null);
}
}
}
} catch (CoreException e) {
// log the error
AdtPlugin.log(e, "Unable to get nature of project '%s'.", project.getName());
}
}
}
public void doDecoration(IDecoration decoration, String suffix) {
decoration.addOverlay(mDescriptor, IDecoration.TOP_LEFT);
if (suffix != null) {
decoration.addSuffix(suffix);
}
}
@Override
public boolean isLabelProperty(Object element, String property) {
// Property change do not affect the label
return false;
}
@Override
public void addListener(ILabelProviderListener listener) {
// No state change will affect the rendering.
}
@Override
public void removeListener(ILabelProviderListener listener) {
// No state change will affect the rendering.
}
@Override
public void dispose() {
// nothing to dispose
}
}
|