Example usage for javax.swing.tree TreePath getPathComponent

List of usage examples for javax.swing.tree TreePath getPathComponent

Introduction

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

Prototype

public Object getPathComponent(int index) 

Source Link

Document

Returns the path element at the specified index.

Usage

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

private Set<String> getOpenPaths() {
    Set<String> retVal = new HashSet<String>();

    TableModel model = getModel();
    AbstractLayoutCache layout = ((OutlineModel) model).getLayout();
    int messageIndex = -1;
    for (int i = 0; i < layout.getRowCount(); i++) {
        TreePath path = layout.getPathForRow(i);

        Object baseObj = path.getLastPathComponent();
        if (baseObj instanceof TreeNodeMessage || baseObj instanceof TreeNodeUnknown) {

            messageIndex++;//from   w  w w .  ja va2s. co  m

            if (layout.getExpandedState(path)) {
                retVal.add(Integer.toString(messageIndex));
            }

        } else {

            baseObj = path.getPathComponent(path.getPathCount() - 2);
            if (baseObj instanceof TreeNodeBase) {
                retVal.add(Integer.toString(messageIndex) + ((TreeNodeBase) baseObj).getTerserPath());
            }
        }

    }

    return retVal;
}

From source file:org.kepler.gui.popups.LibraryPopupListener.java

/** Determine if this object is contained within a KAR
 *  by checking all of the parent objects to see if they
 *  are a KAREntityLibrary. do not check the object itself
*//*  w ww .j a  v  a 2s  . c o  m*/
private boolean _isPathInsideKAR(TreePath selPath) {
    for (int i = (selPath.getPathCount() - 2); i >= 0; i--) {
        if (selPath.getPathComponent(i) instanceof KAREntityLibrary) {
            return true;
        }
    }
    return false;
}

From source file:org.kepler.gui.popups.OutlinePopupListener.java

/**
 * Description of the Method//  www.j  ava2 s .  c o m
 * 
 *@param e
 *            Description of the Parameter
 */
private void maybeShowPopup(MouseEvent e) {
    if (isDebugging)
        log.debug("maybeShowPopup(" + e.toString() + ")");
    if (e.isPopupTrigger() || _trigger) {
        _trigger = false;
        TreePath selPath = _aptree.getPathForLocation(e.getX(), e.getY());
        if (isDebugging)
            log.debug(selPath.toString());
        if ((selPath != null)) {

            // determine if this object is contained within a KAR
            // by checking all of the parent objects to see
            // if they are a KAREntityLibrary
            // do not check the object itself
            boolean inKAR = false;
            Object ob = null;
            for (int i = (selPath.getPathCount() - 2); i >= 0; i--) {
                ob = selPath.getPathComponent(i);
                if (ob instanceof KAREntityLibrary) {
                    inKAR = true;
                    break;
                }
            }

            ob = selPath.getLastPathComponent();
            if (isDebugging)
                log.debug(ob.getClass().getName());

            if (!inKAR) {
                handlePopupOutsideKar(selPath, e);
            }
        }
    }
}

From source file:org.kepler.gui.ResultTreeRebuilder.java

/**
 * Description of the Method/*  w  w w.  j  av  a 2 s . com*/
 * 
 *@exception IllegalActionException
 *                Description of the Exception
 */
private void buildResultTree(EntityLibrary newRoot) throws IllegalActionException {
    if (isDebugging)
        log.debug("buildResultTree()");

    // iterate over each treepath in results
    for (int i = 0; i < results.size(); i++) {

        try {

            TreePath currentPath = results.getTreePath(i);
            if (isDebugging)
                log.debug(currentPath);

            EntityLibrary treeCurrent = newRoot;
            for (int j = 1; j < currentPath.getPathCount(); j++) {

                NamedObj pathCurrent = (NamedObj) currentPath.getPathComponent(j);

                if (pathCurrent instanceof EntityLibrary) {

                    List<EntityLibrary> children = treeCurrent.entityList(EntityLibrary.class);

                    boolean alreadyThere = false;
                    for (EntityLibrary child : children) {
                        if (isDebugging)
                            log.debug(child.getName());
                        if (child.getName().equals(pathCurrent.getName())) {
                            // this EntityLibrary is already there
                            treeCurrent = child;
                            alreadyThere = true;
                            break;
                        }
                    }
                    if (!alreadyThere) {
                        // create it
                        EntityLibrary newEntity = copyEntityLibrary((EntityLibrary) pathCurrent);
                        setContainer(treeCurrent, newEntity);
                        treeCurrent = newEntity;
                    }

                } else {
                    List<NamedObj> children = treeCurrent.entityList(NamedObj.class);

                    boolean alreadyThere = false;
                    for (NamedObj child : children) {
                        if (child.getName().equals(pathCurrent.getName())) {
                            // this NamedObj is already there
                            alreadyThere = true;
                            break;
                        }
                    }
                    if (!alreadyThere) {
                        // create it
                        NamedObj newEntity = cloneEntity((NamedObj) pathCurrent);
                        setContainer(treeCurrent, newEntity);
                        // Leaf node, all done
                        break;
                    }
                }
            }

        } catch (IllegalActionException iae) {
            throw new IllegalActionException("cannot build search result tree: " + iae);
        } catch (NameDuplicationException nde) {
            log.error("EXCEPTION CAUGHT: " + nde.getMessage());
        } catch (Exception e) {
            log.error("EXCEPTION CAUGHT: " + e.getMessage());
        }
    } // end for loop
}

