Search in sources :

Example 16 with ActionNode

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

the class DefaultEntityListCellRenderer method makeSwipeable.

private EntityView makeSwipeable(Entity entity, ViewNode node, Component view) {
    // Check for swipeable container
    SwipeContainer swipe = (SwipeContainer) node.findAttribute(SwipeContainer.class);
    if (swipe != null) {
        EntityView leftCnt = null;
        EntityView rightCnt = null;
        ViewNode leftNode = swipe.getLeft();
        if (leftNode != null) {
            leftCnt = leftNode.createView(entity);
        }
        ViewNode rightNode = swipe.getRight();
        if (rightNode != null) {
            rightCnt = rightNode.createView(entity);
        }
        SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
        return new WrapperEntityView(swipeWrapper, entity, node);
    }
    ActionNode deleteAction = node.getInheritedAction(ActionCategories.LIST_REMOVE_ACTION);
    Actions leftSwipeActions = node.getActions(ActionCategories.LEFT_SWIPE_MENU);
    if (deleteAction != null) {
        leftSwipeActions.add(deleteAction);
    }
    Actions rightSwipeActions = node.getActions(ActionCategories.RIGHT_SWIPE_MENU);
    if (!leftSwipeActions.isEmpty() || !rightSwipeActions.isEmpty()) {
        Container leftCnt = null;
        Container rightCnt = null;
        if (!leftSwipeActions.isEmpty()) {
            leftCnt = new Container(new GridLayout(leftSwipeActions.size()));
            for (ActionNode action : leftSwipeActions) {
                leftCnt.add(action.getViewFactory().createActionView(entity, action));
            }
        }
        if (!rightSwipeActions.isEmpty()) {
            rightCnt = new Container(new GridLayout(rightSwipeActions.size()));
            for (ActionNode action : rightSwipeActions) {
                rightCnt.add(action.getViewFactory().createActionView(entity, action));
            }
        }
        SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
        return new WrapperEntityView(swipeWrapper, entity, node);
    } else {
    // System.out.println("Swipe actions not present");
    }
    return (EntityView) view;
}
Also used : WrapperEntityView(com.codename1.rad.ui.entityviews.WrapperEntityView) SwipeContainer(com.codename1.rad.nodes.SwipeContainer) SwipeableContainer(com.codename1.ui.SwipeableContainer) Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) WrapperEntityView(com.codename1.rad.ui.entityviews.WrapperEntityView) MultiButtonEntityView(com.codename1.rad.ui.entityviews.MultiButtonEntityView) ActionNode(com.codename1.rad.nodes.ActionNode) ViewNode(com.codename1.rad.nodes.ViewNode) SwipeableContainer(com.codename1.ui.SwipeableContainer) SwipeContainer(com.codename1.rad.nodes.SwipeContainer)

Example 17 with ActionNode

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

the class EntityListViewBuilder method provider.

public EntityListViewBuilder provider(@Inject EntityListProvider provider) {
    ActionNode refreshAction = UI.action();
    ActionNode loadMoreAction = UI.action();
    getContext().getController().addActionListener(refreshAction, provider);
    getContext().getController().addActionListener(loadMoreAction, provider);
    builder.refreshAction(refreshAction).loadMoreAction(loadMoreAction);
    return this;
}
Also used : ActionNode(com.codename1.rad.nodes.ActionNode)

Example 18 with ActionNode

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

the class EntityListViewBuilder method provider.

public EntityListViewBuilder provider(Class cls) {
    ActionNode refreshAction = UI.action();
    ActionNode loadMoreAction = UI.action();
    ActionListener<ActionNode.ActionNodeEvent> l = evt -> {
        with(getContext().getController().lookup(cls), EntityListProvider.class, provider -> {
            provider.actionPerformed(evt);
        });
    };
    getContext().getController().addActionListener(loadMoreAction, l);
    getContext().getController().addActionListener(refreshAction, l);
    builder.refreshAction(refreshAction).loadMoreAction(loadMoreAction);
    return this;
}
Also used : Inject(com.codename1.rad.annotations.Inject) EntityList(com.codename1.rad.models.EntityList) ActionNode(com.codename1.rad.nodes.ActionNode) ActionListener(com.codename1.ui.events.ActionListener) ControllerEvent(com.codename1.rad.controllers.ControllerEvent) com.codename1.rad.ui(com.codename1.rad.ui) RAD(com.codename1.rad.annotations.RAD) NonNull.with(com.codename1.rad.util.NonNull.with) ListNode(com.codename1.rad.nodes.ListNode) EntityListProvider(com.codename1.rad.models.EntityListProvider) Node(com.codename1.rad.nodes.Node) Map(java.util.Map) EntityListView(com.codename1.rad.ui.entityviews.EntityListView) ActionNode(com.codename1.rad.nodes.ActionNode) EntityListProvider(com.codename1.rad.models.EntityListProvider)

