Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8d063e5df48074d73a4e7af6d9c4284d1753af11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.actions;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.mapping.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.mapping.provider.SynchronizationScopeManager;
import org.eclipse.team.internal.ccvs.core.mapping.CVSActiveChangeSetCollector;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.ui.PlatformUI;

/**
 * Action for checking in files to a CVS provider.
 * Prompts the user for a release comment.
 */
public class CommitAction extends WorkspaceTraversalAction {
	
	private final class CommitScopeManager extends SynchronizationScopeManager {
		private boolean includeChangeSets;

		private CommitScopeManager(ResourceMapping[] mappings, ResourceMappingContext context, boolean models) {
			super("", mappings, context, models); //$NON-NLS-1$
			includeChangeSets = isIncludeChangeSets(getShell(), CVSUIMessages.CommitAction_2);
		}

		protected ResourceTraversal[] adjustInputTraversals(ResourceTraversal[] traversals) {
			if (includeChangeSets)
				return ((CVSActiveChangeSetCollector)CVSUIPlugin.getPlugin().getChangeSetManager()).adjustInputTraversals(traversals);
			return super.adjustInputTraversals(traversals);
		}
	}

	/*
	 * @see CVSAction#execute(IAction)
	 */
	public void execute(IAction action) throws InvocationTargetException, InterruptedException {
		final ResourceTraversal[][] traversals = new ResourceTraversal[][] { null };
		PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
	            try {
	            	monitor.beginTask(CVSUIMessages.CommitAction_0, 100);
	                traversals[0] = getTraversals(Policy.subMonitorFor(monitor, 80));
	            } catch (CoreException e) {
	                throw new InvocationTargetException(e);
	            } finally {
	            	monitor.done();
	            }
            }
        });
        run(new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
	            try {
	            	CommitWizard.run(getTargetPart(), getShell(), traversals[0]);
	            } catch (CoreException e) {
	                throw new InvocationTargetException(e);
	            }
            }
        }, false, PROGRESS_BUSYCURSOR);
	}
    
	/**
	 * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
	 */
	protected String getErrorTitle() {
		return CVSUIMessages.CommitAction_commitFailed; 
	}

	/**
	 * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForUnmanagedResources()
	 */
	protected boolean isEnabledForUnmanagedResources() {
		return true;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForNonExistantResources()
	 */
	protected boolean isEnabledForNonExistantResources() {
		return true;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getId()
	 */
	public String getId() {
		return ICVSUIConstants.CMD_COMMIT;
	}
	
	protected SynchronizationScopeManager getScopeManager() {
		return new CommitScopeManager(getCVSResourceMappings(), getResourceMappingContext(), true);
	}

	public static boolean isIncludeChangeSets(final Shell shell, final String message) {
		if (CVSUIPlugin.getPlugin().getChangeSetManager().getSets().length == 0)
			return false;
		final IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore();
		final String option = store.getString(ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT);
		if (option.equals(MessageDialogWithToggle.ALWAYS))
			return true; // no, always switch
		
		if (option.equals(MessageDialogWithToggle.NEVER))
			return false; // no, never switch
		
	    // Ask the user whether to switch
		final int[] result = new int[] { 0 };
		Utils.syncExec(new Runnable() {
			public void run() {
				final MessageDialogWithToggle m = MessageDialogWithToggle.openYesNoQuestion(
						shell,
						CVSUIMessages.CommitAction_1, 
						message, 
						CVSUIMessages.ShowAnnotationOperation_4,   
						false /* toggle state */,
						store,
						ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT);
				
				result[0] = m.getReturnCode();
			}
		}, shell);
		
		switch (result[0]) {
		// yes
		case IDialogConstants.YES_ID:
		case IDialogConstants.OK_ID :
		    return true;
		// no
		case IDialogConstants.NO_ID :
		    return false;
		}
		return false;
	}
}

Back to the top