Search in sources :

Example 21 with ActionNode

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

the class EntityListView method refresh.

public void refresh() {
    ActionNode refreshAction = getViewNode().getAction(ActionCategories.LIST_REFRESH_ACTION);
    ActionNode loadMoreAction = getViewNode().getAction(ActionCategories.LIST_LOAD_MORE_ACTION);
    Entity requestData = null;
    if (refreshAction != null) {
        Map extraData = new HashMap();
        EventContext.addExtra(extraData, EntityListProvider.RequestType.REFRESH);
        ControllerEvent evt = ActionSupport.as(refreshAction.fireEvent(getEntity(), this, extraData), ControllerEvent.class);
        if (evt != null && evt.isConsumed()) {
            EntityListProvider.Request request = evt.getAsyncResource(EntityListProvider.Request.class);
            if (request != null) {
                // The provider is fulfilling the request asynchronously.
                request.onResult((res, err) -> {
                    if (err != null) {
                        return;
                    }
                    nextProviderRequest = request.getNextRequest();
                    EntityList modelList = getEntity();
                    modelList.startTransaction();
                    modelList.clear();
                    for (Object o : res) {
                        modelList.add((Entity) o);
                    }
                    boolean localAnimateInsertions = animateInsertions;
                    animateInsertions = false;
                    boolean localAnimateRemovals = animateRemovals;
                    animateRemovals = false;
                    modelList.commitTransaction();
                    animateInsertions = localAnimateInsertions;
                    animateRemovals = localAnimateRemovals;
                    if (loadMoreAction != null) {
                        InfiniteScrollAdapter.addMoreComponents(wrapper, new Component[0], request.hasMore());
                    }
                    Form f = getComponentForm();
                    if (f != null) {
                        getComponentForm().revalidateWithAnimationSafety();
                    }
                });
            }
        }
    }
}
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