Monday, November 26, 2012

Building a tree lookup


1. In the AOT, create a new form named BudgetModelLookup. Set its design properties
as follows:

Property         Value
Frame            Border
WindowType   Popup

2. Add a new Tree control to the design, with the following properties:

Property Value
Name     ModelTree

3. Add the following line to the form's class declaration:
BudgetModelTree budgetModelTree;


4. Override the form's init() method with the following code:
public void init()
{
    FormStringControl callingControl;
    callingControl = SysTableLookup::getCallerStringControl (this.args());
    super();
    budgetModelTree = BudgetModelTree::construct(ModelTree, callingControl.text());
    budgetModelTree.buildTree();
}

5. Override the mouseDblClick() and mouseUp() methods of the ModelTree control
with the following code, respectively:
public int mouseDblClick(int _x, int _y, int _button, boolean _ctrl, boolean _shift)
{
    int ret;
    FormTreeItem formTreeItem;
    BudgetModel budgetModel;
    ret = super(_x, _y, _button, _ctrl, _shift);
    formTreeItem = this.getItem(this.getSelection());
    select firstOnly SubModelId from budgetModel
    where budgetModel.RecId == formTreeItem.data();
    element.closeSelect(budgetModel.SubModelId);
    return ret;
}
public int mouseUp(int _x, int _y, int _button, boolean _ctrl, boolean _shift)
{
    int ret;
    ret = super(_x, _y, _button, _ctrl, _shift);
    return 1;

6. The form should look similar to the following screenshot:



7. In the AOT, open the BudgetModel table, and change its lookupBudgetModel()
method with the following code:

public static void lookupBudgetModel(FormStringControl _ctrl, boolean _showStopped = false)
{
    Args args;
    Object formRun;
    args = new Args();
    args.name(formStr(BudgetModelLookup));
    args.caller(_ctrl);
    formRun = classfactory.formRunClass(args);
    formRun.init();
    _ctrl.performFormLookup(formRun);
}


8. To see the results, open Budgeting | Common | Budget register entries. Start
creating a new entry by clicking on the Budget register entry button in the action
pane, and expand the Budget model lookup:





No comments: