Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jboss.errai.ui.client.widget;
 
 
 import  javax.enterprise.context.Dependent;
 import  javax.inject.Inject;
 
 import  org.jboss.errai.ioc.client.api.AfterInitialization;
import  com.google.gwt.event.logical.shared.ValueChangeEvent;
import  com.google.gwt.event.logical.shared.ValueChangeHandler;
import  com.google.gwt.text.shared.Renderer;
import  com.google.gwt.user.client.ui.ValueListBox;
import  com.google.gwt.view.client.ProvidesKey;

ListBox that contains the available language options. A user of your application can select one of these options by hand. You can add a key in your bundle that is equal to the locale key (default for the one without locale key) to add translation of the label.
   {
      "default": "English",
      "nl": "Nederlands"

   }
 

Author(s):
edewit@redhat.com
@Dependent
public class LocaleListBox extends ValueListBox<Locale> {
  @Inject
  public LocaleListBox() {
    super(new LocaleRenderer(), new LocaleProvidesKey());
  }
  @AfterInitialization
  public void init() {
    addValueChangeHandler(new ValueChangeHandler<Locale>() {
      @Override
      public void onValueChange(ValueChangeEvent<Localeevent) {
        .select(event.getValue().getLocale());
      }
    });
  }
  private static class LocaleRenderer implements Renderer<Locale> {
    @Override
    public String render(Locale locale) {
      return locale.getLabel();
    }
    @Override
    public void render(Locale localeAppendable appendablethrows IOException {
      appendable.append(render(locale));
    }
  }
  private static class LocaleProvidesKey implements ProvidesKey<Locale> {
    @Override
    public Object getKey(Locale item) {
      final String activeLocale = TemplateUtil.getTranslationService().getActiveLocale();
      String defaultLanguage = activeLocale != null ? activeLocale : .;
      return item == null || item.getLocale() == null ? defaultLanguage : item.getLocale();
    }
  }
New to GrepCode? Check out our FAQ X