KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.subscriber;
12
13 import org.eclipse.compare.structuremergeviewer.IDiffElement;
14 import org.eclipse.jface.viewers.ISelectionProvider;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.team.core.synchronize.*;
17 import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
18 import org.eclipse.team.internal.ccvs.core.CVSException;
19 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
20 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
21 import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard;
22 import org.eclipse.team.internal.ui.synchronize.SyncInfoModelElement;
23 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
24 import org.eclipse.team.ui.synchronize.SynchronizeModelOperation;
25 import org.eclipse.ui.PlatformUI;
26
27 public class WorkspaceCommitAction extends CVSParticipantAction {
28
29     public WorkspaceCommitAction(ISynchronizePageConfiguration configuration) {
30         super(configuration);
31         setId(ICVSUIConstants.CMD_COMMIT);
32         setActionDefinitionId(ICVSUIConstants.CMD_COMMIT);
33     }
34
35     public WorkspaceCommitAction(ISynchronizePageConfiguration configuration, ISelectionProvider provider, String JavaDoc bundleKey) {
36         super(configuration, provider, bundleKey);
37         setId(ICVSUIConstants.CMD_COMMIT_ALL);
38         setActionDefinitionId(ICVSUIConstants.CMD_COMMIT_ALL);
39     }
40     
41     /* (non-Javadoc)
42      * @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter()
43      */

44     protected FastSyncInfoFilter getSyncInfoFilter() {
45         return new SyncInfoDirectionFilter(new int[] { SyncInfo.OUTGOING });
46     }
47
48     /* (non-Javadoc)
49      * @see org.eclipse.team.internal.ui.actions.SubscriberAction#getSubscriberOperation(org.eclipse.compare.structuremergeviewer.IDiffElement[])
50      */

51     protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
52         return new WorkspaceCommitOperation(configuration, elements, false /* override */);
53     }
54     
55     public void runOperation() {
56         final SyncInfoSet set = getSyncInfoSet();
57         final Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
58         try {
59             // Include the subscriber operation as a job listener so that the busy feedback for the
60
// commit will appear in the synchronize view
61
CommitWizard.run(shell, set, getSubscriberOperation(getConfiguration(), getFilteredDiffElements()));
62         } catch (CVSException e) {
63             CVSUIPlugin.log(e);
64         }
65     }
66
67     /*
68      * Return the selected SyncInfo for which this action is enabled.
69      *
70      * @return the selected SyncInfo for which this action is enabled.
71      */

72     private SyncInfoSet getSyncInfoSet() {
73         IDiffElement [] elements= getFilteredDiffElements();
74         SyncInfoSet filtered = new SyncInfoSet();
75         for (int i = 0; i < elements.length; i++) {
76             IDiffElement e = elements[i];
77             if (e instanceof SyncInfoModelElement) {
78                 filtered.add(((SyncInfoModelElement)e).getSyncInfo());
79             }
80         }
81         return filtered;
82     }
83 }
84
Popular Tags