views:

94

answers:

1

In my other methods (data, text, etc.) the setItem method works fine to display changes made to a tree item. However, calling setItem after changing an item's icon doesn't seem to have any effect. What is the best way to update the tree item so the new icon appears?

Thanks

public void modified()
{
    FormTreeItem workingItem;
    ;
    super();

    //find the current item
    workingItem = FormTreeControl.getItem(FormTreeControl.getSelection());
    //update the value
    workingItem.Image(1);
    //update the item in the list
    FormTreeControl.setItem(workingItem);

}
A: 

Found a couple of issues here:
1. Never found a way to update the icon on a tree item effectively.
2. Found out some of the tree control objects aren't initialized if you try to add/delete from a datasource method, so deleting items throws Object Not Initialized errors.

Fixed it by:
1. Create a new item (addAfterIdx of the old item).
2. Delete the old item.
3. Select the new item.
3. Move the method from the datasource to the actual form control.

Here's the code that worked for me:

public boolean modified()
{
    boolean ret;
    FormTreeItem workingItem = FormTreeControl.getItem(currentEditingIdx);
    TreeItemIdx newItemIdx;
    ;
    ret = super();

    //create a new item
    newItemIdx = SysFormTreeControl::addTreeItem(FormTreeControl, workingItem.text(), FormTreeControl.getParent(workingItem.idx()), workingItem.data(), element.imageIdx(ABC_Icon.text()));
    //delete the old item
    FormTreeControl.delete(currentEditingIdx);
    //select the new item
    FormTreeControl.selectionChanged(FormTreeControl.getItem(FormTreeControl.getRoot()), FormTreeControl.getItem(newItemIdx), FormTreeSelect::Unknown);

    return ret;
}
Brad