KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc getBundleKeyPrefix() {
34         return "WorkspaceCommitAction."; //$NON-NLS-1$
35
}
36
37     /* (non-Javadoc)
38      * @see org.eclipse.team.internal.ui.mapping.ModelProviderAction#isEnabledForSelection(org.eclipse.jface.viewers.IStructuredSelection)
39      */

40     protected boolean isEnabledForSelection(IStructuredSelection selection) {
41         return internalIsEnabled(selection);
42     }
43
44     private boolean internalIsEnabled(IStructuredSelection selection) {
45         // Only enable commit in outgoing or both modes
46
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     /* (non-Javadoc)
54      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
55      */

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