Search in sources :

Example 1 with DefaultTreeNode

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;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Treeitem(org.zkoss.zul.Treeitem) SimpleTreeModel(org.adempiere.webui.component.SimpleTreeModel) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode)

Example 2 with DefaultTreeNode

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);
        }
    }
}
Also used : Treeitem(org.zkoss.zul.Treeitem) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) DocumentSearch(org.adempiere.webui.util.DocumentSearch)

Example 3 with DefaultTreeNode

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);
}
Also used : MTreeNode(org.compiere.model.MTreeNode) TreeItemAction(org.adempiere.webui.util.TreeItemAction) Treeitem(org.zkoss.zul.Treeitem) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) TreeNodeAction(org.adempiere.webui.util.TreeNodeAction)

Example 4 with DefaultTreeNode

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;
}
Also used : MProduct(org.compiere.model.MProduct) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ArrayList(java.util.ArrayList) KeyNamePair(org.compiere.util.KeyNamePair) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) Vector(java.util.Vector)

Example 5 with DefaultTreeNode

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);
    }
}
Also used : Treeitem(org.zkoss.zul.Treeitem) SimpleTreeModel(org.adempiere.webui.component.SimpleTreeModel) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) SimpleListModel(org.adempiere.webui.component.SimpleListModel)

Aggregations

DefaultTreeNode (org.zkoss.zul.DefaultTreeNode)15 MTreeNode (org.compiere.model.MTreeNode)8 Treeitem (org.zkoss.zul.Treeitem)8 ArrayList (java.util.ArrayList)6 SimpleTreeModel (org.adempiere.webui.component.SimpleTreeModel)6 MProduct (org.compiere.model.MProduct)3 Vector (java.util.Vector)2 SimpleListModel (org.adempiere.webui.component.SimpleListModel)2 KeyNamePair (org.compiere.util.KeyNamePair)2 MPPProductBOM (org.eevolution.model.MPPProductBOM)2 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)2 DropEvent (org.zkoss.zk.ui.event.DropEvent)2 Event (org.zkoss.zk.ui.event.Event)2 Treecol (org.zkoss.zul.Treecol)2 Treecols (org.zkoss.zul.Treecols)2 BigDecimal (java.math.BigDecimal)1 DocumentSearch (org.adempiere.webui.util.DocumentSearch)1 TreeItemAction (org.adempiere.webui.util.TreeItemAction)1 TreeNodeAction (org.adempiere.webui.util.TreeNodeAction)1 Trx (org.compiere.util.Trx)1