Example usage for org.apache.wicket.markup.html.form IChoiceRenderer IChoiceRenderer

List of usage examples for org.apache.wicket.markup.html.form IChoiceRenderer IChoiceRenderer

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form IChoiceRenderer IChoiceRenderer.

Prototype

IChoiceRenderer

Source Link

Usage

From source file:ca.travelagency.components.fields.GenericDropDownChoice.java

License:Apache License

IChoiceRenderer<T> makeRenderer() {
    return new IChoiceRenderer<T>() {
        private static final long serialVersionUID = 1L;

        @Override// w  ww. ja  v  a2  s .com
        public Object getDisplayValue(T daoEntity) {
            return daoEntity.getName();
        }

        @Override
        public String getIdValue(T daoEntity, int index) {
            return "" + daoEntity.getId();
        }
    };
}

From source file:ch.bd.qv.quiz.panels.CheckQuestionPanel.java

License:Apache License

public CheckQuestionPanel(String inner, CheckQuestion bq) {
    super(inner, bq);
    this.checkQuestion = bq;
    add(new CheckBoxMultipleChoice<>("checkboxes", model,
            Lists.newArrayList(checkQuestion.getAnswerKeys().iterator()), new IChoiceRenderer<String>() {
                @Override/*from w  w w.j  av a 2 s.com*/
                public Object getDisplayValue(String object) {
                    return new StringResourceModel(object, CheckQuestionPanel.this, null).getObject();
                }

                @Override
                public String getIdValue(String object, int index) {
                    return new StringResourceModel(object, CheckQuestionPanel.this, null).getObject();
                }
            }).setRequired(true));
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

private DropDownChoice<Integer> getCurrentMessageIdDropdown() {

    IChoiceRenderer<Integer> messageConfigRender = new IChoiceRenderer<Integer>() {
        @Override// w ww  .  java  2  s .  c  o m
        public Object getDisplayValue(Integer object) {
            return String.format("%d - %s", object, getConfig().getMessageConfig(object).getMessageAlias());
        }

        @Override
        public String getIdValue(Integer object, int index) {
            return object.toString();
        }
    };

    IModel<List<Integer>> messageListModel = new LoadableDetachableModel<List<Integer>>() {
        @Override
        protected List<Integer> load() {
            List<MessageConfig> messages = getConfig().getMessageList();
            List<Integer> list = new ArrayList<Integer>(messages.size());
            for (MessageConfig messageConfig : messages) {
                list.add(messageConfig.getMessageId());
            }
            return list;
        }
    };

    DropDownChoice<Integer> dropDown = new DropDownChoice<Integer>("currentMessage",
            new PropertyModel<Integer>(this, "currentMessageId"), messageListModel, messageConfigRender);

    dropDown.add(new AjaxFormSubmitBehavior("onchange") {

        @Override
        protected void onSubmit(final AjaxRequestTarget target) {

            // Reset feedback messages
            target.addChildren(getPage(), FeedbackPanel.class);

            // Change the current message
            currentMessage = getConfig().getMessageConfig(currentMessageId);
            currentMessage.calcOffsets(getConfig().getMessageIdType().getByteSize());

            // Refresh the form
            updateForm(target);
        }

        @Override
        protected void onError(final AjaxRequestTarget target) {
            // Add the drop down to revert the changed selection
            target.add(getComponent());

            handleError(target);
        };
    });

    dropDown.add(new AjaxIndicatorAppender());
    dropDown.setOutputMarkupId(true);

    return dropDown;
}

From source file:com.cubeia.backoffice.web.user.CreateUser.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
* 
* @param parameters//from  w ww .jav a2  s  .c om
*            Page parameters
*/
public CreateUser(final PageParameters parameters) {
    resetFormData();

    Form<?> userForm = new Form<Void>("userForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            CreateUserRequest createUserData = new CreateUserRequest(user, password);
            CreateUserResponse createResponse = userService.createUser(createUserData);

            if (createResponse.getStatus() != OK) {
                error("Error creating user: " + createResponse.getStatus().name());
                return;
            }

            User createdUser = createResponse.getUser();
            log.debug("created user id = " + createdUser.getUserId());
            setResponsePage(EditUser.class, params(EditUser.PARAM_USER_ID, createdUser.getUserId()));
        }
    };

    CompoundPropertyModel<CreateUser> cpm = new CompoundPropertyModel<CreateUser>(this);

    userForm.add(new RequiredTextField<String>("userName", cpm.<String>bind("user.userName")));
    userForm.add(new TextField<String>("externalUserId", cpm.<String>bind("user.externalUserId")));
    userForm.add(new RequiredTextField<Long>("operatorId", cpm.<Long>bind("user.operatorId")));

    final RequiredTextField<String> passwordField = new RequiredTextField<String>("password",
            cpm.<String>bind("password"));
    final RequiredTextField<String> passwordConfirmField = new RequiredTextField<String>("passwordConfirm",
            cpm.<String>bind("passwordConfirm"));
    userForm.add(passwordField);
    userForm.add(passwordConfirmField);
    userForm.add(new EqualPasswordInputValidator(passwordField, passwordConfirmField));

    userForm.add(new TextField<String>("firstName", cpm.<String>bind("user.userInformation.firstName")));
    userForm.add(new TextField<String>("lastName", cpm.<String>bind("user.userInformation.lastName")));
    userForm.add(new TextField<String>("email", cpm.<String>bind("user.userInformation.email"))
            .add(EmailAddressValidator.getInstance()));
    userForm.add(new TextField<String>("title", cpm.<String>bind("user.userInformation.title")));
    userForm.add(new TextField<String>("city", cpm.<String>bind("user.userInformation.city")));
    userForm.add(
            new TextField<String>("billingAddress", cpm.<String>bind("user.userInformation.billingAddress")));
    userForm.add(new TextField<String>("fax", cpm.<String>bind("user.userInformation.fax")));
    userForm.add(new TextField<String>("cellphone", cpm.<String>bind("user.userInformation.cellphone")));
    userForm.add(new DropDownChoice<String>("country", cpm.<String>bind("user.userInformation.country"),
            Arrays.asList(Locale.getISOCountries()), new IChoiceRenderer<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getDisplayValue(String isoCountry) {
                    return new Locale(Locale.ENGLISH.getLanguage(), (String) isoCountry)
                            .getDisplayCountry(Locale.ENGLISH);
                }

                @Override
                public String getIdValue(String isoCountry, int id) {
                    return "" + id;
                }
            }));

    userForm.add(new TextField<String>("zipcode", cpm.<String>bind("user.userInformation.zipcode")));
    userForm.add(new TextField<String>("state", cpm.<String>bind("user.userInformation.state")));
    userForm.add(new TextField<String>("phone", cpm.<String>bind("user.userInformation.phone")));
    userForm.add(new TextField<String>("workphone", cpm.<String>bind("user.userInformation.workphone")));
    userForm.add(new DropDownChoice<Gender>("gender", cpm.<Gender>bind("user.userInformation.gender"),
            Arrays.asList(Gender.values())));

    add(userForm);
    add(new FeedbackPanel("feedback"));
}

