Search in sources :

Example 11 with DefaultTreeNode

use of org.zkoss.zul.DefaultTreeNode in project adempiere by adempiere.

the class SimpleTreeModel method createFrom.

//	End Yamel Senih
/**
	 * 
	 * @param root
	 * @return SimpleTreeModel
	 */
public static SimpleTreeModel createFrom(MTreeNode root) {
    SimpleTreeModel model = null;
    Enumeration<?> nodeEnum = root.children();
    DefaultTreeNode<Object> stRoot = new DefaultTreeNode<Object>(root, nodeEnum.hasMoreElements() ? new ArrayList<TreeNode<Object>>() : null);
    while (nodeEnum.hasMoreElements()) {
        MTreeNode childNode = (MTreeNode) nodeEnum.nextElement();
        DefaultTreeNode<Object> stNode = childNode.getChildCount() > 0 ? new DefaultTreeNode<Object>(childNode, new ArrayList<TreeNode<Object>>()) : new DefaultTreeNode<Object>(childNode);
        stRoot.getChildren().add(stNode);
        if (childNode.getChildCount() > 0) {
            populate(stNode, childNode);
        }
    }
    model = new SimpleTreeModel(stRoot);
    return model;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ArrayList(java.util.ArrayList)

Example 12 with DefaultTreeNode

use of org.zkoss.zul.DefaultTreeNode in project adempiere by adempiere.

the class SimpleTreeModel method find.

/**
	 * @param fromNode
	 * @param recordId
	 * @return DefaultTreeNode
	 */
public DefaultTreeNode<Object> find(DefaultTreeNode<Object> fromNode, int recordId) {
    if (fromNode == null)
        fromNode = getRoot();
    MTreeNode data = (MTreeNode) fromNode.getData();
    if (data.getNode_ID() == recordId)
        return fromNode;
    // This will have no children causing a NPE error in isLeaf().
    try {
        if (isLeaf(fromNode))
            return null;
    } catch (NullPointerException e) {
        logger.severe("Uninitialized node exists in tree. Node ID: " + data.getNode_ID());
        return null;
    }
    int cnt = getChildCount(fromNode);
    for (int i = 0; i < cnt; i++) {
        DefaultTreeNode<Object> child = (DefaultTreeNode<Object>) getChild(fromNode, i);
        DefaultTreeNode<Object> treeNode = find(child, recordId);
        if (treeNode != null)
            return treeNode;
    }
    return null;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode)

Example 13 with DefaultTreeNode

use of org.zkoss.zul.DefaultTreeNode in project adempiere by adempiere.

the class WTreeMaintenance method action_treeAdd.

//	propertyChange
/**
	 * 	Action: Add Node to Tree
	 * 	@param item item
	 */
private void action_treeAdd(ListItem item) {
    log.info("Item=" + item);
    if (item != null) {
        SimpleTreeModel model = (SimpleTreeModel) (TreeModel<?>) centerTree.getModel();
        DefaultTreeNode stn = model.find(model.getRoot(), item.id);
        if (stn != null) {
            MTreeNode tNode = (MTreeNode) stn.getData();
            tNode.setName(item.name);
            tNode.setAllowsChildren(item.isSummary);
            tNode.setImageIndicator(item.imageIndicator);
            model.nodeUpdated(stn);
            Treeitem ti = centerTree.renderItemByPath(model.getPath(stn));
            ti.setTooltiptext(item.description);
        } else {
            stn = new DefaultTreeNode(new MTreeNode(item.id, 0, item.name, item.description, 0, item.isSummary, item.imageIndicator, false, null), new ArrayList<Object>());
            model.addNode(stn);
        }
        //	May cause Error if in tree
        addNode(item);
    }
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Treeitem(org.zkoss.zul.Treeitem) SimpleTreeModel(org.adempiere.webui.component.SimpleTreeModel) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ArrayList(java.util.ArrayList)

Example 14 with DefaultTreeNode

use of org.zkoss.zul.DefaultTreeNode in project adempiere by adempiere.

the class ADTreeOnDropListener method moveNode.

//	moveNode
private void moveNode(DefaultTreeNode movingNode, DefaultTreeNode toNode, boolean moveInto) {
    DefaultTreeNode newParent;
    int index;
    //  remove
    DefaultTreeNode oldParent = treeModel.getParent(movingNode);
    treeModel.removeNode(movingNode);
    //get new index
    if (!moveInto) {
        newParent = treeModel.getParent(toNode);
        //	the next node
        index = newParent.getChildren().indexOf(toNode) + 1;
    } else //	drop on a summary node
    {
        newParent = toNode;
        //	the first node
        index = 0;
    }
    //  insert
    treeModel.addNode(newParent, movingNode, index);
    int[] path = treeModel.getPath(movingNode);
    Treeitem movingItem = tree.renderItemByPath(path);
    tree.setSelectedItem(movingItem);
    Events.sendEvent(tree, new Event(Events.ON_SELECT, tree));
    //	***	Save changes to disk
    Trx trx = Trx.get(Trx.createTrxName("ADTree"), true);
    try {
        int no = 0;
        MTreeNode oldMParent = (MTreeNode) oldParent.getData();
        for (int i = 0; i < oldParent.getChildCount(); i++) {
            DefaultTreeNode nd = (DefaultTreeNode) oldParent.getChildAt(i);
            MTreeNode md = (MTreeNode) nd.getData();
            StringBuffer sql = new StringBuffer("UPDATE ");
            sql.append(mTree.getNodeTableName()).append(" SET Parent_ID=").append(oldMParent.getNode_ID()).append(", SeqNo=").append(i).append(", Updated=SysDate").append(" WHERE AD_Tree_ID=").append(mTree.getAD_Tree_ID()).append(" AND Node_ID=").append(md.getNode_ID());
            log.fine(sql.toString());
            no = DB.executeUpdate(sql.toString(), trx.getTrxName());
        }
        if (oldParent != newParent) {
            MTreeNode newMParent = (MTreeNode) newParent.getData();
            for (int i = 0; i < newParent.getChildCount(); i++) {
                DefaultTreeNode nd = (DefaultTreeNode) newParent.getChildAt(i);
                MTreeNode md = (MTreeNode) nd.getData();
                StringBuffer sql = new StringBuffer("UPDATE ");
                sql.append(mTree.getNodeTableName()).append(" SET Parent_ID=").append(newMParent.getNode_ID()).append(", SeqNo=").append(i).append(", Updated=SysDate").append(" WHERE AD_Tree_ID=").append(mTree.getAD_Tree_ID()).append(" AND Node_ID=").append(md.getNode_ID());
                log.fine(sql.toString());
                no = DB.executeUpdate(sql.toString(), trx.getTrxName());
            }
        }
        //	COMMIT          *********************
        trx.commit(true);
    } catch (Exception e) {
        trx.rollback();
        FDialog.error(windowNo, tree, "TreeUpdateError", e.getLocalizedMessage());
    }
    trx.close();
    trx = null;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Treeitem(org.zkoss.zul.Treeitem) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) Event(org.zkoss.zk.ui.event.Event) DropEvent(org.zkoss.zk.ui.event.DropEvent) Trx(org.compiere.util.Trx)

Example 15 with DefaultTreeNode

use of org.zkoss.zul.DefaultTreeNode in project adempiere by adempiere.

the class WTreeMaintenance method onTreeSelection.

//	valueChanged
/**
	 * 	Tree selection
	 *	@param e event
	 */
private void onTreeSelection(Event e) {
    Treeitem ti = centerTree.getSelectedItem();
    DefaultTreeNode stn = (DefaultTreeNode) ti.getValue();
    MTreeNode tn = (MTreeNode) stn.getData();
    log.info(tn.toString());
    if (tn == null)
        return;
    ListModel model = centerList.getModel();
    int size = model.getSize();
    int index = -1;
    for (index = 0; index < size; index++) {
        ListItem item = (ListItem) model.getElementAt(index);
        if (item.id == tn.getNode_ID())
            break;
    }
    centerList.setSelectedIndex(index);
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Treeitem(org.zkoss.zul.Treeitem) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ListModel(org.zkoss.zul.ListModel) SimpleListModel(org.adempiere.webui.component.SimpleListModel)

Aggregations

DefaultTreeNode (org.zkoss.zul.DefaultTreeNode)15 MTreeNode (org.compiere.model.MTreeNode)8 Treeitem (org.zkoss.zul.Treeitem)8 ArrayList (java.util.ArrayList)6 SimpleTreeModel (org.adempiere.webui.component.SimpleTreeModel)6 MProduct (org.compiere.model.MProduct)3 Vector (java.util.Vector)2 SimpleListModel (org.adempiere.webui.component.SimpleListModel)2 KeyNamePair (org.compiere.util.KeyNamePair)2 MPPProductBOM (org.eevolution.model.MPPProductBOM)2 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)2 DropEvent (org.zkoss.zk.ui.event.DropEvent)2 Event (org.zkoss.zk.ui.event.Event)2 Treecol (org.zkoss.zul.Treecol)2 Treecols (org.zkoss.zul.Treecols)2 BigDecimal (java.math.BigDecimal)1 DocumentSearch (org.adempiere.webui.util.DocumentSearch)1 TreeItemAction (org.adempiere.webui.util.TreeItemAction)1 TreeNodeAction (org.adempiere.webui.util.TreeNodeAction)1 Trx (org.compiere.util.Trx)1