All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jpattern.gwt.client.navigationevent.RootNavigationEvent Maven / Gradle / Ivy

package com.jpattern.gwt.client.navigationevent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.google.gwt.user.client.ui.HasWidgets;
import com.jpattern.gwt.client.IApplicationProvider;
import com.jpattern.gwt.client.history.IHistoryManager;
import com.jpattern.gwt.client.presenter.APresenter;
import com.jpattern.gwt.client.presenter.IPresenter;
import com.jpattern.gwt.client.view.IView;
import com.jpattern.gwt.client.view.NullShowViewStrategy;
import com.jpattern.gwt.client.view.NullView;

/**
 * 
 * @author Francesco Cina
 *
 * 03/ago/2011
 */
public class RootNavigationEvent extends ANavigationEvent {

	private final List registeredNavigationEvents = new ArrayList();
	private final Map> initialNavigationEvents = new HashMap>();

	public RootNavigationEvent(String rootEventName) {
		super(rootEventName);
	}
	
	public RootNavigationEvent(String rootEventName, IApplicationProvider applicationProvider) {
		super(rootEventName , applicationProvider);
	}

	public void startApplication() {
		IHistoryManager historyManager = getProvider().getHistoryService().getHistoryManager();
		historyManager.setRootNavigationEvent(this);
		historyManager.updateState();
	}
	
	@Override
	public IPresenter exec(Map queryStringValues) {
		IPresenter presenter = new RootPresenter(this);
		return presenter;
	}
	
	/**
	 * Register a new navigation event throwable by the current presenter
	 * @param navigationEvent
	 * @param eventTarget the target area where the new view will be rendered
	 * @param navigationEventCallback
	 */
	public void registerNavigationEvent(INavigationEvent navigationEvent, HasWidgets eventTarget, INavigationEventCallback navigationEventCallback) {
		registeredNavigationEvents.add(new NavigationEventData(navigationEvent, eventTarget, navigationEventCallback));
	}
	
	/**
	 * Set an event to be executed when the presenter is initialized
	 * @param navigationEventName
	 * @param registerHistory indicate if the event must be registered in the navigation history, this must be true only if the event has been thrown by an explicit user action
	 */
	public void addInitialNavigationEvent(String navigationEventName) {
		addInitialNavigationEvent(navigationEventName, new HashMap());
	}
	
	/**
	 * Set an event to be executed when the presenter is initialized
	 * @param navigationEventName
	 * @param queryStringValues a map with key value pair to be passed at the navigationEvent exec() method to build the new Presenter
	 * @param registerHistory indicate if the event must be registered in the navigation history, this must be true only if the event has been thrown by an explicit user action
	 */
	public void addInitialNavigationEvent(String navigationEventName, Map queryStringValues) {
		initialNavigationEvents.put(navigationEventName, queryStringValues);
	}

	class RootPresenter extends APresenter {

		public RootPresenter(INavigationEvent navigationEvent) {
			super(new NullShowViewStrategy(new NullView()), navigationEvent);
			for (INavigationEventData entry : registeredNavigationEvents) {
				registerNavigationEvent( entry.getNavigationEvent(), entry.getEventTarget(), entry.getNavigationEventCallback() );
			}
			for (Entry> entry : initialNavigationEvents.entrySet()) {
				addInitialNavigationEvent(entry.getKey(), entry.getValue());
			}
		}

		@Override
		public void preDisplay() {
		}

		@Override
		public void postDisplay() {
		}
		
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy