Search in sources :

Example 1 with ValidationAwareAction

use of com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction in project cuba by cuba-platform.

the class DesktopFrameActionsHolder method addAction.

public void addAction(Action action, int index) {
    int oldIndex = findActionById(actionList, action.getId());
    if (oldIndex >= 0) {
        removeAction(actionList.get(oldIndex));
        if (index > oldIndex) {
            index--;
        }
    }
    if (action.getShortcutCombination() != null) {
        KeyStroke keyStroke = DesktopComponentsHelper.convertKeyCombination(action.getShortcutCombination());
        InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        inputMap.put(keyStroke, action.getId());
        ActionMap actionMap = panel.getActionMap();
        actionMap.put(action.getId(), new ValidationAwareAction() {

            @Override
            public void actionPerformedAfterValidation(ActionEvent e) {
                action.actionPerform(component);
            }
        });
        shortcutActions.put(action, keyStroke);
    }
    actionList.add(index, action);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ValidationAwareAction(com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)

Example 2 with ValidationAwareAction

use of com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction in project cuba by cuba-platform.

the class DesktopWindowManager method setTabsPane.

public void setTabsPane(final JTabbedPane tabsPane) {
    this.tabsPane = tabsPane;
    // todo move to config
    tabsPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control W"), "closeTab");
    tabsPane.getActionMap().put("closeTab", new ValidationAwareAction() {

        @Override
        public void actionPerformedAfterValidation(ActionEvent e) {
            closeTab((JComponent) tabsPane.getSelectedComponent());
        }
    });
}
Also used : ValidationAwareAction(com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)

Example 3 with ValidationAwareAction

use of com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction in project cuba by cuba-platform.

the class DesktopTextField method addEnterPressListener.

@Override
public void addEnterPressListener(EnterPressListener listener) {
    Preconditions.checkNotNullArgument(listener);
    if (!enterPressListeners.contains(listener)) {
        enterPressListeners.add(listener);
    }
    if (!enterPressInitialized) {
        impl.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enter");
        impl.getActionMap().put("enter", new ValidationAwareAction() {

            @Override
            public void actionPerformedAfterValidation(ActionEvent e) {
                EnterPressEvent event = new EnterPressEvent(DesktopTextField.this);
                for (EnterPressListener enterPressListener : new ArrayList<>(enterPressListeners)) {
                    enterPressListener.enterPressed(event);
                }
            }
        });
        enterPressInitialized = true;
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ValidationAwareAction(com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)

Example 4 with ValidationAwareAction

use of com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction in project cuba by cuba-platform.

the class DesktopComponentsHelper method addEnterShortcut.

@Deprecated
public static void addEnterShortcut(com.haulmont.cuba.gui.components.TextField textField, final Runnable runnable) {
    JTextField impl = (JTextField) DesktopComponentsHelper.unwrap(textField);
    impl.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enter");
    impl.getActionMap().put("enter", new ValidationAwareAction() {

        @Override
        public void actionPerformedAfterValidation(ActionEvent e) {
            runnable.run();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) ValidationAwareAction(com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)

Aggregations

ValidationAwareAction (com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)4 ActionEvent (java.awt.event.ActionEvent)3