resultsPanelContainer.setVisible(event.getResponse().getPagedSet().size() > 0);
String historyToken = "";
for (ModelView result : event.getResponse().getPagedSet())
{
final FocusPanel itemContainer = new FocusPanel();
final FlowPanel itemPanel = new FlowPanel();
final Hyperlink name = new Hyperlink();
name.addStyleName(StaticResourceBundle.INSTANCE.coreCss().globalSearchItemName());
name.addStyleName(StaticResourceBundle.INSTANCE.coreCss().ellipsisChild());
if (result instanceof PersonModelView)
{
final PersonModelView person = (PersonModelView) result;
itemPanel.add(AvatarLinkPanel.create(person, Size.Small, false));
name.setText(person.getDisplayName());
name.setTitle(person.getDisplayName());
historyToken = Session.getInstance().generateUrl(
new CreateUrlRequest(Page.PEOPLE, person.getAccountId()));
itemContainer.addClickHandler(new ClickHandler()
{
public void onClick(final ClickEvent event)
{
ArrayList<String> views = new ArrayList<String>();
views.add(person.getAccountId());
eventBus.notifyObservers(new UpdateHistoryEvent(new CreateUrlRequest(Page.PEOPLE,
views)));
}
});
}
else if (result instanceof DomainGroupModelView)
{
final DomainGroupModelView group = (DomainGroupModelView) result;
itemPanel.add(new AvatarLinkPanel(EntityType.GROUP, group.getShortName(), group
.getAvatarId(), Size.Small, false));
name.setText(group.getName());
name.setTitle(group.getName());
historyToken = Session.getInstance().generateUrl(
new CreateUrlRequest(Page.GROUPS, group.getShortName()));
itemContainer.addClickHandler(new ClickHandler()
{
public void onClick(final ClickEvent event)
{
ArrayList<String> views = new ArrayList<String>();
views.add(group.getShortName());
eventBus.notifyObservers(new UpdateHistoryEvent(new CreateUrlRequest(Page.GROUPS,
views)));
}
});
}
itemContainer.addMouseOverHandler(new MouseOverHandler()
{
public void onMouseOver(final MouseOverEvent arg0)
{
selectItem(itemContainer);
}
});
name.setTargetHistoryToken(historyToken);
itemPanel.add(name);
itemContainer.add(itemPanel);
resultsPanel.add(itemContainer);
if (activeItem == null)
{
selectItem(itemContainer);
}
}
if (event.getResponse().getTotal() > event.getResponse().getPagedSet().size())
{
final FocusPanel itemContainer = new FocusPanel();
final FlowPanel itemPanel = new FlowPanel();
itemContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().searchResultsMoreButton());
itemPanel.add(new Label("See more results"));
itemContainer.addClickHandler(new ClickHandler()
{
public void onClick(final ClickEvent event)
{
eventBus.notifyObservers(new UpdateHistoryEvent(new CreateUrlRequest(Page.SEARCH,
generateParams(searchTerm.getText()), false)));
}
});
itemContainer.addMouseOverHandler(new MouseOverHandler()
{
public void onMouseOver(final MouseOverEvent arg0)
{
selectItem(itemContainer);
}
});
itemContainer.add(itemPanel);
resultsPanel.add(itemContainer);
}
}
}