Package org.apache.click.control

Examples of org.apache.click.control.Option


            try {
                Object valueResult = PropertyUtils.getValue(object, value, cache);
                Object labelResult = PropertyUtils.getValue(object, label, cache);

                Option option = null;

                if (labelResult != null) {
                    option = new Option(valueResult, labelResult.toString());
                } else {
                    option = new Option(valueResult.toString());
                }

                getOptionList().add(option);

            } catch (Exception e) {
View Full Code Here


        for (int i = 0, size = order.length; i < size; i++) {
            String value = order[i];
            if (value != null) {
                int oI = -1;
                for (int j = 0, jSize = options.size(); j < jSize; j++) {
                    Option optT = (Option) options.get(j);
                    if (value.equals(optT.getValue())) {
                        oI = j;
                    }
                }
                if (oI != -1) {
                    orderList.add(options.remove(oI));
View Full Code Here

        // the options
        List optionsList = getOptionList();
        if (!optionsList.isEmpty()) {
            int i = -1;
            for (Iterator it = optionsList.iterator(); it.hasNext();) {
                Option option = (Option) it.next();
                i++;
                final String liId = getName() + "_" + i;

                buffer.append("<li>");
                if (sortable) {
                    buffer.elementStart("div");
                    buffer.appendAttribute("style", "cursor:move;");
                } else {
                    buffer.elementStart("label");
                    buffer.appendAttribute("for", liId);
                }
                buffer.appendAttribute("class", "checkListLabel");
                buffer.closeTag();

                buffer.append("<input type=\"checkbox\" ");
                buffer.appendAttributeEscaped("value", option.getValue());
                buffer.appendAttribute("id", liId);
                buffer.appendAttribute("name", getName());

                if (sortable) {
                    buffer.appendAttribute("style", "cursor:default;");
                }

                // set checked status
                List values = getSelectedValues();
                for (int k = 0; k < values.size(); k++) {
                    if (String.valueOf(values.get(k)).equals(option.getValue())) {
                        buffer.appendAttribute("checked", "checked");
                    }
                }

                if (isDisabled()) {
                    buffer.appendAttributeDisabled();
                }
                if (isReadonly()) {
                    buffer.appendAttributeReadonly();
                }
                buffer.elementEnd();

                buffer.appendEscaped(option.getLabel());

                if (sortable) {
                    buffer.append("</div>");
                } else {
                    buffer.append("</label>");
                }

                // hiddenfield if sortable

                if (sortable) {
                    buffer.append("<input type=\"hidden\"");
                    buffer.appendAttribute("name", getName() + "_order");
                    buffer.appendAttributeEscaped("value", option.getValue());
                    buffer.elementEnd();
                }

                buffer.append("</li>");
            }
View Full Code Here

     * the country as the value and the localized country name as the label.
     */
    protected void loadOptionList() {
        // Determine whether option list should be loaded
        if (getOptionList().size() == 1) {
            Option option = (Option) getOptionList().get(0);
            if (option.getValue().equals(Option.EMPTY_OPTION.getValue())) {
                // Continue and load option list

            } else {
                // Don't load list
                return;
            }

        } else if (getOptionList().size() > 1) {
            // Don't load list
            return;
        }

        Set countryList = new TreeSet(new OptionLabelComparator(getLocale()));

        Locale[] availableLocales = Locale.getAvailableLocales();

        for (int i = 0; i < availableLocales.length; i++) {
            final String iso = availableLocales[i].getCountry();
            final String name = availableLocales[i].getDisplayCountry(getLocale());

            if (StringUtils.isNotEmpty(iso) && StringUtils.isNotEmpty(name)) {
                countryList.add(new Option(iso, name));
            }
        }

        if (isRequired() && getOptionList().isEmpty()) {
            add(Option.EMPTY_OPTION);
View Full Code Here

         * @param o1 The first Option to compare.
         * @param o2 The second Option to compare.
         * @return The value returned by comparing the localized labels.
         */
        public final int compare(Object o1, Object o2) {
            Option lhs = (Option) o1;
            Option rhs = (Option) o2;

            return comparator.compare(lhs.getLabel(), rhs.getLabel());
        }
View Full Code Here

        List countries = countrySelect.getOptionList();
        Iterator it = countries.iterator();
       
        Set uniqueChecker = new HashSet();
        while(it.hasNext()) {
            Option option = (Option) it.next();
           
            // Check that no country already exists in checker. If a country
            // already exists, it means that CountrySelect returns duplicate countries
            assertFalse(uniqueChecker.contains(option.getLabel()));

            uniqueChecker.add(option.getLabel());
            System.out.println(option.getValue() + " " + option.getLabel());
        }
    }
View Full Code Here

    private List createOptionsList(int[] values) {
        List ret = new ArrayList();
        for(int i=0; i<values.length; i++) {
            String value = Integer.toString(values[i]);
            String label = "Label: "+i;
            ret.add(new Option(value,label));
        }
        return ret;
    }
View Full Code Here

        String given = "";
        for(int i=0;i<values.length;i++) {
            demanded += values[i]+",";
        }
        for (Iterator it = options.iterator(); it.hasNext(); ) {
            Option opt = (Option) it.next();
            assertNotNull(opt);
            given += opt.getValue()+",";
        }
       
        assertEquals(demanded,given);
    }
View Full Code Here

        customerSelect.setAttribute("onchange", "onCustomerChange(this);");

        List customerList = getCustomerService().getCustomersSortedByName(8);
        for (Iterator i = customerList.iterator(); i.hasNext();) {
            Customer customer = (Customer) i.next();
            customerSelect.add(new Option(customer.getId(), customer.getName()));
        }

        customerSelect.setSize(customerList.size());
    }
View Full Code Here

     */
    protected void loadOptionList() {

        // Determine whether option list should be loaded
        if (getOptionList().size() == 1) {
            Option option = (Option) getOptionList().get(0);
            if (option.getValue().equals(Option.EMPTY_OPTION.getValue())) {
                // continue and load option list

            } else {
                // Don't load list
                return;
            }

        } else if (getOptionList().size() > 1) {
            // Don't load list
            return;
        }

        CayenneForm form = (CayenneForm) getForm();
        DataContext dataContext = form.getDataContext();

        try {
            List list = null;

            if (getSelectQuery() != null) {
                SelectQuery query = getSelectQuery();

                if (!query.getOrderings().isEmpty()) {
                    orderingApplied = true;

                } else if (getOrdering() != null && !orderingApplied) {
                    query.addOrdering(getOrdering());
                    orderingApplied = true;

                } else if (getOptionLabel() != null && !orderingApplied) {
                    query.addOrdering(getOptionLabel(), true);
                    orderingApplied = true;
                }

                list = dataContext.performQuery(query);

            } else if (getNamedQuery() != null) {
                list = dataContext.performQuery(getNamedQuery());

            } else if (getQueryName() != null) {
                 list = dataContext.performQuery(getQueryName(), false);

            } else {
                Class doClass = form.getDataObjectClass();
                String getterName = ClickUtils.toGetterName(getName());
                Method method = doClass.getMethod(getterName, null);
                Class propertyClass = method.getReturnType();

                SelectQuery query = new SelectQuery(propertyClass);

                if (getOrdering() != null && !orderingApplied) {
                    query.addOrdering(getOrdering());
                    orderingApplied = true;

                } else if (getOptionLabel() != null && !orderingApplied) {
                    query.addOrdering(getOptionLabel(), true);
                    orderingApplied = true;
                }

                list = dataContext.performQuery(query);
            }

            if (isRequired() && getOptionList().isEmpty() || isOptional()) {
                getOptionList().add(Option.EMPTY_OPTION);
            }

            Map cache = new HashMap();

            for (int i = 0; i < list.size(); i++) {
                DataObject dataObject = (DataObject) list.get(i);
                String value = DataObjectUtils.pkForObject(dataObject).toString();

                Object label = null;

                if (getDecorator() != null) {
                    label = getDecorator().render(dataObject, getContext());

                } else {
                    if (getOptionLabel() == null) {
                        String msg =
                            "optionLabel not defined for PropertySelect: " + getName();
                        throw new IllegalStateException(msg);
                    }
                    label = PropertyUtils.getValue(dataObject, getOptionLabel(), cache);
                }

                Option option = null;

                if (label != null) {
                    option = new Option(value, label.toString());

                } else {
                    option = new Option(value);
                }

                add(option);
            }

View Full Code Here

TOP

Related Classes of org.apache.click.control.Option

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.