• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.adt.internal.project;
18 
19 import com.android.ide.eclipse.adt.AdtPlugin;
20 import com.android.ide.eclipse.adt.AndroidConstants;
21 import com.android.ide.eclipse.adt.internal.sdk.Sdk;
22 import com.android.sdklib.SdkConstants;
23 
24 import org.eclipse.core.resources.IFolder;
25 import org.eclipse.core.resources.IProject;
26 import org.eclipse.core.resources.IResource;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.jface.resource.ImageDescriptor;
29 import org.eclipse.jface.viewers.IDecoration;
30 import org.eclipse.jface.viewers.ILabelDecorator;
31 import org.eclipse.jface.viewers.ILabelProviderListener;
32 import org.eclipse.jface.viewers.ILightweightLabelDecorator;
33 
34 /**
35  * A {@link ILabelDecorator} associated with an org.eclipse.ui.decorators extension.
36  * This is used to add android icons in some special folders in the package explorer.
37  */
38 public class FolderDecorator implements ILightweightLabelDecorator {
39 
40     private ImageDescriptor mDescriptor;
41 
FolderDecorator()42     public FolderDecorator() {
43         mDescriptor = AdtPlugin.getImageDescriptor("/icons/android_project.png"); //$NON-NLS-1$
44     }
45 
decorate(Object element, IDecoration decoration)46     public void decorate(Object element, IDecoration decoration) {
47         if (element instanceof IFolder) {
48             IFolder folder = (IFolder)element;
49 
50             // get the project and make sure this is an android project
51             IProject project = folder.getProject();
52 
53             try {
54                 if (project.hasNature(AndroidConstants.NATURE_DEFAULT)) {
55                     // check the folder is directly under the project.
56                     if (folder.getParent().getType() == IResource.PROJECT) {
57                         String name = folder.getName();
58                         if (name.equals(SdkConstants.FD_ASSETS)) {
59                             doDecoration(decoration, null);
60                         } else if (name.equals(SdkConstants.FD_RESOURCES)) {
61                             doDecoration(decoration, null);
62                         } else if (name.equals(SdkConstants.FD_GEN_SOURCES)) {
63                             doDecoration(decoration, " [Generated Java Files]");
64                         } else if (name.equals(SdkConstants.FD_NATIVE_LIBS)) {
65                             doDecoration(decoration, null);
66                         } else if (folder.isLinked() && Sdk.CREATOR_ADT.equals(
67                                 ProjectHelper.loadStringProperty(folder, Sdk.PROP_CREATOR))) {
68                             doDecoration(decoration, " [Android Library]");
69                         }
70                     }
71                 }
72             } catch (CoreException e) {
73                 // log the error
74                 AdtPlugin.log(e, "Unable to get nature of project '%s'.", project.getName());
75             }
76         }
77     }
78 
doDecoration(IDecoration decoration, String suffix)79     public void doDecoration(IDecoration decoration, String suffix) {
80         decoration.addOverlay(mDescriptor, IDecoration.TOP_LEFT);
81 
82         if (suffix != null) {
83             decoration.addSuffix(suffix);
84         }
85     }
86 
isLabelProperty(Object element, String property)87     public boolean isLabelProperty(Object element, String property) {
88         // Property change do not affect the label
89         return false;
90     }
91 
addListener(ILabelProviderListener listener)92     public void addListener(ILabelProviderListener listener) {
93         // No state change will affect the rendering.
94     }
95 
removeListener(ILabelProviderListener listener)96     public void removeListener(ILabelProviderListener listener) {
97         // No state change will affect the rendering.
98     }
99 
dispose()100     public void dispose() {
101         // nothing to dispose
102     }
103 }
104