blob: 648da5d78d7abc053aef8f3c6d2760558509b7b7 [file] [log] [blame]
package org.eclipse.team.internal.ccvs.ui.actions;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.lang.reflect.InvocationTargetException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
import org.eclipse.team.internal.ccvs.core.CVSTeamProvider;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.ICVSResource;
import org.eclipse.team.internal.ccvs.core.client.Command;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ui.actions.TeamAction;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
/**
* UpdateAction performs a 'cvs update' command on the selected resources.
* If conflicts are present (file has been changed both remotely and locally),
* the changes will be merged into the local file such that the user must
* resolve the conflicts. This action is temporary code; it will be removed
* when a functional synchronize view has been implemented.
*/
public class UpdateAction extends CVSAction {
/*
* @see IActionDelegate#run(IAction)
*/
public void execute(IAction action) {
run(new WorkspaceModifyOperation() {
public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
try {
Hashtable table = getProviderMapping();
Set keySet = table.keySet();
monitor.beginTask("", keySet.size() * 1000); //$NON-NLS-1$
monitor.setTaskName(Policy.bind("UpdateAction.updating")); //$NON-NLS-1$
Iterator iterator = keySet.iterator();
while (iterator.hasNext()) {
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1000);
CVSTeamProvider provider = (CVSTeamProvider)iterator.next();
List list = (List)table.get(provider);
IResource[] providerResources = (IResource[])list.toArray(new IResource[list.size()]);
provider.update(providerResources, Command.NO_LOCAL_OPTIONS, null, true /*createBackups*/, subMonitor);
}
} catch (TeamException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
}, Policy.bind("UpdateAction.update"), this.PROGRESS_DIALOG); //$NON-NLS-1$
}
/*
* @see TeamAction#isEnabled()
*/
protected boolean isEnabled() throws TeamException {
IResource[] resources = getSelectedResources();
if (resources.length == 0) return false;
for (int i = 0; i < resources.length; i++) {
IResource resource = resources[i];
RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId());
if (provider == null) return false;
ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
ResourceSyncInfo info = cvsResource.getSyncInfo();
if(cvsResource.isFolder()) {
if(!((ICVSFolder)cvsResource).isCVSFolder()) return false;
} else {
if (!cvsResource.isManaged() || info.isAdded()) return false;
}
}
return true;
}
}