Search in sources :

Example 6 with RichMemberComparator

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;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FlexTable(com.google.gwt.user.client.ui.FlexTable) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) RichMember(cz.metacentrum.perun.webgui.model.RichMember) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Column(com.google.gwt.user.cellview.client.Column) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunStatusCell(cz.metacentrum.perun.webgui.widgets.cells.PerunStatusCell) SetStatus(cz.metacentrum.perun.webgui.json.membersManager.SetStatus) RichMemberComparator(cz.metacentrum.perun.webgui.json.comparators.RichMemberComparator) PerunError(cz.metacentrum.perun.webgui.model.PerunError) ListBox(com.google.gwt.user.client.ui.ListBox)

Aggregations

RichMemberComparator (cz.metacentrum.perun.webgui.json.comparators.RichMemberComparator)6 RichMember (cz.metacentrum.perun.webgui.model.RichMember)6 JsonUtils (cz.metacentrum.perun.webgui.json.JsonUtils)5 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Column (com.google.gwt.user.cellview.client.Column)1 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)1 FlexTable (com.google.gwt.user.client.ui.FlexTable)1 ListBox (com.google.gwt.user.client.ui.ListBox)1 SetStatus (cz.metacentrum.perun.webgui.json.membersManager.SetStatus)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)1 PerunStatusCell (cz.metacentrum.perun.webgui.widgets.cells.PerunStatusCell)1