Package org.eclipse.compare.patch
Class ApplyPatchOperation
java.lang.Object
org.eclipse.compare.patch.ApplyPatchOperation
- All Implemented Interfaces:
Runnable
An operation that provides an interface to the Apply Patch Wizard. Users specify
the input in terms of an
IStorage
(note: input must be in unified diff
format), an IResource
target to apply the patch to and can provide CompareConfiguration
elements to supply the label and images used on the preview page and hunk merge page. Finally, the
user can also supply a title and image to override the default ones provided by the Apply Patch Wizard.
Note that the Apply Patch Wizard does not require any particular set of inputs, and in the absence of
any user supplied values, it will work in default mode.- Since:
- 3.3
-
Constructor Summary
ConstructorDescriptionApplyPatchOperation
(IWorkbenchPart targetPart, IResource resource) Create an operation for the given part and resource.ApplyPatchOperation
(IWorkbenchPart part, IStorage patch, IResource target, CompareConfiguration configuration) Creates a new ApplyPatchOperation with the supplied compare configuration, patch and target. -
Method Summary
Modifier and TypeMethodDescriptionprotected Shell
getShell()
Return the parent shell to be used when the wizard is opened.static boolean
Return whether the given storage contains a patch.void
Open the Apply Patch wizard using the values associated with this operation.static IFilePatch[]
parsePatch
(IStorage storage) Parse the given patch and return the set of file patches that it contains.void
run()
protected void
This method will save all dirty editors.void
setPatchWizardImageDescriptor
(ImageDescriptor descriptor) Sets the image descriptor to use in the patch wizard.void
setPatchWizardTitle
(String title) Sets the title of the patch wizard.
-
Constructor Details
-
ApplyPatchOperation
public ApplyPatchOperation(IWorkbenchPart part, IStorage patch, IResource target, CompareConfiguration configuration) Creates a new ApplyPatchOperation with the supplied compare configuration, patch and target. The behaviour of the Apply Patch wizard is controlled by the number of parameters supplied:- If a patch is supplied, the initial input page is skipped. If a patch is not supplied the wizard will open on the input page.
- If the patch is a workspace patch, the target selection page is skipped and the preview page is displayed.
- If the patch is not a workspace patch and the target is specified, the target page is still shown with the target selected.
- Parameters:
part
- an IWorkbenchPart ornull
patch
- an IStorage containing a patch in unified diff format ornull
target
- an IResource which the patch is to be applied to ornull
configuration
- a CompareConfiguration supplying the labels and images for the preview patch page
-
ApplyPatchOperation
Create an operation for the given part and resource. This method is a convenience method that callsApplyPatchOperation(IWorkbenchPart, IStorage, IResource, CompareConfiguration)
with appropriate defaults for the other parameters.- Parameters:
targetPart
- an IResource which the patch is to be applied to ornull
resource
- an IResource which the patch is to be applied to ornull
- See Also:
-
-
Method Details
-
isPatch
Return whether the given storage contains a patch.- Parameters:
storage
- the storage- Returns:
- whether the given storage contains a patch
- Throws:
CoreException
- if an error occurs reading the contents from the storage
-
parsePatch
Parse the given patch and return the set of file patches that it contains.- Parameters:
storage
- the storage that contains the patch- Returns:
- the set of file patches that the storage contains
- Throws:
CoreException
- if an error occurs reading the contents from the storage
-
openWizard
public void openWizard()Open the Apply Patch wizard using the values associated with this operation. This method must be called from the UI thread. -
getShell
Return the parent shell to be used when the wizard is opened. By default, the site of the part is used to get the shell. Subclasses may override.- Returns:
- the parent shell to be used when the wizard is opened
-
saveAllEditors
protected void saveAllEditors()This method will save all dirty editors. It will prompt the user if the Compare preference to save dirty editors before viewing a patch isfalse
. Clients can use this or provide their own implementation. -
setPatchWizardTitle
Sets the title of the patch wizard. Needs to be set beforeopenWizard()
is called.- Parameters:
title
- a string to display in the title bar
-
setPatchWizardImageDescriptor
Sets the image descriptor to use in the patch wizard. Needs to be set beforeopenWizard()
is called.- Parameters:
descriptor
- an image descriptor
-
run
public void run()
-