use of javax.swing.tree.MutableTreeNode in project poi by apache.
the class TreeReaderListener method processPOIFSReaderEvent.
/**
* <p>A document in the POI filesystem has been opened for
* reading. This method retrieves properties of the document and
* adds them to a tree model.</p>
*/
@Override
public void processPOIFSReaderEvent(final POIFSReaderEvent event) {
DocumentDescriptor d;
final DocumentInputStream is = event.getStream();
if (!is.markSupported()) {
throw new UnsupportedOperationException(is.getClass().getName() + " does not support mark().");
}
/* Try do handle this document as a property set. We receive
* an exception if is no property set and handle it as a
* document of some other format. We are not concerned about
* that document's details. */
try {
d = new PropertySetDescriptor(event.getName(), event.getPath(), is, nrOfBytes);
} catch (HPSFException ex) {
d = new DocumentDescriptor(event.getName(), event.getPath(), is, nrOfBytes);
} catch (Exception t) {
throw new RuntimeException("Unexpected exception while processing " + event.getName() + " in " + event.getPath(), t);
}
is.close();
final MutableTreeNode parentNode = getNode(d.path, filename, rootNode);
final MutableTreeNode nameNode = new DefaultMutableTreeNode(d.name);
parentNode.insert(nameNode, 0);
final MutableTreeNode dNode = new DefaultMutableTreeNode(d);
nameNode.insert(dNode, 0);
}
use of javax.swing.tree.MutableTreeNode in project poi by apache.
the class TreeReaderListener method getNode.
/**
* <p>Locates the parent node for a document entry in the tree
* model. If the parent node does not yet exist it will be
* created, too. This is done recursively, if needed.</p>
*
* @param path The tree node for this path is located.
*
* @param fsName The name of the POI filesystem. This is just a
* string which is displayed in the tree at the top lovel.
*
* @param root The root node.
*/
private MutableTreeNode getNode(final POIFSDocumentPath path, final String fsName, final MutableTreeNode root) {
MutableTreeNode n = pathToNode.get(path);
if (n != null) {
/* Node found in map, just return it. */
return n;
}
if (path.length() == 0) {
/* This is the root path of the POI filesystem. Its tree
* node is resp. must be located below the tree node of
* the POI filesystem itself. This is a tree node with the
* POI filesystem's name (this the operating system file's
* name) as its key it the path-to-node map. */
n = pathToNode.get(fsName);
if (n == null) {
/* A tree node for the POI filesystem does not yet
* exist. */
n = new DefaultMutableTreeNode(fsName);
pathToNode.put(fsName, n);
root.insert(n, 0);
}
return n;
}
/* else - The path is somewhere down in the POI filesystem's
* hierarchy. We need the tree node of this path's parent
* and attach our new node to it. */
final String name = path.getComponent(path.length() - 1);
final POIFSDocumentPath parentPath = path.getParent();
final MutableTreeNode parentNode = getNode(parentPath, fsName, root);
n = new DefaultMutableTreeNode(name);
pathToNode.put(path, n);
parentNode.insert(n, 0);
return n;
}
use of javax.swing.tree.MutableTreeNode in project processdash by dtuma.
the class PropTreeModel method reload.
private void reload(DashHierarchy props, DefaultMutableTreeNode node, PropertyKey key) {
DefaultMutableTreeNode child;
int childIndex = 0;
//set the current node name
Prop value = props.pget(key);
if (!key.name().equals(node.getUserObject())) {
node.setUserObject(key.name());
nodeChanged(node);
}
int numPropChildren = value.getNumChildren();
while (numPropChildren > childIndex) {
if (getChildCount(node) <= childIndex) {
child = new DefaultMutableTreeNode("changeMeLater");
insertNodeInto(child, node, childIndex);
} else
child = (DefaultMutableTreeNode) getChild(node, childIndex);
reload(props, child, props.getChildKey(key, childIndex));
childIndex++;
}
while (getChildCount(node) > numPropChildren) removeNodeFromParent((MutableTreeNode) getChild(node, getChildCount(node) - 1));
}
Aggregations