package placebooks.client.ui;

import placebooks.client.model.Shelf;
import placebooks.client.model.User;
import placebooks.client.resources.Resources;
import placebooks.client.ui.PlaceBookToolbarLogin.ShelfListener;
import placebooks.client.ui.places.PlaceBookBrowsePlace;
import placebooks.client.ui.places.PlaceBookEditorNewPlace;
import placebooks.client.ui.places.PlaceBookHomePlace;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.user.client.ui.FlowPanel;

public class PlaceBookToolbar extends FlowPanel
{
	private final PlaceBookToolbarLogin login = new PlaceBookToolbarLogin();
	private PlaceController placeController;

	public PlaceBookToolbar()
	{
		super();
		setStyleName(Resources.INSTANCE.style().toolbar());

		add(new PlaceBookToolbarItem("HOME", null, new ClickHandler()
		{

			@Override
			public void onClick(final ClickEvent event)
			{
				placeController.goTo(new PlaceBookHomePlace(login.getShelf()));

			}
		}));
		add(new PlaceBookToolbarItem("CREATE", Resources.INSTANCE.add(), new ClickHandler()
		{

			@Override
			public void onClick(final ClickEvent event)
			{
				placeController.goTo(new PlaceBookEditorNewPlace(login.getShelf().getUser()));
			}
		}));
		add(new PlaceBookToolbarItem("MY LIBRARY", Resources.INSTANCE.book(), new ClickHandler()
		{

			@Override
			public void onClick(final ClickEvent event)
			{
				placeController.goTo(new PlaceBookBrowsePlace(login.getShelf()));
			}
		}));
		add(login);
	}

	public PlaceController getPlaceController()
	{
		return placeController;
	}
	
	public PlaceBookToolbarLogin getLogin()
	{
		return login;
	}
	
	public void setUser(final User user)
	{
		login.setUser(user);
	}

	public void setPlaceController(final PlaceController placeController)
	{
		login.setPlaceController(placeController);
		this.placeController = placeController;
	}

	public void setShelf(final Shelf shelf)
	{
		login.setShelf(shelf);
	}

	public void setShelfListener(final ShelfListener shelfListener)
	{
		login.setShelfListener(shelfListener);
	}
}

@@ -753,29 +753,36 @@
 troller;%0A%0A%09p
-ublic
+rivate final
  PlaceBookTo
@@ -790,86 +790,24 @@
 lbar
-()%0A%09%7B%0A%09%09super();%0A%09%09setStyleName(Resources.INSTANCE.style().toolbar());%0A%0A%09%09add(
+Item homeItem = 
 new 
@@ -852,38 +852,35 @@
  ClickHandler()%0A
-%09
 %09%7B%0A
-%0A%09
 %09%09@Override%0A%09%09%09p
@@ -867,33 +867,32 @@
 %0A%09%7B%0A%09%09@Override%0A
-%09
 %09%09public void on
@@ -915,36 +915,34 @@
 kEvent event)%0A%09%09
-%09
 %7B%0A
-%09
 %09%09%09placeControll
@@ -995,32 +995,74 @@
 )));%0A%0A%09%09
-%09
 %7D%0A
-%09
 %09%7D)
-)
 ;%0A%09
-%09add(
+%0A%09private final PlaceBookToolbarItem createItem = 
 new Plac
@@ -1125,38 +1125,35 @@
  ClickHandler()%0A
-%09
 %09%7B%0A
-%0A%09
 %09%09@Override%0A%09%09%09p
@@ -1140,33 +1140,32 @@
 %0A%09%7B%0A%09%09@Override%0A
-%09
 %09%09public void on
@@ -1188,36 +1188,34 @@
 kEvent event)%0A%09%09
-%09
 %7B%0A
-%09
 %09%09%09placeControll
@@ -1282,32 +1282,75 @@
 ()));%0A%09%09
-%09
 %7D%0A
-%09
 %09%7D)
-)
 ;%0A%09
-%09add(
+%0A%09private final PlaceBookToolbarItem libraryItem = 
 new Plac
@@ -1430,14 +1430,12 @@
 r()%0A
-%09
 %09%7B%0A%0A
-%09
 %09%09@O
@@ -1442,17 +1442,16 @@
 verride%0A
-%09
 %09%09public
@@ -1490,20 +1490,18 @@
 vent)%0A%09%09
-%09
 %7B%0A
-%09
 %09%09%09place
@@ -1567,29 +1567,248 @@
 ;%0A%09%09
-%09%7D%0A%09%09%7D));%0A%09%09add(login
+%7D%0A%09%7D);%0A%09%0A%09public PlaceBookToolbar()%0A%09%7B%0A%09%09super();%0A%09%09setStyleName(Resources.INSTANCE.style().toolbar());%0A%0A%09%09add(homeItem);%0A%09%09add(createItem);%0A%09%09add(libraryItem);%0A%09%09add(login);%0A%09%09%0A%09%09createItem.setEnabled(false);%0A%09%09libraryItem.setEnabled(false
 );%0A%09
@@ -2018,16 +2018,97 @@
 (user);%0A
+%09%09createItem.setEnabled(user != null);%0A%09%09libraryItem.setEnabled(user != null);%09%09%0A
 %09%7D%0A%0A%09pub

Disable library + create navigation items if user not set.