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;
}
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");
}
}
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]);
}
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);
}
});
}
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);
}
Aggregations