Example usage for org.apache.wicket.markup.html.list ListView ListView

List of usage examples for org.apache.wicket.markup.html.list ListView ListView

Introduction

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

Prototype

public ListView(final String id, final List<T> list) 

Source Link

Usage

From source file:com.cubeia.backoffice.web.wallet.TransactionInfo.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
* 
* @param params//from  www  . j  a v  a 2s. c  o m
*            Page parameters
*/
@SuppressWarnings("serial")
public TransactionInfo(PageParameters params) {
    transactionId = params.get("transactionId").toLongObject();
    Transaction tx = walletService.getTransactionById(transactionId);

    if (tx == null) {
        // TODO: create invalid tx page
        setInvalidTransactionResponsePage(transactionId);
        return;
    }

    add(new Label("txId", "" + transactionId));
    add(new Label("timestamp", "" + formatDate(tx.getTimestamp())));
    add(new Label("comment", "" + tx.getComment()));

    ArrayList<java.util.Map.Entry<String, String>> attribs;

    if (tx.getAttributes() != null) {
        attribs = new ArrayList<Map.Entry<String, String>>(tx.getAttributes().entrySet());
    } else {
        attribs = new ArrayList<Map.Entry<String, String>>();
    }

    ListView<Map.Entry<String, String>> attribList = new ListView<Map.Entry<String, String>>("attributeList",
            attribs) {
        @Override
        protected void populateItem(ListItem<java.util.Map.Entry<String, String>> item) {
            String key = item.getModelObject().getKey();
            String value = item.getModelObject().getValue();
            item.add(new Label("key", Model.of(key)));
            String url = getAttributeLinkUrl(key, value);
            if (url == null) {
                item.add(new Label("value", Model.of(value)));
            } else {
                item.add(new ExternalLinkPanel("value", value, url));
            }
        }

        private String getAttributeLinkUrl(String key, String value) {
            if (transactionLinkTemplates != null && transactionLinkTemplates.containsKey(key)) {
                String templ = transactionLinkTemplates.get(key);
                return templ.replace("${value}", value);
            } else {
                return null;
            }
        }
    };
    add(attribList);

    ArrayList<Entry> entryList = new ArrayList<Entry>();

    if (tx.getEntries() != null) {
        entryList.addAll(tx.getEntries());
    }

    Collections.sort(entryList, new Comparator<Entry>() {
        @Override
        public int compare(Entry o1, Entry o2) {
            return o1.getAccountId().compareTo(o2.getAccountId());
        }
    });

    ListView<Entry> entryListView = new ListView<Entry>("entryList", entryList) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<Entry> item) {
            Entry e = (Entry) item.getModelObject();
            item.add(new Label("id", "" + e.getId()));

            LabelLinkPanel accountLink = new LabelLinkPanel("accountEntriesLink", "" + e.getAccountId(),
                    AccountDetails.class, params(AccountDetails.PARAM_ACCOUNT_ID, e.getAccountId()));
            item.add(accountLink);
            item.add(new Label("amount", "" + e.getAmount()));
            item.add(new Label("resultingBalance", "" + e.getResultingBalance()));
            item.add(new OddEvenRowsAttributeModifier(item.getIndex()));
        }
    };
    add(entryListView);
}

From source file:com.cubeia.games.poker.admin.wicket.pages.system.VerifySystemAccounts.java

License:Open Source License

private void initPage() {
    AccountLookup accountLookup = new AccountLookup(walletService);

    List<AccountInformation> systemAccountList = new ArrayList<>();
    List<AccountInformation> operatorAccountList = new ArrayList<>();
    CurrencyListResult supportedCurrencies = walletService.getSupportedCurrencies();

    List<AccountRole> systemRoles = new ArrayList<>();
    systemRoles.add(AccountRole.MAIN);/*from w w  w  .ja va2  s.c  o m*/
    systemRoles.add(AccountRole.PROMOTION);
    systemRoles.add(AccountRole.RAKE);
    systemRoles.add(AccountRole.BONUS);

    List<AccountRole> operatorRoles = new ArrayList<>();
    operatorRoles.add(AccountRole.MAIN);
    operatorRoles.add(AccountRole.RAKE);
    operatorRoles.add(AccountRole.BONUS);

    // Lookup system accounts
    AccountType type = AccountType.SYSTEM_ACCOUNT;
    boolean errorAlert = false;
    for (Currency currency : supportedCurrencies.getCurrencies()) {
        for (AccountRole role : systemRoles) {
            AccountInformation info = new AccountInformation();
            info.setCurrency(currency.getCode());
            info.setType(type);
            info.setRole(role);

            try {
                long accountId = accountLookup.lookupSystemAccount(currency.getCode(), role);
                if (accountId > 0) {
                    info.setId(accountId);
                    info.setFound(true);
                }
            } catch (NoSuchAccountException e) {
                info.setFound(false);
                errorAlert = true;
            }
            systemAccountList.add(info);
        }
    }

    final WebMarkupContainer alert = new WebMarkupContainer("errorAlert");
    alert.setVisibilityAllowed(errorAlert);
    add(alert);

    // Lookup operator accounts
    List<OperatorDTO> operators = operatorService.getOperators();

    type = AccountType.OPERATOR_ACCOUNT;
    for (OperatorDTO operator : operators) {
        for (Currency currency : supportedCurrencies.getCurrencies()) {
            for (AccountRole role : operatorRoles) {
                AccountInformation info = new AccountInformation();
                info.setCurrency(currency.getCode());
                info.setType(type);
                info.setRole(role);
                info.setOperator(operator.getId() + ":" + operator.getName());
                try {
                    long accountId = accountLookup.lookupOperatorAccount(operator.getId(), currency.getCode(),
                            role);
                    if (accountId > 0) {
                        info.setId(accountId);
                        info.setFound(true);
                    }
                } catch (NoSuchAccountException e) {
                    info.setFound(false);
                }

                operatorAccountList.add(info);
            }
        }
    }

    ListView<AccountInformation> systemList = new ListView<AccountInformation>("systemList",
            systemAccountList) {
        protected void populateItem(ListItem<AccountInformation> item) {
            AccountInformation info = item.getModel().getObject();
            item.add(new Label("role", info.getRole()));
            item.add(new Label("currency", info.getCurrency()));
            Label found = new Label("accountFound", info.isFound() ? "ID " + info.getId() : "Missing");
            if (info.isFound()) {
                found.add(new AttributeModifier("class", "label label-success"));
            } else {
                found.add(new AttributeModifier("class", "label label-warning"));
            }
            item.add(found);

        }
    };
    add(systemList);

    ListView<AccountInformation> operatorList = new ListView<AccountInformation>("operatorList",
            operatorAccountList) {
        protected void populateItem(ListItem<AccountInformation> item) {
            AccountInformation info = item.getModel().getObject();
            item.add(new Label("operator", info.getOperator()));
            item.add(new Label("role", info.getRole()));
            item.add(new Label("currency", info.getCurrency()));
            Label found = new Label("accountFound", info.isFound() ? "ID " + info.getId() : "Missing");
            if (info.isFound()) {
                found.add(new AttributeModifier("class", "label label-success"));
            } else {
                found.add(new AttributeModifier("class", "label label-warning"));
            }
            item.add(found);

        }
    };
    add(operatorList);
}

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

License:Open Source License

private ListView<Account> createAccountListView(AccountQueryResult accountResult) {
    log.debug("account result: {}", accountResult);
    List<Account> accounts = accountResult.getAccounts();
    if (accounts == null) {
        accounts = new ArrayList<Account>();
    }/*from ww w  . ja  v a 2s  .com*/
    HashSet<Account> accountSet = new HashSet<Account>(accounts);
    List<Account> accountList = new ArrayList<Account>(accountSet);
    Collections.sort(accountList, Collections.reverseOrder(new Comparator<Account>() {
        @Override
        public int compare(Account a1, Account a2) {
            return a1.getType().name().compareTo(a2.getType().name());
        }
    }));
    return new ListView<Account>("accounts", Model.ofList(accountList)) {
        private static final long serialVersionUID = 1L;

        @SuppressWarnings("serial")
        @Override
        protected void populateItem(ListItem<Account> item) {
            final Account account = item.getModelObject();

            item.add(new LabelLinkPanel("accountId", "" + account.getId(), "View account " + account.getId(),
                    AccountDetails.class, params(AccountDetails.PARAM_ACCOUNT_ID, account.getId())));

            item.add(new Label("name", new PropertyModel<String>(account, "information.name")));
            item.add(new Label("currency", new PropertyModel<String>(account, "currencyCode")));
            item.add(new Label("created", new DateDisplayModel(account, "created")));
            item.add(new Label("type", new PropertyModel<String>(account, "type")));

            item.add(new Label("balance", new Model<BigDecimal>() {
                public BigDecimal getObject() {
                    BigDecimal amount;
                    try {
                        amount = walletService.getAccountBalance(account.getId()).getBalance().getAmount();
                    } catch (AccountNotFoundException e) {
                        throw new RuntimeException(e);
                    }
                    return amount;
                };
            }));

            item.add(new OddEvenRowsAttributeModifier(item.getIndex()));
        }
    };
}

From source file:com.cubeia.games.poker.admin.wicket.pages.wallet.EditCurrencies.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
*
*///w  ww.j  av  a2s.  c  o m
@SuppressWarnings("serial")
public EditCurrencies(PageParameters parameters) {
    super(parameters);
    add(new FeedbackPanel("feedback", new ComponentFeedbackMessageFilter(EditCurrencies.this)));

    IModel<List<Currency>> currencyModel = new LoadableDetachableModel<List<Currency>>() {
        @Override
        protected List<Currency> load() {
            CurrencyListResult supportedCurrencies = walletService.getSupportedCurrencies();

            if (supportedCurrencies == null) {
                return Collections.<Currency>emptyList();
            }

            ArrayList<Currency> curs = new ArrayList<Currency>(supportedCurrencies.getCurrencies());
            log.debug("got currencies: {}", curs);
            Collections.sort(curs, new Comparator<Currency>() {
                @Override
                public int compare(Currency o1, Currency o2) {
                    return o1.getCode().compareTo(o2.getCode());
                }
            });
            return curs;
        }
    };

    add(new ListView<Currency>("currencies", currencyModel) {
        @Override
        protected void populateItem(ListItem<Currency> item) {
            final Currency c = item.getModelObject();
            item.add(new Label("code", Model.of(c.getCode())));
            item.add(new Label("digits", Model.of(c.getFractionalDigits())));

            item.add(new Link<String>("removeLink") {
                @Override
                public void onClick() {
                    log.debug("removing currency: {}", c);
                    walletService.removeCurrency(c.getCode());
                }
            }.add(new ConfirmOnclickAttributeModifier("Really remove this currency?")));
        }
    });

    final CompoundPropertyModel<Currency> newCurrencyModel = new CompoundPropertyModel<Currency>(
            new Currency(null, 2));

    Form<Currency> addForm = new Form<Currency>("addForm", newCurrencyModel) {
        @Override
        protected void onSubmit() {
            Currency cur = getModelObject();
            log.debug("submit: {}", cur);

            try {
                walletService.addCurrency(cur);
            } catch (Exception e) {
                error("Error creating currency: " + e.getMessage());
                return;
            }

            info("Added currency " + cur.getCode() + " with " + cur.getFractionalDigits()
                    + " fractional digits");
            newCurrencyModel.setObject(new Currency(null, 2));
        }
    };

    addForm.add(new RequiredTextField<String>("code", newCurrencyModel.<String>bind("code"))
            .add(StringValidator.exactLength(3)));
    addForm.add(new RequiredTextField<Integer>("digits", newCurrencyModel.<Integer>bind("fractionalDigits"))
            .add(new RangeValidator<Integer>(0, 8)));
    addForm.add(new FeedbackPanel("feedback", new ContainerFeedbackMessageFilter(addForm)));
    addForm.add(new WebMarkupContainer("submitButton")
            .add(new ConfirmOnclickAttributeModifier("Are you sure you want to add this currency?")));
    add(addForm);
}

From source file:com.cubeia.games.poker.admin.wicket.pages.wallet.TransactionInfo.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
* 
* @param parameters// www .  ja va2  s  . c om
*            Page parameters
*/
@SuppressWarnings("serial")
public TransactionInfo(PageParameters parameters) {
    super(parameters);
    transactionId = parameters.get("transactionId").toLongObject();
    Transaction tx = walletService.getTransactionById(transactionId);

    if (tx == null) {
        // TODO: create invalid tx page
        setInvalidTransactionResponsePage(transactionId);
        return;
    }

    add(new Label("txId", "" + transactionId));
    add(new Label("timestamp", "" + formatDate(tx.getTimestamp())));
    add(new Label("comment", "" + tx.getComment()));

    ArrayList<Map.Entry<String, String>> attribs;

    if (tx.getAttributes() != null) {
        attribs = new ArrayList<Map.Entry<String, String>>(tx.getAttributes().entrySet());
    } else {
        attribs = new ArrayList<Map.Entry<String, String>>();
    }

    ListView<Map.Entry<String, String>> attribList = new ListView<Map.Entry<String, String>>("attributeList",
            attribs) {
        @Override
        protected void populateItem(ListItem<Map.Entry<String, String>> item) {
            String key = item.getModelObject().getKey();
            String value = item.getModelObject().getValue();
            item.add(new Label("key", Model.of(key)));
            String url = getAttributeLinkUrl(key, value);
            if (url == null) {
                item.add(new Label("value", Model.of(value)));
            } else {
                item.add(new ExternalLinkPanel("value", value, url));
            }
        }

        private String getAttributeLinkUrl(String key, String value) {
            if (transactionLinkTemplates != null && transactionLinkTemplates.containsKey(key)) {
                String templ = transactionLinkTemplates.get(key);
                return templ.replace("${value}", value);
            } else {
                return null;
            }
        }
    };
    add(attribList);

    ArrayList<Entry> entryList = new ArrayList<Entry>();

    if (tx.getEntries() != null) {
        entryList.addAll(tx.getEntries());
    }

    Collections.sort(entryList, new Comparator<Entry>() {
        @Override
        public int compare(Entry o1, Entry o2) {
            return o1.getAccountId().compareTo(o2.getAccountId());
        }
    });

    ListView<Entry> entryListView = new ListView<Entry>("entryList", entryList) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<Entry> item) {
            Entry e = (Entry) item.getModelObject();
            item.add(new Label("id", "" + e.getId()));

            LabelLinkPanel accountLink = new LabelLinkPanel("accountEntriesLink", "" + e.getAccountId(),
                    AccountDetails.class, params(AccountDetails.PARAM_ACCOUNT_ID, e.getAccountId()));
            item.add(accountLink);
            item.add(new Label("amount", "" + e.getAmount()));
            item.add(new Label("resultingBalance", "" + e.getResultingBalance()));
            item.add(new OddEvenRowsAttributeModifier(item.getIndex()));
        }
    };
    add(entryListView);
}

From source file:com.customeric.panels.LeadActivities.java

public LeadActivities(String id, IModel<List<? extends Leads>> leadLists) {
    super(id, leadLists);
    if (leadLists == null) {
        leadLists = Model.ofList(DocamineServiceFactory.getLeadsJpaController().findLeadsEntities());
    }/*ww w.  j ava2s  .  co m*/
    leadList = new ListView<Leads>("leadList", leadLists) {

        @Override
        protected void populateItem(ListItem<Leads> li) {
            li.add(new Label("leadId", li.getModelObject().getId() + ""));
        }
    };

    add(leadList);
}

From source file:com.doculibre.constellio.wicket.links.SwitchLocaleLinkHolder.java

License:Open Source License

public SwitchLocaleLinkHolder(String id) {
    super(id);/*from ww  w. j  a v  a 2s  . c  o m*/

    IModel languagesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            ConstellioSession session = ConstellioSession.get();
            Locale currentLocale = session.getLocale();
            List<Locale> supportedLocales = ConstellioSpringUtils.getSupportedLocales();
            List<Locale> linkLocales = new ArrayList<Locale>();
            for (Locale supportedLocale : supportedLocales) {
                if (!supportedLocale.getLanguage().equals(currentLocale.getLanguage())) {
                    linkLocales.add(supportedLocale);
                }
            }
            return linkLocales;
        }
    };
    add(new ListView("languages", languagesModel) {
        @Override
        protected void populateItem(ListItem item) {
            final Locale locale = (Locale) item.getModelObject();
            String language = locale.getLanguage().toUpperCase();
            item.add(new LinkHolder("linkHolder", new Model(language)) {
                @Override
                protected WebMarkupContainer newLink(String id) {
                    Link link = new Link(id) {
                        @Override
                        public void onClick() {
                            ConstellioSession.get().changeLocale(locale);
                        }
                    };
                    link.add(new SimpleAttributeModifier("class", "langue"));
                    return link;
                }
            });
        }
    });
}

From source file:com.doculibre.constellio.wicket.pages.SearchHistoryPage.java

License:Open Source License

