new Observer<ThemeChangedEvent>()
{
public void update(final ThemeChangedEvent arg1)
{
Session.getInstance().getEventBus().notifyObservers(
new UpdateHistoryEvent(new CreateUrlRequest(Page.START)));
Location.reload();
}
});
HashMap<String, String> params = new HashMap<String, String>();
params.put("tab", Long.toString(tabDomainObjects.get(0).getId()));
params.put("galleryTab", "Apps");
params.put("listId", "gadgets");
settings.setTargetHistoryToken(Session.getInstance().generateUrl(
new CreateUrlRequest(Page.GALLERY, params)));
// Respond to history changes.
Session.getInstance().getEventBus().addObserver(UpdatedHistoryParametersEvent.class,
new Observer<UpdatedHistoryParametersEvent>()
{
public void update(final UpdatedHistoryParametersEvent event)
{
// Note: parameters do not need to be decoded here -that's already done
// by
// HistoryHandler before it published the event
if (event.getParameters().get("tab")
// line break
!= null)
{
HashMap<String, String> params = new HashMap<String, String>();
params.put("tab", event.getParameters().get("tab"));
params.put("galleryTab", "Apps");
settings.setTargetHistoryToken(Session.getInstance().generateUrl(
new CreateUrlRequest(Page.GALLERY, params)));
}
if (event.getParameters().get("action").equals("addGadget"))
{
String prefs = event.getParameters().get("prefs");
String url = event.getParameters().get("url");
// Clear current action
event.getParameters().put("action", "");
event.getParameters().put("url", "");
event.getParameters().put("prefs", "");
EventBus.getInstance().notifyObservers(
new UpdatedHistoryParametersEvent(event.getParameters(), false));
GadgetModel.getInstance().insert(
new AddGadgetToStartPageRequest(url, tabsResponse.get(0).getId(),
prefs));
}
else if (event.getParameters().get("action").equals("setTheme"))
{
// Clear current action
EventBus.getInstance().notifyObservers(
new UpdatedHistoryParametersEvent(event.getParameters(), false));
String url = event.getParameters().get("url");
ThemeModel.getInstance().set(url);
}
}
}, true);
// Respond to new tabs.
Session.getInstance().getEventBus().addObserver(InsertedStartTabResponseEvent.class,
new Observer<InsertedStartTabResponseEvent>()
{
public void update(final InsertedStartTabResponseEvent event)
{
Session.getInstance().getEventBus()
.notifyObservers(new HideNotificationEvent());
newTab.getTextBox().setVisible(false);
newTab.getLabel().setVisible(true);
StartPageTab tab = new StartPageTab(event.getResponse());
tabs.insertTab(tab, event.getResponse().getTabIndex());
// If more than 8 tabs (the new tab counts as 1) disable the new tab.
if (tabs.getSize() >= Person.TAB_LIMIT + 1)
{
tabs.removeTab(newTab.getIdentifier());
}
// If 2 tabs are present (the new tab counts as 1) re-enable the remove.
if (tabs.getSize() == 3)
{
((StartPageTab) tabs.getTab(0)).enableRemove();
}
// The start page tab is ready.
Session.getInstance().getEventBus().notifyObservers(
new StartPageTabReadyEvent(tab));
Session.getInstance().getEventBus().notifyObservers(
new UpdateHistoryEvent(new CreateUrlRequest("tab", tab.getIdentifier(),
true)));
}
});
Session.getInstance().getEventBus().addObserver(DeletedStartPageTabResponseEvent.class,
new Observer<DeletedStartPageTabResponseEvent>()
{
public void update(final DeletedStartPageTabResponseEvent event)
{
tabs.removeTab(String.valueOf(event.getResponse().getId()));
tabs.addTab(newTab);
Session.getInstance().getEventBus().notifyObservers(
new ShowNotificationEvent(new Notification(new UndoDeleteNotification(
event.getResponse().getTabName(), new ClickHandler()
{
public void onClick(final ClickEvent clickEvent)
{
StartTabsModel.getInstance().undoDelete(
event.getResponse().getId());
Session.getInstance().getEventBus().notifyObservers(
new HideNotificationEvent());
}
}), "")));
// Highlight the first tab
Session.getInstance().getEventBus().notifyObservers(
new UpdateHistoryEvent(new CreateUrlRequest("tab", ((StartPageTab) tabs
.getTab(0)).getIdentifier(), true)));
// Only one tab left (the new tab counts as 1). Disable remove.
if (tabs.getSize() == 2)
{