Class ThreeSideTextMergeViewer
- java.lang.Object
-
- org.eclipse.jface.viewers.Viewer
-
- org.eclipse.jface.viewers.ContentViewer
-
- com._1c.g5.v8.dt.compare.ui.mergeviewer.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 theContentViewer
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 Summary
Fields Modifier and Type Field Description protected org.eclipse.compare.internal.merge.DocumentMerger
leftToResultMerger
The document merge to manage differences between the left and merge result sidesprotected org.eclipse.compare.internal.merge.DocumentMerger
rightToResultMerger
The document merger to manage differences between the right and merge result sides-
Fields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY
-
-
Constructor Summary
Constructors Constructor Description 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
protected void
configureTextViewer(org.eclipse.jface.text.TextViewer textViewer)
Configures the passed text viewer.void
copyAll(boolean fromLeft)
Copies all content from the left/right to the merge result side.void
copyDiffFromLeft()
Copies the current diff from the left to the merge result side.void
copyDiffFromRight()
Copies the current diff from the right to the merge result side.protected org.eclipse.compare.internal.merge.DocumentMerger
createDocumentMerger(boolean left)
Creates a document merger for the one side of comparison.protected org.eclipse.compare.internal.merge.DocumentMerger.IDocumentMergerInput
createDocumentMergerInput(boolean left)
Creates aDocumentMerger
input.protected org.eclipse.jface.text.source.SourceViewer
createSourceViewer(org.eclipse.swt.widgets.Composite parent)
Creates a new source viewer.protected void
createToolItems(org.eclipse.jface.action.IToolBarManager leftToolBarManager, org.eclipse.jface.action.IToolBarManager rightToolBarManager)
Contributes items to the given tool bar manager.protected boolean
doSave(Object newInput, Object oldInput)
This method is called from theViewer.inputChanged(java.lang.Object, java.lang.Object)
to save any unsaved changes of the old input.void
flush(org.eclipse.core.runtime.IProgressMonitor monitor)
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.protected org.eclipse.compare.CompareConfiguration
getCompareConfiguration()
Returns the compare configuration of this viewer.org.eclipse.swt.widgets.Control
getControl()
protected int
getDirectionAreaWidth()
Returns the direction area width.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)
String
getResultContent()
Returns the merge result area content.ISelection
getSelection()
void
goToNextChange(boolean onLeft)
Goes to the next change on the left/right side and select its.void
goToNextDifference(boolean onLeft)
Goes to the next difference on the left/right side and select its.void
goToNextMergeConflict()
Goes to the next merge conflict.void
goToPreviousChange(boolean onLeft)
Goes to the previous change on the left/right side and select its.void
goToPreviousConflict()
Goes to the previous merge conflict.void
goToPreviousDifference(boolean onLeft)
Goes to the previous difference on the left/right side and select its.protected void
handleDispose(org.eclipse.swt.events.DisposeEvent event)
protected void
handleMergeInputChange()
Handle a change to the given input reported from theICompareInputChangeListener
.protected void
handlePropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent event)
Handles property change event.protected void
inputChanged(Object input, Object oldInput)
protected void
invalidateLines()
Recalculates the content width for all lines in the bounds.protected boolean
isResultDirty()
Return the dirty state of the merge result side of this viewer.protected boolean
isSynchronizedScrolling()
Checks whether the synchronized scrolling mode is active.void
refresh()
void
removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
protected void
setEditable(org.eclipse.jface.text.source.ISourceViewer sourceViewer, boolean state)
Sets the editable state of the given source viewer.void
setResultContent(String newResultConent)
Updates the merge result area content.protected void
setResultDirty(boolean dirty)
Sets the dirty state of the merge result side of this viewer.void
setSelection(ISelection selection, boolean reveal)
void
updateComparison()
Updates the comparison between the left and merge result and the merge result and right sides and updates presentation.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.protected void
updateFont()
Sets a new font to render text with.protected void
updatePresentation()
Updates text presentation of all side merge source viewers.protected void
updateToolItems()
Updates the tool items.-
Methods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput, getLabelProvider, handleLabelProviderChanged, hookControl, labelProviderChanged, setContentProvider, setInput, setLabelProvider
-
Methods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection
-
-
-
-
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 benull
compareConfiguration
- the compare configuration, can not benull
serviceLocator
- the service locator, can not benull
-
-
Method Detail
-
getControl
public org.eclipse.swt.widgets.Control getControl()
- Specified by:
getControl
in classViewer
-
getSelection
public ISelection getSelection()
- Specified by:
getSelection
in interfaceISelectionProvider
- Specified by:
getSelection
in classViewer
-
setSelection
public void setSelection(ISelection selection, boolean reveal)
- Specified by:
setSelection
in classViewer
-
flush
public void flush(org.eclipse.core.runtime.IProgressMonitor monitor)
- Specified by:
flush
in interfaceorg.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 andfalse
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 benull
-
addPropertyChangeListener
public void addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
- Specified by:
addPropertyChangeListener
in interfaceorg.eclipse.compare.IPropertyChangeNotifier
-
removePropertyChangeListener
public void removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
- Specified by:
removePropertyChangeListener
in interfaceorg.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 andfalse
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 andfalse
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 andfalse
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 andfalse
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.
-
inputChanged
protected final void inputChanged(Object input, Object oldInput)
- Overrides:
inputChanged
in classViewer
-
handleDispose
protected void handleDispose(org.eclipse.swt.events.DisposeEvent event)
- Overrides:
handleDispose
in classContentViewer
-
isSynchronizedScrolling
protected boolean isSynchronizedScrolling()
Checks whether the synchronized scrolling mode is active.- Returns:
true
if the ynchronized scrolling mode is active andfalse
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 sidesfalse
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 benull
leftToolBarManager
- the right toolbar manager to contribute to, can not benull
-
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 benull
right
- the input for the left side area, can not benull
mergeResult
- the input for the merge result side area, can not benull
absentObjectMessage
- the absent object message, can not benull
-
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 benull
-
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 benull
- 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 benull
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 aPropertyChangeEvent
with the property nameThreeSideTextMergeEditorInput.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 aDocumentMerger
input.- Returns:
- the newly created
DocumentMerger
input, nevernull
-
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 benull
monitor
- the progress monitor, may benull
-
doSave
protected boolean doSave(Object newInput, Object oldInput)
This method is called from theViewer.inputChanged(java.lang.Object, java.lang.Object)
to save any unsaved changes of the old input.- Parameters:
newInput
- the new input of this viewer, ornull
if there is no new inputoldInput
- the old input element, ornull
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 theICompareInputChangeListener
.
-
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 benull
-
updateFont
protected void updateFont()
Sets a new font to render text with.- Parameters:
font
- new font, cannot benull
-
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)
-
-