Search in sources :

Example 1 with PopupMenu

use of ca.weblite.shared.components.PopupMenu 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 PopupMenu

use of ca.weblite.shared.components.PopupMenu in project CodenameOne by codenameone.

the class PopupMenuSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    PopupMenu addMenu = new PopupMenu();
    addMenu.addCommand(Command.createMaterial("Add Task", FontImage.MATERIAL_ADD_TASK, evt -> {
    // do adding task stuff
    }));
    addMenu.addCommand(Command.createMaterial("Add Chart", FontImage.MATERIAL_ADD_CHART, evt -> {
    // Do adding chart stuff
    }));
    addMenu.setMaterialIcon(FontImage.MATERIAL_MORE);
    addMenu.setCommandLabel("More Options");
    hi.add(new Button(addMenu.getCommand()));
    hi.show();
}
Also used : PopupMenu(ca.weblite.shared.components.PopupMenu) Toolbar(com.codename1.ui.Toolbar) BoxLayout(com.codename1.ui.layouts.BoxLayout) Resources(com.codename1.ui.util.Resources) IOException(java.io.IOException) Form(com.codename1.ui.Form) Log(com.codename1.io.Log) NetworkEvent(com.codename1.io.NetworkEvent) UIManager(com.codename1.ui.plaf.UIManager) Command(com.codename1.ui.Command) Dialog(com.codename1.ui.Dialog) Display(com.codename1.ui.Display) FontImage(com.codename1.ui.FontImage) Label(com.codename1.ui.Label) Button(com.codename1.ui.Button) CN(com.codename1.ui.CN) Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) PopupMenu(ca.weblite.shared.components.PopupMenu)

Aggregations

PopupMenu (ca.weblite.shared.components.PopupMenu)2 Button (com.codename1.ui.Button)2 Command (com.codename1.ui.Command)2 Log (com.codename1.io.Log)1 NetworkEvent (com.codename1.io.NetworkEvent)1 Property (com.codename1.rad.models.Property)1 ActionNode (com.codename1.rad.nodes.ActionNode)1 CN (com.codename1.ui.CN)1 Container (com.codename1.ui.Container)1 Dialog (com.codename1.ui.Dialog)1 Display (com.codename1.ui.Display)1 FontImage (com.codename1.ui.FontImage)1 Form (com.codename1.ui.Form)1 Label (com.codename1.ui.Label)1 Toolbar (com.codename1.ui.Toolbar)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 BorderLayout (com.codename1.ui.layouts.BorderLayout)1 BoxLayout (com.codename1.ui.layouts.BoxLayout)1 GridLayout (com.codename1.ui.layouts.GridLayout)1 UIManager (com.codename1.ui.plaf.UIManager)1