use of cz.metacentrum.perun.webgui.model.Publication in project perun by CESNET.
the class UsersPublicationsTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Publications");
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// CALLBACK
final Map<String, Object> ids = new HashMap<String, Object>();
ids.put("userId", user.getId());
ids.put("authors", 1);
final FindPublicationsByGUIFilter callback = new FindPublicationsByGUIFilter(ids);
final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(callback);
// GET CORRECT TABLE
CellTable<Publication> table;
table = callback.getTable(new FieldUpdater<Publication, String>() {
public void update(int index, Publication object, String value) {
session.getTabManager().addTab(new PublicationDetailTabItem(object, true));
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel();
sp.add(table);
sp.addStyleName("perun-tableScrollPanel");
// ADD, REMOVE menu
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
// FILTER MENU
final TabMenu filterMenu = new TabMenu();
// not visible at start
filterMenu.setVisible(false);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add new Publication", new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTab(new AddPublicationsTabItem(user));
}
}));
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();
UiElements.showDeleteConfirm(list, "Following publications will be removed.", 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 (list.get(i).isLocked() && !session.isPerunAdmin()) {
// skip locked pubs
UiElements.generateAlert("Publication locked", "Publication <strong>" + SafeHtmlUtils.fromString(list.get(i).getTitle()).asString() + "</strong> is locked by " + "administrator and can't be deleted. Please notify administrator about your request.");
continue;
} else {
if (list.get(i).getCreatedBy().equalsIgnoreCase(session.getPerunPrincipal().getActor()) || session.isPerunAdmin() || session.getActiveUser().getId() == list.get(i).getCreatedByUid()) {
// delete whole publication
if (i == list.size() - 1) {
DeletePublication request = new DeletePublication(JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable));
request.deletePublication(list.get(i).getId());
} else {
DeletePublication request = new DeletePublication(JsonCallbackEvents.disableButtonEvents(removeButton));
request.deletePublication(list.get(i).getId());
}
} else {
// else delete only himself
if (i == list.size() - 1) {
DeleteAuthorship request = new DeleteAuthorship(JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable));
request.deleteAuthorship(list.get(i).getId(), userId);
} else {
DeleteAuthorship request = new DeleteAuthorship(JsonCallbackEvents.disableButtonEvents(removeButton));
request.deleteAuthorship(list.get(i).getId(), userId);
}
}
}
}
}
});
}
});
menu.addWidget(removeButton);
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, removeButton);
// fill category listbox
final ListBoxWithObjects<Category> filterCategory = new ListBoxWithObjects<Category>();
final GetCategories call = new GetCategories(new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
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");
}
@Override
public void onLoadingStart() {
filterCategory.clear();
filterCategory.removeNotSelectedOption();
filterCategory.addItem("Loading...");
}
});
final CustomButton showButton = new CustomButton("Show / Hide filter", "Show / Hide filtering options", SmallIcons.INSTANCE.filterIcon());
showButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// showing and hiding filter menu
if (filterMenu.isVisible()) {
filterMenu.setVisible(false);
} else {
filterMenu.setVisible(true);
if (filterCategory.isEmpty()) {
call.retrieveData();
}
}
}
});
menu.addWidget(showButton);
// 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);
}
// buttons
CustomButton applyFilter = new CustomButton("Apply", "Shows publications based on filter", SmallIcons.INSTANCE.filterAddIcon());
CustomButton clearFilter = new CustomButton("Clear", "Shows all publications of User", SmallIcons.INSTANCE.filterDeleteIcon());
// clear filter action
clearFilter.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// clear last values
lastCategoryId = 0;
lastIsbnOrDoi = true;
lastIsbnOrDoiValue = "";
lastTitle = "";
lastYear = "";
lastYearTill = "";
lastYearSince = "";
filterTitle.setText("");
filterYear.setText("");
filterIsbn.setText("");
filterSince.setText("");
filterTill.setText("");
filterCategory.setSelectedIndex(0);
ids.clear();
ids.put("userId", user.getId());
ids.put("authors", 0);
lastIds = ids;
callback.setIds(ids);
callback.clearTable();
callback.retrieveData();
}
});
// apply filter action
applyFilter.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// refresh ids
ids.clear();
ids.put("userId", user.getId());
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 between:</strong>"));
filterMenu.addWidget(filterSince);
filterMenu.addWidget(new HTML(" / "));
filterMenu.addWidget(filterTill);
filterMenu.addWidget(applyFilter);
filterMenu.addWidget(clearFilter);
firstTabPanel.add(menu);
firstTabPanel.add(filterMenu);
firstTabPanel.add(sp);
firstTabPanel.setCellHeight(menu, "30px");
firstTabPanel.setCellHeight(sp, "100%");
// resize perun table to correct size on screen
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.Publication 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;
}
use of cz.metacentrum.perun.webgui.model.Publication in project perun by CESNET.
the class CreatePublication method createPublication.
/**
* Attempts to create a new Publication from EXTERNAL SOURCE, it first tests the values and then submits them.
*
* @param publication Publication
*/
public void createPublication(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("Creating publicaton ext.ID: " + publication.getExternalId() + " failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
Publication pub = jso.cast();
session.getUiElements().setLogSuccessText("Publication with ID: " + pub.getId() + " created.");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.Publication in project perun by CESNET.
the class CreatePublication method createPublication.
/**
* Attempts to create a new Publication from scratch.
*
* @param title
* @param category
* @param year
* @param ISBN
* @param doi
* @param main
*/
public void createPublication(final String title, final int category, final int year, final String ISBN, final String doi, final String main) {
publication = new JSONObject().getJavaScriptObject().cast();
publication.setTitle(title);
publication.setCategoryId(category);
publication.setYear(year);
publication.setIsbn(ISBN);
publication.setMain(main);
publication.setCreatedBy(session.getPerunPrincipal().getActor());
// set to zeros to be processed as internal publication
publication.setPublicationSystemId(0);
publication.setExternalId(0);
publication.setId(0);
publication.setRank(0);
publication.setDoi(doi);
publication.setLocked(false);
publication.setCreatedByUid(session.getActiveUser().getId());
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Creating publication failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
Publication pub = jso.cast();
session.getUiElements().setLogSuccessText("Publication with ID: " + pub.getId() + " created.");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
JSONObject jquery = new JSONObject(publication);
jquery.put("createdDate", null);
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("publication", jquery);
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
Aggregations