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;
}
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;
}
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()]);
}
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);
}
}
}
}
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);
}
Aggregations