From source file:com.cubeia.backoffice.web.user.EditUser.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
* 
* @param parameters/*from  w  w  w  . j  a v  a 2 s  .  com*/
*            Page parameters
*/
public EditUser(PageParameters params) {
    if (!assertValidUserid(params)) {
        return;
    }

    final Long userId = params.get(PARAM_USER_ID).toLongObject();
    loadFormData(userId);

    if (getUser() == null || getUser().getStatus() == UserStatus.REMOVED) {
        log.debug("user is removed, id = " + userId);
        setInvalidUserResponsePage(userId);
        return;
    }

    add(createBlockActionLink(userId));

    add(new Link<Void>("removeActionLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            userService.setUserStatus(userId, UserStatus.REMOVED);
            setInvalidUserResponsePage(userId);
        }
    });

    Form<?> userForm = new Form<Void>("userForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            userService.updateUser(user);
            info("User updated, id = " + user.getUserId());
            loadFormData(userId);
        }
    };

    CompoundPropertyModel<?> cpm = new CompoundPropertyModel<EditUser>(this);

    userForm.add(new Label(PARAM_USER_ID, cpm.bind("user.userId")));
    userForm.add(new Label("status", cpm.bind("user.status")));
    userForm.add(new TextField<Long>("operatorId", cpm.<Long>bind("user.operatorId")).setEnabled(false));
    userForm.add(new TextField<String>("externalUserId", cpm.<String>bind("user.externalUserId")));
    userForm.add(new TextField<String>("userName", cpm.<String>bind("user.userName")));
    userForm.add(new TextField<String>("firstName", cpm.<String>bind("user.userInformation.firstName")));
    userForm.add(new TextField<String>("lastName", cpm.<String>bind("user.userInformation.lastName")));
    userForm.add(new TextField<String>("email", cpm.<String>bind("user.userInformation.email"))
            .add(EmailAddressValidator.getInstance()));
    userForm.add(new TextField<String>("title", cpm.<String>bind("user.userInformation.title")));
    userForm.add(new TextField<String>("city", cpm.<String>bind("user.userInformation.city")));
    userForm.add(
            new TextField<String>("billingAddress", cpm.<String>bind("user.userInformation.billingAddress")));
    userForm.add(new TextField<String>("fax", cpm.<String>bind("user.userInformation.fax")));
    userForm.add(new TextField<String>("cellphone", cpm.<String>bind("user.userInformation.cellphone")));
    userForm.add(new DropDownChoice<String>("country", cpm.<String>bind("user.userInformation.country"),
            Arrays.asList(Locale.getISOCountries()), new IChoiceRenderer<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getDisplayValue(String isoCountry) {
                    return new Locale(Locale.ENGLISH.getLanguage(), (String) isoCountry)
                            .getDisplayCountry(Locale.ENGLISH);
                }

                @Override
                public String getIdValue(String isoCountry, int id) {
                    return "" + id;
                }
            }));

    userForm.add(new TextField<String>("zipcode", cpm.<String>bind("user.userInformation.zipcode")));
    userForm.add(new TextField<String>("state", cpm.<String>bind("user.userInformation.state")));
    userForm.add(new TextField<String>("phone", cpm.<String>bind("user.userInformation.phone")));
    userForm.add(new TextField<String>("workphone", cpm.<String>bind("user.userInformation.workphone")));
    userForm.add(new DropDownChoice<Gender>("gender", cpm.<Gender>bind("user.userInformation.gender"),
            Arrays.asList(Gender.values())));
    userForm.add(createAttributesListView());
    add(userForm);

    Form<?> addAttributeForm = new Form<Void>("addAttrForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            if (user.getAttributes() == null) {
                user.setAttributes(new HashMap<String, String>());
            }
            if (getNewAttributeKey() != null) {
                user.getAttributes().put("" + getNewAttributeKey(), "" + getNewAttributeValue());
            }
            setNewAttributeKey(null);
            setNewAttributeValue(null);
        }
    };
    addAttributeForm.add(new SubmitLink("addAttrLink").add(new Label("addAttrLabel", "Add attribute")));
    addAttributeForm.add(new TextField<String>("newAttrKey", cpm.<String>bind("newAttributeKey")));
    addAttributeForm.add(new TextField<String>("newAttrValue", cpm.<String>bind("newAttributeValue")));
    userForm.add(addAttributeForm);

    Form<?> pwdForm = new Form<Void>("changePasswordForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            userService.updatePassword(user.getUserId(), getPassword1());
            setPassword1(null);
            setPassword2(null);
        }
    };
    PasswordTextField pwd1 = new PasswordTextField("password1", cpm.<String>bind("password1"));
    PasswordTextField pwd2 = new PasswordTextField("password2", cpm.<String>bind("password2"));
    pwdForm.add(new EqualPasswordInputValidator(pwd1, pwd2));
    pwdForm.add(pwd1);
    pwdForm.add(pwd2);
    add(pwdForm);

    add(new FeedbackPanel("feedback"));
}

