Search in sources :

Example 11 with ClientConfig

use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.

the class UserEditor method preCommit.

@Override
protected boolean preCommit() {
    User user = getItem();
    if (PersistenceHelper.isNew(user)) {
        String password = passwField.getValue();
        String passwordConfirmation = confirmPasswField.getValue();
        if (passwField.isRequired() && (StringUtils.isBlank(password) || StringUtils.isBlank(passwordConfirmation))) {
            showNotification(getMessage("emptyPassword"), NotificationType.WARNING);
            return false;
        } else {
            if (Objects.equals(password, passwordConfirmation)) {
                if (StringUtils.isNotEmpty(password)) {
                    ClientConfig passwordPolicyConfig = configuration.getConfig(ClientConfig.class);
                    if (passwordPolicyConfig.getPasswordPolicyEnabled()) {
                        String regExp = passwordPolicyConfig.getPasswordPolicyRegExp();
                        if (!password.matches(regExp)) {
                            showNotification(getMessage("simplePassword"), NotificationType.WARNING);
                            return false;
                        }
                    }
                    String passwordHash = passwordEncryption.getPasswordHash(user.getId(), password);
                    user.setPassword(passwordHash);
                }
            } else {
                showNotification(getMessage("passwordsDoNotMatch"), NotificationType.WARNING);
                return false;
            }
        }
    }
    boolean isDsModified = rolesDs.isModified();
    Collection<UserRole> userRoles = new ArrayList<>(rolesDs.getItems());
    for (UserRole userRole : userRoles) {
        if (userRole.getRole() != null && userRole.getRole().isPredefined()) {
            if (userRole.getRoleName() == null) {
                userRole.setRoleName(userRole.getRole().getName());
            }
            userRole.setRole(null);
            rolesDs.modifyItem(userRole);
        }
    }
    for (Object itemToDelete : ((AbstractDatasource) rolesDs).getItemsToDelete()) {
        if (itemToDelete instanceof UserRole && ((UserRole) itemToDelete).getRoleName() != null) {
            ((UserRole) itemToDelete).setRole(null);
        }
    }
    ((AbstractDatasource) rolesDs).setModified(isDsModified);
    if (rolesDs.isModified()) {
        @SuppressWarnings("unchecked") DatasourceImplementation<UserRole> rolesDsImpl = (DatasourceImplementation) rolesDs;
        CommitContext ctx = new CommitContext(Collections.emptyList(), rolesDsImpl.getItemsToDelete());
        dataSupplier.commit(ctx);
        List<UserRole> modifiedRoles = new ArrayList<>(rolesDsImpl.getItemsToCreate());
        modifiedRoles.addAll(rolesDsImpl.getItemsToUpdate());
        rolesDsImpl.committed(Collections.emptySet());
        for (UserRole userRole : modifiedRoles) {
            rolesDsImpl.modified(userRole);
        }
    }
    return true;
}
Also used : AbstractDatasource(com.haulmont.cuba.gui.data.impl.AbstractDatasource) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 12 with ClientConfig

use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.

the class WebLayoutAnalyzerContextMenuProvider method initContextMenu.

@Override
public void initContextMenu(Window window, Component contextMenuTarget) {
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    if (clientConfig.getLayoutAnalyzerEnabled()) {
        ContextMenu contextMenu = new ContextMenu(contextMenuTarget.unwrap(AbstractComponent.class), true);
        MenuItem menuItem = contextMenu.addItem(messages.getMainMessage("actions.analyzeLayout"), c -> {
            LayoutAnalyzer analyzer = new LayoutAnalyzer();
            List<LayoutTip> tipsList = analyzer.analyze(window);
            if (tipsList.isEmpty()) {
                window.showNotification("No layout problems found", NotificationType.HUMANIZED);
            } else {
                window.openWindow("layoutAnalyzer", OpenType.DIALOG, ParamsMap.of("tipsList", tipsList));
            }
        });
        menuItem.setStyleName("c-cm-item");
    }
}
Also used : AbstractComponent(com.vaadin.ui.AbstractComponent) LayoutTip(com.haulmont.cuba.gui.app.core.dev.LayoutTip) ContextMenu(com.haulmont.cuba.web.widgets.addons.contextmenu.ContextMenu) MenuItem(com.vaadin.ui.MenuBar.MenuItem) LayoutAnalyzer(com.haulmont.cuba.gui.app.core.dev.LayoutAnalyzer) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 13 with ClientConfig

