use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class DesktopWindowManager method addShortcuts.
protected void addShortcuts(Window window, OpenType openType) {
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
String closeShortcut = clientConfig.getCloseShortcut();
window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("closeWindowShortcutAction", closeShortcut) {
@Override
public void actionPerform(Component component) {
if (openType.getOpenMode() != OpenMode.DIALOG || BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) {
if (!isCloseWithShortcutPrevented(window)) {
window.close("close");
}
}
}
});
String previousTabShortcut = clientConfig.getPreviousTabShortcut();
window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("onPreviousTab", previousTabShortcut) {
@Override
public void actionPerform(Component component) {
if (window.getWindowManager() != DesktopWindowManager.this) {
// detached tab
return;
}
if (isMainWindowManager && getLastDialogWindow() == null && tabsPane.getTabCount() > 1) {
int selectedIndex = getSelectedTabIndex();
int newIndex = (selectedIndex + tabsPane.getTabCount() - 1) % tabsPane.getTabCount();
java.awt.Component newTab = tabsPane.getComponentAt(newIndex);
tabsPane.setSelectedComponent(newTab);
moveFocus(newTab);
}
}
});
String nextTabShortcut = clientConfig.getNextTabShortcut();
window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("onNextTab", nextTabShortcut) {
@Override
public void actionPerform(Component component) {
if (window.getWindowManager() != DesktopWindowManager.this) {
// detached tab
return;
}
if (isMainWindowManager && getLastDialogWindow() == null && tabsPane.getTabCount() > 1) {
int selectedIndex = getSelectedTabIndex();
int newIndex = (selectedIndex + 1) % tabsPane.getTabCount();
java.awt.Component newTab = tabsPane.getComponentAt(newIndex);
tabsPane.setSelectedComponent(newTab);
moveFocus(newTab);
}
}
});
}
use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class DesktopWindowManager method createWindowPopupMenu.
protected JPopupMenu createWindowPopupMenu(final Window window) {
JPopupMenu popupMenu = new JPopupMenu();
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
if (clientConfig.getManualScreenSettingsSaving()) {
JMenuItem saveSettingsItem = new JMenuItem(messages.getMainMessage("actions.saveSettings"));
saveSettingsItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
window.saveSettings();
}
});
popupMenu.add(saveSettingsItem);
JMenuItem restoreToDefaultsItem = new JMenuItem(messages.getMainMessage("actions.restoreToDefaults"));
restoreToDefaultsItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
window.deleteSettings();
}
});
popupMenu.add(restoreToDefaultsItem);
}
if (clientConfig.getLayoutAnalyzerEnabled()) {
JMenuItem analyzeLayoutItem = new JMenuItem(messages.getMainMessage("actions.analyzeLayout"));
analyzeLayoutItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
LayoutAnalyzer analyzer = new LayoutAnalyzer();
List<LayoutTip> tipsList = analyzer.analyze(window);
if (tipsList.isEmpty()) {
showNotification("No layout problems found", NotificationType.HUMANIZED);
} else {
window.openWindow("layoutAnalyzer", OpenType.DIALOG, ParamsMap.of("tipsList", tipsList));
}
}
});
popupMenu.add(analyzeLayoutItem);
}
return popupMenu;
}
use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class JXErrorPaneExt method sendSupportEmail.
private void sendSupportEmail(ErrorInfo jXErrorPaneInfo) {
Configuration configuration = AppBeans.get(Configuration.NAME);
ExceptionReportService reportService = AppBeans.get(ExceptionReportService.NAME);
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
TopLevelFrame mainFrame = App.getInstance().getMainFrame();
Messages messages = AppBeans.get(Messages.NAME);
Locale locale = App.getInstance().getLocale();
try {
TimeSource timeSource = AppBeans.get(TimeSource.NAME);
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timeSource.currentTimestamp());
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
User user = userSessionSource.getUserSession().getUser();
Map<String, Object> binding = new HashMap<>();
binding.put("timestamp", date);
binding.put("errorMessage", jXErrorPaneInfo.getBasicErrorMessage());
binding.put("stacktrace", getStackTrace(jXErrorPaneInfo.getErrorException()));
binding.put("systemId", clientConfig.getSystemID());
binding.put("userLogin", user.getLogin());
if (MapUtils.isNotEmpty(additionalExceptionReportBinding)) {
binding.putAll(additionalExceptionReportBinding);
}
reportService.sendExceptionReport(clientConfig.getSupportEmail(), ImmutableMap.copyOf(binding));
mainFrame.showNotification(messages.getMainMessage("errorPane.emailSent", locale), Frame.NotificationType.TRAY);
} catch (Throwable e) {
mainFrame.showNotification(messages.getMainMessage("errorPane.emailSendingErr", locale), Frame.NotificationType.ERROR);
log.error("Can't send error report", e);
}
}
use of com.haulmont.cuba.client.ClientConfig 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);
dialog.dispose();
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);
dialog.dispose();
} 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);
dialog.dispose();
return;
}
}
}
}
}
});
}
use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.
the class DesktopPickerField method initModifiersMask.
protected void initModifiersMask() {
Configuration configuration = AppBeans.get(Configuration.NAME);
ClientConfig config = configuration.getConfig(ClientConfig.class);
String[] strModifiers = StringUtils.split(config.getPickerShortcutModifiers().toUpperCase(), "-");
for (String strModifier : strModifiers) {
KeyCombination.Modifier modifier = KeyCombination.Modifier.valueOf(strModifier);
modifiersMask = modifiersMask | DesktopComponentsHelper.convertModifier(modifier);
}
}
Aggregations