use of cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes in project perun by CESNET.
the class PerunAttributeTableWidget method save.
/**
* Saves the attributes
* If attribute with value null, asks if remove it
* Called recursively
*
* @param attrs
*/
private void save(final ArrayList<Attribute> attrs) {
// call the method
if (saveEvent == null) {
// ids must be set
if (ids == null || ids.isEmpty())
return;
final ArrayList<Attribute> toSet = new ArrayList<Attribute>();
final ArrayList<Attribute> toRemove = new ArrayList<Attribute>();
for (Attribute a : attrs) {
Object oldValue = originalAttributes.get(a.getId());
if (a.getValue().equals(oldValue)) {
// do not save not changed
} else if (a.getValueAsObject() == null) {
toRemove.add(a);
} else {
toSet.add(a);
}
}
if (!toSet.isEmpty()) {
SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// for all attributes to be saved/removed
for (Attribute a : toSet) {
originalAttributes.put(a.getId(), a.getValueAsObject());
}
}
}));
request.setAttributes(ids, toSet);
}
if (!toRemove.isEmpty()) {
RemoveAttributes request2 = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// for all attributes to be saved/removed
for (Attribute a : toRemove) {
originalAttributes.put(a.getId(), a.getValueAsObject());
}
}
}));
request2.removeAttributes(ids, toRemove);
}
if (toSet.isEmpty() && toRemove.isEmpty()) {
UiElements.generateAlert("No changes", "No changes to save.");
}
return;
}
saveEvent.save(attrs);
}
use of cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes 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();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes 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.json.attributesManager.RemoveAttributes in project perun by CESNET.
the class ShellChangeTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
final FlexTable ft = new FlexTable();
ft.setWidth("350px");
ft.setStyleName("inputFormFlexTable");
ft.setHTML(0, 0, "Available shells:");
ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
final ListBox shells = new ListBox();
shells.setWidth("200px");
ft.setWidget(0, 1, shells);
vp.add(ft);
final CustomButton selectShellButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save preferred shell");
// callback for available shells
GetAttributes attrs = new GetAttributes(new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
shells.clear();
shells.addItem("Error while loading");
}
@Override
public void onFinished(JavaScriptObject jso) {
shells.clear();
ArrayList<Attribute> list = JsonUtils.jsoAsList(jso);
if (list.isEmpty() || list == null) {
shells.addItem("No shells available");
return;
}
// fill shells
for (Attribute a : list) {
if (a.getFriendlyName().equalsIgnoreCase("shells")) {
for (int i = 0; i < a.getValueAsJsArray().length(); i++) {
// fill shell values
shells.addItem(a.getValueAsJsArray().get(i));
}
break;
}
}
// set selected
for (int i = 0; i < shells.getItemCount(); i++) {
if (shells.getValue(i).equals(a.getValue())) {
shells.setSelectedIndex(i);
break;
}
}
if (shells.getValue(shells.getSelectedIndex()).equals(a.getValue())) {
selectShellButton.setEnabled(false);
} else {
selectShellButton.setEnabled(true);
}
}
@Override
public void onLoadingStart() {
shells.clear();
shells.addItem("Loading...");
}
});
final TabItem tab = this;
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
selectShellButton.setEnabled(false);
selectShellButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// OK click button
// set new value
a.setValue(shells.getValue(shells.getSelectedIndex()));
// send request
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("user", userId);
ids.put("facility", resource.getFacilityId());
SetAttribute request = new SetAttribute(JsonCallbackEvents.disableButtonEvents(selectShellButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// refresh only what's necessary
events.onFinished(jso);
// don't refresh underlaying tab
session.getTabManager().closeTab(tab, false);
}
}));
request.setAttribute(ids, a);
}
});
attrs.getResourceAttributes(resource.getId());
attrs.retrieveData();
shells.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (shells.getValue(shells.getSelectedIndex()).equals(a.getValue())) {
selectShellButton.setEnabled(false);
} else {
selectShellButton.setEnabled(true);
}
}
});
final CustomButton defaultButton = new CustomButton("Use default", "", SmallIcons.INSTANCE.lightningIcon());
defaultButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("user", userId);
ids.put("facility", resource.getFacilityId());
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(defaultButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// refresh only what's necessary
events.onFinished(jso);
// don't refresh underlaying tab
session.getTabManager().closeTab(tab, false);
}
}));
ArrayList<Attribute> list = new ArrayList<Attribute>();
list.add(a);
request.removeAttributes(ids, list);
}
});
menu.addWidget(selectShellButton);
menu.addWidget(defaultButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes in project perun by CESNET.
the class UserDetailTabItem method loadFacilitySubContent.
private void loadFacilitySubContent(final SimplePanel subContent, final Hyperlink facilityLabel, final ListBoxWithObjects<Facility> listbox) {
final VerticalPanel entryPanel = new VerticalPanel();
entryPanel.setSize("100%", "100%");
subContent.setWidget(entryPanel);
facilityLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + listbox.getSelectedObject().getName() + "</h2>"));
facilityLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new FacilityDetailTabItem(listbox.getSelectedObject())));
final GetAttributesV2 attributes = new GetAttributesV2();
attributes.getUserFacilityAttributes(listbox.getSelectedObject().getId(), user.getId());
TabMenu menu = new TabMenu();
final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes");
saveAttrButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attributes.getTableSelectedList();
if (list == null || list.isEmpty()) {
Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
c.show();
return;
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("user", userId);
ids.put("facility", listbox.getSelectedObject().getId());
SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
request.setAttributes(ids, list);
}
});
menu.addWidget(saveAttrButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Set new attributes", new ClickHandler() {
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("user", userId);
ids.put("facility", listbox.getSelectedObject().getId());
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
}
}));
final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes");
removeAttrButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attributes.getTableSelectedList();
if (list == null || list.isEmpty()) {
Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
c.show();
return;
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("user", userId);
ids.put("facility", listbox.getSelectedObject().getId());
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
request.removeAttributes(ids, list);
}
});
menu.addWidget(removeAttrButton);
entryPanel.add(menu);
CellTable<Attribute> table = attributes.getTable();
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
entryPanel.add(sp);
// better format
entryPanel.add(new SimplePanel());
entryPanel.setCellHeight(entryPanel.getWidget(entryPanel.getWidgetCount() - 1), "100%");
session.getUiElements().resizeSmallTabPanel(sp, 320, this);
}
Aggregations