Example 19 with ActionNode

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

Example 20 with ActionNode

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

the class EntityListView method loadMore.

public void loadMore() {
    Entity requestData = null;
    ActionNode refreshAction = getViewNode().getAction(ActionCategories.LIST_REFRESH_ACTION);
    ActionNode loadMoreAction = getViewNode().getAction(ActionCategories.LIST_LOAD_MORE_ACTION);
    if (loadMoreAction != null) {
        Map extraData = new HashMap();
        if (nextProviderRequest != null) {
            EventContext.addExtra(extraData, nextProviderRequest);
        }
        EventContext.addExtra(extraData, EntityListProvider.RequestType.LOAD_MORE);
        ControllerEvent evt = ActionSupport.as(loadMoreAction.fireEvent(getEntity(), this, extraData), ControllerEvent.class);
        if (evt != null && evt.isConsumed()) {
            EntityListProvider.Request req = evt.getAsyncResource(EntityListProvider.Request.class);
            nextProviderRequest = null;
            if (req != null) {
                req.onResult((res, err) -> {
                    if (err != null) {
                        // We just swallow errors.
                        // The provider can return an error to indicate that it's done but no data.
                        // But it is up to the provider to propagate errors up the UI or log if necessary.
                        InfiniteScrollAdapter.addMoreComponents(wrapper, new Component[0], req.hasMore());
                        return;
                    }
                    nextProviderRequest = req.getNextRequest();
                    EntityList modelSet = getEntity();
                    if (res.size() > 0) {
                        modelSet.startTransaction();
                        for (Entity en : (Iterable<Entity>) res) {
                            modelSet.add(en);
                        }
                        boolean localAnimateInsertions = animateInsertions;
                        animateInsertions = false;
                        boolean localAnimateRemovals = animateRemovals;
                        animateRemovals = false;
                        modelSet.commitTransaction();
                        animateInsertions = localAnimateInsertions;
                        animateRemovals = localAnimateRemovals;
                        InfiniteScrollAdapter.addMoreComponents(wrapper, new Component[0], req.hasMore());
                        Form f = getComponentForm();
                        if (f != null) {
                            getComponentForm().revalidateWithAnimationSafety();
                        }
                    } else {
                        InfiniteScrollAdapter.addMoreComponents(wrapper, new Component[0], req.hasMore());
                    }
                });
            }
        }
    }
}
Also used : Entity(com.codename1.rad.models.Entity) HashMap(java.util.HashMap) Form(com.codename1.ui.Form) ActionNode(com.codename1.rad.nodes.ActionNode) EntityList(com.codename1.rad.models.EntityList) HashMap(java.util.HashMap) Map(java.util.Map) EntityListProvider(com.codename1.rad.models.EntityListProvider) ControllerEvent(com.codename1.rad.controllers.ControllerEvent)

Aggregations

ActionNode (com.codename1.rad.nodes.ActionNode)16 Form (com.codename1.ui.Form)6 EntityList (com.codename1.rad.models.EntityList)5 ListNode (com.codename1.rad.nodes.ListNode)5 Container (com.codename1.ui.Container)5 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)4 UIID (com.codename1.rad.attributes.UIID)4 Entity (com.codename1.rad.models.Entity)4 Button (com.codename1.ui.Button)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 GridLayout (com.codename1.ui.layouts.GridLayout)4 ControllerEvent (com.codename1.rad.controllers.ControllerEvent)3 EntityListProvider (com.codename1.rad.models.EntityListProvider)3 BoxLayout (com.codename1.ui.layouts.BoxLayout)3 Map (java.util.Map)3 ComponentImage (ca.weblite.shared.components.ComponentImage)2 MultiButton (com.codename1.components.MultiButton)2 Log (com.codename1.io.Log)2 NetworkEvent (com.codename1.io.NetworkEvent)2 IconUIID (com.codename1.rad.attributes.IconUIID)2