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

@ConstructorProperties({ "root" })
public DefaultTreeModel(TreeNode root) 

Source Link

Document

Creates a tree in which any node can have children.

Usage

From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * /*from w w  w .  j  av a  2s  .c om*/
 */
public void set(final Container rootCon, final CollectionObject rootCO) {
    this.rootContainer = rootCon;
    this.rootColObj = rootCO;

    colObjIdHash.clear();
    containerIdHash.clear();

    if (rootCon != null) {
        Integer rootParentId = getTopMostParentId(rootCon.getId());
        if (rootParentId != null) {
            this.rootContainer = getContainerFromDB(rootParentId);
            this.rootColObj = rootContainer.getCollectionObject();
        }
    } else if (rootCO == null) {

    }

    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    rootNode.setUserObject(rootContainer != null ? rootContainer : rootColObj);

    if (rootContainer != null) {
        loadContainerTree(rootNode, rootContainer, null);

    } else if (rootColObj != null) {
        loadContainerTree(rootNode, null, rootColObj);
    } else {
        rootNode.setUserObject("New Container");
    }

    model = new DefaultTreeModel(rootNode);
    if (tree == null) {
        tree = new GhostActionableTree(this, model);
        tree.setRowHeight(ROW_HEIGHT);
        tree.setBackground(bgColor);
        tree.setEditable(false);
        tree.setVisibleRowCount(15);
        registerPrintContextMenu(tree);

    } else {
        tree.setModel(model);
    }
    model.reload();

    if (containerPanel != null) {
        containerPanel.getMultiView().setData(rootCon);
    }
}

From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java

private void createNodes() {
    DefaultMutableTreeNode root = new ExtendedTreeNode(algorithm, TreeNodeTypeEnum.ALGORITHM);
    DefaultMutableTreeNode problemNode = new ExtendedTreeNode("Problem", TreeNodeTypeEnum.PROBLEM);
    DefaultMutableTreeNode stopConditionNode = new ExtendedTreeNode("Stop conditions",
            TreeNodeTypeEnum.STOP_CONDITION);
    DefaultMutableTreeNode meassurementNode = new ExtendedTreeNode("Meassurements",
            TreeNodeTypeEnum.MEASSUREMENT);

    addProblem(problemNode, algorithm);//w  ww . j ava2s  .  c om
    addStopCondition(stopConditionNode, algorithm);
    addMeasurement(meassurementNode, algorithm);

    root.add(problemNode);
    root.add(stopConditionNode);
    root.add(meassurementNode);
    TreeModel model = new DefaultTreeModel(root);
    tree.setModel(model);
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

/** This method is called from within the constructor to
 * initialize the form.//from  w  w w  .j  av  a2 s  .  c  o  m
 */
private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();

    setLayout(new java.awt.BorderLayout());

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("Queries by " + System.getProperty("user"));
    tmpData.tooltip("Previous query runs");
    tmpData.visualAttribute("CA");
    top = new DefaultMutableTreeNode(tmpData);
    //top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    //treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(false);

    //jTree1.getSelectionModel().setSelectionMode
    //        (TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setShowsRootHandles(true);
    //JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    if (cellStatus.equalsIgnoreCase("CellDown")) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Data Repository Cell is unavailable");
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
        // Make sure the user can see the lovely new node.
        jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));
    }

    ArrayList<QueryMasterData> queries = previousQueries;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(queries.get(i));
        }
    }

    jScrollPane1.setViewportView(jTree1);
    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jTree1.setTransferHandler(new NodeCopyTransferHandler());
    jTree1.addTreeExpansionListener(this);
}

From source file:net.sf.jabref.groups.GroupSelector.java

/**
 * The first element for each group defines which field to use for the quicksearch. The next two define the name and
 * regexp for the group./*from  w  w  w.  ja  v  a2  s  .  c  om*/
 */
public GroupSelector(JabRefFrame frame, SidePaneManager manager) {
    super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups"));
    this.groupsRoot = new GroupTreeNode(new AllEntriesGroup());

    this.frame = frame;
    hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"),
            !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS));
    grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"),
            Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS));
    ButtonGroup nonHits = new ButtonGroup();
    nonHits.add(hideNonHits);
    nonHits.add(grayOut);
    floatCb.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected());
        }
    });
    andCb.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected());
        }
    });
    invCb.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected());
        }
    });
    showOverlappingGroups.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING,
                    showOverlappingGroups.isSelected());
            if (!showOverlappingGroups.isSelected()) {
                groupsTree.setHighlight2Cells(null);
            }
        }
    });

    select.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SELECT_MATCHES, select.isSelected());
        }
    });
    grayOut.addChangeListener(
            event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected()));

    JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) {

        floatCb.setSelected(true);
        highlCb.setSelected(false);
    } else {
        highlCb.setSelected(true);
        floatCb.setSelected(false);
    }
    JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) {
        andCb.setSelected(true);
        orCb.setSelected(false);
    } else {
        orCb.setSelected(true);
        andCb.setSelected(false);
    }

    showNumberOfElements.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS,
                    showNumberOfElements.isSelected());
            if (groupsTree != null) {
                groupsTree.invalidate();
                groupsTree.validate();
                groupsTree.repaint();
            }
        }
    });

    autoAssignGroup.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected());
        }
    });

    invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS));
    showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING));
    select.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SELECT_MATCHES));
    editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE);
    editModeCb.setSelected(editModeIndicator);
    showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS));
    autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));

    openset.setMargin(new Insets(0, 0, 0, 0));
    settings.add(andCb);
    settings.add(orCb);
    settings.addSeparator();
    settings.add(invCb);
    settings.addSeparator();
    settings.add(select);
    settings.addSeparator();
    settings.add(editModeCb);
    settings.addSeparator();
    settings.add(grayOut);
    settings.add(hideNonHits);
    settings.addSeparator();
    settings.add(showOverlappingGroups);
    settings.addSeparator();
    settings.add(showNumberOfElements);
    settings.add(autoAssignGroup);
    // settings.add(moreRow);
    // settings.add(lessRow);
    openset.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!settings.isVisible()) {
                JButton src = (JButton) e.getSource();
                showNumberOfElements
                        .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS));
                autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));
                settings.show(src, 0, openset.getHeight());
            }
        }
    });
    JButton expand = new JButton(IconTheme.JabRefIcon.ADD_ROW.getSmallIcon());
    expand.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int i = Globals.prefs.getInt(JabRefPreferences.GROUPS_VISIBLE_ROWS) + 1;
            groupsTree.setVisibleRowCount(i);
            groupsTree.revalidate();
            groupsTree.repaint();
            GroupSelector.this.revalidate();
            GroupSelector.this.repaint();
            Globals.prefs.putInt(JabRefPreferences.GROUPS_VISIBLE_ROWS, i);
            LOGGER.info("Height: " + GroupSelector.this.getHeight() + "; Preferred height: "
                    + GroupSelector.this.getPreferredSize().getHeight());
        }
    });
    JButton reduce = new JButton(IconTheme.JabRefIcon.REMOVE_ROW.getSmallIcon());
    reduce.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int i = Globals.prefs.getInt(JabRefPreferences.GROUPS_VISIBLE_ROWS) - 1;
            if (i < 1) {
                i = 1;
            }
            groupsTree.setVisibleRowCount(i);
            groupsTree.revalidate();
            groupsTree.repaint();
            GroupSelector.this.revalidate();
            // _panel.sidePaneManager.revalidate();
            GroupSelector.this.repaint();
            Globals.prefs.putInt(JabRefPreferences.GROUPS_VISIBLE_ROWS, i);
        }
    });

    editModeCb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editModeIndicator = editModeCb.getState();
            updateBorder(editModeIndicator);
            Globals.prefs.putBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE, editModeIndicator);
        }
    });

    int butSize = newButton.getIcon().getIconHeight() + 5;
    Dimension butDim = new Dimension(butSize, butSize);
    //Dimension butDimSmall = new Dimension(20, 20);

    newButton.setPreferredSize(butDim);
    newButton.setMinimumSize(butDim);
    refresh.setPreferredSize(butDim);
    refresh.setMinimumSize(butDim);
    JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFiles.groupsHelp)
            .getHelpButton();
    helpButton.setPreferredSize(butDim);
    helpButton.setMinimumSize(butDim);
    autoGroup.setPreferredSize(butDim);
    autoGroup.setMinimumSize(butDim);
    openset.setPreferredSize(butDim);
    openset.setMinimumSize(butDim);
    expand.setPreferredSize(butDim);
    expand.setMinimumSize(butDim);
    reduce.setPreferredSize(butDim);
    reduce.setMinimumSize(butDim);
    Insets butIns = new Insets(0, 0, 0, 0);
    helpButton.setMargin(butIns);
    reduce.setMargin(butIns);
    expand.setMargin(butIns);
    openset.setMargin(butIns);
    newButton.addActionListener(this);
    refresh.addActionListener(this);
    andCb.addActionListener(this);
    orCb.addActionListener(this);
    invCb.addActionListener(this);
    showOverlappingGroups.addActionListener(this);
    autoGroup.addActionListener(this);
    floatCb.addActionListener(this);
    highlCb.addActionListener(this);
    select.addActionListener(this);
    hideNonHits.addActionListener(this);
    grayOut.addActionListener(this);
    newButton.setToolTipText(Localization.lang("New group"));
    refresh.setToolTipText(Localization.lang("Refresh view"));
    andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups."));
    orCb.setToolTipText(
            Localization.lang("Display all entries belonging to one or more of the selected groups."));
    autoGroup.setToolTipText(Localization.lang("Automatically create groups for database."));
    invCb.setToolTipText(Localization.lang("Show entries *not* in group selection"));
    showOverlappingGroups.setToolTipText(Localization
            .lang("Highlight groups that contain entries contained in any currently selected group"));
    floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top"));
    highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection"));
    select.setToolTipText(Localization.lang("Select entries in group selection"));
    expand.setToolTipText(Localization.lang("Show one more row"));
    reduce.setToolTipText(Localization.lang("Show one less rows"));
    editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries"));
    ButtonGroup bgr = new ButtonGroup();
    bgr.add(andCb);
    bgr.add(orCb);
    ButtonGroup visMode = new ButtonGroup();
    visMode.add(floatCb);
    visMode.add(highlCb);

    JPanel main = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    main.setLayout(gbl);

    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.BOTH;
    //con.insets = new Insets(0, 0, 2, 0);
    con.weightx = 1;
    con.gridwidth = 1;
    con.gridx = 0;
    con.gridy = 0;
    //con.insets = new Insets(1, 1, 1, 1);
    gbl.setConstraints(newButton, con);
    main.add(newButton);
    con.gridx = 1;
    gbl.setConstraints(refresh, con);
    main.add(refresh);
    con.gridx = 2;
    gbl.setConstraints(autoGroup, con);
    main.add(autoGroup);
    con.gridx = 3;
    con.gridwidth = GridBagConstraints.REMAINDER;

    gbl.setConstraints(helpButton, con);
    main.add(helpButton);

    // header.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
    // helpButton.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
    groupsTree = new GroupsTree(this);
    groupsTree.addTreeSelectionListener(this);
    groupsTree.setModel(groupsTreeModel = new DefaultTreeModel(groupsRoot));
    JScrollPane sp = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    revalidateGroups();
    con.gridwidth = GridBagConstraints.REMAINDER;
    con.weighty = 1;
    con.gridx = 0;
    con.gridwidth = 4;
    con.gridy = 1;
    gbl.setConstraints(sp, con);
    main.add(sp);

    JPanel pan = new JPanel();
    GridBagLayout gb = new GridBagLayout();
    con.weighty = 0;
    gbl.setConstraints(pan, con);
    pan.setLayout(gb);
    con.insets = new Insets(0, 0, 0, 0);
    con.gridx = 0;
    con.gridy = 0;
    con.weightx = 1;
    con.gridwidth = 4;
    con.fill = GridBagConstraints.HORIZONTAL;
    gb.setConstraints(openset, con);
    pan.add(openset);

    con.gridwidth = 1;
    con.gridx = 4;
    con.gridy = 0;
    gb.setConstraints(expand, con);
    pan.add(expand);

    con.gridx = 5;
    gb.setConstraints(reduce, con);
    pan.add(reduce);

    con.gridwidth = 6;
    con.gridy = 1;
    con.gridx = 0;
    con.fill = GridBagConstraints.HORIZONTAL;

    con.gridy = 2;
    con.gridx = 0;
    con.gridwidth = 4;
    gbl.setConstraints(pan, con);
    main.add(pan);
    main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    add(main, BorderLayout.CENTER);
    updateBorder(editModeIndicator);
    definePopup();
    NodeAction moveNodeUpAction = new MoveNodeUpAction();
    moveNodeUpAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK));
    NodeAction moveNodeDownAction = new MoveNodeDownAction();
    moveNodeDownAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK));
    NodeAction moveNodeLeftAction = new MoveNodeLeftAction();
    moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK));
    NodeAction moveNodeRightAction = new MoveNodeRightAction();
    moveNodeRightAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK));
}

