Search in sources :

Example 11 with MutableTreeNode

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);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DocumentInputStream(org.apache.poi.poifs.filesystem.DocumentInputStream) HPSFException(org.apache.poi.hpsf.HPSFException) HPSFException(org.apache.poi.hpsf.HPSFException) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 12 with MutableTreeNode

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;
}
Also used : POIFSDocumentPath(org.apache.poi.poifs.filesystem.POIFSDocumentPath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 13 with MutableTreeNode

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));
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Prop(net.sourceforge.processdash.hier.Prop) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Aggregations

MutableTreeNode (javax.swing.tree.MutableTreeNode)13 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 TreeNode (javax.swing.tree.TreeNode)3 Nullable (org.jetbrains.annotations.Nullable)2 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFile (com.intellij.psi.PsiFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 RefactoringElementListener (com.intellij.refactoring.listeners.RefactoringElementListener)1 RefactoringElementListenerProvider (com.intellij.refactoring.listeners.RefactoringElementListenerProvider)1 ListTreeTableModelOnColumns (com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns)1 TreeTableTree (com.intellij.ui.treeStructure.treetable.TreeTableTree)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ColumnInfo (com.intellij.util.ui.ColumnInfo)1 FrameInfo (com.jetbrains.actionscript.profiler.sampler.FrameInfo)1 CPUSnapshotNode (com.jetbrains.actionscript.profiler.ui.node.CPUSnapshotNode)1 CallInfo (com.jetbrains.actionscript.profiler.vo.CallInfo)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1