Search in sources :

Example 1 with ListNode

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

the class DefaultEntityListCellRenderer method getListCellRendererComponent.

@Override
public EntityView getListCellRendererComponent(EntityListView list, Entity value, int index, boolean isSelected, boolean isFocused) {
    ListNode listNode = (ListNode) list.getViewNode();
    MultiButtonEntityView out = new MultiButtonEntityView(value, listNode.getRowTemplate());
    ActionNode node = listNode.getAction(ActionCategories.LIST_SELECT_ACTION);
    if (node != null) {
        out.setAction(node);
    }
    return makeSwipeable(value, listNode.getRowTemplate(), out);
}
Also used : ActionNode(com.codename1.rad.nodes.ActionNode) MultiButtonEntityView(com.codename1.rad.ui.entityviews.MultiButtonEntityView) ListNode(com.codename1.rad.nodes.ListNode)

Example 2 with ListNode

use of com.codename1.rad.nodes.ListNode 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)

Example 3 with ListNode

use of com.codename1.rad.nodes.ListNode in project CodenameOne by codenameone.

the class RADEntityListAddRemoveInvalidateSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    // An entity for the rows our our list view.
    class Person extends Entity {
    }
    entityTypeBuilder(Person.class).string(Thing.name).factory(cls -> {
        return new Person();
    }).build();
    // A remove row action that will be added to each row
    ActionNode removeRow = UI.action(UI.icon(FontImage.MATERIAL_DELETE));
    // An internal list we will use to store the rows of the entitylist
    ArrayList internalList = new ArrayList();
    EntityList profileList = new EntityList() {

        /**
         * Override createInternalList() so that we can use our own data structure
         * for storing this list.  This is contrived to allow us to test the
         * invalidate() method.
         */
        @Override
        protected List createInternalList() {
            return internalList;
        }
    };
    // A list node to wrap our action and pass it to our view
    ListNode node = new ListNode(// of the list.
    UI.actions(ProfileListView.ACCOUNT_LIST_ROW_ACTIONS, removeRow));
    // A ProfileListView to render the list.
    // See https://shannah.github.io/CodeRAD/javadoc/com/codename1/rad/ui/entityviews/ProfileListView.html
    ProfileListView listView = new ProfileListView(profileList, node, 10);
    listView.setScrollableY(true);
    // Create a controller for the ProfileListView so that we can handle actions fired by the view.
    // Normally we'd do this in the FormController but since this sample doesn't have one
    // we create a ViewController for the ProfileListView directly.
    ViewController controller = new ViewController(null);
    controller.setView(listView);
    // Button to add rows to the list
    Button addRow = new Button(FontImage.MATERIAL_ADD);
    // Button to clear the list
    Button clear = new Button("Clear");
    addRow.addActionListener(evt -> {
        // "Add" button clicked.
        // Create new person and add to the list
        Person p = new Person();
        p.set(Thing.name, "Row " + profileList.size());
        profileList.add(p);
    // This will trigger an EntityAddedEvent which will allow
    // the ProfileListView to synchronize
    });
    clear.addActionListener(evt -> {
        // "Clear" button clicked
        // We could have called profileList.clear()
        // but this would send EntityRemoved events for each row removed
        // which is inefficient.  Instead we'll clear the elements in
        // the internal list directly, and then call invalidate()
        // so that the ProfileListView knows to resynchronize its state.
        internalList.clear();
        profileList.invalidate();
    });
    controller.addActionListener(removeRow, evt -> {
        // The "Remove" button was clicked on a row.
        profileList.remove(evt.getEntity());
    });
    Form hi = new Form("Hi World", new BorderLayout());
    hi.add(NORTH, GridLayout.encloseIn(2, clear, addRow));
    hi.add(CENTER, listView);
    hi.show();
}
Also used : 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) ArrayList(java.util.ArrayList) ListNode(com.codename1.rad.nodes.ListNode) GridLayout(com.codename1.ui.layouts.GridLayout) Display(com.codename1.ui.Display) FontImage(com.codename1.ui.FontImage) Label(com.codename1.ui.Label) Button(com.codename1.ui.Button) CN(com.codename1.ui.CN) ViewController(com.codename1.rad.controllers.ViewController) UI(com.codename1.rad.ui.UI) Entity(com.codename1.rad.models.Entity) 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) List(java.util.List) Dialog(com.codename1.ui.Dialog) Thing(com.codename1.rad.schemas.Thing) Entity(com.codename1.rad.models.Entity) BorderLayout(com.codename1.ui.layouts.BorderLayout) ViewController(com.codename1.rad.controllers.ViewController) Button(com.codename1.ui.Button) Form(com.codename1.ui.Form) ActionNode(com.codename1.rad.nodes.ActionNode) ArrayList(java.util.ArrayList) EntityList(com.codename1.rad.models.EntityList) ProfileListView(com.codename1.rad.ui.entityviews.ProfileListView) ListNode(com.codename1.rad.nodes.ListNode)

