Example usage for javax.swing.tree TreePath getLastPathComponent

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

Introduction

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

Prototype

public Object getLastPathComponent() 

Source Link

Document

Returns the last element of this path.

Usage

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

private void treeEntitiesMouseReleased(java.awt.event.MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        TreePath path = treeEntities.getClosestPathForLocation(evt.getX(), evt.getY());
        if (path != null) {
            treeEntities.setSelectionPath(path);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            JPopupMenu menu = depositPresenter.getEntityMenu(node);
            if (menu != null) {
                menu.show(evt.getComponent(), evt.getX(), evt.getY());
            }/*w w  w  . j a  v a  2  s.  c o m*/
        }
    }
}

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

private void treeFileSystemMouseReleased(java.awt.event.MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        TreePath path = treeFileSystem.getClosestPathForLocation(evt.getX(), evt.getY());
        if (path != null) {
            treeFileSystem.setSelectionPath(path);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            JPopupMenu menu = depositPresenter.getFileSystemMenu(node);
            if (menu != null) {
                menu.show(evt.getComponent(), evt.getX(), evt.getY());
            }//from  www . java 2s  . com
        }
    }
}

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

private void treeFileSystemMousePressed(java.awt.event.MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        TreePath path = treeFileSystem.getClosestPathForLocation(evt.getX(), evt.getY());
        if (path != null) {
            treeFileSystem.setSelectionPath(path);
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            JPopupMenu menu = depositPresenter.getFileSystemMenu(node);
            if (menu != null) {
                menu.show(evt.getComponent(), evt.getX(), evt.getY());
            }//from   www  .  j  a v  a2 s  .c  o  m
        }
    } else {
        setDragSourceFileSystem();
    }

}

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

public void expandFileSystemTree(TreePath currentPath) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) currentPath.getLastPathComponent();
    FileSystemObject fso = (FileSystemObject) node.getUserObject();
    if ((fso.getChildren() != null) && (fso.getChildren().size() == 1)
            && (fso.getChildren().get(0).getIsPlaceholder())) {
        //         LOG.debug("Before load children");
        fso.loadChildren(false);/*from  w ww . j  a  va  2 s  .co m*/
        //         LOG.debug("After load children");
        DepositTreeModel model = (DepositTreeModel) theFileSystemTree.getModel();
        //         LOG.debug("Before remove children");
        node.removeAllChildren();
        //         LOG.debug("Before reload node");
        model.reload(node);
        //         LOG.debug("Before add children");
        addChildFiles(node, fso.getChildren(), model, null, null);
        //         LOG.debug("Before expand path");
        theFileSystemTree.expandPath(currentPath);
    }

}

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

public boolean canOpenFiles(TreePath[] paths) {
    boolean retVal = true;
    if (paths == null) {
        retVal = false;/*from  w  w w  . j a  v a2s .  com*/
    } else {
        for (TreePath path : paths) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            if (node.getUserObject() instanceof FileSystemObject) {
                FileSystemObject fso = (FileSystemObject) node.getUserObject();
                if (!fso.getIsFile()) {
                    retVal = false;
                    break;
                }
            } else {
                retVal = false;
                break;
            }
        }
    }
    return retVal;
}

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

private void treeValueChanged(javax.swing.event.TreeSelectionEvent evt) {
    JTree sourceTree = (JTree) evt.getSource();
    TreePath[] paths = sourceTree.getSelectionPaths();
    if (paths != null) {
        theNodeInClipboard.clear();//from   w ww .  j av  a 2  s  . com
        for (TreePath path : paths) {
            theNodeInClipboard.add((DefaultMutableTreeNode) path.getLastPathComponent());
        }
    }

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) evt.getPath().getLastPathComponent();
    JTree tree = (JTree) evt.getSource();
    if (getTreeType(tree).equals(ETreeType.FileSystemTree)) {
        if (node.getUserObject() instanceof FileSystemObject) {
            tree.setEditable(false);
        }
    }
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
    while (parent != null && parent.getUserObject() instanceof FileSystemObject) {
        node = parent;
        parent = (DefaultMutableTreeNode) node.getParent();
    }
    tree.setEditable(true);
    if ((parent != null) && (parent.getUserObject() instanceof StructMap)) {
        if (node.getUserObject() instanceof FileSystemObject) {
            tree.setEditable(false);
        }
    }
}

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

