use of com.codename1.rad.ui.EntityView in project CodeRAD by shannah.
the class DefaultEntityViewFactory 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, this);
}
ViewNode rightNode = swipe.getRight();
if (rightNode != null) {
rightCnt = rightNode.createView(entity, this);
}
SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
return new WrapperEntityView(swipeWrapper, entity, node);
}
Actions leftSwipeActions = node.getActions(ActionCategories.LEFT_SWIPE_MENU);
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(BoxLayout.y());
NodeUtilFunctions.buildActionsBar(node, leftCnt, entity, null, leftSwipeActions, null);
}
if (!rightSwipeActions.isEmpty()) {
rightCnt = new Container(BoxLayout.y());
NodeUtilFunctions.buildActionsBar(node, leftCnt, entity, rightSwipeActions, null, null);
}
SwipeableContainer swipeWrapper = new SwipeableContainer((Component) leftCnt, (Component) rightCnt, view);
return new WrapperEntityView(swipeWrapper, entity, node);
}
return (EntityView) view;
}
use of com.codename1.rad.ui.EntityView in project CodeRAD by shannah.
the class FloatingActionButtonBuilder method build.
@Override
public FloatingActionButton build() {
if (icon == 0)
icon = FontImage.MATERIAL_ADD;
FloatingActionButton out;
if (uiid == null) {
out = FloatingActionButton.createFAB(icon);
} else {
out = FloatingActionButton.createFAB(icon, uiid);
}
// We don't want the fab added to the direct parent.
doNotAddToParentContainer(out);
EntityView ev = getContext().getEntityView();
if (ev != null) {
// Register a decorator that will be executed when the ViewController calls setView()
// This is when we will wrap the target element
getContext().getController().addViewDecorator(cmp -> {
if (done)
return cmp;
done = true;
Component parentContainer = getParentContainer();
if (target != null) {
Component targetComponent = $(target, (Container) getContext().getEntityView()).asComponent();
if (targetComponent != null) {
parentContainer = targetComponent;
}
}
// TODO: We have problems here due to new structure of a Root ViewController
Container parentParent = parentContainer.getParent();
if (parentParent != null) {
Container dummy = new Container();
parentParent.replace(parentContainer, dummy, null);
Container wrapped = out.bindFabToContainer(parentContainer);
parentParent.replace(dummy, wrapped, null);
} else {
Container bound = out.bindFabToContainer(parentContainer);
if (parentContainer == cmp) {
return bound;
}
}
return cmp;
});
}
return out;
}
use of com.codename1.rad.ui.EntityView 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.ui.EntityView 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.ui.EntityView 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