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 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();
}
Aggregations