Class ThreeSideTextMergeViewer

  • All Implemented Interfaces:
    org.eclipse.compare.contentmergeviewer.IFlushable, org.eclipse.compare.IPropertyChangeNotifier, IInputProvider, IInputSelectionProvider, ISelectionProvider
    Direct Known Subclasses:
    XtextThreeSideTextMergeViewer

    public class ThreeSideTextMergeViewer
    extends ContentViewer
    implements org.eclipse.compare.IPropertyChangeNotifier, org.eclipse.compare.contentmergeviewer.IFlushable
    A three side text merge viewer allows clients to compare and merge textual document via running 2-/3-way compare algorithms. It is based on the ContentViewer and uses textual viewers to implement the left, right and merge result (middle) content areas.

    Clients should implement IThreeSideTextMergeViewerProvider in order to viewer actions work correctly.

    • Field Detail

      • leftToResultMerger

        protected org.eclipse.compare.internal.merge.DocumentMerger leftToResultMerger
        The document merge to manage differences between the left and merge result sides
      • rightToResultMerger

        protected org.eclipse.compare.internal.merge.DocumentMerger rightToResultMerger
        The document merger to manage differences between the right and merge result sides
    • Constructor Detail

      • ThreeSideTextMergeViewer

        public ThreeSideTextMergeViewer​(org.eclipse.swt.widgets.Composite parent,
                                        org.eclipse.compare.CompareConfiguration compareConfiguration,
                                        org.eclipse.ui.services.IServiceLocator serviceLocator)
        Creates a text merge viewer under the given parent control.
        Parameters:
        parent - the parent control, can not be null
        compareConfiguration - the compare configuration, can not be null
        serviceLocator - the service locator, can not be null
    • Method Detail

      • getControl

        public org.eclipse.swt.widgets.Control getControl()
        Specified by:
        getControl in class Viewer
      • refresh

        public void refresh()
        Specified by:
        refresh in class Viewer
      • flush

        public void flush​(org.eclipse.core.runtime.IProgressMonitor monitor)
        Specified by:
        flush in interface org.eclipse.compare.contentmergeviewer.IFlushable
      • copyDiffFromLeft

        public void copyDiffFromLeft()
        Copies the current diff from the left to the merge result side.
      • copyDiffFromRight

        public void copyDiffFromRight()
        Copies the current diff from the right to the merge result side.
      • copyAll

        public void copyAll​(boolean fromLeft)
        Copies all content from the left/right to the merge result side.
        Parameters:
        fromLeft - true if you need to copy all content from the left side and false to copy from the right side
      • getResultContent

        public String getResultContent()
        Returns the merge result area content.
        Returns:
        the merge result area content, never null
      • setResultContent

        public void setResultContent​(String newResultConent)
        Updates the merge result area content.
        Parameters:
        newResultConent - a new merge result area content to set, can not be null
      • addPropertyChangeListener

        public void addPropertyChangeListener​(org.eclipse.jface.util.IPropertyChangeListener listener)
        Specified by:
        addPropertyChangeListener in interface org.eclipse.compare.IPropertyChangeNotifier
      • removePropertyChangeListener

        public void removePropertyChangeListener​(org.eclipse.jface.util.IPropertyChangeListener listener)
        Specified by:
        removePropertyChangeListener in interface org.eclipse.compare.IPropertyChangeNotifier
      • updateComparison

        public void updateComparison()
        Updates the comparison between the left and merge result and the merge result and right sides and updates presentation.
      • goToNextDifference

        public void goToNextDifference​(boolean onLeft)
        Goes to the next difference on the left/right side and select its.
        Parameters:
        onLeft - true if the next difference is on the left side and false if it is on the right side
      • goToPreviousDifference

        public void goToPreviousDifference​(boolean onLeft)
        Goes to the previous difference on the left/right side and select its.
        Parameters:
        onLeft - true if the previous difference is on the left side and false if it is on the right side
      • goToNextChange

        public void goToNextChange​(boolean onLeft)
        Goes to the next change on the left/right side and select its.
        Parameters:
        onLeft - true if the next change is on the left side and false if it is on the right side
      • goToPreviousChange

        public void goToPreviousChange​(boolean onLeft)
        Goes to the previous change on the left/right side and select its.
        Parameters:
        onLeft - true if the previous change is on the left side and false if it is on the right side
      • goToNextMergeConflict

        public void goToNextMergeConflict()
        Goes to the next merge conflict.
      • goToPreviousConflict

        public void goToPreviousConflict()
        Goes to the previous merge conflict.
      • handleDispose

        protected void handleDispose​(org.eclipse.swt.events.DisposeEvent event)
        Overrides:
        handleDispose in class ContentViewer
      • isSynchronizedScrolling

        protected boolean isSynchronizedScrolling()
        Checks whether the synchronized scrolling mode is active.
        Returns:
        true if the ynchronized scrolling mode is active and false otherwise
      • getCompareConfiguration

        protected org.eclipse.compare.CompareConfiguration getCompareConfiguration()
        Returns the compare configuration of this viewer.
        Returns:
        the compare configuration, never null
      • getDirectionAreaWidth

        protected int getDirectionAreaWidth()
        Returns the direction area width.
        Returns:
        the direction area width
      • createDocumentMerger

        protected org.eclipse.compare.internal.merge.DocumentMerger createDocumentMerger​(boolean left)
        Creates a document merger for the one side of comparison.
        Parameters:
        left - true if it is needed to create a document merger to compare the left and the merge result sides false to compare the right and the merge result sides
        Returns:
        the newly created document merger, can not be null
      • createToolItems

        protected void createToolItems​(org.eclipse.jface.action.IToolBarManager leftToolBarManager,
                                       org.eclipse.jface.action.IToolBarManager rightToolBarManager)
        Contributes items to the given tool bar manager.
        Parameters:
        leftToolBarManager - the left toolbar manager to contribute to, can not be null
        leftToolBarManager - the right toolbar manager to contribute to, can not be null
      • updateToolItems

        protected void updateToolItems()
        Updates the tool items.
      • updateContent

        protected void updateContent​(Object left,
                                     Object right,
                                     Object mergeResult,
                                     String absentObjectMessage)
        Initializes the text viewers of the three content areas with the given input objects.
        Parameters:
        left - the input for the left side area, can not be null
        right - the input for the left side area, can not be null
        mergeResult - the input for the merge result side area, can not be null
        absentObjectMessage - the absent object message, can not be null
      • configureTextViewer

        protected void configureTextViewer​(org.eclipse.jface.text.TextViewer textViewer)
        Configures the passed text viewer. This method is called after the three text viewers have been created for the content areas.
        Parameters:
        textViewer - the text viewer to configure, can not be null
      • createSourceViewer

        protected org.eclipse.jface.text.source.SourceViewer createSourceViewer​(org.eclipse.swt.widgets.Composite parent)
        Creates a new source viewer. This method is called when creating and initializing the content areas of the merge viewer.
        Parameters:
        parent - the parent of the viewer's control, can not be null
        Returns:
        the newly created source viewer, never null
      • setEditable

        protected void setEditable​(org.eclipse.jface.text.source.ISourceViewer sourceViewer,
                                   boolean state)
        Sets the editable state of the given source viewer.
        Parameters:
        sourceViewer - the given source viewer, can not be null
        state - the state to set
      • isResultDirty

        protected boolean isResultDirty()
        Return the dirty state of the merge result side of this viewer.
        Returns:
        the dirty state of the merge result side
      • setResultDirty

        protected void setResultDirty​(boolean dirty)
        Sets the dirty state of the merge result side of this viewer. If the new value differs from the old all registered listener are notified with a PropertyChangeEvent with the property name ThreeSideTextMergeEditorInput.DIRTY_STATE
        Parameters:
        dirty - the state of the merge result side dirty flag
      • updatePresentation

        protected void updatePresentation()
        Updates text presentation of all side merge source viewers. Redraws diff blocks between the left and merge result sides and the merge result and right sides.
      • createDocumentMergerInput

        protected org.eclipse.compare.internal.merge.DocumentMerger.IDocumentMergerInput createDocumentMergerInput​(boolean left)
        Creates a DocumentMerger input.
        Returns:
        the newly created DocumentMerger input, never null
      • flushResultContent

        protected void flushResultContent​(Object input,
                                          org.eclipse.core.runtime.IProgressMonitor monitor)
        Flushes the modified merge result side content back to input elements via the content provider.
        Parameters:
        input - the merge viewer input, can not be null
        monitor - the progress monitor, may be null
      • doSave

        protected boolean doSave​(Object newInput,
                                 Object oldInput)
        This method is called from the Viewer.inputChanged(java.lang.Object, java.lang.Object) to save any unsaved changes of the old input.
        Parameters:
        newInput - the new input of this viewer, or null if there is no new input
        oldInput - the old input element, or null if there was previously no input
        Returns:
        true if saving was successful, or if the user didn't want to save by pressing 'NO' in the confirmation dialog
      • handleMergeInputChange

        protected void handleMergeInputChange()
        Handle a change to the given input reported from the ICompareInputChangeListener.
      • invalidateLines

        protected void invalidateLines()
        Recalculates the content width for all lines in the bounds.
      • handlePropertyChangeEvent

        protected void handlePropertyChangeEvent​(org.eclipse.jface.util.PropertyChangeEvent event)
        Handles property change event.
        Parameters:
        event - the property change event, cannot be null
      • updateFont

        protected void updateFont()
        Sets a new font to render text with.
        Parameters:
        font - new font, cannot be null
      • getPreviousDiff

        public static org.eclipse.compare.internal.merge.DocumentMerger.Diff getPreviousDiff​(List<org.eclipse.compare.internal.merge.DocumentMerger.Diff> diffs,
                                                                                             org.eclipse.compare.internal.merge.DocumentMerger.Diff currentNavigationDiff,
                                                                                             boolean deep)