Example usage for org.apache.wicket Component getLocale

List of usage examples for org.apache.wicket Component getLocale

Introduction

In this page you can find the example usage for org.apache.wicket Component getLocale.

Prototype

public Locale getLocale() 

Source Link

Document

Gets the locale for this component.

Usage

From source file:org.dcm4chee.web.common.util.DateUtils.java

License:LGPL

public static String getDatePattern(Component c) {
    String pattern = DateTimeFormat.patternForStyle("S-", c.getLocale());
    int pos1 = pattern.indexOf('y');
    if (pos1 != -1) {
        if (pattern.length() <= pos1 + 2) {
            pattern = pattern + "yy";
        } else if (pattern.charAt(pos1 + 2) != 'y') {
            pattern = pattern.substring(0, pos1) + "yyyy" + pattern.substring(pos1 + 2);
        }//from   w w  w  .j a  v a 2  s .  c om
    }
    return pattern;
}

From source file:org.geoserver.web.GeoServerStringResourceLoader.java

License:Open Source License

/**
 * //from   www .  ja v a2s  . co m
 * @see org.apache.wicket.resource.loader.IStringResourceLoader#loadStringResource(org.apache.wicket.Component,
 *      java.lang.String)
 */
public String loadStringResource(final Component component, final String key) {
    if (component == null) {
        return null;
    }

    // The return value
    String string = null;
    Locale locale = component.getLocale();
    String style = component.getStyle();

    // The reason why we need to create that stack is because we need to
    // walk it downwards starting with Page down to the Component
    List containmentStack = getComponentStack(component);

    // Walk the component hierarchy down from page to the component
    for (int i = containmentStack.size() - 1; (i >= 0) && (string == null); i--) {
        Class clazz = (Class) containmentStack.get(i);

        // First, try the fully qualified resource name relative to the
        // component on the path from page down.
        string = loadStringResource(clazz, key, locale, style);
    }

    // If not found, than check if a property with the 'key' provided by
    // the user can be found.
    if (string == null) {
        string = loadStringResource(null, key, locale, style);
    }

    return string;
}

From source file:org.imagebundler.wicket.ImageStyleModel.java

License:Apache License

@Override
protected final String getObject(Component component) {
    Locale locale = component.getLocale();
    return imageItem.getStyle(locale);
}

From source file:org.modelibra.wicket.util.LocalizedText.java

License:Apache License

/**
 * Obtains a localized text from application properties. If the text is not
 * found, the method returns the text key. Use this method if you need
 * localized text in component constructor.
 * /*from ww w .j  a va2  s. c  om*/
 * @param comp
 *            the component requesting the text
 * @param textKey
 * @return text
 */
public static String getApplicationPropertiesText(Component comp, String textKey) {
    String text;
    text = classStringResourceLoader.loadStringResource(null, textKey, comp.getLocale(), comp.getStyle());
    return text;
}

From source file:org.obiba.onyx.wicket.behavior.LanguageStyleBehavior.java

License:Open Source License

@Override
public void onComponentTag(Component component, ComponentTag tag) {
    String cssClass = "obiba-lang-" + component.getLocale();

    if (tag.getAttributes().containsKey("class")) {
        cssClass += " " + tag.getAttributes().getString("class");
    }//from  w  w w.j a  va2 s.c  o m
    tag.getAttributes().put("class", cssClass);
}

From source file:org.projectforge.web.calendar.MyFullCalendarConfig.java

License:Open Source License

/**
 * @param parent Used for localization.// w  w w . j ava 2 s .  c o  m
 * @see Component#getString(String)
 * @see Component#getLocale()
 */
public MyFullCalendarConfig(final Component parent) {
    this.parent = parent;
    setAspectRatio(1.5f);
    setIgnoreTimezone(true);
    setSlotMinutes(15);
    setFirstHour(8);
    getHeader().setLeft("prev,next today");
    getHeader().setCenter("title");
    getHeader().setRight("month,agendaWeek,agendaDay");

    getButtonText().setToday(getString("calendar.today"));
    getButtonText().setWeek(getString("calendar.week"));
    getButtonText().setMonth(getString("calendar.month"));
    getButtonText().setDay(getString("calendar.day"));
    setAllDayText(getString("calendar.allday"));
    I18nCore.setFullCalendarDateFormats(PFUserContext.getUser(), this);
    final DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(parent.getLocale());
    setDayNames(convert(dateFormatSymbols.getWeekdays()));
    setDayNamesShort(convert(dateFormatSymbols.getShortWeekdays()));
    setMonthNames(dateFormatSymbols.getMonths());
    setMonthNamesShort(dateFormatSymbols.getShortMonths());
    setWeekMode("variable");
    setEnableContextMenu(true);
    setEventRenderModel(Model.of(
            "function(event, element) {if (event.tooltipTitle) {initMyPopover(element); element.mypopover({title: event.tooltipTitle, content: event.tooltipContent, html: true })}}"));
}

