| /******************************************************************************* |
| * Copyright (c) 2000, 2003 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.team.internal.ccvs.ui.actions; |
| |
| 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.TeamException; |
| import org.eclipse.team.internal.ccvs.core.CVSTeamProvider; |
| import org.eclipse.team.internal.ccvs.core.client.Command; |
| import org.eclipse.team.internal.ccvs.ui.Policy; |
| 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 WorkspaceAction { |
| /* |
| * @see IActionDelegate#run(IAction) |
| */ |
| public void execute(IAction action) throws InterruptedException, InvocationTargetException { |
| 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(); |
| } |
| } |
| }, true /* cancelable */, PROGRESS_DIALOG); |
| |
| } |
| |
| /** |
| * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle() |
| */ |
| protected String getErrorTitle() { |
| return Policy.bind("UpdateAction.update"); //$NON-NLS-1$ |
| } |
| |
| /** |
| * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForAddedResources() |
| */ |
| protected boolean isEnabledForAddedResources() { |
| return false; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForNonExistantResources() |
| */ |
| protected boolean isEnabledForNonExistantResources() { |
| return true; |
| } |
| |
| } |