public Menu getMenu(Control parent) {
Menu menu = new Menu(parent);
/* Group: None */
final MenuItem noGrouping = new MenuItem(menu, SWT.RADIO);
noGrouping.setText(NewsGrouping.Type.NO_GROUPING.getName());
noGrouping.setSelection(grouping.getType() == NewsGrouping.Type.NO_GROUPING);
noGrouping.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (noGrouping.getSelection() && grouping.getType() != NewsGrouping.Type.NO_GROUPING)
doGrouping(NewsGrouping.Type.NO_GROUPING, true, true);
}
});
menu.setDefaultItem(noGrouping);
/* Separator */
new MenuItem(menu, SWT.SEPARATOR);
/* Group: By Date */
final MenuItem groupByDate = new MenuItem(menu, SWT.RADIO);
groupByDate.setText(NewsGrouping.Type.GROUP_BY_DATE.getName());
groupByDate.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_DATE);
groupByDate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByDate.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_DATE)
doGrouping(NewsGrouping.Type.GROUP_BY_DATE, true, true);
}
});
/* Group: By Author */
final MenuItem groupByAuthor = new MenuItem(menu, SWT.RADIO);
groupByAuthor.setText(NewsGrouping.Type.GROUP_BY_AUTHOR.getName());
groupByAuthor.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_AUTHOR);
groupByAuthor.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByAuthor.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_AUTHOR)
doGrouping(NewsGrouping.Type.GROUP_BY_AUTHOR, true, true);
}
});
/* Group: By Category */
final MenuItem groupByCategory = new MenuItem(menu, SWT.RADIO);
groupByCategory.setText(NewsGrouping.Type.GROUP_BY_CATEGORY.getName());
groupByCategory.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_CATEGORY);
groupByCategory.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByCategory.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_CATEGORY)
doGrouping(NewsGrouping.Type.GROUP_BY_CATEGORY, true, true);
}
});
/* Group: By Topic */
final MenuItem groupByTopic = new MenuItem(menu, SWT.RADIO);
groupByTopic.setText(NewsGrouping.Type.GROUP_BY_TOPIC.getName());
groupByTopic.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_TOPIC);
groupByTopic.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByTopic.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_TOPIC)
doGrouping(NewsGrouping.Type.GROUP_BY_TOPIC, true, true);
}
});
/* Separator */
new MenuItem(menu, SWT.SEPARATOR);
/* Group: By Other */
final MenuItem groupByOther = new MenuItem(menu, SWT.CASCADE);
groupByOther.setText("Other");
Menu otherMenu = new Menu(groupByOther);
groupByOther.setMenu(otherMenu);
/* Group: By State */
final MenuItem groupByState = new MenuItem(otherMenu, SWT.RADIO);
groupByState.setText(NewsGrouping.Type.GROUP_BY_STATE.getName());
groupByState.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_STATE);
groupByState.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByState.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_STATE)
doGrouping(NewsGrouping.Type.GROUP_BY_STATE, true, true);
}
});
/* Group: By Stickyness */
final MenuItem groupByStickyness = new MenuItem(otherMenu, SWT.RADIO);
groupByStickyness.setText(NewsGrouping.Type.GROUP_BY_STICKY.getName());
groupByStickyness.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_STICKY);
groupByStickyness.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByStickyness.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_STICKY)
doGrouping(NewsGrouping.Type.GROUP_BY_STICKY, true, true);
}
});
/* Separator */
new MenuItem(otherMenu, SWT.SEPARATOR);
/* Group: By Label */
final MenuItem groupByLabel = new MenuItem(otherMenu, SWT.RADIO);
groupByLabel.setText(NewsGrouping.Type.GROUP_BY_LABEL.getName());
groupByLabel.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_LABEL);
groupByLabel.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByLabel.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_LABEL)
doGrouping(NewsGrouping.Type.GROUP_BY_LABEL, true, true);
}
});
/* Group: By Rating */
final MenuItem groupByRating = new MenuItem(otherMenu, SWT.RADIO);
groupByRating.setText(NewsGrouping.Type.GROUP_BY_RATING.getName());
groupByRating.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_RATING);
groupByRating.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByRating.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_RATING)
doGrouping(NewsGrouping.Type.GROUP_BY_RATING, true, true);
}
});
/* Separator */
new MenuItem(otherMenu, SWT.SEPARATOR);
/* Group: By Feed */
final MenuItem groupByFeed = new MenuItem(otherMenu, SWT.RADIO);
groupByFeed.setText(NewsGrouping.Type.GROUP_BY_FEED.getName());
groupByFeed.setSelection(grouping.getType() == NewsGrouping.Type.GROUP_BY_FEED);
groupByFeed.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByFeed.getSelection() && grouping.getType() != NewsGrouping.Type.GROUP_BY_FEED)
doGrouping(NewsGrouping.Type.GROUP_BY_FEED, true, true);
}
});
return menu;