Search in sources :

Example 41 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class UIFragment method parseXML.

/**
 * Parses XML string into a Template
 * @param xml XML string describing a UI.
 * @return The corresponding template, or a RuntimeException if parsing failed.
 */
public static UIFragment parseXML(String xml) {
    try {
        XMLParser p = new XMLParser();
        p.setCaseSensitive(true);
        Element el = p.parse(new CharArrayReader(xml.toCharArray()));
        return new UIFragment(el);
    } catch (Exception ex) {
        Log.e(ex);
        throw new RuntimeException(ex.getMessage());
    }
}
Also used : CharArrayReader(com.codename1.io.CharArrayReader) Element(com.codename1.xml.Element) XMLParser(com.codename1.xml.XMLParser) IOException(java.io.IOException)

Example 42 with UI

use of com.codename1.rad.ui.UI 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 43 with UI

use of com.codename1.rad.ui.UI 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)

Aggregations

Component (com.codename1.ui.Component)10 Label (com.codename1.ui.Label)9 ArrayList (java.util.ArrayList)9 Container (com.codename1.ui.Container)8 Form (com.codename1.ui.Form)8 IOException (java.io.IOException)8 TextArea (com.codename1.ui.TextArea)6 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 HashMap (java.util.HashMap)6 Vector (java.util.Vector)6 Entity (com.codename1.rad.models.Entity)5 Hashtable (java.util.Hashtable)5 EntityList (com.codename1.rad.models.EntityList)4 ActionNode (com.codename1.rad.nodes.ActionNode)4 EncodedImage (com.codename1.ui.EncodedImage)4 FontImage (com.codename1.ui.FontImage)4 Border (com.codename1.ui.plaf.Border)4 Log (com.codename1.io.Log)3 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)3 Thing (com.codename1.rad.schemas.Thing)3