Example usage for javax.swing.tree DefaultMutableTreeNode isLeaf

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

Introduction

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

Prototype

public boolean isLeaf() 

Source Link

Document

Returns true if this node has no children.

Usage

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.controller.CreateConsentServiceServlet.java

/**
 * This method provides upon request the root of the organisation-tree and
 * the first batch of it's children.//from   w  ww  .  ja  v  a 2s  .  c  om
 */
@SuppressWarnings("rawtypes")
private void requestTypeTreeRoot() {

    try {

        DefaultMutableTreeNode node = ccService.getOIDTreeRoot();

        Vector<JSONObject> vjbo = new Vector<JSONObject>();

        for (Enumeration e = node.children(); e.hasMoreElements();) {

            DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
            JSONObject jso = new JSONObject();
            jso.put("name", ((OIDObject) n.getUserObject()).getName());
            jso.put("identifier", ((OIDObject) n.getUserObject()).getIdentifier());
            jso.put("hasChildren", !n.isLeaf());
            jso.put("isActive", ((OIDObject) n.getUserObject()).isActive());

            vjbo.add(jso);
        }

        JSONObject root = new JSONObject();
        root.put("name", ((OIDObject) node.getUserObject()).getName());
        root.put("identifier", ((OIDObject) node.getUserObject()).getIdentifier());
        root.put("hasChildren", !node.isLeaf());
        root.put("isActive", ((OIDObject) node.getUserObject()).isActive());
        root.put("children", new JSONArray(vjbo));

        writeJSONObject(root);

    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.controller.CreateConsentServiceServlet.java

/**
 * This method handles requests asking for all nodes containing the given
 * String/*from  w w  w.j  a  v  a  2  s . com*/
 * 
 */
private void requestTypeSearchTree() {

    String searchString = request.getParameter("searchstring").trim();

    if (searchString.equalsIgnoreCase("")) {

        requestTypeTreeRoot();

    } else {
        try {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) ccService.getOIDTreeNodes(searchString)
                    .getRoot();

            ConsentCreatorUtilities consentCreatorUtilities = ConsentCreatorUtilities.getInstance();

            Vector<JSONObject> vjbo = consentCreatorUtilities.traverseTreeForExpand(node);

            JSONObject root = new JSONObject();
            root.put("name", ((OIDObject) node.getUserObject()).getName());
            root.put("identifier", ((OIDObject) node.getUserObject()).getIdentifier());
            root.put("hasChildren", !node.isLeaf());
            root.put("isActive", ((OIDObject) node.getUserObject()).isActive());
            root.put("children", new JSONArray(vjbo));

            writeJSONObject(root);

        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.controller.PrivilegedCreateConsentServiceServlet.java

/**
 * This method handles requests asking for all nodes containing the given
 * String/*  ww  w .j av  a2s.  c  o  m*/
 * 
 */
private void requestTypeSearchTree() {

    String searchString = request.getParameter("searchstring").trim();

    if (searchString.equalsIgnoreCase("")) {

        requestTypeTreeRoot();

    } else {

        try {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) ccService.getOIDTreeNodes(searchString)
                    .getRoot();

            ConsentCreatorUtilities consentCreatorUtilities = ConsentCreatorUtilities.getInstance();

            Vector<JSONObject> vjbo = consentCreatorUtilities.traverseTreeForExpand(node);

            JSONObject root = new JSONObject();
            root.put("name", ((OIDObject) node.getUserObject()).getName());
            root.put("identifier", ((OIDObject) node.getUserObject()).getIdentifier());
            root.put("hasChildren", !node.isLeaf());
            root.put("isActive", ((OIDObject) node.getUserObject()).isActive());
            root.put("children", new JSONArray(vjbo));

            writeJSONObject(root);

        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorService.java

/**
 * Returns all children of the TreeNode with the given ID.
 * //ww w  .  j a  v  a  2  s  .c o m
 * @param oid
 * @return
 */
@SuppressWarnings("rawtypes")
public Vector<OIDObject> getOIDTreeNodeChildren(String oid) {

    Vector<OIDObject> children = new Vector<OIDObject>();

    DefaultMutableTreeNode soughtNode = consentCreatorUtilites.traverseTreeOID(oid, getOIDTreeRoot());

    if (soughtNode != null) {
        for (Enumeration e = soughtNode.children(); e.hasMoreElements();) {

            DefaultMutableTreeNode lon = (DefaultMutableTreeNode) e.nextElement();
            OIDObject o = new OIDObject(((OIDObject) lon.getUserObject()).getIdentifier(),
                    ((OIDObject) lon.getUserObject()).getName(), ((OIDObject) lon.getUserObject()).isActive());
            o.setHasChildren(!lon.isLeaf());
            children.add(o);
        }
    }
    return children;
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Constructs a Vector from the given Node and it's sub-Nodes
 * /*from ww w .java 2 s .com*/
 * @param node
 * @return
 */
public Vector<JSONObject> traverseTreeForExpand(DefaultMutableTreeNode node) {

    try {

        Vector<JSONObject> vjbo = new Vector<JSONObject>();

        for (Enumeration e = node.children(); e.hasMoreElements();) {

            DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
            JSONObject jso = new JSONObject();
            jso.put("name", ((OIDObject) n.getUserObject()).getName());
            jso.put("identifier", ((OIDObject) n.getUserObject()).getIdentifier());
            jso.put("hasChildren", !n.isLeaf());
            jso.put("isActive", ((OIDObject) n.getUserObject()).isActive());

            if (n.getChildCount() != 0) {
                Vector<JSONObject> retvjo = traverseTreeForExpand(n);
                jso.put("children", retvjo);
            }
            vjbo.add(jso);
        }
        return vjbo;

    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }
    return null;

}

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

private DefaultMutableTreeNode findService(DefaultMutableTreeNode node, ServiceId jumpToService) {
    if (node.isLeaf()) {
        Object userObject = node.getUserObject();
        if (jumpToService.equals(userObject)) {
            return node;
        }/* w ww. j a va 2 s .c om*/
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode result = findService((DefaultMutableTreeNode) node.getChildAt(i),
                    jumpToService);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private ArrayList<DefaultMutableTreeNode> getLocalLeafs(DefaultMutableTreeNode node, TreePath path) {
    ArrayList<DefaultMutableTreeNode> list = new ArrayList<DefaultMutableTreeNode>();
    TreePath temp;//from w  w  w.  j av a 2s. c om

    if (node.isLeaf()) {
        list.add(node);
    } else {
        Enumeration<DefaultMutableTreeNode> en = node.children();

        while (en.hasMoreElements()) {
            DefaultMutableTreeNode elem = en.nextElement();

            temp = path.pathByAddingChild(elem);
            jTreeResults.expandPath(temp);

            list.addAll(getLocalLeafs(elem, temp));
        }
    }

    return list;
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

public void updateP2PThumbnail(SearchResult result) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) getjTreeResults().getLastSelectedPathComponent();
    if (node == null) {
        return;//from w  w  w .  j a v a  2  s. c om
    }

    Object nodeInfo = null;
    DefaultMutableTreeNode nodeLeaf = null;

    if (node.getLevel() == 4 || (node.isLeaf() && node.getLevel() > 1)) {
        Object nodeInfoLeaf = null;

        if (node.getLevel() == 4) {
            nodeLeaf = node.getFirstLeaf();
            nodeInfoLeaf = nodeLeaf.getUserObject();
        } else {
            // Leaf
            nodeInfo = node.getUserObject();
            nodeLeaf = node;
            nodeInfoLeaf = nodeInfo;
        }

        //SearchResult r = (SearchResult) nodeInfoLeaf;

        if (nodeInfoLeaf == result) {
            showThumbnail(result.getExtrafields().get("Thumbnail"));
        }
    }

}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jTreeResultsValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTreeResultsValueChanged

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) getjTreeResults().getLastSelectedPathComponent();
    if (node == null) {
        return;/*from ww  w  . java 2 s. c o  m*/
    }
    this.jButtonDownload.setEnabled(false);
    Object nodeInfo = null;
    DefaultMutableTreeNode nodeLeaf = null;

    if (node.getLevel() == 4 || (node.isLeaf() && node.getLevel() > 1)) {
        Object nodeInfoLeaf = null;

        if (node.getLevel() == 4) {
            nodeLeaf = node.getFirstLeaf();
            nodeInfoLeaf = nodeLeaf.getUserObject();
        } else {
            // Leaf
            nodeInfo = node.getUserObject();
            nodeLeaf = node;
            nodeInfoLeaf = nodeInfo;
        }

        SearchResult r = (SearchResult) nodeInfoLeaf;

        Hashtable extras = r.getExtrafields();
        String thumb = (String) extras.get("Thumbnail");

        //System.out.println("Filename: " + r.getFileName());
        //System.out.println("FileHash: " + r.getFileHash());

        if (thumb != null) {
            showThumbnail(thumb);
        } else if (!SearchResult.class.isInstance(nodeInfoLeaf)
                && SearchResult.class.isInstance(nodeInfoLeaf)) {
            SearchResult res = searchTree.searchThumbnail(r.getFileName(), r.getFileHash());

            if (res != null) {
                Hashtable extras2 = res.getExtrafields();

                if (extras2 != null) {
                    thumb = (String) extras2.get("Thumbnail");

                    if (thumb != null) {
                        extras.put("Thumbnail", thumb); // put the thumbnail in the original SearchResult

                        showThumbnail(thumb);
                    } else {
                        cleanThumbnails();
                    }
                }
            }
        } else if (SearchResult.class.isInstance(nodeInfoLeaf)) {
            searchTree.searchP2PThumbnail((SearchResult) r);
            cleanThumbnails();
        } else {
            cleanThumbnails();
        }

    } else {
        cleanThumbnails();
    }

    //Controll the enable buttons
    if (node.isLeaf()) {
        jButtonDump.setEnabled(true);
        IPluginControllerUser plugins = null;
        try {
            plugins = this.clientCore.getUser().getPluginController();

            if ((SearchResult) nodeInfo == null) {

            }

            if (!plugins.isLocalPlugin(((SearchResult) nodeInfo).getPluginName())) {
                jButtonDownload.setEnabled(true);
                jButtonSend.setEnabled(false);
            } else {
                jButtonSend.setEnabled(true);
                jButtonView.setEnabled(true);
            }
        } catch (RemoteException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        jButtonDump.setEnabled(false);
        jButtonDownload.setEnabled(false);
        jButtonView.setEnabled(false);

        jButtonSend.setEnabled(true);
    }
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

private void jButtonViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonViewActionPerformed
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeResults.getLastSelectedPathComponent();
    if (node == null) {
        return;/*from   ww w.  j av a  2  s.co  m*/
    }

    Object nodeInfo = node.getUserObject();
    // int selected = this.jList1.getSelectedIndex();
    if (node.isLeaf()) {
        if (SearchResult.class.isInstance(nodeInfo)) {
            SearchResult tmp = (SearchResult) nodeInfo;

            if (clientCore.isLocalServer()) {
                String path = tmp.getOrigin();

                File f = new File(path);
                if (!f.exists()) {
                    JOptionPane.showMessageDialog(this,
                            "Dicoogle can't open this file, because this file does not exists in your file system. Try Dump button instead View!",
                            "Error opening the file", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                if (ClientSettings.getInstance().getExtV() == null
                        || ClientSettings.getInstance().getExtV().equals("")) {

                    try {
                        Desktop.getDesktop().open(new File(path));

                    } catch (IOException ex) {
                        String folder = path.substring(0, path.lastIndexOf('/'));

                        try {
                            Desktop.getDesktop().open(new File(folder));

                        } catch (IOException ex1) {
                            JOptionPane.showMessageDialog(this, "Dicoogle can't open this file!",
                                    "Error opening the file", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } else {
                    try {
                        ProcessBuilder pb = new ProcessBuilder(ClientSettings.getInstance().getExtV(), path);
                        pb.start();

                        //Runtime.getRuntime().exec(ClientSettings.getInstance().getExtV() + " "+path);
                    } catch (IOException ex) {
                        //ex.printStackTrace();

                        String folder = path.substring(0, path.lastIndexOf('/'));

                        try {
                            Desktop.getDesktop().open(new File(folder));

                        } catch (IOException ex1) {
                            JOptionPane.showMessageDialog(this, "Dicoogle can't open this file!",
                                    "Error opening the file", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            } else {
                try {
                    SimpleEntry<RemoteFile, Integer> entry = UserRefs.getInstance().getSearch()
                            .downloadFile(tmp);

                    TransferStatus ts = new TransferStatus(entry.getKey());

                    FileReceiver receiver = new FileReceiver(entry.getKey(), clientCore.getServerAddress(),
                            entry.getValue(), ts);

                    Thread tReceiver = receiver;
                    tReceiver.start();

                    ts.setVisible(true);
                    ts.toFront();

                } catch (RemoteException ex) {
                    Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}