Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

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

Introduction

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

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

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;/* w  ww  .j  a  va2 s.  c om*/
    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

private void initPanel() {

    i18n();//from  ww  w.ja v a2  s  .co m

    txtDueDays.setText(Integer.toString(qmssched.getDuedays()));

    spinTaeglich.setModel(new SpinnerNumberModel(1, 1, 365, 1));
    spinWoche.setModel(new SpinnerNumberModel(1, 1, 52, 1));
    spinMonat.setModel(new SpinnerNumberModel(1, 1, 12, 1));
    spinYearly.setModel(new SpinnerNumberModel(1, 1, 10, 1));
    spinDayInMonth.setModel(new SpinnerNumberModel(1, 1, 31, 1));

    spinTaeglich.setValue(Math.max(qmssched.getDaily(), 1));
    spinWoche.setValue(Math.max(qmssched.getWeekly(), 1));
    spinMonat.setValue(Math.max(qmssched.getMonthly(), 1));
    spinDayInMonth.setValue(Math.max(qmssched.getDayinmonth(), 1));
    spinYearly.setValue(Math.max(qmssched.getYearly(), 1));

    cbMon.setSelected(true);

    cmbMonth.setSelectedIndex(qmssched.isYearly() ? qmssched.getMonthinyear() - 1 : 0);
    spinDayInMonthInYear.setModel(new SpinnerNumberModel(qmssched.isYearly() ? qmssched.getDayinmonth() : 1, 1,
            maxdays[cmbMonth.getSelectedIndex()], 1));
    cmbMonth.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                spinDayInMonthInYear
                        .setModel(new SpinnerNumberModel(1, 1, maxdays[cmbMonth.getSelectedIndex()], 1));
            }
        }
    });

    if (qmssched.isDaily()) {
        tabWdh.setSelectedIndex(TAB_DAILY);
    } else if (qmssched.isWeekly()) {
        cbMon.setSelected(qmssched.getWeekday() == DateTimeConstants.MONDAY);
        cbDie.setSelected(qmssched.getWeekday() == DateTimeConstants.TUESDAY);
        cbMit.setSelected(qmssched.getWeekday() == DateTimeConstants.WEDNESDAY);
        cbDon.setSelected(qmssched.getWeekday() == DateTimeConstants.THURSDAY);
        cbFre.setSelected(qmssched.getWeekday() == DateTimeConstants.FRIDAY);
        cbSam.setSelected(qmssched.getWeekday() == DateTimeConstants.SATURDAY);
        cbSon.setSelected(qmssched.getWeekday() == DateTimeConstants.SUNDAY);

        tabWdh.setSelectedIndex(TAB_WEEKLY);
    } else if (qmssched.isMonthly()) {

        spinDayInMonth.setValue(qmssched.getDayinmonth());
        cmbTag.setSelectedIndex(qmssched.getWeekday());

        tabWdh.setSelectedIndex(TAB_MONTHLY);
    } else if (qmssched.isYearly()) {
        spinYearly.setValue(qmssched.getYearly());
        spinDayInMonthInYear.setValue(qmssched.getDayinmonth());
        cmbMonth.setSelectedIndex(qmssched.getMonthinyear() - 1);
        tabWdh.setSelectedIndex(TAB_YEARLY);
    }

    jdcStartingOn.setMinSelectableDate(new Date());
    jdcStartingOn.setDate(qmssched.getStartingOn());

    ArrayList<Date> timelist = SYSCalendar.getTimeList();
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel(timelist.toArray());
    dcbm.insertElementAt(null, 0);

    txtBemerkung.setText(qmssched.getText());
    txtQMS.setText(qmssched.getMeasure());

    cmbLocation.setTreeModel(new DefaultTreeModel(StationTools.getCompleteStructure()));

    Object userObject = null;
    if (qmssched.getHome() != null) {
        userObject = qmssched.getHome();
    } else if (qmssched.getStation() != null) {
        userObject = qmssched.getStation();
    }

    int row = 0;
    if (userObject == null) {
        cmbLocation.setSelectedItem(null);
    } else {
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) cmbLocation.getTreeModel().getRoot();
        DefaultMutableTreeNode theNode = null;
        for (Enumeration e = root.depthFirstEnumeration(); e.hasMoreElements() && theNode == null;) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
            if (userObject.equals(node.getUserObject())) {
                cmbLocation.setSelectedItem(node);
                break;
            }
            row++;
        }
    }
}

From source file:op.controlling.PnlQMSSchedule.java

public void save() throws NumberFormatException {

    qmssched.setDaily(/*www.jav a 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.alfresco.repo.jive.impl.MockJiveService.java

private final List<JiveCommunity> getSubCommunities(final TreeNode parent) {
    List<JiveCommunity> result = new ArrayList<JiveCommunity>();

    if (parent != null) {
        int childCount = mockCommunities.getChildCount(parent);

        if (childCount > 0) {
            for (int i = 0; i < childCount; i++) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) mockCommunities.getChild(parent, i);

                if (node != null) {
                    JiveCommunity subCommunity = (JiveCommunity) node.getUserObject();

                    if (subCommunity != null) {
                        result.add(subCommunity);
                    }/*from w  w  w .  j a v  a  2s.co  m*/
                }
            }
        }
    }

    return (result);
}

From source file:org.alfresco.repo.jive.impl.MockJiveService.java

