Example usage for org.apache.wicket.model ComponentPropertyModel ComponentPropertyModel

List of usage examples for org.apache.wicket.model ComponentPropertyModel ComponentPropertyModel

Introduction

In this page you can find the example usage for org.apache.wicket.model ComponentPropertyModel ComponentPropertyModel.

Prototype

public ComponentPropertyModel(final String propertyName) 

Source Link

Document

Constructor

Usage

From source file:org.devgateway.eudevfin.dim.pages.transaction.crs.ForLoansOnlyTab.java

License:Open Source License

private void addComponents() {
    /**// ww w  . j  a v a 2  s. c  o  m
     * BEWARE {@link ComponentPropertyModel} is a read-only model
     */
    ComponentPropertyModel<CurrencyUnit> readOnlyCurrencyModel = new ComponentPropertyModel<>("currency");

    DropDownField<Category> typeOfRepayment = new DropDownField<>("44typeOfRepayment",
            new RWComponentPropertyModel<Category>("typeOfRepayment"),
            categoryFactory.get(CategoryConstants.TYPE_OF_REPAYMENT_TAG));
    typeOfRepayment.getField().add(new LoansField12UpdateBehavior());
    add(typeOfRepayment);

    DropDownField<Category> numberOfRepayments = new DropDownField<>("45numberOfRepayments",
            new RWComponentPropertyModel<Category>("numberOfRepaymentsAnnum"),
            categoryFactory.get(CategoryConstants.NUM_OF_REPAYMENTS_PER_ANNUM_TAG));
    numberOfRepayments.getField().add(new LoansField12UpdateBehavior());
    add(numberOfRepayments);

    TextInputField<String> interestRate = new TextInputField<>("46interestRate",
            new InterestRateToBigDecimalModel(new RWComponentPropertyModel<BigDecimal>("interestRate")));
    interestRate.getField().add(new LoansField12UpdateBehavior());
    interestRate.typeString().decorateMask("99999");

    add(interestRate);

    TextInputField<BigDecimal> secondInterestRate = new TextInputField<>("47secondInterestRate",
            new RWComponentPropertyModel<BigDecimal>("secondInterestRate"));
    secondInterestRate.getField().add(new LoansField12UpdateBehavior());
    secondInterestRate.typeBigDecimal();
    add(secondInterestRate);

    DateInputField firstRepaymentDate = new DateInputField("48firstRepaymentDate",
            new DateToLocalDateTimeModel(new RWComponentPropertyModel<LocalDateTime>("firstRepaymentDate")));
    firstRepaymentDate.getField().add(new LoansField12UpdateBehavior());
    add(firstRepaymentDate);

    DateInputField finalRepaymentDate = new DateInputField("49finalRepaymentDate",
            new DateToLocalDateTimeModel(new RWComponentPropertyModel<LocalDateTime>("finalRepaymentDate")));
    finalRepaymentDate.getField().add(new LoansField12UpdateBehavior());
    add(finalRepaymentDate);

    TextInputField<BigDecimal> interestReceived = new TextInputField<>("50interestReceived", new BigMoneyModel(
            new RWComponentPropertyModel<BigMoney>("interestReceived"), readOnlyCurrencyModel));
    interestReceived.getField().add(new LoansField12UpdateBehavior());
    interestReceived.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(interestReceived);

    TextInputField<BigDecimal> principalDisbursed = new TextInputField<>("51principalDisbursed",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("principalDisbursedOutstanding"),
                    readOnlyCurrencyModel));
    principalDisbursed.typeBigDecimal().add(new CurrencyUpdateBehavior());
    principalDisbursed.getField().add(new LoansField12UpdateBehavior());
    add(principalDisbursed);

    TextInputField<BigDecimal> arrearsOfPrincipals = new TextInputField<>("52arrearsOfPrincipals",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("arrearsOfPrincipal"),
                    readOnlyCurrencyModel));
    arrearsOfPrincipals.typeBigDecimal().add(new CurrencyUpdateBehavior());
    arrearsOfPrincipals.getField().add(new LoansField12UpdateBehavior());
    add(arrearsOfPrincipals);

    TextInputField<BigDecimal> arrearsOfInterest = new TextInputField<>("53arrearsOfInterest",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("arrearsOfInterest"),
                    readOnlyCurrencyModel));
    arrearsOfInterest.typeBigDecimal().add(new CurrencyUpdateBehavior());
    arrearsOfInterest.getField().add(new LoansField12UpdateBehavior());
    add(arrearsOfInterest);
}

