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;
}
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);
}
Aggregations