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());
}
}
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());
}
});
}
}
}
}
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;
}
Aggregations