From source file:org.devgateway.eudevfin.dim.pages.transaction.crs.VolumeDataTab.java

License:Open Source License

private void addComponents() {

    ComponentPropertyModel<CurrencyUnit> readOnlyCurrencyModel = new ComponentPropertyModel<>("currency");
    ChoiceProvider<CurrencyUnit> nationalCurrenciesProvider = this.currencyUnitProviderFactory
            .getCurrencyUnitProviderInstance(CurrencyUnitProviderFactory.NATIONAL_UNSORTED_CURRENCIES_PROVIDER);
    currency = new DropDownField<CurrencyUnit>("32currency",
            new RWComponentPropertyModel<CurrencyUnit>("currency"), nationalCurrenciesProvider) {
        //            @Override
        //            protected void onUpdate(AjaxRequestTarget target) {
        //                send(getPage(), Broadcast.DEPTH, new CurrencyChangedEventPayload(target));
        //            }
    };/*www .java2 s.c  om*/
    currency.required();
    add(currency);
    TextInputField<BigDecimal> commitments = new TextInputField<>("33commitments",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("commitments"), readOnlyCurrencyModel));
    commitments.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(commitments);

    TextInputField<BigDecimal> amountsExtended = new TextInputField<>("34amountsExtended", new BigMoneyModel(
            new RWComponentPropertyModel<BigMoney>("amountsExtended"), readOnlyCurrencyModel));
    amountsExtended.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountsExtended);

    TextInputField<BigDecimal> amountsReceived = new TextInputField<>("35amountsReceived", new BigMoneyModel(
            new RWComponentPropertyModel<BigMoney>("amountsReceived"), readOnlyCurrencyModel));
    amountsReceived.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountsReceived);

    TextInputField<BigDecimal> amountUntied = new TextInputField<>("36amountUntied",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("amountsUntied"), readOnlyCurrencyModel));
    amountUntied.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountUntied);

    TextInputField<BigDecimal> amountPartiallyUntied = new TextInputField<>("37amountPartiallyUntied",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("amountsPartiallyUntied"),
                    readOnlyCurrencyModel));
    amountPartiallyUntied.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountPartiallyUntied);

    TextInputField<BigDecimal> amountTied = new TextInputField<>("38amountTied",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("amountsTied"), readOnlyCurrencyModel));
    amountTied.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountTied);

    TextInputField<BigDecimal> amountOfIRTC = new TextInputField<>("39amountOfIRTC",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("amountOfIRTC"), readOnlyCurrencyModel));
    amountOfIRTC.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountOfIRTC);

    TextInputField<BigDecimal> amountOfExpertsCommitments = new TextInputField<>("40amountOfExpertsCommitments",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("projectAmountExpertCommitments"),
                    readOnlyCurrencyModel));
    amountOfExpertsCommitments.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountOfExpertsCommitments);

    TextInputField<BigDecimal> amountOfExpertsExtended = new TextInputField<>("41amountOfExpertsExtended",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("projectAmountExpertExtended"),
                    readOnlyCurrencyModel));
    amountOfExpertsExtended.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountOfExpertsExtended);

    TextInputField<BigDecimal> amountOfExportCredit = new TextInputField<>("42amountOfExportCredit",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("amountOfExportCreditInAFPackage"),
                    readOnlyCurrencyModel));
    amountOfExportCredit.typeBigDecimal().add(new CurrencyUpdateBehavior());
    add(amountOfExportCredit);
}

