use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class FacilityAllowedGroupsTabItem method draw.
public Widget draw() {
// set title
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Allowed Groups");
final ListBoxWithObjects<VirtualOrganization> vosListbox = new ListBoxWithObjects<VirtualOrganization>();
final ListBoxWithObjects<Service> servicesListbox = new ListBoxWithObjects<Service>();
final GetAllowedGroups jsonCallback = new GetAllowedGroups(facilityId);
jsonCallback.setCheckable(false);
// content
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(new HTML("<strong>Filter by VO:</strong>"));
menu.addWidget(vosListbox);
menu.addWidget(new HTML("<strong>Filter by service:</strong>"));
menu.addWidget(servicesListbox);
// get the table
final GetAllowedVos vosCall = new GetAllowedVos(facilityId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
vosListbox.clear();
vosListbox.removeAllOption();
vosListbox.addAllItems(new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso)));
vosListbox.addAllOption();
if (lastSelectedVoId == 0) {
vosListbox.setSelectedIndex(0);
} else {
for (VirtualOrganization vo : vosListbox.getAllObjects()) {
if (vo.getId() == lastSelectedVoId) {
vosListbox.setSelected(vo, true);
break;
}
}
}
jsonCallback.setVos(vosListbox.getAllObjects());
vosCallDone = true;
}
public void onLoadingStart() {
vosListbox.removeAllOption();
vosListbox.clear();
vosListbox.addItem("Loading...");
vosCallDone = false;
}
public void onError(PerunError error) {
vosListbox.clear();
vosListbox.removeAllOption();
vosListbox.addItem("Error while loading");
vosCallDone = false;
}
});
vosCall.retrieveData();
GetFacilityAssignedServices servCall = new GetFacilityAssignedServices(facilityId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
servicesListbox.clear();
servicesListbox.removeAllOption();
servicesListbox.addAllItems(new TableSorter<Service>().sortByName(JsonUtils.<Service>jsoAsList(jso)));
servicesListbox.addAllOption();
if (servicesListbox.isEmpty()) {
servicesListbox.addItem("No service available on facility");
}
if (lastSelectedServiceId == 0) {
// choose all
servicesListbox.setSelectedIndex(0);
} else {
for (Service s : servicesListbox.getAllObjects()) {
if (s.getId() == lastSelectedServiceId) {
servicesListbox.setSelected(s, true);
break;
}
}
}
callDone = true;
}
public void onLoadingStart() {
servicesListbox.removeAllOption();
servicesListbox.clear();
servicesListbox.addItem("Loading...");
callDone = false;
}
public void onError(PerunError error) {
servicesListbox.clear();
servicesListbox.removeAllOption();
servicesListbox.addItem("Error while loading");
callDone = false;
}
});
servCall.retrieveData();
Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
if (vosCallDone && callDone) {
jsonCallback.setVoId(lastSelectedVoId);
jsonCallback.setServiceId(lastSelectedServiceId);
jsonCallback.retrieveData();
return false;
} else {
return true;
}
}
}, 200);
vosListbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (vosListbox.getSelectedIndex() > 0) {
jsonCallback.setVoId(vosListbox.getSelectedObject().getId());
lastSelectedVoId = vosListbox.getSelectedObject().getId();
} else {
jsonCallback.setVoId(0);
lastSelectedVoId = 0;
}
jsonCallback.retrieveData();
}
});
servicesListbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (servicesListbox.getSelectedIndex() > 0) {
jsonCallback.setServiceId(servicesListbox.getSelectedObject().getId());
lastSelectedServiceId = servicesListbox.getSelectedObject().getId();
} else {
jsonCallback.setServiceId(0);
lastSelectedServiceId = 0;
}
jsonCallback.retrieveData();
}
});
CellTable<Group> table = jsonCallback.getEmptyTable(new FieldUpdater<Group, String>() {
@Override
public void update(int i, Group group, String s) {
if (session.isVoAdmin(group.getVoId()) || session.isGroupAdmin(group.getId())) {
session.getTabManager().addTab(new GroupDetailTabItem(group));
} else {
// show alert
UiElements.generateInfo("You are not VO / Group manager of this group", "You MUST be VO manager or Group manager of group: <strong>" + SafeHtmlUtils.fromString(group.getName()).asString() + "</strong> to view it's details.");
}
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class FacilityHostsSettingsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts settings");
// main panel
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
final GetAttributesV2 attrs = new GetAttributesV2();
final ListBoxWithObjects<Host> listbox = new ListBoxWithObjects<Host>();
// refresh attributes for hosts
listbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (listbox.getSelectedObject() != null) {
lastSelectedHostId = listbox.getSelectedObject().getId();
attrs.getHostAttributes(lastSelectedHostId);
attrs.retrieveData();
} else {
lastSelectedHostId = 0;
}
}
});
// retrieve hosts
final GetHosts hosts = new GetHosts(facilityId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
listbox.clear();
ArrayList<Host> result = JsonUtils.jsoAsList(jso);
if (result != null && !result.isEmpty()) {
for (Host h : result) {
listbox.addItem(h);
if (h.getId() == lastSelectedHostId) {
listbox.setSelected(h, true);
}
}
if (lastSelectedHostId == 0) {
lastSelectedHostId = listbox.getSelectedObject().getId();
}
attrs.getHostAttributes(lastSelectedHostId);
attrs.retrieveData();
}
}
@Override
public void onError(PerunError error) {
listbox.clear();
listbox.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
listbox.clear();
listbox.addItem("Loading...");
}
});
hosts.retrieveData();
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(attrs);
// menu
TabMenu menu = new TabMenu();
// Save changes button
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, events);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
SetAttributes request = new SetAttributes(saveChangesButtonEvent);
request.setAttributes(ids, list);
}
}
});
// Remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attrs.getList()), true);
}
}));
menu.addWidget(removeButton);
menu.addWidget(new HTML("<strong>Select host:</strong>"));
menu.addWidget(listbox);
// attrs table
CellTable<Attribute> table = attrs.getEmptyTable();
// 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 and the table to the main panel
firstTabPanel.add(menu);
firstTabPanel.setCellHeight(menu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects 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 between:</strong>"));
filterMenu.addWidget(filterSince);
filterMenu.addWidget(new HTML(" / "));
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();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects 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.widgets.ListBoxWithObjects in project perun by CESNET.
the class DestinationResultsTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Tasks results: " + destination);
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
final ListBoxWithObjects<RichService> listbox = new ListBoxWithObjects<RichService>();
final CustomButton cb = new CustomButton(ButtonTranslation.INSTANCE.forcePropagationButton(), ButtonTranslation.INSTANCE.forcePropagation(), SmallIcons.INSTANCE.arrowRightIcon());
GetFacilityAssignedServicesForGUI servCall = new GetFacilityAssignedServicesForGUI(facilityId);
servCall.setEvents(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
listbox.clear();
ArrayList<RichService> list = JsonUtils.jsoAsList(jso);
list = new TableSorter<RichService>().sortByName(list);
for (RichService s : list) {
if (s.getAllowedOnFacility().equalsIgnoreCase("allowed") && (s.getService() != null && s.getService().isEnabled())) {
listbox.addItem(s);
}
}
if (listbox.isEmpty()) {
listbox.addItem("No service available");
cb.setEnabled(false);
}
}
@Override
public void onError(PerunError error) {
listbox.clear();
listbox.addItem("Error while loading");
cb.setEnabled(false);
}
@Override
public void onLoadingStart() {
listbox.clear();
listbox.addItem("Loading...");
}
});
if (facilityId != 0) {
servCall.retrieveData();
}
cb.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
ForceServicePropagation force = new ForceServicePropagation(JsonCallbackEvents.disableButtonEvents(cb));
force.forcePropagation(facilityId, listbox.getSelectedObject().getId());
}
});
menu.addWidget(cb);
menu.addWidget(new HTML("<strong>Service: </strong>"));
menu.addWidget(listbox);
Anchor a = new Anchor("View facility details >>");
a.setStyleName("pointer");
a.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().addTab(new FacilityDetailTabItem(facility));
}
});
menu.addWidget(a);
ArrayList<String> dest = new ArrayList<String>();
dest.add(destination);
final GetTaskResultsByDestinations callback = new GetTaskResultsByDestinations(dest);
CellTable<TaskResult> table = callback.getTable();
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations