List of usage examples for org.apache.wicket.markup.html.form AbstractChoice getChoices
public final List<? extends E> getChoices()
From source file:org.cipango.ims.hss.web.serviceprofile.EditIfcsPage.java
License:Apache License
@SuppressWarnings("unchecked") private void apply(AjaxRequestTarget target, Form<?> form1, Action action) { AbstractChoice available = (AbstractChoice) form1.get("available"); AbstractChoice used = (AbstractChoice) form1.get("used"); AbstractChoice shared = (AbstractChoice) form1.get("shared"); Iterator it;// w ww . ja v a2s. co m List choosen; switch (action) { case ADD_TO_IFC: case ADD_TO_SHARED: it = ((List) available.getDefaultModelObject()).iterator(); choosen = available.getChoices(); break; case MOVE_TO_SHARED: case REMOVE_FROM_IFC: it = ((List) used.getDefaultModelObject()).iterator(); choosen = used.getChoices(); break; case MOVE_TO_IFC: case REMOVE_FROM_SHARED: it = ((List) shared.getDefaultModelObject()).iterator(); choosen = shared.getChoices(); break; default: throw new IllegalStateException("Unknown action " + action); } ServiceProfile profile = _dao.findById(_key); ListView ifcs = (ListView) getPage().get("contextMenu:ifcs"); Collection<String> contextModel = (Collection<String>) ifcs.getDefaultModelObject(); while (it.hasNext()) { String ifcName = (String) it.next(); InitialFilterCriteria ifc = _ifcDao.findById(ifcName); try { switch (action) { case ADD_TO_IFC: profile.addIfc(ifc, false); used.getChoices().add(ifcName); contextModel.add(ifcName); break; case ADD_TO_SHARED: profile.addIfc(ifc, true); shared.getChoices().add(ifcName); contextModel.add(ifcName); break; case MOVE_TO_IFC: profile.moveIfc(ifc, false); used.getChoices().add(ifcName); break; case MOVE_TO_SHARED: profile.moveIfc(ifc, true); shared.getChoices().add(ifcName); break; case REMOVE_FROM_IFC: case REMOVE_FROM_SHARED: _dao.unlink(profile, ifc); contextModel.remove(ifcName); available.getChoices().add(ifcName); break; default: break; } choosen.remove(ifcName); } catch (HssException e) { error(e.getMessage()); } it.remove(); } _dao.save(profile); getCxManager().profileUpdated(profile); if (target != null) { target.addComponent(form1); target.addComponent(getPage().get("feedback")); target.addComponent(getPage().get("contextMenu")); target.addComponent(getPage().get("pprPanel").setVisible(true)); } }
From source file:org.opensingular.form.wicket.helpers.SingularFormBaseTest.java
License:Apache License
public List<String> getkeysFromSelection(AbstractChoice choice) { final List<String> list = new ArrayList<>(); for (Object c : choice.getChoices()) { list.add(choice.getChoiceRenderer().getIdValue(c, choice.getChoices().indexOf(c))); }/*from w w w. ja v a2s.com*/ return list; }
From source file:org.opensingular.form.wicket.helpers.SingularFormBaseTest.java
License:Apache License
public List<String> getDisplaysFromSelection(AbstractChoice choice) { final List<String> list = new ArrayList<>(); for (Object c : choice.getChoices()) { list.add(String.valueOf(choice.getChoiceRenderer().getDisplayValue(c))); }/* w w w .j a v a 2 s . c om*/ return list; }
From source file:org.yes.cart.web.page.component.customer.address.AddressForm.java
License:Apache License
/** * Create address form.//from w ww . j ava2 s . c o m * * @param s form id * @param addressIModel address model. * @param addressType address type * @param successPage success page class * @param successPageParameters success page parameters * @param cancelPage optional cancel page class * @param cancelPageParameters optional cancel page parameters */ public AddressForm(final String s, final IModel<Address> addressIModel, final String addressType, final Class<? extends Page> successPage, final PageParameters successPageParameters, final Class<? extends Page> cancelPage, final PageParameters cancelPageParameters) { super(s, addressIModel); this.successPage = successPage; this.successPageParameters = successPageParameters; final Address address = addressIModel.getObject(); preprocessAddress(address); final boolean creating = address.getAddressId() == 0L; final List<State> stateList = getStateList(address.getCountryCode()); final List<Country> countryList = addressBookFacade.getAllCountries(ShopCodeContext.getShopCode(), addressType); RepeatingView fields = new RepeatingView(FIELDS); add(fields); final String lang = getLocale().getLanguage(); values = addressBookFacade.getShopCustomerAddressAttributes(address.getCustomer(), ApplicationDirector.getCurrentShop(), addressType); final Map<String, AttrValue> valuesMap = new HashMap<String, AttrValue>(); for (final AttrValue av : values) { valuesMap.put(av.getAttribute().getVal(), av); try { final Object val = PropertyUtils.getProperty(address, av.getAttribute().getVal()); av.setVal(val != null ? String.valueOf(val) : null); } catch (Exception e) { LOG.error("Unable to get address property for {}, prop {}", av.getAttribute(), av.getAttribute().getVal()); } } final AttrValue stateCode = valuesMap.get("stateCode"); final AbstractChoice<State, State> stateDropDownChoice = new DropDownChoice<State>(STATE, new StateModel(new PropertyModel(stateCode, "val"), stateList), stateList) .setChoiceRenderer(new StateRenderer()); final boolean needState = !stateList.isEmpty(); stateDropDownChoice.setRequired(needState); stateDropDownChoice.setVisible(needState); final AttrValue countryCode = valuesMap.get("countryCode"); final AbstractChoice<Country, Country> countryDropDownChoice = new DropDownChoice<Country>(COUNTRY, new CountryModel(new PropertyModel(countryCode, "val"), countryList), countryList) { @Override protected void onSelectionChanged(final Country country) { super.onSelectionChanged(country); stateDropDownChoice.setChoices(getStateList(country.getCountryCode())); final boolean needState = !stateDropDownChoice.getChoices().isEmpty(); stateDropDownChoice.setRequired(needState); stateDropDownChoice.setVisible(needState); if (valuesMap.containsKey("stateCode")) { valuesMap.get("stateCode").setVal(StringUtils.EMPTY); } } @Override protected boolean wantOnSelectionChangedNotifications() { return true; } }.setChoiceRenderer(new CountryRenderer()); countryDropDownChoice.setRequired(true); for (final AttrValue attrValue : values) { WebMarkupContainer row; if ("countryCode".equals(attrValue.getAttribute().getVal())) { row = new WebMarkupContainer(fields.newChildId()); row.add(getLabel(attrValue, lang)); row.add(new Fragment("editor", "countryCodeEditor", this).add(countryDropDownChoice)); } else if ("stateCode".equals(attrValue.getAttribute().getVal())) { row = new WebMarkupContainer(fields.newChildId()) { @Override public boolean isVisible() { return stateDropDownChoice.isVisible(); } }; row.add(getLabel(attrValue, lang)); row.add(new Fragment("editor", "stateCodeEditor", this).add(stateDropDownChoice)); } else { row = new WebMarkupContainer(fields.newChildId()); row.add(getLabel(attrValue, lang)); row.add(getEditor(attrValue, false)); } fields.add(row); } final AbstractLink submit = new SubmitLink(ADD_ADDRESS) { @Override public void onSubmit() { final Address addr = getModelObject(); final boolean isNew = addr.getAddressId() == 0; final ShoppingCart cart = ((AbstractWebPage) getPage()).getCurrentCart(); if (isNew || cart.getLogonState() == ShoppingCart.LOGGED_IN) { for (final AttrValue value : values) { try { PropertyUtils.setProperty(addr, value.getAttribute().getVal(), value.getVal()); } catch (Exception e) { LOG.error("Unable to set address property for {}, prop {}", value.getAttribute(), value.getAttribute().getVal()); } } final Shop shop = ((AbstractWebPage) getPage()).getCurrentCustomerShop(); addressBookFacade.createOrUpdate(addr, shop); // if we just added new address that became new default or we modified an address that is in the cart // reset address if (isNew && addr.isDefaultAddress() || Long.valueOf(addr.getAddressId()).equals(cart.getOrderInfo().getBillingAddressId()) || Long.valueOf(addr.getAddressId()) .equals(cart.getOrderInfo().getDeliveryAddressId())) { final String key = Address.ADDR_TYPE_BILLING.equals(addressType) ? ShoppingCartCommand.CMD_SETADDRESES_P_BILLING_ADDRESS : ShoppingCartCommand.CMD_SETADDRESES_P_DELIVERY_ADDRESS; shoppingCartCommandFactory.execute(ShoppingCartCommand.CMD_SETADDRESES, cart, (Map) new HashMap() { { put(ShoppingCartCommand.CMD_SETADDRESES, ShoppingCartCommand.CMD_SETADDRESES); put(key, addr); } }); } } setResponsePage(successPage, successPageParameters); } }; add(submit); submit.add(new Label("addAddressLabel", WicketUtil.createStringResourceModel(this, creating ? "create" : "save"))); final Component cancel = new SubmitLink(CANCEL_LINK) { @Override public void onSubmit() { setResponsePage(cancelPage, cancelPageParameters); } }.setDefaultFormProcessing(false).setVisible(cancelPage != null); add(cancel); }