Search in sources :

Example 6 with Controller

use of com.codename1.rad.controllers.Controller in project CodeRAD by shannah.

the class Controller method addActions.

/**
 * Adds a set of actions to this controller, registered to a given category.
 * @param category The category to register the actions under.
 * @param actions The actions to register.
 * @see #extendAction(ActionNode.Category, SuccessCallback) To extend an existing action
 * from a parent controller, and register the extended action on this controller.
 * @since 2.0
 */
public void addActions(ActionNode.Category category, ActionNode... actions) {
    if (actionMap == null) {
        actionMap = new HashMap();
    }
    Actions acts = null;
    if (!actionMap.containsKey(category)) {
        acts = new Actions();
        actionMap.put(category, acts);
    } else {
        acts = actionMap.get(category);
    }
    acts.add(actions);
}
Also used : Actions(com.codename1.rad.ui.Actions)

Example 7 with Controller

use of com.codename1.rad.controllers.Controller 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 Controller

use of com.codename1.rad.controllers.Controller in project CodeRAD by shannah.

the class Controller method withParentLookupEntity.

/**
 * Calls {@link #lookupEntity(Class)} on the Parent controller.
 * @param type The typeof entity to look for.  This may also be an Interface.
 * @param callback Callback executed only if a matching entity is found.
 * @return True if entity is found.
 * @since 2.0
 */
public boolean withParentLookupEntity(Class type, SuccessCallback<Entity> callback) {
    Entity o = parentLookupEntity(type);
    if (o == null)
        return false;
    callback.onSucess(o);
    return true;
}
Also used : Entity(com.codename1.rad.models.Entity)

Example 9 with Controller

use of com.codename1.rad.controllers.Controller in project CodenameOne by codenameone.

the class ProfileAvatarViewSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    Profile profile = new Profile();
    profile.set(Profile.name, "Steve");
    profile.set(Profile.icon, "https://www.codenameone.com/img/steve.jpg");
    ProfileAvatarView avatar = new ProfileAvatarView(profile, 30f);
    hi.add("Avatar with Name and Icon");
    hi.add(FlowLayout.encloseCenter(avatar));
    profile = new Profile();
    profile.set(Profile.name, "Steve");
    avatar = new ProfileAvatarView(profile, 30f);
    hi.add("Avatar with only Name");
    hi.add(FlowLayout.encloseCenter(avatar));
    profile = new Profile();
    avatar = new ProfileAvatarView(profile, 30f);
    hi.add("Avatar with no name or icon");
    hi.add(FlowLayout.encloseCenter(avatar));
    profile = new Profile();
    profile.set(Profile.name, "Steve");
    profile.set(Profile.icon, "https://www.codenameone.com/img/steve.jpg");
    hi.add("Avatar with view controller");
    hi.add(FlowLayout.encloseCenter(new ProfileViewController(null, profile).getView()));
    hi.show();
}
Also used : Form(com.codename1.ui.Form) ProfileAvatarView(com.codename1.rad.ui.entityviews.ProfileAvatarView)

Example 10 with Controller

use of com.codename1.rad.controllers.Controller in project CodenameOne by codenameone.

