Example usage for javax.swing.tree DefaultTreeModel DefaultTreeModel

List of usage examples for javax.swing.tree DefaultTreeModel DefaultTreeModel

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeModel DefaultTreeModel.

Prototype

public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren) 

Source Link

Document

Creates a tree specifying whether any node can have children, or whether only certain nodes can have children.

Usage

From source file:ca.uhn.hl7v2.testpanel.ui.v2tree.Hl7V2MessageTree.java

/**
 * Updates the panel with a new Message.
 *//*from   ww w . j a  va  2s.c om*/
public void setMessage(Hl7V2MessageCollection theMessage) {

    removeMessageListeners();

    myMessages = theMessage;

    myMessages.addPropertyChangeListener(Hl7V2MessageCollection.PROP_HIGHLITED_PATH, myHighlitedPathListener);
    myMessages.addPropertyChangeListener(Hl7V2MessageCollection.PARSED_MESSAGES_PROPERTY,
            myParsedMessagesListener);
    myMessages.addPropertyChangeListener(Hl7V2MessageCollection.PROP_VALIDATIONCONTEXT_OR_PROFILE,
            myValidationContextListener);
    myMessages.addPropertyChangeListener(Hl7V2MessageCollection.PROP_ENCODING, myMessageEncodingListener);

    myTop = new TreeNodeRoot();
    myTreeModel = new DefaultTreeModel(myTop, false);

    myTableModel = new TreeRowModel(myTreeModel);
    OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(myTreeModel, myTableModel);
    setModel(outlineModel);

    setRootVisible(false);

    setDefaultRenderer(NodeValidationFailure.class, new ValidationTreeCellRenderer());

    // Volumn index is off by one because of the tree
    getColumnModel().getColumn(TreeRowModel.COL_VALUE + 1).setCellRenderer(new ValueCellRenderer(this));

    updateUI();

    myUpdaterThread.scheduleUpdateNow();

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            int width = getWidth() - 140;

            getColumnModel().getColumn(0).setPreferredWidth(width / 2);

            // Min
            getColumnModel().getColumn(1).setPreferredWidth(35);
            getColumnModel().getColumn(1).setMinWidth(35);
            getColumnModel().getColumn(1).setMaxWidth(35);

            // Max
            getColumnModel().getColumn(2).setPreferredWidth(35);
            getColumnModel().getColumn(2).setMinWidth(35);
            getColumnModel().getColumn(2).setMaxWidth(35);

            // Length
            getColumnModel().getColumn(3).setPreferredWidth(50);
            getColumnModel().getColumn(3).setMinWidth(50);
            getColumnModel().getColumn(3).setMaxWidth(50);

            // Validated
            getColumnModel().getColumn(4).setPreferredWidth(20);
            getColumnModel().getColumn(4).setMinWidth(20);
            getColumnModel().getColumn(4).setMaxWidth(20);

            getColumnModel().getColumn(5).setPreferredWidth(width / 2);
        }
    });

}

From source file:Creator.WidgetPanel.java

public void loadTree() {

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Widget Links");
    treeModel = new DefaultTreeModel(root, true);

    Map<String, DefaultMutableTreeNode> treeMap = new TreeMap<>();

    for (Entry<String, WidgetLink> entry : ws.getWidgetLinkEntrySet()) {

        String[] entryString = entry.getKey().split("-");

        if (!treeMap.containsKey(entryString[0])) {
            DefaultMutableTreeNode folder = new DefaultMutableTreeNode(entryString[0], true);
            treeMap.put(entryString[0], folder);
        }/*from   w w  w  .  j  ava  2  s .  c  om*/

        DefaultMutableTreeNode child = new DefaultMutableTreeNode(entryString[1], true);

        // Add the fields of the widget link
        for (String s : entry.getValue().getTreeStrings()) {
            MutableTreeNode childStats = new DefaultMutableTreeNode(s, false);
            child.add(childStats);
        }

        //MutableTreeNode child = new DefaultMutableTreeNode(entry.getValue().getTreeStrings(entryString[1]), false);
        treeMap.get(entryString[0]).add(child);
    }

    for (Entry<String, DefaultMutableTreeNode> entry : treeMap.entrySet()) {
        root.add(entry.getValue());
    }

    _JTree_WidgetLinks.setModel(treeModel);

}

From source file:nl.tudelft.goal.SimpleIDE.FilePanel.java

/**
 * DOC/* w  w w  .  jav  a 2s.  c  o m*/
 *
 * @param mainp
 *            the main panel, for centering dialogs.
 * @param state
 *            the IDE state
 */
public FilePanel(JPanel mainp, IDEState state) {

    this.mainpanel = mainp;
    this.ideState = state;
    this.rootNode = new FileNode(NodeType.ROOT, null);
    this.rootNode.setAllowsChildren(true);
    this.projectsNode = new FileNode(NodeType.ROOT, new File("MAS Projects")); //$NON-NLS-1$
    this.nullNode = new NullNode();
    this.rootNode.add(this.projectsNode);
    this.rootNode.add(this.nullNode);

    this.treeModel = new DefaultTreeModel(this.rootNode, true);
    this.fileTree = new JTree(this.treeModel);

    // add the various event listeners
    addListeners();

    // double-click should not toggle the tree
    this.fileTree.setToggleClickCount(-1);

    // set the layout
    setLayout(new BorderLayout());
    this.fileTree.setEditable(false); // TODO: allow this.
    this.fileTree.setRootVisible(false);
    this.fileTree.setShowsRootHandles(true);
    this.fileTree.setCellRenderer(new IDENodeRenderer());
    // include tree view in pane
    JScrollPane fileTreeView = new JScrollPane(this.fileTree);
    this.add(new JLabel("Files"), BorderLayout.NORTH); //$NON-NLS-1$
    this.add(fileTreeView, BorderLayout.CENTER);

    this.allFiles = new FileNodeMap();

    this.platform = PlatformManager.getCurrent();
}