Example usage for javax.swing.tree DefaultMutableTreeNode getChildCount

List of usage examples for javax.swing.tree DefaultMutableTreeNode getChildCount

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children of this node.

Usage

From source file:eu.crisis_economics.abm.dashboard.GASearchHandler.java

private void saveParameterOrGene(final DefaultMutableTreeNode node, final ObjectFactory factory,
        final Object parent) {
    final ParameterOrGene userObj = (ParameterOrGene) node.getUserObject();
    final ParameterInfo info = userObj.getInfo();

    if (userObj.isGene()) {
        final GeneInfo geneInfo = userObj.getGeneInfo();

        final eu.crisis_economics.abm.dashboard.generated.Gene gene = factory.createGene();
        gene.setName(info.getName());/*w w  w .  j a va 2 s  .co m*/
        gene.setGeneType(geneInfo.getValueType());

        if (GeneInfo.INTERVAL.equals(geneInfo.getValueType())) {
            gene.setInteger(geneInfo.isIntegerVals());
            gene.setMin(geneInfo.isIntegerVals() ? new BigDecimal(geneInfo.getMinValue().longValue())
                    : new BigDecimal(geneInfo.getMinValue().doubleValue()));
            gene.setMax(geneInfo.isIntegerVals() ? new BigDecimal(geneInfo.getMaxValue().longValue())
                    : new BigDecimal(geneInfo.getMaxValue().doubleValue()));
        } else {
            final List<String> geneValues = gene.getGeneValueList();
            for (final Object value : geneInfo.getValueRange())
                geneValues.add(String.valueOf(value));
        }

        if (parent instanceof eu.crisis_economics.abm.dashboard.generated.Chromosome) {
            final eu.crisis_economics.abm.dashboard.generated.Chromosome chromosome = (eu.crisis_economics.abm.dashboard.generated.Chromosome) parent;
            chromosome.getGeneList().add(gene);
        } else if (parent instanceof SubmodelParameter) {
            final SubmodelParameter submodelParameter = (SubmodelParameter) parent;
            submodelParameter.getGeneList().add(gene);
        }

    } else if (info instanceof SubmodelInfo) {
        final SubmodelInfo sInfo = (SubmodelInfo) info;

        final SubmodelParameter parameter = factory.createSubmodelParameter();
        parameter.setName(info.getName());
        parameter.setType(sInfo.getActualType() == null ? "null" : sInfo.getActualType().getName());

        if (parent instanceof eu.crisis_economics.abm.dashboard.generated.Chromosome) {
            final eu.crisis_economics.abm.dashboard.generated.Chromosome chromosome = (eu.crisis_economics.abm.dashboard.generated.Chromosome) parent;
            chromosome.getSubmodelParameterList().add(parameter);
        } else if (parent instanceof SubmodelParameter) {
            final SubmodelParameter submodelParameter = (SubmodelParameter) parent;
            submodelParameter.getSubmodelParameterList().add(parameter);
        }

        if (node.getChildCount() > 0) {
            @SuppressWarnings("rawtypes")
            final Enumeration childNodes = node.children();
            while (childNodes.hasMoreElements()) {
                final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) childNodes.nextElement();
                saveParameterOrGene(childNode, factory, parameter);
            }
        }
    } else {
        final Parameter parameter = factory.createParameter();
        parameter.setName(info.getName());
        parameter.setParameterType(ParameterType.CONSTANT);
        parameter.getContent().add(info.getValue().toString());

        if (parent instanceof eu.crisis_economics.abm.dashboard.generated.Chromosome) {
            final eu.crisis_economics.abm.dashboard.generated.Chromosome chromosome = (eu.crisis_economics.abm.dashboard.generated.Chromosome) parent;
            chromosome.getParameterList().add(parameter);
        } else if (parent instanceof SubmodelParameter) {
            final SubmodelParameter submodelParameter = (SubmodelParameter) parent;
            submodelParameter.getParameterList().add(parameter);
        }
    }
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

