Search in sources :

Example 1 with FindNewAuthors

use of cz.metacentrum.perun.webgui.json.cabinetManager.FindNewAuthors in project perun by CESNET.

the class AddAuthorTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add author");
    this.users = new FindNewAuthors("");
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // PUB-INFO
    TabMenu info = new TabMenu();
    info.addWidget(new HTML("<strong>FULL&nbsp;CITE: </strong>" + publication.getMain()));
    firstTabPanel.add(info);
    // HORIZONTAL MENU
    TabMenu tabMenu = new TabMenu();
    // get the table
    final CellTable<Author> table;
    if (session.isPerunAdmin()) {
        table = users.getEmptyTable(new FieldUpdater<Author, String>() {

            public void update(int index, Author object, String value) {
                session.getTabManager().addTab(new UserDetailTabItem(object.getId()));
            }
        });
    } else {
        table = users.getEmptyTable();
    }
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected user(s) as author(s) of publication: " + publication.getTitle());
    tabMenu.addWidget(addButton);
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(users, table, addButton);
    final TabItem tab = this;
    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<Author> list = users.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // proceed
                for (int i = 0; i < list.size(); i++) {
                    final String name = list.get(i).getDisplayName();
                    // add name events
                    JsonCallbackEvents authorshipEvents = new JsonCallbackEvents() {

                        public void onFinished(JavaScriptObject jso) {
                            updateAlreadyAdded(name);
                        }
                    };
                    // merge with refresh?
                    if (i == list.size() - 1 && events != null) {
                        authorshipEvents = JsonCallbackEvents.mergeEvents(authorshipEvents, events);
                    }
                    // call
                    CreateAuthorship request = new CreateAuthorship(JsonCallbackEvents.disableButtonEvents(addButton, authorshipEvents));
                    request.createAuthorship(publicationId, list.get(i).getId());
                    if (i == list.size() - 1) {
                        users.clearTableSelectedSet();
                    }
                }
            }
        }
    });
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            users.searchFor(text);
            searchString = text;
        }
    }, ButtonTranslation.INSTANCE.searchUsers());
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // add already added
    firstTabPanel.add(alreadyAddedAuthors);
    firstTabPanel.setCellHeight(alreadyAddedAuthors, "30px");
    // add table to the main panel
    firstTabPanel.add(sp);
    // do not resize like perun table to prevent wrong width in inner tab
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CreateAuthorship(cz.metacentrum.perun.webgui.json.cabinetManager.CreateAuthorship) FindNewAuthors(cz.metacentrum.perun.webgui.json.cabinetManager.FindNewAuthors) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Author(cz.metacentrum.perun.webgui.model.Author)

Aggregations

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 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 CreateAuthorship (cz.metacentrum.perun.webgui.json.cabinetManager.CreateAuthorship)1 FindNewAuthors (cz.metacentrum.perun.webgui.json.cabinetManager.FindNewAuthors)1 Author (cz.metacentrum.perun.webgui.model.Author)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 UserDetailTabItem (cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1