1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.resources.mapping.ResourceMapping; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.team.internal.ccvs.core.*; 17 import org.eclipse.team.internal.ccvs.core.client.Command; 18 import org.eclipse.team.internal.ccvs.core.client.Session; 19 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 20 import org.eclipse.team.internal.ccvs.ui.Policy; 21 import org.eclipse.ui.IWorkbenchPart; 22 23 public abstract class SingleCommandOperation extends RepositoryProviderOperation { 24 25 private LocalOption[] options = Command.NO_LOCAL_OPTIONS; 26 27 public SingleCommandOperation(IWorkbenchPart part, ResourceMapping[] mappings, LocalOption[] options) { 28 super(part, mappings); 29 if (options != null) { 30 this.options = options; 31 } 32 } 33 34 37 protected void execute(CVSTeamProvider provider, IResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException { 38 monitor.beginTask(null, 100); 39 Session session = new Session(getRemoteLocation(provider), getLocalRoot(provider), true ); 40 session.open(Policy.subMonitorFor(monitor, 10), isServerModificationOperation()); 41 try { 42 IStatus status = executeCommand(session, provider, getCVSArguments(session, resources), recurse, Policy.subMonitorFor(monitor, 90)); 43 if (isReportableError(status)) { 44 throw new CVSException(status); 45 } 46 } finally { 47 session.close(); 48 } 49 } 50 51 protected final ICVSResource[] getCVSArguments(IResource[] resources) { 52 return super.getCVSArguments(resources); 53 } 54 55 protected ICVSResource[] getCVSArguments(Session session, IResource[] resources) { 56 return getCVSArguments(resources); 57 } 58 59 62 protected void execute(CVSTeamProvider provider, ICVSTraversal entry, IProgressMonitor monitor) throws CVSException, InterruptedException { 63 try { 64 super.execute(provider, entry, monitor); 67 collectStatus(Status.OK_STATUS); 68 } catch (CVSException e) { 69 collectStatus(e.getStatus()); 70 } 71 } 72 77 protected boolean isServerModificationOperation() { 78 return false; 79 } 80 81 89 protected abstract IStatus executeCommand(Session session, CVSTeamProvider provider, ICVSResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException ; 90 91 protected LocalOption[] getLocalOptions(boolean recurse) { 92 LocalOption[] result = options; 93 if (recurse) { 94 result = Command.DO_NOT_RECURSE.removeFrom(options); 96 } else { 97 result = Command.RECURSE.removeFrom(options); 98 result = Command.DO_NOT_RECURSE.addTo(options); 99 } 100 return result; 101 } 102 103 protected void setLocalOptions(LocalOption[] options) { 104 this.options = options; 105 } 106 107 protected void addLocalOption(LocalOption option) { 108 options = option.addTo(options); 109 } 110 } 111 | Popular Tags |