public void treeExpanded(TreeExpansionEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryData data = (QueryData) node.getUserObject();

    /*if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase(
    "QueryResultData")) {/*w w w  . j  ava 2  s  .  c  o  m*/
       QueryResultData rdata = (QueryResultData) node.getUserObject();
       if (rdata.patientCount().equalsIgnoreCase("0")) {
    return;
    /*
     * final JPanel parent = this;
     * java.awt.EventQueue.invokeLater(new Runnable() { public void
     * run() { JOptionPane.showMessageDialog(parent, "There's no
     * patient in this set.", "Message",
     * JOptionPane.INFORMATION_MESSAGE); } });
     */

    //}
    //}*/

    jTree1.scrollPathToVisible(new TreePath(node));

    System.out.println("Node expanded: " + data.name());

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }

    // check to see if child is a placeholder ('working...')
    // if so, make Web Service call to update children of node
    if (node.getChildCount() == 1) {
        final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0);
        if (((QueryData) node1.getUserObject()).visualAttribute().equals("LAO")
                && ((QueryData) node1.getUserObject()).name().equals("working ......")) {
            final DefaultMutableTreeNode anode = node;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    populateChildNodes(anode);
                }
            });
        }
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0);
            QueryData adata = (QueryData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                adata.visualAttribute("CA");
            }
        }
    }
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void savePSParameter(final DefaultMutableTreeNode node, final ObjectFactory factory,
        final Object parent, final int position) {
    final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
    final ParameterInfo info = userObj.info;

    if (info instanceof SubmodelInfo) {
        final SubmodelInfo sInfo = (SubmodelInfo) info;

        final SubmodelParameter parameter = factory.createSubmodelParameter();
        parameter.setName(info.getName());
        parameter.setType(sInfo.getActualType() == null ? "null" : sInfo.getActualType().getName());
        parameter.setPosition(BigInteger.valueOf(position));

        if (parent instanceof Combination) {
            final Combination combination = (Combination) parent;
            combination.getSubmodelParameterList().add(parameter);
        } else if (parent instanceof SubmodelParameter) {
            final SubmodelParameter submodelParameter = (SubmodelParameter) parent;
            submodelParameter.getSubmodelParameterList().add(parameter);
        }/*from  ww  w .  j  av  a2  s  . co  m*/

        if (node.getChildCount() > 0) {
            @SuppressWarnings("rawtypes")
            final Enumeration childNodes = node.children();
            int childPosition = 1;
            while (childNodes.hasMoreElements()) {
                final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) childNodes.nextElement();
                savePSParameter(childNode, factory, parameter, childPosition++);
            }
        }
    } else {
        final Parameter parameter = factory.createParameter();
        parameter.setName(info.getName());
        parameter.setPosition(BigInteger.valueOf(position));

        switch (info.getDefinitionType()) {
        case ParameterInfo.CONST_DEF:
            parameter.setParameterType(ParameterType.CONSTANT);
            parameter.getContent().add(info.getValue().toString());
            break;

        case ParameterInfo.LIST_DEF:
            parameter.setParameterType(ParameterType.LIST);
            savePSListParameter(info, parameter, factory);
            break;

        case ParameterInfo.INCR_DEF:
            parameter.setParameterType(ParameterType.INCREMENT);
            savePSIncrementParameter(info, parameter, factory);
            break;
        }

        if (parent instanceof Combination) {
            final Combination combination = (Combination) parent;
            combination.getParameterList().add(parameter);
        } else if (parent instanceof SubmodelParameter) {
            final SubmodelParameter submodelParameter = (SubmodelParameter) parent;
            submodelParameter.getParameterList().add(parameter);
        }
    }
}

From source file:lcmc.gui.resources.ServiceInfo.java

/** Puts a resource down in a group. */
void downResource(final Host dcHost, final boolean testOnly) {
    final GroupInfo gi = groupInfo;
    final DefaultMutableTreeNode giNode = gi.getNode();
    if (giNode == null) {
        return;//from w  w  w  . j  a  va 2 s  .  c  o m
    }
    final DefaultMutableTreeNode node = getNode();
    if (node == null) {
        return;
    }
    final int index = giNode.getIndex(node);
    if (index < giNode.getChildCount() - 1) {
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> e = giNode.children();
        final List<String> newOrder = new ArrayList<String>();
        while (e.hasMoreElements()) {
            final DefaultMutableTreeNode n = e.nextElement();
            final ServiceInfo child = (ServiceInfo) n.getUserObject();
            newOrder.add(child.getHeartbeatId(testOnly));
        }
        final String el = newOrder.remove(index);
        newOrder.add(index + 1, el);
        if (!testOnly) {
            setUpdated(true);
        }
        gi.applyWhole(dcHost, false, newOrder, testOnly);
    }
}

