Search in sources :

Example 1 with Publication

use of cz.metacentrum.perun.webgui.model.Publication in project perun by CESNET.

the class FindSimilarPublications method getEmptyTable.

/**
 * Returns table of users publications
 * @return table
 */
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 similar publications found.");
    // show checkbox column
    if (this.checkable) {
        // checkbox column column
        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");
    // 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 2 with Publication

use of cz.metacentrum.perun.webgui.model.Publication in project perun by CESNET.

the class FindExternalPublications method getEmptyTable.

/**
 * Returns table with publications
 * @return table
 */
public CellTable<Publication> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Publication>(list);
    // Cell table
    table = new PerunTable<Publication>(list);
    table.removeRowCountChangeHandler();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    // 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.prepareToSearch("Please select external pub. system and year range to search for publications for import."));
    loaderImage.setEmptyResultMessage("No publications found in external system.");
    // show checkbox column
    if (this.checkable) {
        table.addCheckBoxColumn();
    }
    /*
		// CATEGORY COLUMN
		ArrayList<String> categories = new ArrayList<String>();
		categories.add("Bodované v RIVu");
		categories.add("Nebodované v RIVu");
		categories.add("Příspěvek do ročenky");
		categories.add("Výjimečné výsledky");
		categories.add("Jiné");

		Column<Publication, String> categoryColumn = new Column<Publication, String>(new SelectionCell(categories)){
		@Override
		public String getValue(Publication object) {
		// category ID as string, 0 if not set
		int id = object.getCategoryId();
		if (id == 0) {
		// set default == 21/Bodované v RIVu to object
		object.setCategoryId(21);
		}
		if (id == 21) {
		return "Bodované v RIVu";
		} else if (id == 22) {
		return "Nebodované v RIVu";
		} else if (id == 23) {
		return "Výjimečné výsledky";
		} else if (id == 24) {
		return "Příspěvek do ročenky";
		} else if (id == 25) {
		return "Jiné";
		} else {
		return String.valueOf(id); // return ID if no match
		}
		}
		};
		categoryColumn.setFieldUpdater(new FieldUpdater<Publication, String>() {
		public void update(int index, Publication object, String value) {

		int id = 0;
		if (value.equalsIgnoreCase("Bodované v RIVu")) {
		id = 21;
		} else if (value.equalsIgnoreCase("Nebodované v RIVu")) {
		id = 22;
		} else if (value.equalsIgnoreCase("Příspěvek do ročenky")) {
		id = 24;
		} else if (value.equalsIgnoreCase("Výjimečné výsledky")) {
		id = 23;
		} else if (value.equalsIgnoreCase("Jiné")) {
		id = 25;
		}
		object.setCategoryId(id);
		selectionModel.setSelected(object, true);

		}
		});
		table.addColumn(categoryColumn, "Category");

		// NOT USEFULL => DISABLED
		// EXTERNAL ID
		TextColumn<Publication> externalIdColumn = new TextColumn<Publication>() {
		public String getValue(Publication object) {
		return String.valueOf(object.getExternalId());
		};
		};
		externalIdColumn.setSortable(true);
		columnSortHandler.setComparator(externalIdColumn, new PublicationComparator(PublicationComparator.Column.EXTERNAL_ID));
		table.addColumn(externalIdColumn, "External Id");
		*/
    // TITLE COLUMN
    TextColumn<Publication> titleColumn = new TextColumn<Publication>() {

        public String getValue(Publication object) {
            return object.getTitle();
        }
    };
    titleColumn.setSortable(true);
    columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
    table.addColumn(titleColumn, "Title");
    // AUTHORS COLUMN
    TextColumn<Publication> authorColumn = new TextColumn<Publication>() {

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

        public String getValue(Publication object) {
            return String.valueOf(object.getYear());
        }
    };
    yearColumn.setSortable(true);
    columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
    table.addColumn(yearColumn, "Year");
    // ISBN COLUMN
    TextColumn<Publication> isbnColumn = new TextColumn<Publication>() {

        public String getValue(Publication object) {
            return object.getIsbn();
        }
    };
    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) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Publication(cz.metacentrum.perun.webgui.model.Publication) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 3 with Publication