From source file:de.erdesignerng.visual.common.OutlineComponent.java

public void setModel(Model aModel) {

    userObjectMap.clear();/* w ww. j a  v  a2 s  . c o m*/
    expandedUserObjects.clear();

    DefaultMutableTreeNode theRoot = new DefaultMutableTreeNode(TreeGroupingElement.MODEL);

    Comparator<OwnedModelItem> theComparator = new BeanComparator("name");

    // Add the user-defined datatypes
    if (aModel.getDialect() != null) {
        if (aModel.getDialect().isSupportsCustomTypes()) {
            List<CustomType> theCustomTypes = new ArrayList<>();
            theCustomTypes.addAll(aModel.getCustomTypes());
            Collections.sort(theCustomTypes, theComparator);
            buildCustomTypesChildren(aModel, theRoot, theCustomTypes);
        }

        // Add the domains
        List<Domain> theDomains = new ArrayList<>();
        theDomains.addAll(aModel.getDomains());
        Collections.sort(theDomains, theComparator);
        buildDomainsChildren(aModel, theRoot, theDomains);
    }

    // Add the Tables
    List<Table> theTables = new ArrayList<>();
    theTables.addAll(aModel.getTables());
    Collections.sort(theTables, theComparator);
    buildTablesChildren(aModel, theRoot, theTables);

    // Add the Views
    List<View> theViews = new ArrayList<>();
    theViews.addAll(aModel.getViews());
    Collections.sort(theTables, theComparator);
    buildViewsChildren(aModel, theRoot, theViews);

    // Add the Relations
    List<Relation> theRelations = new ArrayList<>();
    theRelations.addAll(aModel.getRelations());
    Collections.sort(theRelations, theComparator);
    buildRelationChildren(theRoot, theRelations);

    // Add the Indexes
    List<Index> theIndexes = new ArrayList<>();
    for (Table theTable : aModel.getTables()) {
        theIndexes.addAll(theTable.getIndexes());
    }
    Collections.sort(theIndexes, theComparator);
    buildIndexChildren(theRoot, theIndexes);

    // Add the subject areas
    List<SubjectArea> theSAList = new ArrayList<>();
    theSAList.addAll(aModel.getSubjectAreas());
    Collections.sort(theSAList, theComparator);
    buildSubjectAreasChildren(aModel, theRoot, theSAList);

    tree.setModel(new DefaultTreeModel(theRoot));

    // if (aExpandAll) {
    for (int row = 0; row < tree.getRowCount(); row++) {
        TreePath thePath = tree.getPathForRow(row);
        DefaultMutableTreeNode theNode = (DefaultMutableTreeNode) thePath.getLastPathComponent();
        Object theUserObject = theNode.getUserObject();
        if (theUserObject instanceof TreeGroupingElement) {
            tree.expandRow(row);
        }
    }
    // }
}

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Will be called from the Thread in which the "unlinked files search" is
 * processed. As the result of the search, the root node of the determined
 * file structure is passed./*from w  w w .jav  a  2s  . co  m*/
 *
 * @param rootNode
 *            The root of the file structure as the result of the search.
 */
