View | Details | Raw Unified | Return to bug 111164 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ccvs/ui/wizards/CommitWizard.java (-4 / +22 lines)
Lines 157-162 Link Here
157
    private CommitWizardCommitPage fCommitPage;
157
    private CommitWizardCommitPage fCommitPage;
158
	private IJobChangeListener jobListener;
158
	private IJobChangeListener jobListener;
159
	private IWorkbenchPart part;
159
	private IWorkbenchPart part;
160
	private CVSOperation[] returnOperationSlot = null;
160
    
161
    
161
    public CommitWizard(SyncInfoSet infos) throws CVSException {
162
    public CommitWizard(SyncInfoSet infos) throws CVSException {
162
        this(infos.getResources());
163
        this(infos.getResources());
Lines 270-277 Link Here
270
        }
271
        }
271
        
272
        
272
        final AddAndCommitOperation operation= new AddAndCommitOperation(getPart(), files.getResources(), unadded.getResources(), comment);
273
        final AddAndCommitOperation operation= new AddAndCommitOperation(getPart(), files.getResources(), unadded.getResources(), comment);
273
        if (jobListener != null)
274
        
274
        	operation.setJobChangeListener(jobListener);
275
        
275
        
276
        
276
        if (fFileTypePage != null) {
277
        if (fFileTypePage != null) {
277
            final Map extensionsToSave= new HashMap();
278
            final Map extensionsToSave= new HashMap();
Lines 289-294 Link Here
289
            operation.setModesForNamesForOneTime(namesNotToSave);
290
            operation.setModesForNamesForOneTime(namesNotToSave);
290
        }
291
        }
291
        
292
        
293
        if(returnOperationSlot != null){
294
        	returnOperationSlot[0] = operation;
295
        	return super.performFinish();
296
        }
297
        
298
        if (jobListener != null)
299
        	operation.setJobChangeListener(jobListener);
300
        
292
        try {
301
        try {
293
            operation.run();
302
            operation.run();
294
        } catch (InvocationTargetException e) {
303
        } catch (InvocationTargetException e) {
Lines 323-338 Link Here
323
    }
332
    }
324
    
333
    
325
    public static void run(IWorkbenchPart part, Shell shell, IResource [] resources) throws CVSException {
334
    public static void run(IWorkbenchPart part, Shell shell, IResource [] resources) throws CVSException {
335
        run(part, shell, resources, null);
336
    }
337
    
338
    public static void run(IWorkbenchPart part, Shell shell, IResource [] resources, CVSOperation[] op) throws CVSException {
326
        try {
339
        try {
327
			CommitWizard commitWizard = new CommitWizard(resources);
340
			CommitWizard commitWizard = new CommitWizard(resources);
328
			commitWizard.setPart(part);
341
			commitWizard.setPart(part);
342
			commitWizard.setReturnOperationSlot(op);
329
			run(shell, commitWizard);
343
			run(shell, commitWizard);
330
		} catch (OperationCanceledException e) {
344
		} catch (OperationCanceledException e) {
331
			// Ignore
345
			// Ignore
332
		}
346
		}
333
    }
347
    }
334
    
348
    
335
    private void setPart(IWorkbenchPart part) {
349
    private void setReturnOperationSlot(CVSOperation[] op) {
350
		this.returnOperationSlot  = op;
351
	}
352
353
	private void setPart(IWorkbenchPart part) {
336
		this.part = part;
354
		this.part = part;
337
	}
355
	}
338
356
Lines 447-453 Link Here
447
        return files;
465
        return files;
448
    }
466
    }
449
    
467
    
