/*******************************************************************************
 * Copyright (c) 2005, 2006 Subclipse project 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:
 *     Subclipse project committers - initial API and implementation
 ******************************************************************************/
package org.tigris.subversion.subclipse.core.commands;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.tigris.subversion.subclipse.core.SVNException;
import org.tigris.subversion.subclipse.core.client.OperationManager;
import org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.SVNClientException;

/**
 * Remove stale transactions and locks from the working copy.  This operation can only be run
 * on folders.
 */
public class CleanupResourcesCommand implements ISVNCommand {

    private final SVNWorkspaceRoot root;
    private final IResource[] resources;

    public CleanupResourcesCommand(SVNWorkspaceRoot root, IResource[] resources) {
        this.root = root;
        this.resources = resources;
        
    }
    
    /* (non-Javadoc)
     * @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
     */
    public void run(IProgressMonitor monitor) throws SVNException {
    	ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
        try {
            monitor.beginTask(null, 100 * resources.length);            
            OperationManager.getInstance().beginOperation(svnClient);           
            for (int i = 0; i < resources.length; i++) {
                svnClient.cleanup(resources[i].getLocation().toFile());
                monitor.worked(100);
            }
        } catch (SVNClientException e) {
            throw SVNException.wrapException(e);
        } finally {
            OperationManager.getInstance().endOperation();
            root.getRepository().returnSVNClient(svnClient);
            monitor.done();
        }
    } 
}

@@ -604,16 +604,71 @@
 mands;%0A%0A
+import java.util.LinkedHashSet;%0Aimport java.util.Set;%0A%0A
 import o
@@ -704,16 +704,16 @@
 source;%0A
-
 import o
@@ -1346,16 +1346,96 @@
 sources;
+%0A    private Set%3CIResource%3E cleanedUpResources = new LinkedHashSet%3CIResource%3E();
 %0A%0A    pu
@@ -2176,16 +2176,70 @@
 ile());%0A
+                cleanedUpResources.add(resources%5Bi%5D);%0A
         
@@ -2391,32 +2391,286 @@
 nally %7B%0A    
-        
+%09%09Set%3CIResource%3E refreshResources = new LinkedHashSet%3CIResource%3E();%0A    %09%09for (IResource resource : cleanedUpResources) %7B%0A    %09%09%09refreshResources.add(resource);%0A    %09%09%09OperationManager.getInstance().onNotify(resource.getLocation().toFile(), null);%0A    %09%09%7D%0A    %09%09
 OperationMan
@@ -2701,16 +2701,38 @@
 eration(
+true, refreshResources
 );%0A     

Refresh local status cache after Cleanup operation