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 |
} |