Search in sources :

Example 6 with ShortcutListener

use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.

the class WebDataGrid method initComponent.

protected void initComponent(CubaGrid component) {
    setSelectionMode(SelectionMode.SINGLE);
    component.setImmediate(true);
    component.setColumnReorderingAllowed(true);
    containerWrapper = new GeneratedPropertyContainer(component.getContainerDataSource());
    component.setContainerDataSource(containerWrapper);
    component.addSelectionListener(e -> {
        if (datasource == null) {
            return;
        }
        final Set<E> selected = getSelected();
        if (selected.isEmpty()) {
            Entity dsItem = datasource.getItemIfValid();
            // noinspection unchecked
            datasource.setItem(null);
            if (dsItem == null) {
                // in this case item change event will not be generated
                refreshActionsState();
            }
        } else {
            // reset selection and select new item
            if (isMultiSelect()) {
                // noinspection unchecked
                datasource.setItem(null);
            }
            Entity newItem = selected.iterator().next();
            Entity dsItem = datasource.getItemIfValid();
            // noinspection unchecked
            datasource.setItem(newItem);
            if (Objects.equals(dsItem, newItem)) {
                // in this case item change event will not be generated
                refreshActionsState();
            }
        }
        LookupSelectionChangeEvent selectionChangeEvent = new LookupSelectionChangeEvent(this);
        getEventRouter().fireEvent(LookupSelectionChangeListener.class, LookupSelectionChangeListener::lookupValueChanged, selectionChangeEvent);
        if (getEventRouter().hasListeners(SelectionListener.class)) {
            List<E> addedItems = getItemsByIds(e.getAdded());
            List<E> removedItems = getItemsByIds(e.getRemoved());
            List<E> selectedItems = getItemsByIds(e.getSelected());
            SelectionEvent<E> event = new SelectionEvent<>(WebDataGrid.this, addedItems, removedItems, selectedItems);
            // noinspection unchecked
            getEventRouter().fireEvent(SelectionListener.class, SelectionListener::selected, event);
        }
    });
    component.addShortcutListener(new ShortcutListener("dataGridEnter", KeyCode.ENTER, null) {

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == WebDataGrid.this.component) {
                if (WebDataGrid.this.isEditorEnabled()) {
                    // since it's the default shortcut to open editor
                    return;
                }
                if (enterPressAction != null) {
                    enterPressAction.actionPerform(WebDataGrid.this);
                } else {
                    handleDoubleClickAction();
                }
            }
        }
    });
    component.addItemClickListener(e -> {
        if (e.isDoubleClick() && e.getItem() != null && !WebDataGrid.this.isEditorEnabled()) {
            // note: for now Grid doesn't send double click if editor is enabled,
            // but it's better to handle it manually
            handleDoubleClickAction();
        }
        if (getEventRouter().hasListeners(ItemClickListener.class)) {
            MouseEventDetails mouseEventDetails = WebWrapperUtils.toMouseEventDetails(e);
            // noinspection unchecked
            E item = (E) datasource.getItem(e.getItemId());
            if (item == null) {
                // datasource, so we don't want to send such event because it's useless
                return;
            }
            Column column = getColumnByPropertyId(e.getPropertyId());
            ItemClickEvent<E> event = new ItemClickEvent<>(WebDataGrid.this, mouseEventDetails, item, e.getItemId(), column != null ? column.getId() : null);
            // noinspection unchecked
            getEventRouter().fireEvent(ItemClickListener.class, ItemClickListener::onItemClick, event);
        }
    });
    component.addColumnReorderListener(e -> {
        if (e.isUserOriginated()) {
            // Grid doesn't know about columns hidden by security permissions,
            // so we need to return them back to they previous positions
            columnsOrder = restoreColumnsOrder(getColumnsOrderInternal());
            if (getEventRouter().hasListeners(ColumnReorderListener.class)) {
                ColumnReorderEvent event = new ColumnReorderEvent(WebDataGrid.this);
                getEventRouter().fireEvent(ColumnReorderListener.class, ColumnReorderListener::columnReordered, event);
            }
        }
    });
    componentComposition = new GridComposition();
    componentComposition.setPrimaryStyleName("c-data-grid-composition");
    componentComposition.setGrid(component);
    componentComposition.addComponent(component);
    componentComposition.setWidthUndefined();
    component.setSizeUndefined();
    component.setHeightMode(HeightMode.UNDEFINED);
    component.setRowStyleGenerator(createRowStyleGenerator());
    component.setCellStyleGenerator(createCellStyleGenerator());
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) ShortcutListener(com.vaadin.event.ShortcutListener) GeneratedPropertyContainer(com.vaadin.data.util.GeneratedPropertyContainer)

Example 7 with ShortcutListener

use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.

the class WebMaskedField method addEnterPressListener.

@Override
public void addEnterPressListener(EnterPressListener listener) {
    getEventRouter().addListener(EnterPressListener.class, listener);
    if (enterShortcutListener == null) {
        enterShortcutListener = new ShortcutListener("enter", KeyCode.ENTER, null) {

            @Override
            public void handleAction(Object sender, Object target) {
                EnterPressEvent event = new EnterPressEvent(WebMaskedField.this);
                getEventRouter().fireEvent(EnterPressListener.class, EnterPressListener::enterPressed, event);
            }
        };
        component.addShortcutListener(enterShortcutListener);
    }
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener)

Example 8 with ShortcutListener

use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.

the class WebTextField method addEnterPressListener.

@Override
public void addEnterPressListener(EnterPressListener listener) {
    getEventRouter().addListener(EnterPressListener.class, listener);
    if (enterShortcutListener == null) {
        enterShortcutListener = new ShortcutListener("", KeyCode.ENTER, null) {

            @Override
            public void handleAction(Object sender, Object target) {
                EnterPressEvent event = new EnterPressEvent(WebTextField.this);
                getEventRouter().fireEvent(EnterPressListener.class, EnterPressListener::enterPressed, event);
            }
        };
        component.addShortcutListener(enterShortcutListener);
    }
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener)

Example 9 with ShortcutListener

use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.

the class CubaFoldersPane method createAppFoldersPane.

protected Component createAppFoldersPane() {
    List<AppFolder> appFolders = foldersService.loadAppFolders();
    if (appFolders.isEmpty())
        return null;
    appFoldersTree = new CubaTree();
    appFoldersTree.setCubaId("appFoldersTree");
    appFoldersTree.setSelectable(true);
    appFoldersTree.setItemStyleGenerator(new FolderTreeStyleProvider());
    appFoldersTree.addShortcutListener(new ShortcutListener("applyAppFolder", ShortcutAction.KeyCode.ENTER, (int[]) null) {

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == appFoldersTree) {
                AbstractSearchFolder folder = (AbstractSearchFolder) appFoldersTree.getValue();
                if (folder != null) {
                    openFolder(folder);
                }
            }
        }
    });
    appFoldersTree.addExpandListener(new Tree.ExpandListener() {

        @Override
        public void nodeExpand(Tree.ExpandEvent event) {
            AppFolder folder = (AppFolder) event.getItemId();
            if (StringUtils.isBlank(folder.getQuantityScript())) {
                folder.setQuantity(null);
                folder.setItemStyle(null);
                setFolderTreeItemCaption(appFoldersTree, folder);
            }
        }
    });
    appFoldersTree.addCollapseListener(new Tree.CollapseListener() {

        @Override
        public void nodeCollapse(Tree.CollapseEvent event) {
            AppFolder folder = (AppFolder) event.getItemId();
            if (StringUtils.isBlank(folder.getQuantityScript())) {
                reloadSingleParentFolder(folder, null);
                setFolderTreeItemCaption(appFoldersTree, folder);
            }
        }
    });
    appFoldersRoot = messages.getMainMessage("folders.appFoldersRoot");
    fillTree(appFoldersTree, appFolders, isNeedRootAppFolder() ? appFoldersRoot : null);
    appFoldersTree.addItemClickListener(new FolderClickListener());
    appFoldersTree.addActionHandler(new AppFolderActionsHandler());
    for (Object itemId : appFoldersTree.rootItemIds()) {
        appFoldersTree.expandItemsRecursively(itemId);
    }
    return appFoldersTree;
}
Also used : CubaTree(com.haulmont.cuba.web.toolkit.ui.CubaTree) AppFolder(com.haulmont.cuba.core.entity.AppFolder) ShortcutListener(com.vaadin.event.ShortcutListener) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) CubaTree(com.haulmont.cuba.web.toolkit.ui.CubaTree)