From source file:com.cubeia.games.poker.admin.wicket.pages.tournaments.configuration.TournamentConfigurationPanel.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
public TournamentConfigurationPanel(String id, Form<?> form,
        PropertyModel<TournamentConfiguration> propertyModel, boolean sitAndGo) {
    super(id, propertyModel);
    this.model = propertyModel;
    add(new RequiredTextField<String>("name", new PropertyModel(model, "name")));
    add(new RequiredTextField<Integer>("seatsPerTable", new PropertyModel(model, "seatsPerTable")));
    DropDownChoice<TimingProfile> timing = new DropDownChoice<TimingProfile>("timingType", model("timingType"),
            adminDAO.getTimingProfiles(), renderer("name"));
    timing.setRequired(true);/*w  w  w. j a v  a  2s. c  o m*/
    add(timing);
    TextField<Integer> minPlayers = new TextField<Integer>("minPlayers",
            new PropertyModel(model, "minPlayers"));
    minPlayers.add(RangeValidator.minimum(2));
    add(minPlayers);
    TextField<Integer> maxPlayers = new TextField<Integer>("maxPlayers",
            new PropertyModel(model, "maxPlayers"));
    maxPlayers.add(RangeValidator.minimum(2));
    add(maxPlayers);
    add(new RequiredTextField<BigDecimal>("buyIn", new PropertyModel(model, "buyIn")));
    add(new RequiredTextField<BigDecimal>("fee", new PropertyModel(model, "fee")));
    add(new RequiredTextField<BigDecimal>("guaranteedPrizePool",
            new PropertyModel(model, "guaranteedPrizePool")));
    add(new CheckBox("payoutAsBonus", new PropertyModel(model, "payOutAsBonus")));
    add(new RequiredTextField<BigDecimal>("startingChips", new PropertyModel(model, "startingChips")));
    DropDownChoice<BetStrategyType> strategy = new DropDownChoice<BetStrategyType>("betStrategy",
            new PropertyModel(model, "betStrategy"), asList(BetStrategyType.values()), renderer("name"));
    strategy.setRequired(true);
    add(strategy);

    DropDownChoice<PokerVariant> variant = new DropDownChoice<PokerVariant>("variant",
            new PropertyModel(model, "variant"), asList(PokerVariant.values()), renderer("name"));
    variant.setRequired(true);
    add(variant);
    form.add(new TournamentPlayersValidator(minPlayers, maxPlayers));

    final List<OperatorDTO> operators = networkClient.getOperators();

    add(new ListMultipleChoice<Long>("operatorIds", model("operatorIds"), getOperatorIds(operators),
            new IChoiceRenderer<Long>() {

                @Override
                public Object getDisplayValue(Long id) {
                    return getOperatorName(operators, id);
                }

                @Override
                public String getIdValue(Long object, int index) {
                    return object.toString();
                }
            }));
    TextField<String> userRule = new TextField<String>("userRuleExpression",
            new PropertyModel(model, "userRuleExpression"));
    add(userRule);

    DropDownChoice<String> currency = new DropDownChoice<String>("currency", model("currency"),
            networkClient.getCurrencies(), new ChoiceRenderer<String>());
    currency.setRequired(true);
    add(currency);
    DropDownChoice<BlindsStructure> blindsStructure = new DropDownChoice<BlindsStructure>("blindsStructure",
            model("blindsStructure"), adminDAO.getBlindsStructures(), renderer("name"));
    blindsStructure.setRequired(true);
    add(blindsStructure);
    DropDownChoice<PayoutStructure> payoutStructure = new DropDownChoice<PayoutStructure>("payoutStructure",
            model("payoutStructure"), adminDAO.getPayoutStructures(), renderer("name"));
    payoutStructure.setRequired(true);
    add(payoutStructure);

    if (sitAndGo) {
        maxPlayers.setVisible(false);
    }

    TextArea<String> description = new TextArea<String>("description", new PropertyModel(model, "description"));
    description.add(StringValidator.maximumLength(1000));
    add(description);
}

