use of org.adempiere.webui.component.SimpleTreeModel in project adempiere by adempiere.
the class ADTabPanel method setSelectedNode.
private void setSelectedNode(int recordId) {
if (recordId <= 0)
return;
if (treePanel.getTree().getSelectedItem() != null) {
SimpleTreeNode treeNode = (SimpleTreeNode) treePanel.getTree().getSelectedItem().getValue();
MTreeNode data = (MTreeNode) treeNode.getData();
if (data.getNode_ID() == recordId)
return;
}
SimpleTreeModel model = (SimpleTreeModel) treePanel.getTree().getModel();
SimpleTreeNode treeNode = model.find(null, recordId);
if (treeNode != null) {
int[] path = model.getPath(model.getRoot(), treeNode);
Treeitem ti = treePanel.getTree().renderItemByPath(path);
treePanel.getTree().setSelectedItem(ti);
} else {
addNewNode();
}
}
use of org.adempiere.webui.component.SimpleTreeModel in project adempiere by adempiere.
the class ADTreePanel method nodeChanged.
//
/**************************************************************************
* Node Changed - synchronize Node
*
* @param save true the node was saved (changed/added), false if the row was deleted
* @param keyID the ID of the row changed
* @param name name
* @param description description
* @param isSummary summary node
* @param imageIndicator image indicator
*/
@SuppressWarnings("unchecked")
public void nodeChanged(boolean save, int keyID, String name, String description, boolean isSummary, String imageIndicator) {
if (tree == null)
return;
// if ID==0=root - don't update it
if (keyID == 0)
return;
// try to find the node
TreeModel<Object> model = tree.getModel();
DefaultTreeNode<Object> root = (DefaultTreeNode<Object>) model.getRoot();
SimpleTreeModel sModel = new SimpleTreeModel(root);
DefaultTreeNode<Object> node = sModel.find(null, keyID);
// Node not found and saved -> new
if (node == null && save) {
MTreeNode rootData = (MTreeNode) root.getData();
MTreeNode mTreeNode = new MTreeNode(keyID, 0, name, description, rootData.getNode_ID(), isSummary, imageIndicator, false, null);
DefaultTreeNode<Object> newNode = new DefaultTreeNode<Object>(mTreeNode);
sModel.addNode(root, newNode, 0);
int[] path = sModel.getPath(newNode);
Treeitem ti = tree.renderItemByPath(path);
tree.setSelectedItem(ti);
} else // Node found and saved -> change
if (node != null && save) {
MTreeNode mTreeNode = (MTreeNode) node.getData();
mTreeNode.setName(name);
mTreeNode.setAllowsChildren(isSummary);
int[] path = sModel.getPath(node);
Treeitem ti = tree.renderItemByPath(path);
tree.setSelectedItem(ti);
} else // Node found and not saved -> delete
if (node != null && !save) {
sModel.removeNode(node);
} else // Error
{
node = null;
}
// Nothing to display
if (node == null)
return;
}
use of org.adempiere.webui.component.SimpleTreeModel in project adempiere by adempiere.
the class ADTabPanel method addNewNode.
private void addNewNode() {
if (gridTab.getRecord_ID() > 0) {
String name = (String) gridTab.getValue("Name");
String description = (String) gridTab.getValue("Description");
boolean summary = gridTab.getValueAsBoolean("IsSummary");
// Menu - Action
String imageIndicator = (String) gridTab.getValue("Action");
//
SimpleTreeModel model = (SimpleTreeModel) treePanel.getTree().getModel();
SimpleTreeNode treeNode = model.getRoot();
MTreeNode root = (MTreeNode) treeNode.getData();
MTreeNode node = new MTreeNode(gridTab.getRecord_ID(), 0, name, description, root.getNode_ID(), summary, imageIndicator, false, null);
SimpleTreeNode newNode = new SimpleTreeNode(node, new ArrayList<Object>());
model.addNode(newNode);
int[] path = model.getPath(model.getRoot(), newNode);
Treeitem ti = treePanel.getTree().renderItemByPath(path);
treePanel.getTree().setSelectedItem(ti);
}
}
use of org.adempiere.webui.component.SimpleTreeModel in project adempiere by adempiere.
the class ADTabPanel method deleteNode.
private void deleteNode(int recordId) {
if (recordId <= 0)
return;
SimpleTreeModel model = (SimpleTreeModel) treePanel.getTree().getModel();
if (treePanel.getTree().getSelectedItem() != null) {
SimpleTreeNode treeNode = (SimpleTreeNode) treePanel.getTree().getSelectedItem().getValue();
MTreeNode data = (MTreeNode) treeNode.getData();
if (data.getNode_ID() == recordId) {
model.removeNode(treeNode);
return;
}
}
SimpleTreeNode treeNode = model.find(null, recordId);
if (treeNode != null) {
model.removeNode(treeNode);
}
}
use of org.adempiere.webui.component.SimpleTreeModel in project adempiere by adempiere.
the class WTreeMaintenance method onListSelection.
// action_fillTree
/**
* List Selection Listener
* @param e event
*/
private void onListSelection(Event e) {
ListItem selected = null;
try {
SimpleListModel model = (SimpleListModel) centerList.getModel();
int i = centerList.getSelectedIndex();
selected = (ListItem) model.getElementAt(i);
} catch (Exception ex) {
}
log.info("Selected=" + selected);
if (// allow add if not in tree
selected != null) {
SimpleTreeModel tm = (SimpleTreeModel) (TreeModel<?>) centerTree.getModel();
DefaultTreeNode stn = tm.find(tm.getRoot(), selected.id);
if (stn != null) {
int[] path = tm.getPath(stn);
Treeitem ti = centerTree.renderItemByPath(path);
ti.setSelected(true);
}
bAdd.setEnabled(stn == null);
}
}
Aggregations