Search in sources :

Example 41 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler 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)

Example 42 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.

the class GetMemberGroups method getTable.

/**
	 * Returns the table with subgroups.
	 * @return
	 */
public CellTable<Group> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<Group>(list);
    // Cell table
    table = new PerunTable<Group>(list);
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Group> columnSortHandler = new ListHandler<Group>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Group>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("User is not member of any group.");
    // checkbox column column
    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;
        }
    };
    // 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 (Group obj : list) {
                if (!obj.isCoreGroup()) {
                    selectionModel.setSelected(obj, value);
                }
            }
        }
    });
    if (checkable) {
        table.addColumn(checkBoxColumn, checkBoxHeader);
    }
    table.addIdColumn("Group ID", tableFieldUpdater);
    table.addNameColumn(tableFieldUpdater);
    table.addDescriptionColumn(tableFieldUpdater);
    return table;
}
Also used : Group(cz.metacentrum.perun.webgui.model.Group) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Header(com.google.gwt.user.cellview.client.Header) Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunCheckboxCell(cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)

Example 43 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.

the class GetRichSubGroups method getTable.

/**
	 * Returns the table with subgroups.
	 * @return
	 */
public CellTable<RichGroup> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<RichGroup>(list);
    // Cell table
    table = new PerunTable<RichGroup>(list);
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<RichGroup> columnSortHandler = new ListHandler<RichGroup>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichGroup>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("Group has no sub-groups.");
    // checkbox column column
    table.addCheckBoxColumn();
    table.addIdColumn("Group ID", tableFieldUpdater);
    // Add a synchronization clicable icon column.
    Column<RichGroup, RichGroup> syncColumn = new Column<RichGroup, RichGroup>(new CustomClickableInfoCellWithImageResource("click")) {

        @Override
        public RichGroup getValue(RichGroup object) {
            return object;
        }

        @Override
        public String getCellStyleNames(Cell.Context context, RichGroup object) {
            if (tableFieldUpdater != null) {
                return super.getCellStyleNames(context, object) + " pointer image-hover";
            } else {
                return super.getCellStyleNames(context, object);
            }
        }
    };
    syncColumn.setFieldUpdater(new FieldUpdater<RichGroup, RichGroup>() {

        @Override
        public void update(int index, final RichGroup object, RichGroup value) {
            GetEntityById get = new GetEntityById(PerunEntity.RICH_GROUP, object.getId(), new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    final RichGroup object = jso.cast();
                    String name, syncEnabled, syncInterval, syncTimestamp, syncSuccessTimestamp, syncState, authGroup;
                    name = object.getName();
                    if (object.isSyncEnabled()) {
                        syncEnabled = "enabled";
                    } else {
                        syncEnabled = "disabled";
                    }
                    if (object.getSynchronizationInterval() == null) {
                        syncInterval = "N/A";
                    } else {
                        if (JsonUtils.checkParseInt(object.getSynchronizationInterval())) {
                            int time = Integer.parseInt(object.getSynchronizationInterval()) * 5 / 60;
                            if (time == 0) {
                                time = Integer.parseInt(object.getSynchronizationInterval()) * 5;
                                syncInterval = time + " minute(s)";
                            } else {
                                syncInterval = time + " hour(s)";
                            }
                        } else {
                            syncInterval = object.getSynchronizationInterval();
                        }
                    }
                    if (object.getLastSynchronizationState() == null) {
                        if (object.getLastSuccessSynchronizationTimestamp() != null) {
                            syncState = "OK";
                        } else {
                            syncState = "Not synced yet";
                        }
                    } else {
                        if (session.isPerunAdmin()) {
                            syncState = object.getLastSynchronizationState();
                        } else {
                            syncState = "Internal Error";
                        }
                    }
                    if (object.getLastSynchronizationTimestamp() == null) {
                        syncTimestamp = "N/A";
                    } else {
                        syncTimestamp = object.getLastSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getLastSuccessSynchronizationTimestamp() == null) {
                        syncSuccessTimestamp = "N/A";
                    } else {
                        syncSuccessTimestamp = object.getLastSuccessSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getAuthoritativeGroup() != null && object.getAuthoritativeGroup().equals("1")) {
                        authGroup = "Yes";
                    } else {
                        authGroup = "No";
                    }
                    String html = "Group name: <b>" + name + "</b><br>";
                    html += "Synchronization: <b>" + syncEnabled + "</b><br>";
                    if (object.isSyncEnabled()) {
                        html += "Last sync. state: <b>" + syncState + "</b><br>";
                        html += "Last sync. timestamp: <b>" + syncTimestamp + "</b><br>";
                        html += "Last successful sync. timestamp: <b>" + syncSuccessTimestamp + "</b><br>";
                        html += "Sync. Interval: <b>" + syncInterval + "</b><br>";
                        html += "Authoritative group: <b>" + authGroup + "</b><br>";
                    }
                    FlexTable layout = new FlexTable();
                    layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.informationIcon())));
                    layout.setHTML(0, 1, "<p style=\"line-height: 1.2;\">" + html);
                    layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                    layout.getFlexCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                    layout.getFlexCellFormatter().setStyleName(0, 0, "alert-box-image");
                    final CustomButton okButton = new CustomButton("Force synchronization", SmallIcons.INSTANCE.arrowRefreshIcon());
                    okButton.addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            ForceGroupSynchronization call = new ForceGroupSynchronization(JsonCallbackEvents.disableButtonEvents(okButton));
                            call.synchronizeGroup(object.getId());
                        }
                    });
                    if (!session.isVoAdmin(object.getVoId()) && !session.isGroupAdmin(object.getId()))
                        okButton.setEnabled(false);
                    okButton.setVisible(object.isSyncEnabled());
                    final Confirm c = new Confirm("Group synchronization info", layout, okButton, null, true);
                    c.setHideOnButtonClick(false);
                    c.setCancelIcon(SmallIcons.INSTANCE.acceptIcon());
                    c.setCancelButtonText("OK");
                    c.setCancelClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            c.hide();
                        }
                    });
                    c.show();
                }
            });
            get.retrieveData();
        }

        ;
    });
    syncColumn.setSortable(true);
    columnSortHandler.setComparator(syncColumn, new Comparator<RichGroup>() {

        @Override
        public int compare(RichGroup o1, RichGroup o2) {
            if (o1 != null && o2 != null) {
                int o1val = 0;
                int o2val = 0;
                if (o1.isSyncEnabled())
                    o1val = 5;
                if (o2.isSyncEnabled())
                    o2val = 5;
                if (o1.getAuthoritativeGroup() != null && o1.getAuthoritativeGroup().equalsIgnoreCase("1"))
                    o1val = o1val + 3;
                if (o2.getAuthoritativeGroup() != null && o2.getAuthoritativeGroup().equalsIgnoreCase("1"))
                    o2val = o2val + 3;
                return o1val - o2val;
            }
            return 0;
        }
    });
    table.addColumn(syncColumn, "Sync");
    table.setColumnWidth(syncColumn, "70px");
    table.addNameColumn(tableFieldUpdater);
    table.addDescriptionColumn(tableFieldUpdater);
    return table;
}
Also used : RichGroup(cz.metacentrum.perun.webgui.model.RichGroup) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Column(com.google.gwt.user.cellview.client.Column) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomClickableInfoCellWithImageResource(cz.metacentrum.perun.webgui.widgets.cells.CustomClickableInfoCellWithImageResource)