From source file:org.devgateway.eudevfin.dim.pages.transaction.custom.CustomForLoansOnlyTab.java

License:Open Source License

private void addComponents() {
    /**/*from w  w  w .j  a v  a  2 s . c om*/
     * BEWARE {@link org.apache.wicket.model.ComponentPropertyModel} is a read-only model
     */
    ComponentPropertyModel<CurrencyUnit> readOnlyCurrencyModel = new ComponentPropertyModel<>("currency");

    TextInputField<BigDecimal> futureDebtPrincipal = new TextInputField<>("54futureDebtPrincipal",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("futureDebtPrincipal"),
                    readOnlyCurrencyModel));
    futureDebtPrincipal.typeBigDecimal().add(new CurrencyUpdateBehavior());
    futureDebtPrincipal.getField().add(new LoansField12UpdateBehavior());
    add(futureDebtPrincipal);

    TextInputField<BigDecimal> futureDebtInterest = new TextInputField<>("54futureDebtInterest",
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("futureDebtInterest"),
                    readOnlyCurrencyModel));
    futureDebtInterest.typeBigDecimal().add(new CurrencyUpdateBehavior());
    futureDebtInterest.getField().add(new LoansField12UpdateBehavior());
    add(futureDebtInterest);
}

From source file:org.devgateway.eudevfin.mcm.pages.EditNonFlowItemsPage.java

License:Open Source License

public WebMarkupContainer initializeFakeFinancialContainer(String id, String fieldId, PageParameters parameters,
        String typeOfFinanceCode, boolean percentage) {
    // initialize a wrapping container
    WebMarkupContainer container = new WebMarkupContainer(id);

    // initialize a non flow transaction
    final FinancialTransaction financialTransaction = initializeNonFlowTransaction(new FinancialTransaction(),
            parameters, typeOfFinanceCode, null);

    // create a compoundmodel and assign it to he container
    container.setDefaultModel(new CompoundPropertyModel<FinancialTransaction>(financialTransaction));

    // create a read only model to read the currency
    ComponentPropertyModel<CurrencyUnit> readOnlyCurrencyModel = new ComponentPropertyModel<>("currency");

    // create textinputfield to edit the amount
    FinancialAmountTextInputField field = new FinancialAmountTextInputField(fieldId,
            new BigMoneyModel(new RWComponentPropertyModel<BigMoney>("amountsExtended"), readOnlyCurrencyModel))
                    .required();/*from w  w w . j av a  2  s .  co  m*/
    if (percentage)
        field.range(new BigDecimal(0), new BigDecimal(100));
    container.add(field);

    return container;
}

From source file:org.devgateway.eudevfin.projects.module.modals.TransactionsTableModal.java

