Search in sources :

Example 6 with EntityView

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;
}
Also used : WrapperEntityView(com.codename1.rad.ui.entityviews.WrapperEntityView) Container(com.codename1.ui.Container) SwipeContainer(com.codename1.rad.nodes.SwipeContainer) SwipeableContainer(com.codename1.ui.SwipeableContainer) WrapperEntityView(com.codename1.rad.ui.entityviews.WrapperEntityView) MultiButtonEntityView(com.codename1.rad.ui.entityviews.MultiButtonEntityView) ViewNode(com.codename1.rad.nodes.ViewNode) SwipeableContainer(com.codename1.ui.SwipeableContainer) SwipeContainer(com.codename1.rad.nodes.SwipeContainer)

Example 7 with EntityView

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;
}
Also used : Container(com.codename1.ui.Container) EntityView(com.codename1.rad.ui.EntityView) FloatingActionButton(com.codename1.components.FloatingActionButton) Component(com.codename1.ui.Component)

Example 8 with EntityView

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;
}
Also used : Entity(com.codename1.rad.models.Entity) AbstractEntityView(com.codename1.rad.ui.AbstractEntityView) EntityView(com.codename1.rad.ui.EntityView) ArrayList(java.util.ArrayList) Component(com.codename1.ui.Component)

Example 9 with EntityView

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++;
    }
}
Also used : Entity(com.codename1.rad.models.Entity) AbstractEntityView(com.codename1.rad.ui.AbstractEntityView) EntityView(com.codename1.rad.ui.EntityView)

Example 10 with EntityView

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;
}
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

EntityView (com.codename1.rad.ui.EntityView)5 Component (com.codename1.ui.Component)5 Container (com.codename1.ui.Container)5 Entity (com.codename1.rad.models.Entity)4 ActionNode (com.codename1.rad.nodes.ActionNode)4 ViewNode (com.codename1.rad.nodes.ViewNode)4 AbstractEntityView (com.codename1.rad.ui.AbstractEntityView)4 MultiButtonEntityView (com.codename1.rad.ui.entityviews.MultiButtonEntityView)4 ListNode (com.codename1.rad.nodes.ListNode)3 WrapperEntityView (com.codename1.rad.ui.entityviews.WrapperEntityView)3 Badge (com.codename1.rad.attributes.Badge)2 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)2 Condition (com.codename1.rad.attributes.Condition)2 SelectedCondition (com.codename1.rad.attributes.SelectedCondition)2 EntityList (com.codename1.rad.models.EntityList)2 PropertySelector (com.codename1.rad.models.PropertySelector)2 EnabledCondition (com.codename1.rad.nodes.ActionNode.EnabledCondition)2 SwipeContainer (com.codename1.rad.nodes.SwipeContainer)2 Form (com.codename1.ui.Form)2 SwipeableContainer (com.codename1.ui.SwipeableContainer)2