use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.

the class MainTabSheetActionHandler method getActions.

@Override
public Action[] getActions(Object target, Object sender) {
    if (!initialized) {
        Messages messages = AppBeans.get(Messages.NAME);
        closeAllTabs = new com.vaadin.event.Action(messages.getMainMessage("actions.closeAllTabs"));
        closeOtherTabs = new com.vaadin.event.Action(messages.getMainMessage("actions.closeOtherTabs"));
        closeCurrentTab = new com.vaadin.event.Action(messages.getMainMessage("actions.closeCurrentTab"));
        showInfo = new com.vaadin.event.Action(messages.getMainMessage("actions.showInfo"));
        analyzeLayout = new com.vaadin.event.Action(messages.getMainMessage("actions.analyzeLayout"));
        saveSettings = new com.vaadin.event.Action(messages.getMainMessage("actions.saveSettings"));
        restoreToDefaults = new com.vaadin.event.Action(messages.getMainMessage("actions.restoreToDefaults"));
        initialized = true;
    }
    List<Action> actions = new ArrayList<>(5);
    actions.add(closeCurrentTab);
    actions.add(closeOtherTabs);
    actions.add(closeAllTabs);
    if (target != null) {
        Configuration configuration = AppBeans.get(Configuration.NAME);
        ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
        if (clientConfig.getManualScreenSettingsSaving()) {
            actions.add(saveSettings);
            actions.add(restoreToDefaults);
        }
        UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
        UserSession userSession = sessionSource.getUserSession();
        if (userSession.isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION) && findEditor((Layout) target) != null) {
            actions.add(showInfo);
        }
        if (clientConfig.getLayoutAnalyzerEnabled()) {
            actions.add(analyzeLayout);
        }
    }
    return actions.toArray(new Action[0]);
}
Also used : Action(com.vaadin.event.Action) ShowInfoAction(com.haulmont.cuba.gui.components.sys.ShowInfoAction) Action(com.vaadin.event.Action) UserSession(com.haulmont.cuba.security.global.UserSession) ArrayList(java.util.ArrayList) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 14 with ClientConfig

use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.

the class WebAppWorkArea method createPreviousWindowTabShortcut.

protected ShortcutListener createPreviousWindowTabShortcut(RootWindow topLevelWindow) {
    Configuration configuration = beanLocator.get(Configuration.NAME);
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    String previousTabShortcut = clientConfig.getPreviousTabShortcut();
    KeyCombination combination = KeyCombination.create(previousTabShortcut);
    return new ShortcutListenerDelegate("onPreviousTab", 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 selectedTabId = tabSheet.getTab(selectedTabComponent);
            int tabPosition = tabSheet.getTabPosition(selectedTabId);
            int newTabPosition = (tabSheet.getComponentCount() + 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 15 with ClientConfig

use of com.haulmont.cuba.client.ClientConfig in project cuba by cuba-platform.

the class ScreenValidation method showValidationErrors.

/**
 * Show validation alert with passed errors and first problem UI component.
 *
 * @param origin screen controller
 * @param errors validation error
 */
public void showValidationErrors(FrameOwner origin, ValidationErrors errors) {
    checkNotNullArgument(origin);
    checkNotNullArgument(errors);
    if (errors.isEmpty()) {
        return;
    }
    StringBuilder buffer = new StringBuilder();
    for (ValidationErrors.Item error : errors.getAll()) {
        buffer.append(error.description).append("\n");
    }
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    String validationNotificationType = clientConfig.getValidationNotificationType();
    if (validationNotificationType.endsWith("_HTML")) {
        // HTML validation notification types are not supported
        validationNotificationType = validationNotificationType.replace("_HTML", "");
    }
    Notifications notifications = getScreenContext(origin).getNotifications();
    notifications.create(NotificationType.valueOf(validationNotificationType)).withCaption(messages.getMainMessage("validationFail.caption")).withDescription(buffer.toString()).show();
    focusProblemComponent(errors);
}
Also used : ClientConfig(com.haulmont.cuba.client.ClientConfig) Notifications(com.haulmont.cuba.gui.Notifications)

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