1 11 package org.eclipse.team.ui.synchronize; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.compare.CompareConfiguration; 16 import org.eclipse.compare.CompareUI; 17 import org.eclipse.core.resources.mapping.RemoteResourceMappingContext; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.core.runtime.jobs.*; 20 import org.eclipse.team.core.mapping.ISynchronizationContext; 21 import org.eclipse.team.core.mapping.ISynchronizationScopeManager; 22 import org.eclipse.team.core.mapping.provider.SynchronizationContext; 23 import org.eclipse.team.internal.ui.TeamUIMessages; 24 import org.eclipse.team.ui.TeamUI; 25 import org.eclipse.ui.IWorkbenchPart; 26 import org.eclipse.ui.progress.IWorkbenchSiteProgressService; 27 import org.eclipse.ui.progress.WorkbenchJob; 28 29 35 public abstract class ModelParticipantMergeOperation extends ModelMergeOperation { 36 37 42 public static final int REQUEST_PREVIEW = 1024; 43 44 private ModelSynchronizeParticipant participant; 45 private boolean ownsParticipant = true; 46 47 private boolean sentToSyncView; 48 49 private static final Object PARTICIPANT_MERGE_FAMILY = new Object (); 50 51 56 protected ModelParticipantMergeOperation(IWorkbenchPart part, ISynchronizationScopeManager manager) { 57 super(part, manager); 58 } 59 60 63 protected void initializeContext(IProgressMonitor monitor) throws CoreException { 64 if (participant == null) { 65 participant = createParticipant(); 66 if (isPreviewRequested() && !isPreviewInDialog()) { 67 handlePreviewRequest(); 69 sentToSyncView = true; 70 } 71 participant.getContext().refresh(getScope().getTraversals(), 72 RemoteResourceMappingContext.FILE_CONTENTS_REQUIRED, monitor); 73 if (!sentToSyncView) 75 try { 76 Job.getJobManager().join(participant.getContext(), monitor); 77 } catch (InterruptedException e) { 78 } 80 } 81 } 82 83 86 protected void execute(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 87 try { 88 super.execute(monitor); 89 } finally { 90 if (ownsParticipant && participant != null) 91 participant.dispose(); 92 } 93 } 94 95 98 protected void executeMerge(IProgressMonitor monitor) throws CoreException { 99 if (!sentToSyncView) 100 super.executeMerge(monitor); 101 } 102 103 106 protected void handlePreviewRequest() { 107 Job job = new WorkbenchJob(getJobName()) { 108 public IStatus runInUIThread(IProgressMonitor monitor) { 109 if (isPreviewInDialog()) { 110 CompareConfiguration cc = new CompareConfiguration(); 111 ISynchronizePageConfiguration pageConfiguration = participant.createPageConfiguration(); 112 if (pageConfiguration.getComparisonType() == ISynchronizePageConfiguration.THREE_WAY) { 114 pageConfiguration.setSupportedModes(ISynchronizePageConfiguration.INCOMING_MODE | ISynchronizePageConfiguration.CONFLICTING_MODE); 115 pageConfiguration.setMode(ISynchronizePageConfiguration.INCOMING_MODE); 116 } 117 ParticipantPageCompareEditorInput input = new ParticipantPageCompareEditorInput(cc, pageConfiguration, participant); 118 CompareUI.openCompareDialog(input); 119 } else { 120 ISynchronizeManager mgr = TeamUI.getSynchronizeManager(); 121 ISynchronizeView view = mgr.showSynchronizeViewInActivePage(); 122 mgr.addSynchronizeParticipants(new ISynchronizeParticipant[] {participant}); 123 view.display(participant); 124 Object adapted = view.getSite().getAdapter(IWorkbenchSiteProgressService.class); 125 if (adapted instanceof IWorkbenchSiteProgressService) { 126 IWorkbenchSiteProgressService siteProgress = (IWorkbenchSiteProgressService) adapted; 127 siteProgress.showBusyForFamily(PARTICIPANT_MERGE_FAMILY); 128 } 129 } 130 return Status.OK_STATUS; 131 } 132 }; 133 job.addJobChangeListener(new JobChangeAdapter() { 134 public void done(IJobChangeEvent event) { 135 if (TeamUI.getSynchronizeManager().get(participant.getId(), participant.getSecondaryId()) == null) 137 participant.dispose(); 138 } 139 140 }); 141 ownsParticipant = false; 142 job.schedule(); 143 } 144 145 public boolean belongsTo(Object family) { 146 if (family == PARTICIPANT_MERGE_FAMILY) { 147 return true; 148 } 149 if (participant != null && participant == family) 150 return true; 151 return super.belongsTo(family); 152 } 153 154 158 protected boolean isPreviewInDialog() { 159 return true; 160 } 161 162 165 protected ISynchronizationContext getContext() { 166 if (participant != null) 167 return participant.getContext(); 168 return null; 169 } 170 171 174 protected String getPreviewRequestMessage() { 175 if (!isPreviewRequested()) { 176 return TeamUIMessages.ResourceMappingMergeOperation_4; 177 } 178 return super.getPreviewRequestMessage(); 179 } 180 181 192 protected ModelSynchronizeParticipant createParticipant() { 193 return ModelSynchronizeParticipant.createParticipant(createMergeContext(), getJobName()); 194 } 195 196 205 protected abstract SynchronizationContext createMergeContext(); 206 207 } 208 | Popular Tags |