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