private final static TreeNode findNodeById(final TreeModel tree, final DefaultMutableTreeNode node,
        final long communityId) {
    TreeNode result = null;/*from ww w .  ja v  a2 s. c o  m*/

    if (node != null) {
        JiveCommunity community = (JiveCommunity) node.getUserObject();

        if (community != null && community.getId() == communityId) {
            result = node;
        } else {
            int childCount = tree.getChildCount(node);

            if (childCount > 0) {
                for (int i = 0; i < childCount; i++) {
                    // Recursion
                    result = findNodeById(tree, (DefaultMutableTreeNode) tree.getChild(node, i), communityId);

                    // Termination condition
                    if (result != null) {
                        break;
                    }
                }
            }
        }
    }

    return (result);
}

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

public void dataNodeChanged(DataNodeEvent e) {

    DefaultMutableTreeNode node = getProjectModel().getNodeForObjectPath(new Object[] {
            e.getDomain() != null ? e.getDomain() : (DataChannelDescriptor) mediator.getProject().getRootNode(),
            e.getDataNode() });/*from  w  w w  .  j a  va  2  s  .c  o m*/

    if (node != null) {

        if (e.isNameChange()) {
            positionNode((DefaultMutableTreeNode) node.getParent(), node,
                    Comparators.getDataDomainChildrenComparator());
            showNode(node);
        } else {

            getProjectModel().nodeChanged(node);

            DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();

            // check for DataMap additions/removals...
            Object[] mapsName = e.getDataNode().getDataMapNames().toArray();
            int mapCount = mapsName.length;

            // DataMap was linked
            if (mapCount > node.getChildCount()) {

                for (int i = 0; i < mapCount; i++) {
                    boolean found = false;
                    for (int j = 0; j < node.getChildCount(); j++) {
                        DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(j);
                        if (domain.getDataMap(mapsName[i].toString()) == child.getUserObject()) {
                            found = true;
                            break;
                        }
                    }

                    if (!found) {
                        DefaultMutableTreeNode newMapNode = new DefaultMutableTreeNode(
                                domain.getDataMap(mapsName[i].toString()), false);
                        positionNode(node, newMapNode, Comparators.getNamedObjectComparator());
                        break;
                    }
                }
            }
            // DataMap was unlinked
            else if (mapCount < node.getChildCount()) {
                int j = 0;
                while (j < node.getChildCount()) {
                    boolean found = false;
                    DefaultMutableTreeNode child;
                    child = (DefaultMutableTreeNode) node.getChildAt(j);
                    Object obj = child.getUserObject();
                    for (int i = 0; i < mapCount; i++) {
                        if (domain.getDataMap(mapsName[i].toString()) == obj) {
                            found = true;
                            j++;
                        }
                    }
                    if (!found) {
                        removeNode(child);
                    }
                }
            }
        }
    }
}

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

/**
 * Returns array of the user objects ending with this and starting with one under
 * root. That is the array of actual objects rather than wrappers.
 *///from w w w.ja  v a2  s  . co  m
private Object[] getUserObjects(DefaultMutableTreeNode node) {
    List list = new ArrayList();
    while (!node.isRoot()) {
        list.add(0, node.getUserObject());
        node = (DefaultMutableTreeNode) node.getParent();
    }
    return list.toArray();
}

From source file:org.apache.directory.fortress.web.panel.GroupListPanel.java

private void removeSelectedItems(TreeGrid<DefaultTreeModel, DefaultMutableTreeNode, String> grid) {
    Collection<IModel<DefaultMutableTreeNode>> selected = grid.getSelectedItems();
    for (IModel<DefaultMutableTreeNode> model : selected) {
        DefaultMutableTreeNode node = model.getObject();
        treeModel.removeNodeFromParent(node);
        Group group = (Group) node.getUserObject();
        log.debug(".removeSelectedItems user node: " + group.getName());
        //List<Group> groups = ((List<Group>) getDefaultModel().getObject());
        //groups.remove(group.getName());
    }/*from  ww w .  ja  va  2 s . c om*/
}

From source file:org.apache.directory.fortress.web.panel.ObjectListPanel.java

private void removeSelectedItems(TreeGrid<DefaultTreeModel, DefaultMutableTreeNode, String> grid) {
    Collection<IModel<DefaultMutableTreeNode>> selected = grid.getSelectedItems();
    for (IModel<DefaultMutableTreeNode> model : selected) {
        DefaultMutableTreeNode node = model.getObject();
        treeModel.removeNodeFromParent(node);
        PermObj permObj = (PermObj) node.getUserObject();
        log.debug(".removeSelectedItems user node: " + permObj.getObjName());
        List<PermObj> permObjs = ((List<PermObj>) getDefaultModel().getObject());
        permObjs.remove(permObj);/*www.  java 2  s.c om*/
    }
}

From source file:org.apache.directory.fortress.web.panel.OUListPanel.java

private void removeSelectedItems(TreeGrid<DefaultTreeModel, DefaultMutableTreeNode, String> grid) {
    Collection<IModel<DefaultMutableTreeNode>> selected = grid.getSelectedItems();
    for (IModel<DefaultMutableTreeNode> model : selected) {
        DefaultMutableTreeNode node = model.getObject();
        treeModel.removeNodeFromParent(node);
        OrgUnit orgUnit = (OrgUnit) node.getUserObject();
        log.debug(".removeSelectedItems ou node: " + orgUnit.getName());
        List<OrgUnit> orgUnits = ((List<OrgUnit>) getDefaultModel().getObject());
        orgUnits.remove(orgUnit);//from  w w  w .j  av  a 2  s  .  c  o  m
    }
}