use of cz.metacentrum.perun.webgui.model.Publication in project perun by CESNET.

the class PublicationDetailTabItem method draw.

public Widget draw() {
    // show only part of title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(publication.getTitle()));
    // MAIN PANEL
    ScrollPanel sp = new ScrollPanel();
    sp.addStyleName("perun-tableScrollPanel");
    VerticalPanel vp = new VerticalPanel();
    vp.addStyleName("perun-table");
    sp.add(vp);
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(sp, 350, this);
    // content
    final FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    if (!publication.isLocked()) {
        ft.setHTML(1, 0, "Id / Origin:");
        ft.setHTML(2, 0, "Title:");
        ft.setHTML(3, 0, "Year:");
        ft.setHTML(4, 0, "Category:");
        ft.setHTML(5, 0, "Rank:");
        ft.setHTML(6, 0, "ISBN / ISSN:");
        ft.setHTML(7, 0, "DOI:");
        ft.setHTML(8, 0, "Full cite:");
        ft.setHTML(9, 0, "Created by:");
        ft.setHTML(10, 0, "Created date:");
        for (int i = 0; i < ft.getRowCount(); i++) {
            ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
        }
        ft.getFlexCellFormatter().setWidth(1, 0, "100px");
        final ListBoxWithObjects<Category> listbox = new ListBoxWithObjects<Category>();
        // fill listbox
        JsonCallbackEvents events = new JsonCallbackEvents() {

            public void onFinished(JavaScriptObject jso) {
                for (Category cat : JsonUtils.<Category>jsoAsList(jso)) {
                    listbox.addItem(cat);
                    // if right, selected
                    if (publication.getCategoryId() == cat.getId()) {
                        listbox.setSelected(cat, true);
                    }
                }
            }
        };
        GetCategories categories = new GetCategories(events);
        categories.retrieveData();
        final TextBox rank = new TextBox();
        rank.setWidth("30px");
        rank.setMaxLength(4);
        rank.setText(String.valueOf(publication.getRank()));
        final TextBox title = new TextBox();
        title.setMaxLength(1024);
        title.setText(publication.getTitle());
        title.setWidth("500px");
        final TextBox year = new TextBox();
        year.setText(String.valueOf(publication.getYear()));
        year.setMaxLength(4);
        year.setWidth("30px");
        final TextBox isbn = new TextBox();
        isbn.setText(publication.getIsbn());
        isbn.setMaxLength(32);
        final TextBox doi = new TextBox();
        doi.setText(publication.getDoi());
        doi.setMaxLength(256);
        final TextArea main = new TextArea();
        main.setText(publication.getMain());
        main.setSize("500px", "70px");
        // set max length
        main.getElement().setAttribute("maxlength", "4000");
        ft.setHTML(1, 1, publication.getId() + " / <Strong>Ext. Id: </strong>" + publication.getExternalId() + " <Strong>System: </strong>" + SafeHtmlUtils.fromString(publication.getPublicationSystemName()).asString());
        ft.setWidget(2, 1, title);
        ft.setWidget(3, 1, year);
        ft.setWidget(4, 1, listbox);
        if (session.isPerunAdmin()) {
            // only perunadmin can change rank
            ft.setWidget(5, 1, rank);
        } else {
            ft.setHTML(5, 1, SafeHtmlUtils.fromString(String.valueOf(publication.getRank()) + "").asString());
        }
        ft.setWidget(6, 1, isbn);
        ft.setWidget(7, 1, doi);
        ft.setWidget(8, 1, main);
        ft.setHTML(9, 1, SafeHtmlUtils.fromString((publication.getCreatedBy() != null) ? publication.getCreatedBy() : "").asString());
        ft.setHTML(10, 1, SafeHtmlUtils.fromString((String.valueOf(publication.getCreatedDate()) != null) ? String.valueOf(publication.getCreatedDate()) : "").asString());
        // update button
        final CustomButton change = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in publication details");
        change.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                Publication pub = JsonUtils.clone(publication).cast();
                if (!JsonUtils.checkParseInt(year.getText())) {
                    JsonUtils.cantParseIntConfirm("YEAR", year.getText());
                } else {
                    pub.setYear(Integer.parseInt(year.getText()));
                }
                if (session.isPerunAdmin()) {
                    pub.setRank(Double.parseDouble(rank.getText()));
                }
                pub.setCategoryId(listbox.getSelectedObject().getId());
                pub.setTitle(title.getText());
                pub.setMain(main.getText());
                pub.setIsbn(isbn.getText());
                pub.setDoi(doi.getText());
                UpdatePublication upCall = new UpdatePublication(JsonCallbackEvents.disableButtonEvents(change, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        // refresh page content
                        Publication p = jso.cast();
                        publication = p;
                        draw();
                    }
                }));
                upCall.updatePublication(pub);
            }
        });
        ft.setWidget(0, 0, change);
    } else {
        ft.getFlexCellFormatter().setColSpan(0, 0, 2);
        ft.setWidget(0, 0, new HTML(new Image(SmallIcons.INSTANCE.lockIcon()) + " <strong>Publication is locked. Ask administrator to perform any changes for you at meta@cesnet.cz.</strong>"));
        ft.setHTML(1, 0, "Id / Origin:");
        ft.setHTML(2, 0, "Title:");
        ft.setHTML(3, 0, "Year:");
        ft.setHTML(4, 0, "Category:");
        ft.setHTML(5, 0, "Rank:");
        ft.setHTML(6, 0, "ISBN / ISSN:");
        ft.setHTML(7, 0, "DOI:");
        ft.setHTML(8, 0, "Full cite:");
        ft.setHTML(9, 0, "Created by:");
        ft.setHTML(10, 0, "Created date:");
        for (int i = 0; i < ft.getRowCount(); i++) {
            ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
        }
        ft.getFlexCellFormatter().setWidth(1, 0, "100px");
        ft.setHTML(1, 1, publication.getId() + " / <Strong>Ext. Id: </strong>" + publication.getExternalId() + " <Strong>System: </strong>" + SafeHtmlUtils.fromString(publication.getPublicationSystemName()).asString());
        ft.setHTML(2, 1, SafeHtmlUtils.fromString((publication.getTitle() != null) ? publication.getTitle() : "").asString());
        ft.setHTML(3, 1, SafeHtmlUtils.fromString((String.valueOf(publication.getYear()) != null) ? String.valueOf(publication.getYear()) : "").asString());
        ft.setHTML(4, 1, SafeHtmlUtils.fromString((publication.getCategoryName() != null) ? publication.getCategoryName() : "").asString());
        ft.setHTML(5, 1, SafeHtmlUtils.fromString(String.valueOf(publication.getRank()) + " (default is 0)").asString());
        ft.setHTML(6, 1, SafeHtmlUtils.fromString((publication.getIsbn() != null) ? publication.getIsbn() : "").asString());
        ft.setHTML(7, 1, SafeHtmlUtils.fromString((publication.getDoi() != null) ? publication.getDoi() : "").asString());
        ft.setHTML(8, 1, SafeHtmlUtils.fromString((publication.getMain() != null) ? publication.getMain() : "").asString());
        ft.setHTML(9, 1, SafeHtmlUtils.fromString((publication.getCreatedBy() != null) ? publication.getCreatedBy() : "").asString());
        ft.setHTML(10, 1, SafeHtmlUtils.fromString((String.valueOf(publication.getCreatedDate()) != null) ? String.valueOf(publication.getCreatedDate()) : "").asString());
    }
    if (session.isPerunAdmin()) {
        final CustomButton lock;
        if (publication.isLocked()) {
            lock = new CustomButton("Unlock", "Allow editing of publication details (for users).", SmallIcons.INSTANCE.lockOpenIcon());
            ft.setWidget(0, 0, lock);
            ft.getFlexCellFormatter().setColSpan(0, 0, 1);
            ft.setWidget(0, 1, new HTML(new Image(SmallIcons.INSTANCE.lockIcon()) + " Publication is locked."));
        } else {
            lock = new CustomButton("Lock", "Deny editing of publication details (for users).", SmallIcons.INSTANCE.lockIcon());
            ft.setWidget(0, 1, lock);
        }
        lock.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                LockUnlockPublications upCall = new LockUnlockPublications(JsonCallbackEvents.disableButtonEvents(lock, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        // refresh page content
                        publication.setLocked(!publication.isLocked());
                        draw();
                    }
                }));
                Publication p = JsonUtils.clone(publication).cast();
                upCall.lockUnlockPublication(!publication.isLocked(), p);
            }
        });
    }
    DisclosurePanel dp = new DisclosurePanel();
    dp.setWidth("100%");
    dp.setContent(ft);
    dp.setOpen(true);
    FlexTable detailsHeader = new FlexTable();
    detailsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.bookIcon()));
    detailsHeader.setHTML(0, 1, "<h3>Details</h3>");
    dp.setHeader(detailsHeader);
    vp.add(dp);
    vp.add(loadAuthorsSubTab());
    vp.add(loadThanksSubTab());
    this.contentWidget.setWidget(sp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Category(cz.metacentrum.perun.webgui.model.Category) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Publication(cz.metacentrum.perun.webgui.model.Publication) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 4 with Publication

use of cz.metacentrum.perun.webgui.model.Publication in project perun by CESNET.

the class UpdatePublication method updatePublication.

/**
 * Attempts to update a Publication, it first tests the values and then submits them.
 *
 * @param publication Publication
 */
public void updatePublication(final Publication publication) {
    this.publication = publication;
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // json object
    JSONObject jsonQuery = prepareJSONObject();
    // local events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Updating publication: " + publication.getId() + " failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            Publication pub = jso.cast();
            session.getUiElements().setLogSuccessText("Publication with ID: " + pub.getId() + " updated.");
            events.onFinished(jso);
        }

        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    // create request
    JsonPostClient request = new JsonPostClient(newEvents);
    request.sendData(JSON_URL, jsonQuery);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) Publication(cz.metacentrum.perun.webgui.model.Publication) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 5 with Publication

use of cz.metacentrum.perun.webgui.model.Publication in project perun by CESNET.

the class AllPublicationsTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // CALLBACK
    final Map<String, Object> ids = new HashMap<String, Object>();
    ids.put("authors", 1);
    ids.put("yearSince", JsonUtils.getCurrentYear());
    final FindPublicationsByGUIFilter callback = new FindPublicationsByGUIFilter(ids);
    // menus
    TabMenu menu = new TabMenu();
    final HTML userHtml = new HTML("<strong>User:</strong>");
    userHtml.setVisible(false);
    final ListBoxWithObjects<Author> users = new ListBoxWithObjects<Author>();
    users.setVisible(false);
    final TabMenu filterMenu = new TabMenu();
    filterMenu.setVisible(false);
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Create new publication", new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTab(new AddPublicationsTabItem(session.getUser()));
        }
    }));
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove selected publication(s)");
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Publication> list = callback.getTableSelectedList();
            String text = "Following publications will be removed.";
            UiElements.showDeleteConfirm(list, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    // TODO - should have only one callback to core
                    for (int i = 0; i < list.size(); i++) {
                        if (i == list.size() - 1) {
                            DeletePublication request = new DeletePublication(JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(callback)));
                            request.deletePublication(list.get(i).getId());
                        } else {
                            DeletePublication request = new DeletePublication(JsonCallbackEvents.disableButtonEvents(removeButton));
                            request.deletePublication(list.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    menu.addWidget(removeButton);
    // fill users listbox
    final FindAllAuthors userCall = new FindAllAuthors(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            users.removeNotSelectedOption();
            users.clear();
            users.addNotSelectedOption();
            ArrayList<Author> list = JsonUtils.jsoAsList(jso.cast());
            list = new TableSorter<Author>().sortByName(list);
            for (int i = 0; i < list.size(); i++) {
                users.addItem(list.get(i));
                if (lastUserId != 0) {
                    if (lastUserId == list.get(i).getId()) {
                        users.setSelected(list.get(i), true);
                    }
                }
            }
            if (lastUserId == 0) {
                users.setSelectedIndex(0);
            }
        }

        public void onError(PerunError error) {
            users.clear();
            users.removeNotSelectedOption();
            users.addItem("Error while loading");
        }

        public void onLoadingStart() {
            users.clear();
            users.removeNotSelectedOption();
            users.addItem("Loading...");
        }
    });
    // fill category listbox
    final ListBoxWithObjects<Category> filterCategory = new ListBoxWithObjects<Category>();
    final GetCategories call = new GetCategories(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            filterCategory.removeNotSelectedOption();
            filterCategory.clear();
            filterCategory.addNotSelectedOption();
            ArrayList<Category> list = JsonUtils.jsoAsList(jso.cast());
            list = new TableSorter<Category>().sortByName(list);
            for (int i = 0; i < list.size(); i++) {
                filterCategory.addItem(list.get(i));
                // set last selected
                if (lastCategoryId != 0) {
                    if (list.get(i).getId() == lastCategoryId) {
                        filterCategory.setSelected(list.get(i), true);
                    }
                }
            }
            if (lastCategoryId == 0) {
                filterCategory.setSelectedIndex(0);
            }
        }

        public void onError(PerunError error) {
            filterCategory.clear();
            filterCategory.removeNotSelectedOption();
            filterCategory.addItem("Error while loading");
        }

        public void onLoadingStart() {
            filterCategory.clear();
            filterCategory.removeNotSelectedOption();
            filterCategory.addItem("Loading...");
        }
    });
    // switch lock state button
    final CustomButton lock = new CustomButton("Lock", "Lock selected publications", SmallIcons.INSTANCE.lockIcon());
    lock.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Publication> list = callback.getTableSelectedList();
            if (list != null && !list.isEmpty()) {
                LockUnlockPublications request = new LockUnlockPublications(JsonCallbackEvents.disableButtonEvents(lock, JsonCallbackEvents.refreshTableEvents(callback)));
                request.lockUnlockPublications(true, list);
            }
        }
    });
    // switch lock state button
    final CustomButton unlock = new CustomButton("Unlock", "Unlock selected publications", SmallIcons.INSTANCE.lockOpenIcon());
    unlock.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Publication> list = callback.getTableSelectedList();
            if (list != null && !list.isEmpty()) {
                LockUnlockPublications request = new LockUnlockPublications(JsonCallbackEvents.disableButtonEvents(unlock, JsonCallbackEvents.refreshTableEvents(callback)));
                request.lockUnlockPublications(false, list);
            }
        }
    });
    menu.addWidget(lock);
    menu.addWidget(unlock);
    CustomButton filter = new CustomButton("Show / Hide filter", SmallIcons.INSTANCE.filterIcon(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (filterMenu.isVisible() == false) {
                filterMenu.setVisible(true);
                userHtml.setVisible(true);
                users.setVisible(true);
                if (users.isEmpty()) {
                    userCall.retrieveData();
                }
                if (filterCategory.isEmpty()) {
                    call.retrieveData();
                }
            } else {
                filterMenu.setVisible(false);
                userHtml.setVisible(false);
                users.setVisible(false);
            }
        }
    });
    menu.addWidget(filter);
    // filter objects
    final TextBox filterTitle = new TextBox();
    filterTitle.setWidth("80px");
    filterTitle.setText(lastTitle);
    final TextBox filterYear = new TextBox();
    filterYear.setMaxLength(4);
    filterYear.setWidth("30px");
    filterYear.setText(lastYear);
    final TextBox filterIsbn = new TextBox();
    filterIsbn.setWidth("60px");
    filterIsbn.setText(lastIsbnOrDoiValue);
    final TextBox filterSince = new TextBox();
    filterSince.setMaxLength(4);
    filterSince.setWidth("30px");
    filterSince.setText(lastYearSince);
    final TextBox filterTill = new TextBox();
    filterTill.setMaxLength(4);
    filterTill.setWidth("30px");
    filterTill.setText(lastYearTill);
    final ListBox codeBox = new ListBox();
    codeBox.addItem("ISBN/ISSN:");
    codeBox.addItem("DOI:");
    if (!lastIsbnOrDoi) {
        codeBox.setSelectedIndex(1);
    }
    // add users filter in upper menu
    menu.addWidget(userHtml);
    menu.addWidget(users);
    // buttons
    CustomButton applyFilter = new CustomButton("Apply", "Show publications based on filter", SmallIcons.INSTANCE.filterAddIcon());
    CustomButton clearFilter = new CustomButton("Clear", "Show all publications", SmallIcons.INSTANCE.filterDeleteIcon());
    clearFilter.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // clear last values
            lastCategoryId = 0;
            lastIsbnOrDoi = true;
            lastIsbnOrDoiValue = "";
            lastTitle = "";
            lastUserId = 0;
            lastYear = "";
            lastYearTill = "";
            lastYearSince = "";
            // clear form
            filterTitle.setText("");
            filterYear.setText("");
            filterIsbn.setText("");
            filterSince.setText("");
            filterTill.setText("");
            filterCategory.setSelectedIndex(0);
            users.setSelectedIndex(0);
            ids.clear();
            ids.put("authors", 1);
            lastIds = ids;
            callback.setIds(ids);
            callback.clearTable();
            callback.retrieveData();
        }
    });
    applyFilter.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // refresh ids
            ids.clear();
            if (users.getSelectedIndex() > 0) {
                ids.put("userId", users.getSelectedObject().getId());
                lastUserId = users.getSelectedObject().getId();
            } else {
                ids.put("userId", 0);
                lastUserId = 0;
            }
            ids.put("authors", 1);
            // checks input
            if (!filterTitle.getText().isEmpty()) {
                ids.put("title", filterTitle.getText());
                lastTitle = filterTitle.getText();
            } else {
                lastTitle = "";
            }
            if (!filterYear.getText().isEmpty()) {
                if (!JsonUtils.checkParseInt(filterYear.getText())) {
                    JsonUtils.cantParseIntConfirm("YEAR", filterYear.getText());
                    lastYear = "";
                    return;
                } else {
                    ids.put("year", filterYear.getText());
                    lastYear = filterYear.getText();
                }
            }
            if (!filterIsbn.getText().isEmpty()) {
                if (codeBox.getSelectedIndex() == 0) {
                    // ISBN/ISSN selected
                    lastIsbnOrDoi = true;
                    ids.put("isbn", filterIsbn.getText());
                } else {
                    // DOI selected
                    lastIsbnOrDoi = false;
                    ids.put("doi", filterIsbn.getText());
                }
                lastIsbnOrDoiValue = filterIsbn.getText();
            }
            if (!filterSince.getText().isEmpty()) {
                if (!JsonUtils.checkParseInt(filterSince.getText())) {
                    JsonUtils.cantParseIntConfirm("YEAR SINCE", filterSince.getText());
                    lastYearSince = "";
                    return;
                } else {
                    ids.put("yearSince", filterSince.getText());
                    lastYearSince = filterSince.getText();
                }
            }
            if (!filterTill.getText().isEmpty()) {
                if (!JsonUtils.checkParseInt(filterTill.getText())) {
                    JsonUtils.cantParseIntConfirm("YEAR TILL", filterTill.getText());
                    lastYearTill = "";
                    return;
                } else {
                    ids.put("yearTill", filterTill.getText());
                    lastYearTill = filterTill.getText();
                }
            }
            if (filterCategory.getSelectedIndex() > 0) {
                ids.put("category", filterCategory.getSelectedObject().getId());
                lastCategoryId = filterCategory.getSelectedObject().getId();
            } else {
                lastCategoryId = 0;
            }
            lastIds = ids;
            callback.setIds(ids);
            callback.clearTable();
            callback.retrieveData();
        }
    });
    // add to filter menu
    filterMenu.addWidget(new HTML("<strong>Title:</strong>"));
    filterMenu.addWidget(filterTitle);
    filterMenu.addWidget(codeBox);
    filterMenu.addWidget(filterIsbn);
    filterMenu.addWidget(new HTML("<strong>Category:</strong>"));
    filterMenu.addWidget(filterCategory);
    filterMenu.addWidget(new HTML("<strong>Year:</strong>"));
    filterMenu.addWidget(filterYear);
    filterMenu.addWidget(new HTML("<strong>Year&nbsp;between:</strong>"));
    filterMenu.addWidget(filterSince);
    filterMenu.addWidget(new HTML("&nbsp;/&nbsp;"));
    filterMenu.addWidget(filterTill);
    filterMenu.addWidget(applyFilter);
    filterMenu.addWidget(clearFilter);
    vp.add(menu);
    vp.setCellHeight(menu, "50px");
    vp.add(filterMenu);
    if (!lastIds.isEmpty()) {
        callback.setIds(lastIds);
    }
    CellTable<Publication> table = callback.getTable(new FieldUpdater<Publication, String>() {

        public void update(int index, Publication object, String value) {
            session.getTabManager().addTab(new PublicationDetailTabItem(object));
        }
    });
    removeButton.setEnabled(false);
    lock.setEnabled(false);
    unlock.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeButton);
    JsonUtils.addTableManagedButton(callback, table, lock);
    JsonUtils.addTableManagedButton(callback, table, unlock);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    // resize perun table to correct size on screen
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Category(cz.metacentrum.perun.webgui.model.Category) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) GetCategories(cz.metacentrum.perun.webgui.json.cabinetManager.GetCategories) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FindAllAuthors(cz.metacentrum.perun.webgui.json.cabinetManager.FindAllAuthors) Publication(cz.metacentrum.perun.webgui.model.Publication) DeletePublication(cz.metacentrum.perun.webgui.json.cabinetManager.DeletePublication) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) LockUnlockPublications(cz.metacentrum.perun.webgui.json.cabinetManager.LockUnlockPublications) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) DeletePublication(cz.metacentrum.perun.webgui.json.cabinetManager.DeletePublication) Author(cz.metacentrum.perun.webgui.model.Author) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) FindPublicationsByGUIFilter(cz.metacentrum.perun.webgui.json.cabinetManager.FindPublicationsByGUIFilter)

Aggregations

Publication (cz.metacentrum.perun.webgui.model.Publication)9 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)8 PerunError (cz.metacentrum.perun.webgui.model.PerunError)7 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)6 ArrayList (java.util.ArrayList)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 JSONObject (com.google.gwt.json.client.JSONObject)3 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)3 HTML (com.google.gwt.user.client.ui.HTML)3 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)3 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)3 PublicationComparator (cz.metacentrum.perun.webgui.json.comparators.PublicationComparator)3 Category (cz.metacentrum.perun.webgui.model.Category)3 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)3 Context (com.google.gwt.cell.client.Cell.Context)2 JsArray (com.google.gwt.core.client.JsArray)2 Element (com.google.gwt.dom.client.Element)2