Search in sources :

Example 6 with Node

use of com.codename1.rad.nodes.Node in project CodeRAD by shannah.

the class Controller method createViewNode.

/**
 * Creates the view node that should be used as the node for the controller's view. This method should
 * be overridden by subclasses to define the default view node, but this method shouldn't be called directly.  Rather
 * the {@link #getViewNode()} method should be called so that the view node is only created once.  {@link #getViewNode() }
 * will also set the parent node to the view node of the parent controller to more easily benefit from inherited attributes
 * in the UI descriptor hierarchy.
 * @return A ViewNode
 */
protected ViewNode createViewNode() {
    startControllerInternal();
    ViewNode n = new ViewNode();
    if (actionMap != null) {
        for (ActionNode.Category c : actionMap.keySet()) {
            n.setAttributes(UI.actions(c, actionMap.get(c)));
        }
    }
    return n;
}
Also used : ActionNode(com.codename1.rad.nodes.ActionNode) ViewNode(com.codename1.rad.nodes.ViewNode)

Example 7 with Node

use of com.codename1.rad.nodes.Node in project CodeRAD by shannah.

the class Controller method extendAction.

/**
 * Extends an action from a parent controller, and registers it as an action on this controller.
 * @param category The category to register the action to.
 * @param callback Callback which is executed immediately on the action, which is used to configure
 *                 the action.
 * @return The action node that was added/extended.
 * @see #extendAction(ActionNode.Category, boolean, Attribute[])
 */
public ActionNode extendAction(ActionNode.Category category, SuccessCallback<ActionNode> callback) {
    ActionNode extendedAction = extendAction(category, false);
    callback.onSucess(extendedAction);
    return extendedAction;
}
Also used : ActionNode(com.codename1.rad.nodes.ActionNode)

Example 8 with Node

use of com.codename1.rad.nodes.Node in project CodeRAD by shannah.

the class Node method mergeRecursive.

protected static final Attribute[] mergeRecursive(Attribute[]... arrs) {
    LinkedHashMap<Class, Attribute> map = new LinkedHashMap<>();
    for (Attribute[] arr : arrs) {
        for (Attribute att : arr) {
            Attribute existing = map.get(att.getClass());
            if (existing == null) {
                map.put(att.getClass(), att);
                continue;
            }
            if (existing instanceof Node) {
                Node existingNode = (Node) existing;
                Node node = (Node) att;
                existingNode.mergeAttributes(node, true);
            } else {
                map.put(att.getClass(), att);
            }
        }
    }
    return map.values().toArray(new Attribute[map.size()]);
}
Also used : ViewPropertyParameterAttribute(com.codename1.rad.attributes.ViewPropertyParameterAttribute) NodeDecoratorAttribute(com.codename1.rad.attributes.NodeDecoratorAttribute) PropertySelectorAttribute(com.codename1.rad.attributes.PropertySelectorAttribute) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with Node

use of com.codename1.rad.nodes.Node in project CodeRAD by shannah.

the class Node method mergeAttributes.

private void mergeAttributes(Node node, boolean recursive) {
    for (Attribute att : node.attributes) {
        if (attributes.getAttribute(att.getClass()) == null) {
            setAttributes(att);
        } else {
            if (recursive && att instanceof Node) {
                Node existing = (Node) attributes.getAttribute(att.getClass());
                Node newNode = (Node) att;
                existing.mergeAttributes(newNode, recursive);
            } else {
                setAttributes(att);
            }
        }
    }
}
Also used : ViewPropertyParameterAttribute(com.codename1.rad.attributes.ViewPropertyParameterAttribute) NodeDecoratorAttribute(com.codename1.rad.attributes.NodeDecoratorAttribute) PropertySelectorAttribute(com.codename1.rad.attributes.PropertySelectorAttribute)

Example 10 with Node

use of com.codename1.rad.nodes.Node in project CodeRAD by shannah.

the class Node method setAttributes.

/**
 * Sets attributes on this node.
 * @param atts The attributes to set.
 */
public void setAttributes(Attribute... atts) {
    for (Attribute att : atts) {
        if (att == null) {
            continue;
        }
        if (att instanceof Node) {
            Node n = (Node) att;
            if (n.parent != null && n.parent != this) {
                if (n.canProxy()) {
                    n = n.proxy(this);
                } else {
                    throw new IllegalStateException("Node " + n + " already has parent " + n.parent + ".  Cannot be added to " + this);
                }
            } else {
                n.parent = this;
            }
            NodeDecoratorAttribute nodeDecorator = (NodeDecoratorAttribute) n.findAttribute(NodeDecoratorAttribute.class);
            if (nodeDecorator != null) {
                // System.out.println("Decorating node "+n+" with "+nodeDecorator.getValue());
                nodeDecorator.getValue().decorate(n);
            }
            this.childNodes.add(n);
        }
        if (att.getClass() == ViewPropertyParameterAttribute.class) {
            ViewPropertyParameterAttribute valueAtt = (ViewPropertyParameterAttribute) att;
            ViewPropertyParameter val = (ViewPropertyParameter) valueAtt.getValue();
            viewParameters.put(val.getProperty(), val);
        }
        if (att.getClass() == ActionsNode.class) {
            ActionsNode actionsNode = (ActionsNode) att;
            ActionNode.Category category = actionsNode.getCategory();
            if (category != null) {
                actions.put(category, actionsNode);
            }
        }
    }
    this.attributes.setAttributes(atts);
}
Also used : Category(com.codename1.rad.nodes.ActionNode.Category) NodeDecoratorAttribute(com.codename1.rad.attributes.NodeDecoratorAttribute) ViewPropertyParameterAttribute(com.codename1.rad.attributes.ViewPropertyParameterAttribute) NodeDecoratorAttribute(com.codename1.rad.attributes.NodeDecoratorAttribute) PropertySelectorAttribute(com.codename1.rad.attributes.PropertySelectorAttribute) ViewPropertyParameterAttribute(com.codename1.rad.attributes.ViewPropertyParameterAttribute)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)11 ViewNode (com.codename1.rad.nodes.ViewNode)10 ActionNode (com.codename1.rad.nodes.ActionNode)8 Container (com.codename1.ui.Container)7 ListNode (com.codename1.rad.nodes.ListNode)6 PropertySelectorAttribute (com.codename1.rad.attributes.PropertySelectorAttribute)5 Node (com.codename1.rad.nodes.Node)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 MultiButtonEntityView (com.codename1.rad.ui.entityviews.MultiButtonEntityView)4 Label (com.codename1.ui.Label)4 GridLayout (com.codename1.ui.layouts.GridLayout)4 Log (com.codename1.io.Log)3 NodeDecoratorAttribute (com.codename1.rad.attributes.NodeDecoratorAttribute)3 ViewPropertyParameterAttribute (com.codename1.rad.attributes.ViewPropertyParameterAttribute)3 Entity (com.codename1.rad.models.Entity)3 EntityList (com.codename1.rad.models.EntityList)3 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)3 Thing (com.codename1.rad.schemas.Thing)3 WrapperEntityView (com.codename1.rad.ui.entityviews.WrapperEntityView)3 Button (com.codename1.ui.Button)3