use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class AdempiereTreeModel method saveChangedNodes.
public void saveChangedNodes(MTreeNode from, MTreeNode to) {
int AD_Tree_ID = m_MTree.getAD_Tree_ID();
Trx trx = Trx.get(Trx.createTrxName("AdempiereTreeModel"), true);
try {
for (int i = 0; i < from.getChildCount(); i++) {
MTreeNode nd = (MTreeNode) from.getChildAt(i);
String whereClause = "AD_Tree_ID=" + AD_Tree_ID + " AND Node_ID=" + nd.getNode_ID();
PO tree = MTable.get(Env.getCtx(), m_MTree.getNodeTableName()).getPO(whereClause, trx.getTrxName());
if (tree.get_ValueAsInt("Parent_ID") != from.getNode_ID() || tree.get_ValueAsInt("SeqNo") != i) {
tree.set_CustomColumn("Parent_ID", from.getNode_ID());
tree.set_CustomColumn("SeqNo", i);
tree.saveEx();
}
}
if (from != to) {
// Renumber and set parent ID for the children of the 'to' node.
int nextSeqNo = 0;
for (int i = 0; i < to.getChildCount(); i++) {
// Skip the entry of the 'from' node to avoid duplication
if (i == Integer.parseInt(from.getSeqNo()))
continue;
MTreeNode nd = (MTreeNode) to.getChildAt(i);
String whereClause = "AD_Tree_ID=" + AD_Tree_ID + " AND Node_ID=" + nd.getNode_ID();
PO tree = MTable.get(Env.getCtx(), m_MTree.getNodeTableName()).getPO(whereClause, trx.getTrxName());
if (tree.get_ValueAsInt("Parent_ID") != to.getNode_ID() || tree.get_ValueAsInt("SeqNo") < nextSeqNo) {
tree.set_CustomColumn("Parent_ID", to.getNode_ID());
tree.set_CustomColumn("SeqNo", nextSeqNo++);
tree.saveEx();
} else {
nextSeqNo = tree.get_ValueAsInt("SeqNo") + 1;
}
}
}
trx.commit(true);
} catch (Exception e) {
trx.rollback();
log.log(Level.SEVERE, "move", e);
}
trx.close();
trx = null;
log.config("complete");
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class ADTreeOnDropListener method moveNode.
/**
* Move TreeNode
* @param movingNode The node to be moved
* @param toNode The target node
*/
private void moveNode(DefaultTreeNode movingNode, DefaultTreeNode toNode) {
log.info(movingNode.toString() + " to " + toNode.toString());
if (movingNode == toNode)
return;
MTreeNode toMNode = (MTreeNode) toNode.getData();
DefaultTreeNode newParent;
int index;
if (// drop on a child node
!toMNode.isSummary()) {
moveNode(movingNode, toNode, false);
} else // drop on a summary node
{
//prompt user to select insert after or drop into the summary node
int[] path = treeModel.getPath(toNode);
Treeitem toItem = tree.renderItemByPath(path);
tree.setSelectedItem(toItem);
Events.sendEvent(tree, new Event(Events.ON_SELECT, tree));
MenuListener listener = new MenuListener(movingNode, toNode);
//TODO: translation
Menupopup popup = new Menupopup();
Menuitem menuItem = new Menuitem("Insert After");
menuItem.setValue("InsertAfter");
menuItem.setParent(popup);
menuItem.addEventListener(Events.ON_CLICK, listener);
menuItem = new Menuitem("Move Into");
menuItem.setValue("MoveInto");
menuItem.setParent(popup);
menuItem.addEventListener(Events.ON_CLICK, listener);
popup.setPage(tree.getPage());
popup.open(toItem.getTreerow());
}
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class MenuPanel method generateMenu.
private void generateMenu(Treechildren treeChildren, MTreeNode mNode) {
Enumeration<?> nodeEnum = mNode.children();
while (nodeEnum.hasMoreElements()) {
MTreeNode mChildNode = (MTreeNode) nodeEnum.nextElement();
Treeitem treeitem = new Treeitem();
treeChildren.appendChild(treeitem);
treeitem.setLabel(mChildNode.getName());
treeitem.setTooltiptext(mChildNode.getDescription());
if (mChildNode.getChildCount() != 0) {
treeitem.setOpen(false);
Treechildren treeItemChildren = new Treechildren();
generateMenu(treeItemChildren, mChildNode);
if (treeItemChildren.getChildren().size() != 0)
treeitem.appendChild(treeItemChildren);
treeitem.getTreerow().addEventListener(Events.ON_CLICK, this);
} else {
treeitem.setValue(String.valueOf(mChildNode.getNode_ID()));
if (mChildNode.isReport())
treeitem.setImage(ServletFns.resolveThemeURL("~./images/mReport.png"));
else if (mChildNode.isProcess() || mChildNode.isTask())
treeitem.setImage(ServletFns.resolveThemeURL("~./images/mProcess.png"));
else if (mChildNode.isWorkFlow())
treeitem.setImage(ServletFns.resolveThemeURL("~./images/mWorkFlow.png"));
else
treeitem.setImage(ServletFns.resolveThemeURL("~./images/mWindow.png"));
// Elaine 2008/07/24
treeitem.getTreerow().setDraggable("favourite");
treeitem.getTreerow().addEventListener(Events.ON_CLICK, this);
}
}
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class TreeSearchPanel method addTreeItem.
private void addTreeItem(DefaultTreeNode<?> node) {
Object data = node.getData();
if (data instanceof MTreeNode) {
MTreeNode mNode = (MTreeNode) data;
treeNodeItemMap.put(mNode.getName(), node);
}
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class MenuPanel method init.
private void init() {
ctx = Env.getCtx();
int adRoleId = Env.getAD_Role_ID(ctx);
int adTreeId = getTreeId(ctx, adRoleId);
MTree mTree = new MTree(ctx, adTreeId, false, true, null);
MTreeNode rootNode = mTree.getRoot();
initComponents();
initMenu(rootNode);
pnlSearch.initialise();
}
Aggregations