From source file:org.wicketstuff.extjs.util.ExtConfigResourceLoader.java

License:Apache License

protected void loadStringResource(final Component component, final String key, final Config config) {
    if (component == null) {
        return;/*from   w  w  w.  j av  a 2s . c  om*/
    }

    Locale locale = component.getLocale();
    String style = component.getStyle();

    // The key prefix is equal to the component path relative to the
    // current component on the top of the stack.
    String prefix = Strings.replaceAll(component.getPageRelativePath(), ":", ".").toString();

    // The reason why we need to create that stack is because we need to
    // walk it downwards starting with Page down to the Component
    List searchStack = getComponentStack(component);

    // Walk the component hierarchy down from page to the component
    for (int i = searchStack.size() - 1; i >= 0; i--) {
        Class clazz = (Class) searchStack.get(i);

        // First, try the fully qualified resource name relative to the
        // component on the path from page down.
        if ((prefix != null) && (prefix.length() > 0)) {
            loadStringResource(clazz, prefix + '.' + key, locale, style, config);
            prefix = Strings.afterFirst(prefix, '.');
        }

        if (i == 0 && component.getClass().equals(clazz)) {
            /*
             * Before the last component that is supposed to contains the components default we try in the application configuration file
             */
            loadStringResource(Application.get().getClass(), key, locale, style, config);
        }

        loadStringResource(clazz, key, locale, style, config);
    }

}

From source file:org.wicketstuff.extjs.util.ExtConfigResourceLoader.java

License:Apache License

protected String getCacheKey(final String key, final Component component) {
    String cacheKey = key;/*w  w  w .jav a2 s  .  c o  m*/
    if (component != null) {
        AppendingStringBuffer buffer = new AppendingStringBuffer(200);
        buffer.append(key);

        Component cursor = component;
        while (cursor != null) {
            buffer.append("-").append(cursor.getClass().hashCode());

            if (cursor instanceof Page) {
                break;
            }

            if (cursor.getParent() != null && !(cursor.getParent() instanceof AbstractRepeater)) {
                /*
                 * only append component id if parent is not a repeater because
                 *
                 * (a) these ids are irrelevant when generating resource cache keys
                 *
                 * (b) they cause a lot of redundant keys to be generated
                 */
                buffer.append(":").append(cursor.getId());
            }
            cursor = cursor.getParent();

        }

        buffer.append("-").append(component.getLocale());
        buffer.append("-").append(component.getStyle());
        // TODO 1.4 look if we want to properly separate getstyle/getvariation
        // for now getvariation() is rolled up into getstyle()
        // buffer.append("-").append(component.getVariation());
        cacheKey = buffer.toString();
    }
    return cacheKey;
}

From source file:org.wicketstuff.gchart.ChartLibLoaderBehavior.java

License:Apache License

@Override
public void bind(Component component) {
    if (!(component instanceof Page)) {
        throw new IllegalArgumentException("This behavior should be used at the page, not the chart!");
    }//w ww.  j a  v a2 s  .c  o  m
    super.bind(component);
    locale = component.getLocale();
}

From source file:org.wicketstuff.jquery.datepicker.DatePickerBehavior.java

License:Apache License

@Override
protected void onBind() {
    super.onBind();
    Component component = getComponent();
    if (component instanceof TextField) {
        component.setOutputMarkupId(true);

        if (component instanceof ITextFormatProvider) {
            format_ = ((ITextFormatProvider) component).getTextFormat().toLowerCase();
        } else {//  ww w.  j  av  a2 s .co m
            TextField<?> tf = (TextField<?>) component;
            IConverter<?> cnv = tf.getConverter(tf.getType());
            if (cnv != null && DateConverter.class.isAssignableFrom(cnv.getClass())) {
                SimpleDateFormat sdf = (SimpleDateFormat) ((DateConverter) cnv)
                        .getDateFormat(component.getLocale());
                format_ = sdf.toPattern().toLowerCase();
            }

            // convertDateInOptions(cnv, "startDate", component.getLocale());
            // convertDateInOptions(cnv, "endDate", component.getLocale());
        }

        component.add(getDatePickerStyle());
    } else {
        throw new RuntimeException("DatePicketBehavior is intended to be attached to a TextField component!");
    }
}