private void hookContextualMenu() {
MenuManager manager = new MenuManager();
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
final IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
/* Open */
{
manager.add(new Separator("open"));
/* Show only when internal browser is used */
if (!selection.isEmpty() && !fPreferences.getBoolean(DefaultPreferences.USE_CUSTOM_EXTERNAL_BROWSER) && !fPreferences.getBoolean(DefaultPreferences.USE_DEFAULT_EXTERNAL_BROWSER))
manager.add(new OpenInExternalBrowserAction(selection));
}
/* Mark / Label */
{
manager.add(new Separator("mark"));
/* Mark */
MenuManager markMenu = new MenuManager("Mark", "mark");
manager.add(markMenu);
/* Mark as Read */
IAction action = new MarkNewsReadAction(selection);
action.setEnabled(!selection.isEmpty());
markMenu.add(action);
/* Mark All Read */
action = new MarkAllNewsReadAction();
markMenu.add(action);
/* Sticky */
markMenu.add(new Separator());
action = new MakeNewsStickyAction(selection);
action.setEnabled(!selection.isEmpty());
markMenu.add(action);
/* Label */
if (!selection.isEmpty()) {
Collection<ILabel> labels = DynamicDAO.loadAll(ILabel.class);
/* Label */
MenuManager labelMenu = new MenuManager("Label");
manager.appendToGroup("mark", labelMenu);
/* Retrieve Labels that all selected News contain */
Set<ILabel> selectedLabels = ModelUtils.getLabelsForAll(selection);
IAction removeAllLabels = new Action("Remove All Labels") {
@Override
public void run() {
Collection<ILabel> labels = DynamicDAO.loadAll(ILabel.class);
new LabelAction(labels, selection, false).run();
}
};
removeAllLabels.setEnabled(!labels.isEmpty());
labelMenu.add(removeAllLabels);
labelMenu.add(new Separator());
for (final ILabel label : labels) {
IAction labelAction = new Action(label.getName(), IAction.AS_CHECK_BOX) {
@Override
public void run() {
Set<ILabel> labels = new HashSet<ILabel>(1);
labels.add(label);
new LabelAction(labels, selection, isChecked()).run();
}
};
labelAction.setChecked(selectedLabels.contains(label));
labelMenu.add(labelAction);
}
labelMenu.add(new Separator());
labelMenu.add(new Action("Organize...") {
@Override
public void run() {
PreferencesUtil.createPreferenceDialogOn(fViewer.getTree().getShell(), ManageLabelsPreferencePage.ID, null, null).open();
}
});
}
}
manager.add(new Separator("edit"));
manager.add(new Separator("copy"));
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
/* Need a good Selection here */
if (selection.isEmpty() || (selection.size() == 1 && selection.getFirstElement() instanceof EntityGroup))
return;
/* Show in Feed (only for searchmarks) */
if (fViewer.getInput() instanceof SearchMarkReference) {
OpenNewsAction showInFeedAction = new OpenNewsAction(selection);