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);
}
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());
}
});
}
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;
}
}
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();
}
});
}
Aggregations