Search in sources :

Example 1 with SelectedCondition

use of com.codename1.rad.attributes.SelectedCondition in project CodeRAD by shannah.

the class DefaultActionViewFactory method update.

public static void update(MultiButton 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);
        String currTextVal = btn.getTextLines();
        if (!Objects.equals(currTextVal.trim(), newTextVal.trim())) {
            btn.setTextLines(newTextVal.trim());
            repaint = true;
        }
    }
    if (!action.isTextStyle() && !"".equals(btn.getTextLines().trim())) {
        btn.setTextLine1("");
        btn.setTextLine2("");
        btn.setTextLine3("");
        btn.setTextLine4("");
        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.isCheckBox()) {
        SelectedCondition selectedCond = action.getSelectedCondition();
        if (selectedCond != null) {
            boolean selected = selectedCond.getValue().test(entity);
            if (selected != btn.isSelected()) {
                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) 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 2 with SelectedCondition

use of com.codename1.rad.attributes.SelectedCondition 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)

Aggregations

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 ActionNode (com.codename1.rad.nodes.ActionNode)2 EnabledCondition (com.codename1.rad.nodes.ActionNode.EnabledCondition)2 Component (com.codename1.ui.Component)2 Container (com.codename1.ui.Container)2 Form (com.codename1.ui.Form)2 CheckBox (com.codename1.ui.CheckBox)1