Search in sources :

Example 66 with Entity

use of com.codename1.rad.models.Entity 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 67 with Entity

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

the class EntityListView method handleEntityAdded.

/**
 * Handles when entities are added
 * @param evt The event
 * @param commit Whether to animate/revalidate UI right now.
 * @return
 */
private Component handleEntityAdded(EntityList.EntityAddedEvent evt, boolean commit) {
    EntityList.EntityAddedEvent eae = (EntityList.EntityAddedEvent) evt;
    Entity e = eae.getEntity();
    int index = evt.getIndex();
    EntityView rowView = renderer.getListCellRendererComponent(this, e, index, selection.isSelected(index, 0), false);
    Component cmp = (Component) rowView;
    if (index >= 0 && index < wrapper.getComponentCount()) {
        wrapper.addComponent(index, cmp);
    } else {
        wrapper.add(cmp);
    }
    if (getComponentForm() != null) {
        if (animateInsertions) {
            cmp.setX(0);
            cmp.setY(wrapper.getHeight() + wrapper.getScrollY());
            cmp.setWidth(getWidth());
            cmp.setHeight(cmp.getPreferredH());
            if (commit) {
                ComponentAnimation anim = wrapper.createAnimateHierarchy(300);
                anim.addOnCompleteCall(() -> {
                    wrapper.scrollComponentToVisible(cmp);
                });
                getComponentForm().getAnimationManager().addAnimation(anim);
            }
        } else {
            if (commit) {
                getComponentForm().revalidateLater();
            }
        }
    }
    return cmp;
}
Also used : Entity(com.codename1.rad.models.Entity) ComponentAnimation(com.codename1.ui.animations.ComponentAnimation) AbstractEntityView(com.codename1.rad.ui.AbstractEntityView) EntityView(com.codename1.rad.ui.EntityView) EntityList(com.codename1.rad.models.EntityList) Component(com.codename1.ui.Component)

Example 68 with Entity

use of com.codename1.rad.models.Entity 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 69 with Entity

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

the class ImageContainer method createToFileSystem.

public static ImageContainer createToFileSystem(Entity entity, Property property, String filePath) {
    ImageContainer out = new ImageContainer();
    out.filePath = filePath;
    out.useFileSystem = true;
    out.property = new PropertySelector(entity, property);
    return out;
}
Also used : PropertySelector(com.codename1.rad.models.PropertySelector)

Example 70 with Entity

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

the class ImageContainer method createToStorage.

public static ImageContainer createToStorage(Entity entity, Property property, String storageFile) {
    ImageContainer out = new ImageContainer();
    out.storageFile = storageFile;
    out.useStorage = true;
    out.property = new PropertySelector(entity, property);
    return out;
}
Also used : PropertySelector(com.codename1.rad.models.PropertySelector)

Aggregations

Entity (com.codename1.rad.models.Entity)38 Property (com.codename1.rad.models.Property)15 EntityList (com.codename1.rad.models.EntityList)13 Container (com.codename1.ui.Container)12 BorderLayout (com.codename1.ui.layouts.BorderLayout)11 ActionNode (com.codename1.rad.nodes.ActionNode)10 FieldNode (com.codename1.rad.nodes.FieldNode)10 Form (com.codename1.ui.Form)8 ViewNode (com.codename1.rad.nodes.ViewNode)7 GridLayout (com.codename1.ui.layouts.GridLayout)7 SimpleDateFormat (com.codename1.l10n.SimpleDateFormat)6 ResultParser (com.codename1.rad.io.ResultParser)6 Component (com.codename1.ui.Component)6 Element (com.codename1.xml.Element)6 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)5 Thing (com.codename1.rad.schemas.Thing)5 Button (com.codename1.ui.Button)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 Map (java.util.Map)5 Log (com.codename1.io.Log)4