use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class VTreePanel method mouseClicked.
// keyPressed
/*************************************************************************/
/**
* Mouse clicked
* @param e event
*/
protected void mouseClicked(MouseEvent e) {
// *** JTree ***
if (e.getSource() instanceof JTree) {
// Left Double Click
if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 0) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
if (selRow != -1) {
MTreeNode tn = (MTreeNode) tree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
setSelectedNode(tn);
}
} else // Right Click for PopUp
if ((m_editable || m_hasBar) && SwingUtilities.isRightMouseButton(e)) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
if (selRow != -1) {
tree.setSelectionRow(selRow);
}
if (// need select first
tree.getSelectionPath() != null) {
MTreeNode nd = (MTreeNode) tree.getSelectionPath().getLastPathComponent();
if (// only add leaves to bar
nd.isLeaf())
mBarAdd.setEnabled(true);
else
mBarAdd.setEnabled(false);
Rectangle r = tree.getPathBounds(tree.getSelectionPath());
popMenuTree.show(tree, (int) r.getMaxX(), (int) r.getY());
}
}
} else // *** JButton ***
if (e.getSource() instanceof JButton) {
if (SwingUtilities.isRightMouseButton(e)) {
m_buttonSelected = (CButton) e.getSource();
popMenuBar.show(m_buttonSelected, e.getX(), e.getY());
}
}
// JButton
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class VTreePanel method selectID.
// setSelectedNode
/**
* Select ID in Tree
* @param nodeID Node ID
* @param show scroll to node
* @return true if selected
*/
private boolean selectID(int nodeID, boolean show) {
if (m_root == null)
return false;
log.config("NodeID=" + nodeID + ", Show=" + show + ", root=" + m_root);
// try to find the node
MTreeNode node = m_root.findNode(nodeID);
if (node != null) {
TreePath treePath = new TreePath(node.getPath());
log.config("Node=" + node + ", Path=" + treePath.toString());
tree.setSelectionPath(treePath);
if (show) {
// expand it
tree.makeVisible(treePath);
tree.scrollPathToVisible(treePath);
}
return true;
}
log.info("Node not found; ID=" + nodeID);
return false;
}
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 TreeXML method appendNode.
private String appendNode(MTreeNode thisNode) {
StringBuffer tempTree = new StringBuffer();
Integer ID = new Integer(thisNode.getNode_ID());
MContainer container = m_map.get(ID);
//
int size = thisNode.getChildCount();
for (int i = 0; i < size; i++) {
MTreeNode child = (MTreeNode) thisNode.getChildAt(i);
ID = new Integer(child.getNode_ID());
container = m_map.get(ID);
if (container == null) {
continue;
}
if (!container.isActive())
continue;
//
tempTree.append("<treenode>");
tempTree.append("<CM_Container_ID>" + container.get_ID() + "</CM_Container_ID>");
tempTree.append("<Name>" + container.getName() + "</Name>");
tempTree.append("<Title>" + container.getTitle() + "</Title>");
tempTree.append("<RelativeURL>" + container.getRelativeURL() + "</RelativeURL>");
tempTree.append("<Description>" + container.getDescription() + "</Description>");
tempTree.append("<children>" + child.getChildCount() + "</children>");
xmlContainer = container.get_xmlString(xmlContainer);
if (child.isSummary())
tempTree.append(appendNode(child));
tempTree.append("</treenode>");
}
return tempTree.toString();
}
Aggregations