the class RADActionBoundUIIDSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Toggled Actions Sample", new BorderLayout());
    // Create a tag fo the online status property.
    Tag TAG_ONLINE = new Tag("online");
    // Create an action that will indicte the online/offline status
    ActionNode status = UI.action(// on state of TAG_ONLINE property.
    UI.label(person -> {
        if (person.isFalsey(TAG_ONLINE)) {
            return "Offline";
        } else {
            return "Online";
        }
    }), // Depending on state of TAG_ONLINE property
    UI.uiid(person -> {
        if (person.isFalsey(TAG_ONLINE)) {
            return "LoggedOutStatusButton";
        } else {
            return "LoggedInStatusButton";
        }
    }), // Icon for the action
    UI.icon(FontImage.MATERIAL_PERSON), // define it to always return true so action is always visible.
    UI.condition(person -> {
        return true;
    }));
    // A User entity we use for the models.
    class User extends Entity {
    }
    entityTypeBuilder(User.class).Boolean(TAG_ONLINE).string(Thing.name).factory(cls -> {
        return new User();
    }).build();
    // Create an entity list that will hold several users.
    EntityList el = new EntityList();
    for (int i = 0; i < 200; i++) {
        User u = new User();
        u.set(Thing.name, "User " + i);
        u.set(TAG_ONLINE, i % 2 == 0);
        el.add(u);
    }
    // The ListNode is a wrapper that will be passed to our View so that
    // they can access our action.
    ListNode node = new ListNode(// for each row.
    UI.actions(ProfileListView.ACCOUNT_LIST_ROW_ACTIONS, status));
    // Use a ProfileListView to display all of the users
    // https://shannah.github.io/CodeRAD/javadoc/com/codename1/rad/ui/entityviews/ProfileListView.html
    ProfileListView plv = new ProfileListView(el, node, 8);
    plv.setScrollableY(true);
    // In order to respond to events raised by the action, our view needs to be wrapped
    // in a controller.  Normally our form would have a FormViewController so we could
    // just use FormController, but this sample is compressed to be inside
    // a single method here so we'll create a dedicated ViewController for the list
    ViewController ctrl = new ViewController(null);
    ctrl.setView(plv);
    ctrl.addActionListener(status, evt -> {
        // The action was pressed by the user
        // Update the model's online status
        User u = (User) evt.getEntity();
        u.set(TAG_ONLINE, u.isFalsey(TAG_ONLINE));
    // This will trigger a property change in the model which will update the view.
    });
    hi.add(CENTER, plv);
    hi.show();
}
Also used : ViewNode(com.codename1.rad.nodes.ViewNode) Toolbar(com.codename1.ui.Toolbar) BoxLayout(com.codename1.ui.layouts.BoxLayout) EntityTypeBuilder.entityTypeBuilder(com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder) Form(com.codename1.ui.Form) NetworkEvent(com.codename1.io.NetworkEvent) ListNode(com.codename1.rad.nodes.ListNode) Display(com.codename1.ui.Display) FontImage(com.codename1.ui.FontImage) Label(com.codename1.ui.Label) CN(com.codename1.ui.CN) ViewController(com.codename1.rad.controllers.ViewController) UI(com.codename1.rad.ui.UI) Entity(com.codename1.rad.models.Entity) Tag(com.codename1.rad.models.Tag) Resources(com.codename1.ui.util.Resources) EntityList(com.codename1.rad.models.EntityList) IOException(java.io.IOException) ActionNode(com.codename1.rad.nodes.ActionNode) Log(com.codename1.io.Log) BorderLayout(com.codename1.ui.layouts.BorderLayout) ProfileListView(com.codename1.rad.ui.entityviews.ProfileListView) UIManager(com.codename1.ui.plaf.UIManager) Dialog(com.codename1.ui.Dialog) Thing(com.codename1.rad.schemas.Thing) EntityListView(com.codename1.rad.ui.entityviews.EntityListView) Entity(com.codename1.rad.models.Entity) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) ViewController(com.codename1.rad.controllers.ViewController) ActionNode(com.codename1.rad.nodes.ActionNode) EntityList(com.codename1.rad.models.EntityList) ProfileListView(com.codename1.rad.ui.entityviews.ProfileListView) Tag(com.codename1.rad.models.Tag) ListNode(com.codename1.rad.nodes.ListNode)

Aggregations

Form (com.codename1.ui.Form)6 ActionNode (com.codename1.rad.nodes.ActionNode)5 Entity (com.codename1.rad.models.Entity)4 ViewNode (com.codename1.rad.nodes.ViewNode)3 Component (com.codename1.ui.Component)3 Toolbar (com.codename1.ui.Toolbar)3 IOException (java.io.IOException)3 Log (com.codename1.io.Log)2 NetworkEvent (com.codename1.io.NetworkEvent)2 ViewController (com.codename1.rad.controllers.ViewController)2 EntityList (com.codename1.rad.models.EntityList)2 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)2 ListNode (com.codename1.rad.nodes.ListNode)2 Thing (com.codename1.rad.schemas.Thing)2 UI (com.codename1.rad.ui.UI)2 ProfileListView (com.codename1.rad.ui.entityviews.ProfileListView)2 CN (com.codename1.ui.CN)2 Dialog (com.codename1.ui.Dialog)2 Display (com.codename1.ui.Display)2 FontImage (com.codename1.ui.FontImage)2