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