Search in sources :

Example 1 with DefaultProperty

use of org.apache.pivot.beans.DefaultProperty in project pivot by apache.

the class BXMLExplorerDocument method analyseObjectTree.

@SuppressWarnings("unchecked")
private TreeNode analyseObjectTree(Object container) {
    // doesn't look neat
    if (container instanceof TablePane) {
        TreeBranch branch = new TreeBranch(nameForObject(container));
        TablePane table = (TablePane) container;
        for (TablePane.Row row : table.getRows()) {
            TreeNode childBranch = analyseObjectTree(row);
            branch.add(childBranch);
        }
        setComponentIconOnTreeNode(container, branch);
        return branch;
    }
    // We don't want to analyse the components that are added as part of the
    // skin, so use similar logic to BXMLSerializer
    DefaultProperty defaultProperty = container.getClass().getAnnotation(DefaultProperty.class);
    if (defaultProperty != null) {
        TreeBranch branch = new TreeBranch(nameForObject(container));
        String defaultPropertyName = defaultProperty.value();
        BeanAdapter beanAdapter = new BeanAdapter(container);
        if (!beanAdapter.containsKey(defaultPropertyName)) {
            throw new IllegalStateException("default property " + defaultPropertyName + " not found on " + container);
        }
        Object defaultPropertyValue = beanAdapter.get(defaultPropertyName);
        if (defaultPropertyValue != null) {
            if (defaultPropertyValue instanceof Component) {
                TreeNode childBranch = analyseObjectTree(defaultPropertyValue);
                branch.add(childBranch);
            }
        }
        // so make empty branches into nodes.
        if (branch.isEmpty()) {
            TreeNode node = new TreeNode(branch.getText());
            setComponentIconOnTreeNode(container, node);
            return node;
        }
        setComponentIconOnTreeNode(container, branch);
        return branch;
    }
    if (container instanceof Sequence<?>) {
        TreeBranch branch = new TreeBranch(nameForObject(container));
        Iterable<Object> sequence = (Iterable<Object>) container;
        for (Object child : sequence) {
            TreeNode childBranch = analyseObjectTree(child);
            branch.add(childBranch);
        }
        setComponentIconOnTreeNode(container, branch);
        return branch;
    }
    TreeNode node = new TreeNode(nameForObject(container));
    setComponentIconOnTreeNode(container, node);
    return node;
}
Also used : Sequence(org.apache.pivot.collections.Sequence) DefaultProperty(org.apache.pivot.beans.DefaultProperty) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) TreeNode(org.apache.pivot.wtk.content.TreeNode) BeanAdapter(org.apache.pivot.beans.BeanAdapter) Component(org.apache.pivot.wtk.Component) TablePane(org.apache.pivot.wtk.TablePane)

Aggregations

BeanAdapter (org.apache.pivot.beans.BeanAdapter)1 DefaultProperty (org.apache.pivot.beans.DefaultProperty)1 Sequence (org.apache.pivot.collections.Sequence)1 Component (org.apache.pivot.wtk.Component)1 TablePane (org.apache.pivot.wtk.TablePane)1 TreeBranch (org.apache.pivot.wtk.content.TreeBranch)1 TreeNode (org.apache.pivot.wtk.content.TreeNode)1