Package org.apache.click.control

Examples of org.apache.click.control.Option


     * 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

    public void add(String value) {
        if (value == null) {
            String msg = "value parameter cannot be null";
            throw new IllegalArgumentException(msg);
        }
        getOptionList().add(new Option(value));
    }
View Full Code Here

            String msg = "options parameter cannot be null";
            throw new IllegalArgumentException(msg);
        }
        for (Iterator i = options.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();
            Option option = new Option(entry.getKey().toString(), entry
                    .getValue().toString());
            getOptionList().add(option);
        }
    }
View Full Code Here

            String msg = "options parameter cannot be null";
            throw new IllegalArgumentException(msg);
        }
        for (int i = 0; i < options.length; i++) {
            String value = options[i];
            getOptionList().add(new Option(value, value));
        }
    }
View Full Code Here

            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

            throw new IllegalStateException(msg);
        }

        // 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;
        }

        DataContext dataContext = DataContext.getThreadDataContext();

        List list = Collections.EMPTY_LIST;

        if (getSelectQuery() != null) {
            list = dataContext.performQuery(getSelectQuery());

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

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

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

        Map cache = new HashMap();

        for (int i = 0; i < list.size(); i++) {
            Object row = list.get(i);

            Object value = null;
            Object label = null;

            if (row instanceof DataRow) {
                DataRow dataRow = (DataRow) row;

                if (dataRow.containsKey(getOptionValue())) {
                    value = dataRow.get(getOptionValue());

                } else {
                    String msg = "no value in dataRow for optionValue: "
                                 + getOptionValue();
                    throw new RuntimeException(msg);
                }

                if (getOptionLabel() != null) {

                    if (dataRow.containsKey(getOptionLabel())) {
                        label = dataRow.get(getOptionLabel());

                    } else {
                        String msg = "no value in dataRow for optionLabel: "
                                     + getOptionLabel();
                        throw new RuntimeException(msg);
                    }

                } else {
                    label = getDecorator().render(dataRow, getContext());
                }

            } else {

                try {

                    value = PropertyUtils.getValue(row, getOptionValue(), cache);

                    if (getOptionLabel() != null) {
                        label = PropertyUtils.getValue(row, getOptionLabel(), cache);

                    } else {
                        label = getDecorator().render(row, getContext());
                    }

                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            value = (value != null) ? value : "";
            label = (label != null) ? label : "";

            getOptionList().add(new Option(value.toString(), label.toString()));
        }
    }
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);
                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.