Example 10 with ShortcutListener

use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.

the class ServerLogWindow method init.

@Override
public void init(Map<String, Object> params) {
    localJmxField.setValue(jmxControlAPI.getLocalNodeName());
    localJmxField.setEditable(false);
    localJmxInstance = jmxControlAPI.getLocalInstance();
    jmxInstancesDs.refresh();
    jmxConnectionField.setValue(localJmxInstance);
    jmxConnectionField.setRequired(true);
    jmxConnectionField.addValueChangeListener(e -> {
        JmxInstance 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()));
        Collections.sort(currentLoggers);
        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"));
    ComboBox comboBox = logFileNameField.unwrap(ComboBox.class);
    comboBox.addShortcutListener(new ShortcutListener("", KeyCode.D, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }) {

        @Override
        public void handleAction(Object sender, Object target) {
            downloadLog();
        }
    });
    comboBox.addShortcutListener(new ShortcutListener("", KeyCode.S, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }) {

        @Override
        public void handleAction(Object sender, Object target) {
            showLogTail();
        }
    });
    downloadButton.setDescription("CTRL-SHIFT-D");
    showTailButton.setDescription("CTRL-SHIFT-S");
}
Also used : LookupAction(com.haulmont.cuba.gui.components.PickerField.LookupAction) StringUtils(org.apache.commons.lang.StringUtils) 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) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) 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) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) IOException(java.io.IOException) JmxRemoteLoggingAPI(com.haulmont.cuba.web.jmx.JmxRemoteLoggingAPI) CubaScrollBoxLayout(com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) Level(ch.qos.logback.classic.Level) ModifierKey(com.vaadin.event.ShortcutAction.ModifierKey) StringReader(java.io.StringReader) AppConfig(com.haulmont.cuba.gui.AppConfig) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) ShortcutListener(com.vaadin.event.ShortcutListener) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) BufferedReader(java.io.BufferedReader) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ComboBox(com.vaadin.ui.ComboBox) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) ShortcutListener(com.vaadin.event.ShortcutListener) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Aggregations

ShortcutListener (com.vaadin.event.ShortcutListener)15 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)3 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)2 Entity (com.haulmont.cuba.core.entity.Entity)2 KeyCombination (com.haulmont.cuba.gui.components.KeyCombination)2 CubaTree (com.haulmont.cuba.web.toolkit.ui.CubaTree)2 AbstractComponent (com.vaadin.ui.AbstractComponent)2 Component (com.vaadin.ui.Component)2 CssLayout (com.vaadin.ui.CssLayout)2 Level (ch.qos.logback.classic.Level)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 AppFolder (com.haulmont.cuba.core.entity.AppFolder)1 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 Security (com.haulmont.cuba.core.global.Security)1 LogArchiver (com.haulmont.cuba.core.sys.logging.LogArchiver)1 LogControlException (com.haulmont.cuba.core.sys.logging.LogControlException)1 LoggingHelper (com.haulmont.cuba.core.sys.logging.LoggingHelper)1 AppConfig (com.haulmont.cuba.gui.AppConfig)1 DialogParams (com.haulmont.cuba.gui.DialogParams)1