1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.HashSet ; 15 import java.util.Set ; 16 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.client.Command; 21 import org.eclipse.team.internal.ccvs.core.client.RTag; 22 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 23 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 24 import org.eclipse.team.internal.ccvs.ui.actions.TagAction; 25 import org.eclipse.team.internal.ccvs.ui.tags.TagSource; 26 import org.eclipse.ui.IWorkbenchPart; 27 28 public class TagInRepositoryOperation extends RemoteOperation implements ITagOperation { 29 30 private Set localOptions = new HashSet (); 31 private CVSTag tag; 32 33 public TagInRepositoryOperation(IWorkbenchPart part, ICVSRemoteResource[] remoteResource) { 34 super(part, remoteResource); 35 } 36 37 40 public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { 41 ICVSRemoteResource[] resources = getRemoteResources(); 42 monitor.beginTask(null, 1000 * resources.length); 43 for (int i = 0; i < resources.length; i++) { 44 IStatus status = resources[i].tag(getTag(), getLocalOptions(), new SubProgressMonitor(monitor, 1000)); 45 collectStatus(status); 46 } 47 if (!errorsOccurred()) { 48 try { 49 TagAction.broadcastTagChange(getCVSResources(), getTag()); 50 } catch (InvocationTargetException e) { 51 throw CVSException.wrapException(e); 52 } 53 } 54 } 55 56 59 protected String getErrorMessage(IStatus[] problems, int operationCount) { 60 if(operationCount == 1) { 61 return CVSUIMessages.TagInRepositoryAction_tagProblemsMessage; 62 } else { 63 return NLS.bind(CVSUIMessages.TagInRepositoryAction_tagProblemsMessageMultiple, new String [] { Integer.toString(operationCount - problems.length), Integer.toString(problems.length) }); 64 } 65 } 66 67 private LocalOption[] getLocalOptions() { 68 return (LocalOption[]) localOptions.toArray(new LocalOption[localOptions.size()]); 69 } 70 71 74 public CVSTag getTag() { 75 return tag; 76 } 77 78 81 public void setTag(CVSTag tag) { 82 this.tag = tag; 83 } 84 85 88 public void addLocalOption(LocalOption option) { 89 localOptions.add(option); 90 } 91 92 95 public void moveTag() { 96 addLocalOption(RTag.FORCE_REASSIGNMENT); 97 addLocalOption(RTag.CLEAR_FROM_REMOVED); 98 if (tag != null && tag.getType() == CVSTag.BRANCH) { 99 addLocalOption(RTag.FORCE_BRANCH_REASSIGNMENT); 100 } 101 } 102 103 106 public void doNotRecurse() { 107 addLocalOption(Command.DO_NOT_RECURSE); 108 } 109 110 protected String getTaskName() { 111 return CVSUIMessages.TagFromRepository_taskName; 112 } 113 114 117 public TagSource getTagSource() { 118 return TagSource.create(getCVSResources()); 119 } 120 121 protected boolean isReportableError(IStatus status) { 122 return super.isReportableError(status) 123 || status.getCode() == CVSStatus.TAG_ALREADY_EXISTS; 124 } 125 126 129 public boolean isEmpty() { 130 return getCVSResources().length == 0; 131 } 132 } 133 | Popular Tags |