Saturday, February 16, 2013

Up Down Sequence Logic

In one of the customizations, there was a requirement to allow users to move items up/down in BOMDesignerDetails Form. This form uses a Tree control, which displays a BOM and its items in a tree structure. A user should be able to resequence these items with Up and Down arrows. Sounds simple and it is, once you know how. There is a standard form EConDesigner which has this feature and I replicated the code for the two buttons. Code is in the clicked method of the buttons. Logic utilizes few standard Tree control methods like getSelection, getPrevSibling, getNextSibling, moveItem, selectItems. Below is a simpler description, our requirement was a little more complex requiring renumbering of LineNum as the sequence changes and simultaneous update to a Map, which stored the key, value pairs for each item. 



MoveUpButton
void clicked()
{
    int idx_mv = ModelTree.getSelection();
    int idx;
    ;

    if (idx_mv)
    {
        idx = ModelTree.getPrevSibling(idx_mv);
        if (idx)
        {
            idx_mv = ModelTree.moveItem(idx, ModelTree.getParent(idx_mv), idx_mv);
            ModelTree.selectItems(idx, idx);
        }
    }
}
MoveDownButton
void clicked()
{
    int idx_mv = ModelTree.getSelection();
    int idx;
    ;

    if (idx_mv)
    {
        idx = ModelTree.getNextSibling(idx_mv);
        if (idx)
        {
            idx_mv = ModelTree.moveItem(idx_mv, ModelTree.getParent(idx_mv), idx);
            ModelTree.selectItems(idx_mv, idx_mv);
        }
    }
}

No comments:

Post a Comment