KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.util.ArrayList JavaDoc;
14 import java.util.Arrays JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.resources.mapping.ResourceMapping;
19 import org.eclipse.core.resources.mapping.ResourceMappingContext;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.osgi.util.NLS;
23 import org.eclipse.team.core.subscribers.SubscriberResourceMappingContext;
24 import org.eclipse.team.internal.ccvs.core.*;
25 import org.eclipse.team.internal.ccvs.core.client.Command;
26 import org.eclipse.team.internal.ccvs.core.client.Session;
27 import org.eclipse.team.internal.ccvs.core.client.Update;
28 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
29 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
30 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
31 import org.eclipse.team.internal.ccvs.ui.Policy;
32 import org.eclipse.ui.IWorkbenchPart;
33
34 /**
35  * Operation which performs a CVS update
36  */

37 public class UpdateOperation extends SingleCommandOperation {
38
39     private CVSTag tag;
40     
41     /**
42      * Create an UpdateOperation that will perform on update on the given resources
43      * using the given local option. If a tag is provided, it will be added to the
44      * local options using the appropriate argument (-r or -D). If the tag is <code>null</code>
45      * then the tag will be omitted from the local options and the tags on the local resources
46      * will be used.
47      */

48     public UpdateOperation(IWorkbenchPart part, IResource[] resources, LocalOption[] options, CVSTag tag) {
49         this(part, asResourceMappers(resources), options, tag);
50     }
51
52     /**
53      * Create an UpdateOperation that will perform on update on the given resources
54      * using the given local option. If a tag is provided, it will be added to the
55      * local options using the appropriate argument (-r or -D). If the tag is <code>null</code>
56      * then the tag will be omitted from the local options and the tags on the local resources
57      * will be used.
58      */

59     public UpdateOperation(IWorkbenchPart part, ResourceMapping[] mappings, LocalOption[] options, CVSTag tag) {
60         super(part, mappings, options);
61         this.tag = tag;
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.team.internal.ccvs.ui.operations.SingleCommandOperation#executeCommand(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.CVSTeamProvider, org.eclipse.core.resources.IResource[], org.eclipse.core.runtime.IProgressMonitor)
66      */

67     protected IStatus executeCommand(
68         Session session,
69         CVSTeamProvider provider,
70         ICVSResource[] resources,
71         boolean recurse, IProgressMonitor monitor)
72         throws CVSException, InterruptedException JavaDoc {
73             
74             LocalOption[] commandOptions = getLocalOptions(recurse);
75         
76             monitor.beginTask(null, 100);
77             IStatus execute = getUpdateCommand().execute(
78                 session,
79                 Command.NO_GLOBAL_OPTIONS,
80                 commandOptions,
81                 resources,
82                 getCommandOutputListener(),
83                 Policy.subMonitorFor(monitor, 95));
84             
85             updateWorkspaceSubscriber(provider, resources, recurse, Policy.subMonitorFor(monitor, 5));
86             monitor.done();
87             return execute;
88     }
89
90     protected LocalOption[] getLocalOptions(boolean recurse) {
91         // Build the local options
92
List JavaDoc localOptions = new ArrayList JavaDoc();
93         // Use the appropriate tag options
94
if (tag != null) {
95             localOptions.add(Update.makeTagOption(tag));
96         }
97         // Build the arguments list
98
localOptions.addAll(Arrays.asList(super.getLocalOptions(recurse)));
99         LocalOption[] commandOptions = (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]);
100         return commandOptions;
101     }
102
103     protected Update getUpdateCommand() {
104         return Command.UPDATE;
105     }
106
107     /* (non-Javadoc)
108      * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#getTaskName()
109      */

110     protected String JavaDoc getTaskName() {
111         return CVSUIMessages.UpdateOperation_taskName; //;
112
}
113     
114     /* (non-Javadoc)
115      * @see org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation#getTaskName(org.eclipse.team.internal.ccvs.core.CVSTeamProvider)
116      */

117     protected String JavaDoc getTaskName(CVSTeamProvider provider) {
118         return NLS.bind(CVSUIMessages.UpdateOperation_0, new String JavaDoc[] { provider.getProject().getName() });
119     }
120     
121     /**
122      * Return the listener that is used to process E and M messages.
123      * The default is <code>null</code>.
124      * @return
125      */

126     protected ICommandOutputListener getCommandOutputListener() {
127         return null;
128     }
129     
130     protected boolean isReportableError(IStatus status) {
131         return super.isReportableError(status)
132             || status.getCode() == CVSStatus.UNMEGERED_BINARY_CONFLICT
133             || status.getCode() == CVSStatus.INVALID_LOCAL_RESOURCE_PATH
134             || status.getCode() == CVSStatus.RESPONSE_HANDLING_FAILURE;
135     }
136
137     /* (non-Javadoc)
138      * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#getErrorMessage(org.eclipse.core.runtime.IStatus[], int)
139      */

140     protected String JavaDoc getErrorMessage(IStatus[] failures, int totalOperations) {
141         return CVSUIMessages.UpdateAction_update;
142     }
143     
144     /* (non-Javadoc)
145      * @see org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation#getResourceMappingContext()
146      */

147     protected ResourceMappingContext getResourceMappingContext() {
148         return SubscriberResourceMappingContext.createContext(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber());
149     }
150
151     public CVSTag getTag() {
152         return tag;
153     }
154
155     public void setTag(CVSTag tag) {
156         this.tag = tag;
157     }
158 }
159
Popular Tags