public SearchHistoryPage(PageParameters params) {
    super(params);

    add(new WebMarkupContainer("cloudKeyword.header") {
        @Override//from   w  w  w.j a  va  2  s. com
        public boolean isVisible() {
            return false;
        }
    });

    IModel historiqueRechercheModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            return ConstellioSession.get().getCombinedSearchHistory();
        }
    };
    add(new ListView("searchHistory", historiqueRechercheModel) {
        @Override
        protected void populateItem(ListItem item) {
            final SimpleSearch simpleSearch = (SimpleSearch) item.getModelObject();
            final String collectionName = simpleSearch.getCollectionName();
            RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
            RecordCollection collection = collectionServices.get(collectionName);
            final Locale displayLocale = collection.getDisplayLocale(getLocale());

            final int index = item.getIndex();

            item.add(new Label("query", simpleSearch.getQuery()));

            IModel includedFacetValuesModel = new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    List<FacetValue> includedFacetValues = new ArrayList<FacetValue>();
                    List<SearchedFacet> searchedFacets = simpleSearch.getSearchedFacets();
                    for (SearchedFacet searchedFacet : searchedFacets) {
                        SearchableFacet searchableFacet = searchedFacet.getSearchableFacet();
                        for (String includedValue : searchedFacet.getIncludedValues()) {
                            includedFacetValues.add(new FacetValue(searchableFacet, includedValue));
                        }
                    }
                    return includedFacetValues;
                }
            };
            item.add(new ListView("includedFacetValues", includedFacetValuesModel) {
                @Override
                protected void populateItem(ListItem item) {
                    final FacetValue facetValue = (FacetValue) item.getModelObject();

                    RecordCollectionServices collectionServices = ConstellioSpringUtils
                            .getRecordCollectionServices();
                    String collectionName = simpleSearch.getCollectionName();
                    RecordCollection collection = collectionServices.get(collectionName);
                    Locale displayLocale = collection.getDisplayLocale(getLocale());

                    StringBuffer label = new StringBuffer();
                    label.append(facetValue.getSearchableFacet().getLabels().get(displayLocale));
                    label.append(" : ");
                    label.append(facetValue.getLabel(displayLocale));

                    item.add(new Label("label", label.toString()));
                }
            });

            IModel excludedFacetValuesModel = new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    List<FacetValue> excludedFacetValues = new ArrayList<FacetValue>();
                    List<SearchedFacet> searchedFacets = simpleSearch.getSearchedFacets();
                    for (SearchedFacet searchedFacet : searchedFacets) {
                        SearchableFacet searchableFacet = searchedFacet.getSearchableFacet();
                        for (String excludedFacetValue : searchedFacet.getExcludedValues()) {
                            excludedFacetValues.add(new FacetValue(searchableFacet, excludedFacetValue));
                        }
                    }
                    return excludedFacetValues;
                }
            };

            item.add(new ListView("excludedFacetValues", excludedFacetValuesModel) {
                @Override
                protected void populateItem(ListItem item) {
                    final FacetValue facetValue = (FacetValue) item.getModelObject();

                    StringBuffer label = new StringBuffer();
                    label.append(facetValue.getSearchableFacet().getLabels().get(displayLocale));
                    label.append(" : ");
                    label.append(facetValue.getLabel(displayLocale));
                    item.add(new Label("label", label.toString()));
                }
            });

            item.add(new Label("noFacet", "S/O") {
                @Override
                public boolean isVisible() {
                    return simpleSearch.isFacetApplied();
                }
            });

            IModel cloudKeywordModel = new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    String libelle;
                    CloudKeyword cloudKeyword = simpleSearch.getCloudKeyword();
                    if (cloudKeyword != null) {
                        libelle = cloudKeyword.getKeyword();
                    } else {
                        libelle = "S/O";
                    }
                    return libelle;
                }
            };
            item.add(new Label("cloudKeyword.keyword", cloudKeywordModel) {
                @Override
                public boolean isVisible() {
                    return false;
                }
            });

            item.add(new Label("collectionName", collection.getTitle(displayLocale)));

            SearchResultsDataProvider dataProvider = new SearchResultsDataProvider(simpleSearch, 10);
            int nbResultats = dataProvider.size();
            dataProvider.detach();
            item.add(new Label("resultsCount", NumberFormatUtils.format(nbResultats, getLocale())));

            item.add(new Link("relaunchSearchLink") {
                @Override
                public void onClick() {
                    SimpleSearch clone = simpleSearch.clone();
                    // int sizeHistorique =
                    // ConstellioSession.get().getSearchHistory(solrServerName).size();
                    // Pas la dernire recherche de l'historique
                    // if (index < sizeHistorique - 1) {
                    // ConstellioSession.get().addSearchHistory(clone);
                    // }
                    PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
                    setResponsePage(pageFactoryPlugin.getSearchResultsPage(),
                            SearchResultsPage.getParameters(clone));
                }
            });

            item.add(new Link("deleteSearchLink") {
                @Override
                public void onClick() {
                    ConstellioSession.get().removeSearchHistory(index);
                }
            });
        }
    });
}

From source file:com.doculibre.constellio.wicket.panels.admin.collection.AddEditCollectionPanel.java

License:Open Source License

