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

ResourceMonitor

public class ResourceMonitor extends Object implements org.eclipse.core.resources.IResourceChangeListener
Resource Monitor for the whole editor plugin. Other, more simple, listeners can register to that one.

Fields Summary
private static final ResourceMonitor
sThis
private final ArrayList
mFileListeners
private final ArrayList
mFolderListeners
private final ArrayList
mProjectListeners
private final ArrayList
mEventListeners
private org.eclipse.core.resources.IWorkspace
mWorkspace
Constructors Summary
Methods Summary
public synchronized voidaddFileListener(com.android.ide.eclipse.editors.resources.manager.ResourceMonitor$IFileListener listener, int kindMask)
Adds a file listener.

param
listener The listener to receive the events.
param
kindMask The event mask to filter out specific events. {@link ListenerBundle#MASK_NONE} will forward all events.

        FileListenerBundle bundle = new FileListenerBundle();
        bundle.listener = listener;
        bundle.kindMask = kindMask;
        
        mFileListeners.add(bundle);
    
public synchronized voidaddFolderListener(com.android.ide.eclipse.editors.resources.manager.ResourceMonitor$IFolderListener listener, int kindMask)
Adds a folder listener.

param
listener The listener to receive the events.
param
kindMask The event mask to filter out specific events. {@link ListenerBundle#MASK_NONE} will forward all events.

        FolderListenerBundle bundle = new FolderListenerBundle();
        bundle.listener = listener;
        bundle.kindMask = kindMask;
        
        mFolderListeners.add(bundle);
    
public synchronized voidaddProjectListener(com.android.ide.eclipse.editors.resources.manager.ResourceMonitor$IProjectListener listener)
Adds a project listener.

param
listener The listener to receive the events.

        mProjectListeners.add(listener);
        
        // we need to look at the opened projects and give them to the listener.

        // get the list of opened android projects.
        IWorkspaceRoot workspaceRoot = mWorkspace.getRoot();
        IJavaModel javaModel = JavaCore.create(workspaceRoot);
        IJavaProject[] androidProjects = BaseProjectHelper.getAndroidProjects(javaModel);

        for (IJavaProject androidProject : androidProjects) {
            listener.projectOpenedWithWorkspace(androidProject.getProject());
        }
    
public synchronized voidaddResourceEventListener(com.android.ide.eclipse.editors.resources.manager.ResourceMonitor$IResourceEventListener listener)
Adds a resource event listener.

param
listener The listener to receive the events.

        mEventListeners.add(listener);
    
public static com.android.ide.eclipse.editors.resources.manager.ResourceMonitorgetMonitor()

        return sThis;
    
public synchronized voidremoveFileListener(com.android.ide.eclipse.editors.resources.manager.ResourceMonitor$IFileListener listener)
Removes an existing file listener.

param
listener the listener to remove.

        for (int i = 0 ; i < mFileListeners.size() ; i++) {
            FileListenerBundle bundle = mFileListeners.get(i);
            if (bundle.listener == listener) {
                mFileListeners.remove(i);
                return;
            }
        }
    
public synchronized voidremoveFolderListener(com.android.ide.eclipse.editors.resources.manager.ResourceMonitor$IFolderListener listener)
Removes an existing folder listener.

param
listener the listener to remove.

        for (int i = 0 ; i < mFolderListeners.size() ; i++) {
            FolderListenerBundle bundle = mFolderListeners.get(i);
            if (bundle.listener == listener) {
                mFolderListeners.remove(i);
                return;
            }
        }
    
public synchronized voidremoveProjectListener(com.android.ide.eclipse.editors.resources.manager.ResourceMonitor$IProjectListener listener)
Removes an existing project listener.

param
listener the listener to remove.

        mProjectListeners.remove(listener);
    
public synchronized voidremoveResourceEventListener(com.android.ide.eclipse.editors.resources.manager.ResourceMonitor$IResourceEventListener listener)
Removes an existing Resource Event listener.

param
listener the listener to remove.

        mEventListeners.remove(listener);
    
public voidresourceChanged(org.eclipse.core.resources.IResourceChangeEvent event)
Processes the workspace resource change events.

        // notify the event listeners of a start.
        for (IResourceEventListener listener : mEventListeners) {
            listener.resourceChangeEventStart();
        }
        
        if (event.getType() == IResourceChangeEvent.PRE_DELETE) {
            // a project is being deleted. Lets get the project object and remove
            // its compiled resource list.
            IResource r = event.getResource();
            IProject project = r.getProject();

            // notify the listeners.
            for (IProjectListener pl : mProjectListeners) {
                pl.projectDeleted(project);
            }
        } else {
            // this a regular resource change. We get the delta and go through it with a visitor.
            IResourceDelta delta = event.getDelta();
            
            DeltaVisitor visitor = new DeltaVisitor();
            try {
                delta.accept(visitor);
            } catch (CoreException e) {
            }
        }

        // we're done, notify the event listeners.
        for (IResourceEventListener listener : mEventListeners) {
            listener.resourceChangeEventEnd();
        }
    
public static com.android.ide.eclipse.editors.resources.manager.ResourceMonitorstartMonitoring(org.eclipse.core.resources.IWorkspace ws)
Starts the resource monitoring.

param
ws The current workspace.
return
The monitor object.

        if (sThis != null) {
            ws.addResourceChangeListener(sThis,
                    IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE);
            sThis.mWorkspace = ws;
        }
        return sThis;
    
public static voidstopMonitoring(org.eclipse.core.resources.IWorkspace ws)
Stops the resource monitoring.

param
ws The current workspace.

        if (sThis != null) {
            ws.removeResourceChangeListener(sThis);
            
            sThis.mFileListeners.clear();
            sThis.mProjectListeners.clear();
        }