private TreePath[] loadEntity(String entityPath) {
    DepositTreeModel model = (DepositTreeModel) theFrame.treeFileSystem.getModel();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot();
    File theFile = new File(entityPath);
    LOG.debug("testProcessFileTreeKeyPress, root full path " + theFile.getAbsolutePath());
    try {//  w w w. j  ava  2 s. c om
        LOG.debug("testProcessFileTreeKeyPress, root canonical path " + theFile.getCanonicalPath());
        theFrame.storeCurrentPath(theFile.getCanonicalPath());
    } catch (Exception ex) {
        fail();
    }
    FileSystemObject fso = (FileSystemObject) rootNode.getUserObject();
    fso.ensureChildPathLoaded(theFrame.getCurrentPath());
    FSOCollection coll = FSOCollection.create();
    coll.add(fso);
    FileSystemObject child = coll.getFSOByFullPath(theFrame.getCurrentPath(), true);
    depositPresenter.addFileSystemRoot(fso, false, false, theFrame.getCurrentPath());
    depositPresenter.selectNode(child, ETreeType.FileSystemTree);
    TreePath currentTreePath = theFrame.treeFileSystem.getSelectionPath();
    DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) currentTreePath.getLastPathComponent();
    assertTrue(currentNode.getUserObject() instanceof FileSystemObject);
    fso = (FileSystemObject) currentNode.getUserObject();
    assertFalse(fso.getIsPlaceholder());
    assertTrue(fso.getFullPath().equals(theFrame.getCurrentPath()));
    return theFrame.treeFileSystem.getSelectionPaths();
}

From source file:op.care.med.structure.PnlMed.java

private void treeMedMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treeMedMousePressed
    if (product == null)
        return;/*from ww  w  . j ava  2 s .c o  m*/
    if (!OPDE.getAppInfo().isAllowedTo(InternalClassACL.MANAGER, internalClassID))
        return;

    if (SwingUtilities.isRightMouseButton(evt)) {
        // Dieses Popupmenu fr den Table
        SYSTools.unregisterListeners(menu);
        menu = new JPopupMenu();
        //            JMenuItem itemdaf = new JMenuItem("Neue Darreichungsform");
        //            itemdaf.addActionListener(new java.awt.event.ActionListener() {
        //                public void actionPerformed(java.awt.event.ActionEvent evt) {
        //                    btnNeuDAF(evt);
        //                }
        //            });
        //            menu.add(itemdaf);

        if (treeMed.getRowForLocation(evt.getX(), evt.getY()) != -1
                && OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {
            JMenuItem itemedit = null;
            JMenuItem itemUPRedit = null;
            //                JMenuItem itemnew = null;
            //                JMenuItem itempack = null;
            TreePath curPath = treeMed.getPathForLocation(evt.getX(), evt.getY());
            final DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) curPath.getLastPathComponent();
            treeMed.setSelectionPath(curPath);
            //                final ListElement le = (ListElement) dmtn.getUserObject();
            //                int nodetype = ((Integer) le.getObject()).intValue();

            if (dmtn.getUserObject() instanceof TradeForm) {
                final TradeForm tradeForm = (TradeForm) dmtn.getUserObject();
                itemedit = new JMenuItem(SYSTools.xx("misc.msg.edit"));
                itemedit.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        new DlgTradeForm(tradeForm);
                        createTree();
                    }
                });
                itemUPRedit = new JMenuItem(SYSTools.xx("upreditor.tooltip"));
                itemUPRedit.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        new DlgUPREditor(tradeForm, new Closure() {
                            @Override
                            public void execute(Object o) {
                                reload();
                            }
                        });
                    }
                });
                itemUPRedit.setEnabled(tradeForm.getDosageForm().isUPRn());
                //                    itempack = new JMenuItem("Neue Verpackung");
                //                    itempack.addActionListener(new java.awt.event.ActionListener() {
                //                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                //                            MedPackage mypack = new MedPackage(tradeForm);
                //                            new DlgPack(OPDE.getMainframe(), "Neu", mypack);
                ////                            OPDE.getEMF().getCache().evict(Darreichung.class, darreichung.getID());
                //                            createTree();
                //                        }
                //                    });
            } else if (dmtn.getUserObject() instanceof MedPackage) {
                final MedPackage packung = (MedPackage) dmtn.getUserObject();
                itemedit = new JMenuItem("Bearbeiten");
                itemedit.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        new DlgPack(SYSTools.xx("misc.msg.edit"), packung);
                        createTree();
                    }
                });
            } else if (dmtn.getUserObject() instanceof MedProducts) {

                itemedit = new JMenuItem("Bearbeiten");
                itemedit.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        DlgProduct dlg = new DlgProduct(SYSTools.xx("misc.msg.edit"),
                                (MedProducts) dmtn.getUserObject());
                        product = dlg.getProduct();
                        createTree();
                    }
                });
            }

            if (itemedit != null)
                menu.add(itemedit);
            if (itemUPRedit != null)
                menu.add(itemUPRedit);
        }
        menu.show(evt.getComponent(), evt.getX(), evt.getY());
    }
}

