Search in sources :

Example 21 with ClientConfig

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);
            }
        }
    });
}
Also used : com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction) ClientConfig(com.haulmont.cuba.client.ClientConfig) DesktopAbstractComponent(com.haulmont.cuba.desktop.gui.components.DesktopAbstractComponent) Component(com.haulmont.cuba.gui.components.Component)

Example 22 with ClientConfig

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;
}
Also used : List(java.util.List) LayoutAnalyzer(com.haulmont.cuba.gui.app.core.dev.LayoutAnalyzer) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 23 with ClientConfig

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);
    }
}
Also used : Locale(java.util.Locale) User(com.haulmont.cuba.security.entity.User) TopLevelFrame(com.haulmont.cuba.desktop.TopLevelFrame) HashMap(java.util.HashMap) ExceptionReportService(com.haulmont.cuba.core.app.ExceptionReportService) ClientConfig(com.haulmont.cuba.client.ClientConfig) SimpleDateFormat(java.text.SimpleDateFormat)

Example 24 with ClientConfig

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;
                        }
                    }
                }
            }
        }
    });
}
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 25 with ClientConfig

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);
    }
}
Also used : ClientConfig(com.haulmont.cuba.client.ClientConfig)

Aggregations

ClientConfig (com.haulmont.cuba.client.ClientConfig)40 Configuration (com.haulmont.cuba.core.global.Configuration)14 Messages (com.haulmont.cuba.core.global.Messages)6 Inject (javax.inject.Inject)6 Icons (com.haulmont.cuba.gui.icons.Icons)5 Element (org.dom4j.Element)5 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)3 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)3 Component (com.haulmont.cuba.gui.components.Component)3 ShortcutListenerDelegate (com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate)3 EventRouter (com.haulmont.bali.events.EventRouter)2 Preconditions (com.haulmont.bali.util.Preconditions)2 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)2 MetaClass (com.haulmont.chile.core.model.MetaClass)2 Entity (com.haulmont.cuba.core.entity.Entity)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 TopLevelFrame (com.haulmont.cuba.desktop.TopLevelFrame)2 com.haulmont.cuba.gui (com.haulmont.cuba.gui)2 LayoutAnalyzer (com.haulmont.cuba.gui.app.core.dev.LayoutAnalyzer)2 Action (com.haulmont.cuba.gui.components.Action)2