Package org.eclipse.team.ui.synchronize
Class ModelMergeOperation
java.lang.Object
org.eclipse.core.runtime.jobs.JobChangeAdapter
org.eclipse.team.ui.TeamOperation
org.eclipse.team.ui.synchronize.ModelOperation
org.eclipse.team.ui.synchronize.ModelMergeOperation
- All Implemented Interfaces:
IJobChangeListener
,IRunnableWithProgress
- Direct Known Subclasses:
ModelParticipantMergeOperation
A model operation that executes a merge according to the merge lifecycle
associated with an
IMergeContext
and IResourceMappingMerger
instances obtained from the model providers involved.- Since:
- 3.2
-
Constructor Summary
ModifierConstructorDescriptionprotected
ModelMergeOperation
(IWorkbenchPart part, ISynchronizationScopeManager manager) Create a model merge operation. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
execute
(IProgressMonitor monitor) Perform a merge.protected void
executeMerge
(IProgressMonitor monitor) Perform a merge.protected void
handleMergeFailure
(IStatus status) Method invoked when the context contains unmergable changes.protected void
Method invoked when the context contains no changes.protected void
A preview of the merge has been requested.protected void
handleValidationFailure
(IStatus status) Method invoked when the context contains changes that failed validation by at least oneIResourceMappingMerger
.protected boolean
Return whether the context of this operation has changes that are of interest to the operation.protected abstract void
initializeContext
(IProgressMonitor monitor) Initialize the merge context for this merge operation.protected IStatus
performMerge
(ModelProvider provider, IProgressMonitor monitor) Attempt to merge all the mappings that come from the given provider.protected IStatus
performMerge
(IProgressMonitor monitor) Attempt a headless merge of the elements in the context of this operation.static IStatus
validateMerge
(IMergeContext context, IProgressMonitor monitor) Validate the merge context with the model providers that have mappings in the scope of the context.Methods inherited from class org.eclipse.team.ui.synchronize.ModelOperation
beginOperation, endOperation, getContext, getPreviewRequestMessage, getScope, getScopeManager, initializeScope, isPreviewRequested, promptForInputChange, promptIfInputChange, run, sortByExtension
Methods inherited from class org.eclipse.team.ui.TeamOperation
belongsTo, canRunAsJob, getGotoAction, getJobName, getKeepOperation, getOperationIcon, getPart, getSchedulingRule, getShell, isKeepOneProgressServiceEntry, isPostponeAutobuild, isSameFamilyAs, isUserInitiated, run, shouldRun
Methods inherited from class org.eclipse.core.runtime.jobs.JobChangeAdapter
aboutToRun, awake, done, running, scheduled, sleeping
-
Constructor Details
-
ModelMergeOperation
Create a model merge operation.- Parameters:
part
- the workbench part from which the operation was requested ornull
manager
- the scope manager
-
-
Method Details
-
validateMerge
Validate the merge context with the model providers that have mappings in the scope of the context. TheIResourceMappingMerger
for each model provider will be consulted and any non-OK status will be accumulated and returned,- Parameters:
context
- the merge context being validatedmonitor
- a progress monitor- Returns:
- a status or multi-status that identify any conditions that should force a preview of the merge
-
execute
protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException Perform a merge. FirstinitializeContext(IProgressMonitor)
is called to determine the set of resource changes. Then theexecuteMerge(IProgressMonitor)
method is invoked.- Specified by:
execute
in classModelOperation
- Parameters:
monitor
- a progress monitor- Throws:
InvocationTargetException
- if an error occursInterruptedException
- if operation is interrupted
-
executeMerge
Perform a merge. This method is invoked fromexecute(IProgressMonitor)
after the context has been initialized. If there are changes in the context, they will be validating by callingvalidateMerge(IMergeContext, IProgressMonitor)
. If there are no validation problems,performMerge(IProgressMonitor)
will then be called to perform the merge. If there are problems encountered or if a preview was requested,handlePreviewRequest()
is called.- Parameters:
monitor
- a progress monitor- Throws:
CoreException
-
handlePreviewRequest
protected void handlePreviewRequest()A preview of the merge has been requested. By default, this method does nothing. Subclasses that wish to support previewing must override this method to preview the merge and theModelOperation.getPreviewRequestMessage()
to have the option presented to the user if the scope changes. -
initializeContext
Initialize the merge context for this merge operation. After this method is invoked, theModelOperation.getContext()
method must return an instance ofIMergeContext
that is fully initialized.- Parameters:
monitor
- a progress monitor- Throws:
CoreException
- if an error occurs
-
handleValidationFailure
Method invoked when the context contains changes that failed validation by at least oneIResourceMappingMerger
. By default, the user is prompted to inform them that unmergeable changes were found and thehandlePreviewRequest()
method is invoked. Subclasses may override.- Parameters:
status
- the status returned from the mergers that reported the validation failures
-
handleMergeFailure
Method invoked when the context contains unmergable changes. By default, the user is prompted to inform them that unmergeable changes were found. Subclasses may override.- Parameters:
status
- the status returned from the merger that reported the conflict
-
handleNoChanges
protected void handleNoChanges()Method invoked when the context contains no changes. By default, the user is prompted to inform them that no changes were found. Subclasses may override. -
performMerge
Attempt a headless merge of the elements in the context of this operation. The merge is performed by obtaining theIResourceMappingMerger
for the model providers in the context's scope. The merger of the model providers are invoked in the order determined by theModelOperation.sortByExtension(ModelProvider[])
method. The method will stop on the first conflict encountered. This method will throw a runtime exception if the operation does not have a merge context.- Parameters:
monitor
- a progress monitor- Returns:
- a status that indicates whether the merge succeeded.
- Throws:
CoreException
- if an error occurred
-
performMerge
protected IStatus performMerge(ModelProvider provider, IProgressMonitor monitor) throws CoreException Attempt to merge all the mappings that come from the given provider. Return a status which indicates whether the merge succeeded or if unmergeable conflicts were found. By default, this method invokes theIResourceMappingMerger.merge(IMergeContext, IProgressMonitor)
method but does not wait for the context to update (seeISynchronizationContext
. Callers that are invoking the merge on multiple models should wait until the context has updated before invoking merge on another merger. The following line of code will wait for the context to update:Job.getJobManager().join(getContext(), monitor);
This method will throw a runtime exception if the operation does not have a merge context.
- Parameters:
provider
- the model provider whose mappings are to be mergedmonitor
- a progress monitor- Returns:
- a non-OK status if there were unmergable conflicts
- Throws:
CoreException
- if an error occurred
-
hasChangesOfInterest
protected boolean hasChangesOfInterest()Return whether the context of this operation has changes that are of interest to the operation. Subclasses may override.- Returns:
- whether the context of this operation has changes that are of interest to the operation
-