Search in sources :

Example 21 with Treeitem

use of org.zkoss.zul.Treeitem 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 22 with Treeitem

use of org.zkoss.zul.Treeitem 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

Treeitem (org.zkoss.zul.Treeitem)22 DefaultTreeNode (org.zkoss.zul.DefaultTreeNode)8 MTreeNode (org.compiere.model.MTreeNode)7 Treechildren (org.zkoss.zul.Treechildren)7 DeleteEntitiesModel (org.adempiere.util.DeleteEntitiesModel)5 DropEvent (org.zkoss.zk.ui.event.DropEvent)5 Treerow (org.zkoss.zul.Treerow)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SimpleTreeModel (org.adempiere.webui.component.SimpleTreeModel)3 Component (org.zkoss.zk.ui.Component)3 SQLException (java.sql.SQLException)2 Collection (java.util.Collection)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 SimpleListModel (org.adempiere.webui.component.SimpleListModel)2 Event (org.zkoss.zk.ui.event.Event)2 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 HashSet (java.util.HashSet)1