*
* @param colIndex the column index
* @return the context menu for the given column
*/
protected Menu createContextMenu(final int colIndex) {
final Menu menu = new Menu();
if (cm.isSortable(colIndex)) {
MenuItem item = new MenuItem();
item.setText(DefaultMessages.getMessages().gridView_sortAscText());
item.setIcon(header.getAppearance().sortAscendingIcon());
item.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
doSort(colIndex, SortDir.ASC);
}
});
menu.add(item);
item = new MenuItem();
item.setText(DefaultMessages.getMessages().gridView_sortDescText());
item.setIcon(header.getAppearance().sortDescendingIcon());
item.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
doSort(colIndex, SortDir.DESC);
}
});
menu.add(item);
}
MenuItem columns = new MenuItem();
columns.setText(DefaultMessages.getMessages().gridView_columnsText());
columns.setIcon(header.getAppearance().columnsIcon());
columns.setData("gxt-columns", "true");
final Menu columnMenu = new Menu();
int cols = cm.getColumnCount();
for (int i = 0; i < cols; i++) {
ColumnConfig<M, ?> config = cm.getColumn(i);
// ignore columns with no header text
if (!hasHeaderValue(i)) {
continue;
}
final int fcol = i;
final CheckMenuItem check = new CheckMenuItem();
check.setHideOnClick(false);
check.setHTML(cm.getColumnHeader(i));
check.setChecked(!cm.isHidden(i));
if (!config.isHideable()) {
check.disable();
}
check.addCheckChangeHandler(new CheckChangeHandler<CheckMenuItem>() {
@Override
public void onCheckChange(CheckChangeEvent<CheckMenuItem> event) {
cm.setHidden(fcol, !cm.isHidden(fcol));
restrictMenu(cm, columnMenu);
}
});
columnMenu.add(check);
}
restrictMenu(cm, columnMenu);
columns.setEnabled(columnMenu.getWidgetCount() > 0);
columns.setSubMenu(columnMenu);
menu.add(columns);
return menu;
}