From source file:ui.panel.UILicenseAdd.java

private JPanel createPnlFeature() {
    JPanel panel = p.createPanel(Layouts.gridbag);

    GridBagConstraints g = new GridBagConstraints();
    lblSelectFeature = l.createLabel("Select Features", SwingConstants.LEFT);
    g.gridx = 0;//w  w  w  .  java 2s .  co  m
    g.gridy = 0;
    g.gridwidth = 2;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(lblSelectFeature, g);

    lblServiceApi = l.createLabel("Service APIs Used", SwingConstants.LEFT);
    g.gridx = 4;
    g.gridy = 0;
    g.gridwidth = 2;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(lblServiceApi, g);
    getFeaturesData();
    DefaultMutableTreeNode root = new MyDataNode("Features", "Features");
    for (String key : Data.featureList.keySet()) {
        try {
            DefaultMutableTreeNode element = new MyDataNode(key, Data.fieldNames.get(key));

            JSONArray features = Data.featureList.get(key);
            ArrayList<DefaultMutableTreeNode> arrayFeatureCheckBox = new ArrayList<DefaultMutableTreeNode>();

            for (int i = 0; i < features.length(); i++) {
                JSONObject feature = features.getJSONObject(i);
                DefaultMutableTreeNode featureElement = new MyDataNode((String) feature.get("name"),
                        Data.fieldNames.get(feature.get("name")));
                element.add(featureElement);
                arrayFeatureCheckBox.add(featureElement);
            }

            root.add(element);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    tree = new JTree(root);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            model.removeAllElements();
            String item = tree.getSelectionModel().getSelectionPath().getLastPathComponent().toString();
            MyDataNode node = (MyDataNode) tree.getSelectionModel().getSelectionPath().getLastPathComponent();
            String selected = node.getValue();
            servicesList = new HashMap<String, String>();
            try {
                if (selected.equalsIgnoreCase("Features")) {
                    for (String key : Data.featureList.keySet()) {
                        JSONArray featureArray = Data.featureList.get(key);

                        for (int i = 0; i < featureArray.length(); i++) {
                            JSONArray servicesArray = featureArray.getJSONObject(i).getJSONArray("services");

                            for (int x = 0; x < servicesArray.length(); x++) {
                                servicesList.put(Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                        servicesArray.getJSONObject(x).getString("name"));
                            }
                        }
                    }
                } else if (path.getPathCount() == 2) {
                    for (String key : Data.featureList.keySet()) {
                        if (key.equals(selected)) {
                            JSONArray featureArray = Data.featureList.get(key);

                            for (int i = 0; i < featureArray.length(); i++) {
                                JSONArray servicesArray = featureArray.getJSONObject(i)
                                        .getJSONArray("services");

                                for (int x = 0; x < servicesArray.length(); x++) {
                                    servicesList.put(
                                            Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                            servicesArray.getJSONObject(x).getString("name"));
                                }
                            }
                        } else {
                            continue;
                        }
                    }
                } else {
                    MyDataNode nodePath = (MyDataNode) path.getPathComponent(1);
                    for (String key : Data.featureList.keySet()) {
                        if (key.equals(nodePath.getValue())) {

                            JSONArray featureArray = Data.featureList.get(key);
                            for (int i = 0; i < featureArray.length(); i++) {
                                System.out.println(
                                        featureArray.getJSONObject(i).getString("name") + ":" + selected);
                                if (featureArray.getJSONObject(i).getString("name").equals(selected)) {
                                    JSONArray servicesArray = featureArray.getJSONObject(i)
                                            .getJSONArray("services");
                                    System.out.println(servicesArray);
                                    for (int x = 0; x < servicesArray.length(); x++) {
                                        servicesList.put(
                                                Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                                servicesArray.getJSONObject(x).getString("name"));
                                    }
                                } else {
                                    continue;
                                }
                            }
                        } else {
                            continue;
                        }
                    }
                }
            } catch (JSONException ex) {
                ex.printStackTrace();
            }
            for (String serviceKey : servicesList.keySet()) {
                model.addElement(servicesList.get(serviceKey));
            }
            listServiceUsed.setModel(model);
        }
    });
    checkTreeManager = new CheckTreeManager(tree);

    spTreeCheckBox = new JScrollPane(tree);
    spTreeCheckBox.setPreferredSize(new Dimension(300, 300));
    g.gridx = 0;
    g.gridy = 1;
    g.gridwidth = 3;
    g.anchor = g.LINE_START;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(spTreeCheckBox, g);

    model = new DefaultListModel<>();
    model.addElement("");
    listServiceUsed = new JList<String>(model);
    spList = new JScrollPane(listServiceUsed);
    spList.setPreferredSize(new Dimension(300, 300));
    g.gridx = 4;
    g.gridy = 1;
    g.gridwidth = 3;
    g.anchor = g.LINE_START;
    panel.add(spList, g);

    return panel;
}