Example 44 with ListHandler

use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.

the class GetAllowedVos method getTable.

/**
	 * Returns table widget with allowed Vos
	 *
	 * @return table widget
	 */
public CellTable<VirtualOrganization> getTable() {
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<VirtualOrganization>(list);
    // Cell table
    table = new PerunTable<VirtualOrganization>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<VirtualOrganization> columnSortHandler = new ListHandler<VirtualOrganization>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<VirtualOrganization>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // checkbox column column
    if (checkable == true) {
        table.addCheckBoxColumn();
    }
    VoColumnProvider columnProvider = new VoColumnProvider(table, null);
    // FIXME we need field updater
    IsClickableCell<GeneralObject> authz = VoColumnProvider.getDefaultClickableAuthz();
    columnProvider.addIdColumn(authz, 100);
    columnProvider.addShortNameColumn(authz, 200);
    columnProvider.addNameColumn(authz, 0);
    return table;
}
Also used : VoColumnProvider(cz.metacentrum.perun.webgui.json.columnProviders.VoColumnProvider) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Aggregations

ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)44 Column (com.google.gwt.user.cellview.client.Column)28 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)13 Header (com.google.gwt.user.cellview.client.Header)13 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)13 Attribute (cz.metacentrum.perun.webgui.model.Attribute)12 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)11 CustomClickableTextCell (cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell)8 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)6 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)6 TextColumn (com.google.gwt.user.cellview.client.TextColumn)5 Application (cz.metacentrum.perun.webgui.model.Application)5 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)5 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)5 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)5 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)5 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 VoColumnProvider (cz.metacentrum.perun.webgui.json.columnProviders.VoColumnProvider)4 RichUserComparator (cz.metacentrum.perun.webgui.json.comparators.RichUserComparator)4