Search in sources :

Example 16 with PerunCheckboxCell

use of cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell in project perun by CESNET.

the class GetUserExtSources method getTable.

/**
 * Return table with checkboxes containing user external sources
 *
 * @return table containing user ext sources
 */
public CellTable<UserExtSource> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<UserExtSource>(list);
    // Cell table
    table = new PerunTable<UserExtSource>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<UserExtSource> columnSortHandler = new ListHandler<UserExtSource>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<UserExtSource>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // checkbox column column
    com.google.gwt.user.cellview.client.Column<UserExtSource, UserExtSource> checkBoxColumn = new com.google.gwt.user.cellview.client.Column<UserExtSource, UserExtSource>(new PerunCheckboxCell<UserExtSource>(true, false, false)) {

        @Override
        public UserExtSource getValue(UserExtSource object) {
            // Get the value from the selection model.
            GeneralObject go = object.cast();
            go.setChecked(selectionModel.isSelected(object));
            return go.cast();
        }
    };
    // updates the columns size
    table.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
    // Add the columns
    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {

        public Boolean getValue() {
            // return true to see a checked checkbox.
            return false;
        }
    };
    checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {

        public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (UserExtSource obj : list) {
                if (!obj.isPersistent()) {
                    selectionModel.setSelected(obj, value);
                }
            }
        }
    });
    table.addColumn(checkBoxColumn, checkBoxHeader);
    table.addIdColumn("UES ID", tableFieldUpdater, 100);
    // Name column
    Column<UserExtSource, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {

        public String getValue(UserExtSource extSource) {
            return String.valueOf(extSource.getExtSource().getName());
        }
    }, tableFieldUpdater);
    // Login column
    Column<UserExtSource, String> loginColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {

        public String getValue(UserExtSource extSource) {
            return String.valueOf(extSource.getLogin());
        }
    }, tableFieldUpdater);
    // LOA column
    Column<UserExtSource, String> loaColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {

        public String getValue(UserExtSource extSource) {
            return String.valueOf(extSource.getLoa());
        }
    }, tableFieldUpdater);
    // LastAccess column
    Column<UserExtSource, String> lastAccessColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {

        public String getValue(UserExtSource extSource) {
            if (extSource.getLastAccess() != null && !extSource.getLastAccess().isEmpty()) {
                return extSource.getLastAccess().split("\\.")[0];
            } else {
                return "N/A";
            }
        }
    }, tableFieldUpdater);
    // sort name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new GeneralComparator<UserExtSource>(GeneralComparator.Column.NAME));
    // sort login column
    loginColumn.setSortable(true);
    columnSortHandler.setComparator(loginColumn, new Comparator<UserExtSource>() {

        public int compare(UserExtSource o1, UserExtSource o2) {
            return o1.getLogin().compareTo(o2.getLogin());
        }
    });
    // sort loa column
    loaColumn.setSortable(true);
    columnSortHandler.setComparator(loaColumn, new Comparator<UserExtSource>() {

        public int compare(UserExtSource o1, UserExtSource o2) {
            return o1.getLoa() - o2.getLoa();
        }
    });
    // sort lastAccess column
    lastAccessColumn.setSortable(true);
    columnSortHandler.setComparator(lastAccessColumn, new Comparator<UserExtSource>() {

        public int compare(UserExtSource o1, UserExtSource o2) {
            String la1 = (o1.getLastAccess() != null && !o1.getLastAccess().isEmpty()) ? o1.getLastAccess().split("\\.")[0] : "N/A";
            String la2 = (o2.getLastAccess() != null && !o2.getLastAccess().isEmpty()) ? o2.getLastAccess().split("\\.")[0] : "N/A";
            return la1.compareTo(la2);
        }
    });
    table.addColumn(nameColumn, "External source name");
    table.addColumn(loginColumn, "ID in external source");
    table.addColumn(loaColumn, "Level of assurance");
    table.addColumn(lastAccessColumn, "Last access");
    return table;
}
Also used : Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunCheckboxCell(cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Header(com.google.gwt.user.cellview.client.Header) UserExtSource(cz.metacentrum.perun.webgui.model.UserExtSource)

Aggregations

CheckboxCell (com.google.gwt.cell.client.CheckboxCell)16 Column (com.google.gwt.user.cellview.client.Column)16 Header (com.google.gwt.user.cellview.client.Header)16 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)16 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)14 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)9 Attribute (cz.metacentrum.perun.webgui.model.Attribute)7 Group (cz.metacentrum.perun.webgui.model.Group)5 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)4 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)3 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)3 ColumnSortEvent (com.google.gwt.user.cellview.client.ColumnSortEvent)2 IsClickableCell (cz.metacentrum.perun.webgui.json.columnProviders.IsClickableCell)2 MemberColumnProvider (cz.metacentrum.perun.webgui.json.columnProviders.MemberColumnProvider)2 RichMember (cz.metacentrum.perun.webgui.model.RichMember)2 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 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 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1