Search in sources :

Example 21 with EntityList

use of com.codename1.rad.models.EntityList in project CodeRAD by shannah.

the class EntityListView method requiresUpdate.

/**
 * Checks to see if the model has changed since last update, and requires update.
 * Update is required only if rows are added or removed.
 * @return
 */
private boolean requiresUpdate() {
    List<Entity> viewSet = new ArrayList<Entity>();
    EntityList<?> modelSet = getEntity();
    int modelSize = modelSet.size();
    int index = 0;
    for (Component child : wrapper) {
        if (child instanceof EntityView) {
            EntityView rowView = (EntityView) child;
            if (index >= modelSize && modelSet.get(index) != rowView) {
                return true;
            }
            index++;
        }
    }
    return index != modelSize;
}
Also used : Entity(com.codename1.rad.models.Entity) AbstractEntityView(com.codename1.rad.ui.AbstractEntityView) EntityView(com.codename1.rad.ui.EntityView) ArrayList(java.util.ArrayList) Component(com.codename1.ui.Component)

Example 22 with EntityList

use of com.codename1.rad.models.EntityList in project CodeRAD by shannah.

the class EntityListView method update.

@Override
public void update() {
    if (firstUpdate) {
        firstUpdate = false;
    } else {
        return;
    }
    EntityList<?> entityList = getEntity();
    int index = 0;
    for (Entity e : entityList) {
        EntityView rowView = renderer.getListCellRendererComponent(this, e, index, selection.isSelected(index, 0), false);
        wrapper.add((Component) rowView);
        index++;
    }
}
Also used : Entity(com.codename1.rad.models.Entity) AbstractEntityView(com.codename1.rad.ui.AbstractEntityView) EntityView(com.codename1.rad.ui.EntityView)

Example 23 with EntityList

use of com.codename1.rad.models.EntityList 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)

Example 24 with EntityList

use of com.codename1.rad.models.EntityList 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)

Example 25 with EntityList

use of com.codename1.rad.models.EntityList in project CodeRAD by shannah.

the class TabsEntityView method createListTab.

private EntityView createListTab(ListNode ln) {
    PropertySelector selector = ln.createPropertySelector(getEntity());
    if (selector == null) {
        return null;
    }
    EntityList tabEntity = selector.getEntityList(null);
    if (tabEntity == null) {
        return null;
    }
    ln.setAttributesIfNotExists(UI.param(SCROLLABLE_Y, true));
    return new EntityListView(tabEntity, ln);
}
Also used : PropertySelector(com.codename1.rad.models.PropertySelector) EntityList(com.codename1.rad.models.EntityList)

Aggregations

EntityList (com.codename1.rad.models.EntityList)18 Entity (com.codename1.rad.models.Entity)14 Map (java.util.Map)6 Thing (com.codename1.rad.schemas.Thing)5 AbstractTest (com.codename1.testing.AbstractTest)5 Form (com.codename1.ui.Form)5 List (java.util.List)5 Log (com.codename1.io.Log)4 ResultParser (com.codename1.rad.io.ResultParser)4 ActionNode (com.codename1.rad.nodes.ActionNode)4 ProfileListView (com.codename1.rad.ui.entityviews.ProfileListView)4 ArrayList (java.util.ArrayList)4 BaseEntity (com.codename1.rad.models.BaseEntity)3 BaseEntity.entityTypeBuilder (com.codename1.rad.models.BaseEntity.entityTypeBuilder)3 Result (com.codename1.rad.processing.Result)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 ButtonList (com.codename1.components.ButtonList)2 NetworkEvent (com.codename1.io.NetworkEvent)2 ParseException (com.codename1.l10n.ParseException)2 SimpleDateFormat (com.codename1.l10n.SimpleDateFormat)2