de.knightsoftnet.validationexample.client.ui.page.settings.SettingsPresenter.java Source code

Java tutorial

Introduction

Here is the source code for de.knightsoftnet.validationexample.client.ui.page.settings.SettingsPresenter.java

Source

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package de.knightsoftnet.validationexample.client.ui.page.settings;

import de.knightsoftnet.validationexample.client.ui.basepage.BasePagePresenter;
import de.knightsoftnet.validationexample.client.ui.navigation.NameTokens;

import com.google.gwt.i18n.client.LocaleInfo;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Window;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.NoGatekeeper;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;

import javax.inject.Inject;

/**
 * Presenter of the validator test settings.
 *
 * @author Manfred Tremmel
 *
 */
public class SettingsPresenter extends Presenter<SettingsPresenter.MyView, SettingsPresenter.MyProxy> {

    public interface MyView extends View {
        void setPresenter(SettingsPresenter pactivity);
    }

    @ProxyCodeSplit
    @NameToken(NameTokens.SETTINGS)
    @NoGatekeeper
    public interface MyProxy extends ProxyPlace<SettingsPresenter> {
    }

    /**
     * constructor parameters are generated by injection.
     *
     * @param peventBus event bus
     * @param pview view of the page
     * @param pproxy proxy to handle pages
     */
    @Inject
    public SettingsPresenter(final EventBus peventBus, final SettingsPresenter.MyView pview, final MyProxy pproxy) {
        super(peventBus, pview, pproxy, BasePagePresenter.SLOT_MAIN_CONTENT);
        this.getView().setPresenter(this);
    }

    /**
     * change the language of the ui.
     *
     * @param planguage language to switch to.
     */
    public final void changeLanguage(final String planguage) {
        Cookies.setCookie(LocaleInfo.getLocaleCookieName(), planguage);
        Window.Location.reload();
    }
}