Example usage for com.vaadin.server VaadinRequest getLocale

List of usage examples for com.vaadin.server VaadinRequest getLocale

Introduction

In this page you can find the example usage for com.vaadin.server VaadinRequest getLocale.

Prototype

public Locale getLocale();

Source Link

Document

Gets locale information from the query, e.g.

Usage

From source file:org.lucidj.vaadinui.BaseVaadinUI.java

License:Apache License

private void init_desktop(VaadinRequest vaadinRequest) {
    Responsive.makeResponsive(this);
    setLocale(vaadinRequest.getLocale());

    if (vaadinRequest instanceof VaadinServletRequest) {
        VaadinServletRequest vsr = (VaadinServletRequest) vaadinRequest;
        InetAddress remote_addr = null;

        // TODO: USE AUTOMATIC KEY AUTHENTICATION FOR SINGLE MODE
        try {//from w w w.j  a  va2s . co  m
            remote_addr = InetAddress.getByName(vsr.getRemoteAddr());
        } catch (UnknownHostException ignore) {
        }
        ;

        // Login tokens may be used only when browsing from the same machine
        if (remote_addr != null && remote_addr.isLoopbackAddress()
                && Login.isValidLoginToken(vsr.getParameter("token"))) {
            // Autologin into System when browsing from localhost
            log.warn("Automatic login from localhost using login token");
            security.createSystemSubject();

            // Erase the token from URL
            getPage().getJavaScript().execute("window.lucidj_vaadin_helper.clearUrl ()");
        }
    }

    if (!security.getSubject().isAuthenticated()) {
        setContent(new Login(security, new Login.LoginListener() {
            @Override
            public void loginSuccessful() {
                show_desktop();
            }
        }));
    } else {
        show_desktop();
    }
}

From source file:org.vaadin.webinars.springandvaadin.i18n.ui.createTask.CreateTaskUi.java

License:Apache License

@Override
protected void init(final VaadinRequest request) {
    engine.getRuntimeService().startProcessInstanceByKey("process");
    setLocale(request.getLocale());
    List<Task> tasks = engine.getTaskService().createTaskQuery().list();
    final String id = tasks.get(0).getId();
    getPage().setTitle("Task manager");
    CreateTaskClickListener listener = new CreateTaskClickListener(name, id, description,
            "/task_manager/expectedTime", getUI());
    submit.addClickListener(listener);//from w w w . j  a  v  a2 s .  co m
    HorizontalLayout nameLayout = helper.getHorizontalLayout("Task name:", name);
    HorizontalLayout descriptionLayout = helper.getHorizontalLayout("Description:", description);
    List<? extends AbstractComponent> components = Arrays.asList(nameLayout, descriptionLayout, submit);
    setContent(helper.getMainLayout(components));
}

From source file:org.vaadin.webinars.springandvaadin.i18n.ui.I18nUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    setLocale(request.getLocale());

    getPage().setTitle(messageSource.getMessage("page.title", null, getLocale()));

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);/*from www .  j  a  v  a 2 s .co m*/
    layout.setSpacing(true);
    setContent(layout);

    final TextField textField = new TextField(messageSource.getMessage("textField.caption", null, getLocale()));
    layout.addComponent(textField);

    final Button button = new Button(messageSource.getMessage("button.caption", null, getLocale()));
    button.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Notification.show(messageSource.getMessage("greeting.caption",
                    new Object[] { textField.getValue() }, getLocale()));
        }
    });
    layout.addComponent(button);

    final Button swe = new Button("P svenska", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            LocaleContextHolder.setLocale(new Locale("sv"));
            getPage().reload();
        }
    });
    layout.addComponent(swe);

    final Button eng = new Button("In English", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            LocaleContextHolder.setLocale(new Locale("en"));
            getPage().reload();
        }
    });
    layout.addComponent(eng);

}

From source file:pl.exsio.frameset.vaadin.i18n.locale.provider.ClientLocaleProviderImpl.java

License:Open Source License

@Override
public Locale getLocale() {
    VaadinRequest request = this.getCurrentVaadinRequest();
    if (request instanceof VaadinRequest) {
        String forcedLocale = request.getParameter(FORCED_LOCALE_PARAM);
        if (forcedLocale != null && !forcedLocale.isEmpty()) {
            this.lastKnownLocale = this.getLocaleFromString(forcedLocale);
        } else {/* w  w w  . j av  a2s. c  om*/
            this.lastKnownLocale = request.getLocale();
        }
    }
    return this.lastKnownLocale;
}