Search in sources :

Example 36 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class DefaultActionViewFactory method update.

public static void update(Button btn, Entity entity, ActionNode action) {
    boolean repaint = false;
    boolean revalidate = false;
    Condition cond = action.getCondition();
    if (cond != null) {
        boolean hidden = !cond.getValue().test(entity);
        if (hidden != btn.isHidden()) {
            btn.setHidden(hidden);
            btn.setVisible(!hidden);
            revalidate = true;
        }
    }
    EnabledCondition enabledCond = action.getEnabledCondition();
    if (enabledCond != null) {
        boolean enabled = enabledCond.getValue().test(entity);
        if (enabled != btn.isEnabled()) {
            btn.setEnabled(enabled);
            repaint = true;
        }
    }
    if (action.getLabel() != null) {
        String currTextVal = btn.getText();
        String newTextVal = action.getLabelText(entity);
        if (!Objects.equals(currTextVal, newTextVal)) {
            btn.setText(newTextVal);
            repaint = true;
        }
    }
    if (!action.isTextStyle() && !"".equals(btn.getText().trim())) {
        btn.setText("");
        repaint = true;
    }
    if (action.getUIID() != null) {
        String currUiid = btn.getUIID();
        String newUiid = action.getUIID(entity, "Button");
        if (!Objects.equals(currUiid, newUiid)) {
            btn.setUIID(newUiid);
            repaint = true;
        }
    }
    if (btn instanceof CheckBox) {
        SelectedCondition selectedCond = action.getSelectedCondition();
        if (selectedCond != null) {
            boolean selected = selectedCond.getValue().test(entity);
            if (selected != btn.isSelected()) {
                ((CheckBox) btn).setSelected(selected);
                repaint = true;
                ActionNode newState = selected ? action.getSelected() : action.getUnselected();
                ActionNode oldState = selected ? action.getUnselected() : action.getSelected();
                if (oldState != newState) {
                    String currText = btn.getText();
                    String newText = newState.getLabelText(entity);
                    if (!newState.isTextStyle()) {
                        newText = "";
                    }
                    if (!Objects.equals(newText, currText)) {
                        btn.setText(newText);
                    }
                }
            }
        }
    }
    Badge badge = action.getBadge();
    if (badge != null) {
        btn.setBadgeText(badge.getValue(entity));
        BadgeUIID badgeUiid = action.getBadgeUIID();
        if (badgeUiid != null) {
            btn.setBadgeUIID(badgeUiid.getValue());
        }
    }
    if (revalidate || repaint) {
        Form f = btn.getComponentForm();
        if (f != null) {
            if (revalidate) {
                Component entityView = findEntityViewParent(btn);
                if (entityView instanceof Container) {
                    ((Container) entityView).revalidateLater();
                } else {
                    entityView.repaint();
                }
            } else {
                btn.repaint();
            }
        }
    }
}
Also used : EnabledCondition(com.codename1.rad.nodes.ActionNode.EnabledCondition) Condition(com.codename1.rad.attributes.Condition) SelectedCondition(com.codename1.rad.attributes.SelectedCondition) SelectedCondition(com.codename1.rad.attributes.SelectedCondition) Container(com.codename1.ui.Container) Form(com.codename1.ui.Form) CheckBox(com.codename1.ui.CheckBox) EnabledCondition(com.codename1.rad.nodes.ActionNode.EnabledCondition) ActionNode(com.codename1.rad.nodes.ActionNode) Badge(com.codename1.rad.attributes.Badge) Component(com.codename1.ui.Component) BadgeUIID(com.codename1.rad.attributes.BadgeUIID)

Example 37 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class DefaultActionViewFactory method initUI.

