Search in sources :

Example 6 with ShortcutListenerDelegate

use of com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate in project cuba by cuba-platform.

the class ServerLogWindow method init.

@Override
public void init(Map<String, Object> params) {
    initLoweredAttentionPatterns();
    localJmxField.setValue(jmxControlAPI.getLocalNodeName());
    localJmxInstance = jmxControlAPI.getLocalInstance();
    jmxInstancesDs.refresh();
    jmxConnectionField.setValue(localJmxInstance);
    jmxConnectionField.setRequired(true);
    jmxConnectionField.addValueChangeListener(e -> {
        JmxInstance jmxInstance = e.getValue();
        try {
            refreshHostInfo();
        } catch (JmxControlException ex) {
            showNotification(getMessage("exception.unableToConnectToInterface"), NotificationType.WARNING);
            if (jmxInstance != localJmxInstance) {
                jmxConnectionField.setValue(localJmxInstance);
            }
        }
    });
    autoRefreshCheck.addValueChangeListener(e -> {
        if (Boolean.TRUE.equals(e.getValue())) {
            updateLogTailTimer.start();
        } else {
            updateLogTailTimer.stop();
        }
    });
    jmxConnectionField.removeAllActions();
    LookupAction action = LookupAction.create(jmxConnectionField);
    action.setAfterLookupCloseHandler((window, actionId) -> {
        jmxInstancesDs.refresh();
    });
    jmxConnectionField.addAction(action);
    jmxConnectionField.addAction(new BaseAction("actions.Add").withIcon("icons/plus-btn.png").withHandler(event -> {
        JmxInstanceEditor instanceEditor = (JmxInstanceEditor) openEditor(metadata.create(JmxInstance.class), OpenType.DIALOG);
        instanceEditor.addCloseListener(actionId -> {
            if (COMMIT_ACTION_ID.equals(actionId)) {
                jmxInstancesDs.refresh();
                jmxConnectionField.setValue(instanceEditor.getItem());
            }
        });
    }));
    logTailLabel.setSizeAuto();
    logTailLabel.setHtmlEnabled(true);
    logTailLabel.setStyleName("c-log-content");
    loggerLevelField.setOptionsList(LoggingHelper.getLevels());
    appenderLevelField.setOptionsList(LoggingHelper.getLevels());
    refreshHostInfo();
    loggerNameField.addValueChangeListener(e -> {
        List<String> currentLoggers = new ArrayList<>(jmxRemoteLoggingAPI.getLoggerNames(getSelectedConnection()));
        currentLoggers.sort(null);
        currentLoggers.add(0, getMessage("logger.new"));
        if (e.getValue() != null && e.getValue().equals(currentLoggers.get(0))) {
            openAddLoggerDialog();
        }
    });
    downloadButton.setEnabled(security.isSpecificPermitted("cuba.gui.administration.downloadlogs"));
    logFileNameField.withUnwrapped(ComboBox.class, vComboBox -> {
        vComboBox.addShortcutListener(new ShortcutListenerDelegate("", KeyCode.D, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }).withHandler((sender, target) -> downloadLog()));
        vComboBox.addShortcutListener(new ShortcutListenerDelegate("", KeyCode.S, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }).withHandler((sender, target) -> showLogTail()));
    });
    downloadButton.setDescription("CTRL-SHIFT-D");
    showTailButton.setDescription("CTRL-SHIFT-S");
    logContainer.withUnwrappedComposition(CubaScrollBoxLayout.class, vScrollBox -> vScrollBox.setDelayed(true));
}
Also used : LookupAction(com.haulmont.cuba.gui.components.PickerField.LookupAction) java.util(java.util) LookupAction(com.haulmont.cuba.gui.components.PickerField.LookupAction) Security(com.haulmont.cuba.core.global.Security) ComboBox(com.vaadin.ui.ComboBox) LoggerFactory(org.slf4j.LoggerFactory) ParamsMap(com.haulmont.bali.util.ParamsMap) Settings(com.haulmont.cuba.gui.settings.Settings) Timer(com.haulmont.cuba.gui.components.Timer) StringUtils(org.apache.commons.lang3.StringUtils) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) Matcher(java.util.regex.Matcher) JmxControlAPI(com.haulmont.cuba.web.jmx.JmxControlAPI) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) LogArchiver(com.haulmont.cuba.core.sys.logging.LogArchiver) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) Logger(org.slf4j.Logger) LoggingHelper(com.haulmont.cuba.core.sys.logging.LoggingHelper) LogDataProvider(com.haulmont.cuba.web.export.LogDataProvider) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) IOException(java.io.IOException) JmxRemoteLoggingAPI(com.haulmont.cuba.web.jmx.JmxRemoteLoggingAPI) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) Level(ch.qos.logback.classic.Level) ModifierKey(com.vaadin.event.ShortcutAction.ModifierKey) StringReader(java.io.StringReader) WebConfig(com.haulmont.cuba.web.WebConfig) AppConfig(com.haulmont.cuba.gui.AppConfig) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) ShortcutListenerDelegate(com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate) CubaScrollBoxLayout(com.haulmont.cuba.web.widgets.CubaScrollBoxLayout) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) Element(org.dom4j.Element) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) ShortcutListenerDelegate(com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance)

