Class StructureRootNode
- java.lang.Object
-
- org.eclipse.compare.structuremergeviewer.DocumentRangeNode
-
- org.eclipse.compare.structuremergeviewer.StructureRootNode
-
- All Implemented Interfaces:
IDocumentRange
,IEditableContent
,IEditableContentExtension
,IEncodedStreamContentAccessor
,IStreamContentAccessor
,ITypedElement
,IStructureComparator
,IAdaptable
,IDisposable
public class StructureRootNode extends DocumentRangeNode implements IDisposable, ITypedElement
A node that acts as the root of the tree returned from aStructureCreator
. This node performs the following tasks tasks:- It adapts to an
ISharedDocumentAdapter
that provides the proper document key (@seegetAdapter(Class)
). - It invokes
IStructureCreator.save(IStructureComparator, Object)
whennodeChanged(DocumentRangeNode)
is called. - It disposes of the
IDisposable
provided in the constructor whendispose()
is called.
This class may be subclassed by clients.
- Since:
- 3.3
-
-
Field Summary
Fields Modifier and Type Field Description static String
ROOT_ID
The string constant (value"root"
) that is used as the id of the root node.static int
ROOT_TYPE
The integer constant (value0
) that is used as the type code of the root node.-
Fields inherited from interface org.eclipse.compare.contentmergeviewer.IDocumentRange
RANGE_CATEGORY
-
Fields inherited from interface org.eclipse.compare.ITypedElement
FOLDER_TYPE, TEXT_TYPE, UNKNOWN_TYPE
-
-
Constructor Summary
Constructors Constructor Description StructureRootNode(IDocument document, Object input, StructureCreator creator, ISharedDocumentAdapter adapter)
Create the structure root node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Disposes of this service.<T> T
getAdapter(Class<T> adapter)
OverrideIAdaptable.getAdapter(Class)
in order to provide anISharedDocumentAdapter
that provides the proper look up key based on the input from which this structure node was created.Image
getImage()
Returns an image for this object.String
getName()
Returns the name of this object.String
getType()
Returns the type of this object.boolean
isReadOnly()
Return whether the typed element being displayed is read-only. a read-only element will require a call to validateEdit before the element can be modified on disk.protected void
nodeChanged(DocumentRangeNode node)
Override in order to invokeIStructureCreator.save(IStructureComparator, Object)
when the contents of a node have changed.ITypedElement
replace(ITypedElement child, ITypedElement other)
This method is called on a parent to add or remove a child, or to copy the contents of a child.IStatus
validateEdit(Shell shell)
If the element is read-only, this method should be called to attempt to make it writable.-
Methods inherited from class org.eclipse.compare.structuremergeviewer.DocumentRangeNode
addChild, equals, getAppendPosition, getCharset, getChildren, getContents, getDocument, getId, getParentNode, getRange, getTypeCode, hashCode, internalSetContents, isEditable, setAppendPosition, setContent, setId, setLength
-
-
-
-
Field Detail
-
ROOT_TYPE
public static final int ROOT_TYPE
The integer constant (value0
) that is used as the type code of the root node.
-
ROOT_ID
public static final String ROOT_ID
The string constant (value"root"
) that is used as the id of the root node.- See Also:
DocumentRangeNode.getId()
, Constant Field Values
-
-
Constructor Detail
-
StructureRootNode
public StructureRootNode(IDocument document, Object input, StructureCreator creator, ISharedDocumentAdapter adapter)
Create the structure root node.- Parameters:
document
- the documentinput
- the input associated with the documentcreator
- the structure creator that is creating the nodeadapter
- the shared document adapter from which the document was obtained ornull
if the document was not obtained from anISharedDocumentAdapter
-
-
Method Detail
-
dispose
public void dispose()
Description copied from interface:IDisposable
Disposes of this service. All resources must be freed. All listeners must be detached. Dispose will only be called once during the life cycle of a service.- Specified by:
dispose
in interfaceIDisposable
-
getAdapter
public <T> T getAdapter(Class<T> adapter)
OverrideIAdaptable.getAdapter(Class)
in order to provide anISharedDocumentAdapter
that provides the proper look up key based on the input from which this structure node was created.- Specified by:
getAdapter
in interfaceIAdaptable
- Overrides:
getAdapter
in classDocumentRangeNode
- Type Parameters:
T
- the class type- Parameters:
adapter
- the adapter class to look up- Returns:
- the object adapted to the given class or
null
- See Also:
IAdaptable.getAdapter(Class)
-
nodeChanged
protected void nodeChanged(DocumentRangeNode node)
Override in order to invokeIStructureCreator.save(IStructureComparator, Object)
when the contents of a node have changed.- Overrides:
nodeChanged
in classDocumentRangeNode
- Parameters:
node
- the changed node
-
replace
public ITypedElement replace(ITypedElement child, ITypedElement other)
Description copied from interface:IEditableContent
This method is called on a parent to add or remove a child, or to copy the contents of a child. What to do is encoded in the two arguments as follows:add: dest == null src != null remove: dest != null src == null copy: dest != null src != null - Specified by:
replace
in interfaceIEditableContent
- Overrides:
replace
in classDocumentRangeNode
- Parameters:
child
- the existing child of this object to be replaced; ifnull
a new child can be added.other
- the new child to be added or replaced; ifnull
an existing child can be removed.- Returns:
- the argument
dest
-
getImage
public Image getImage()
Description copied from interface:ITypedElement
Returns an image for this object. This image is used when displaying this object in the UI.- Specified by:
getImage
in interfaceITypedElement
- Returns:
- the image of this object or
null
if this type of input has no image
-
getName
public String getName()
Description copied from interface:ITypedElement
Returns the name of this object. The name is used when displaying this object in the UI.- Specified by:
getName
in interfaceITypedElement
- Returns:
- the name of this object
-
getType
public String getType()
Description copied from interface:ITypedElement
Returns the type of this object. For objects with a file name this is typically the file extension. For folders its the constantFOLDER_TYPE
. The type is used for determining a suitable viewer for this object.- Specified by:
getType
in interfaceITypedElement
- Returns:
- the type of this object
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:IEditableContentExtension
Return whether the typed element being displayed is read-only. a read-only element will require a call to validateEdit before the element can be modified on disk.- Specified by:
isReadOnly
in interfaceIEditableContentExtension
- Overrides:
isReadOnly
in classDocumentRangeNode
- Returns:
- whether the typed element is read-only
-
validateEdit
public IStatus validateEdit(Shell shell)
Description copied from interface:IEditableContentExtension
If the element is read-only, this method should be called to attempt to make it writable.- Specified by:
validateEdit
in interfaceIEditableContentExtension
- Overrides:
validateEdit
in classDocumentRangeNode
- Parameters:
shell
- a shell used to prompt the user if required.- Returns:
- a status object that is
OK
if things are fine, otherwise a status describing reasons why modifying the given files is not reasonable. A status with a severity ofCANCEL
is returned if the validation was canceled, indicating the edit should not proceed.
-
-