Search in sources :

Example 1 with ActionNode

use of com.codename1.rad.nodes.ActionNode in project CodeRAD by shannah.

the class NodeUtilFunctions method buildActionsBar.

static void buildActionsBar(Node node, Container target, Entity entity, Actions right, Actions left, Actions overflow, Actions middle) {
    Container actionsBar = new Container(new BorderLayout());
    Container actionsBarRight = new Container(new BorderLayout());
    if (middle != null && middle.size() > 0) {
        GridLayout layout = new GridLayout(middle.size());
        Container cnt = new Container(layout);
        middle.addToContainer(cnt, entity);
        actionsBar.add(BorderLayout.CENTER, cnt);
    }
    if (left != null) {
        Container cnt = new Container(BoxLayout.x());
        for (ActionNode action : left) {
            cnt.add(action.getViewFactory().createActionView(entity, action));
        }
        if (actionsBar.getComponentCount() > 0) {
            actionsBar.add(BorderLayout.WEST, cnt);
        } else {
            actionsBar.add(BorderLayout.CENTER, cnt);
        }
    }
    if (right != null) {
        Container cnt = new Container(BoxLayout.x());
        $(cnt).setAlignment(RIGHT);
        for (ActionNode action : right) {
            // System.out.println("right node "+action);
            cnt.add(action.getViewFactory().createActionView(entity, action));
        }
        // System.out.println("Adding to right "+cnt);
        actionsBarRight.add(BorderLayout.CENTER, cnt);
    }
    if (overflow != null && !overflow.isEmpty()) {
        PopupMenu popup = new PopupMenu();
        for (ActionNode action : overflow) {
            Property.Label label = action.getLabel();
            String labelStr = label != null ? label.getValue() : "";
            Command cmd = new Command(labelStr) {

                @Override
                public void actionPerformed(ActionEvent evt) {
                    action.fireEvent(entity, target);
                }
            };
            if (action.getImageIcon() != null) {
                cmd.setIcon(action.getImageIcon().getValue());
            } else if (action.getMaterialIcon() != null) {
                cmd.setMaterialIcon(action.getMaterialIcon().getValue());
            }
            popup.addCommand(cmd);
        }
        actionsBarRight.add(BorderLayout.EAST, new Button(popup.getCommand()));
    }
    if (actionsBarRight.getComponentCount() > 0) {
        actionsBar.add(BorderLayout.EAST, actionsBarRight);
    }
    if (actionsBar.getComponentCount() > 0) {
        target.add(actionsBar);
    }
}
Also used : Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) Command(com.codename1.ui.Command) Button(com.codename1.ui.Button) ActionEvent(com.codename1.ui.events.ActionEvent) ActionNode(com.codename1.rad.nodes.ActionNode) Property(com.codename1.rad.models.Property) PopupMenu(ca.weblite.shared.components.PopupMenu)

Example 2 with ActionNode

use of com.codename1.rad.nodes.ActionNode in project CodeRAD by shannah.

the class Actions method addToContainer.

public void addToContainer(Container cnt, Entity entity, ComponentSelector.ComponentMapper wrapper) {
    boolean requiresFlowLayoutWrapperForBadge = (cnt.getLayout() instanceof GridLayout || cnt.getLayout() instanceof BorderLayout || cnt.getLayout() instanceof BoxLayout);
    for (ActionNode n : this) {
        if (requiresFlowLayoutWrapperForBadge && n.getBadge() != null) {
            // If there is a badge, we'll wrap it in a flowlayout
            Container fl = FlowLayout.encloseCenter(n.createView(entity));
            fl.getStyle().stripMarginAndPadding();
            if (wrapper == null) {
                cnt.addComponent(fl);
            } else {
                cnt.addComponent(wrapper.map(fl));
            }
        } else {
            if (wrapper == null) {
                cnt.addComponent(n.createView(entity));
            } else {
                cnt.addComponent(wrapper.map(n.createView(entity)));
            }
        }
    }
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) BoxLayout(com.codename1.ui.layouts.BoxLayout) ActionNode(com.codename1.rad.nodes.ActionNode)

Example 3 with ActionNode

use of com.codename1.rad.nodes.ActionNode 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 4 with ActionNode

use of com.codename1.rad.nodes.ActionNode in project CodeRAD by shannah.

the class DefaultEntityListCellRenderer method getListCellRendererComponent.

@Override
public EntityView getListCellRendererComponent(EntityListView list, Entity value, int index, boolean isSelected, boolean isFocused) {
    ListNode listNode = (ListNode) list.getViewNode();
    MultiButtonEntityView out = new MultiButtonEntityView(value, listNode.getRowTemplate());
    ActionNode node = listNode.getAction(ActionCategories.LIST_SELECT_ACTION);
    if (node != null) {
        out.setAction(node);
    }
    return makeSwipeable(value, listNode.getRowTemplate(), out);
}
Also used : ActionNode(com.codename1.rad.nodes.ActionNode) MultiButtonEntityView(com.codename1.rad.ui.entityviews.MultiButtonEntityView) ListNode(com.codename1.rad.nodes.ListNode)

Example 5 with ActionNode

use of com.codename1.rad.nodes.ActionNode in project CodeRAD by shannah.

the class Buttons method rebuild.

private void rebuild() {
    built = true;
    requiresRefresh = false;
    removeAll();
    this.actionCategory = actionCategory;
    Actions actions = getViewNode().getInheritedActions(this.actionCategory);
    Actions overflowActions = null;
    actions = actions.proxy(getViewNode());
    if (limit >= 0 && actions.size() >= limit) {
        // Note: >= because need to fit overflow button under limit
        overflowActions = new Actions();
        Actions tempActions = new Actions();
        int len = actions.size();
        int index = -1;
        UIID uiid = null;
        for (ActionNode action : actions) {
            index++;
            if (index < limit - (overflowMenuStyle == OverflowMenuStyle.None ? 0 : 1)) {
                tempActions.add(action);
            } else {
                overflowActions.add(action);
            }
            if (uiid == null) {
                uiid = action.getUIID();
            }
        }
        actions = tempActions;
        if (overflowActions.size() > 0) {
            ActionNode overflowAction = overflowButtonAction.icon(FontImage.MATERIAL_MORE_HORIZ).build();
            // Try to match the UIID of the other actions
            if (uiid != null) {
                overflowAction.setAttributes(uiid);
            }
            overflowAction.setParent(getViewNode());
            final Actions fOverflowActions = overflowActions;
            overflowActions.copyAttributesIfNotExists(overflowActionTemplate.build());
            overflowAction.addActionListener(e -> {
                e.consume();
                showOverflowMenu(fOverflowActions);
            });
            if (overflowMenuStyle != OverflowMenuStyle.None) {
                actions.add(overflowAction);
            }
        }
    }
    actions.copyAttributesIfNotExists(actionTemplate.build());
    actions.addToContainer(this, getEntity(), buttonWrapper);
    revalidateWithAnimationSafety();
}
Also used : Actions(com.codename1.rad.ui.Actions) UIID(com.codename1.rad.attributes.UIID) ActionNode(com.codename1.rad.nodes.ActionNode)

Aggregations

ActionNode (com.codename1.rad.nodes.ActionNode)16 Form (com.codename1.ui.Form)6 EntityList (com.codename1.rad.models.EntityList)5 ListNode (com.codename1.rad.nodes.ListNode)5 Container (com.codename1.ui.Container)5 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)4 UIID (com.codename1.rad.attributes.UIID)4 Entity (com.codename1.rad.models.Entity)4 Button (com.codename1.ui.Button)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 GridLayout (com.codename1.ui.layouts.GridLayout)4 ControllerEvent (com.codename1.rad.controllers.ControllerEvent)3 EntityListProvider (com.codename1.rad.models.EntityListProvider)3 BoxLayout (com.codename1.ui.layouts.BoxLayout)3 Map (java.util.Map)3 ComponentImage (ca.weblite.shared.components.ComponentImage)2 MultiButton (com.codename1.components.MultiButton)2 Log (com.codename1.io.Log)2 NetworkEvent (com.codename1.io.NetworkEvent)2 IconUIID (com.codename1.rad.attributes.IconUIID)2