Example 7 with ShortcutListenerDelegate

use of com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate in project cuba by cuba-platform.

the class WebAppWorkArea method createCloseShortcut.

protected ShortcutListener createCloseShortcut(RootWindow topLevelWindow) {
    Configuration configuration = beanLocator.get(Configuration.NAME);
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination combination = KeyCombination.create(closeShortcut);
    return new ShortcutListenerDelegate("onClose", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())).withHandler((sender, target) -> closeWindowByShortcut(topLevelWindow));
}
Also used : Configuration(com.haulmont.cuba.core.global.Configuration) ShortcutListenerDelegate(com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 8 with ShortcutListenerDelegate

use of com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate in project cuba by cuba-platform.

the class WebAppWorkArea method createNextWindowTabShortcut.

protected ShortcutListener createNextWindowTabShortcut(RootWindow topLevelWindow) {
    Configuration configuration = beanLocator.get(Configuration.NAME);
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    String nextTabShortcut = clientConfig.getNextTabShortcut();
    KeyCombination combination = KeyCombination.create(nextTabShortcut);
    return new ShortcutListenerDelegate("onNextTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())).withHandler((sender, target) -> {
        TabSheetBehaviour tabSheet = getTabbedWindowContainer().getTabSheetBehaviour();
        if (tabSheet != null && !hasModalWindow() && tabSheet.getComponentCount() > 1) {
            com.vaadin.ui.Component selectedTabComponent = tabSheet.getSelectedTab();
            String tabId = tabSheet.getTab(selectedTabComponent);
            int tabPosition = tabSheet.getTabPosition(tabId);
            int newTabPosition = (tabPosition + 1) % tabSheet.getComponentCount();
            String newTabId = tabSheet.getTab(newTabPosition);
            tabSheet.setSelectedTab(newTabId);
            moveFocus(tabSheet, newTabId);
        }
    });
}
Also used : Configuration(com.haulmont.cuba.core.global.Configuration) ShortcutListenerDelegate(com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate) ClientConfig(com.haulmont.cuba.client.ClientConfig) Component(com.vaadin.ui.Component)

Example 9 with ShortcutListenerDelegate

use of com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate in project cuba by cuba-platform.

the class WebTree method createShortcutsDelegate.

protected ShortcutsDelegate<ShortcutListener> createShortcutsDelegate() {
    return new ShortcutsDelegate<ShortcutListener>() {

        @Override
        protected ShortcutListener attachShortcut(String actionId, KeyCombination keyCombination) {
            ShortcutListener shortcut = new ShortcutListenerDelegate(actionId, keyCombination.getKey().getCode(), KeyCombination.Modifier.codes(keyCombination.getModifiers())).withHandler((sender, target) -> {
                if (sender == componentComposition) {
                    Action action = getAction(actionId);
                    if (action != null && action.isEnabled() && action.isVisible()) {
                        action.actionPerform(WebTree.this);
                    }
                }
            });
            componentComposition.addShortcutListener(shortcut);
            return shortcut;
        }

        @Override
        protected void detachShortcut(Action action, ShortcutListener shortcutDescriptor) {
            componentComposition.removeShortcutListener(shortcutDescriptor);
        }

        @Override
        protected Collection<Action> getActions() {
            return WebTree.this.getActions();
        }
    };
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ShowInfoAction(com.haulmont.cuba.gui.components.sys.ShowInfoAction) ShortcutListenerDelegate(com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate) ShortcutsDelegate(com.haulmont.cuba.gui.components.sys.ShortcutsDelegate)

Aggregations

ShortcutListenerDelegate (com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate)9 ClientConfig (com.haulmont.cuba.client.ClientConfig)5 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)4 Configuration (com.haulmont.cuba.core.global.Configuration)3 ShowInfoAction (com.haulmont.cuba.gui.components.sys.ShowInfoAction)3 WebConfig (com.haulmont.cuba.web.WebConfig)3 Component (com.vaadin.ui.Component)3 java.util (java.util)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Entity (com.haulmont.cuba.core.entity.Entity)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 ShortcutsDelegate (com.haulmont.cuba.gui.components.sys.ShortcutsDelegate)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 AppUI (com.haulmont.cuba.web.AppUI)2 Action (com.vaadin.event.Action)2 ShortcutAction (com.vaadin.event.ShortcutAction)2 KeyCode (com.vaadin.event.ShortcutAction.KeyCode)2 ShortcutListener (com.vaadin.event.ShortcutListener)2