private void searchFinishedHandler(CheckableTreeNode rootNode) {
    treeModel = new DefaultTreeModel(rootNode);
    tree.setModel(treeModel);
    tree.setRootVisible(rootNode.getChildCount() > 0);

    tree.invalidate();
    tree.repaint();

    progressBarSearching.setVisible(false);
    labelSearchingDirectoryInfo.setVisible(false);
    buttonScan.setVisible(true);
    actionSelectAll.actionPerformed(null);

    disOrEnableDialog(true);
    buttonApply.setEnabled(true);
}

From source file:edu.harvard.i2b2.previousquery.ui.QueryPreviousRunsPanel.java

/**
 * This method is called from within the constructor to initialize the form.
 *//*from w  w  w  .j  a v a2 s. c  o m*/
private void initComponents() {

    System.setProperty("PQSortByTimeCheckBox", "true");
    System.setProperty("QueryToolMaxQueryNumber", "20");
    System.setProperty("PQMaxPatientsNumber", "200");
    System.setProperty("PQSortByNameCheckBox", "false");

    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();

    setLayout(new java.awt.BorderLayout());

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("Queries by " + UserInfoBean.getInstance().getUserName());
    tmpData.tooltip("Previous query runs");
    tmpData.visualAttribute("CA");
    top = new DefaultMutableTreeNode(tmpData);
    // top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    // treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(false);

    // jTree1.getSelectionModel().setSelectionMode
    // (TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setShowsRootHandles(true);
    // JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    if (cellStatus.equalsIgnoreCase("CellDown")) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Data Repository Cell is unavailable");
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
        // Make sure the user can see the lovely new node.
        jTree1.expandPath(new TreePath(top.getPath()));
    }

    ArrayList<QueryMasterData> queries = previousQueries;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(queries.get(i));
        }
    }

    jScrollPane1.setViewportView(jTree1);
    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jTree1.setTransferHandler(new NodeCopyTransferHandler());
    jTree1.addTreeExpansionListener(this);
    jTree1.addTreeWillExpandListener(this);
}

