1 11 package org.eclipse.team.internal.ccvs.ui.mappings; 12 13 import org.eclipse.core.resources.ResourcesPlugin; 14 import org.eclipse.core.resources.mapping.ResourceMapping; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.dialogs.IDialogConstants; 17 import org.eclipse.jface.dialogs.MessageDialog; 18 import org.eclipse.swt.widgets.Display; 19 import org.eclipse.team.core.diff.*; 20 import org.eclipse.team.core.mapping.IMergeContext; 21 import org.eclipse.team.core.mapping.ISynchronizationContext; 22 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 23 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 24 import org.eclipse.ui.IWorkbenchPart; 25 26 public class ModelReplaceOperation extends ModelUpdateOperation { 27 28 boolean hasPrompted = false; 29 30 public ModelReplaceOperation(IWorkbenchPart part, ResourceMapping[] selectedMappings, boolean consultModels) { 31 super(part, selectedMappings, consultModels); 32 } 33 34 37 protected String getJobName() { 38 return CVSUIMessages.ReplaceOperation_taskName; 39 } 40 41 44 protected boolean isAttemptHeadlessMerge() { 45 return true; 46 } 47 48 51 protected boolean hasChangesOfInterest() { 52 IMergeContext context = (IMergeContext)getContext(); 53 return !context.getDiffTree().isEmpty(); 54 } 55 56 59 protected int getMergeType() { 60 return ISynchronizationContext.TWO_WAY; 61 } 62 63 66 protected IStatus performMerge(IProgressMonitor monitor) throws CoreException { 67 if (!hasLocalChanges() || promptForOverwrite()) { 68 return super.performMerge(monitor); 69 } 70 return new Status(IStatus.ERROR, CVSUIPlugin.ID, REQUEST_PREVIEW, "", null); } 72 73 76 protected boolean promptForOverwrite() { 77 if (hasPrompted) 78 return true; 79 final int[] result = new int[] { 1 }; 80 Display.getDefault().syncExec(new Runnable () { 81 public void run() { 82 MessageDialog dialog = new MessageDialog(getShell(), CVSUIMessages.ModelReplaceOperation_0, null, CVSUIMessages.ModelReplaceOperation_1, 88 MessageDialog.QUESTION, new String [] { CVSUIMessages.ModelReplaceOperation_2, CVSUIMessages.ModelReplaceOperation_3, 89 IDialogConstants.CANCEL_LABEL }, result[0]); 91 result[0] = dialog.open(); 92 93 }; 94 }); 95 if (result[0] == 2) 96 throw new OperationCanceledException(); 97 hasPrompted = true; 98 return result[0] == 0; 99 } 100 101 private boolean hasLocalChanges() { 102 return getContext().getDiffTree().hasMatchingDiffs(ResourcesPlugin.getWorkspace().getRoot().getFullPath(), new FastDiffFilter() { 103 public boolean select(IDiff node) { 104 if (node instanceof IThreeWayDiff) { 105 IThreeWayDiff twd = (IThreeWayDiff) node; 106 int direction = twd.getDirection(); 107 if (direction == IThreeWayDiff.OUTGOING || direction == IThreeWayDiff.CONFLICTING) { 108 return true; 109 } 110 } else { 111 return true; 113 } 114 return false; 115 } 116 }); 117 } 118 } 119 | Popular Tags |