use of cz.metacentrum.perun.webgui.widgets.cells.PerunGroupCell in project perun by CESNET.
the class GetAllGroupsWithHierarchy method getTable.
/**
* Returns table with groups in hierarchical structure and with custom field updater
*
* @return table widget
*/
public CellTable<Group> getTable() {
// retrieve data
retrieveData();
dataProvider = new ListDataProvider<Group>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
table.setVisibleRange(0, 1000);
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Group>createCheckboxManager());
// Updates the selection model = when selection changed, highlights the group children
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
highlightRowsWhenChanged();
}
});
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
// Checkbox column. This table will uses a checkbox column for
// selection.
Column<Group, Group> checkBoxColumn = new Column<Group, Group>(new PerunCheckboxCell<Group>(true, false, coreGroupsCheckable)) {
@Override
public Group getValue(Group object) {
// Get the value from the selection model.
object.setChecked(selectionModel.isSelected(object));
return object;
}
};
// Create ID column.
Column<Group, String> idColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Group, String>() {
public String getValue(Group g) {
return String.valueOf(g.getId());
}
}, tableFieldUpdater);
// Name column
Column<Group, Group> nameColumn = new Column<Group, Group>(new PerunGroupCell()) {
@Override
public Group getValue(Group object) {
return object;
}
};
nameColumn.setFieldUpdater(new FieldUpdater<Group, Group>() {
public void update(int index, Group object, Group value) {
tableFieldUpdater.update(index, object, value.getName());
}
});
// Create description column.
Column<Group, String> descriptionColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Group, String>() {
public String getValue(Group group) {
return group.getDescription();
}
}, tableFieldUpdater);
// updates the columns size
table.setColumnWidth(checkBoxColumn, 40.0, Unit.PX);
table.setColumnWidth(idColumn, 80.0, Unit.PX);
// Add the columns.
table.addColumn(checkBoxColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
table.addColumn(idColumn, "ID");
table.addColumn(nameColumn, "Name");
table.addColumn(descriptionColumn, "Description");
return table;
}
Aggregations