/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2013 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.plugin.geocoder.puregwt.example.client.sample;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.ResizeLayoutPanel;
import com.google.gwt.user.client.ui.Widget;

import org.geomajas.plugin.geocoder.client.GeocoderWidget;
import org.geomajas.puregwt.client.event.MapInitializationEvent;
import org.geomajas.puregwt.client.event.MapInitializationHandler;
import org.geomajas.puregwt.client.map.MapPresenter;
import org.geomajas.puregwt.client.widget.MapLayoutPanel;
import org.geomajas.puregwt.example.base.client.ExampleBase;
import org.geomajas.puregwt.example.base.client.sample.SamplePanel;

/**
 * Class description.
 *
 * @author Dosi Bingov
 */
public class GeoCoderExample implements SamplePanel {

	protected DockLayoutPanel rootElement;

	private MapPresenter mapPresenter;

	@UiField
	protected ResizeLayoutPanel mapPanel;

	@Override
	public Widget asWidget() {
		// return root layout element
		return rootElement;
	}

	/**
	 * UI binder interface.
	 *
	 * @author Dosi Bingov
	 */
	interface FeatureSelectedExampleUiBinder extends
			UiBinder<DockLayoutPanel, GeoCoderExample> {

	}

	private static final FeatureSelectedExampleUiBinder UIBINDER = GWT.create(FeatureSelectedExampleUiBinder.class);

	public GeoCoderExample() {
		rootElement = UIBINDER.createAndBindUi(this);

		// Create the MapPresenter
		mapPresenter = ExampleBase.getInjector().getMapPresenter();

		// Initialize the map
		mapPresenter.getEventBus().addMapInitializationHandler(new MyMapInitializationHandler());
		mapPresenter.initialize("geocoder-app", "mapOsm");
		ResizeLayoutPanel resizeLayoutPanel = new ResizeLayoutPanel();
		final MapLayoutPanel layout = new MapLayoutPanel();
		resizeLayoutPanel.setWidget(layout);
		resizeLayoutPanel.setSize("100%", "100%");
		layout.setPresenter(mapPresenter);

		// create geocoder widget
		GeocoderWidget geocoder = new GeocoderWidget(mapPresenter);
		geocoder.getElement().getStyle().setTop(7, Style.Unit.PX);
		geocoder.getElement().getStyle().setLeft(100, Style.Unit.PX);

		// add geocoder widget to the map
		mapPresenter.getWidgetPane().add(geocoder);

		mapPanel.setWidget(resizeLayoutPanel);
	}

	/**
	 * private MapInitializationHandler to zoom in the map.
	 */
	private class MyMapInitializationHandler implements MapInitializationHandler {

		public void onMapInitialized(MapInitializationEvent event) {
			double scale = mapPresenter.getViewPort().getScale() * 6;
			mapPresenter.getViewPort().applyScale(scale);
		}
	}
}
@@ -887,24 +887,79 @@
 derWidget;%0D%0A
+import org.geomajas.puregwt.client.GeomajasGinjector;%0D%0A
 import org.g
@@ -1008,24 +1008,24 @@
 tionEvent;%0D%0A
-
 import org.g
@@ -1526,16 +1526,115 @@
 ter;%0D%0A%0D%0A
+%09private static final GeomajasGinjector GEOMAJASINJECTOR = GWT.create(GeomajasGinjector.class);%0D%0A%0D%0A
 %09@UiFiel
@@ -2205,33 +2205,24 @@
 r = 
-ExampleBase.getInjector()
+GEOMAJASINJECTOR
 .get

work around for deprecated method