newsMenu.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
final IStructuredSelection selection;
FeedView activeFeedView = OwlUI.getActiveFeedView();
FeedViewInput activeInput = null;
if (activeFeedView != null) {
selection = (IStructuredSelection) activeFeedView.getSite().getSelectionProvider().getSelection();
activeInput = (FeedViewInput) activeFeedView.getEditorInput();
} else
selection = StructuredSelection.EMPTY;
boolean isEntityGroupSelected = OwlUI.isEntityGroupSelected(selection);
/* Open */
if (!isEntityGroupSelected) {
manager.add(new Separator("open")); //$NON-NLS-1$
/* Open News in Browser */
manager.add(new OpenInBrowserAction(selection, WebBrowserContext.createFrom(selection, activeFeedView)) {
@Override
public boolean isEnabled() {
return !selection.isEmpty();
}
});
/* Open Externally - Show only when internal browser is used */
if (!selection.isEmpty() && !preferences.getBoolean(DefaultPreferences.USE_CUSTOM_EXTERNAL_BROWSER) && !preferences.getBoolean(DefaultPreferences.USE_DEFAULT_EXTERNAL_BROWSER))
manager.add(new OpenInExternalBrowserAction(selection));
}
/* Attachments */
{
fillAttachmentsMenu(manager, selection, getActionBarConfigurer().getWindowConfigurer().getWindow(), false);
}
/* Mark / Label */
{
manager.add(new Separator("mark")); //$NON-NLS-1$
/* Mark */
{
MenuManager markMenu = new MenuManager(Messages.ApplicationActionBarAdvisor_MARK, "mark"); //$NON-NLS-1$
manager.add(markMenu);
/* Mark as Read */
IAction action = new ToggleReadStateAction(selection);
action.setEnabled(!selection.isEmpty());
markMenu.add(action);
/* Mark All Read */
action = new MarkAllNewsReadAction();
action.setEnabled(activeFeedView != null);
markMenu.add(action);
/* Sticky */
markMenu.add(new Separator());
action = new MakeNewsStickyAction(selection);
action.setEnabled(!selection.isEmpty());
markMenu.add(action);
}
/* Label */
fillLabelMenu(manager, selection, getActionBarConfigurer().getWindowConfigurer().getWindow(), false);
}
/* Move To / Copy To */
if (!selection.isEmpty()) {
manager.add(new Separator("movecopy")); //$NON-NLS-1$
/* Load all news bins and sort by name */
List<INewsBin> newsbins = new ArrayList<INewsBin>(DynamicDAO.loadAll(INewsBin.class));
Comparator<INewsBin> comparator = new Comparator<INewsBin>() {
public int compare(INewsBin o1, INewsBin o2) {
return o1.getName().compareTo(o2.getName());
};
};
Collections.sort(newsbins, comparator);
/* Move To */
MenuManager moveMenu = new MenuManager(Messages.ApplicationActionBarAdvisor_MOVE_TO, "moveto"); //$NON-NLS-1$
manager.add(moveMenu);
for (INewsBin bin : newsbins) {
if (activeInput != null && activeInput.getMark().equals(bin))
continue;
moveMenu.add(new MoveCopyNewsToBinAction(selection, bin, true));
}
moveMenu.add(new MoveCopyNewsToBinAction(selection, null, true));
moveMenu.add(new Separator());
moveMenu.add(new AutomateFilterAction(PresetAction.MOVE, selection));
/* Copy To */
MenuManager copyMenu = new MenuManager(Messages.ApplicationActionBarAdvisor_COPY_TO, "copyto"); //$NON-NLS-1$
manager.add(copyMenu);
for (INewsBin bin : newsbins) {
if (activeInput != null && activeInput.getMark().equals(bin))
continue;
copyMenu.add(new MoveCopyNewsToBinAction(selection, bin, false));
}