org.merlotxml.merlot
Class DOMTreeTableAdapter

java.lang.Object
  extended bycom.sun.javax.swing.AbstractTreeTableModel
      extended byorg.merlotxml.merlot.DNDJTreeTableModel
          extended byorg.merlotxml.merlot.DOMTreeTableAdapter
All Implemented Interfaces:
MerlotConstants, MerlotNodeListener, javax.swing.tree.TreeModel, com.sun.javax.swing.TreeTableModel
Direct Known Subclasses:
MerlotLibraryTreeTableModel

public class DOMTreeTableAdapter
extends DNDJTreeTableModel
implements MerlotNodeListener, MerlotConstants

Adapts a DOM Document object into a TreeTableModel

Author:
Kelly A. Campbell

Nested Class Summary
protected  class DOMTreeTableAdapter.DisplayInsertedNodeRunnable
           
 
Field Summary
protected  java.util.Hashtable _children_of_the_nodes
           
protected  XMLFile _file
           
protected  MerlotDOMNode _root
           
protected  java.util.Vector _statusListeners
           
protected  com.sun.javax.swing.JTreeTable _table
          The tree which we need to have a ref to when inserting new nodes so we can select the new row
protected  javax.swing.undo.UndoManager _undoManager
           
static java.lang.String ELEMENT
           
protected static int NODE_CHANGED_EVENT
           
protected static int NODE_INSERTED_EVENT
           
protected static int NODE_REMOVED_EVENT
           
 
Fields inherited from class com.sun.javax.swing.AbstractTreeTableModel
listenerList, root
 
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
DOMTreeTableAdapter(MerlotDOMNode root)
           
DOMTreeTableAdapter(XMLFile file)
           
 
Method Summary
 void addIDManagerAsNodeListener()
           
 void addStatusListener(StatusListener listener)
           
 void cacheReset(MerlotDOMNode parent)
           
 void childrenChanged(MerlotDOMNode nd)
          reset the cache for a given node
 boolean dropOnRow(int row, java.lang.Object data, int where)
          called by DNDJTreeTable when an object is dropped somewhere.
protected  java.util.Vector filterChildNodes(MerlotDOMNode nd)
          This gets the set of child nodes for a given node, and filters out stuff we don't want to display in the table (like #text nodes)
 void fireStatusChanged(StatusEvent evt)
           
 void fireTreeStructureChanged(java.lang.Object source, java.lang.Object[] path)
           
 java.lang.Object getChild(java.lang.Object node, int n)
           
 int getChildCount(java.lang.Object node)
           
 java.lang.Class getColumnClass(int column)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int column)
           
 MerlotDOMDocument getDocument()
           
 int[] getLocationPathForNode(MerlotDOMNode nd)
          This gets the location of a node specified by the indices of the nodes in the path within their parent containers.
 MerlotDOMNode getNodeAtRow(int row)
           
 java.lang.String getPCDATA(org.w3c.dom.Node nd)
          Returns any PCDATA as a string if it exists as a "#text" child node of the given node or null
 java.awt.datatransfer.Transferable getTransferable(javax.swing.tree.TreePath[] paths)
          returns a MerlotDOMFragment containing the nodes in the paths
 java.lang.Object[] getTreePathForNode(MerlotDOMNode nd)
          builds the path from this object up to the root and then make an array with it in correct traversal order i.e.
 java.lang.Object getValueAt(java.lang.Object node, int column)
           
 javax.swing.undo.UndoableEdit importFragment(int row, MerlotDOMFragment frag, int where, boolean paste)
          Imports a fragment into the current document tree.
 javax.swing.undo.UndoableEdit importFragment(int row, MerlotDOMFragment frag, int where, boolean paste, boolean pruneLibItems)
           
 void nodeChanged(MerlotDOMNode parent, int[] i, MerlotDOMNode[] children)
           
 void nodeDeleted(MerlotDOMNode nd)
           
protected  void nodeEvent(int event, MerlotDOMNode parent, int[] childIndices, MerlotDOMNode[] children)
           
 void nodeInserted(MerlotDOMNode parent, int[] i, MerlotDOMNode[] children)
          triggers the proper event to notify a node of a child being added in the tree display
 void nodeRemoved(MerlotDOMNode parent, int[] i, MerlotDOMNode[] children)
          notifies the listener that one or more nodes under the given parent were deleted.
 void refreshNode(MerlotDOMNode node)
          Refreshes the node in the tree
 void removeStatusListener(StatusListener listener)
           
 void setColumns(java.lang.String[] attr, java.lang.String[] names)
           
 void setJTreeTable(com.sun.javax.swing.JTreeTable table)
           
 void setUndoManager(javax.swing.undo.UndoManager m)
           
 
Methods inherited from class org.merlotxml.merlot.DNDJTreeTableModel
setRoot
 
Methods inherited from class com.sun.javax.swing.AbstractTreeTableModel
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getIndexOfChild, getRoot, isCellEditable, isLeaf, removeTreeModelListener, setValueAt, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NODE_INSERTED_EVENT

protected static final int NODE_INSERTED_EVENT
See Also:
Constant Field Values

NODE_REMOVED_EVENT

protected static final int NODE_REMOVED_EVENT
See Also:
Constant Field Values

NODE_CHANGED_EVENT

protected static final int NODE_CHANGED_EVENT
See Also:
Constant Field Values

ELEMENT

public static final java.lang.String ELEMENT
See Also:
Constant Field Values

_children_of_the_nodes

