Example usage for javax.swing.tree DefaultTreeModel getChild

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

Introduction

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

Prototype

public Object getChild(Object parent, int index) 

Source Link

Document

Returns the child of parent at index index in the parent's child array.

Usage

From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java

private void analisiRicorsivaAggiuntaTC(Object root, Scenario scenario, DefaultTreeModel model,
        TopComponent topComponentAdded) {
    int indice = model.getChildCount(root);
    for (int i = 0; i < indice; i++) {
        analisiRicorsivaAggiuntaTC(model.getChild(root, i), scenario, model, topComponentAdded);
    }/*  w w w . j  a  va 2  s.co  m*/
    //        if (indice == 2) {
    TreeTopComponentAdapter componentAdapter = (TreeTopComponentAdapter) ((DefaultMutableTreeNode) root)
            .getUserObject();
    TopComponent tc = componentAdapter.getTopComponent();
    if (tc != null && tc == scenario.getMappingTaskTopComponent()) {
        TreeNode treeNode = (TreeNode) root;
        int place = model.getChildCount(treeNode.getParent());
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
                new TreeTopComponentAdapter(topComponentAdded, false, false, false));
        model.insertNodeInto(newNode, (DefaultMutableTreeNode) treeNode.getParent(), place);
    }
    //            return;
    //        }

}

From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java

private void analisiRicorsivaAggiuntaIstanza(Object root, Scenario scenario, DefaultTreeModel model,
        String stringa) {/*from  ww  w  .j  av  a 2 s  .  c  o m*/
    int indice = model.getChildCount(root);
    for (int i = 0; i < indice; i++) {
        analisiRicorsivaAggiuntaIstanza(model.getChild(root, i), scenario, model, stringa);
    }
    //        if (indice == 2) {
    TreeTopComponentAdapter componentAdapter = (TreeTopComponentAdapter) ((DefaultMutableTreeNode) root)
            .getUserObject();
    TopComponent tc = componentAdapter.getTopComponent();
    if (tc != null && tc == scenario.getMappingTaskTopComponent()) {

        TreeTopComponentAdapter ttca = new TreeTopComponentAdapter(null, false, false, true);
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(ttca);
        TreeNode treeNode = ((TreeNode) root).getParent();
        TreeNode nodeInstancesFather = treeNode.getChildAt(2);
        //            if (stringa.equals(Costanti.SOURCE)) {
        TreeNode nodeInstacesSource = nodeInstancesFather.getChildAt(0);
        TreeNode nodeInstacesTarget = nodeInstancesFather.getChildAt(1);
        List<String> sourceInstancesName = (List<String>) scenario.getMappingTask().getSourceProxy()
                .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST);
        List<String> targetInstancesName = (List<String>) scenario.getMappingTask().getTargetProxy()
                .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST);
        int place = 0;
        String name = "xxx";
        if (sourceInstancesName.size() != nodeInstacesSource.getChildCount()) {
            place = nodeInstacesSource.getChildCount();
            name = findTitle(sourceInstancesName.get(sourceInstancesName.size() - 1));
            model.insertNodeInto(newNode, (DefaultMutableTreeNode) nodeInstacesSource, place);
        } else if (targetInstancesName.size() != nodeInstacesTarget.getChildCount()) {
            place = nodeInstacesTarget.getChildCount();
            name = findTitle(targetInstancesName.get(targetInstancesName.size() - 1));
            model.insertNodeInto(newNode, (DefaultMutableTreeNode) nodeInstacesTarget, place);
        }
        ttca.setName(name);
        scenario.getXQueryTopComponent().update();

        //                return;
        //            }

    }
    //            return;
    //        }

}

From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java

