fTrayMenu = trayMenuManager.createContextMenu(shell);
fTrayMenu.setVisible(true);
}
private void onSingleClick(Shell shell) {
NotificationService service = Controller.getDefault().getNotificationService();
List<INews> newsToShow = new ArrayList<INews>();
Mode mode = Mode.RECENT;
/* Return early if Notifier already showing */
if (service.isPopupVisible())
return;
/* Show News Downloaded while Minimized */
if (!fTeasingNewsCache.isEmpty()) {
synchronized (fTeasingNewsCache) {
int counter = 0;
for (int i = fTeasingNewsCache.size() - 1; i >= 0; i--) {
NewsReference reference = new NewsReference(fTeasingNewsCache.get(i));
INews newsitem = reference.resolve();
if (newsitem != null && newsitem.getState() == INews.State.NEW && service.shouldShow(newsitem)) {
newsToShow.add(newsitem);
if (++counter >= TEASE_LIMIT)
break;
} else
CoreUtils.reportIndexIssue();
/* Return early if Notifier already showing */
if (service.isPopupVisible())
return;
}
}
mode = Mode.INCOMING_MANUAL;
}
/* Show Recent News if no teasing news present */
if (newsToShow.isEmpty()) {
/* Build the Search if not yet done */
if (fTodaysNewsSearch == null) {
IModelFactory factory = Owl.getModelFactory();
String newsClassName = INews.class.getName();
ISearchField ageInDaysField = factory.createSearchField(INews.AGE_IN_DAYS, newsClassName);
ISearchField ageInMinutesField = factory.createSearchField(INews.AGE_IN_MINUTES, newsClassName);
ISearchCondition dayCondition = factory.createSearchCondition(ageInDaysField, SearchSpecifier.IS_LESS_THAN, 1); // From Today after Midnight
ISearchCondition recentCondition = factory.createSearchCondition(ageInMinutesField, SearchSpecifier.IS_LESS_THAN, -60 * 6); // Up to 6 Hours Ago
fTodaysNewsSearch = factory.createSearch(null);
fTodaysNewsSearch.setMatchAllConditions(false);
fTodaysNewsSearch.addSearchCondition(dayCondition);
fTodaysNewsSearch.addSearchCondition(recentCondition);
}
/* Sort by Id (simulate sorting by date) */
List<SearchHit<NewsReference>> result = Owl.getPersistenceService().getModelSearch().searchNews(fTodaysNewsSearch);
Set<NewsReference> recentNews = new TreeSet<NewsReference>(new Comparator<NewsReference>() {
public int compare(NewsReference ref1, NewsReference ref2) {
if (ref1.equals(ref2))
return 0;
return ref1.getId() > ref2.getId() ? -1 : 1;
}
});
for (SearchHit<NewsReference> hit : result) {
recentNews.add(hit.getResult());
}
/* Resolve and Add News from Result */
int counter = 0;
for (NewsReference reference : recentNews) {
INews newsitem = reference.resolve();
if (newsitem != null && newsitem.isVisible() && service.shouldShow(newsitem)) {
newsToShow.add(newsitem);
if (++counter >= TEASE_LIMIT)
break;
} else if (newsitem == null)
CoreUtils.reportIndexIssue();
/* Return early if Notifier already showing */
if (service.isPopupVisible())
return;
}
mode = Mode.RECENT;
}
/* Return early if Notifier already showing */
if (service.isPopupVisible())
return;
/* Tease with News */
if (!newsToShow.isEmpty()) {
service.show(newsToShow, null, mode);
clearTease(true);
}
/* Otherwise show Context Menu */
else