protected java.util.Hashtable _children_of_the_nodes

_root

protected MerlotDOMNode _root

_undoManager

protected javax.swing.undo.UndoManager _undoManager

_file

protected XMLFile _file

_statusListeners

protected java.util.Vector _statusListeners

_table

protected com.sun.javax.swing.JTreeTable _table
The tree which we need to have a ref to when inserting new nodes so we can select the new row

Constructor Detail

DOMTreeTableAdapter

public DOMTreeTableAdapter(XMLFile file)

DOMTreeTableAdapter

public DOMTreeTableAdapter(MerlotDOMNode root)
Method Detail

addIDManagerAsNodeListener

public void addIDManagerAsNodeListener()

getDocument

public MerlotDOMDocument getDocument()

setUndoManager

public void setUndoManager(javax.swing.undo.UndoManager m)

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface com.sun.javax.swing.TreeTableModel

getColumnClass

public java.lang.Class getColumnClass(int column)
Specified by:
getColumnClass in interface com.sun.javax.swing.TreeTableModel

getColumnName

public java.lang.String getColumnName(int column)
Specified by:
getColumnName in interface com.sun.javax.swing.TreeTableModel

setColumns

public void setColumns(java.lang.String[] attr,
                       java.lang.String[] names)

getValueAt

public java.lang.Object getValueAt(java.lang.Object node,
                                   int column)
Specified by:
getValueAt in interface com.sun.javax.swing.TreeTableModel

getChild

public java.lang.Object getChild(java.lang.Object node,
                                 int n)
Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object node)
Specified by:
getChildCount in interface javax.swing.tree.TreeModel

filterChildNodes

protected java.util.Vector filterChildNodes(MerlotDOMNode nd)
This gets the set of child nodes for a given node, and filters out stuff we don't want to display in the table (like #text nodes)

Returns:
a vector of Node's

childrenChanged

public void childrenChanged(MerlotDOMNode nd)
reset the cache for a given node


nodeEvent

protected void nodeEvent(int event,
                         MerlotDOMNode parent,
                         int[] childIndices,
                         MerlotDOMNode[] children)

nodeInserted

public void nodeInserted(MerlotDOMNode parent,
                         int[] i,
                         MerlotDOMNode[] children)
triggers the proper event to notify a node of a child being added in the tree display

Specified by:
nodeInserted in interface MerlotNodeListener

nodeRemoved

public void nodeRemoved(MerlotDOMNode parent,
                        int[] i,
                        MerlotDOMNode[] children)
Description copied from interface: MerlotNodeListener
notifies the listener that one or more nodes under the given parent were deleted. Their previous indices are given.

Specified by:
nodeRemoved in interface MerlotNodeListener

nodeChanged

public void nodeChanged(MerlotDOMNode parent,
                        int[] i,
                        MerlotDOMNode[] children)
Specified by:
nodeChanged in interface MerlotNodeListener

nodeDeleted

public void nodeDeleted(MerlotDOMNode nd)
Specified by:
nodeDeleted in interface MerlotNodeListener

cacheReset

public void cacheReset(MerlotDOMNode parent)

refreshNode

public void refreshNode(MerlotDOMNode node)
Refreshes the node in the tree


getLocationPathForNode

public int[] getLocationPathForNode(MerlotDOMNode nd)
This gets the location of a node specified by the indices of the nodes in the path within their parent containers. This creates a snapshot of where a node was located at a certain time specifically for undoing operations


getTreePathForNode

public java.lang.Object[] getTreePathForNode(MerlotDOMNode nd)
builds the path from this object up to the root and then make an array with it in correct traversal order i.e. root down


fireTreeStructureChanged

public void fireTreeStructureChanged(java.lang.Object source,
                                     java.lang.Object[] path)

getPCDATA

public java.lang.String getPCDATA(org.w3c.dom.Node nd)
Returns any PCDATA as a string if it exists as a "#text" child node of the given node or null


setJTreeTable

public void setJTreeTable(com.sun.javax.swing.JTreeTable table)

dropOnRow

public boolean dropOnRow(int row,
                         java.lang.Object data,
                         int where)
called by DNDJTreeTable when an object is dropped somewhere. Hands off the object to importFragment.

Specified by:
dropOnRow in class DNDJTreeTableModel
Parameters:
row - the row affected
data - the data being dropped
where - INTO, BEFORE, or AFTER

getNodeAtRow

public MerlotDOMNode getNodeAtRow(int row)

importFragment

public javax.swing.undo.UndoableEdit importFragment(int row,
                                                    MerlotDOMFragment frag,
                                                    int where,
                                                    boolean paste)
Imports a fragment into the current document tree. If the fragment is from another document, then it is copied. If it is from the current document, and this is not a paste operation, then it is moved. (Actually imported, and the old one is deleted).

Returns:
an undoable edit if successfull, null otherwise

importFragment

public javax.swing.undo.UndoableEdit importFragment(int row,
                                                    MerlotDOMFragment frag,
                                                    int where,
                                                    boolean paste,
                                                    boolean pruneLibItems)

getTransferable

public java.awt.datatransfer.Transferable getTransferable(javax.swing.tree.TreePath[] paths)
returns a MerlotDOMFragment containing the nodes in the paths

Overrides:
getTransferable in class DNDJTreeTableModel

addStatusListener

public void addStatusListener(StatusListener listener)

removeStatusListener

public void removeStatusListener(StatusListener listener)

fireStatusChanged

public void fireStatusChanged(StatusEvent evt)