private boolean analisiRicorsivaCancellaScenario(Object root, Scenario scenario, DefaultTreeModel model) {
    int indice = model.getChildCount(root);
    //        if (indice == 1 || indice == 2) {
    TreeTopComponentAdapter componentAdapter = (TreeTopComponentAdapter) ((DefaultMutableTreeNode) root)
            .getUserObject();//www .j  a  v a  2s  .c om
    TopComponent tc = componentAdapter.getTopComponent();
    if (tc != null && tc == scenario.getMappingTaskTopComponent()) {
        TreeNode treeNode = (TreeNode) root;
        model.removeNodeFromParent((MutableTreeNode) treeNode.getParent());
        return false;
    }
    //        }

    for (int i = 0; i < indice; i++) {
        if (!analisiRicorsivaCancellaScenario(model.getChild(root, i), scenario, model)) {
            return false;
        }
    }
    return true;

    //        for (int i = 0; i < root.getChildCount(); i++) {
    //            TreePath treePath = jTree.getPathForRow(i);
    //            TreeNode treeNode = (TreeNode) treePath.getLastPathComponent();
    //            TreeTopComponentAdapter componentAdapter = (TreeTopComponentAdapter) ((DefaultMutableTreeNode) treeNode).getUserObject();
    //            TopComponent tc = componentAdapter.getTopComponent();
    //            if (tc != null && tc == scenario.getMappingTaskTopComponent()) {
    //                int place = model.getChildCount(treeNode.getParent());
    //                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(new TreeTopComponentAdapter(topComponentAdded, false, false));
    //                model.insertNodeInto(newNode, (DefaultMutableTreeNode) treeNode.getParent(), place);
    //                model.reload();
    //                break;
    //            }
    //        }
}

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void createPlaylistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createPlaylistActionPerformed
        String input = JOptionPane.showInputDialog("Enter playlist Name: ");
        if (input == null) {
        } else if (!input.equals("")) {
            int validInput = sd.newTreeNode(input);
            if (validInput == 1) {
                treeReferesh();/*from ww  w  .j a v  a  2s . co  m*/
                DefaultTreeModel model = (DefaultTreeModel) folder_Playlist_Tree.getModel();
                DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
                DefaultMutableTreeNode playlist = (DefaultMutableTreeNode) model.getChild(root, 1);
                DefaultMutableTreeNode newPlaylist = (DefaultMutableTreeNode) model.getChild(playlist,
                        model.getChildCount(playlist) - 1);

                getSongTable(newPlaylist.toString());

                TreeNode[] nodes = model.getPathToRoot(newPlaylist);
                TreePath treepath = new TreePath(nodes);

                folder_Playlist_Tree.setExpandsSelectedPaths(true);
                folder_Playlist_Tree.setSelectionPath(treepath);
                folder_Playlist_Tree.scrollPathToVisible(treepath);

                addJMenuItemsToPopUP();

                lastOpen = input;
                for (ObjectBean list1 : list) {
                    if (list1.getTitle().equals("library")) {
                        list1.setLastOpen(lastOpen);
                    }
                }
            } else {
                createPlaylistActionPerformed(evt);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please Enter Valid Playlist Name", "Error in Name",
                    JOptionPane.ERROR_MESSAGE);
            createPlaylistActionPerformed(evt);
        }
    }

From source file:org.codinjutsu.tools.jenkins.view.BrowserPanel.java

private void updateJobNode(Job job) {
    final DefaultTreeModel model = (DefaultTreeModel) jobTree.getModel();
    final Object modelRoot = model.getRoot();
    final int childCount = model.getChildCount(modelRoot);
    for (int i = 0; i < childCount; ++i) {
        Object child = model.getChild(modelRoot, i);
        if (child instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
            if (childNode.getUserObject() == job) {
                model.nodeChanged(childNode);
                break;
            }/*from   w w  w  . j  a va  2  s . c  o m*/
        }
    }
}

From source file:org.openengsb.ui.admin.testClient.TestClientTest.java

@Test
public void testForEachDomainVisibleInCreatePartIsAnEntryInTree_shouldWork() throws Exception {
    setupAndStartTestClientPage();//  ww  w  . j a va2s . co m
    tester.assertRenderedPage(TestClient.class);
    List<String> domains = new ArrayList<String>();
    List<String> availableInTree = new ArrayList<String>();
    List<DefaultMutableTreeNode> availableInTreeAsTreeNode = new ArrayList<DefaultMutableTreeNode>();

    Component domainsComponent = tester.getComponentFromLastRenderedPage("serviceManagementContainer:domains");
    int count = ((ArrayList<?>) domainsComponent.getDefaultModelObject()).size();

    // get all domains
    for (int i = 0; i < count; i++) {
        Component label = tester
                .getComponentFromLastRenderedPage("serviceManagementContainer:domains:" + i + ":domain.name");
        domains.add(label.getDefaultModelObjectAsString());
    }

    // get all services from the tree
    DefaultTreeModel serviceListTree = (DefaultTreeModel) tester
            .getComponentFromLastRenderedPage("methodCallForm:serviceList").getDefaultModelObject();
    count = serviceListTree.getChildCount(serviceListTree.getRoot());
    for (int i = 0; i < count; i++) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) serviceListTree
                .getChild(serviceListTree.getRoot(), i);
        String userObject = (String) child.getUserObject();
        availableInTreeAsTreeNode.add(child);
        availableInTree.add(userObject);
    }

    for (int i = 0; i < domains.size(); i++) {
        String domain = domains.get(i);
        assertThat(availableInTree.contains(domain), is(true));
        assertThat(serviceListTree.getChildCount(availableInTreeAsTreeNode.get(i)), greaterThan(0));
    }
}

From source file:ser321.media.MediaJavaClient.java

private void clearTree(DefaultMutableTreeNode root, DefaultTreeModel model) {
    try {/*from   w w w . j  a v  a2  s  .  com*/
        DefaultMutableTreeNode next = null;
        int subs = model.getChildCount(root);
        for (int k = subs - 1; k >= 0; k--) {
            next = (DefaultMutableTreeNode) model.getChild(root, k);
            debug("removing node labelled:" + (String) next.getUserObject());
            model.removeNodeFromParent(next);
        }
    } catch (Exception ex) {
        System.out.println("Exception while trying to clear tree:");
        ex.printStackTrace();
    }
}