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 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 Summary
FieldsModifier and TypeFieldDescriptionprotected org.eclipse.compare.internal.merge.DocumentMergerThe document merge to manage differences between the left and merge result sidesprotected org.eclipse.compare.internal.merge.DocumentMergerThe document merger to manage differences between the right and merge result sidesFields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY -
Constructor Summary
ConstructorsConstructorDescriptionThreeSideTextMergeViewer(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
Modifier and TypeMethodDescriptionvoidaddPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener) protected voidconfigureTextViewer(org.eclipse.jface.text.TextViewer textViewer) Configures the passed text viewer.voidcopyAll(boolean fromLeft) Copies all content from the left/right to the merge result side.voidCopies the current diff from the left to the merge result side.voidCopies the current diff from the right to the merge result side.protected org.eclipse.compare.internal.merge.DocumentMergercreateDocumentMerger(boolean left) Creates a document merger for the one side of comparison.protected org.eclipse.compare.internal.merge.DocumentMerger.IDocumentMergerInputcreateDocumentMergerInput(boolean left) Creates aDocumentMergerinput.protected org.eclipse.jface.text.source.SourceViewercreateSourceViewer(org.eclipse.swt.widgets.Composite parent) Creates a new source viewer.protected voidcreateToolItems(org.eclipse.jface.action.IToolBarManager leftToolBarManager, org.eclipse.jface.action.IToolBarManager rightToolBarManager) Contributes items to the given tool bar manager.protected booleanThis method is called from theViewer.inputChanged(java.lang.Object, java.lang.Object)to save any unsaved changes of the old input.voidflush(org.eclipse.core.runtime.IProgressMonitor monitor) protected voidflushResultContent(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.CompareConfigurationReturns the compare configuration of this viewer.org.eclipse.swt.widgets.Controlprotected intReturns the direction area width.static org.eclipse.compare.internal.merge.DocumentMerger.DiffgetPreviousDiff(List<org.eclipse.compare.internal.merge.DocumentMerger.Diff> diffs, org.eclipse.compare.internal.merge.DocumentMerger.Diff currentNavigationDiff, boolean deep) Returns the merge result area content.voidgoToNextChange(boolean onLeft) Goes to the next change on the left/right side and select its.voidgoToNextDifference(boolean onLeft) Goes to the next difference on the left/right side and select its.voidGoes to the next merge conflict.voidgoToPreviousChange(boolean onLeft) Goes to the previous change on the left/right side and select its.voidGoes to the previous merge conflict.voidgoToPreviousDifference(boolean onLeft) Goes to the previous difference on the left/right side and select its.protected voidhandleDispose(org.eclipse.swt.events.DisposeEvent event) protected voidHandle a change to the given input reported from theICompareInputChangeListener.protected voidhandlePropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent event) Handles property change event.protected final voidinputChanged(Object input, Object oldInput) protected voidRecalculates the content width for all lines in the bounds.protected booleanReturn the dirty state of the merge result side of this viewer.protected booleanChecks whether the synchronized scrolling mode is active.voidrefresh()voidremovePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener) protected voidsetEditable(org.eclipse.jface.text.source.ISourceViewer sourceViewer, boolean state) Sets the editable state of the given source viewer.voidsetResultContent(String newResultConent) Updates the merge result area content.protected voidsetResultDirty(boolean dirty) Sets the dirty state of the merge result side of this viewer.voidsetSelection(ISelection selection, boolean reveal) voidUpdates the comparison between the left and merge result and the merge result and right sides and updates presentation.protected voidupdateContent(Object left, Object right, Object mergeResult, String absentObjectMessage) Initializes the text viewers of the three content areas with the given input objects.protected voidSets a new font to render text with.protected voidUpdates text presentation of all side merge source viewers.protected voidUpdates the tool items.Methods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput, getLabelProvider, handleLabelProviderChanged, hookControl, labelProviderChanged, setContentProvider, setInput, setLabelProviderMethods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection
-
Field Details
-
leftToResultMerger
protected org.eclipse.compare.internal.merge.DocumentMerger leftToResultMergerThe document merge to manage differences between the left and merge result sides -
rightToResultMerger
protected org.eclipse.compare.internal.merge.DocumentMerger rightToResultMergerThe document merger to manage differences between the right and merge result sides
-
-
Constructor Details
-
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 benullcompareConfiguration- the compare configuration, can not benullserviceLocator- the service locator, can not benull
-
-
Method Details
-
getControl
public org.eclipse.swt.widgets.Control getControl()- Specified by:
getControlin classViewer
-
getSelection
- Specified by:
getSelectionin interfaceISelectionProvider- Specified by:
getSelectionin classViewer
-
refresh
public void refresh() -
setSelection
- Specified by:
setSelectionin classViewer
-
flush
public void flush(org.eclipse.core.runtime.IProgressMonitor monitor) - Specified by:
flushin 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-trueif you need to copy all content from the left side andfalseto copy from the right side
-
getResultContent
Returns the merge result area content.- Returns:
- the merge result area content, never
null
-
setResultContent
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:
addPropertyChangeListenerin interfaceorg.eclipse.compare.IPropertyChangeNotifier
-
removePropertyChangeListener
public void removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener) - Specified by:
removePropertyChangeListenerin 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-trueif the next difference is on the left side andfalseif 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-trueif the previous difference is on the left side andfalseif 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-trueif the next change is on the left side andfalseif 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-trueif the previous change is on the left side andfalseif 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
- Overrides:
inputChangedin classViewer
-
handleDispose
protected void handleDispose(org.eclipse.swt.events.DisposeEvent event) - Overrides:
handleDisposein classContentViewer
-
isSynchronizedScrolling
protected boolean isSynchronizedScrolling()Checks whether the synchronized scrolling mode is active.- Returns:
trueif the ynchronized scrolling mode is active andfalseotherwise
-
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-trueif it is needed to create a document merger to compare the left and the merge result sidesfalseto 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 benullleftToolBarManager- 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 benullright- the input for the left side area, can not benullmergeResult- the input for the merge result side area, can not benullabsentObjectMessage- 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 benullstate- 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 aPropertyChangeEventwith 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 aDocumentMergerinput.- Returns:
- the newly created
DocumentMergerinput, nevernull
-
flushResultContent
Flushes the modified merge result side content back to input elements via the content provider.- Parameters:
input- the merge viewer input, can not benullmonitor- the progress monitor, may benull
-
doSave
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, ornullif there is no new inputoldInput- the old input element, ornullif there was previously no input- Returns:
trueif 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)
-