KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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 org.eclipse.core.resources.IResource;
14 import org.eclipse.core.resources.mapping.ResourceTraversal;
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.team.core.ICache;
18 import org.eclipse.team.core.ICacheListener;
19 import org.eclipse.team.core.diff.*;
20 import org.eclipse.team.core.mapping.ISynchronizationContext;
21 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
22 import org.eclipse.team.ui.mapping.ITeamContentProviderManager;
23 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
24
25 /**
26  * A commit action that will commit all outgoing changes in the context.
27  */

28 public class WorkspaceCommitAction extends AbstractCommitAction implements IDiffChangeListener {
29
30     /**
31      * Create the action
32      * @param configuration the synchronize page configuration
33      */

34     public WorkspaceCommitAction(ISynchronizePageConfiguration configuration) {
35         super(configuration);
36         setId(ICVSUIConstants.CMD_COMMIT_ALL);
37         setActionDefinitionId(ICVSUIConstants.CMD_COMMIT_ALL);
38         final IDiffTree tree = getDiffTree();
39         tree.addDiffChangeListener(this);
40         getSynchronizationContext().getCache().addCacheListener(new ICacheListener() {
41             public void cacheDisposed(ICache cache) {
42                 tree.removeDiffChangeListener(WorkspaceCommitAction.this);
43             }
44         });
45         updateEnablement();
46         
47     }
48     
49     protected String JavaDoc getBundleKeyPrefix() {
50         return "WorkspaceToolbarCommitAction."; //$NON-NLS-1$
51
}
52
53     private IDiffTree getDiffTree() {
54         ISynchronizationContext context = (ISynchronizationContext)getConfiguration().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT);
55         IDiffTree tree = context.getDiffTree();
56         return tree;
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.team.internal.ui.mapping.ModelProviderAction#isEnabledForSelection(org.eclipse.jface.viewers.IStructuredSelection)
61      */

62     protected boolean isEnabledForSelection(IStructuredSelection selection) {
63         // Enablement has nothing to do with selection
64
return isEnabled();
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.team.core.diff.IDiffChangeListener#diffChanged(org.eclipse.team.core.diff.IDiffChangeEvent, org.eclipse.core.runtime.IProgressMonitor)
69      */

70     public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) {
71         updateEnablement();
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.team.core.diff.IDiffChangeListener#propertyChanged(int, org.eclipse.core.runtime.IPath[])
76      */

77     public void propertyChanged(IDiffTree tree, int property, IPath[] paths) {
78         // Do nothing
79
}
80     
81     public void updateEnablement() {
82         boolean enabled = (getDiffTree().countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK) > 0)
83             && (getDiffTree().countFor(IThreeWayDiff.CONFLICTING, IThreeWayDiff.DIRECTION_MASK) == 0);
84         setEnabled(enabled);
85     }
86     
87     protected IResource[] getTargetResources() {
88         return getSynchronizationContext().getScope().getRoots();
89     }
90
91     protected ResourceTraversal[] getCommitTraversals(IStructuredSelection selection, IProgressMonitor monitor)
92             throws CoreException {
93         return getSynchronizationContext().getScope().getTraversals();
94     }
95
96 }
97
Popular Tags