public boolean saveUser(BeanFieldGroup<User> fieldGroup, String clearPass) throws FieldGroup.CommitException, BLException { fieldGroup.commit(); BeanItem<User> item = fieldGroup.getItemDataSource(); try { return (boolean) DB.execWithTransaction( (db) -> { User u = item.getBean(); db.save(u); if (clearPass != null && !clearPass.isEmpty()) { UserManager mgr = new UserManager(db); try { mgr.setPassword(u, clearPass); } catch (BLException e) { return false; } addRevisionCreated( db, getEntityName(), item.getItemProperty("id").getValue().toString()); u.setForcePasswordChange(true); db.session().update(u); return true; } return false; }); } catch (Exception e) { getApp().getLog().error(e); return false; } }
protected Panel createTextFieldPanel(ConfigurationParameter parameter, Validator validator) { Panel paramPanel = new Panel(); paramPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); paramPanel.setWidth("100%"); GridLayout paramLayout = new GridLayout(3, 3); paramLayout.setSpacing(true); paramLayout.setSizeFull(); paramLayout.setMargin(true); paramLayout.setColumnExpandRatio(0, .25f); paramLayout.setColumnExpandRatio(1, .75f); Label configLabel = new Label("Platform Configuration"); configLabel.addStyleName(ValoTheme.LABEL_HUGE); configLabel.setSizeUndefined(); paramLayout.addComponent(configLabel, 0, 0, 1, 0); paramLayout.setComponentAlignment(configLabel, Alignment.TOP_LEFT); Label label = new Label(parameter.getName()); label.setIcon(VaadinIcons.COG); label.addStyleName(ValoTheme.LABEL_LARGE); label.addStyleName(ValoTheme.LABEL_BOLD); label.setSizeUndefined(); paramLayout.addComponent(label, 0, 1, 1, 1); paramLayout.setComponentAlignment(label, Alignment.TOP_LEFT); logger.info(parameter.getName() + " " + parameter.getValue()); Label valueLabel = new Label("Value:"); valueLabel.setSizeUndefined(); usernameField = new TextField(); usernameField.addValidator(validator); usernameField.setNullSettingAllowed(true); usernameField.setNullRepresentation(""); usernameField.setValidationVisible(false); usernameField.setWidth("80%"); usernameField.setId(parameter.getName()); if (parameter instanceof ConfigurationParameterIntegerImpl) { StringToIntegerConverter plainIntegerConverter = new StringToIntegerConverter() { protected java.text.NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; }; }; // either set for the field or in your field factory for multiple fields usernameField.setConverter(plainIntegerConverter); } else if (parameter instanceof ConfigurationParameterLongImpl) { StringToLongConverter plainLongConverter = new StringToLongConverter() { protected java.text.NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; }; }; // either set for the field or in your field factory for multiple fields usernameField.setConverter(plainLongConverter); } BeanItem<ConfigurationParameter> parameterItem = new BeanItem<ConfigurationParameter>(parameter); if (parameter.getValue() != null) { usernameField.setPropertyDataSource(parameterItem.getItemProperty("value")); } paramLayout.addComponent(valueLabel, 0, 2); paramLayout.addComponent(usernameField, 1, 2); paramLayout.setComponentAlignment(valueLabel, Alignment.TOP_RIGHT); paramPanel.setContent(paramLayout); return paramPanel; }