1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.Arrays ; 15 import java.util.HashSet ; 16 import java.util.Set ; 17 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.resources.mapping.ResourceMapping; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.core.runtime.IStatus; 23 import org.eclipse.osgi.util.NLS; 24 import org.eclipse.team.internal.ccvs.core.*; 25 import org.eclipse.team.internal.ccvs.core.client.*; 26 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 27 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 28 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 29 import org.eclipse.team.internal.ccvs.ui.Policy; 30 import org.eclipse.team.internal.ccvs.ui.actions.TagAction; 31 import org.eclipse.team.internal.ccvs.ui.tags.TagSource; 32 import org.eclipse.ui.IWorkbenchPart; 33 34 public class TagOperation extends RepositoryProviderOperation implements ITagOperation { 35 36 private Set localOptions = new HashSet (); 37 private CVSTag tag; 38 39 public TagOperation(IWorkbenchPart part, ResourceMapping[] mappers) { 40 super(part, mappers); 41 } 42 43 public CVSTag getTag() { 44 return tag; 45 } 46 47 public void setTag(CVSTag tag) { 48 this.tag = tag; 49 } 50 51 54 protected void execute(CVSTeamProvider provider, IResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException { 55 IStatus status = tag(provider, resources, recurse, monitor); 56 collectStatus(status); 57 } 58 59 62 protected String getErrorMessage(IStatus[] problems, int operationCount) { 63 if(operationCount == 1) { 65 return CVSUIMessages.TagAction_tagProblemsMessage; 66 } else { 67 return NLS.bind(CVSUIMessages.TagAction_tagProblemsMessageMultiple, new String [] { Integer.toString(operationCount - problems.length), Integer.toString(problems.length) }); 68 } 69 } 70 71 82 public IStatus tag(CVSTeamProvider provider, IResource[] resources, boolean recurse, IProgressMonitor progress) throws CVSException { 83 84 LocalOption[] commandOptions = (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]); 85 if (recurse) { 86 commandOptions = Command.DO_NOT_RECURSE.removeFrom(commandOptions); 87 } else { 88 commandOptions = Command.RECURSE.removeFrom(commandOptions); 89 commandOptions = Command.DO_NOT_RECURSE.addTo(commandOptions); 90 } 91 92 String [] arguments = getStringArguments(resources); 94 95 CVSWorkspaceRoot root = provider.getCVSWorkspaceRoot(); 97 Session s = new Session(root.getRemoteLocation(), root.getLocalRoot()); 98 progress.beginTask(null, 100); 99 try { 100 s.open(Policy.subMonitorFor(progress, 20), true ); 102 return Command.TAG.execute(s, 103 Command.NO_GLOBAL_OPTIONS, 104 commandOptions, 105 tag, 106 arguments, 107 null, 108 Policy.subMonitorFor(progress, 80)); 109 } finally { 110 s.close(); 111 progress.done(); 112 } 113 } 114 115 public void addLocalOption(LocalOption option) { 116 localOptions.add(option); 117 } 118 119 122 public void moveTag() { 123 addLocalOption(Tag.FORCE_REASSIGNMENT); 124 } 125 126 129 public void doNotRecurse() { 130 addLocalOption(Command.DO_NOT_RECURSE); 131 } 132 133 protected String getTaskName() { 134 return CVSUIMessages.TagFromWorkspace_taskName; 135 } 136 137 140 protected String getTaskName(CVSTeamProvider provider) { 141 return NLS.bind(CVSUIMessages.TagOperation_0, new String [] { provider.getProject().getName() }); 142 } 143 144 147 public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { 148 super.execute(monitor); 149 if (!errorsOccurred()) { 150 try { 151 TagAction.broadcastTagChange(getCVSResources(), getTag()); 152 } catch (InvocationTargetException e) { 153 throw CVSException.wrapException(e); 154 } 155 } 156 } 157 158 private ICVSResource[] getCVSResources() { 159 IResource[] resources = getTraversalRoots(); 160 ICVSResource[] cvsResources = new ICVSResource[resources.length]; 161 for (int i = 0; i < resources.length; i++) { 162 cvsResources[i] = CVSWorkspaceRoot.getCVSResourceFor(resources[i]); 163 } 164 return cvsResources; 165 } 166 167 170 public TagSource getTagSource() { 171 return TagSource.create(getProjects()); 172 } 173 174 private IProject[] getProjects() { 175 ResourceMapping[] mappings = getSelectedMappings(); 176 Set projects = new HashSet (); 177 for (int i = 0; i < mappings.length; i++) { 178 ResourceMapping mapping = mappings[i]; 179 projects.addAll(Arrays.asList(mapping.getProjects())); 180 } 181 return (IProject[]) projects.toArray(new IProject[projects.size()]); 182 } 183 184 protected boolean isReportableError(IStatus status) { 185 return super.isReportableError(status) 186 || status.getCode() == CVSStatus.TAG_ALREADY_EXISTS; 187 } 188 189 192 public boolean isEmpty() { 193 return getSelectedMappings().length == 0; 194 } 195 } 196 | Popular Tags |