From source file:com.cubeia.games.poker.admin.wicket.pages.user.CreateUser.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
* 
* @param parameters//from   ww w. ja  v  a  2s  .  c om
*            Page parameters
*/
public CreateUser(final PageParameters parameters) {
    super(parameters);
    resetFormData();

    Form<?> userForm = new Form<Void>("userForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            CreateUserRequest createUserData = new CreateUserRequest(user, password);
            CreateUserResponse createResponse = userService.createUser(createUserData);

            if (createResponse.getStatus() != OK) {
                error("Error creating user: " + createResponse.getStatus().name());
                return;
            }

            User createdUser = createResponse.getUser();
            log.debug("created user id = " + createdUser.getUserId());
            setResponsePage(EditUser.class, params(EditUser.PARAM_USER_ID, createdUser.getUserId()));
        }
    };

    CompoundPropertyModel<CreateUser> cpm = new CompoundPropertyModel<CreateUser>(this);

    userForm.add(new RequiredTextField<String>("userName", cpm.<String>bind("user.userName")));
    userForm.add(new TextField<String>("externalUserId", cpm.<String>bind("user.externalUserId")));
    userForm.add(new RequiredTextField<Long>("operatorId", cpm.<Long>bind("user.operatorId")));

    final RequiredTextField<String> passwordField = new RequiredTextField<String>("password",
            cpm.<String>bind("password"));
    final RequiredTextField<String> passwordConfirmField = new RequiredTextField<String>("passwordConfirm",
            cpm.<String>bind("passwordConfirm"));
    userForm.add(passwordField);
    userForm.add(passwordConfirmField);
    userForm.add(new EqualPasswordInputValidator(passwordField, passwordConfirmField));

    userForm.add(new TextField<String>("firstName", cpm.<String>bind("user.userInformation.firstName")));
    userForm.add(new TextField<String>("lastName", cpm.<String>bind("user.userInformation.lastName")));
    userForm.add(new TextField<String>("email", cpm.<String>bind("user.userInformation.email"))
            .add(EmailAddressValidator.getInstance()));
    userForm.add(new TextField<String>("title", cpm.<String>bind("user.userInformation.title")));
    userForm.add(new TextField<String>("city", cpm.<String>bind("user.userInformation.city")));
    userForm.add(
            new TextField<String>("billingAddress", cpm.<String>bind("user.userInformation.billingAddress")));
    userForm.add(new TextField<String>("fax", cpm.<String>bind("user.userInformation.fax")));
    userForm.add(new TextField<String>("cellphone", cpm.<String>bind("user.userInformation.cellphone")));
    userForm.add(new DropDownChoice<String>("country", cpm.<String>bind("user.userInformation.country"),
            Arrays.asList(Locale.getISOCountries()), new IChoiceRenderer<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getDisplayValue(String isoCountry) {
                    return new Locale(Locale.ENGLISH.getLanguage(), (String) isoCountry)
                            .getDisplayCountry(Locale.ENGLISH);
                }

                @Override
                public String getIdValue(String isoCountry, int id) {
                    return "" + id;
                }
            }));

    userForm.add(new TextField<String>("zipcode", cpm.<String>bind("user.userInformation.zipcode")));
    userForm.add(new TextField<String>("state", cpm.<String>bind("user.userInformation.state")));
    userForm.add(new TextField<String>("phone", cpm.<String>bind("user.userInformation.phone")));
    userForm.add(new TextField<String>("workphone", cpm.<String>bind("user.userInformation.workphone")));
    userForm.add(new DropDownChoice<Gender>("gender", cpm.<Gender>bind("user.userInformation.gender"),
            Arrays.asList(Gender.values())));

    add(userForm);
    add(new FeedbackPanel("feedback"));
}

From source file:com.cubeia.games.poker.admin.wicket.pages.user.EditUser.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
* 
* @param parameters/*from w w w  . ja va2 s. c o  m*/
*            Page parameters
*/
public EditUser(PageParameters parameters) {
    super(parameters);
    if (!assertValidUserid(parameters)) {
        return;
    }

    final Long userId = parameters.get(PARAM_USER_ID).toLongObject();
    loadFormData(userId);

    if (getUser() == null || getUser().getStatus() == UserStatus.REMOVED) {
        log.debug("user is removed, id = " + userId);
        setInvalidUserResponsePage(userId);
        return;
    }

    add(createBlockActionLink(userId));

    add(new Link<Void>("removeActionLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            userService.setUserStatus(userId, UserStatus.REMOVED);
            setInvalidUserResponsePage(userId);
        }
    });

    Form<?> userForm = new Form<Void>("userForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            userService.updateUser(user);
            info("User updated, id = " + user.getUserId());
            loadFormData(userId);
        }
    };

    CompoundPropertyModel<?> cpm = new CompoundPropertyModel<EditUser>(this);

    userForm.add(new Label(PARAM_USER_ID, cpm.bind("user.userId")));
    userForm.add(new Label("status", cpm.bind("user.status")));
    userForm.add(new TextField<Long>("operatorId", cpm.<Long>bind("user.operatorId")).setEnabled(false));
    userForm.add(new TextField<String>("externalUserId", cpm.<String>bind("user.externalUserId")));
    userForm.add(new TextField<String>("userName", cpm.<String>bind("user.userName")));
    userForm.add(new TextField<String>("firstName", cpm.<String>bind("user.userInformation.firstName")));
    userForm.add(new TextField<String>("lastName", cpm.<String>bind("user.userInformation.lastName")));
    userForm.add(new TextField<String>("email", cpm.<String>bind("user.userInformation.email"))
            .add(EmailAddressValidator.getInstance()));
    userForm.add(new TextField<String>("title", cpm.<String>bind("user.userInformation.title")));
    userForm.add(new TextField<String>("city", cpm.<String>bind("user.userInformation.city")));
    userForm.add(
            new TextField<String>("billingAddress", cpm.<String>bind("user.userInformation.billingAddress")));
    userForm.add(new TextField<String>("fax", cpm.<String>bind("user.userInformation.fax")));
    userForm.add(new TextField<String>("cellphone", cpm.<String>bind("user.userInformation.cellphone")));
    userForm.add(new DropDownChoice<String>("country", cpm.<String>bind("user.userInformation.country"),
            Arrays.asList(Locale.getISOCountries()), new IChoiceRenderer<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getDisplayValue(String isoCountry) {
                    return new Locale(Locale.ENGLISH.getLanguage(), (String) isoCountry)
                            .getDisplayCountry(Locale.ENGLISH);
                }

                @Override
                public String getIdValue(String isoCountry, int id) {
                    return "" + id;
                }
            }));

    userForm.add(new TextField<String>("zipcode", cpm.<String>bind("user.userInformation.zipcode")));
    userForm.add(new TextField<String>("state", cpm.<String>bind("user.userInformation.state")));
    userForm.add(new TextField<String>("phone", cpm.<String>bind("user.userInformation.phone")));
    userForm.add(new TextField<String>("workphone", cpm.<String>bind("user.userInformation.workphone")));
    userForm.add(new DropDownChoice<Gender>("gender", cpm.<Gender>bind("user.userInformation.gender"),
            Arrays.asList(Gender.values())));
    userForm.add(createAttributesListView());
    add(userForm);

    Form<?> addAttributeForm = new Form<Void>("addAttrForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            if (user.getAttributes() == null) {
                user.setAttributes(new HashMap<String, String>());
            }
            if (getNewAttributeKey() != null) {
                user.getAttributes().put("" + getNewAttributeKey(), "" + getNewAttributeValue());
            }
            setNewAttributeKey(null);
            setNewAttributeValue(null);
        }
    };
    addAttributeForm.add(new SubmitLink("addAttrLink").add(new Label("addAttrLabel", "Add attribute")));
    addAttributeForm.add(new TextField<String>("newAttrKey", cpm.<String>bind("newAttributeKey")));
    addAttributeForm.add(new TextField<String>("newAttrValue", cpm.<String>bind("newAttributeValue")));
    userForm.add(addAttributeForm);

    Form<?> pwdForm = new Form<Void>("changePasswordForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            userService.updatePassword(user.getUserId(), getPassword1());
            setPassword1(null);
            setPassword2(null);
        }
    };
    PasswordTextField pwd1 = new PasswordTextField("password1", cpm.<String>bind("password1"));
    PasswordTextField pwd2 = new PasswordTextField("password2", cpm.<String>bind("password2"));
    pwdForm.add(new EqualPasswordInputValidator(pwd1, pwd2));
    pwdForm.add(pwd1);
    pwdForm.add(pwd2);
    add(pwdForm);

    add(new FeedbackPanel("feedback"));
}