public AddEditCollectionPanel(String id, RecordCollection collection) {
    super(id, false);
    this.collectionModel = new ReloadableEntityModel<RecordCollection>(collection);
    edit = collection.getId() != null;/*ww  w  .  ja  va  2 s  .c om*/

    final Form form = getForm();
    form.setModel(new CompoundPropertyModel(collectionModel));
    form.add(new SetFocusBehavior(form));

    TextField nameField = new RequiredTextField("name");
    form.add(nameField);
    nameField.setEnabled(collection.getId() == null);
    nameField.setOutputMarkupId(true);
    nameField.add(new StringValidator.MaximumLengthValidator(50));
    nameField.add(new PatternValidator(ConstellioNameUtils.NAME_PATTERN));
    nameField.add(new DuplicateItemValidator() {
        @Override
        protected boolean isDuplicate(Object value) {
            RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
            return collectionServices.get((String) value) != null;
        }
    });

    TextField openSearchURL = new TextField("openSearchURL");
    form.add(openSearchURL);

    final WebMarkupContainer titleContainer = new WebMarkupContainer("titleContainer");
    form.add(titleContainer);
    titleContainer.setOutputMarkupId(true);

    MultiLocaleComponentHolder titleHolder = new MultiLocaleComponentHolder("title", collectionModel,
            new PropertyModel(collectionModel, "locales")) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextField titleLocaleField = new RequiredTextField("titleField", componentModel);
            item.add(titleLocaleField);
            titleLocaleField.setOutputMarkupId(true);
            titleLocaleField.add(new StringValidator.MaximumLengthValidator(255));
            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    return collectionModel.getObject().getLocales().size() > 1;
                }
            });
        }
    };
    titleContainer.add(titleHolder);

    final WebMarkupContainer descriptionContainer = new WebMarkupContainer("descriptionContainer");
    form.add(descriptionContainer);
    descriptionContainer.setOutputMarkupId(true);

    MultiLocaleComponentHolder descriptionHolder = new MultiLocaleComponentHolder("description",
            collectionModel, new PropertyModel(collectionModel, "locales")) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextArea descriptionLocaleField = new TextArea("descriptionLocale", componentModel);
            item.add(descriptionLocaleField);
            descriptionLocaleField.setOutputMarkupId(true);
            item.add(descriptionLocaleField);
            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    return collectionModel.getObject().getLocales().size() > 1;
                }
            });
        }
    };
    descriptionContainer.add(descriptionHolder);

    List<Locale> supportedLocales = ConstellioSpringUtils.getSupportedLocales();
    if (collection.getId() == null) {
        collection.setLocales(new HashSet<Locale>(supportedLocales));
    }

    CheckGroup localesCheckGroup = new CheckGroup("localesCheckGroup",
            new PropertyModel(collectionModel, "locales"));
    form.add(localesCheckGroup);
    localesCheckGroup.setOutputMarkupId(true);
    localesCheckGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(titleContainer);
            target.addComponent(descriptionContainer);
        }
    });

    final Map<Locale, Check> localeChecks = new HashMap<Locale, Check>();
    localesCheckGroup.add(new ListView("locales", supportedLocales) {
        @Override
        protected void populateItem(ListItem item) {
            final Locale locale = (Locale) item.getModelObject();
            Check localeCheck = localeChecks.get(locale);
            if (localeCheck == null) {
                localeCheck = new Check("localeCheck", new Model(locale));
                localeChecks.put(locale, localeCheck);
            }
            item.add(localeCheck);
            item.add(new LocaleNameLabel("localeName", locale));
        }
    });

    CheckBox publicCollectionCheck = new CheckBox("publicCollection");
    form.add(publicCollectionCheck);
}

From source file:com.doculibre.constellio.wicket.panels.admin.connectorTypeMeta.AdminConnectorTypeMetaMappingsPanel.java

License:Open Source License

public AdminConnectorTypeMetaMappingsPanel(String id) {
    super(id);/*from w w w  .  j  av a 2 s . com*/

    IModel connectorTypesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            ConnectorTypeServices connectorTypeServices = ConstellioSpringUtils.getConnectorTypeServices();
            return connectorTypeServices.list();
        }
    };
    add(new ListView("connectorTypes", connectorTypesModel) {
        @Override
        protected void populateItem(ListItem item) {
            ConnectorType connectorType = (ConnectorType) item.getModelObject();
            final ReloadableEntityModel<ConnectorType> connectorTypeModel = new ReloadableEntityModel<ConnectorType>(
                    connectorType);
            FoldableSectionPanel foldableSectionPanel = new FoldableSectionPanel("crudPanel",
                    new PropertyModel(connectorTypeModel, "name")) {
                @Override
                protected Component newFoldableSection(String id) {
                    ConnectorType connectorType = connectorTypeModel.getObject();
                    return new ConnectorTypeMetaMappingListPanel(id, connectorType);
                }

                @Override
                public void detachModels() {
                    connectorTypeModel.detach();
                    super.detachModels();
                }
            };
            item.add(foldableSectionPanel);
            foldableSectionPanel.setOpened(false);
        }
    });
}