/* Retrieve Labels that all selected News contain */
labelMenu.add(new Separator());
Set<ILabel> selectedLabels = ModelUtils.getLabelsForAll(selection);
for (final ILabel label : labels) {
LabelAction labelAction = new LabelAction(label, selection);
labelAction.setChecked(selectedLabels.contains(label));
labelMenu.add(labelAction);
}
/* New Label */
labelMenu.add(new Action(Messages.ApplicationActionBarAdvisor_NEW_LABEL) {
@Override
public void run() {
LabelDialog dialog = new LabelDialog(shellProvider.getShell(), DialogMode.ADD, null);
if (dialog.open() == IDialogConstants.OK_ID) {
String name = dialog.getName();
RGB color = dialog.getColor();
ILabel newLabel = Owl.getModelFactory().createLabel(null, name);
newLabel.setColor(OwlUI.toString(color));
newLabel.setOrder(labels.size());
DynamicDAO.save(newLabel);
LabelAction labelAction = new LabelAction(newLabel, selection);
labelAction.run();
}
}
@Override
public boolean isEnabled() {
return !selection.isEmpty();
}
});
/* Remove All Labels */
labelMenu.add(new Separator());
LabelAction removeAllLabels = new LabelAction(null, selection);
removeAllLabels.setId(RemoveLabelsHandler.ID);
removeAllLabels.setActionDefinitionId(RemoveLabelsHandler.ID);
removeAllLabels.setEnabled(!selection.isEmpty() && !labels.isEmpty());
labelMenu.add(removeAllLabels);
}