/*******************************************************************************
 * Copyright (c) 2004, 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 java.io.File;

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.client.OperationProgressNotifyListener;
import org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.SVNClientException;
import org.tigris.subversion.svnclientadapter.SVNRevision;

/**
 * Update the given resources in the given project to the given revision
 * 
 * @author Cedric Chabanois (cchab at tigris.org)
 */
public class UpdateResourcesCommand implements ISVNCommand {
    private SVNWorkspaceRoot root;
    private IResource[] resources;
    private SVNRevision revision;
    private boolean recursive;    
    
    /**
     * Update the given resources.
     * BEWARE ! The resource array has to be sorted properly, so parent folder (incoming additions) are updated sooner than their children.
     * BEWARE ! For incoming deletions, it has to be opposite. 
     * WATCH OUT ! These two statements mean that you CANNOT have both additions and deletions within the same call !!!
     * When doing recursive call, it's obviously not an issue ... 
     * @param root
     * @param resources
     * @param revision
     * @param recursive
     */
    public UpdateResourcesCommand(SVNWorkspaceRoot root, IResource[] resources, SVNRevision revision, boolean recursive) {
        this.root = root;
        this.resources = resources;
        this.revision = revision;
        this.recursive = recursive;
    }
    
	/* (non-Javadoc)
	 * @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public void run(final IProgressMonitor monitor) throws SVNException {
        try {
            monitor.beginTask(null, 100 * resources.length);                    
            ISVNClientAdapter svnClient = root.getRepository().getSVNClient();

            OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor));
    		if (resources.length == 1)
    		{
                monitor.subTask(resources[0].getName());
                svnClient.update(resources[0].getLocation().toFile(),revision, recursive);
                monitor.worked(100);    			
    		}
    		else
    		{
    			File[] files = new File[resources.length];
    			for (int i = 0; i < resources.length; i++) {
					files[i] = resources[i].getLocation().toFile();
				}
   				svnClient.update(files, revision, recursive, false);
   				monitor.worked(100);
    		}
        } catch (SVNClientException e) {
            throw SVNException.wrapException(e);
        } finally {
            OperationManager.getInstance().endOperation();
            monitor.done();
        }        
	}
    
    
}

@@ -721,16 +721,79 @@
 onitor;%0A
+import org.tigris.subversion.subclipse.core.ISVNCoreConstants;%0A
 import o
@@ -1561,43 +1561,145 @@
 ion;
-%0A    private boolean recursive;    
+ %0A    private int depth = ISVNCoreConstants.DEPTH_UNKNOWN;%0A    private boolean ignoreExternals = false;%0A    private boolean force = true;
 %0A   
@@ -2204,32 +2204,8 @@
 ion%0A
-     * @param recursive%0A
     
@@ -2312,27 +2312,8 @@
 sion
-, boolean recursive
 ) %7B%0A
@@ -2412,44 +2412,8 @@
 on;%0A
-        this.recursive = recursive;%0A
     
@@ -3095,24 +3095,44 @@
 vision, 
-recursiv
+depth, ignoreExternals, forc
 e);%0A    
@@ -3404,23 +3404,36 @@
 on, 
-recursive, fals
+depth, ignoreExternals, forc
 e);%0A
@@ -3686,16 +3686,246 @@
     %0A%09%7D%0A
+%0A%09public void setDepth(int depth) %7B%0A%09%09this.depth = depth;%0A%09%7D%0A%0A%09public void setIgnoreExternals(boolean ignoreExternals) %7B%0A%09%09this.ignoreExternals = ignoreExternals;%0A%09%7D%0A%0A%09public void setForce(boolean force) %7B%0A%09%09this.force = force;%0A%09%7D
     %0A   

Update dialog exposing revision, ignore externals, force, depth (not done in Sync view yet). Issue #: 637