Search in sources :

Example 11 with Action

use of com.haulmont.cuba.gui.components.Action in project cuba by cuba-platform.

the class DesktopPickerField method updateOrderedShortcuts.

protected void updateOrderedShortcuts() {
    InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED);
    for (int i = 0; i < 9; i++) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_1 + i, modifiersMask, false);
        inputMap.remove(keyStroke);
    }
    int index = 0;
    for (Action action : actionsOrder) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_1 + index, modifiersMask, false);
        List<KeyStroke> keyStrokes = new LinkedList<>();
        keyStrokes.add(keyStroke);
        keyStrokesMap.put(action, keyStrokes);
        inputMap.put(keyStroke, action.getId());
        index++;
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(com.haulmont.cuba.gui.components.Action)

Example 12 with Action

use of com.haulmont.cuba.gui.components.Action in project cuba by cuba-platform.

the class SessionLogBrowser method enableLogging.

public void enableLogging() {
    if (globalConfig.getUserSessionLogEnabled()) {
        showOptionDialog(getMessage("dialogs.Confirmation"), getMessage("confirmDisable"), MessageType.CONFIRMATION, new Action[] { new DialogAction(DialogAction.Type.YES, true).withHandler(actionPerformedEvent -> {
            globalConfig.setUserSessionLogEnabled(false);
            enableBtn.setCaption(getMessage("enableLogging"));
        }), new DialogAction(DialogAction.Type.NO) });
    } else {
        globalConfig.setUserSessionLogEnabled(true);
        enableBtn.setCaption(getMessage("disableLogging"));
    }
}
Also used : Inject(javax.inject.Inject) GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) AbstractLookup(com.haulmont.cuba.gui.components.AbstractLookup) Map(java.util.Map) Button(com.haulmont.cuba.gui.components.Button) DialogAction(com.haulmont.cuba.gui.components.DialogAction) Action(com.haulmont.cuba.gui.components.Action) DialogAction(com.haulmont.cuba.gui.components.DialogAction)

Example 13 with Action

use of com.haulmont.cuba.gui.components.Action in project cuba by cuba-platform.

the class DesktopWindowManager method createButtonsPanel.

protected JPanel createButtonsPanel(Action[] actions, final DialogWindow dialog) {
    JPanel buttonsPanel = new JPanel();
    boolean hasPrimaryAction = false;
    for (final Action action : actions) {
        JButton button = new JButton(action.getCaption());
        String icon = action.getIcon();
        if (icon != null) {
            button.setIcon(AppBeans.get(IconResolver.class).getIconResource(icon));
        }
        final DialogActionHandler dialogActionHandler = new DialogActionHandler(dialog, action);
        button.addActionListener(dialogActionHandler);
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JButton b = (JButton) e.getSource();
                userActionsLog.trace("Button (name = {}, text = {}) was clicked in dialog", b.getName(), b.getText());
            }
        });
        if (actions.length == 1) {
            dialog.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosing(WindowEvent e) {
                    dialogActionHandler.onClose();
                }
            });
        }
        button.setPreferredSize(new Dimension(button.getPreferredSize().width, DesktopComponentsHelper.BUTTON_HEIGHT));
        button.setMaximumSize(new Dimension(Integer.MAX_VALUE, DesktopComponentsHelper.BUTTON_HEIGHT));
        if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) {
            hasPrimaryAction = true;
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    button.requestFocus();
                }
            });
        }
        buttonsPanel.add(button);
    }
    if (!hasPrimaryAction && actions.length > 0) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                buttonsPanel.getComponent(0).requestFocus();
            }
        });
    }
    return buttonsPanel;
}
Also used : ValidationAwareAction(com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction) Action(com.haulmont.cuba.gui.components.Action) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 14 with Action

use of com.haulmont.cuba.gui.components.Action in project cuba by cuba-platform.

the class DesktopWindowManager method assignDialogShortcuts.

protected void assignDialogShortcuts(final JDialog dialog, JPanel panel, final Action[] actions) {
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    InputMap inputMap = panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap actionMap = panel.getActionMap();
    String commitShortcut = getConfigValueIfConnected(clientConfig::getCommitShortcut, "cuba.gui.commitShortcut", "CTRL-ENTER");
    KeyCombination okCombination = KeyCombination.create(commitShortcut);
    KeyStroke okKeyStroke = DesktopComponentsHelper.convertKeyCombination(okCombination);
    inputMap.put(okKeyStroke, "okAction");
    actionMap.put("okAction", new javax.swing.AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            for (Action action : actions) {
                if (action instanceof DialogAction) {
                    switch(((DialogAction) action).getType()) {
                        case OK:
                        case YES:
                            action.actionPerform(null);
                            dialog.setVisible(false);
                            cleanupAfterModalDialogClosed(null);
                            return;
                    }
                }
            }
        }
    });
    String closeShortcut = getConfigValueIfConnected(clientConfig::getCloseShortcut, "cuba.gui.closeShortcut", "ESCAPE");
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);
    KeyStroke closeKeyStroke = DesktopComponentsHelper.convertKeyCombination(closeCombination);
    inputMap.put(closeKeyStroke, "closeAction");
    actionMap.put("closeAction", new javax.swing.AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (actions.length == 1) {
                actions[0].actionPerform(null);
                dialog.setVisible(false);
                cleanupAfterModalDialogClosed(null);
            } else {
                for (Action action : actions) {
                    if (action instanceof DialogAction) {
                        switch(((DialogAction) action).getType()) {
                            case CANCEL:
                            case CLOSE:
                            case NO:
                                action.actionPerform(null);
                                dialog.setVisible(false);
                                cleanupAfterModalDialogClosed(null);
                                return;
                        }
                    }
                }
            }
        }
    });
}
Also used : ValidationAwareAction(com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction) Action(com.haulmont.cuba.gui.components.Action) javax.swing(javax.swing) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 15 with Action

use of com.haulmont.cuba.gui.components.Action in project cuba by cuba-platform.

the class DesktopTree method createPopupMenu.

protected JPopupMenu createPopupMenu() {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem menuItem;
    for (final com.haulmont.cuba.gui.components.Action action : actionList) {
        if (StringUtils.isNotBlank(action.getCaption()) && action.isVisible()) {
            menuItem = new JMenuItem(action.getCaption());
            if (action.getIcon() != null) {
                menuItem.setIcon(AppBeans.get(IconResolver.class).getIconResource(action.getIcon()));
            }
            if (action.getShortcutCombination() != null) {
                menuItem.setAccelerator(DesktopComponentsHelper.convertKeyCombination(action.getShortcutCombination()));
            }
            menuItem.setEnabled(action.isEnabled());
            menuItem.addActionListener(e -> action.actionPerform(DesktopTree.this));
            popup.add(menuItem);
        }
    }
    return popup;
}
Also used : com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Action(com.haulmont.cuba.gui.components.Action)

Aggregations

Action (com.haulmont.cuba.gui.components.Action)18 AbstractAction (javax.swing.AbstractAction)5 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)4 Component (com.haulmont.cuba.gui.components.Component)3 Window (com.haulmont.cuba.gui.components.Window)3 ClientConfig (com.haulmont.cuba.client.ClientConfig)2 Messages (com.haulmont.cuba.core.global.Messages)2 ValidationAwareAction (com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)2 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)2 DialogAction (com.haulmont.cuba.gui.components.DialogAction)2 CollectionDsActionsNotifier (com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier)2 WeakCollectionChangeListener (com.haulmont.cuba.gui.data.impl.WeakCollectionChangeListener)2 HierarchicalDsWrapper (com.haulmont.cuba.web.gui.data.HierarchicalDsWrapper)2 Inject (javax.inject.Inject)2 JTextComponent (javax.swing.text.JTextComponent)2 Element (org.dom4j.Element)2 BoundAction (org.jdesktop.swingx.action.BoundAction)2 Iterables (com.google.common.collect.Iterables)1 Pair (com.haulmont.bali.datastruct.Pair)1 EventRouter (com.haulmont.bali.events.EventRouter)1