From source file:op.controlling.PnlQMSSchedule.java

public void save() throws NumberFormatException {

    qmssched.setDaily(//  w w w .java 2s  .c o m
            tabWdh.getSelectedIndex() == TAB_DAILY ? Byte.parseByte(spinTaeglich.getValue().toString()) : 0);
    qmssched.setWeekly(
            tabWdh.getSelectedIndex() == TAB_WEEKLY ? Byte.parseByte(spinWoche.getValue().toString()) : 0);
    qmssched.setMonthly(
            tabWdh.getSelectedIndex() == TAB_MONTHLY ? Byte.parseByte(spinMonat.getValue().toString()) : 0);
    qmssched.setYearly(
            tabWdh.getSelectedIndex() == TAB_YEARLY ? Byte.parseByte(spinYearly.getValue().toString()) : 0);
    qmssched.setStartingOn(jdcStartingOn.getDate());

    if (tabWdh.getSelectedIndex() == TAB_DAILY) {
        qmssched.setWeekday(0);
    }

    if (tabWdh.getSelectedIndex() == TAB_MONTHLY) {
        qmssched.setDayinmonth(Integer.parseInt(spinDayInMonth.getValue().toString()));
        qmssched.setWeekday(cmbTag.getSelectedIndex());
    }

    if (tabWdh.getSelectedIndex() == TAB_YEARLY) {
        qmssched.setDayinmonth(Integer.parseInt(spinDayInMonthInYear.getValue().toString()));
        qmssched.setMonthinyear(cmbMonth.getSelectedIndex() + 1);
    }

    qmssched.setMeasure(SYSTools.tidy(txtQMS.getText()));
    qmssched.setText(SYSTools.tidy(txtBemerkung.getText()));

    qmssched.setDuedays(Integer.parseInt(txtDueDays.getText()));

    if (cmbLocation.getSelectedItem() == null) {
        qmssched.setHome(null);
        qmssched.setStation(null);
    } else if (cmbLocation.getSelectedItem() instanceof TreePath) {
        TreePath treePath = (TreePath) cmbLocation.getSelectedItem();
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
        if (node.getUserObject() instanceof Station) {
            qmssched.setStation((Station) node.getUserObject());
            qmssched.setHome(null);
        } else if (node.getUserObject() instanceof Homes) {
            qmssched.setHome((Homes) node.getUserObject());
            qmssched.setStation(null);
        } else {
            qmssched.setHome(null);
            qmssched.setStation(null);
        }
    } else {
        qmssched.setHome(null);
        qmssched.setStation(null);
    }

    qmssched.getQmsList().clear();
    QmsTools.generate(qmssched, 2);

}

From source file:org.apache.cayenne.modeler.ProjectTreeView.java

/**
 * Removes current node from the tree. Selects a new node adjacent to the currently
 * selected node instead./*w ww .  ja  va2  s  . c  o m*/
 */
protected void removeNode(DefaultMutableTreeNode toBeRemoved) {

    // lookup for the new selected node
    Object selectedNode = null;

    TreePath selectionPath = getSelectionPath();
    if (selectionPath != null) {
        selectedNode = selectionPath.getLastPathComponent();
    }

    if (toBeRemoved == selectedNode) {

        // first search siblings
        DefaultMutableTreeNode newSelection = toBeRemoved.getNextSibling();
        if (newSelection == null) {
            newSelection = toBeRemoved.getPreviousSibling();

            // try parent
            if (newSelection == null) {
                newSelection = (DefaultMutableTreeNode) toBeRemoved.getParent();

                // search the whole tree
                if (newSelection == null) {

                    newSelection = toBeRemoved.getNextNode();
                    if (newSelection == null) {

                        newSelection = toBeRemoved.getPreviousNode();
                    }
                }
            }
        }

        showNode(newSelection);
    }

    // remove this node
    getProjectModel().removeNodeFromParent(toBeRemoved);
}