KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > mappings > ModelUpdateOperation


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.mappings;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.ResourcesPlugin;
18 import org.eclipse.core.resources.mapping.ResourceMapping;
19 import org.eclipse.core.runtime.*;
20 import org.eclipse.team.core.mapping.ISynchronizationContext;
21 import org.eclipse.team.core.mapping.provider.SynchronizationContext;
22 import org.eclipse.team.core.subscribers.SubscriberScopeManager;
23 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
24 import org.eclipse.team.internal.ccvs.core.ICVSResource;
25 import org.eclipse.team.internal.ccvs.core.client.PruneFolderVisitor;
26 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
27 import org.eclipse.team.internal.ccvs.ui.*;
28 import org.eclipse.team.internal.core.mapping.CompoundResourceTraversal;
29 import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
30 import org.eclipse.ui.IWorkbenchPart;
31
32 public class ModelUpdateOperation extends AbstractModelMergeOperation {
33     
34     public ModelUpdateOperation(IWorkbenchPart targetPart, ResourceMapping[] selectedResourceMappings, boolean consultModels) {
35         this(targetPart, WorkspaceSubscriberContext.createUpdateScopeManager(selectedResourceMappings, consultModels));
36     }
37     
38     public ModelUpdateOperation(IWorkbenchPart targetPart, ResourceMapping[] resourceMappings) {
39         this(targetPart, resourceMappings, true);
40     }
41
42     public ModelUpdateOperation(IWorkbenchPart targetPart, SubscriberScopeManager manager) {
43         super(targetPart, manager, true);
44     }
45
46     /* (non-Javadoc)
47      * @see org.eclipse.team.ui.TeamOperation#getJobName()
48      */

49     protected String JavaDoc getJobName() {
50         return CVSUIMessages.UpdateOperation_taskName;
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.team.ui.operations.ResourceMappingOperation#isPreviewRequested()
55      */

56     public boolean isPreviewRequested() {
57         return super.isPreviewRequested() || !isAttemptHeadlessMerge();
58     }
59
60     protected boolean isAttemptHeadlessMerge() {
61         return CVSUIPlugin.getPlugin().getPreferenceStore().getString(ICVSUIConstants.PREF_UPDATE_HANDLING).equals(ICVSUIConstants.PREF_UPDATE_HANDLING_PERFORM);
62     }
63
64     /**
65      * Return the merge type associated with this operation.
66      * @return the merge type associated with this operation
67      */

68     protected int getMergeType() {
69         return ISynchronizationContext.THREE_WAY;
70     }
71     
72     /* (non-Javadoc)
73      * @see org.eclipse.team.ui.operations.ResourceMappingMergeOperation#createParticipant()
74      */

75     protected ModelSynchronizeParticipant createParticipant() {
76         return new WorkspaceModelParticipant(createMergeContext());
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.team.ui.operations.ModelParticipantMergeOperation#createMergeContext()
81      */

82     protected SynchronizationContext createMergeContext() {
83         return WorkspaceSubscriberContext.createContext(getScopeManager(), getMergeType());
84     }
85     
86     protected void executeMerge(IProgressMonitor monitor) throws CoreException {
87         super.executeMerge(monitor);
88         // Prune any empty folders within the traversals
89
if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories()) {
90             CompoundResourceTraversal ct = new CompoundResourceTraversal();
91             ct.addTraversals(getContext().getScope().getTraversals());
92             IResource[] roots = ct.getRoots();
93             List JavaDoc cvsResources = new ArrayList JavaDoc();
94             for (int i = 0; i < roots.length; i++) {
95                 IResource resource = roots[i];
96                 if (resource.getProject().isAccessible()) {
97                     cvsResources.add(CVSWorkspaceRoot.getCVSResourceFor(roots[i]));
98                 }
99             }
100             new PruneFolderVisitor().visit(
101                 CVSWorkspaceRoot.getCVSFolderFor(ResourcesPlugin.getWorkspace().getRoot()),
102                 (ICVSResource[]) cvsResources.toArray(new ICVSResource[cvsResources.size()]));
103         }
104     }
105 }
106
Popular Tags