use of com.codename1.rad.nodes.ActionNode in project CodeRAD by shannah.
the class DefaultEntityListCellRenderer method makeSwipeable.
private EntityView makeSwipeable(Entity entity, ViewNode node, Component view) {
// Check for swipeable container
SwipeContainer swipe = (SwipeContainer) node.findAttribute(SwipeContainer.class);
if (swipe != null) {
EntityView leftCnt = null;
EntityView rightCnt = null;
ViewNode leftNode = swipe.getLeft();
if (leftNode != null) {
leftCnt = leftNode.createView(entity);
}
ViewNode rightNode = swipe.getRight();
if (rightNode != null) {
rightCnt = rightNode.createView(entity);
}
SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
return new WrapperEntityView(swipeWrapper, entity, node);
}
ActionNode deleteAction = node.getInheritedAction(ActionCategories.LIST_REMOVE_ACTION);
Actions leftSwipeActions = node.getActions(ActionCategories.LEFT_SWIPE_MENU);
if (deleteAction != null) {
leftSwipeActions.add(deleteAction);
}
Actions rightSwipeActions = node.getActions(ActionCategories.RIGHT_SWIPE_MENU);
if (!leftSwipeActions.isEmpty() || !rightSwipeActions.isEmpty()) {
Container leftCnt = null;
Container rightCnt = null;
if (!leftSwipeActions.isEmpty()) {
leftCnt = new Container(new GridLayout(leftSwipeActions.size()));
for (ActionNode action : leftSwipeActions) {
leftCnt.add(action.getViewFactory().createActionView(entity, action));
}
}
if (!rightSwipeActions.isEmpty()) {
rightCnt = new Container(new GridLayout(rightSwipeActions.size()));
for (ActionNode action : rightSwipeActions) {
rightCnt.add(action.getViewFactory().createActionView(entity, action));
}
}
SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
return new WrapperEntityView(swipeWrapper, entity, node);
} else {
// System.out.println("Swipe actions not present");
}
return (EntityView) view;
}
use of com.codename1.rad.nodes.ActionNode in project CodeRAD by shannah.
the class EntityListViewBuilder method provider.
public EntityListViewBuilder provider(@Inject EntityListProvider provider) {
ActionNode refreshAction = UI.action();
ActionNode loadMoreAction = UI.action();
getContext().getController().addActionListener(refreshAction, provider);
getContext().getController().addActionListener(loadMoreAction, provider);
builder.refreshAction(refreshAction).loadMoreAction(loadMoreAction);
return this;
}
use of com.codename1.rad.nodes.ActionNode in project CodeRAD by shannah.
the class EntityListViewBuilder method provider.
public EntityListViewBuilder provider(Class cls) {
ActionNode refreshAction = UI.action();
ActionNode loadMoreAction = UI.action();
ActionListener<ActionNode.ActionNodeEvent> l = evt -> {
with(getContext().getController().lookup(cls), EntityListProvider.class, provider -> {
provider.actionPerformed(evt);
});
};
getContext().getController().addActionListener(loadMoreAction, l);
getContext().getController().addActionListener(refreshAction, l);
builder.refreshAction(refreshAction).loadMoreAction(loadMoreAction);
return this;
}
use of com.codename1.rad.nodes.ActionNode in project CodeRAD by shannah.
the class ContactListDecorator method decorate.
@Override
public void decorate(Node node) {
if (!(node instanceof ListNode)) {
return;
}
ListNode listNode = (ListNode) node;
Node rowTemplate = listNode.getRowTemplate();
rowTemplate.setAttributes(UI.param(MultiButtonEntityView.LINE1_UIID, "ContactListLine1"));
rowTemplate.setAttributes(UI.param(MultiButtonEntityView.LINE2_UIID, "ContactListLine2"));
for (ActionNode n : rowTemplate.getActions(ActionCategories.LEFT_SWIPE_MENU)) {
n.setAttributes(UI.actionStyle(ActionStyle.IconOnly));
n.setAttributes(new UIID("SwipeableContainerButton"));
}
ActionNode removeAction = listNode.getAction(ActionCategories.LIST_REMOVE_ACTION);
if (removeAction != null) {
removeAction.setAttributes(UI.actionStyle(ActionStyle.IconOnly));
removeAction.setAttributes(new UIID("SwipeableContainerButton"));
}
// swipeLeftNode.setAttributes(LEFT_SWIPE_MENU);
// listNode.getRowTemplate().setAttributes(swipeLeftNode);
node.setAttributes(iconRenderer(new FirstCharEntityImageRenderer(10)));
node.setAttributes(UI.param(MultiButtonEntityView.ICON, Thing.name));
}
use of com.codename1.rad.nodes.ActionNode 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());
}
});
}
}
}
}
Aggregations