public final void AddComponents(PageParameters parameters, final PageReference modalWindowPage,
        final ModalWindow window) {
    final TransactionSearchModel transactionSearch = new TransactionSearchModel();
    CompoundPropertyModel<TransactionSearchModel> model = new CompoundPropertyModel<>(transactionSearch);
    setModel(model);/* ww w . j  ava2 s  .  co m*/

    final Form<FinancialTransaction> form = new Form<>("form");

    final ComponentPropertyModel<CurrencyUnit> readOnlyCurrencyModel = new ComponentPropertyModel<>("currency");

    // 1. Geographic focus    
    //In the DB, table AreaTranslation is data only  for locale = "en" or "fr"
    //If someday, all the available languages will be added in the DB, the call should be changed to:
    //List<Area> areas = areaService.findUsedAreaAsList(Session.get().getLocale().getLanguage());
    List<Area> areas = areaService.findUsedAreaAsList("en");
    GeographicFocusChoiceProvider geograficFocusProvider = new GeographicFocusChoiceProvider(areas,
            areaService);
    DropDownField<Area> geographicFocus;
    geographicFocus = new DropDownField<Area>("geographicFocus",
            new RWComponentPropertyModel<Area>("geographicFocus"), geograficFocusProvider) {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            super.onUpdate(target);

            if (transactionSearch.getGeographicFocus() != null) {
                List<Organization> orgs = organizationService
                        .findUsedOrgByGeographicFocus(transactionSearch.getGeographicFocus().getCode());

                FinancingInstitutionChoiceProvider financingInstitutionProvider = new FinancingInstitutionChoiceProvider(
                        orgs, organizationService);
                DropDownField<Organization> financingInstitution;
                financingInstitution = new DropDownField<Organization>("financingInstitution",
                        new RWComponentPropertyModel<Organization>("financingInstitution"),
                        financingInstitutionProvider) {

                    @Override
                    protected void onUpdate(AjaxRequestTarget target) {
                        super.onUpdate(target);

                        List<Integer> repYears = customTransactionService.findDistinctReportingYears();
                        DropDownField<Integer> reportingYear;
                        reportingYear = new DropDownField<Integer>("reportingYear",
                                new YearToLocalDateTimeModel(
                                        new RWComponentPropertyModel<LocalDateTime>("reportingYear")),
                                new YearProvider(repYears)) {

                            @Override
                            protected void onUpdate(AjaxRequestTarget target) {
                                super.onUpdate(target);

                                if (transactionSearch.getGeographicFocus() != null
                                        && null != transactionSearch.getFinancingInstitution()
                                        && transactionSearch.getReportingYear() != null) {
                                    String geographicFocus = transactionSearch.getGeographicFocus().getCode();
                                    String financingInstitution = transactionSearch.getFinancingInstitution()
                                            .getCode();
                                    LocalDateTime reportingYear = transactionSearch.getReportingYear();

                                    List<CustomFinancialTransaction> transactions = customTransactionService
                                            .findByReportingYearAndDraftFalse(reportingYear.getYear());

                                    List<CustomFinancialTransaction> foundTrs = new ArrayList<>();
                                    for (CustomFinancialTransaction trs : transactions) {
                                        if (trs.getRecipient() != null
                                                && trs.getRecipient().getCode() == geographicFocus) {
                                            foundTrs.add(trs);
                                        }
                                    }

                                    DropDownField<CustomFinancialTransaction> trsDropDown = new DropDownField<CustomFinancialTransaction>(
                                            "projectTitle",
                                            new RWComponentPropertyModel<CustomFinancialTransaction>(
                                                    "transaction"),
                                            new TransactionChoiceProvider(foundTrs, customTransactionService)) {
                                        @Override
                                        protected void onUpdate(AjaxRequestTarget target) {
                                            super.onUpdate(target);

                                            CustomFinancialTransaction ctx = transactionSearch.getTransaction();

                                            if (ctx != null) {
                                                CurrencyUnit currency = ctx.getCurrency();
                                                String amount = transactionSearch.getTransaction()
                                                        .getAmountsExtended().getAmount().toString();

                                                if (null != currency.toString()) {
                                                    switch (currency.toString()) {
                                                    case "RON":
                                                        amountUSD.getField().getModel().setObject(
                                                                RateUtil.moneyToString(rateUtil.exchange(
                                                                        ctx.getAmountsExtended(),
                                                                        CurrencyUnit.USD, ctx.getFixedRate(),
                                                                        RateUtil.getStartOfMonth(
                                                                                ctx.getCommitmentDate()))));
                                                        amountRON.getField().getModel().setObject(amount);
                                                        amountEUR.getField().getModel().setObject(
                                                                RateUtil.moneyToString(rateUtil.exchange(
                                                                        ctx.getAmountsExtended(),
                                                                        CurrencyUnit.EUR, ctx.getFixedRate(),
                                                                        RateUtil.getStartOfMonth(
                                                                                ctx.getCommitmentDate()))));
                                                        break;
                                                    case "EUR":
                                                        // ToDo Refactor When We figure it out the exchange rate
                                                        amountUSD.getField().getModel().setObject(amount);
                                                        amountRON.getField().getModel().setObject(amount);
                                                        amountEUR.getField().getModel().setObject(amount);
                                                        break;
                                                    case "USD":
                                                        // ToDo Refactor When We figure it out the exchange rate
                                                        amountUSD.getField().getModel().setObject(amount);
                                                        amountRON.getField().getModel().setObject(amount);
                                                        amountEUR.getField().getModel().setObject(amount);
                                                        break;
                                                    }
                                                }
                                                getParent().replace(amountUSD);
                                                getParent().replace(amountEUR);
                                                getParent().replace(amountRON);
                                                target.add(amountUSD);
                                                target.add(amountEUR);
                                                target.add(amountRON);
                                            }
                                        }

                                    };
                                    trsDropDown.required();
                                    trsDropDown.getField().setEnabled(true);
                                    getParent().replace(trsDropDown);
                                    target.add(trsDropDown);
                                }
                            }
                        };
                        reportingYear.setSize(InputBehavior.Size.Medium);
                        reportingYear.getField().setEnabled(true);
                        getParent().replace(reportingYear);
                        target.add(reportingYear);

                    }
                };
                financingInstitution.required();
                financingInstitution.getField().setEnabled(true);
                getParent().replace(financingInstitution);
                target.add(financingInstitution);
            }
        }
    };

    // 2. Financing Institution        
    List<Organization> orgs = new ArrayList<>();
    DropDownField<Organization> financingInstitution = new DropDownField<>("financingInstitution",
            new RWComponentPropertyModel<Organization>("financingInstitution"),
            new FinancingInstitutionChoiceProvider(orgs, organizationService));
    financingInstitution.required();
    financingInstitution.getField().setEnabled(false);

    // 3. Reporting year
    List<Integer> years = new ArrayList<>();
    DropDownField<Integer> reportingYear = new DropDownField<>("reportingYear",
            new YearToLocalDateTimeModel(new RWComponentPropertyModel<LocalDateTime>("reportingYear")),
            new YearProvider(years));
    reportingYear.setSize(InputBehavior.Size.Medium);
    reportingYear.getField().setEnabled(false);

    // 4. Project title  
    List<CustomFinancialTransaction> trans = new ArrayList<>();
    DropDownField<CustomFinancialTransaction> projectTitle = new DropDownField<>("projectTitle",
            new RWComponentPropertyModel<CustomFinancialTransaction>("transaction"),
            new TransactionChoiceProvider(trans, customTransactionService));
    projectTitle.required();
    projectTitle.getField().setEnabled(false);

    // 5. Amount USD   
    amountUSD = new TextInputField<>("amountUSD", new RWComponentPropertyModel<String>("amountUSD"));
    amountUSD.typeString();
    amountUSD.getField().setEnabled(false);

    // 6. Amount RON   
    amountRON = new TextInputField<>("amountRON", new RWComponentPropertyModel<String>("amountRON"));
    amountRON.typeString();
    amountRON.getField().setEnabled(false);

    // 7. Amount EURO   
    amountEUR = new TextInputField<>("amountEUR", new RWComponentPropertyModel<String>("amountEUR"));
    amountEUR.typeString();
    amountEUR.getField().setEnabled(false);

    form.add(geographicFocus);
    form.add(financingInstitution);
    form.add(reportingYear);
    form.add(projectTitle);
    form.add(amountUSD);
    form.add(amountRON);
    form.add(amountEUR);

    form.add(new BootstrapSubmitButton("submit", new StringResourceModel("button.submit", this, null)) {

        private static final long serialVersionUID = -7833958712063599191L;

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (transactionSearch.getTransaction() != null) {
                NewProjectPage.project.addTransactions(transactionSearch.getTransaction());
            }
            if (window != null) {
                window.close(target);
            }
        }

    });

    BootstrapCancelButton cancelButton = new BootstrapCancelButton("cancel",
            new StringResourceModel("button.cancel", this, null)) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (window != null) {
                window.close(target);
            }
        }

    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    add(form);
}