Class ApplyPatchOperation

java.lang.Object
org.eclipse.compare.patch.ApplyPatchOperation
All Implemented Interfaces:
Runnable

public class ApplyPatchOperation extends Object implements 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 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 or null
      patch - an IStorage containing a patch in unified diff format or null
      target - an IResource which the patch is to be applied to or null
      configuration - a CompareConfiguration supplying the labels and images for the preview patch page
    • ApplyPatchOperation

      public ApplyPatchOperation(IWorkbenchPart targetPart, IResource resource)
      Create an operation for the given part and resource. This method is a convenience method that calls ApplyPatchOperation(IWorkbenchPart, IStorage, IResource, CompareConfiguration) with appropriate defaults for the other parameters.
      Parameters:
      targetPart - an IResource which the patch is to be applied to or null
      resource - an IResource which the patch is to be applied to or null
      See Also:
  • Method Details

    • isPatch

      public static boolean isPatch(IStorage storage) throws CoreException
      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

      public static IFilePatch[] parsePatch(IStorage storage) throws CoreException
      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

      protected Shell 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 is false. Clients can use this or provide their own implementation.
    • setPatchWizardTitle

      public void setPatchWizardTitle(String title)
      Sets the title of the patch wizard. Needs to be set before openWizard() is called.
      Parameters:
      title - a string to display in the title bar
    • setPatchWizardImageDescriptor

      public void setPatchWizardImageDescriptor(ImageDescriptor descriptor)
      Sets the image descriptor to use in the patch wizard. Needs to be set before openWizard() is called.
      Parameters:
      descriptor - an image descriptor
    • run

      public void run()
      Specified by:
      run in interface Runnable