
com.jpattern.gwt.client.navigationevent.ANavigationEvent Maven / Gradle / Ivy
package com.jpattern.gwt.client.navigationevent;
import java.util.Map;
import com.jpattern.gwt.client.ApplicationProxy;
import com.jpattern.gwt.client.IApplicationProvider;
import com.jpattern.gwt.client.presenter.IPresenter;
import com.jpattern.gwt.client.presenter.IPresenterDefinition;
import com.jpattern.gwt.client.presenter.PresenterDefinition;
/**
*
* @author Francesco Cina
*
* 01/ago/2011
*/
public abstract class ANavigationEvent extends ABaseNavigationEvent implements INavigationEvent {
private IPresenter presenter;
/**
*
* @param eventName the unique event name
*/
public ANavigationEvent(String eventName) {
this(eventName, false, new String[0]);
}
/**
*
* @param eventName
* @param requireAuthentication whether the user have to be logged-in to access the presenter
* @param allowedRoles = The list of roles allowed to access this presenter.
* If a user doesn't belong to the roles list, the presenter will not be executed
* An empty array means no restriction to the access (default behaviour).
*/
public ANavigationEvent(String eventName, boolean requireAuthentication, String[] allowedRoles) {
this(eventName, requireAuthentication, allowedRoles, ApplicationProxy.getInstance().getApplicationProvider());
}
/**
*
* @param eventName
* @param provider
*/
public ANavigationEvent(String eventName, IApplicationProvider provider) {
this(eventName , false, new String[0], provider);
}
/**
*
* @param eventName
* @param requireAuthentication whether the user have to be logged-in to access the presenter
* @param allowedRoles = The list of roles allowed to access this presenter.
* If a user doesn't belong to the roles list, the presenter will not be executed
* An empty array means no restriction to the access (default behaviour).
* @param provider
*/
public ANavigationEvent(String eventName, boolean requireAuthentication, String[] allowedRoles, IApplicationProvider provider) {
super(eventName, requireAuthentication, allowedRoles, provider);
}
@Override
public final void notifyNavigationEvent(IPresenter parentPresenter, Map queryStringValues, String[] childrenEvent, boolean registerEvent) {
getProvider().getHistoryService().getHistoryManager().registerHistory(parentPresenter, queryStringValues, childrenEvent, registerEvent, this);
}
@Override
public final IPresenter launch(IPresenter parentPresenter, Map queryStringValues, String[] childrenEvent) {
IPresenter presenter = getPresenter(queryStringValues);
presenter.launchNavigationEvent(childrenEvent, false, queryStringValues);
initPresenter(parentPresenter, presenter);
return presenter;
}
private void initPresenter(IPresenter parentPresenter, IPresenter presenter) {
presenter.setParent(parentPresenter);
presenter.initPresenter();
parentPresenter.getView().onNavigationEvent(getName());
}
private IPresenter getPresenter(Map queryStringValues) {
presenter = exec(queryStringValues);
presenter.setApplicationProvider(getProvider());
return presenter;
}
/**
* Return the newly created presenter
* @return
*/
protected abstract IPresenter exec(Map queryStringValues);
/**
* Build a presenter definition based on the allowedRoles and the requireAuthentication fields.
* The name of the presenter is set as the same of the current ANavigationEvent
* @return
*/
protected IPresenterDefinition getPresenterDefinition() {
return new PresenterDefinition(getName(), isRequireAuthentication(), getAllowedRole(), this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy