use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class AllAuthorsTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
vp.getElement().setAttribute("style", "padding-top: 5px;");
vp.setSize("100%", "100%");
// MENU
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
final FindAllAuthors callback = new FindAllAuthors();
menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
callback.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterAuthors());
CellTable<Author> table = callback.getTable(new FieldUpdater<Author, String>() {
public void update(int index, Author object, String value) {
if (session.isPerunAdmin()) {
session.getTabManager().addTab(new UsersPublicationsTabItem(object.getId()));
}
}
});
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.TabMenu 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.TabMenu in project perun by CESNET.
the class AttributeDefinitionDetailTabItem method draw.
public Widget draw() {
titleWidget.setText(def.getName());
final TabItem tab = this;
// create main panel for content
final FlexTable mainPage = new FlexTable();
mainPage.setWidth("100%");
final ExtendedTextBox description = new ExtendedTextBox();
description.setWidth("100%");
description.getTextBox().setText(def.getDescription());
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (description.getTextBox().getText().trim().isEmpty()) {
description.setError("Description can't be empty.");
return false;
}
description.setOk();
return true;
}
};
final ExtendedTextBox displayName = new ExtendedTextBox();
displayName.setWidth("100%");
displayName.getTextBox().setText(def.getDisplayName());
final ExtendedTextBox.TextBoxValidator validatorName = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (displayName.getTextBox().getText().trim().isEmpty()) {
displayName.setError("Display name can't be empty.");
return false;
}
displayName.setOk();
return true;
}
};
description.setValidator(validator);
displayName.setValidator(validatorName);
FlexTable attributeDetailTable = new FlexTable();
attributeDetailTable.setStyleName("inputFormFlexTable");
final CustomButton updateButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save attribute details");
updateButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
for (AttributeRights r : rights) {
if (r.getRole().equalsIgnoreCase("SELF")) {
list.add(getRightsFromWidgets(selfRead, selfWrite, r));
} else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
list.add(getRightsFromWidgets(voRead, voWrite, r));
} else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
list.add(getRightsFromWidgets(groupRead, groupWrite, r));
} else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
list.add(getRightsFromWidgets(facilityRead, facilityWrite, r));
}
}
if ((!def.getDescription().equals(description.getTextBox().getText().trim()) || !def.getDisplayName().equals(displayName.getTextBox().getText().trim()))) {
if (!validator.validateTextBox() || !validatorName.validateTextBox())
return;
def.setDescription(description.getTextBox().getText().trim());
def.setDisplayName(displayName.getTextBox().getText().trim());
UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// after update - update rights
SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
enableDisableWidgets(true);
}
@Override
public void onLoadingStart() {
enableDisableWidgets(false);
}
@Override
public void onError(PerunError error) {
enableDisableWidgets(true);
}
}));
request.setAttributeRights(list);
}
}));
request.updateAttribute(def);
} else {
// after update - update rights
SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
enableDisableWidgets(true);
}
@Override
public void onLoadingStart() {
enableDisableWidgets(false);
}
@Override
public void onError(PerunError error) {
enableDisableWidgets(true);
}
}));
request.setAttributeRights(list);
}
}
});
attributeDetailTable.setHTML(0, 0, "Display name:");
attributeDetailTable.setWidget(0, 1, displayName);
attributeDetailTable.setHTML(1, 0, "Description:");
attributeDetailTable.setWidget(1, 1, description);
for (int i = 0; i < attributeDetailTable.getRowCount(); i++) {
attributeDetailTable.getFlexCellFormatter().setStyleName(i, 0, "itemName");
}
final FlexTable rightsTable = new FlexTable();
rightsTable.setStyleName("inputFormFlexTable");
rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
rightsTable.setHTML(0, 2, "<strong>VO</strong>");
rightsTable.setHTML(0, 3, "<strong>GROUP</strong>");
rightsTable.setHTML(0, 4, "<strong>FACILITY</strong>");
rightsTable.setHTML(1, 0, "<strong>READ</strong>");
rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
rightsTable.setWidget(1, 1, selfRead);
rightsTable.setWidget(2, 1, selfWrite);
rightsTable.setWidget(1, 2, voRead);
rightsTable.setWidget(2, 2, voWrite);
rightsTable.setWidget(1, 3, groupRead);
rightsTable.setWidget(2, 3, groupWrite);
rightsTable.setWidget(1, 4, facilityRead);
rightsTable.setWidget(2, 4, facilityWrite);
rightsTable.addStyleName("centeredTable");
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(updateButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, false);
}
}));
GetAttributeRights rightsCall = new GetAttributeRights(def.getId(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
rights = JsonUtils.jsoAsList(jso);
for (AttributeRights r : rights) {
if (r.getRole().equalsIgnoreCase("SELF")) {
setRightsToWidgets(selfRead, selfWrite, r);
} else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
setRightsToWidgets(voRead, voWrite, r);
} else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
setRightsToWidgets(groupRead, groupWrite, r);
} else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
setRightsToWidgets(facilityRead, facilityWrite, r);
}
}
enableDisableWidgets(true);
rightsTable.setVisible(true);
}
@Override
public void onError(PerunError error) {
enableDisableWidgets(true);
rightsTable.setVisible(false);
}
@Override
public void onLoadingStart() {
enableDisableWidgets(false);
rightsTable.setVisible(false);
}
});
rightsCall.retrieveData();
// create new instance for jsonCall
final GetServicesByAttrDefinition services = new GetServicesByAttrDefinition(def.getId());
services.setCheckable(false);
CellTable<Service> attrDefTable = services.getTable(new FieldUpdater<Service, String>() {
@Override
public void update(int index, Service object, String value) {
session.getTabManager().addTab(new ServiceDetailTabItem(object));
}
});
attrDefTable.setStyleName("perun-table");
ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
scrollTable.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(scrollTable, 350, this);
// set content to page
mainPage.setWidget(0, 0, menu);
mainPage.getFlexCellFormatter().setColSpan(0, 0, 2);
mainPage.setWidget(1, 0, attributeDetailTable);
mainPage.setWidget(1, 1, rightsTable);
mainPage.getFlexCellFormatter().setWidth(1, 0, "50%");
mainPage.getFlexCellFormatter().setWidth(1, 1, "50%");
HTML title = new HTML("<p>Required by service</p>");
title.setStyleName("subsection-heading");
mainPage.setWidget(2, 0, title);
mainPage.getFlexCellFormatter().setColSpan(2, 0, 2);
// put page into scroll panel
mainPage.setWidget(3, 0, scrollTable);
mainPage.getFlexCellFormatter().setColSpan(3, 0, 2);
mainPage.getFlexCellFormatter().setHeight(3, 0, "100%");
this.contentWidget.setWidget(mainPage);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class AttributeDefinitionsTabItem method draw.
public Widget draw() {
// create main panel for content
VerticalPanel mainPage = new VerticalPanel();
mainPage.setWidth("100%");
// create new instance for jsonCall
final GetAttributesDefinition attrDef = new GetAttributesDefinition();
final ExtendedSuggestBox box = new ExtendedSuggestBox(attrDef.getOracle());
// custom events for reloading when created or deleted
final JsonCallbackEvents refreshTabEvents = JsonCallbackEvents.mergeEvents(JsonCallbackEvents.refreshTableEvents(attrDef), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (box.getSuggestBox().getValue() != null)
attrDef.filterTable(box.getSuggestBox().getValue());
}
});
// TAB MENU
TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(UiElements.getRefreshButton(this));
// create buttons
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, buttonTranslation.createAttributeDefinition(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateAttributeDefinitionTabItem());
}
}));
// remove button
final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, buttonTranslation.deleteAttributeDefinition());
deleteButton.setEnabled(false);
deleteButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<AttributeDefinition> attrDefToBeDeleted = attrDef.getTableSelectedList();
String text = "Following attribute definitions will be deleted.";
UiElements.showDeleteConfirm(attrDefToBeDeleted, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < attrDefToBeDeleted.size(); i++) {
final int x = i;
DeleteAttribute request = new DeleteAttribute(JsonCallbackEvents.disableButtonEvents(deleteButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// remove deleted attrs from table
attrDef.removeFromBackupTable(attrDefToBeDeleted.get(x));
}
}));
request.deleteAttributeDefinition(attrDefToBeDeleted.get(i).getId());
}
}
});
}
});
tabMenu.addWidget(deleteButton);
// filter box
tabMenu.addFilterWidget(box, new PerunSearchEvent() {
public void searchFor(String text) {
attrDef.filterTable(text);
}
}, buttonTranslation.filterAttributeDefinition());
final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
final ArrayList<AttributeDefinition> list = attrDef.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < list.size(); i++) {
final int x = i;
UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
attrDef.getSelectionModel().setSelected(list.get(x), false);
}
}));
request.updateAttribute(list.get(i));
}
}
}
});
tabMenu.addWidget(saveButton);
// add menu to page
mainPage.add(tabMenu);
mainPage.setCellHeight(tabMenu, "30px");
CellTable<AttributeDefinition> attrDefTable = attrDef.getTable(new FieldUpdater<AttributeDefinition, String>() {
@Override
public void update(int index, AttributeDefinition object, String value) {
session.getTabManager().addTabToCurrentTab(new AttributeDefinitionDetailTabItem(object), true);
}
});
attrDefTable.setStyleName("perun-table");
ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
scrollTable.addStyleName("perun-tableScrollPanel");
JsonUtils.addTableManagedButton(attrDef, attrDefTable, deleteButton);
// put page into scroll panel
mainPage.add(scrollTable);
session.getUiElements().resizePerunTable(scrollTable, 350, this);
this.contentWidget.setWidget(mainPage);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class FacilitySettingsTabItem method draw.
public Widget draw() {
// set title
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Service settings");
// content
vp.setSize("100%", "100%");
vp.clear();
// HORIZONTAL MENU
TabMenu menu = new TabMenu();
// Get Attributes method
final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2();
final GetAttributesV2 attrs = new GetAttributesV2();
attrs.getFacilityAttributes(facilityId);
// get empty table
final CellTable<Attribute> table = reqAttrs.getEmptyTable();
final CellTable<Attribute> table2 = attrs.getEmptyTable();
sp.setWidget(table);
sp2.setWidget(table2);
// ids to retrieve data from rpc
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("facility", facility.getId());
// service switcher checkbox
final CheckBox switchServicesChb = new CheckBox(WidgetTranslation.INSTANCE.offerAvailableServicesOnly(), false);
// selected by default - unselected if switch hidden
switchServicesChb.setValue(lastCheckBoxValue);
switchServicesChb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
// services listbox
final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
// on change of service update table
servList.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
if (servList.getSelectedIndex() == 0) {
// show all facility attributes
attrs.retrieveData();
setTable(false);
lastServiceId = 0;
indexInList = 0;
return;
}
if (switchServicesChb.getValue() == true && servList.getSelectedIndex() == 1) {
// show required attrs for all assigned services
ids.remove("service");
lastServiceId = 0;
indexInList = 1;
} else if ((switchServicesChb.getValue() == true && servList.getSelectedIndex() > 1) || (switchServicesChb.getValue() == false && servList.getSelectedIndex() > 0)) {
// show required attrs for selected service
// >0 when listing all services
// >1 when listing assigned services
ids.put("service", servList.getSelectedObject().getId());
lastServiceId = servList.getSelectedObject().getId();
}
// load req attrs
reqAttrs.setIds(ids);
reqAttrs.clearTable();
reqAttrs.retrieveData();
setTable(true);
}
});
// event which fills the listbox and call getRequiredAttributes
final JsonCallbackEvents event = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
servList.clear();
ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
srv = new TableSorter<Service>().sortByName(srv);
for (int i = 0; i < srv.size(); i++) {
servList.addItem(srv.get(i));
}
// no services available - load all facility attrs
if (servList.isEmpty()) {
servList.addNotSelectedOption();
lastServiceId = 0;
indexInList = 0;
attrs.retrieveData();
setTable(false);
return;
}
// offer only available
if (switchServicesChb.getValue() == true) {
servList.addNotSelectedOption();
servList.addAllOption();
if (lastServiceId == 0) {
if (indexInList == 1) {
// all
servList.setSelectedIndex(1);
} else if (indexInList == 0) {
// not selected - load all fac attrs
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
}
}
} else {
// offer all services
servList.addNotSelectedOption();
if (lastServiceId == 0) {
// if no service selected, load all fac attrs
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
}
}
// if some service was selected
if (lastServiceId != 0) {
// remove service since we can't be sure, it was loaded again
ids.remove("service");
// either all or first service in a list
servList.setSelectedIndex(1);
for (Service s : servList.getAllObjects()) {
if (s.getId() == lastServiceId) {
// if found, select it
servList.setSelected(s, true);
ids.put("service", lastServiceId);
break;
}
}
}
// get required attrs for service
reqAttrs.clearTable();
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
setTable(true);
}
@Override
public void onError(PerunError error) {
servList.clear();
if (required) {
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
} else {
((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
}
servList.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
servList.removeAllOption();
servList.removeNotSelectedOption();
servList.clear();
servList.addItem("Loading...");
}
};
final GetServices allServices = new GetServices(event);
final GetFacilityAssignedServices assignedServices = new GetFacilityAssignedServices(facility.getId(), event);
// if hide and unchecked or just unchecked
if (!lastCheckBoxValue) {
allServices.retrieveData();
} else {
assignedServices.retrieveData();
}
// Save changes button
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
final JsonCallbackEvents refreshEvents = JsonCallbackEvents.refreshTableEvents(reqAttrs);
final JsonCallbackEvents refreshEvents2 = JsonCallbackEvents.refreshTableEvents(attrs);
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents);
final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents2);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
request.setAttributes(ids, list);
}
}
});
// Remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents);
final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents2);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("facility", facilityId);
RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
request.removeAttributes(ids, list);
}
}
});
// switch serv checkbox
switchServicesChb.addClickHandler(new ClickHandler() {
// load proper set of services on click
public void onClick(ClickEvent event) {
lastCheckBoxValue = switchServicesChb.getValue();
if (switchServicesChb.getValue() == true) {
assignedServices.retrieveData();
} else {
allServices.retrieveData();
}
}
});
// allow to set new (currently unused facility attribute)
CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("facility", facility.getId());
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, (required) ? reqAttrs.getList() : attrs.getList()), true);
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
menu.addWidget(setNewAttributeButton);
menu.addWidget(removeButton);
menu.addWidget(new HTML("<strong>Service: </strong>"));
menu.addWidget(servList);
if (!hide) {
menu.addWidget(switchServicesChb);
}
/* TODO - not yet implemented
CustomButton fillDefaultButton = new CustomButton("Fill default values", SmallIcons.INSTANCE.scriptGoIcon(), new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("not yet implemented");
}
});
fillDefaultButton.setTitle("Fill default values for this service/facility - nothing is saved unless you click on 'Save changes'");
CustomButton checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon(), new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("not yet implemented");
}
});
checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");
menu.addWidget(fillDefaultButton);
menu.addWidget(checkValuesButton);
*/
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
table.setWidth("100%");
table2.addStyleName("perun-table");
table2.setWidth("100%");
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
sp2.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp2, 350, this);
// add menu and the table to the main panel
vp.add(menu);
vp.setCellHeight(menu, "30px");
// default is required attributes
setTable(true);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations