org.merlotxml.merlot
Class MerlotDOMNode

java.lang.Object
  extended byorg.merlotxml.merlot.MerlotDOMNode
All Implemented Interfaces:
java.lang.Cloneable, MerlotConstants, java.awt.datatransfer.Transferable
Direct Known Subclasses:
MerlotDOMComment, MerlotDOMDoctype, MerlotDOMDocument, MerlotDOMElement, MerlotDOMFragment, MerlotDOMProcessingInstruction, MerlotDOMText

public class MerlotDOMNode
extends java.lang.Object
implements java.awt.datatransfer.Transferable, java.lang.Cloneable, MerlotConstants

DOM node container for Merlot. Contains a DOM node, handles getting an icon for a particular node, getting the editor for a node, etc. Also implements transferable so that the node can be drag and dropped, or cut and pasted.

Author:
Kelly A. Campbell

Field Summary
protected  java.util.Vector _children
          cached list of child nodes
protected  MerlotDOMNode[] _clonedFrom
          The node we were cloned from if any...
protected  DTDPluginConfig _dtdPluginConfig
          the plugin this node is associated with
protected  XMLFile _file
          The file this node came from
protected  java.util.Vector _listeners
          Listeners of for actions on this node
protected  MerlotDOMNode _parent
           
protected  org.w3c.dom.Node _theNode
           
static java.awt.datatransfer.DataFlavor DOM_TREENODE_FLAVOR
           
 
Fields inherited from interface org.merlotxml.merlot.MerlotConstants
ACTION_MENU_ACCELERATOR, ACTION_MENU_ICON, ACTION_NAME, ACTION_SHORT_DESCRIPTION, ACTION_SMALL_ICON, AFTER, BEFORE, ERR, INTO, UI, XML
 
Constructor Summary
MerlotDOMNode(org.w3c.dom.Node data, XMLFile file)
           
 
Method Summary
 void addMerlotNodeListener(MerlotNodeListener l)
           
 void appendChild(MerlotDOMNode child)
           
 java.lang.String array2String(int[] array)
           
 java.lang.String array2String(java.lang.Object[] array)
           
 java.lang.Object clone()
          provides a deep copy
 void delete()
           
 boolean equals(java.lang.Object o)
           
 void fireNodeChanged()
           
 void fireNodeDeleted()
          This handles the case of notifying anything editing the node that it is deleted.
 void fireNodeInserted(MerlotDOMNode parent, int[] childindices, MerlotDOMNode[] newchildren)
           
 void fireNodeRemoved(MerlotDOMNode parent, int[] childindices, MerlotDOMNode[] oldchildren)
          This one handles the case of keeping the tree view up to date.
 java.util.Enumeration getAppendableElements()
          returns an enumeration of DTDElements
 org.w3c.dom.NamedNodeMap getAttributes()
           
 java.util.Vector getAttributesOfType(int type)
          Gets only the attributes (org.w3c.dom.Node) that have the specified type.
 java.util.Vector getChildElements()
           
 int getChildIndex(MerlotDOMNode child)
          Returns the index of the location of the child in the parent
 MerlotDOMNode[] getChildNodes()
          gets a list of child nodes and creates an array of merlotDOMNodes.
 java.lang.String getChildText(boolean suppressWhiteSpace)
           
protected  MerlotDOMNode[] getClonedFrom()
           
 java.lang.String getDescriptiveText()
          Determines the most descriptive text for a node based on priorities set in plugin.xml.
 java.lang.String getDescriptiveText(java.util.Map nodeProperties, java.util.List defaultOrder)
           
 java.lang.String getDisplayText()
           
 org.w3c.dom.Document getDocument()
           
 java.util.Enumeration getDTDAttributes()
          Deprecated. Use getGrammarAttributes
 DTDDocument getDTDDocument()
          Deprecated. Use getGrammarDocument.
 DTDPluginConfig getDTDPluginConfig()
          Returns the dtd plugin config for this node if it exists
 MerlotDOMEditor getEditor()
          This should return the editor object for this type of element if one is found, otherwise a default one should be returned.
 javax.swing.JPanel getEditPanel()
           
 java.lang.String getFirstAttributeOfType(int attrType)
          Gets all the attributes (org.w3c.dom.Node) that have the specified type.
 MerlotDOMNode getFirstChild()
          Gets the first child that is non-empty text, or returns null if none
 GrammarSimpleType getGrammarAttribute(java.lang.String name)
           
 GrammarSimpleType[] getGrammarAttributes()
          Provides access to the grammar of the attributes defined for this node for both DTDs and Schemas.
 GrammarComplexType getGrammarComplexType()
          Provides access to element grammar for both DTDs and Schemas.
 GrammarDocument getGrammarDocument()
          Provides access to element and attribute grammar for both DTDs and Schemas.
 javax.swing.Icon getIcon()
          Gets a large icon
 IDManager getIdManager()
          Return THE IDManager specific to the document containing this node.
protected  int[] getIndices()
          this gets the index of this child or if it's a fragment, then the indices of all the nodes in the top level of the fragment
 java.util.Enumeration getInsertableElements()
          Deprecated. Use getGrammarComplexType().getInsertableElements()
 java.util.Enumeration getInsertableElements(int index)
          Deprecated. Use getGrammarComplexType().getInsertableElements(index)
 MerlotDOMDocument getMerlotDOMDocument()
          this goes up the tree recursively until it finds the merlot dom document
protected  java.util.Vector getMerlotNodeListeners()
           
 java.lang.String getNodeName()
           
protected  MerlotDOMNode[] getNodes()
           
 MerlotDOMNode getParentNode()
           
 MerlotDOMNode getPreviousSibling()
          Returns the previous sibling or null if this is the first sibling
 MerlotDOMNode getPreviousSibling(MerlotDOMNode child)
           
 java.lang.String getProperty(java.lang.Object property)
          Property must either be a String containing the attribute name, or an Integer with a DTDConstant specifying an attribute type.
 org.w3c.dom.Node getRealNode()
           
 javax.swing.Icon getSmallIcon()
          Gets a small icon for this node based on its type
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
           
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
           
 XMLFile getXMLFile()
          returns the XML file object
 int hashCode()
           
 MerlotDOMNode importChild(MerlotDOMNode child)
          imports a child node from another document
 MerlotDOMNode importChild(MerlotDOMNode child, boolean asLastChild)
           
 MerlotDOMNode importChildAfter(MerlotDOMNode child)
          imports a node and places it after this one
 MerlotDOMNode importChildBefore(MerlotDOMNode child)
          imports a node and places it before this one
 void insertAfter(MerlotDOMNode sibling)
          inserts this after the sibling
 void insertBefore(MerlotDOMNode sibling)
          inserts this before the sibling
 void insertChildAt(MerlotDOMNode child, int loc)
           
 boolean isAllowableChild(MerlotDOMNode child, boolean newChild)
          Returns true if the child is a valid type to be a child of this according to the DTD
 boolean isAllowableChild(MerlotDOMNode child, int index, boolean newChild)
           
 boolean isAllowableChild(java.lang.String child, int index)
           
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
           
 boolean isElement()
          Element nodes should overload this to return true.
 boolean isRootElement()
           
 boolean isSpecialNode()
           
 boolean isValid()
           
 boolean locationIsValid(boolean checkParents)
           
 boolean mayBeRemoved()
           
 MerlotDOMNode newChild(org.w3c.dom.Node nd)
           
 MerlotDOMNode newChild(java.lang.String nodename)
          creates a new child and adds it to the end of the list
 MerlotDOMNode newSiblingAfter(org.w3c.dom.Node nd)
          creates a new sibling and inserts it after this node
 MerlotDOMNode newSiblingAfter(java.lang.String nodename)
           
 MerlotDOMNode newSiblingBefore(org.w3c.dom.Node nd)
          creates a new sibling and inserts it after this node
 MerlotDOMNode newSiblingBefore(java.lang.String nodename)
           
 void printNode()
           
 void printNode(java.lang.String prepend)
           
 void removeAllMerlotDOMNodeListeners()
          Removes all listeners from this node
 void removeAttributes()
           
 void removeChild(MerlotDOMNode nd)
          Removes a child node
 void removeMerlotNodeListener(MerlotNodeListener l)
           
protected  void resetCache()
           
 void setAttributes(java.util.HashMap h)
          Sets the attributes according the given hashtable.
protected  void setClonedFrom(MerlotDOMNode[] nd)
           
 void setDescriptiveText(java.lang.String description)
          Concept here is that a node can have it's description set externally by a plugin and that text be displayed - it can double as a cache for node descriptions
 void setParentNode(MerlotDOMNode nd)
           
protected  void setParentNode(MerlotDOMNode nd, boolean updateChildren)
           
 java.lang.String toPathString()
           
 java.lang.String toString()
           
 java.lang.String toXMLShort()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_theNode

protected org.w3c.dom.Node _theNode

_file

protected XMLFile _file
The file this node came from


_parent

protected MerlotDOMNode _parent

_clonedFrom

protected MerlotDOMNode[] _clonedFrom
The node we were cloned from if any... used for dnd moves so we can delete the original node that was being moved.


_listeners

protected java.util.Vector _listeners
Listeners of for actions on this node


_children

protected java.util.Vector _children
cached list of child nodes


_dtdPluginConfig

protected DTDPluginConfig _dtdPluginConfig
the plugin this node is associated with


DOM_TREENODE_FLAVOR

public static final java.awt.datatransfer.DataFlavor DOM_TREENODE_FLAVOR
Constructor Detail

MerlotDOMNode

public MerlotDOMNode(org.w3c.dom.Node data,
                     XMLFile file)
Method Detail

getDocument

public org.w3c.dom.Document getDocument()

getMerlotDOMDocument

public MerlotDOMDocument getMerlotDOMDocument()
this goes up the tree recursively until it finds the merlot dom document


getSmallIcon

public javax.swing.Icon getSmallIcon()
Gets a small icon for this node based on its type


getIcon

public javax.swing.Icon getIcon()
Gets a large icon


isElement

public boolean isElement()
Element nodes should overload this to return true.


getXMLFile

public XMLFile getXMLFile()
returns the XML file object


getDTDPluginConfig

public DTDPluginConfig getDTDPluginConfig()
Returns the dtd plugin config for this node if it exists


getEditor

public MerlotDOMEditor getEditor()
This should return the editor object for this type of element if one is found, otherwise a default one should be returned.


getNodeName

public java.lang.String getNodeName()

getChildIndex

public int getChildIndex(MerlotDOMNode child)
                  throws org.w3c.dom.DOMException
Returns the index of the location of the child in the parent

Throws:
org.w3c.dom.DOMException

getFirstChild

public MerlotDOMNode getFirstChild()
Gets the first child that is non-empty text, or returns null if none


getChildElements

public java.util.Vector getChildElements()

getChildNodes

public MerlotDOMNode[] getChildNodes()
gets a list of child nodes and creates an array of merlotDOMNodes. Returns null if no children are available


resetCache

protected void resetCache()

getAttributes

public org.w3c.dom.NamedNodeMap getAttributes()

getFirstAttributeOfType

public java.lang.String getFirstAttributeOfType(int attrType)
Gets all the attributes (org.w3c.dom.Node) that have the specified type.

See Also:
for the possible types

getAttributesOfType

public java.util.Vector getAttributesOfType(int type)
Gets only the attributes (org.w3c.dom.Node) that have the specified type.

See Also:
for the possible types

setAttributes

