Class DiffNode
- java.lang.Object
-
- org.eclipse.compare.structuremergeviewer.DiffElement
-
- org.eclipse.compare.structuremergeviewer.DiffContainer
-
- org.eclipse.compare.structuremergeviewer.DiffNode
-
- All Implemented Interfaces:
ITypedElement
,ICompareInput
,IDiffContainer
,IDiffElement
public class DiffNode extends DiffContainer implements ICompareInput
Diff node are used as the compare result of the differencing engine. Since it implements theITypedElement
andICompareInput
interfaces it can be used directly to display the compare result in aDiffTreeViewer
and as the input to any other compare/merge viewer.DiffNode
s are typically created as the result of performing a compare with theDifferencer
.Clients typically use this class as is, but may subclass if required.
- See Also:
DiffTreeViewer
,Differencer
-
-
Field Summary
-
Fields inherited from interface org.eclipse.compare.ITypedElement
FOLDER_TYPE, TEXT_TYPE, UNKNOWN_TYPE
-
-
Constructor Summary
Constructors Constructor Description DiffNode(int kind)
Creates a newDiffNode
with the given diff kind.DiffNode(int kind, ITypedElement ancestor, ITypedElement left, ITypedElement right)
Creates a newDiffNode
and initializes with the given values.DiffNode(ITypedElement left, ITypedElement right)
Creates a newDiffNode
with diff kindDifferencer.CHANGE
and initializes with the given values.DiffNode(IDiffContainer parent, int kind)
Creates a newDiffNode
and initializes with the given values.DiffNode(IDiffContainer parent, int kind, ITypedElement ancestor, ITypedElement left, ITypedElement right)
Creates a newDiffNode
and initializes with the given values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCompareInputChangeListener(ICompareInputChangeListener listener)
Registers a listener for changes of thisICompareInput
.void
copy(boolean leftToRight)
Copy one side (source) to the other side (destination) depending on the value ofleftToRight
.boolean
dontExpand()
Returnstrue
if this node shouldn't automatically be expanded in aDiffTreeViewer
.boolean
equals(Object other)
protected void
fireChange()
Sends out notification that a change has occurred on theICompareInput
.ITypedElement
getAncestor()
Returns the ancestor side of this input.ITypedElement
getId()
Returns the first not-null
input of this node.Image
getImage()
TheDiffElement
implementation of thisITypedInput
method returnsnull
.ITypedElement
getLeft()
Returns the left side of this input.String
getName()
Returns the (non-null
) name of the left or right side if they are identical.ITypedElement
getRight()
Returns the right side of this input.String
getType()
TheDiffElement
implementation of thisITypedElement
method returnsITypedElement.UNKNOWN_TYPE
.int
hashCode()
void
removeCompareInputChangeListener(ICompareInputChangeListener listener)
Unregisters aICompareInput
listener.void
setAncestor(ITypedElement ancestor)
Sets the ancestor input to the given value.void
setDontExpand(boolean dontExpand)
Controls whether this node is not automatically expanded when displayed in aDiffTreeViewer
.void
setLeft(ITypedElement left)
Sets the left input to the given value.void
setRight(ITypedElement right)
Sets the right input to the given value.-
Methods inherited from class org.eclipse.compare.structuremergeviewer.DiffContainer
add, findChild, getChildren, hasChildren, remove, removeToRoot
-
Methods inherited from class org.eclipse.compare.structuremergeviewer.DiffElement
getKind, getParent, setKind, setParent
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.compare.structuremergeviewer.ICompareInput
getKind
-
Methods inherited from interface org.eclipse.compare.structuremergeviewer.IDiffElement
getKind, getParent, setParent
-
-
-
-
Constructor Detail
-
DiffNode
public DiffNode(IDiffContainer parent, int kind, ITypedElement ancestor, ITypedElement left, ITypedElement right)
Creates a newDiffNode
and initializes with the given values.- Parameters:
parent
- under which the new container is added as a child ornull
kind
- of difference (defined inDifferencer
)ancestor
- the common ancestor input to a compareleft
- the left input to a compareright
- the right input to a compare
-
DiffNode
public DiffNode(ITypedElement left, ITypedElement right)
Creates a newDiffNode
with diff kindDifferencer.CHANGE
and initializes with the given values.- Parameters:
left
- the left input to a compareright
- the right input to a compare
-
DiffNode
public DiffNode(int kind, ITypedElement ancestor, ITypedElement left, ITypedElement right)
Creates a newDiffNode
and initializes with the given values.- Parameters:
kind
- of difference (defined inDifferencer
)ancestor
- the common ancestor input to a compareleft
- the left input to a compareright
- the right input to a compare
-
DiffNode
public DiffNode(int kind)
Creates a newDiffNode
with the given diff kind.- Parameters:
kind
- of difference (defined inDifferencer
)
-
DiffNode
public DiffNode(IDiffContainer parent, int kind)
Creates a newDiffNode
and initializes with the given values.- Parameters:
parent
- under which the new container is added as a child ornull
kind
- of difference (defined inDifferencer
)
-
-
Method Detail
-
addCompareInputChangeListener
public void addCompareInputChangeListener(ICompareInputChangeListener listener)
Registers a listener for changes of thisICompareInput
. Has no effect if an identical listener is already registered.- Specified by:
addCompareInputChangeListener
in interfaceICompareInput
- Parameters:
listener
- the listener to add
-
removeCompareInputChangeListener
public void removeCompareInputChangeListener(ICompareInputChangeListener listener)
Unregisters aICompareInput
listener. Has no effect if listener is not registered.- Specified by:
removeCompareInputChangeListener
in interfaceICompareInput
- Parameters:
listener
- the listener to remove
-
fireChange
protected void fireChange()
Sends out notification that a change has occurred on theICompareInput
.
-
dontExpand
public boolean dontExpand()
Returnstrue
if this node shouldn't automatically be expanded in aDiffTreeViewer
.- Returns:
true
if node shouldn't automatically be expanded
-
setDontExpand
public void setDontExpand(boolean dontExpand)
Controls whether this node is not automatically expanded when displayed in aDiffTreeViewer
.- Parameters:
dontExpand
- iftrue
this node is not automatically expanded inDiffTreeViewer
-
getId
public ITypedElement getId()
Returns the first not-null
input of this node. Method checks the three inputs in the order: ancestor, right, left.- Returns:
- the first not-
null
input of this node
-
getName
public String getName()
Returns the (non-null
) name of the left or right side if they are identical. Otherwise both names are concatenated (separated with a slash ('/')).Subclasses may re-implement to provide a different name for this node.
- Specified by:
getName
in interfaceICompareInput
- Specified by:
getName
in interfaceITypedElement
- Returns:
- the name of this node.
-
getImage
public Image getImage()
Description copied from class:DiffElement
TheDiffElement
implementation of thisITypedInput
method returnsnull
. Subclasses may re-implement to provide an image for this element.- Specified by:
getImage
in interfaceICompareInput
- Specified by:
getImage
in interfaceITypedElement
- Overrides:
getImage
in classDiffElement
- Returns:
null
.
-
getType
public String getType()
Description copied from class:DiffElement
TheDiffElement
implementation of thisITypedElement
method returnsITypedElement.UNKNOWN_TYPE
. Subclasses may re-implement to provide a type for this element.- Specified by:
getType
in interfaceITypedElement
- Overrides:
getType
in classDiffElement
- Returns:
ITypedElement.UNKNOWN_TYPE
.
-
setAncestor
public void setAncestor(ITypedElement ancestor)
Sets the ancestor input to the given value.- Parameters:
ancestor
- the new value for the ancestor input- Since:
- 3.0
-
getAncestor
public ITypedElement getAncestor()
Description copied from interface:ICompareInput
Returns the ancestor side of this input. Returnsnull
if this input has no ancestor or in the two-way compare case.- Specified by:
getAncestor
in interfaceICompareInput
- Returns:
- the ancestor of this input, or
null
-
setLeft
public void setLeft(ITypedElement left)
Sets the left input to the given value.- Parameters:
left
- the new value for the left input
-
getLeft
public ITypedElement getLeft()
Description copied from interface:ICompareInput
Returns the left side of this input. Returnsnull
if there is no left side (deletion or addition).- Specified by:
getLeft
in interfaceICompareInput
- Returns:
- the left side of this input, or
null
-
setRight
public void setRight(ITypedElement right)
Sets the right input to the given value.- Parameters:
right
- the new value for the right input
-
getRight
public ITypedElement getRight()
Description copied from interface:ICompareInput
Returns the right side of this input. Returnsnull
if there is no right side (deletion or addition).- Specified by:
getRight
in interfaceICompareInput
- Returns:
- the right side of this input, or
null
-
copy
public void copy(boolean leftToRight)
Description copied from interface:ICompareInput
Copy one side (source) to the other side (destination) depending on the value ofleftToRight
. This method is called from a merge viewer if a corresponding action ("take left" or "take right") has been pressed.The implementation should handle the following cases:
-
if the source side is
null
the destination must be deleted, -
if the destination is
null
the destination must be created and filled with the contents from the source, -
if both sides are non-
null
the contents of source must be copied to destination.
ICompareInputChangeListener
.- Specified by:
copy
in interfaceICompareInput
- Parameters:
leftToRight
- iftrue
the left side is copied to the right side. Iffalse
the right side is copied to the left side
-
if the source side is
-
-