use of org.zkoss.zul.DefaultTreeNode 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.zkoss.zul.DefaultTreeNode in project adempiere by adempiere.
the class TreeSearchPanel method onEvent.
/**
* @param event
* @see EventListener#onEvent(Event)
*/
public void onEvent(Event event) {
if (cmbSearch.equals(event.getTarget()) && ((event.getName().equals(Events.ON_CHANGE) || event.getName().equals(Events.ON_OK)))) {
String value = cmbSearch.getValue();
if (value != null && value.trim().length() > 0 && value.substring(0, 1).equals(PREFIX_DOCUMENT_SEARCH)) {
DocumentSearch search = new DocumentSearch();
if (search.openDocumentsByDocumentNo(value.substring(1)))
cmbSearch.setText(null);
return;
}
Object node = treeNodeItemMap.get(value);
Treeitem treeItem = null;
if (node == null) {
return;
} else if (node instanceof Treeitem) {
treeItem = (Treeitem) node;
} else {
DefaultTreeNode<?> sNode = (DefaultTreeNode<?>) node;
int[] path = tree.getModel().getPath(sNode);
treeItem = tree.renderItemByPath(path);
tree.setSelectedItem(treeItem);
}
if (treeItem != null) {
select(treeItem);
Clients.showBusy(Msg.getMsg(Env.getCtx(), "Loading"));
Events.echoEvent("onPostSelect", this, null);
}
}
}
use of org.zkoss.zul.DefaultTreeNode in project adempiere by adempiere.
the class TreeSearchPanel method refreshSearchList.
private void refreshSearchList() {
treeNodeItemMap.clear();
if (tree.getModel() == null) {
TreeUtils.traverse(tree, new TreeItemAction() {
public void run(Treeitem treeItem) {
addTreeItem(treeItem);
}
});
} else {
TreeUtils.traverse(tree.getModel(), new TreeNodeAction() {
public void run(DefaultTreeNode<?> treeNode) {
addTreeItem(treeNode);
}
});
}
treeValues = new String[treeNodeItemMap.size()];
treeDescription = new String[treeNodeItemMap.size()];
int i = -1;
for (Object value : treeNodeItemMap.values()) {
i++;
if (value instanceof Treeitem) {
Treeitem treeItem = (Treeitem) value;
treeValues[i] = treeItem.getLabel();
treeDescription[i] = treeItem.getTooltiptext();
} else if (value instanceof DefaultTreeNode) {
DefaultTreeNode<?> sNode = (DefaultTreeNode<?>) value;
MTreeNode mNode = (MTreeNode) sNode.getData();
treeValues[i] = mNode.getName();
treeDescription[i] = mNode.getDescription();
}
}
cmbSearch.setDescription(treeDescription);
cmbSearch.setDict(treeValues);
}
use of org.zkoss.zul.DefaultTreeNode in project adempiere by adempiere.
the class WTreeBOM method parent.
public DefaultTreeNode parent(MPPProductBOM bom) {
DefaultTreeNode parent = new DefaultTreeNode(productSummary(bom), new ArrayList());
for (MPPProductBOMLine bomline : bom.getLines()) {
MProduct component = MProduct.get(getCtx(), bomline.getM_Product_ID());
Vector<Object> line = new Vector<Object>(17);
// 0 Select
line.add(new Boolean(false));
// 1 IsActive
line.add(new Boolean(true));
// 2 Line
line.add(new Integer(bomline.getLine()));
// 3 ValidDrom
line.add((Timestamp) bomline.getValidFrom());
// 4 ValidTo
line.add((Timestamp) bomline.getValidTo());
KeyNamePair pp = new KeyNamePair(component.getM_Product_ID(), component.getName());
// 5 M_Product_ID
line.add(pp);
KeyNamePair uom = new KeyNamePair(bomline.getC_UOM_ID(), bomline.getC_UOM().getUOMSymbol());
// 6 C_UOM_ID
line.add(uom);
// 7 IsQtyPercentage
line.add(new Boolean(bomline.isQtyPercentage()));
// 8 BatchPercent
line.add((BigDecimal) bomline.getQtyBatch());
// 9 QtyBom
line.add((BigDecimal) bomline.getQtyBOM());
// 10 IsCritical
line.add(new Boolean(bomline.isCritical()));
// 11 LTOffSet
line.add((Integer) bomline.getLeadTimeOffset());
// 12 Assay
line.add((BigDecimal) bomline.getAssay());
// 13 Scrap
line.add((BigDecimal) (bomline.getScrap()));
// 14 IssueMethod
line.add((String) bomline.getIssueMethod());
// 15 BackflushGroup
line.add((String) bomline.getBackflushGroup());
// 16 Forecast
line.add((BigDecimal) bomline.getForecast());
dataBOM.add(line);
parent.getChildren().add(component(component));
}
return parent;
}
use of org.zkoss.zul.DefaultTreeNode 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