public void setAttributes(java.util.HashMap h)
Sets the attributes according the given hashtable. (probably should make getAttributes consistent with this at some point


getAppendableElements

public java.util.Enumeration getAppendableElements()
returns an enumeration of DTDElements


getInsertableElements

public java.util.Enumeration getInsertableElements(int index)
Deprecated. Use getGrammarComplexType().getInsertableElements(index)

returns the nodes that are insertable at the given index.


getInsertableElements

public java.util.Enumeration getInsertableElements()
Deprecated. Use getGrammarComplexType().getInsertableElements()

returns the nodes that are insertable at any index.


isAllowableChild

public boolean isAllowableChild(MerlotDOMNode child,
                                boolean newChild)
Returns true if the child is a valid type to be a child of this according to the DTD


isAllowableChild

public boolean isAllowableChild(MerlotDOMNode child,
                                int index,
                                boolean newChild)

isAllowableChild

public boolean isAllowableChild(java.lang.String child,
                                int index)

getPreviousSibling

public MerlotDOMNode getPreviousSibling()
Returns the previous sibling or null if this is the first sibling


getPreviousSibling

public MerlotDOMNode getPreviousSibling(MerlotDOMNode child)
                                 throws org.w3c.dom.DOMException
Throws:
org.w3c.dom.DOMException

getParentNode

public MerlotDOMNode getParentNode()

setParentNode

public void setParentNode(MerlotDOMNode nd)

setParentNode

protected void setParentNode(MerlotDOMNode nd,
                             boolean updateChildren)

setClonedFrom

protected void setClonedFrom(MerlotDOMNode[] nd)

getClonedFrom

protected MerlotDOMNode[] getClonedFrom()

newChild

public MerlotDOMNode newChild(java.lang.String nodename)
                       throws org.w3c.dom.DOMException
creates a new child and adds it to the end of the list

Throws:
org.w3c.dom.DOMException

newChild

public MerlotDOMNode newChild(org.w3c.dom.Node nd)

newSiblingAfter

public MerlotDOMNode newSiblingAfter(org.w3c.dom.Node nd)
creates a new sibling and inserts it after this node


newSiblingAfter

public MerlotDOMNode newSiblingAfter(java.lang.String nodename)

newSiblingBefore

public MerlotDOMNode newSiblingBefore(org.w3c.dom.Node nd)
creates a new sibling and inserts it after this node


newSiblingBefore

public MerlotDOMNode newSiblingBefore(java.lang.String nodename)

insertAfter

public void insertAfter(MerlotDOMNode sibling)
inserts this after the sibling


insertBefore

public void insertBefore(MerlotDOMNode sibling)
inserts this before the sibling


insertChildAt

public void insertChildAt(MerlotDOMNode child,
                          int loc)

appendChild

public void appendChild(MerlotDOMNode child)

importChild

public MerlotDOMNode importChild(MerlotDOMNode child)
imports a child node from another document


importChild

public MerlotDOMNode importChild(MerlotDOMNode child,
                                 boolean asLastChild)

importChildBefore

public MerlotDOMNode importChildBefore(MerlotDOMNode child)
imports a node and places it before this one


importChildAfter

public MerlotDOMNode importChildAfter(MerlotDOMNode child)
imports a node and places it after this one


removeChild

public void removeChild(MerlotDOMNode nd)
                 throws org.w3c.dom.DOMException
Removes a child node

Throws:
org.w3c.dom.DOMException

getIndices

protected int[] getIndices()
this gets the index of this child or if it's a fragment, then the indices of all the nodes in the top level of the fragment


getNodes

protected MerlotDOMNode[] getNodes()

delete

public void delete()

getDTDDocument

public DTDDocument getDTDDocument()
Deprecated. Use getGrammarDocument.


getDTDAttributes

public java.util.Enumeration getDTDAttributes()
Deprecated. Use getGrammarAttributes


getGrammarDocument

public GrammarDocument getGrammarDocument()
Provides access to element and attribute grammar for both DTDs and Schemas.


getGrammarComplexType

public GrammarComplexType getGrammarComplexType()
Provides access to element grammar for both DTDs and Schemas.


getGrammarAttributes

public GrammarSimpleType[] getGrammarAttributes()
Provides access to the grammar of the attributes defined for this node for both DTDs and Schemas.


getGrammarAttribute

public GrammarSimpleType getGrammarAttribute(java.lang.String name)

getEditPanel

public javax.swing.JPanel getEditPanel()
                                throws java.lang.InstantiationException,
                                       java.lang.IllegalAccessException
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

getRealNode

public org.w3c.dom.Node getRealNode()

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable

clone

public java.lang.Object clone()
provides a deep copy


addMerlotNodeListener

public void addMerlotNodeListener(MerlotNodeListener l)

removeMerlotNodeListener

public void removeMerlotNodeListener(MerlotNodeListener l)

removeAllMerlotDOMNodeListeners

public void removeAllMerlotDOMNodeListeners()
Removes all listeners from this node


getMerlotNodeListeners

protected java.util.Vector getMerlotNodeListeners()

array2String

public java.lang.String array2String(int[] array)

array2String

public java.lang.String array2String(java.lang.Object[] array)

fireNodeInserted

public void fireNodeInserted(MerlotDOMNode parent,
                             int[] childindices,
                             MerlotDOMNode[] newchildren)

fireNodeDeleted

public void fireNodeDeleted()
This handles the case of notifying anything editing the node that it is deleted.


fireNodeRemoved

public void fireNodeRemoved(MerlotDOMNode parent,
                            int[] childindices,
                            MerlotDOMNode[] oldchildren)
This one handles the case of keeping the tree view up to date.


fireNodeChanged

public void fireNodeChanged()

toString

public java.lang.String toString()

toPathString

public java.lang.String toPathString()

equals

public boolean equals(java.lang.Object o)

getDisplayText

public java.lang.String getDisplayText()

getDescriptiveText

public java.lang.String getDescriptiveText()
Determines the most descriptive text for a node based on priorities set in plugin.xml.


getDescriptiveText

public java.lang.String getDescriptiveText(java.util.Map nodeProperties,
                                           java.util.List defaultOrder)

setDescriptiveText

public void setDescriptiveText(java.lang.String description)
Concept here is that a node can have it's description set externally by a plugin and that text be displayed - it can double as a cache for node descriptions


toXMLShort

public java.lang.String toXMLShort()

getProperty

public java.lang.String getProperty(java.lang.Object property)
Property must either be a String containing the attribute name, or an Integer with a DTDConstant specifying an attribute type.


hashCode

public int hashCode()

printNode

public void printNode()

printNode

public void printNode(java.lang.String prepend)

getChildText

public java.lang.String getChildText(boolean suppressWhiteSpace)

isSpecialNode

public boolean isSpecialNode()

getIdManager

public IDManager getIdManager()
Return THE IDManager specific to the document containing this node.


isRootElement

public boolean isRootElement()

isValid

public boolean isValid()

removeAttributes

public void removeAttributes()

locationIsValid

public boolean locationIsValid(boolean checkParents)

mayBeRemoved

public boolean mayBeRemoved()