public static void initUI(Button btn, Entity entity, ActionNode action) {
    btn.setBlockLead(true);
    boolean text = action.isTextStyle();
    boolean includeIcon = action.isIconStyle();
    UIID uiid = action.getUIID();
    if (uiid != null) {
        btn.setUIID(uiid.getValue(entity));
    }
    IconUIID iconUiid = action.getIconUIID();
    if (iconUiid != null) {
        btn.setIconUIID(iconUiid.getValue());
    }
    Button button = btn;
    if (action.getLabel() != null && text) {
        button.setText(action.getLabel().getValue(entity.getEntity()));
    }
    if (!text && button.getText().length() > 0) {
        button.setText("");
    }
    if (action.getImageIcon() != null && includeIcon) {
        button.setIcon(action.getImageIcon().getValue());
        if (action.getSelected() != action && action.getSelected().getImageIcon() != action.getImageIcon()) {
            button.setRolloverIcon(action.getSelected().getImageIcon().getValue());
        }
        if (action.getPressed() != action && action.getPressed().getImageIcon() != action.getImageIcon()) {
            button.setPressedIcon(action.getPressed().getImageIcon().getValue());
        }
        if (action.getDisabled() != action && action.getDisabled().getImageIcon() != action.getImageIcon()) {
            button.setDisabledIcon(action.getDisabled().getImageIcon().getValue());
        }
    }
    if (action.getMaterialIcon() != null && includeIcon) {
        char unselectedIcon = action.getMaterialIcon().getValue();
        char selectedIcon = action.getSelected().getMaterialIcon().getValue();
        char pressedIcon = action.getPressed().getMaterialIcon().getValue();
        char selectedPressed = pressedIcon;
        if (action.getPressed() == action) {
            selectedPressed = selectedIcon;
        }
        char disabledIcon = action.getDisabled().getMaterialIcon().getValue();
        // button.setMaterialIcon(action.getMaterialIcon().getValue());
        FontImage.setMaterialIcon(btn, new char[] { unselectedIcon, selectedIcon, pressedIcon, selectedPressed, disabledIcon }, -1);
    }
    if (action.getTextIcon() != null && includeIcon) {
        String iconText = action.getTextIcon().getValue(entity);
        Button iconLabel = new Button(iconText);
        if (btn.getIconStyleComponent() != btn) {
            iconLabel.setUIID(btn.getIconStyleComponent().getUIID());
        } else {
            iconLabel.setUIID(btn.getUIID());
            // IF the button has a border and padding set, we don't
            // want to to also be applied to the icon.
            iconLabel.getAllStyles().stripMarginAndPadding();
        }
        iconLabel.setWidth(iconLabel.getPreferredW());
        iconLabel.setHeight(iconLabel.getPreferredH());
        btn.setIcon(new ComponentImage(iconLabel, iconLabel.getWidth(), iconLabel.getHeight()));
    }
    if (includeIcon && text) {
        ActionStyle style = action.getActionStyle();
        if (style != null) {
            switch(style) {
                case IconTop:
                    button.setTextPosition(BOTTOM);
                    break;
                case IconBottom:
                    button.setTextPosition(TOP);
                    break;
                case IconLeft:
                    button.setTextPosition(RIGHT);
                    break;
                case IconRight:
                    button.setTextPosition(LEFT);
            }
        }
    }
    button.addActionListener(evt -> {
        action.fireEvent(entity, button);
        update(button, entity, action);
    });
    update(button, entity, action);
    action.decorateComponent(btn);
}
Also used : ComponentImage(ca.weblite.shared.components.ComponentImage) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) IconUIID(com.codename1.rad.attributes.IconUIID) IconUIID(com.codename1.rad.attributes.IconUIID) BadgeUIID(com.codename1.rad.attributes.BadgeUIID) UIID(com.codename1.rad.attributes.UIID)

Example 38 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class DefaultActionViewFactory method initUI.

public static void initUI(MultiButton btn, Entity entity, ActionNode action) {
    btn.setBlockLead(true);
    boolean text = action.isTextStyle();
    boolean includeIcon = action.isIconStyle();
    UIID uiid = action.getUIID();
    if (uiid != null) {
        btn.setUIID(uiid.getValue(entity));
    }
    IconUIID iconUiid = action.getIconUIID();
    if (iconUiid != null) {
        btn.setIconUIID(iconUiid.getValue());
    }
    MultiButton button = btn;
    if (action.getLabel() != null && text) {
        button.setTextLines(action.getLabel().getValue(entity.getEntity()));
    }
    if (action.getImageIcon() != null && includeIcon) {
        button.setIcon(action.getImageIcon().getValue());
        if (action.getSelected() != action && action.getSelected().getImageIcon() != action.getImageIcon()) {
            button.setRolloverIcon(action.getSelected().getImageIcon().getValue());
        }
        if (action.getPressed() != action && action.getPressed().getImageIcon() != action.getImageIcon()) {
            button.setPressedIcon(action.getPressed().getImageIcon().getValue());
        }
        if (action.getDisabled() != action && action.getDisabled().getImageIcon() != action.getImageIcon()) {
            button.setDisabledIcon(action.getDisabled().getImageIcon().getValue());
        }
    }
    if (action.getMaterialIcon() != null && includeIcon) {
        char unselectedIcon = action.getMaterialIcon().getValue();
        char selectedIcon = action.getSelected().getMaterialIcon().getValue();
        char pressedIcon = action.getPressed().getMaterialIcon().getValue();
        char selectedPressed = pressedIcon;
        if (action.getPressed() == action) {
            selectedPressed = selectedIcon;
        }
        char disabledIcon = action.getDisabled().getMaterialIcon().getValue();
        // button.setMaterialIcon(action.getMaterialIcon().getValue());
        FontImage.setMaterialIcon(btn, new char[] { unselectedIcon, selectedIcon, pressedIcon, selectedPressed, disabledIcon }, -1);
    }
    if (action.getTextIcon() != null && includeIcon) {
        String iconText = action.getTextIcon().getValue(entity);
        Button iconLabel = new Button(iconText);
        if (btn.getIconStyleComponent() != btn) {
            iconLabel.setUIID(btn.getIconStyleComponent().getUIID());
        } else {
            iconLabel.setUIID(btn.getUIID());
            // IF the button has a border and padding set, we don't
            // want to to also be applied to the icon.
            iconLabel.getAllStyles().stripMarginAndPadding();
        }
        iconLabel.setWidth(iconLabel.getPreferredW());
        iconLabel.setHeight(iconLabel.getPreferredH());
        btn.setIcon(new ComponentImage(iconLabel, iconLabel.getWidth(), iconLabel.getHeight()));
    }
    if (includeIcon && text) {
        ActionStyle style = action.getActionStyle();
        if (style != null) {
            switch(style) {
                case IconTop:
                    button.setTextPosition(BOTTOM);
                    break;
                case IconBottom:
                    button.setTextPosition(TOP);
                    break;
                case IconLeft:
                    button.setTextPosition(RIGHT);
                    break;
                case IconRight:
                    button.setTextPosition(LEFT);
            }
        }
    }
    if (!text) {
        button.setText("");
    }
    button.addActionListener(evt -> {
        action.fireEvent(entity, button);
        update(button, entity, action);
    });
    update(button, entity, action);
    action.decorateComponent(btn);
}
Also used : ComponentImage(ca.weblite.shared.components.ComponentImage) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) IconUIID(com.codename1.rad.attributes.IconUIID) IconUIID(com.codename1.rad.attributes.IconUIID) BadgeUIID(com.codename1.rad.attributes.BadgeUIID) UIID(com.codename1.rad.attributes.UIID) MultiButton(com.codename1.components.MultiButton)

Example 39 with Entity

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

Example 40 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class DefaultEntityViewFactory method createView.

@Override
public EntityView createView(Entity entity, ViewNode node) {
    ViewType type = (ViewType) node.findAttribute(ViewType.class);
    if (type == null) {
        type = ViewType.MULTIBUTTON;
    }
    EntityViewFactory f = registry.get(type);
    if (f == null) {
        throw new IllegalArgumentException("Factory doesn't know how to build view " + type);
    }
    EntityView out = f.createView(entity, node);
    return makeSwipeable(entity, node, (Component) out);
}
Also used : WrapperEntityView(com.codename1.rad.ui.entityviews.WrapperEntityView) MultiButtonEntityView(com.codename1.rad.ui.entityviews.MultiButtonEntityView) ViewType(com.codename1.rad.attributes.ViewType)

Aggregations

Entity (com.codename1.rad.models.Entity)38 Property (com.codename1.rad.models.Property)15 EntityList (com.codename1.rad.models.EntityList)13 Container (com.codename1.ui.Container)12 BorderLayout (com.codename1.ui.layouts.BorderLayout)11 ActionNode (com.codename1.rad.nodes.ActionNode)10 FieldNode (com.codename1.rad.nodes.FieldNode)10 Form (com.codename1.ui.Form)8 ViewNode (com.codename1.rad.nodes.ViewNode)7 GridLayout (com.codename1.ui.layouts.GridLayout)7 SimpleDateFormat (com.codename1.l10n.SimpleDateFormat)6 ResultParser (com.codename1.rad.io.ResultParser)6 Component (com.codename1.ui.Component)6 Element (com.codename1.xml.Element)6 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)5 Thing (com.codename1.rad.schemas.Thing)5 Button (com.codename1.ui.Button)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 Map (java.util.Map)5 Log (com.codename1.io.Log)4