450
    private static boolean isAdded(IResource resource) throws CVSException {
468
    public static boolean isAdded(IResource resource) throws CVSException {
451
        final ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
469
        final ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
452
        if (cvsResource.isFolder()) {
470
        if (cvsResource.isFolder()) {
453
            return ((ICVSFolder)cvsResource).isCVSFolder();
471
            return ((ICVSFolder)cvsResource).isCVSFolder();
(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (+4 lines)
Lines 1136-1139 Link Here
1136
	public static String NewLocationWizard_2;
1136
	public static String NewLocationWizard_2;
1137
	public static String NewLocationWizard_3;
1137
	public static String NewLocationWizard_3;
1138
	public static String NewLocationWizard_4;
1138
	public static String NewLocationWizard_4;
1139
	
1140
	public static String AbstractCommitAction_ChangeSetsCommitDialogTitle;
1141
	public static String AbstractCommitAction_ChangeSetsCommitDialogMessage;
1142
	public static String AbstractCommitAction_ChangeSetsCommitingJob;
1139
}
1143
}
(-)src/org/eclipse/team/internal/ccvs/ui/messages.properties (+4 lines)
Lines 1159-1161 Link Here
1159
AnnotatePreferencePage_AnnotatePrefPageTitle=Annotate
1159
AnnotatePreferencePage_AnnotatePrefPageTitle=Annotate
1160
AnnotatePreferencePage_AnnotatePrefPageMessage=Options for CVS Annotate:
1160
AnnotatePreferencePage_AnnotatePrefPageMessage=Options for CVS Annotate:
1161
AnnotatePreferencePage_AnnotatePrefPageBinaryFileMessage=Attempt to annotate a &binary file
1161
AnnotatePreferencePage_AnnotatePrefPageBinaryFileMessage=Attempt to annotate a &binary file
1162
1163
AbstractCommitAction_ChangeSetsCommitDialogTitle=Change sets commit
1164
AbstractCommitAction_ChangeSetsCommitDialogMessage=Do you want to automatically commit selected change sets with previously entered comments?
1165
AbstractCommitAction_ChangeSetsCommitingJob=Commiting Change Sets and Resources
(-)src/org/eclipse/team/internal/ccvs/ui/mappings/AbstractCommitAction.java (-8 / +196 lines)
Lines 11-39 Link Here
11
package org.eclipse.team.internal.ccvs.ui.mappings;
11
package org.eclipse.team.internal.ccvs.ui.mappings;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.*;
15
import java.util.List;
16
15
17
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.mapping.ResourceTraversal;
17
import org.eclipse.core.resources.mapping.ResourceTraversal;
19
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.jface.dialogs.IDialogConstants;
21
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.operation.IRunnableWithProgress;
22
import org.eclipse.jface.operation.IRunnableWithProgress;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.StructuredSelection;
23
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.team.core.diff.IDiff;
26
import org.eclipse.team.core.diff.IDiff;
25
import org.eclipse.team.core.diff.IThreeWayDiff;
27
import org.eclipse.team.core.diff.IThreeWayDiff;
26
import org.eclipse.team.core.mapping.IResourceDiffTree;
28
import org.eclipse.team.core.mapping.IResourceDiffTree;
27
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
29
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
28
import org.eclipse.team.internal.ccvs.core.CVSException;
30
import org.eclipse.team.internal.ccvs.core.CVSException;
31
import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
29
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
32
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
33
import org.eclipse.team.internal.ccvs.ui.operations.CVSOperation;
30
import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard;
34
import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard;
35
import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard.AddAndCommitOperation;
36
import org.eclipse.team.internal.core.subscribers.ChangeSet;
31
import org.eclipse.team.internal.ui.Utils;
37
import org.eclipse.team.internal.ui.Utils;
32
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
38
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
39
import org.eclipse.ui.IWorkbenchPart;
33
import org.eclipse.ui.PlatformUI;
40
import org.eclipse.ui.PlatformUI;
34
41
35
public abstract class AbstractCommitAction extends CVSModelProviderAction {
42
public abstract class AbstractCommitAction extends CVSModelProviderAction {
36
43
44
	private class CommitOperationsWrapper extends CVSOperation{
45
46
		private CVSOperation resourcesCommitOp;
47
		private ChangeSet[] changeSets;
48
		
49
		protected CommitOperationsWrapper(IWorkbenchPart part, 
50
				CVSOperation resourcesCommitOp, ChangeSet[] changeSets) {
51
			super(part);
52
			this.resourcesCommitOp = resourcesCommitOp;
53
			this.changeSets = changeSets;
54
		}
55
		
56
		protected CommitOperationsWrapper(IWorkbenchPart part) {
57
			super(part);
58
		}
59
60
		protected void execute(IProgressMonitor monitor) throws CVSException,
61
				InterruptedException {
62
			try {
63
				if(resourcesCommitOp != null){
64
					resourcesCommitOp.run();
65
				}
66
				for (int i = 0; i < changeSets.length; i++) {
67
					ChangeSet changeSet = (ChangeSet) changeSets[i];
68
					IResource[] setResources = changeSet.getResources();
69
					IResource[] toAddArray = null;
70
					try {
71
						toAddArray = findToAddResources(setResources);
72
					} catch (CVSException e) {
73
						Utils.handleError(getConfiguration().getSite().getShell(), 
74
								e, null, null);
75
						return;
76
					}
77
					String comment = getComment(changeSet);
78
					AddAndCommitOperation op = new AddAndCommitOperation(
79
							getConfiguration().getSite().getPart(), setResources,
80
							toAddArray, comment);
81
					op.run();
82
				}
83
			} catch (InvocationTargetException e) {
84
				e.printStackTrace();
85
			}
86
		}
87
88
		protected String getTaskName() {
89
			return CVSUIMessages.AbstractCommitAction_ChangeSetsCommitingJob;
90
		}
91
		
92
		private IResource[] findToAddResources(IResource[] setResources)
93
				throws CVSException {
94
			List toAdd = new ArrayList();
95
			for (int j = 0; j < setResources.length; j++) {
96
				if (!CommitWizard.isAdded(setResources[j])) {
97
					toAdd.add(setResources[j]);
98
				}
99
			}
100
101
			IResource[] toAddArray = new IResource[toAdd.size()];
102
			for (int j = 0; j < toAdd.size(); j++) {
103
				toAddArray[j] = (IResource) toAdd.get(j);
104
			}
105
106
			return toAddArray;
107
		}
108
109
		private String getComment(ChangeSet changeSet) {
110
			String comment = changeSet.getComment();
111
			if (comment == null) {
112
				comment = changeSet.getName();
113
			}
114
			return comment;
115
		}
116
117
		public void setChangeSets(ChangeSet[] array) {
118
			changeSets = array;
119
		}
120
121
		public void setIndependentResourcesCommitOp(CVSOperation operation) {
122
			resourcesCommitOp = operation;
123
		}
124
		
125
	}
126
	
37
	public AbstractCommitAction(ISynchronizePageConfiguration configuration) {
127
	public AbstractCommitAction(ISynchronizePageConfiguration configuration) {
38
		super(configuration);
128
		super(configuration);
39
	}
129
	}
Lines 60-83 Link Here
60
		} catch (InterruptedException e) {
150
		} catch (InterruptedException e) {
61
			// Ignore
151
			// Ignore
62
		}
152
		}
153
		
154
		
155
		final CommitOperationsWrapper wrapper = new CommitOperationsWrapper(getConfiguration().getSite().getPart());
156
		//check if there are selected change sets
157
		if(selectedChangeSets(selection)){
158
			boolean canContinue = handleChangeSets(resources, selection, 
159
					wrapper);
160
			if(!canContinue){ //action cancelled
161
				return;
162
			}
163
		}
164
		final CVSOperation[] op = new CVSOperation[1];
165
		//launch commit wizard
63
		if (!resources.isEmpty() && ((IResource[])resources.get(0)).length > 0) {
166
		if (!resources.isEmpty() && ((IResource[])resources.get(0)).length > 0) {
64
	        Shell shell= getConfiguration().getSite().getShell();
167
	        Shell shell= getConfiguration().getSite().getShell();
65
	        try {
168
	        try {
66
	            CommitWizard.run(getConfiguration().getSite().getPart(), shell, ((IResource[])resources.get(0)));
169
	            CommitWizard.run(getConfiguration().getSite().getPart(), shell, 
170
	            		((IResource[])resources.get(0)), op);
67
	        } catch (CVSException e) {
171
	        } catch (CVSException e) {
68
	            CVSUIPlugin.log(e);
172
	            CVSUIPlugin.log(e);
69
	        }
173
	        }
70
		}
174
		}
175
		if(op[0] == null){
176
			return; //action cancelled
177
		}
178
		wrapper.setIndependentResourcesCommitOp(op[0]);
179
		
180
		try {
181
			wrapper.run();
182
		} catch (InvocationTargetException e) {
183
			Utils.handleError(getConfiguration().getSite().getShell(), e, null, null);
184
		} catch (InterruptedException e) {
185
			// ignore
186
		}
187
	}
188
189
	private boolean selectedChangeSets(final IStructuredSelection selection) {
190
		final Object [] selectionAsArray = selection.toArray();
191
		for(int i = 0; i < selectionAsArray.length; i++){
192
			if((selectionAsArray[i] instanceof ChangeSet) ){
193
				return true; 
194
			}
195
		}
196
		return false;
197
	}
198
	
199
	/* splits the selection into resources to commit and commit sets */
200
	private boolean handleChangeSets(final List resources,
201
		final IStructuredSelection selection, final CommitOperationsWrapper wrapper) {
202
		MessageDialog question = new MessageDialog(getConfiguration().getSite().getShell(),
203
				CVSUIMessages.AbstractCommitAction_ChangeSetsCommitDialogTitle, null,
204
				CVSUIMessages.AbstractCommitAction_ChangeSetsCommitDialogMessage, MessageDialog.QUESTION, 
205
				new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
206
				IDialogConstants.CANCEL_LABEL}, 0);
207
		question.setBlockOnOpen(true);
208
		int result = question.open();
209
		if(result == 2){
210
			return false;
211
		}
212
		if(result == 0){ 
213
			try {
214
				PlatformUI.getWorkbench().getProgressService()
215
					.busyCursorWhile(new IRunnableWithProgress() {
216
					public void run(IProgressMonitor monitor) 
217
						throws InvocationTargetException, InterruptedException {
218
						try {
219
							final Object [] selectionAsArray = selection.toArray();
220
							final List changeSets = new ArrayList();
221
					    	for(int i = 0; i < selectionAsArray.length; i++){
222
					    		if((selectionAsArray[i] instanceof ChangeSet) ){
223
					    			changeSets.add(selectionAsArray[i]); 
224
					    		}
225
					    	}
226
					    	ResourceTraversal[] traversals = getCommitTraversals(
227
					    			changeSets, monitor);
228
					    	
229
					    	List changeSetsResources = Arrays.asList(
230
					    			getOutgoingChanges(
231
					    					getSynchronizationContext().getDiffTree(), 
232
					    					traversals, monitor)); 
233
					    	List resourcesList = new ArrayList(
234
					    			Arrays.asList((IResource[]) resources.get(0)));
235
					    	
236
					    	resourcesList.removeAll(changeSetsResources);
237
					    	
238
					    	resources.clear();
239
					    	resources.add((IResource[])resourcesList.toArray(
240
					    			new IResource[]{}));
241
					    	
242
					    	wrapper.setChangeSets((ChangeSet[])changeSets.toArray(new ChangeSet[]{}));
243
						} catch (CoreException e) {
244
							throw new InvocationTargetException(e);
245
						}
246
					}
247
				});
248
			} catch (InvocationTargetException e) {
249
				Utils.handleError(getConfiguration().getSite().getShell(), e, null, null);
250
			} catch (InterruptedException e) {
251
				// Ignore
252
			}
253
		}
254
		return true;
71
	}
255
	}
