@Override protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) { final Locale aDisplayLocale = aWPEC.getDisplayLocale(); final HCNodeList aNodeList = aWPEC.getNodeList(); // Toolbar on top final IButtonToolbar<?> aToolbar = aNodeList.addAndReturnChild(getStyler().createToolbar()); aToolbar.addButtonNew( EText.BUTTON_CREATE_NEW_USER.getDisplayText(aDisplayLocale), createCreateURL(aWPEC)); final ITabBox<?> aTabBox = getStyler().createTabBox(); final AccessManager aMgr = AccessManager.getInstance(); final Collection<? extends IUser> aActiveUsers = aMgr.getAllActiveUsers(); aTabBox.addTab( EText.TAB_ACTIVE.getDisplayTextWithArgs( aDisplayLocale, Integer.toString(aActiveUsers.size())), getTabWithUsers(aDisplayLocale, aActiveUsers, getID() + "1")); final Collection<? extends IUser> aDisabledUsers = aMgr.getAllDisabledUsers(); aTabBox.addTab( EText.TAB_DISABLED.getDisplayTextWithArgs( aDisplayLocale, Integer.toString(aDisabledUsers.size())), getTabWithUsers(aDisplayLocale, aDisabledUsers, getID() + "2")); final Collection<? extends IUser> aDeletedUsers = aMgr.getAllDeletedUsers(); aTabBox.addTab( EText.TAB_DELETED.getDisplayTextWithArgs( aDisplayLocale, Integer.toString(aDeletedUsers.size())), getTabWithUsers(aDisplayLocale, aDeletedUsers, getID() + "3")); aNodeList.addChild(aTabBox); }
/** * Create toolbar for viewing an existing object. Contains the back button and the edit button. * * @param aWPEC The display locale to use * @param bCanGoBack true to enable back button * @param bCanEdit true to enable edit button * @param aSelectedObject The selected object * @return Never <code>null</code>. */ @Nonnull @OverrideOnDemand protected IButtonToolbar<?> createViewToolbar( @Nonnull final WPECTYPE aWPEC, final boolean bCanGoBack, final boolean bCanEdit, @Nonnull final DATATYPE aSelectedObject) { final IButtonToolbar<?> aToolbar = createNewViewToolbar(aWPEC); if (bCanGoBack) { // Back to list aToolbar.addButtonBack(aWPEC.getDisplayLocale()); } if (bCanEdit) { // Edit object aToolbar.addButtonEdit(aWPEC.getDisplayLocale(), createEditURL(aWPEC, aSelectedObject)); } modifyViewToolbar(aWPEC, aSelectedObject, aToolbar); return aToolbar; }
/** * Create toolbar for editing an existing object * * @param aWPEC The web page execution context. Never <code>null</code>. * @param aForm The handled form. Never <code>null</code>. * @param aSelectedObject The selected object. Never <code>null</code>. * @return Never <code>null</code>. */ @Nonnull @OverrideOnDemand protected IButtonToolbar<?> createEditToolbar( @Nonnull final WPECTYPE aWPEC, @Nonnull final HCForm aForm, @Nonnull final DATATYPE aSelectedObject) { final IButtonToolbar<?> aToolbar = createNewEditToolbar(aWPEC); aToolbar.addHiddenField(CHCParam.PARAM_ACTION, ACTION_EDIT); aToolbar.addHiddenField(CHCParam.PARAM_OBJECT, aSelectedObject.getID()); aToolbar.addHiddenField(CHCParam.PARAM_SUBACTION, ACTION_SAVE); // Save button aToolbar.addSubmitButtonSave(aWPEC.getDisplayLocale()); // Cancel button aToolbar.addButtonCancel(aWPEC.getDisplayLocale()); modifyEditToolbar(aWPEC, aSelectedObject, aToolbar); return aToolbar; }
@Override protected boolean handleCustomActions( @Nonnull final WebPageExecutionContext aWPEC, @Nullable final IUser aSelectedObject) { if (aWPEC.hasAction(ACTION_RESET_PASSWORD) && aSelectedObject != null) { if (!canResetPassword(aSelectedObject)) throw new IllegalStateException("Won't work!"); final Locale aDisplayLocale = aWPEC.getDisplayLocale(); final boolean bShowForm = true; final FormErrors aFormErrors = new FormErrors(); if (aWPEC.hasSubAction(ACTION_PERFORM)) { final String sPlainTextPassword = aWPEC.getAttr(FIELD_PASSWORD); final String sPlainTextPasswordConfirm = aWPEC.getAttr(FIELD_PASSWORD_CONFIRM); final List<String> aPasswordErrors = GlobalPasswordSettings.getPasswordConstraintList() .getInvalidPasswordDescriptions(sPlainTextPassword, aDisplayLocale); for (final String sPasswordError : aPasswordErrors) aFormErrors.addFieldError(FIELD_PASSWORD, sPasswordError); if (!EqualsUtils.equals(sPlainTextPassword, sPlainTextPasswordConfirm)) aFormErrors.addFieldError( FIELD_PASSWORD_CONFIRM, EText.ERROR_PASSWORDS_DONT_MATCH.getDisplayText(aDisplayLocale)); if (aFormErrors.isEmpty()) { AccessManager.getInstance().setUserPassword(aSelectedObject.getID(), sPlainTextPassword); aWPEC .getNodeList() .addChild( getStyler() .createSuccessBox( EText.SUCCESS_RESET_PASSWORD.getDisplayTextWithArgs( aDisplayLocale, SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale)))); return true; } } if (bShowForm) { // Show input form final boolean bHasAnyPasswordConstraint = GlobalPasswordSettings.getPasswordConstraintList().hasConstraints(); final HCForm aForm = aWPEC.getNodeList().addAndReturnChild(createFormSelf()); final IHCTableForm<?> aTable = aForm.addAndReturnChild( getStyler().createTableForm(new HCCol(200), HCCol.star(), new HCCol(20))); aTable.setSpanningHeaderContent( EText.TITLE_RESET_PASSWORD.getDisplayTextWithArgs( aDisplayLocale, SecurityUI.getUserDisplayName(aSelectedObject, aDisplayLocale))); final String sPassword = EText.LABEL_PASSWORD.getDisplayText(aDisplayLocale); aTable .createItemRow() .setLabel( sPassword, bHasAnyPasswordConstraint ? ELabelType.MANDATORY : ELabelType.OPTIONAL) .setCtrl(new HCEditPassword(FIELD_PASSWORD).setPlaceholder(sPassword)) .setNote(SecurityUI.createPasswordConstraintTip(aDisplayLocale)) .setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD)); final String sPasswordConfirm = EText.LABEL_PASSWORD_CONFIRM.getDisplayText(aDisplayLocale); aTable .createItemRow() .setLabel( sPasswordConfirm, bHasAnyPasswordConstraint ? ELabelType.MANDATORY : ELabelType.OPTIONAL) .setCtrl(new HCEditPassword(FIELD_PASSWORD_CONFIRM).setPlaceholder(sPasswordConfirm)) .setNote(SecurityUI.createPasswordConstraintTip(aDisplayLocale)) .setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD_CONFIRM)); final IButtonToolbar<?> aToolbar = aForm.addAndReturnChild(getStyler().createToolbar()); aToolbar.addHiddenField(CHCParam.PARAM_ACTION, ACTION_RESET_PASSWORD); aToolbar.addHiddenField(CHCParam.PARAM_OBJECT, aSelectedObject.getID()); aToolbar.addHiddenField(CHCParam.PARAM_SUBACTION, ACTION_PERFORM); aToolbar.addSubmitButtonSave(aDisplayLocale); aToolbar.addButtonCancel(aDisplayLocale); } return false; } return true; }