}
};
}
private void hookContextualMenu() {
MenuManager manager = new MenuManager();
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
manager.add(new Separator("open"));
manager.add(new Separator("mark"));
manager.add(new Separator("edit"));
manager.add(new Separator("copy"));
manager.add(new Separator("label"));
IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
/* Need a Selection here */
if (selection.isEmpty())
return;
/* Show in Feed (only for searchmarks) */
if (fViewer.getInput() instanceof SearchMarkReference) {
OpenNewsAction showInFeedAction = new OpenNewsAction(selection);
showInFeedAction.setText("Show in Feed");
manager.appendToGroup("open", showInFeedAction);
}
/* Sticky */
manager.appendToGroup("label", new MakeTypesStickyAction(selection));
/* Label */
MenuManager labelMenu = new MenuManager("Label");
manager.appendToGroup("label", labelMenu);
/* Retrieve selected Labels from Selection (including NULL!) */
Set<ILabel> selectedLabels = ModelUtils.getLabels(selection);
ILabel commonLabel = null;
if (selectedLabels.size() == 1)
commonLabel = selectedLabels.iterator().next();
IAction labelNone = new Action("None", IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
new LabelAction(null, (IStructuredSelection) fViewer.getSelection()).run();
}
};
labelNone.setChecked(selectedLabels.size() == 0 || (selectedLabels.size() == 1 && commonLabel == null));
labelMenu.add(labelNone);
labelMenu.add(new Separator());
Collection<ILabel> labels = DynamicDAO.loadAll(ILabel.class);
for (final ILabel label : labels) {
IAction labelAction = new Action(label.getName(), IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
new LabelAction(label, (IStructuredSelection) fViewer.getSelection()).run();
}
};
labelAction.setChecked(label.equals(commonLabel));
labelMenu.add(labelAction);
}
}
});
/* Create and Register with Workbench */