From source file:lcmc.gui.resources.ServiceInfo.java

/**
 * Returns list of items for service popup menu with actions that can
 * be executed on the heartbeat services.
 *//*from  ww w  .  j  a  v  a2s  . c o m*/
@Override
public List<UpdatableItem> createPopup() {
    final List<UpdatableItem> items = new ArrayList<UpdatableItem>();
    final boolean testOnly = false;
    final CloneInfo ci = getCloneInfo();
    if (ci == null) {
        addDependencyMenuItems(items, false, testOnly);
    }
    /* start resource */
    final MyMenuItem startMenuItem = new MyMenuItem(Tools.getString("ClusterBrowser.Hb.StartResource"),
            START_ICON, ClusterBrowser.STARTING_PTEST_TOOLTIP, new AccessMode(ConfigData.AccessType.OP, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;

        @Override
        public final String enablePredicate() {
            if (getBrowser().clStatusFailed()) {
                return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            } else if (isStarted(testOnly)) {
                return Tools.getString("ServiceInfo.AlreadyStarted");
            } else {
                return getService().isAvailableWithText();
            }
        }

        @Override
        public void action() {
            hidePopup();
            startResource(getBrowser().getDCHost(), testOnly);
        }
    };
    final ClusterBrowser.ClMenuItemCallback startItemCallback = getBrowser().new ClMenuItemCallback(
            startMenuItem, null) {
        @Override
        public void action(final Host dcHost) {
            startResource(dcHost, true); /* testOnly */
        }
    };
    addMouseOverListener(startMenuItem, startItemCallback);
    items.add((UpdatableItem) startMenuItem);

    /* stop resource */
    final MyMenuItem stopMenuItem = new MyMenuItem(Tools.getString("ClusterBrowser.Hb.StopResource"), STOP_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP, new AccessMode(ConfigData.AccessType.OP, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;

        @Override
        public String enablePredicate() {
            if (getBrowser().clStatusFailed()) {
                return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            } else if (isStopped(testOnly)) {
                return Tools.getString("ServiceInfo.AlreadyStopped");
            } else {
                return getService().isAvailableWithText();
            }
        }

        @Override
        public void action() {
            hidePopup();
            stopResource(getBrowser().getDCHost(), testOnly);
        }
    };
    final ClusterBrowser.ClMenuItemCallback stopItemCallback = getBrowser().new ClMenuItemCallback(stopMenuItem,
            null) {
        @Override
        public void action(final Host dcHost) {
            stopResource(dcHost, true); /* testOnly */
        }
    };
    addMouseOverListener(stopMenuItem, stopItemCallback);
    items.add((UpdatableItem) stopMenuItem);

    /* up group resource */
    final MyMenuItem upMenuItem = new MyMenuItem(Tools.getString("ClusterBrowser.Hb.UpResource"), GROUP_UP_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP, new AccessMode(ConfigData.AccessType.OP, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean visiblePredicate() {
            return groupInfo != null;
        }

        @Override
        public String enablePredicate() {
            if (getResource().isNew()) {
                return IS_NEW_STRING;
            }
            final GroupInfo gi = groupInfo;
            if (gi == null) {
                return "no";
            }
            if (getBrowser().clStatusFailed()) {
                return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            }
            final DefaultMutableTreeNode giNode = gi.getNode();
            if (giNode == null) {
                return "no";
            }
            final DefaultMutableTreeNode node = getNode();
            if (node == null) {
                return "no";
            }
            final int index = giNode.getIndex(node);
            if (index == 0) {
                return "already up";
            }
            return null;
        }

        @Override
        public void action() {
            hidePopup();
            upResource(getBrowser().getDCHost(), testOnly);
        }
    };
    final ClusterBrowser.ClMenuItemCallback upItemCallback = getBrowser().new ClMenuItemCallback(upMenuItem,
            null) {
        @Override
        public void action(final Host dcHost) {
            upResource(dcHost, true); /* testOnly */
        }
    };
    addMouseOverListener(upMenuItem, upItemCallback);
    items.add((UpdatableItem) upMenuItem);

    /* down group resource */
    final MyMenuItem downMenuItem = new MyMenuItem(Tools.getString("ClusterBrowser.Hb.DownResource"),
            GROUP_DOWN_ICON, ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.OP, false), new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean visiblePredicate() {
            return groupInfo != null;
        }

        @Override
        public String enablePredicate() {
            if (getResource().isNew()) {
                return IS_NEW_STRING;
            }
            final GroupInfo gi = groupInfo;
            if (gi == null) {
                return "no";
            }
            if (getBrowser().clStatusFailed()) {
                return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            }
            final DefaultMutableTreeNode giNode = gi.getNode();
            if (giNode == null) {
                return "no";
            }
            final DefaultMutableTreeNode node = getNode();
            if (node == null) {
                return "no";
            }
            final int index = giNode.getIndex(node);
            if (index >= giNode.getChildCount() - 1) {
                return "already down";
            }
            return null;
        }

        @Override
        public void action() {
            hidePopup();
            downResource(getBrowser().getDCHost(), testOnly);
        }
    };
    final ClusterBrowser.ClMenuItemCallback downItemCallback = getBrowser().new ClMenuItemCallback(downMenuItem,
            null) {
        @Override
        public void action(final Host dcHost) {
            downResource(dcHost, true); /* testOnly */
        }
    };
    addMouseOverListener(downMenuItem, downItemCallback);
    items.add((UpdatableItem) downMenuItem);

    /* clean up resource */
    final MyMenuItem cleanupMenuItem = new MyMenuItem(
            Tools.getString("ClusterBrowser.Hb.CleanUpFailedResource"), SERVICE_RUNNING_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,

            Tools.getString("ClusterBrowser.Hb.CleanUpResource"), SERVICE_RUNNING_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP, new AccessMode(ConfigData.AccessType.OP, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean predicate() {
            return getService().isAvailable() && isOneFailed(testOnly);
        }

        @Override
        public String enablePredicate() {
            if (getBrowser().clStatusFailed()) {
                return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            } else if (!isOneFailedCount(testOnly)) {
                return "no fail count";
            } else {
                return getService().isAvailableWithText();
            }
        }

        @Override
        public void action() {
            hidePopup();
            cleanupResource(getBrowser().getDCHost(), testOnly);
        }
    };
    /* cleanup ignores CIB_file */
    items.add((UpdatableItem) cleanupMenuItem);

    /* manage resource */
    final MyMenuItem manageMenuItem = new MyMenuItem(Tools.getString("ClusterBrowser.Hb.ManageResource"),
            MANAGE_BY_CRM_ICON, ClusterBrowser.STARTING_PTEST_TOOLTIP,

            Tools.getString("ClusterBrowser.Hb.UnmanageResource"), UNMANAGE_BY_CRM_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,

            new AccessMode(ConfigData.AccessType.OP, false), new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean predicate() {
            return !isManaged(testOnly);
        }

        @Override
        public String enablePredicate() {
            if (getBrowser().clStatusFailed()) {
                return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            } else {
                return getService().isAvailableWithText();
            }
        }

        @Override
        public void action() {
            hidePopup();
            if (this.getText().equals(Tools.getString("ClusterBrowser.Hb.ManageResource"))) {
                setManaged(true, getBrowser().getDCHost(), testOnly);
            } else {
                setManaged(false, getBrowser().getDCHost(), testOnly);
            }
        }
    };
    final ClusterBrowser.ClMenuItemCallback manageItemCallback = getBrowser().new ClMenuItemCallback(
            manageMenuItem, null) {
        @Override
        public void action(final Host dcHost) {
            setManaged(!isManaged(false), dcHost, true); /* testOnly */
        }
    };
    addMouseOverListener(manageMenuItem, manageItemCallback);
    items.add((UpdatableItem) manageMenuItem);
    addMigrateMenuItems(items);
    if (ci == null) {
        /* remove service */
        final MyMenuItem removeMenuItem = new MyMenuItem(Tools.getString("ClusterBrowser.Hb.RemoveService"),
                ClusterBrowser.REMOVE_ICON, ClusterBrowser.STARTING_PTEST_TOOLTIP,
                new AccessMode(ConfigData.AccessType.ADMIN, false),
                new AccessMode(ConfigData.AccessType.OP, false)) {
            private static final long serialVersionUID = 1L;

            @Override
            public String enablePredicate() {
                if (getService().isNew()) {
                    return null;
                }
                if (getBrowser().clStatusFailed()) {
                    return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
                } else if (getService().isRemoved()) {
                    return IS_BEING_REMOVED_STRING;
                } else if (isRunning(testOnly) && !Tools.getConfigData().isAdvancedMode()) {
                    return "cannot remove running resource<br>" + "(advanced mode only)";
                }
                if (groupInfo == null) {
                    return null;
                }
                final ClusterStatus cs = getBrowser().getClusterStatus();
                final List<String> gr = cs.getGroupResources(groupInfo.getHeartbeatId(testOnly), testOnly);

                if (gr != null && gr.size() > 1) {
                    return null;
                } else {
                    return "you can remove the group";
                }
            }

            @Override
            public void action() {
                hidePopup();
                if (getService().isOrphaned()) {
                    cleanupResource(getBrowser().getDCHost(), testOnly);
                } else {
                    removeMyself(false);
                }
                getBrowser().getCRMGraph().repaint();
            }
        };
        final ServiceInfo thisClass = this;
        final ClusterBrowser.ClMenuItemCallback removeItemCallback = getBrowser().new ClMenuItemCallback(
                removeMenuItem, null) {
            @Override
            public final boolean isEnabled() {
                return super.isEnabled() && !getService().isNew();
            }

            @Override
            public final void action(final Host dcHost) {
                removeMyselfNoConfirm(dcHost, true); /* test only */
            }
        };
        addMouseOverListener(removeMenuItem, removeItemCallback);
        items.add((UpdatableItem) removeMenuItem);
    }
    /* view log */
    final MyMenuItem viewLogMenu = new MyMenuItem(Tools.getString("ClusterBrowser.Hb.ViewServiceLog"),
            LOGFILE_ICON, null, new AccessMode(ConfigData.AccessType.RO, false),
            new AccessMode(ConfigData.AccessType.RO, false)) {

        private static final long serialVersionUID = 1L;

        @Override
        public String enablePredicate() {
            if (getService().isNew()) {
                return IS_NEW_STRING;
            } else {
                return null;
            }
        }

        @Override
        public void action() {
            hidePopup();
            ServiceLogs l = new ServiceLogs(getBrowser().getCluster(), getNameForLog(),
                    getService().getHeartbeatId());
            l.showDialog();
        }
    };
    items.add(viewLogMenu);
    /* more migrate options */
    final MyMenu migrateSubmenu = new MyMenu(Tools.getString("ClusterBrowser.MigrateSubmenu"),
            new AccessMode(ConfigData.AccessType.OP, false), new AccessMode(ConfigData.AccessType.OP, false)) {
        private static final long serialVersionUID = 1L;

        @Override
        public String enablePredicate() {
            return null; //TODO: enable only if it has items
        }
    };
    items.add(migrateSubmenu);
    addMoreMigrateMenuItems(migrateSubmenu);

    /* config files */
    final MyMenu filesSubmenu = new MyMenu(Tools.getString("ClusterBrowser.FilesSubmenu"),
            new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.ADMIN, false)) {
        private static final long serialVersionUID = 1L;

        @Override
        public String enablePredicate() {
            return null; //TODO: enable only if it has items
        }

        @Override
        public void update() {
            super.update();
            final MyMenu self = this;
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    removeAll();
                    addFilesMenuItems(self);
                }
            });
        }
    };
    items.add(filesSubmenu);
    return items;
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

