KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.mapping.*;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.dialogs.IDialogConstants;
20 import org.eclipse.jface.dialogs.MessageDialogWithToggle;
21 import org.eclipse.jface.operation.IRunnableWithProgress;
22 import org.eclipse.jface.preference.IPreferenceStore;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.team.core.mapping.provider.SynchronizationScopeManager;
25 import org.eclipse.team.internal.ccvs.core.mapping.CVSActiveChangeSetCollector;
26 import org.eclipse.team.internal.ccvs.ui.*;
27 import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard;
28 import org.eclipse.team.internal.ui.Utils;
29 import org.eclipse.ui.PlatformUI;
30
31 /**
32  * Action for checking in files to a CVS provider.
33  * Prompts the user for a release comment.
34  */

35 public class CommitAction extends WorkspaceTraversalAction {
36     
37     private final class CommitScopeManager extends SynchronizationScopeManager {
38         private boolean includeChangeSets;
39
40         private CommitScopeManager(ResourceMapping[] mappings, ResourceMappingContext context, boolean models) {
41             super("", mappings, context, models); //$NON-NLS-1$
42
includeChangeSets = isIncludeChangeSets(getShell(), CVSUIMessages.CommitAction_2);
43         }
44
45         protected ResourceTraversal[] adjustInputTraversals(ResourceTraversal[] traversals) {
46             if (includeChangeSets)
47                 return ((CVSActiveChangeSetCollector)CVSUIPlugin.getPlugin().getChangeSetManager()).adjustInputTraversals(traversals);
48             return super.adjustInputTraversals(traversals);
49         }
50     }
51
52     /*
53      * @see CVSAction#execute(IAction)
54      */

55     public void execute(IAction action) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
56         final ResourceTraversal[][] traversals = new ResourceTraversal[][] { null };
57         PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
58             public void run(IProgressMonitor monitor)
59                     throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
60                 try {
61                     monitor.beginTask(CVSUIMessages.CommitAction_0, 100);
62                     traversals[0] = getTraversals(Policy.subMonitorFor(monitor, 80));
63                 } catch (CoreException e) {
64                     throw new InvocationTargetException JavaDoc(e);
65                 } finally {
66                     monitor.done();
67                 }
68             }
69         });
70         run(new IRunnableWithProgress() {
71             public void run(IProgressMonitor monitor)
72                     throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
73                 try {
74                     CommitWizard.run(getTargetPart(), getShell(), traversals[0]);
75                 } catch (CoreException e) {
76                     throw new InvocationTargetException JavaDoc(e);
77                 }
78             }
79         }, false, PROGRESS_BUSYCURSOR);
80     }
81     
82     /**
83      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
84      */

85     protected String JavaDoc getErrorTitle() {
86         return CVSUIMessages.CommitAction_commitFailed;
87     }
88
89     /**
90      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForUnmanagedResources()
91      */

92     protected boolean isEnabledForUnmanagedResources() {
93         return true;
94     }
95     
96     /* (non-Javadoc)
97      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForNonExistantResources()
98      */

99     protected boolean isEnabledForNonExistantResources() {
100         return true;
101     }
102     
103     /* (non-Javadoc)
104      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getId()
105      */

106     public String JavaDoc getId() {
107         return ICVSUIConstants.CMD_COMMIT;
108     }
109     
110     protected SynchronizationScopeManager getScopeManager() {
111         return new CommitScopeManager(getCVSResourceMappings(), getResourceMappingContext(), true);
112     }
113
114     public static boolean isIncludeChangeSets(final Shell shell, final String JavaDoc message) {
115         if (CVSUIPlugin.getPlugin().getChangeSetManager().getSets().length == 0)
116             return false;
117         final IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore();
118         final String JavaDoc option = store.getString(ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT);
119         if (option.equals(MessageDialogWithToggle.ALWAYS))
120             return true; // no, always switch
121

122         if (option.equals(MessageDialogWithToggle.NEVER))
123             return false; // no, never switch
124

125         // Ask the user whether to switch
126
final int[] result = new int[] { 0 };
127         Utils.syncExec(new Runnable JavaDoc() {
128             public void run() {
129                 final MessageDialogWithToggle m = MessageDialogWithToggle.openYesNoQuestion(
130                         shell,
131                         CVSUIMessages.CommitAction_1,
132                         message,
133                         CVSUIMessages.ShowAnnotationOperation_4,
134                         false /* toggle state */,
135                         store,
136                         ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT);
137                 
138                 result[0] = m.getReturnCode();
139             }
140         }, shell);
141         
142         switch (result[0]) {
143         // yes
144
case IDialogConstants.YES_ID:
145         case IDialogConstants.OK_ID :
146             return true;
147         // no
148
case IDialogConstants.NO_ID :
149             return false;
150         }
151         return false;
152     }
153 }
154
Popular Tags