1 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 28 public class WorkspaceCommitAction extends AbstractCommitAction implements IDiffChangeListener { 29 30 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 getBundleKeyPrefix() { 50 return "WorkspaceToolbarCommitAction."; } 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 62 protected boolean isEnabledForSelection(IStructuredSelection selection) { 63 return isEnabled(); 65 } 66 67 70 public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) { 71 updateEnablement(); 72 } 73 74 77 public void propertyChanged(IDiffTree tree, int property, IPath[] paths) { 78 } 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 |