Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 15-35
Link Here
|
15 |
package org.eclipse.team.internal.ccvs.ui.wizards; |
15 |
package org.eclipse.team.internal.ccvs.ui.wizards; |
16 |
|
16 |
|
17 |
import java.lang.reflect.InvocationTargetException; |
17 |
import java.lang.reflect.InvocationTargetException; |
18 |
import java.util.ArrayList; |
18 |
import java.util.*; |
19 |
import java.util.Arrays; |
|
|
20 |
import java.util.Collection; |
21 |
import java.util.Collections; |
22 |
import java.util.HashMap; |
23 |
import java.util.HashSet; |
24 |
import java.util.Iterator; |
25 |
import java.util.List; |
26 |
import java.util.Map; |
27 |
|
19 |
|
28 |
import org.eclipse.core.resources.*; |
20 |
import org.eclipse.core.resources.*; |
|
|
21 |
import org.eclipse.core.resources.mapping.ResourceMapping; |
29 |
import org.eclipse.core.resources.mapping.ResourceTraversal; |
22 |
import org.eclipse.core.resources.mapping.ResourceTraversal; |
30 |
import org.eclipse.core.runtime.*; |
23 |
import org.eclipse.core.runtime.*; |
31 |
import org.eclipse.core.runtime.jobs.IJobChangeEvent; |
24 |
import org.eclipse.core.runtime.jobs.*; |
32 |
import org.eclipse.core.runtime.jobs.IJobChangeListener; |
|
|
33 |
import org.eclipse.jface.dialogs.*; |
25 |
import org.eclipse.jface.dialogs.*; |
34 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
26 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
35 |
import org.eclipse.jface.preference.IPreferenceStore; |
27 |
import org.eclipse.jface.preference.IPreferenceStore; |
Lines 38-52
Link Here
|
38 |
import org.eclipse.swt.widgets.Shell; |
30 |
import org.eclipse.swt.widgets.Shell; |
39 |
import org.eclipse.team.core.IFileContentManager; |
31 |
import org.eclipse.team.core.IFileContentManager; |
40 |
import org.eclipse.team.core.Team; |
32 |
import org.eclipse.team.core.Team; |
41 |
import org.eclipse.team.core.synchronize.*; |
33 |
import org.eclipse.team.core.diff.*; |
|
|
34 |
import org.eclipse.team.core.mapping.*; |
35 |
import org.eclipse.team.core.synchronize.SyncInfoSet; |
42 |
import org.eclipse.team.internal.ccvs.core.*; |
36 |
import org.eclipse.team.internal.ccvs.core.*; |
43 |
import org.eclipse.team.internal.ccvs.core.client.Command; |
37 |
import org.eclipse.team.internal.ccvs.core.client.Command; |
44 |
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; |
38 |
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; |
45 |
import org.eclipse.team.internal.ccvs.ui.*; |
39 |
import org.eclipse.team.internal.ccvs.ui.*; |
|
|
40 |
import org.eclipse.team.internal.ccvs.ui.actions.CommitAction; |
41 |
import org.eclipse.team.internal.ccvs.ui.mappings.AbstractCommitAction; |
42 |
import org.eclipse.team.internal.ccvs.ui.mappings.WorkspaceSubscriberContext; |
46 |
import org.eclipse.team.internal.ccvs.ui.operations.*; |
43 |
import org.eclipse.team.internal.ccvs.ui.operations.*; |
47 |
import org.eclipse.team.internal.core.subscribers.SubscriberSyncInfoCollector; |
44 |
import org.eclipse.team.internal.core.subscribers.SubscriberDiffTreeEventHandler; |
48 |
import org.eclipse.team.internal.ui.Policy; |
45 |
import org.eclipse.team.internal.ui.Policy; |
49 |
import org.eclipse.team.ui.synchronize.ResourceScope; |
46 |
import org.eclipse.team.internal.ui.Utils; |
|
|
47 |
import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant; |
50 |
import org.eclipse.ui.IWorkbenchPart; |
48 |
import org.eclipse.ui.IWorkbenchPart; |
51 |
import org.eclipse.ui.PlatformUI; |
49 |
import org.eclipse.ui.PlatformUI; |
52 |
|
50 |
|
Lines 154-162
Link Here
|
154 |
} |
152 |
} |
155 |
|
153 |
|
156 |
private final IResource[] fResources; |
154 |
private final IResource[] fResources; |
157 |
private final SyncInfoSet fOutOfSyncInfos; |
155 |
private IResource[] fUnaddedDiffs; |
158 |
private final SyncInfoSet fUnaddedInfos; |
156 |
private final ModelSynchronizeParticipant fParticipant; |
159 |
private final CommitWizardParticipant fParticipant; |
|
|
160 |
|
157 |
|
161 |
private CommitWizardFileTypePage fFileTypePage; |
158 |
private CommitWizardFileTypePage fFileTypePage; |
162 |
private CommitWizardCommitPage fCommitPage; |
159 |
private CommitWizardCommitPage fCommitPage; |
Lines 176-217
Link Here
|
176 |
setDefaultPageImageDescriptor(CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); |
173 |
setDefaultPageImageDescriptor(CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); |
177 |
|
174 |
|
178 |
fResources= resources; |
175 |
fResources= resources; |
179 |
fParticipant= new CommitWizardParticipant(new ResourceScope(fResources), this); |
176 |
ResourceMapping[] mappings = Utils.getResourceMappings(resources); |
180 |
|
177 |
fParticipant = createWorkspaceParticipant(mappings, getShell()); |
181 |
SyncInfoSet infos = getAllOutOfSync(); |
178 |
|
182 |
fOutOfSyncInfos= new SyncInfoSet(infos.getNodes(new FastSyncInfoFilter.SyncInfoDirectionFilter(new int [] { SyncInfo.OUTGOING, SyncInfo.CONFLICTING }))); |
179 |
getAllOutOfSync(); |
183 |
fUnaddedInfos= getUnaddedInfos(fOutOfSyncInfos); |
180 |
fUnaddedDiffs = getUnaddedResources(getDiffTree().getAffectedResources()); |
184 |
} |
181 |
} |
185 |
|
182 |
|
|
|
183 |
private ModelSynchronizeParticipant createWorkspaceParticipant(ResourceMapping[] selectedMappings, Shell shell) { |
184 |
ISynchronizationScopeManager manager = WorkspaceSubscriberContext.createWorkspaceScopeManager(selectedMappings, true, CommitAction.isIncludeChangeSets(shell, CVSUIMessages.SyncAction_1)); |
185 |
return new CommitWizardParticipant(WorkspaceSubscriberContext.createContext(manager, ISynchronizationContext.THREE_WAY), this); |
186 |
} |
187 |
|
186 |
public CommitWizard(SyncInfoSet infos, IJobChangeListener jobListener) throws CVSException { |
188 |
public CommitWizard(SyncInfoSet infos, IJobChangeListener jobListener) throws CVSException { |
187 |
this(infos); |
189 |
this(infos); |
188 |
this.jobListener = jobListener; |
190 |
this.jobListener = jobListener; |
189 |
} |
191 |
} |
190 |
|
192 |
|
191 |
private SyncInfoSet getAllOutOfSync() throws CVSException { |
193 |
private void getAllOutOfSync() throws CVSException { |
192 |
final SubscriberSyncInfoCollector syncInfoCollector = fParticipant.getSubscriberSyncInfoCollector(); |
194 |
try { |
193 |
try { |
195 |
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { |
194 |
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { |
196 |
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { |
195 |
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { |
197 |
monitor.beginTask(null, IProgressMonitor.UNKNOWN); |
196 |
monitor.beginTask(CVSUIMessages.CommitWizard_4, IProgressMonitor.UNKNOWN); |
198 |
|
197 |
syncInfoCollector.waitForCollector(monitor); |
199 |
ISynchronizationContext context = getParticipant().getContext(); |
198 |
monitor.done(); |
200 |
SubscriberDiffTreeEventHandler handler = (SubscriberDiffTreeEventHandler) Utils.getAdapter(context, SubscriberDiffTreeEventHandler.class); |
199 |
} |
201 |
handler.initializeIfNeeded(); |
200 |
}); |
202 |
Job.getJobManager().join(context, monitor); |
201 |
} catch (InvocationTargetException e) { |
203 |
|
202 |
throw CVSException.wrapException(e); |
204 |
if (monitor.isCanceled()) { |
203 |
} catch (InterruptedException e) { |
205 |
throw new InterruptedException(); |
204 |
throw new OperationCanceledException(); |
206 |
} |
205 |
} |
207 |
monitor.done(); |
206 |
return fParticipant.getSyncInfoSet(); |
208 |
} |
|
|
209 |
}); |
210 |
} catch (InvocationTargetException e) { |
211 |
throw CVSException.wrapException(e); |
212 |
} catch(InterruptedException e) { |
213 |
throw new OperationCanceledException(); |
214 |
} |
207 |
} |
215 |
} |
208 |
|
216 |
|
209 |
public boolean hasOutgoingChanges() { |
217 |
public boolean hasOutgoingChanges() { |
210 |
return fOutOfSyncInfos.size() > 0; |
218 |
IResourceDiffTree tree = getDiffTree(); |
|
|
219 |
return tree != null && tree.hasMatchingDiffs(ResourcesPlugin.getWorkspace().getRoot().getFullPath(), new FastDiffFilter() { |
220 |
public boolean select(IDiff diff) { |
221 |
return AbstractCommitAction.hasLocalChange(diff); |
222 |
} |
223 |
}); |
211 |
} |
224 |
} |
212 |
|
225 |
|
|
|
226 |
boolean hasConflicts() { |
227 |
IResourceDiffTree tree = getDiffTree(); |
228 |
return tree != null && tree.hasMatchingDiffs(ResourcesPlugin.getWorkspace().getRoot().getFullPath(), new FastDiffFilter() { |
229 |
public boolean select(IDiff diff) { |
230 |
if (diff instanceof IThreeWayDiff) { |
231 |
IThreeWayDiff twd = (IThreeWayDiff) diff; |
232 |
return twd.getDirection() == IThreeWayDiff.CONFLICTING; |
233 |
} |
234 |
return false; |
235 |
} |
236 |
}); |
237 |
} |
238 |
|
213 |
public int getHighestProblemSeverity() { |
239 |
public int getHighestProblemSeverity() { |
214 |
IResource[] resources = fOutOfSyncInfos.getResources(); |
240 |
IResource[] resources = getDiffTree().getAffectedResources(); |
215 |
int mostSeriousSeverity = -1; |
241 |
int mostSeriousSeverity = -1; |
216 |
|
242 |
|
217 |
for (int i = 0; i < resources.length; i++) { |
243 |
for (int i = 0; i < resources.length; i++) { |
Lines 227-233
Link Here
|
227 |
|
253 |
|
228 |
return mostSeriousSeverity; |
254 |
return mostSeriousSeverity; |
229 |
} |
255 |
} |
230 |
|
256 |
|
|
|
257 |
IResourceDiffTree getDiffTree() { |
258 |
return fParticipant.getContext().getDiffTree(); |
259 |
} |
260 |
|
231 |
public CommitWizardFileTypePage getFileTypePage() { |
261 |
public CommitWizardFileTypePage getFileTypePage() { |
232 |
return fFileTypePage; |
262 |
return fFileTypePage; |
233 |
} |
263 |
} |
Lines 236-242
Link Here
|
236 |
return fCommitPage; |
266 |
return fCommitPage; |
237 |
} |
267 |
} |
238 |
|
268 |
|
239 |
public CommitWizardParticipant getParticipant() { |
269 |
public ModelSynchronizeParticipant getParticipant() { |
240 |
return fParticipant; |
270 |
return fParticipant; |
241 |
} |
271 |
} |
242 |
|
272 |
|
Lines 253-277
Link Here
|
253 |
if (comment == null) |
283 |
if (comment == null) |
254 |
return false; |
284 |
return false; |
255 |
|
285 |
|
256 |
final SyncInfoSet infos= fCommitPage.getInfosToCommit(); |
286 |
IResource[] resources = AbstractCommitAction.getOutgoingChanges(getDiffTree(), fCommitPage.getTraversalsToCommit(), null); |
257 |
if (infos.size() == 0) |
287 |
if (resources.length == 0) |
258 |
return true; |
288 |
return true; |
259 |
|
289 |
|
260 |
final SyncInfoSet unadded; |
290 |
final IResource[] unadded; |
261 |
try { |
291 |
try { |
262 |
unadded = getUnaddedInfos(infos); |
292 |
unadded = getUnaddedResources(resources); |
263 |
} catch (CVSException e1) { |
293 |
} catch (CVSException e1) { |
264 |
return false; |
294 |
return false; |
265 |
} |
295 |
} |
266 |
|
296 |
|
267 |
final SyncInfoSet files; |
297 |
final IResource[] files = getFiles(resources); |
268 |
try { |
|
|
269 |
files = getFiles(infos); |
270 |
} catch (CVSException e1) { |
271 |
return false; |
272 |
} |
273 |
|
298 |
|
274 |
final AddAndCommitOperation operation= new AddAndCommitOperation(getPart(), files.getResources(), unadded.getResources(), comment); |
299 |
final AddAndCommitOperation operation= new AddAndCommitOperation(getPart(), files, unadded, comment); |
275 |
if (jobListener != null) |
300 |
if (jobListener != null) |
276 |
operation.setJobChangeListener(jobListener); |
301 |
operation.setJobChangeListener(jobListener); |
277 |
|
302 |
|
Lines 315-321
Link Here
|
315 |
|
340 |
|
316 |
final Collection names= new HashSet(); |
341 |
final Collection names= new HashSet(); |
317 |
final Collection extensions= new HashSet(); |
342 |
final Collection extensions= new HashSet(); |
318 |
getUnknownNamesAndExtension(fUnaddedInfos, names, extensions); |
343 |
getUnknownNamesAndExtension(fUnaddedDiffs, names, extensions); |
319 |
|
344 |
|
320 |
if (names.size() + extensions.size() > 0) { |
345 |
if (names.size() + extensions.size() > 0) { |
321 |
fFileTypePage= new CommitWizardFileTypePage(extensions, names); |
346 |
fFileTypePage= new CommitWizardFileTypePage(extensions, names); |
Lines 419-468
Link Here
|
419 |
return dialog.open(); |
444 |
return dialog.open(); |
420 |
} |
445 |
} |
421 |
|
446 |
|
422 |
private static void getUnknownNamesAndExtension(SyncInfoSet infos, Collection names, Collection extensions) { |
447 |
private void getUnknownNamesAndExtension(IResource[] resources, Collection names, Collection extensions) { |
423 |
|
448 |
|
424 |
final IFileContentManager manager= Team.getFileContentManager(); |
449 |
final IFileContentManager manager= Team.getFileContentManager(); |
425 |
|
450 |
|
426 |
for (final Iterator iter = infos.iterator(); iter.hasNext();) { |
451 |
for (int i = 0; i < resources.length; i++) { |
427 |
|
452 |
|
428 |
final SyncInfo info = (SyncInfo)iter.next(); |
453 |
IResource local = resources[i]; |
429 |
|
454 |
if (local instanceof IFile && manager.getType((IFile)local) == Team.UNKNOWN) { |
430 |
IResource local = info.getLocal(); |
455 |
final String extension= local.getFileExtension(); |
431 |
if (local instanceof IFile && manager.getType((IFile)local) == Team.UNKNOWN) { |
456 |
if (extension != null && !manager.isKnownExtension(extension)) { |
432 |
final String extension= local.getFileExtension(); |
457 |
extensions.add(extension); |
433 |
if (extension != null && !manager.isKnownExtension(extension)) { |
458 |
} |
434 |
extensions.add(extension); |
459 |
|
435 |
} |
460 |
final String name= local.getName(); |
436 |
|
461 |
if (extension == null && name != null && !manager.isKnownFilename(name)) |
437 |
final String name= local.getName(); |
462 |
names.add(name); |
438 |
if (extension == null && name != null && !manager.isKnownFilename(name)) |
463 |
} |
439 |
names.add(name); |
464 |
} |
440 |
} |
|
|
441 |
} |
442 |
} |
443 |
|
444 |
private static SyncInfoSet getUnaddedInfos(SyncInfoSet infos) throws CVSException { |
445 |
final SyncInfoSet unadded= new SyncInfoSet(); |
446 |
for (final Iterator iter = infos.iterator(); iter.hasNext();) { |
447 |
final SyncInfo info = (SyncInfo) iter.next(); |
448 |
final IResource resource= info.getLocal(); |
449 |
if (!isAdded(resource)) |
450 |
unadded.add(info); |
451 |
} |
452 |
return unadded; |
453 |
} |
454 |
|
455 |
private static SyncInfoSet getFiles(SyncInfoSet infos) throws CVSException { |
456 |
final SyncInfoSet files= new SyncInfoSet(); |
457 |
for (final Iterator iter = infos.iterator(); iter.hasNext();) { |
458 |
final SyncInfo info = (SyncInfo) iter.next(); |
459 |
final IResource resource= info.getLocal(); |
460 |
if (resource.getType() == IResource.FILE) |
461 |
files.add(info); |
462 |
} |
463 |
return files; |
464 |
} |
465 |
} |
465 |
|
466 |
|
|
|
467 |
private IResource[] getUnaddedResources(IResource[] resources) throws CVSException { |
468 |
List/*<IResource>*/ unadded = new ArrayList/*<IResource>*/(); |
469 |
for (int i = 0; i < resources.length; i++) { |
470 |
if (!isAdded(resources[i])) { |
471 |
unadded.add(resources[i]); |
472 |
} |
473 |
} |
474 |
return (IResource[]) unadded.toArray(new IResource[0]); |
475 |
} |
476 |
|
477 |
private IResource[] getFiles(IResource[] resources) { |
478 |
final List files = new ArrayList(); |
479 |
for (int i = 0; i < resources.length; i++) { |
480 |
if (resources[i].getType() == IResource.FILE) |
481 |
files.add(resources[i]); |
482 |
} |
483 |
return (IResource[]) files.toArray(new IResource[0]); |
484 |
} |
485 |
|
466 |
private static boolean isAdded(IResource resource) throws CVSException { |
486 |
private static boolean isAdded(IResource resource) throws CVSException { |
467 |
final ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); |
487 |
final ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); |
468 |
if (cvsResource.isFolder()) { |
488 |
if (cvsResource.isFolder()) { |