protected Menu onShowContextMenu(final TableColumn column) {
final Menu menu = new Menu();
if (column.isSortable()) {
MenuItem item = new MenuItem();
item.setText(GXT.MESSAGES.gridView_sortAscText());
item.setIconStyle("my-icon-asc");
item.addSelectionListener(new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
table.sort(column.index, SortDir.ASC);
}
});
menu.add(item);
item = new MenuItem();
item.setText(GXT.MESSAGES.gridView_sortDescText());
item.setIconStyle("my-icon-desc");
item.addSelectionListener(new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
table.sort(column.index, SortDir.DESC);
}
});
menu.add(item);
}
MenuItem columns = new MenuItem();
columns.setText(GXT.MESSAGES.gridView_columnsText());
columns.setIconStyle("icon-columns");
final Menu columnMenu = new Menu();
int cols = columnModel.getColumnCount();
for (int i = 0; i < cols; i++) {
final TableColumn def = columnModel.getColumn(i);
final CheckMenuItem check = new CheckMenuItem();
check.setHideOnClick(false);
check.setText(def.getText());
check.setChecked(!def.isHidden());
check.addSelectionListener(new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
def.setHidden(!check.isChecked());
showColumn(def.index, !def.isHidden());
if (columnModel.getVariableColumnCount() > 0) {
resizeColumns(false, true);
}
if (columnModel.getVisibleColumnCount() == 1) {
for (Item item : columnMenu.getItems()) {
CheckMenuItem check = (CheckMenuItem) item;
if (check.isChecked()) {
item.disable();
}
}
} else if (columnModel.getVisibleColumnCount() == 2) {
for (Item item : columnMenu.getItems()) {
item.enable();
}
}
}
});
columnMenu.add(check);
if (columnModel.getVisibleColumnCount() == 1) {
for (Item item : columnMenu.getItems()) {
CheckMenuItem ci = (CheckMenuItem) item;
if (ci.isChecked()) {
ci.disable();
}
}
}
}
columns.setSubMenu(columnMenu);
menu.add(columns);
return menu;
}