| package org.eclipse.team.internal.ccvs.ui.actions; |
| |
| /* |
| * (c) Copyright IBM Corp. 2000, 2001. |
| * All Rights Reserved. |
| */ |
| |
| import java.lang.reflect.InvocationTargetException; |
| |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| 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.ICVSResource; |
| import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; |
| import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; |
| import org.eclipse.team.internal.ccvs.ui.Policy; |
| import org.eclipse.team.internal.ccvs.ui.RepositoryManager; |
| import org.eclipse.team.internal.ui.actions.TeamAction; |
| import org.eclipse.ui.actions.WorkspaceModifyOperation; |
| |
| /** |
| * Action for checking in files to a CVS provider. |
| * Prompts the user for a release comment. |
| */ |
| public class CommitAction extends CVSAction { |
| /* |
| * @see IActionDelegate#run(IAction) |
| */ |
| public void execute(IAction action) { |
| run(new WorkspaceModifyOperation() { |
| public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException { |
| try { |
| RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager(); |
| String comment = promptForComment(manager); |
| if (comment != null) { |
| manager.commit(getSelectedResources(), comment, monitor); |
| } |
| } catch (TeamException e) { |
| throw new InvocationTargetException(e); |
| } |
| } |
| }, Policy.bind("CommitAction.commitFailed"), 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); |
| if (resource.getType()!=IResource.PROJECT&&!cvsResource.isManaged()) return false; |
| } |
| return true; |
| } |
| |
| /** |
| * Prompts the user for a release comment. |
| * @return the comment, or null to cancel |
| */ |
| protected String promptForComment(RepositoryManager manager) { |
| return manager.promptForComment(getShell()); |
| } |
| } |