use of cz.metacentrum.perun.webgui.widgets.cells.TextInputCellWithTabIndex in project perun by CESNET.
the class GetCategories method getEmptyTable.
/**
* Returns table of users publications
* @return table
*/
public CellTable<Category> getEmptyTable() {
// Table data provider.
dataProvider = new ListDataProvider<Category>(list);
// Cell table
table = new PerunTable<Category>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<Category> columnSortHandler = new ListHandler<Category>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Category>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
loaderImage.setEmptyResultMessage("No publications categories found.");
// tab index for values
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// show checkbox column
if (this.checkable) {
// checkbox column column
table.addCheckBoxColumn();
}
// ID COLUMN
table.addIdColumn("Category ID", tableFieldUpdater, 80);
table.addNameColumn(tableFieldUpdater);
// Rank COLUMN
Column<Category, String> rankColumn = JsonUtils.addColumn(new TextInputCellWithTabIndex(), new JsonUtils.GetValue<Category, String>() {
public String getValue(Category category) {
return String.valueOf(category.getRank());
}
}, new FieldUpdater<Category, String>() {
public void update(int index, Category object, String newText) {
// parsing value
try {
double value = Double.parseDouble(newText);
object.setRank(value);
selectionModel.setSelected(object, true);
} catch (NumberFormatException ex) {
selectionModel.setSelected(object, false);
session.getUiElements().setLogErrorText("Rank mismatch for category: " + object.getName() + " and value: " + newText);
}
}
});
// Sorting value column
rankColumn.setSortable(true);
columnSortHandler.setComparator(rankColumn, new Comparator<Category>() {
public int compare(Category o1, Category o2) {
// return int diff of doubles
return (int) (o1.getRank() - o2.getRank());
}
});
table.addColumn(rankColumn, "Rank");
return table;
}
Aggregations