KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > operations > TagInRepositoryOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.operations;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Set JavaDoc;
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 JavaDoc localOptions = new HashSet JavaDoc();
31     private CVSTag tag;
32
33     public TagInRepositoryOperation(IWorkbenchPart part, ICVSRemoteResource[] remoteResource) {
34         super(part, remoteResource);
35     }
36
37     /* (non-Javadoc)
38      * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
39      */

40     public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException JavaDoc {
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 JavaDoc e) {
51                 throw CVSException.wrapException(e);
52             }
53         }
54     }
55
56     /**
57      * Override to dislay the number of tag operations that succeeded
58      */

59     protected String JavaDoc 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 JavaDoc[] { 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     /* (non-Javadoc)
72      * @see org.eclipse.team.internal.ccvs.ui.operations.ITagOperation#getTag()
73      */

74     public CVSTag getTag() {
75         return tag;
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.team.internal.ccvs.ui.operations.ITagOperation#setTag(org.eclipse.team.internal.ccvs.core.CVSTag)
80      */

81     public void setTag(CVSTag tag) {
82         this.tag = tag;
83     }
84
85     /* (non-Javadoc)
86      * @see org.eclipse.team.internal.ccvs.ui.operations.ITagOperation#addLocalOption(org.eclipse.team.internal.ccvs.core.client.Command.LocalOption)
87      */

88     public void addLocalOption(LocalOption option) {
89         localOptions.add(option);
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.team.internal.ccvs.ui.operations.ITagOperation#moveTag()
94      */

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     /* (non-Javadoc)
104      * @see org.eclipse.team.internal.ccvs.ui.operations.ITagOperation#recurse()
105      */

106     public void doNotRecurse() {
107         addLocalOption(Command.DO_NOT_RECURSE);
108     }
109
110     protected String JavaDoc getTaskName() {
111         return CVSUIMessages.TagFromRepository_taskName;
112     }
113
114     /* (non-Javadoc)
115      * @see org.eclipse.team.internal.ccvs.ui.operations.ITagOperation#getTagSource()
116      */

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     /* (non-Javadoc)
127      * @see org.eclipse.team.internal.ccvs.ui.operations.ITagOperation#isEmpty()
128      */

129     public boolean isEmpty() {
130         return getCVSResources().length == 0;
131     }
132 }
133
Popular Tags