From source file:com.doculibre.constellio.wicket.panels.search.advanced.AbstractSearchRulePanel.java

License:Open Source License

@SuppressWarnings("unchecked")
public AbstractSearchRulePanel(String id, final SimpleSearch search, final T rule, IModel ruleTypesChoice) {
    super(id);//from   w w w .j  a  v  a2  s .  c  om

    enabledRuleModel = new LoadableDetachableModel() {

        @Override
        protected Object load() {
            return getEnabledRuleFor(rule, search);
        }
    };

    SimpleSearch clonedSearch = search.clone();

    SimpleParams currentRuleParams = rule.toSimpleParams(true);

    List<RuleTypeChoice> baseChoices = (List<RuleTypeChoice>) ruleTypesChoice.getObject();
    RuleTypeChoice selectedChoice = null;
    List<RuleTypeChoice> adaptedChoices = new ArrayList<RuleTypeChoice>();
    for (RuleTypeChoice baseChoice : baseChoices) {
        boolean isSelected = true;
        RuleTypeChoice adaptedChoice = new RuleTypeChoice();
        adaptedChoice.name = baseChoice.name;
        clonedSearch.setAdvancedSearchRule(rule.getRootSearchRule());
        adaptedChoice.params.addAll(search.toSimpleParams(true));
        for (String param : baseChoice.params.keySet()) {
            String paramName = param.replace(SearchRule.ROOT_PREFIX, "");
            String adaptedName = rule.getPrefix() + paramName;
            String value = baseChoice.params.getString(param);

            adaptedChoice.params.remove(adaptedName);
            adaptedChoice.params.add(adaptedName, value);
            isSelected &= value.equals(currentRuleParams.getString(adaptedName));
        }

        if (isSelected) {
            selectedChoice = adaptedChoice;
        }
        adaptedChoices.add(adaptedChoice);
    }
    IChoiceRenderer renderer = new IChoiceRenderer() {

        @Override
        public Object getDisplayValue(Object object) {
            RuleTypeChoice choice = (RuleTypeChoice) object;
            return choice.name;
        }

        @Override
        public String getIdValue(Object object, int index) {
            RuleTypeChoice choice = (RuleTypeChoice) object;

            String url = urlFor(getPage().getClass(), SimpleParamsUtils.toPageParameters(choice.params))
                    .toString();
            return url;
        }

    };
    DropDownChoice typeSelect = new DropDownChoice("type", new Model(selectedChoice), adaptedChoices, renderer);
    typeSelect.add(new SimpleAttributeModifier("onChange",
            "goToUrl(this.value, '" + SearchRule.ROOT_PREFIX + "', '" + rule.getPrefix() + "')"));
    //We dont want this value to be submit, because it is very long and not usefull
    typeSelect.add(new SimpleAttributeModifier("name", ""));
    add(typeSelect);

    HiddenField searchRuleTypeHiddenField = new HiddenField("searchRuleType", new Model(getSearchRuleType()));
    searchRuleTypeHiddenField.add(
            new SimpleAttributeModifier("name", rule.getPrefix() + SearchRule.DELIM + SearchRule.PARAM_TYPE));
    add(searchRuleTypeHiddenField);
}

