Browsable view

The concept of browsing view is very close to the standard view, with in addition, the handling of hierarchical elements.

Example of a browsing view XML description

The XML description remains the same as the standard one.

<view name="browsableView" action="display" provider="com.axemble.education.providers.demo.advanced.BrowsableView"> 
	<column name="NAME" label="LG_NAME" /> 
	<column name="COMMANDS" label="LG_COMMANDS" /> 
</view>

Code example of a class associated to a browsing view

This is an example of a browsing view implementation. The example is based on a fictive hierarchical structure.

public class BrowsableView extends BaseBrowsableViewProvider implements ICollectionModelViewProvider {
    private Object parent;
    public HashMap childrenMap = new HashMap();

    public class Tree...
    Tree root = new Tree("root", "Root");

    public BrowsableView(INavigateContext context, CtlAbstractView view) {
        super(context, view);
// build tree structure... root.children.add( firstRow );
        root.children.add(secondRow);
    }

    protected Collection getBrowsableOptions() {
        return null;
    }

    protected Collection getRootOptions() {
        if (parent == null) {
            Collection ret = new ArrayList();
            ret.add(new Option("", "ROOT"));
            return ret;
        } else {
            return getBrowsableOptions();
        }
    }

    public List getModelItems() {
        Tree tree;
        if (parent == null) tree = root;
        else tree = (Tree) parent;
        ArrayList lines = new ArrayList();
        for (Iterator iterator = tree.children.iterator(); iterator.hasNext(); ) {
            Tree child = (Tree) iterator.next();
            ViewModelItem line = new ViewModelItem(child.key);
            line.setValue("NAME", child.name);
            line.setBrowsableColumn("NAME");
            LinkedList l = new LinkedList();
            l.add(new CtlButton("ok", new CtlText("OK")));
            line.setValue("COMMANDS", l);
            lines.add(line);
        }
        return lines;
    }

    protected void onBrowse(Object key) {
        try {
            if (StringUtils.isEmpty((String) key)) parent = null;
            else {
                parent = (Tree) childrenMap.get(key);
            }
            super.onBrowse(key);
        } catch (Exception e) {
            getNavigator().processErrors(e);
        }
    }
}