| /******************************************************************************* |
| * 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.ui.target; |
| |
| |
| 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.jface.action.IAction; |
| import org.eclipse.team.core.TeamException; |
| import org.eclipse.team.internal.core.InfiniteSubProgressMonitor; |
| import org.eclipse.team.internal.core.target.TargetManager; |
| import org.eclipse.team.internal.core.target.TargetProvider; |
| import org.eclipse.team.internal.ui.Policy; |
| import org.eclipse.ui.actions.WorkspaceModifyOperation; |
| |
| /** |
| * Action for checking in the selected resources |
| */ |
| public class PutAction extends TargetAction { |
| /* |
| * Method declared on IActionDelegate. |
| */ |
| public void run(IAction action) { |
| run(new WorkspaceModifyOperation() { |
| public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException { |
| try { |
| Hashtable table = getTargetProviderMapping(); |
| Set keySet = table.keySet(); |
| monitor.beginTask("", keySet.size() * 1000); //$NON-NLS-1$ |
| Iterator iterator = keySet.iterator(); |
| while (iterator.hasNext()) { |
| IProgressMonitor subMonitor = new InfiniteSubProgressMonitor(monitor, 1000); |
| TargetProvider provider = (TargetProvider)iterator.next(); |
| monitor.setTaskName(Policy.bind("PutAction.working", provider.getURL().toExternalForm())); //$NON-NLS-1$ |
| List list = (List)table.get(provider); |
| IResource[] providerResources = (IResource[])list.toArray(new IResource[list.size()]); |
| |
| provider.put(providerResources, subMonitor); |
| } |
| } catch (TeamException e) { |
| throw new InvocationTargetException(e); |
| } finally { |
| monitor.done(); |
| } |
| } |
| }, Policy.bind("PutAction.title"), 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]; |
| TargetProvider provider = TargetManager.getProvider(resource.getProject()); |
| if(provider == null) |
| return false; |
| if(! provider.canGet(resource)) |
| return false; //if one can't don't allow for any |
| } |
| return true; |
| } |
| } |