Search in sources :

Example 46 with ListHandler

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

the class FindPublicationsByGUIFilter method getEmptyTable.

/**
 * Returns table of users publications
 * @return
 */
public CellTable<Publication> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Publication>(list);
    // Cell table
    table = new PerunTable<Publication>(list);
    // display row-count for perun admin only
    if (!session.isPerunAdmin()) {
        table.removeRowCountChangeHandler();
    }
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Publication> columnSortHandler = new ListHandler<Publication>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Publication>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No publications found. Try to change filtering options.");
    // show checkbox column
    if (this.checkable) {
        table.addCheckBoxColumn();
    }
    // ID COLUMN
    table.addIdColumn("Publication ID", tableFieldUpdater, 60);
    Column<Publication, ImageResource> lockedColumn = new Column<Publication, ImageResource>(new CustomImageResourceCell("click")) {

        public ImageResource getValue(Publication object) {
            if (object.isLocked()) {
                return SmallIcons.INSTANCE.lockIcon();
            } else {
                return SmallIcons.INSTANCE.lockOpenIcon();
            }
        }

        public void onBrowserEvent(final Context context, final Element elem, final Publication object, NativeEvent event) {
            // on click and for perun admin
            if ("click".equals(event.getType()) && session.isPerunAdmin()) {
                final ImageResource value;
                if (object.isLocked()) {
                    value = SmallIcons.INSTANCE.lockOpenIcon();
                    object.setLocked(false);
                } else {
                    value = SmallIcons.INSTANCE.lockIcon();
                    object.setLocked(true);
                }
                LockUnlockPublications request = new LockUnlockPublications(new JsonCallbackEvents() {

                    @Override
                    public void onLoadingStart() {
                        getCell().setValue(context, elem, SmallIcons.INSTANCE.updateIcon());
                    }

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // change picture (object already changed)
                        getCell().setValue(context, elem, value);
                    }

                    @Override
                    public void onError(PerunError error) {
                        // on error switch object back
                        if (object.isLocked()) {
                            object.setLocked(false);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockOpenIcon());
                        } else {
                            object.setLocked(true);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockIcon());
                        }
                    }
                });
                // send request
                ArrayList<Publication> list = new ArrayList<Publication>();
                list.add(object);
                request.lockUnlockPublications(object.isLocked(), list);
            }
        }
    };
    table.addColumn(lockedColumn, "Lock");
    // TITLE COLUMN
    Column<Publication, String> titleColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getTitle();
        }
    }, this.tableFieldUpdater);
    titleColumn.setSortable(true);
    columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
    table.addColumn(titleColumn, "Title");
    // if display authors
    if (ids.containsKey("authors")) {
        if ((Integer) ids.get("authors") == 1) {
            // AUTHORS COLUMN
            Column<Publication, String> authorColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

                public String getValue(Publication object) {
                    return object.getAuthorsFormatted();
                }
            }, this.tableFieldUpdater);
            authorColumn.setSortable(true);
            columnSortHandler.setComparator(authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
            table.addColumn(authorColumn, "Reported by");
        }
    }
    // YEAR COLUMN
    Column<Publication, String> yearColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return String.valueOf(object.getYear());
        }
    }, this.tableFieldUpdater);
    yearColumn.setSortable(true);
    columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
    table.addColumn(yearColumn, "Year");
    // CATEGORY COLUMN
    Column<Publication, String> categoryColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getCategoryName();
        }
    }, this.tableFieldUpdater);
    categoryColumn.setSortable(true);
    columnSortHandler.setComparator(categoryColumn, new PublicationComparator(PublicationComparator.Column.CATEGORY));
    table.addColumn(categoryColumn, "Category");
    // THANKS COLUMN
    Column<Publication, String> thanksColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            String result = "";
            JsArray<Thanks> thks = object.getThanks();
            for (int i = 0; i < thks.length(); i++) {
                result += thks.get(i).getOwnerName() + ", ";
            }
            if (result.length() >= 2) {
                result = result.substring(0, result.length() - 2);
            }
            return result;
        }
    }, this.tableFieldUpdater);
    thanksColumn.setSortable(true);
    columnSortHandler.setComparator(thanksColumn, new PublicationComparator(PublicationComparator.Column.THANKS));
    table.addColumn(thanksColumn, "Thanked to");
    /*
		 * HIDE ISBN COLUMN FOR NOW
		// ISBN COLUMN
		Column<Publication, String> isbnColumn = JsonUtils.addColumn(
		new CustomClickableTextCell(), "",
		new JsonUtils.GetValue<Publication, String>() {
		public String getValue(Publication object) {
		return object.getIsbn();
		}
		}, this.tableFieldUpdater);

		isbnColumn.setSortable(true);
		columnSortHandler.setComparator(isbnColumn, new PublicationComparator(PublicationComparator.Column.ISBN));
		table.addColumn(isbnColumn, "ISBN");
		*/
    // CITE COLUMN
    Column<Publication, String> citaceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return "Cite";
        }
    }, new FieldUpdater<Publication, String>() {

        public void update(int index, Publication object, String value) {
            SimplePanel sp = new SimplePanel();
            sp.add(new HTML(object.getMain()));
            Confirm cf = new Confirm("Cite publication", sp, true);
            cf.show();
        }
    });
    table.addColumn(citaceColumn, "Cite");
    return table;
}
Also used : PublicationComparator(cz.metacentrum.perun.webgui.json.comparators.PublicationComparator) Element(com.google.gwt.dom.client.Element) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) ImageResource(com.google.gwt.resources.client.ImageResource) Column(com.google.gwt.user.cellview.client.Column) Context(com.google.gwt.cell.client.Cell.Context) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) CustomImageResourceCell(cz.metacentrum.perun.webgui.widgets.cells.CustomImageResourceCell) JsArray(com.google.gwt.core.client.JsArray) Publication(cz.metacentrum.perun.webgui.model.Publication) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 47 with ListHandler

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

