KickJava   Java API By Example, From Geeks To Geeks.

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


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 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     /* (non-Javadoc)
35      * @see org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation#execute(org.eclipse.team.internal.ccvs.core.CVSTeamProvider, org.eclipse.core.resources.IResource[], org.eclipse.core.runtime.IProgressMonitor)
36      */

37     protected void execute(CVSTeamProvider provider, IResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException JavaDoc {
38         monitor.beginTask(null, 100);
39         Session session = new Session(getRemoteLocation(provider), getLocalRoot(provider), true /* output to console */);
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     /* (non-Javadoc)
60      * @see org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation#execute(org.eclipse.team.internal.ccvs.core.CVSTeamProvider, org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation.ICVSTraversal, org.eclipse.core.runtime.IProgressMonitor)
61      */

62     protected void execute(CVSTeamProvider provider, ICVSTraversal entry, IProgressMonitor monitor) throws CVSException, InterruptedException JavaDoc {
63         try {
64             // TODO: This does not properly count the number of operations
65
// Changing it causes an error in the test cases
66
super.execute(provider, entry, monitor);
67             collectStatus(Status.OK_STATUS);
68         } catch (CVSException e) {
69             collectStatus(e.getStatus());
70         }
71     }
72     /**
73      * Indicate whether the operation requires write access to the server (i.e.
74      * the operation changes state on the server whether it be to commit, tag, admin, etc).
75      * @return
76      */

77     protected boolean isServerModificationOperation() {
78         return false;
79     }
80
81     /**
82      * Method overridden by subclasses to issue the command to the CVS repository using the given session.
83      * @param session an open session which will be closed by the caller
84      * @param provider the provider for the project that contains the resources
85      * @param resources the resources to be operated on
86      * @param recurse whether the operation is deep or shallow
87      * @param monitor a progress monitor
88      */

89     protected abstract IStatus executeCommand(Session session, CVSTeamProvider provider, ICVSResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException JavaDoc;
90
91     protected LocalOption[] getLocalOptions(boolean recurse) {
92         LocalOption[] result = options;
93         if (recurse) {
94             // For deep operations, we just need to make sure that the -l option isn't present
95
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