private DefaultMutableTreeNode findNode(DefaultMutableTreeNode node, Object userObject) {
    DefaultMutableTreeNode retVal = null;
    if (node.getUserObject().equals(userObject)) {
        retVal = node;//from  www.  ja  v  a  2  s. c  om
    }
    if (retVal == null) {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode nodeChild = (DefaultMutableTreeNode) node.getChildAt(i);
            retVal = findNode(nodeChild, userObject);
            if (retVal != null) {
                break;
            }
        }
    }
    return retVal;
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

private void getMatchingFiles(String baseFileName, DefaultMutableTreeNode rootNode, FSOCollection files) {
    if (rootNode.getUserObject() instanceof FileSystemObject) {
        FileSystemObject fso = (FileSystemObject) rootNode.getUserObject();
        if (fso.getFileNameWithoutRepTypeOrSuffix().equals(baseFileName)) {
            files.add(fso);//from  w w w .  ja va 2s  . com
        }
    }
    for (int i = 0; i < rootNode.getChildCount(); i++) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) rootNode.getChildAt(i);
        getMatchingFiles(baseFileName, node, files);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void expandNode(JTree whichTree, DefaultMutableTreeNode node, boolean recurse) {

    whichTree.expandPath(new TreePath(node.getPath()));
    if (recurse && node.getChildCount() > 0) {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
            expandNode(whichTree, child, recurse);
        }/*from  w w  w  . ja v  a 2  s .c o  m*/
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void addChildFiles(DefaultMutableTreeNode rootNode, FSOCollection children, DepositTreeModel model,
        String pathToDisplay, JTree whichTree) {
    LOG.debug("addChildFiles, root: " + rootNode.getUserObject());
    model.reload(rootNode);// w  w w.j a  va2 s .c o m
    /*      for (FileSystemObject fso : children) {
             if (fso.getFile() == null) {
    LOG.debug("add child (file is null): " + fso.getDescription());
             } else {
    LOG.debug("add child (file is not null): "
          + fso.getDescription());
             }
             if ((!model.getTreeType().equals(ETreeType.FileSystemTree))
       || (!fso.getIsFile()) || (!fileIsInEntity(fso))) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    node.setUserObject(fso);
    model.insertNodeInto(node, rootNode, rootNode.getChildCount());
    addChildFiles(node, fso.getChildren(), model, pathToDisplay,
          whichTree);
    if ((pathToDisplay != null)
          && (pathToDisplay.equals(fso.getFullPath()))) {
       expandNode(whichTree, node, false);
       whichTree.scrollPathToVisible(new TreePath(node.getPath()));
    }
             }
          }*/
    for (int i = 0; i < children.size(); i++) {
        FileSystemObject fso = children.get(i);
        if (fso.getFile() == null) {
            LOG.debug("add child (file is null): " + fso.getDescription());
        } else {
            LOG.debug("add child (file is not null): " + fso.getDescription());
        }
        if ((!model.getTreeType().equals(ETreeType.FileSystemTree)) || (!fso.getIsFile())
                || (!fileIsInEntity(fso))) {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode();
            node.setUserObject(fso);
            model.insertNodeInto(node, rootNode, rootNode.getChildCount());
            addChildFiles(node, fso.getChildren(), model, pathToDisplay, whichTree);
            if ((pathToDisplay != null) && (pathToDisplay.equals(fso.getFullPath()))) {
                expandNode(whichTree, node, false);
                whichTree.scrollPathToVisible(new TreePath(node.getPath()));
            }
        }
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public DefaultMutableTreeNode addIntellectualEntity(DefaultMutableTreeNode rootNode, FileGroup entity,
        boolean editEntry) {
    DepositTreeModel model = (DepositTreeModel) theEntityTree.getModel();
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    newNode.setUserObject(entity);//  w  ww  .j a v a2s  . c o m
    model.insertNodeInto(newNode, rootNode, rootNode.getChildCount());
    if (entity.getChildren() == null) {
        entity.setChildren(FSOCollection.create());
    }
    addChildFiles(newNode, entity.getChildren(), model, null, null);
    TreePath newPath = new TreePath(newNode.getPath());
    theEntityTree.scrollPathToVisible(newPath);
    theEntityTree.setSelectionPath(newPath);
    theEntityTree.repaint();
    if (editEntry) {
        editEntity();
    }
    return newNode;
}