From source file:com.doculibre.constellio.wicket.panels.search.advanced.searchRulePanels.AbstractNumericSearchRulePanel.java

License:Open Source License

public AbstractNumericSearchRulePanel(String id, SimpleSearch search, T rule, IModel typesModel) {
    super(id, search, rule, typesModel);

    equationSelect = new DropDownChoice("equation", new Model(rule.getEquation()),
            Arrays.asList(getAvailableEquations()), new IChoiceRenderer() {

                @Override/*from  www .j a  v  a 2 s .com*/
                public String getIdValue(Object object, int index) {
                    return ((MathEquation) object).name();
                }

                @Override
                public Object getDisplayValue(Object object) {
                    return new StringResourceModel(((MathEquation) object).name(),
                            AbstractNumericSearchRulePanel.this, null).getString();
                }
            });
    equationSelect.add(new SimpleAttributeModifier("name",
            rule.getPrefix() + SearchRule.DELIM + AbstractNumericSearchRule.PARAM_EQUATION));

    add(equationSelect);
    params = search.toSimpleParams(true);

    add(getInputPanel("comp", rule.getPrefix() + SearchRule.DELIM + AbstractNumericSearchRule.PARAM_VALUE_1,
            new Model((Serializable) rule.getComparisonValue())));

    boolean comp2Visible = rule.getEquation().need2Param();
    IModel labelBetweenModel = new StringResourceModel("and", AbstractNumericSearchRulePanel.this, null);
    add(new Label("and", labelBetweenModel).setVisible(comp2Visible));

    add(getInputPanel("comp2", rule.getPrefix() + SearchRule.DELIM + AbstractNumericSearchRule.PARAM_VALUE_2,
            new Model((Serializable) rule.getSecondComparisonValue())).setVisible(comp2Visible));
}