KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > subscriber > WorkspaceUpdateOperation


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.subscriber;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.compare.structuremergeviewer.IDiffElement;
16 import org.eclipse.core.resources.*;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.team.core.TeamException;
20 import org.eclipse.team.core.synchronize.SyncInfo;
21 import org.eclipse.team.core.synchronize.SyncInfoSet;
22 import org.eclipse.team.internal.ccvs.core.CVSException;
23 import org.eclipse.team.internal.ccvs.core.client.Command;
24 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
25 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
26 import org.eclipse.team.internal.ccvs.ui.Policy;
27 import org.eclipse.team.internal.ccvs.ui.operations.ReplaceOperation;
28 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
29
30 /**
31  * This action performs an update for the CVSWorkspaceSubscriber.
32  */

33 public class WorkspaceUpdateOperation extends SafeUpdateOperation {
34
35     protected WorkspaceUpdateOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements, boolean promptBeforeUpdate) {
36         super(configuration, elements, promptBeforeUpdate);
37     }
38
39     /* (non-Javadoc)
40      * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#runUpdateDeletions(org.eclipse.team.core.synchronize.SyncInfo[], org.eclipse.core.runtime.IProgressMonitor)
41      */

42     protected void runUpdateDeletions(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
43         monitor.beginTask(null, nodes.length * 100);
44         for (int i = 0; i < nodes.length; i++) {
45             SyncInfo node = nodes[i];
46             unmanage(node, Policy.subMonitorFor(monitor, 50));
47             deleteAndKeepHistory(node.getLocal(), Policy.subMonitorFor(monitor, 50));
48         }
49         pruneEmptyParents(nodes);
50         monitor.done();
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#runSafeUpdate(org.eclipse.team.core.synchronize.SyncInfo[], org.eclipse.core.runtime.IProgressMonitor)
55      */

56     protected void runSafeUpdate(IProject project, SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
57         safeUpdate(project, getIResourcesFrom(nodes), new LocalOption[] { Command.DO_NOT_RECURSE }, monitor);
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#overwriteUpdate(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
62      */

63     protected void overwriteUpdate(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
64         try {
65             new ReplaceOperation(getPart(), syncSet.getResources(), null /* tag */, false /* recurse */)
66                 .run(monitor);
67         } catch (InvocationTargetException JavaDoc e) {
68             throw CVSException.wrapException(e);
69         } catch (InterruptedException JavaDoc e) {
70             Policy.cancelOperation();
71         }
72         
73     }
74     
75
76     /* (non-Javadoc)
77      * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#updated(org.eclipse.core.resources.IResource[])
78      */

79     protected void updated(IResource[] resources) throws TeamException {
80         // Do nothing
81
}
82     
83     private void unmanage(SyncInfo element, IProgressMonitor monitor) throws CVSException {
84         CVSWorkspaceRoot.getCVSResourceFor(element.getLocal()).unmanage(monitor);
85     }
86
87     private void deleteAndKeepHistory(IResource resource, IProgressMonitor monitor) throws CVSException {
88         try {
89             if (!resource.exists()) return;
90             if (resource.getType() == IResource.FILE)
91                 ((IFile)resource).delete(false /* force */, true /* keep history */, monitor);
92             else if (resource.getType() == IResource.FOLDER)
93                 ((IFolder)resource).delete(false /* force */, true /* keep history */, monitor);
94         } catch (CoreException e) {
95             throw CVSException.wrapException(e);
96         }
97     }
98
99 }
100
Popular Tags