use of cz.metacentrum.perun.webgui.json.comparators.RichMemberComparator in project perun by CESNET.
the class GetGroupRichMembers method getTable.
/**
* Returns the table with rich members of group
*
* @return table widget
*/
public CellTable<RichMember> getTable() {
// retrieves data
retrieveData();
// Table data provider.
dataProvider = new ListDataProvider<RichMember>(list);
// Cell table
table = new PerunTable<RichMember>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<RichMember> columnSortHandler = new ListHandler<RichMember>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// Table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichMember>createCheckboxManager());
// Set empty content & loader
table.setEmptyTableWidget(loaderImage);
// Checkbox column column
table.addCheckBoxColumn();
// Status column
Column<RichMember, String> statusColumn = new Column<RichMember, String>(new PerunStatusCell()) {
@Override
public String getValue(RichMember object) {
return object.getStatus();
}
};
// own onClick tab for changing member's status
statusColumn.setFieldUpdater(new FieldUpdater<RichMember, String>() {
public void update(int index, final RichMember object, String value) {
FlexTable widget = new FlexTable();
final ListBox lb = new ListBox(false);
lb.addItem("VALID", "VALID");
lb.addItem("INVALID", "INVALID");
lb.addItem("SUSPENDED", "SUSPENDED");
lb.addItem("EXPIRED", "EXPIRED");
lb.addItem("DISABLED", "DISABLED");
widget.setHTML(0, 0, "<strong>Status: </strong>");
widget.setWidget(0, 1, lb);
// pick which one is already set
for (int i = 0; i < lb.getItemCount(); i++) {
if (lb.getItemText(i).equalsIgnoreCase(object.getStatus())) {
lb.setSelectedIndex(i);
}
}
Confirm conf = new Confirm("Change member's status: " + object.getUser().getFullName(), widget, true);
conf.setCancelButtonText("Cancel");
conf.setOkButtonText("Change status");
conf.setOkClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SetStatus call = new SetStatus(object.getId(), new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
clearTable();
retrieveData();
}
public void onError(PerunError error) {
clearTable();
retrieveData();
}
});
call.setStatus(lb.getValue(lb.getSelectedIndex()));
}
});
conf.show();
}
});
// status column sortable
statusColumn.setSortable(true);
columnSortHandler.setComparator(statusColumn, new GeneralComparator<RichMember>(GeneralComparator.Column.STATUS));
table.addColumn(statusColumn, "Status");
table.setColumnWidth(statusColumn, 20, Unit.PX);
// Create member ID column.
Column<RichMember, String> memberIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<RichMember, String>() {
public String getValue(RichMember object) {
return String.valueOf(object.getId());
}
}, this.tableFieldUpdater);
// Create User ID column.
Column<RichMember, String> userIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<RichMember, String>() {
public String getValue(RichMember object) {
return String.valueOf(object.getUser().getId());
}
}, this.tableFieldUpdater);
columnSortHandler.setComparator(memberIdColumn, new RichMemberComparator(RichMemberComparator.Column.MEMBER_ID));
memberIdColumn.setSortable(true);
userIdColumn.setSortable(true);
columnSortHandler.setComparator(userIdColumn, new RichMemberComparator(RichMemberComparator.Column.USER_ID));
table.setColumnWidth(memberIdColumn, 110.0, Unit.PX);
table.setColumnWidth(userIdColumn, 110.0, Unit.PX);
// headers
if (JsonUtils.isExtendedInfoVisible()) {
table.addColumn(memberIdColumn, "Member ID");
table.addColumn(userIdColumn, "User ID");
}
table.addNameColumn(tableFieldUpdater);
return table;
}
Aggregations