FileDocCategorySizeDatePackage
ResourceFolder.javaAPI DocAndroid 1.5 API8303Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.resources.manager

ResourceFolder

public final class ResourceFolder extends Resource
Resource Folder class. Contains list of {@link ResourceFile}s, the {@link FolderConfiguration}, and a link to the workspace {@link IFolder} object.

Fields Summary
ResourceFolderType
mType
com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration
mConfiguration
com.android.ide.eclipse.editors.resources.manager.files.IAbstractFolder
mFolder
ArrayList
mFiles
private final boolean
mIsFramework
Constructors Summary
public ResourceFolder(ResourceFolderType type, com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration config, com.android.ide.eclipse.editors.resources.manager.files.IAbstractFolder folder, boolean isFrameworkRepository)
Creates a new {@link ResourceFolder}

param
type The type of the folder
param
config The configuration of the folder
param
folder The associated {@link IAbstractFolder} object.
param
isFrameworkRepository

    
                                      
        
                
        mType = type;
        mConfiguration = config;
        mFolder = folder;
        mIsFramework = isFrameworkRepository;
    
Methods Summary
public voidaddFile(ResourceFile file)
Adds a {@link ResourceFile} to the folder.

param
file The {@link ResourceFile}.

        if (mFiles == null) {
            mFiles = new ArrayList<ResourceFile>();
        }

        mFiles.add(file);
    
public com.android.ide.eclipse.editors.resources.configurations.FolderConfigurationgetConfiguration()

        return mConfiguration;
    
public ResourceFilegetFile(com.android.ide.eclipse.editors.resources.manager.files.IAbstractFile file)
Returns the {@link ResourceFile} matching a {@link IAbstractFile} object.

param
file The {@link IFile} object.
return
the {@link ResourceFile} or null if no match was found.

        if (mFiles != null) {
            for (ResourceFile f : mFiles) {
                if (f.getFile().equals(file)) {
                    return f;
                }
            }
        }
        return null;
    
public ResourceFilegetFile(org.eclipse.core.resources.IFile file)
Returns the {@link ResourceFile} matching a {@link IFile} object.

param
file The {@link IFile} object.
return
the {@link ResourceFile} or null if no match was found.

        if (mFiles != null) {
            for (ResourceFile f : mFiles) {
                IFile iFile = f.getFile().getIFile();
                if (iFile != null && iFile.equals(file)) {
                    return f;
                }
            }
        }
        return null;
    
public ResourceFilegetFile(java.lang.String filename)
Returns the {@link ResourceFile} matching a given name.

param
filename The name of the file to return.
return
the {@link ResourceFile} or null if no match was found.

        if (mFiles != null) {
            for (ResourceFile f : mFiles) {
                if (f.getFile().getName().equals(filename)) {
                    return f;
                }
            }
        }
        return null;
    
public com.android.ide.eclipse.editors.resources.manager.files.IAbstractFoldergetFolder()
Returns the {@link IFolder} associated with this object.

        return mFolder;
    
public java.util.CollectiongetResourceTypes()
Returns the list of {@link ResourceType}s generated by the files inside this folder.

        ArrayList<ResourceType> list = new ArrayList<ResourceType>();

        if (mFiles != null) {
            for (ResourceFile file : mFiles) {
                ResourceType[] types = file.getResourceTypes();
                
                // loop through those and add them to the main list,
                // if they are not already present
                if (types != null) {
                    for (ResourceType resType : types) {
                        if (list.indexOf(resType) == -1) {
                            list.add(resType);
                        }
                    }
                }
            }
        }
        
        return list;
    
public java.util.CollectiongetResources(com.android.ide.eclipse.common.resources.ResourceType type, ProjectResources projectResources)
Get the list of {@link ResourceItem} of a specific type generated by all the files in the folder. This method must make sure not to create duplicates.

param
type The type of {@link ResourceItem} to return.
param
projectResources The global Project Resource object, allowing the implementation to query for already existing {@link ResourceItem}
return
The list of new {@link ResourceItem}
see
ProjectResources#findResourceItem(ResourceType, String)

        Collection<ProjectResourceItem> list = new ArrayList<ProjectResourceItem>();
        if (mFiles != null) {
            for (ResourceFile f : mFiles) {
                list.addAll(f.getResources(type, projectResources));
            }
        }
        return list;
    
public ResourceFolderTypegetType()
Returns the {@link ResourceFolderType} of this object.

        return mType;
    
public booleanhasFile(java.lang.String name)
Returns whether the folder contains a file with the given name.

param
name the name of the file.

        return mFolder.hasFile(name);
    
public booleanhasResources(com.android.ide.eclipse.common.resources.ResourceType type)
Returns whether a file in the folder is generating a resource of a specified type.

param
type The {@link ResourceType} being looked up.

        // Check if the folder type is able to generate resource of the type that was asked.
        // this is a first check to avoid going through the files.
        ResourceFolderType[] folderTypes = FolderTypeRelationship.getRelatedFolders(type);
        
        boolean valid = false;
        for (ResourceFolderType rft : folderTypes) {
            if (rft == mType) {
                valid = true;
                break;
            }
        }
        
        if (valid) {
            if (mFiles != null) {
                for (ResourceFile f : mFiles) {
                    if (f.hasResources(type)) {
                        return true;
                    }
                }
            }
        }
        return false;
    
public booleanisFramework()
Returns whether the folder is a framework resource folder.

        return mIsFramework;
    
public voidremoveFile(org.eclipse.core.resources.IFile file)
Attempts to remove the {@link ResourceFile} associated with a specified {@link IFile}.

param
file the IFile object.

        if (mFiles != null) {
            int count = mFiles.size();
            for (int i = 0 ; i < count ; i++) {
                ResourceFile resFile = mFiles.get(i);
                if (resFile != null) {
                    IFile iFile = resFile.getFile().getIFile();
                    if (iFile != null && iFile.equals(file)) {
                        mFiles.remove(i);
                        touch();
                    }
                }
            }
        }