From source file:com.ibm.soatf.gui.SOATestingFrameworkGUI.java

/**
 * //from w w  w.j ava  2 s  .  c  o m
 * @param iface 
 */
private void updateDetails(GUIObjects.Interface iface) {
    final Interface ifaceMasterXML = iface.getWrappedObject();
    String name = ifaceMasterXML.getName();
    final InterfaceConfiguration ICFG;
    try {
        ICFG = MCFG.getInterfaceConfig(name);
    } catch (MasterConfigurationException ex) {
        logger.error("Can't load interface details.", ex);
        resetInterfaceDetails();
        return;
    }
    DefaultMutableTreeNode nodeInterface = new DefaultMutableTreeNode(iface);
    DefaultMutableTreeNode nodeProjects = new DefaultMutableTreeNode("SOA Projects");
    //Loop through all project defined in 
    //SOATestingFrameworkMasterConfiguration.Interfaces.Interface
    for (Project project : ifaceMasterXML.getProjects().getProject()) {
        DefaultMutableTreeNode nodeProject = new DefaultMutableTreeNode(new GUIObjects.Project(project));
        nodeProjects.add(nodeProject);
    }
    nodeInterface.add(nodeProjects);
    DefaultMutableTreeNode nodePatterns = new DefaultMutableTreeNode("Flow Patterns");
    /*for (Interface.Patterns.ReferencedFlowPattern refPattern : ifaceMasterXML.getPatterns().getReferencedFlowPattern()) {
     for (int i = 0; i < refPattern.getOccurrence(); i++) {
     String flowPatternId = refPattern.getIdentificator();
     FlowPattern flowPattern = MCFG.getFlowPattern(flowPatternId);
     DefaultMutableTreeNode nodeFlowPattern = new DefaultMutableTreeNode(new GUIObjects.FlowPattern(flowPattern));
     ICFG.getInterfaceFlowPattern(flowPatternId);
     for (TestScenario testScenario : flowPattern.getTestScenario()) {
     DefaultMutableTreeNode nodeTestScenario = new DefaultMutableTreeNode(new GUIObjects.TestScenario(testScenario));
     for (ExecutionBlock executionBlock : testScenario.getExecutionBlock()) {
     DefaultMutableTreeNode nodeExecutionBlock = new DefaultMutableTreeNode(new GUIObjects.ExecutionBlock(executionBlock));
     for (Operation operation : executionBlock.getOperation()) {
     DefaultMutableTreeNode nodeOperation = new DefaultMutableTreeNode(new GUIObjects.Operation(operation));
     nodeExecutionBlock.add(nodeOperation);
     }
     nodeTestScenario.add(nodeExecutionBlock);
     }
     nodeFlowPattern.add(nodeTestScenario);
     }
     nodePatterns.add(nodeFlowPattern);
     }
     }*/
    List<IfaceFlowPattern> ifaceFlowPatterns;
    try {
        ifaceFlowPatterns = ICFG.getIfaceFlowPatterns();
    } catch (InterfaceConfigurationException ex) {
        logger.error("Can't load interface flow patterns.", ex);
        resetInterfaceDetails();
        return;
    }
    for (IfaceFlowPattern iFlowPattern : ifaceFlowPatterns) {
        DefaultMutableTreeNode nodeInterfaceFlowPattern = new DefaultMutableTreeNode(
                new GUIObjects.IfaceFlowPattern(iFlowPattern));
        for (IfaceTestScenario iTestScenario : iFlowPattern.getIfaceTestScenario()) {
            DefaultMutableTreeNode nodeInterfaceTestScenario = new DefaultMutableTreeNode(
                    new GUIObjects.InterfaceTestScenario(iTestScenario));
            for (IfaceExecBlock iExecutionBlock : iTestScenario.getIfaceExecBlock()) {
                DefaultMutableTreeNode nodeInterfaceExecutionBlock = new DefaultMutableTreeNode(
                        new GUIObjects.InterfaceExecutionBlock(iExecutionBlock));
                ExecutionBlock executionBlock;
                try {
                    executionBlock = MCFG.getExecutionBlock(iFlowPattern.getRefId(), iTestScenario.getRefId(),
                            iExecutionBlock.getRefId());
                } catch (MasterConfigurationException ex) {
                    logger.error("Can't load execution block", ex);
                    resetInterfaceDetails();
                    return;
                }
                for (Operation operation : executionBlock.getOperation()) {
                    DefaultMutableTreeNode nodeOperation = new DefaultMutableTreeNode(
                            new GUIObjects.Operation(operation));
                    nodeInterfaceExecutionBlock.add(nodeOperation);
                }
                nodeInterfaceTestScenario.add(nodeInterfaceExecutionBlock);
            }
            TestScenarioPreOrPostExecutionBlock postExecBlock = null;
            try {
                postExecBlock = MCFG.getPostExecutionBlock(iFlowPattern.getRefId(), iTestScenario.getRefId());
            } catch (MasterConfigurationException ex) {
                ;
            }
            if (postExecBlock != null) {
                //TODO KROKY
            }
            nodeInterfaceFlowPattern.add(nodeInterfaceTestScenario);
        }
        nodePatterns.add(nodeInterfaceFlowPattern);
    }
    nodeInterface.add(nodePatterns);

    DefaultTreeModel defaultTreeModel = new DefaultTreeModel(nodeInterface);
    jtInterfaceDetails.setModel(defaultTreeModel);
}

From source file:com.ibm.soatf.gui.SOATestingFrameworkGUI.java

private void resetInterfaceDetails() {
    jtInterfaceDetails.setModel(new DefaultTreeModel(null));
}

From source file:net.sf.jabref.gui.groups.GroupSelector.java

private void setGroups(GroupTreeNode groupsRoot) {
    this.groupsRoot = new GroupTreeNodeViewModel(groupsRoot);
    groupsTreeModel = new DefaultTreeModel(this.groupsRoot);
    this.groupsRoot.subscribeToDescendantChanged(groupsTreeModel::nodeStructureChanged);
    groupsTree.setModel(groupsTreeModel);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_EXPAND_TREE)) {
        this.groupsRoot.expandSubtree(groupsTree);
    }/*  w  w w . j  a  v  a  2s .  c om*/
}