72
	
256
	
73
	protected IStructuredSelection getActualSelection() {
257
	protected IStructuredSelection getActualSelection() {
74
		return getStructuredSelection();
258
		return getStructuredSelection();
75
	}
259
	}
260
	
261
	private ResourceTraversal[] getCommitTraversals(final List changeSets, 
262
			IProgressMonitor monitor) throws CoreException{
263
		return getCommitTraversals(new StructuredSelection(changeSets), monitor);
264
	}
76
265
77
	protected abstract ResourceTraversal[] getCommitTraversals(IStructuredSelection selection, IProgressMonitor monitor) throws CoreException;
266
	protected abstract ResourceTraversal[] getCommitTraversals(IStructuredSelection selection, IProgressMonitor monitor) throws CoreException;
78
	
267
	
79
    protected IResource[] getOutgoingChanges(final IResourceDiffTree tree, ResourceTraversal[] traversals, IProgressMonitor monitor) {
268
	protected IResource[] getOutgoingChanges(final IResourceDiffTree tree, ResourceTraversal[] traversals, IProgressMonitor monitor) {
80
    	final List resources = new ArrayList();
269
		final List resources = new ArrayList();
81
		IDiff[] diffs = tree.getDiffs(traversals);
270
		IDiff[] diffs = tree.getDiffs(traversals);
82
		for (int i = 0; i < diffs.length; i++) {
271
		for (int i = 0; i < diffs.length; i++) {
83
			IDiff diff = diffs[i];
272
			IDiff diff = diffs[i];
Lines 88-95 Link Here
88
			}
277
			}
89
		}
278
		}
90
		return (IResource[]) resources.toArray(new IResource[resources.size()]);
279
		return (IResource[]) resources.toArray(new IResource[resources.size()]);
91
    }
280
	}
92
    
281
	
93
	private boolean hasLocalChange(IDiff diff) {
282
	private boolean hasLocalChange(IDiff diff) {
94
		if (diff instanceof IThreeWayDiff) {
283
		if (diff instanceof IThreeWayDiff) {
95
			IThreeWayDiff twd = (IThreeWayDiff) diff;
284
			IThreeWayDiff twd = (IThreeWayDiff) diff;
Lines 98-102 Link Here
98
		}
287
		}
99
		return false;
288
		return false;
100
	}
289
	}
101
102
}
290
}

Return to bug 111164