1 11 package org.eclipse.team.internal.ccvs.ui.mappings; 12 13 import org.eclipse.core.resources.mapping.ResourceTraversal; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.jface.util.IPropertyChangeListener; 17 import org.eclipse.jface.util.PropertyChangeEvent; 18 import org.eclipse.jface.viewers.*; 19 import org.eclipse.team.internal.ccvs.core.CVSException; 20 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 21 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants; 22 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 23 24 public class CommitAction extends AbstractCommitAction implements IPropertyChangeListener { 25 26 public CommitAction(final ISynchronizePageConfiguration configuration) { 27 super(configuration); 28 configuration.addPropertyChangeListener(this); 29 setId(ICVSUIConstants.CMD_COMMIT); 30 setActionDefinitionId(ICVSUIConstants.CMD_COMMIT); 31 } 32 33 protected String getBundleKeyPrefix() { 34 return "WorkspaceCommitAction."; } 36 37 40 protected boolean isEnabledForSelection(IStructuredSelection selection) { 41 return internalIsEnabled(selection); 42 } 43 44 private boolean internalIsEnabled(IStructuredSelection selection) { 45 int mode = getConfiguration().getMode(); 47 if (mode == ISynchronizePageConfiguration.OUTGOING_MODE || mode == ISynchronizePageConfiguration.BOTH_MODE) { 48 return getResourceMappings(selection).length > 0; 49 } 50 return false; 51 } 52 53 56 public void propertyChange(PropertyChangeEvent event) { 57 if (event.getSource() == getConfiguration() && event.getProperty() == ISynchronizePageConfiguration.P_MODE) { 58 setEnabled(internalIsEnabled(getStructuredSelection())); 59 } 60 } 61 62 protected ResourceTraversal[] getCommitTraversals(IStructuredSelection selection, IProgressMonitor monitor) 63 throws CoreException { 64 return getResourceTraversals(selection, monitor); 65 } 66 67 protected IStructuredSelection getActualSelection() throws CVSException { 68 IStructuredSelection selection = getStructuredSelection(); 69 IStructuredSelection actualSelection = internalGetActualSelection(); 70 if (!equal(selection, actualSelection)) { 71 throw new CVSException(CVSUIMessages.CommitAction_3); 72 } 73 return selection; 74 } 75 76 private boolean equal(IStructuredSelection selection, 77 IStructuredSelection actualSelection) { 78 return selection.equals(actualSelection); 79 } 80 81 private IStructuredSelection internalGetActualSelection() { 82 ISelection s = getConfiguration().getSite().getSelectionProvider().getSelection(); 83 if (s instanceof IStructuredSelection) { 84 return (IStructuredSelection) s; 85 } 86 return StructuredSelection.EMPTY; 87 } 88 89 } 90 | Popular Tags |