1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.dialogs.ErrorDialog; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.team.core.mapping.IMergeContext; 20 import org.eclipse.team.core.mapping.ISynchronizationContext; 21 import org.eclipse.team.core.mapping.provider.SynchronizationContext; 22 import org.eclipse.team.internal.ui.Policy; 23 import org.eclipse.team.internal.ui.TeamUIMessages; 24 import org.eclipse.team.ui.mapping.SynchronizationOperation; 25 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 26 import org.eclipse.team.ui.synchronize.ModelMergeOperation; 27 28 public final class MergeAllOperation extends SynchronizationOperation { 29 30 private final IMergeContext context; 31 private final String jobName; 32 33 public MergeAllOperation(String jobName, ISynchronizePageConfiguration configuration, Object [] elements, IMergeContext context) { 34 super(configuration, elements); 35 this.jobName = jobName; 36 this.context = context; 37 } 38 39 42 public void execute(IProgressMonitor monitor) throws InvocationTargetException , 43 InterruptedException { 44 new ModelMergeOperation(getPart(), ((SynchronizationContext)context).getScopeManager()) { 45 public boolean isPreviewRequested() { 46 return false; 47 } 48 protected void initializeContext(IProgressMonitor monitor) throws CoreException { 49 monitor.beginTask(null, 10); 50 monitor.done(); 51 } 52 protected ISynchronizationContext getContext() { 53 return context; 54 } 55 protected void executeMerge(IProgressMonitor monitor) throws CoreException { 56 monitor.beginTask(null, 100); 57 if (!hasChangesOfInterest()) { 58 handleNoChanges(); 59 } else if (isPreviewRequested()) { 60 handlePreviewRequest(); 61 } else { 62 IStatus status = ModelMergeOperation.validateMerge(getMergeContext(), Policy.subMonitorFor(monitor, 10)); 63 if (!status.isOK()) { 64 if (!promptToContinue(status)) 65 return; 66 } 67 status = performMerge(Policy.subMonitorFor(monitor, 90)); 68 if (!status.isOK()) { 69 handleMergeFailure(status); 70 } 71 } 72 monitor.done(); 73 } 74 private IMergeContext getMergeContext() { 75 return (IMergeContext)getContext(); 76 } 77 private boolean promptToContinue(final IStatus status) { 78 final boolean[] result = new boolean[] { false }; 79 Runnable runnable = new Runnable () { 80 public void run() { 81 ErrorDialog dialog = new ErrorDialog(getShell(), TeamUIMessages.ModelMergeOperation_0, TeamUIMessages.ModelMergeOperation_1, status, IStatus.ERROR | IStatus.WARNING | IStatus.INFO) { 82 protected void createButtonsForButtonBar(Composite parent) { 83 createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, 84 false); 85 createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, 86 true); 87 createDetailsButton(parent); 88 } 89 92 protected void buttonPressed(int id) { 93 if (id == IDialogConstants.YES_ID) 94 super.buttonPressed(IDialogConstants.OK_ID); 95 else if (id == IDialogConstants.NO_ID) 96 super.buttonPressed(IDialogConstants.CANCEL_ID); 97 super.buttonPressed(id); 98 } 99 }; 100 int code = dialog.open(); 101 result[0] = code == 0; 102 } 103 }; 104 getShell().getDisplay().syncExec(runnable); 105 return (result[0]); 106 } 107 }.run(monitor); 108 } 109 110 113 protected boolean canRunAsJob() { 114 return true; 115 } 116 117 120 protected String getJobName() {; 121 return jobName; 122 } 123 } | Popular Tags |