Example 4 with ListNode

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

the class FormNode method setAttributes.

public void setAttributes(Attribute... atts) {
    if (sections == null) {
        sections = new Sections();
    }
    // super.setAttributes(atts);
    for (Attribute att : atts) {
        if (att.getClass() == SectionNode.class) {
            sections.add((SectionNode) att);
            ((SectionNode) att).setParent(this);
        } else if (att.getClass() == FieldNode.class) {
            if (globalSection == null) {
                globalSection = new SectionNode();
                globalSection.setParent(this);
            }
            globalSection.setAttributes(att);
        } else if (att instanceof ListNode) {
            rootList = (ListNode) att;
            super.setAttributes(att);
        } else if (att instanceof ViewNode) {
            rootView = (ViewNode) att;
            super.setAttributes(att);
        } else {
            super.setAttributes(att);
        }
    }
}
Also used : Attribute(com.codename1.rad.models.Attribute)

Example 5 with ListNode

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

the class ContactListDecorator method decorate.

@Override
public void decorate(Node node) {
    if (!(node instanceof ListNode)) {
        return;
    }
    ListNode listNode = (ListNode) node;
    Node rowTemplate = listNode.getRowTemplate();
    rowTemplate.setAttributes(UI.param(MultiButtonEntityView.LINE1_UIID, "ContactListLine1"));
    rowTemplate.setAttributes(UI.param(MultiButtonEntityView.LINE2_UIID, "ContactListLine2"));
    for (ActionNode n : rowTemplate.getActions(ActionCategories.LEFT_SWIPE_MENU)) {
        n.setAttributes(UI.actionStyle(ActionStyle.IconOnly));
        n.setAttributes(new UIID("SwipeableContainerButton"));
    }
    ActionNode removeAction = listNode.getAction(ActionCategories.LIST_REMOVE_ACTION);
    if (removeAction != null) {
        removeAction.setAttributes(UI.actionStyle(ActionStyle.IconOnly));
        removeAction.setAttributes(new UIID("SwipeableContainerButton"));
    }
    // swipeLeftNode.setAttributes(LEFT_SWIPE_MENU);
    // listNode.getRowTemplate().setAttributes(swipeLeftNode);
    node.setAttributes(iconRenderer(new FirstCharEntityImageRenderer(10)));
    node.setAttributes(UI.param(MultiButtonEntityView.ICON, Thing.name));
}
Also used : FirstCharEntityImageRenderer(com.codename1.rad.ui.image.FirstCharEntityImageRenderer) ActionNode(com.codename1.rad.nodes.ActionNode) ListNode(com.codename1.rad.nodes.ListNode) Node(com.codename1.rad.nodes.Node) ActionsNode(com.codename1.rad.nodes.ActionsNode) ActionNode(com.codename1.rad.nodes.ActionNode) UIID(com.codename1.rad.attributes.UIID) ListNode(com.codename1.rad.nodes.ListNode)

Aggregations

ListNode (com.codename1.rad.nodes.ListNode)5 ActionNode (com.codename1.rad.nodes.ActionNode)4 EntityList (com.codename1.rad.models.EntityList)3 Log (com.codename1.io.Log)2 NetworkEvent (com.codename1.io.NetworkEvent)2 ViewController (com.codename1.rad.controllers.ViewController)2 Entity (com.codename1.rad.models.Entity)2 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)2 ViewNode (com.codename1.rad.nodes.ViewNode)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 Form (com.codename1.ui.Form)2 Label (com.codename1.ui.Label)2 Toolbar (com.codename1.ui.Toolbar)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2