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