final EventBus eventBus = Session.getInstance().getEventBus();
final String flaggedActivitiesFilterName = "Flagged Activities";
final String pendingGroupsFilterName = "Group Requests";
// set up the tab itself
final PagedListPanel adminTabContent = new PagedListPanel("pending", new SingleColumnPagedListRenderer(),
"tab", "Pending");
adminTabContent.addStyleName(StaticResourceBundle.INSTANCE.coreCss().pendingTabContent());
// wire up the data retrieval events
eventBus.addObserver(GotFlaggedActivitiesResponseEvent.class, new Observer<GotFlaggedActivitiesResponseEvent>()
{
public void update(final GotFlaggedActivitiesResponseEvent event)
{
if (flaggedActivitiesFilterName.equals(adminTabContent.getCurrentFilter()))
{
adminTabContent.render(event.getResponse(), "No flagged activities.");
}
flaggedActivityCount = event.getResponse().getTotal();
adminTabContent.setFilterTitle(flaggedActivitiesFilterName, "Flagged Activities ("
+ flaggedActivityCount + ")");
setTitle("Pending (" + (flaggedActivityCount + pendingGroupCount) + ")");
}
});
eventBus.addObserver(GotPendingGroupsResponseEvent.class, new Observer<GotPendingGroupsResponseEvent>()
{
public void update(final GotPendingGroupsResponseEvent event)
{
if (pendingGroupsFilterName.equals(adminTabContent.getCurrentFilter()))
{
adminTabContent.render(event.getResponse(), "No pending group requests.");
}
pendingGroupCount = event.getResponse().getTotal();
adminTabContent.setFilterTitle(pendingGroupsFilterName, "Group Requests (" + pendingGroupCount + ")");
setTitle("Pending (" + (flaggedActivityCount + pendingGroupCount) + ")");
}
});
// request the data to get the counts
// We need the counts for both of the lists, but at most one list will perform an initial data load, we need to
// force the load. (Only the list which is visible will load; if the tab is inactive then there are zero
// visible lists.)
FlaggedActivityModel.getInstance().fetch(new GetFlaggedActivitiesRequest(0, 1), false);
PendingGroupsModel.getInstance().fetch(new GetPendingGroupsRequest(0, 1), false);
// wire up events to refresh the list when something is removed
eventBus.addObserver(UpdatedActivityFlagResponseEvent.class, new Observer<UpdatedActivityFlagResponseEvent>()
{
public void update(final UpdatedActivityFlagResponseEvent ev)
{
eventBus.notifyObservers(new ShowNotificationEvent(new Notification(
"The flagged activity has been allowed")));
adminTabContent.reload();
}
});
eventBus.addObserver(UpdatedReviewPendingGroupResponseEvent.class,
new Observer<UpdatedReviewPendingGroupResponseEvent>()
{
public void update(final UpdatedReviewPendingGroupResponseEvent ev)
{
adminTabContent.reload();
}
});
eventBus.addObserver(DeletedActivityResponseEvent.class, new Observer<DeletedActivityResponseEvent>()
{
public void update(final DeletedActivityResponseEvent ev)
{
adminTabContent.reload();
}
});
// prepare the StaticResourceBundle.INSTANCE.coreCss().filters()
// flagged content StaticResourceBundle.INSTANCE.coreCss().filter()
StreamMessageItemRenderer flaggedRenderer = new StreamMessageItemRenderer(ShowRecipient.YES);
flaggedRenderer.setShowManageFlagged(true);
flaggedRenderer.setShowComment(true);
BaseActivityLinkBuilder activityLinkBuilder = new InContextActivityLinkBuilder();
activityLinkBuilder.addExtraParameter("manageFlagged", "true");
flaggedRenderer.setActivityLinkBuilder(activityLinkBuilder);
adminTabContent.addSet(flaggedActivitiesFilterName, FlaggedActivityModel.getInstance(), flaggedRenderer,
new GetFlaggedActivitiesRequest(0, 0));
// pending groups StaticResourceBundle.INSTANCE.coreCss().filter()
adminTabContent.addSet(pendingGroupsFilterName, PendingGroupsModel.getInstance(), new PendingGroupRenderer(),
new GetPendingGroupsRequest(0, 0));
return adminTabContent;
}