Class CompareUIPlugin

All Implemented Interfaces:
BundleActivator

public final class CompareUIPlugin extends AbstractUIPlugin
The Compare UI plug-in defines the entry point to initiate a configurable compare operation on arbitrary resources. The result of the compare is opened into a compare editor where the details can be browsed and edited in dynamically selected structure and content viewers.

The Compare UI provides a registry for content and structure compare viewers, which is initialized from extensions contributed to extension points declared by this plug-in.

This class is the plug-in runtime class for the "org.eclipse.compare" plug-in.

  • Field Details

  • Constructor Details

    • CompareUIPlugin

      public CompareUIPlugin()
      Creates the CompareUIPlugin object and registers all structure creators, content merge viewers, and structure merge viewers contributed to this plug-in's extension points.

      Note that instances of plug-in runtime classes are automatically created by the platform in the course of plug-in activation.

  • Method Details

    • start

      public void start(BundleContext context) throws Exception
      Description copied from class: AbstractUIPlugin
      The AbstractUIPlugin implementation of this Plugin method refreshes the plug-in actions. Subclasses may extend this method, but must send super first. Starts up this plug-in.

      This method should be overridden in subclasses that need to do something when this plug-in is started. Implementors should call the inherited method at the first possible point to ensure that any system requirements can be met.

      If this method throws an exception, it is taken as an indication that plug-in initialization has failed; as a result, the plug-in will not be activated; moreover, the plug-in will be marked as disabled and ineligible for activation for the duration.

      Note 1: This method is automatically invoked by the platform the first time any code in the plug-in is executed.

      Note 2: This method is intended to perform simple initialization of the plug-in environment. The platform may terminate initializers that do not complete in a timely fashion.

      Note 3: The class loader typically has monitors acquired during invocation of this method. It is strongly recommended that this method avoid synchronized blocks or other thread locking mechanisms, as this would lead to deadlock vulnerability.

      Note 4: The supplied bundle context represents the plug-in to the OSGi framework. For security reasons, it is strongly recommended that this object should not be divulged.

      Note 5: This method and the Plugin.stop(BundleContext) may be called from separate threads, but the OSGi framework ensures that both methods will not be called simultaneously.

      Clients must never explicitly call this method.
      Specified by:
      start in interface BundleActivator
      Overrides:
      start in class AbstractUIPlugin
      Parameters:
      context - the bundle context for this plug-in
      Throws:
      Exception - if this plug-in did not start up properly
    • stop

      public void stop(BundleContext context) throws Exception
      Description copied from class: AbstractUIPlugin
      The AbstractUIPlugin implementation of this Plugin method saves this plug-in's preference and dialog stores and shuts down its image registry (if they are in use). Subclasses may extend this method, but must send super last. A try-finally statement should be used where necessary to ensure that super.stop() is always done. Stops this plug-in.

      This method should be re-implemented in subclasses that need to do something when the plug-in is shut down. Implementors should call the inherited method as late as possible to ensure that any system requirements can be met.

      Plug-in shutdown code should be robust. In particular, this method should always make an effort to shut down the plug-in. Furthermore, the code should not assume that the plug-in was started successfully.

      Note 1: If a plug-in has been automatically started, this method will be automatically invoked by the platform when the platform is shut down.

      Note 2: This method is intended to perform simple termination of the plug-in environment. The platform may terminate invocations that do not complete in a timely fashion.

      Note 3: The supplied bundle context represents the plug-in to the OSGi framework. For security reasons, it is strongly recommended that this object should not be divulged.

      Note 4: This method and the Plugin.start(BundleContext) may be called from separate threads, but the OSGi framework ensures that both methods will not be called simultaneously.

      Clients must never explicitly call this method.
      Specified by:
      stop in interface BundleActivator
      Overrides:
      stop in class AbstractUIPlugin
      Parameters:
      context - the bundle context for this plug-in
      Throws:
      Exception - if this method fails to shut down this plug-in
    • getDefault

      public static CompareUIPlugin getDefault()
      Returns the singleton instance of this plug-in runtime class.
      Returns:
      the compare plug-in instance
    • getResourceBundle

      public ResourceBundle getResourceBundle()
      Returns this plug-in's resource bundle.
      Returns:
      the plugin's resource bundle
    • getPluginId

      public static String getPluginId()
      Returns this plug-in's unique identifier.
      Returns:
      the plugin's unique identifier
    • getActiveWorkbench

      public static IWorkbench getActiveWorkbench()
    • getActiveWorkbenchWindow

      public static IWorkbenchWindow getActiveWorkbenchWindow()
    • getShell

      public static Shell getShell()
      If the workbench is running returns the SWT Shell of the active workbench window or null if no workbench window is active. If the workbench is not running, returns the shell of the default display.
      Returns:
      If the workbench is running, returns the SWT Shell of the active workbench window, or null if no workbench window is active. Otherwise returns the shell of the default display.
    • disposeOnShutdown

      public static void disposeOnShutdown(Image image)
      Registers the given image for being disposed when this plug-in is shutdown.
      Parameters:
      image - the image to register for disposal
    • openCompareEditor

      public void openCompareEditor(CompareEditorInput input, IWorkbenchPage page, IReusableEditor editor, boolean activate)
      Performs the comparison described by the given input and opens a compare editor on the result.
      Parameters:
      input - the input on which to open the compare editor
      page - the workbench page on which to create a new compare editor
      editor - if not null the input is opened in this editor
      activate - if true the editor will be activated
      See Also:
    • openCompareDialog

      public void openCompareDialog(CompareEditorInput input)
      Performs the comparison described by the given input and opens a compare dialog on the result.
      Parameters:
      input - the input on which to open the compare editor
      See Also:
    • prepareInput

      public IStatus prepareInput(CompareEditorInput input, IProgressMonitor monitor)
    • compareResultOK

      public boolean compareResultOK(CompareEditorInput input, IRunnableContext context)
    • registerImageDescriptor

      public static void registerImageDescriptor(String type, ImageDescriptor descriptor)
      Registers an image descriptor for the given type.
      Parameters:
      type - the type
      descriptor - the image descriptor
    • getImageDescriptor

      public static ImageDescriptor getImageDescriptor(String relativePath)
    • getImage

      public static Image getImage(String type)
      Returns a shared image for the given type, or a generic image if none has been registered for the given type.

      Note: Images returned from this method will be automatically disposed of when this plug-in shuts down. Callers must not dispose of these images themselves.

      Parameters:
      type - the type
      Returns:
      the image
    • getImage

      public static Image getImage(IAdaptable adaptable)
      Returns a shared image for the given adaptable. This convenience method queries the given adaptable for its IWorkbenchAdapter.getImageDescriptor, which it uses to create an image if it does not already have one.

      Note: Images returned from this method will be automatically disposed of when this plug-in shuts down. Callers must not dispose of these images themselves.

      Parameters:
      adaptable - the adaptable for which to find an image
      Returns:
      an image
    • getStructureCreator

      public StructureCreatorDescriptor getStructureCreator(String type)
      Returns an structure creator descriptor for the given type.
      Parameters:
      type - the type for which to find a descriptor
      Returns:
      a descriptor for the given type, or null if no descriptor has been registered
    • createStreamMerger

      public IStreamMerger createStreamMerger(String type)
      Returns a stream merger for the given type.
      Parameters:
      type - the type for which to find a stream merger
      Returns:
      a stream merger for the given type, or null if no stream merger has been registered
    • createStreamMerger

      public IStreamMerger createStreamMerger(IContentType type)
      Returns a stream merger for the given content type.
      Parameters:
      type - the type for which to find a stream merger
      Returns:
      a stream merger for the given type, or null if no stream merger has been registered
    • findStructureViewerDescriptor

      public ViewerDescriptor[] findStructureViewerDescriptor(Viewer oldViewer, ICompareInput input, CompareConfiguration configuration)
    • findStructureViewer

      public Viewer findStructureViewer(Viewer oldViewer, ICompareInput input, Composite parent, CompareConfiguration configuration)
      Returns a structure compare viewer based on an old viewer and an input object. If the old viewer is suitable for showing the input, the old viewer is returned. Otherwise, the input's type is used to find a viewer descriptor in the registry which in turn is used to create a structure compare viewer under the given parent composite. If no viewer descriptor can be found null is returned.
      Parameters:
      oldViewer - a new viewer is only created if this old viewer cannot show the given input
      input - the input object for which to find a structure viewer
      parent - the SWT parent composite under which the new viewer is created
      configuration - a configuration which is passed to a newly created viewer
      Returns:
      the compare viewer which is suitable for the given input object or null
    • findCompareFilters

      public CompareFilterDescriptor[] findCompareFilters(Object in)
    • findContentViewerDescriptor

      public ViewerDescriptor[] findContentViewerDescriptor(Viewer oldViewer, Object in, CompareConfiguration cc)
    • findContentViewer

      public Viewer findContentViewer(Viewer oldViewer, Object in, Composite parent, CompareConfiguration cc)
      Returns a content compare viewer based on an old viewer and an input object. If the old viewer is suitable for showing the input the old viewer is returned. Otherwise the input's type is used to find a viewer descriptor in the registry which in turn is used to create a content compare viewer under the given parent composite. If no viewer descriptor can be found null is returned.
      Parameters:
      oldViewer - a new viewer is only created if this old viewer cannot show the given input
      in - the input object for which to find a content viewer
      parent - the SWT parent composite under which the new viewer is created
      cc - a configuration which is passed to a newly created viewer
      Returns:
      the compare viewer which is suitable for the given input object or null
    • addStructureViewerAlias

      public void addStructureViewerAlias(String type, String alias)
    • removeAllStructureViewerAliases

      public void removeAllStructureViewerAliases(String type)
    • filter

      public boolean filter(String name, boolean isFolder, boolean isArchive)
    • handleNoDifference

      protected void handleNoDifference()
    • getDirtyEditors

      public static IEditorPart[] getDirtyEditors()
      Returns an array of all editors that have an unsaved content. If the identical content is presented in more than one editor, only one of those editor parts is part of the result.
      Returns:
      an array of all dirty editor parts.
    • logErrorMessage

      public static void logErrorMessage(String message)
    • log

      public static void log(Throwable e)
    • log

      public static void log(IStatus status)