the class GetRichAdminsWithAttributes method getTable.

/**
 * Returns the table with member-users
 *
 * @return CellTable widget
 */
public CellTable<User> getTable() {
    // Retrieves data
    this.retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<User>(list);
    // Cell table
    table = new PerunTable<User>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    if (entity.equals(PerunEntity.VIRTUAL_ORGANIZATION)) {
        loaderImage.setEmptyResultMessage("VO has no managers (try to switch to 'Groups' view).");
    } else if (entity.equals(PerunEntity.GROUP)) {
        loaderImage.setEmptyResultMessage("Group has no managers (try to switch to 'Groups' view).");
    } else if (entity.equals(PerunEntity.FACILITY)) {
        loaderImage.setEmptyResultMessage("Facility has no managers (try to switch to 'Groups' view).");
    } else if (entity.equals(PerunEntity.SECURITY_TEAM)) {
        loaderImage.setEmptyResultMessage("SecurityTeam has no members (try to switch to 'Groups' view).");
    }
    // Sorting
    ListHandler<User> columnSortHandler = new ListHandler<User>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // Table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<User>createCheckboxManager());
    // Set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // Checkbox column column
    if (checkable) {
        table.addCheckBoxColumn();
    }
    // Create User ID column.
    Column<User, String> userIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            return String.valueOf(object.getId());
        }
    }, this.tableFieldUpdater);
    userIdColumn.setSortable(true);
    columnSortHandler.setComparator(userIdColumn, new GeneralComparator<User>(GeneralComparator.Column.ID));
    table.setColumnWidth(userIdColumn, 110.0, Unit.PX);
    if (JsonUtils.isExtendedInfoVisible()) {
        table.addColumn(userIdColumn, "User ID");
    }
    table.setHyperlinksAllowed(false);
    table.addNameColumn(tableFieldUpdater);
    // Create organization column.
    Column<User, String> organizationColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:organization");
            if (at != null && at.getValue() != null && !"null".equalsIgnoreCase(at.getValue())) {
                return at.getValue();
            }
            return "";
        }
    }, this.tableFieldUpdater);
    // Create e-mail column.
    Column<User, String> emailColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
            if (at != null && at.getValue() != null && !"null".equalsIgnoreCase(at.getValue())) {
                return at.getValue().replace(",", " ");
            }
            return "";
        }
    }, this.tableFieldUpdater);
    // Create name column.
    Column<User, String> loginsColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            return object.getLogins();
        }
    }, this.tableFieldUpdater);
    organizationColumn.setSortable(true);
    columnSortHandler.setComparator(organizationColumn, new RichUserComparator(RichUserComparator.Column.ORGANIZATION));
    emailColumn.setSortable(true);
    columnSortHandler.setComparator(emailColumn, new RichUserComparator(RichUserComparator.Column.EMAIL));
    // Add the other columns.
    table.addColumn(organizationColumn, "Organization");
    table.addColumn(emailColumn, "E-mail");
    table.addColumn(loginsColumn, "Logins");
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) User(cz.metacentrum.perun.webgui.model.User) RichUserComparator(cz.metacentrum.perun.webgui.json.comparators.RichUserComparator) Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 48 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)48 Column (com.google.gwt.user.cellview.client.Column)31 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)14 Header (com.google.gwt.user.cellview.client.Header)14 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)14 Attribute (cz.metacentrum.perun.webgui.model.Attribute)12 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)12 CustomClickableTextCell (cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell)8 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)7 TextColumn (com.google.gwt.user.cellview.client.TextColumn)6 Group (cz.metacentrum.perun.webgui.model.Group)5 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)5 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)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 Application (cz.metacentrum.perun.webgui.model.Application)4 Cell (com.google.gwt.cell.client.Cell)3 ClickableTextCell (com.google.gwt.cell.client.ClickableTextCell)3 TextInputCell (com.google.gwt.cell.client.TextInputCell)3