use of cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes in project perun by CESNET.
the class GroupResourceRequiredAttributesTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings for " + Utils.getStrippedStringWithEllipsis(resource.getName()));
if (JsonUtils.isExtendedInfoVisible()) {
columnId = 3;
} else {
columnId = 2;
}
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
TabMenu menu = new TabMenu();
final Label facilityId = new Label();
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
Facility fac = (Facility) jso;
facilityId.setText(String.valueOf(fac.getId()));
}
};
GetFacility facility = new GetFacility(resourceId, events);
facility.retrieveData();
mainTab.add(new HTML("<hr size=\"2px\" />"));
// set attributes type to group_resource
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("group", groupId);
// gets all required group attributes for specified group and resource
final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
reqAttrsTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// get all required group_resource attributes too
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
final ListBoxWithObjects<RichMember> listBox = new ListBoxWithObjects<RichMember>();
listBox.setTitle(WidgetTranslation.INSTANCE.selectingMember());
// local event fills the listBox
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
mems = new TableSorter<RichMember>().sortByName(mems);
listBox.addNotSelectedOption();
for (int i = 0; i < mems.size(); i++) {
listBox.addItem(mems.get(i));
}
listBox.addAllOption();
}
};
final GetGroupRichMembers getGroupRichMembers = new GetGroupRichMembers(groupId, localEvents);
getGroupRichMembers.retrieveData();
reqAttrsTable.addStyleName("perun-table");
final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
sp.addStyleName("perun-tableScrollPanel");
// store for column with values
final Column<Attribute, ?> columnStore = reqAttrsTable.getColumn(columnId);
listBox.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
int selectedIndex = listBox.getSelectedIndex();
// no member selected
if (selectedIndex == 0) {
// offer just group and group resource attributes
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get groups attributes
ids.put("group", groupId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// get group_resource attributes
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
reqAttrs.sortTable();
// some member is selected
} else {
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get member, member-resource, user, user-facility attributes
ids.put("member", listBox.getSelectedObject().getId());
ids.put("resource", resourceId);
// to get user, user-facility attrs
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// all members are selected
if (selectedIndex == 1) {
// remove value column
reqAttrsTable.removeColumn(columnId);
// create own value column
// Value column
Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {
public Attribute getValue(Attribute attribute) {
attribute.setValueAsJso(null);
return attribute;
}
}, new FieldUpdater<Attribute, Attribute>() {
public void update(int index, Attribute object, Attribute value) {
object = value;
reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
}
});
// add to table
reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
} else {
// member selected
// return original column
reqAttrsTable.removeColumn(columnId);
reqAttrsTable.insertColumn(columnId, columnStore, "Value");
}
}
}
});
CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// send lists
ArrayList<Attribute> groupList = new ArrayList<Attribute>();
ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> memberList = new ArrayList<Attribute>();
ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> userList = new ArrayList<Attribute>();
ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
SetAttributes request = new SetAttributes();
int selectedIndex = listBox.getSelectedIndex();
// if all selected
if (selectedIndex == 1) {
// TODO - USE NEW CONFIRM DESIGN
if (!Window.confirm("Same values for selected attributes will be set to all members in group." + "\n\nDo you want to continue ?")) {
return;
}
}
// get different attributes
for (Attribute attr : list) {
if (attr.getNamespace().contains("urn:perun:group:")) {
groupList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
groupResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member:")) {
memberList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member_resource:")) {
memberResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user:")) {
userList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user_facility:")) {
userFacilityList.add(attr);
}
}
// if not empty, send request
if (!(groupList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
request.setAttributes(ids, groupList);
}
if (!(groupResourceList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
ids.put("resource", resourceId);
request.setAttributes(ids, groupResourceList);
}
if (!(memberList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberList);
}
} else {
// for one member
ids.clear();
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberList);
}
}
if (!(memberResourceList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("resource", resourceId);
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberResourceList);
}
} else {
// for one member
ids.clear();
ids.put("resource", resourceId);
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberResourceList);
}
}
if (!(userList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", (listBox.getObjectAt(i)).getUser().getId());
request.setAttributes(ids, userList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
request.setAttributes(ids, userList);
}
}
if (!(userFacilityList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", listBox.getObjectAt(i).getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
}
reqAttrs.clearTableSelectedSet();
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
saveChangesButton.setEnabled(false);
menu.addWidget(new HTML("<strong>Group members:</strong>"));
menu.addWidget(listBox);
// table content
session.getUiElements().resizePerunTable(sp, 350, this);
mainTab.add(menu);
mainTab.add(sp);
mainTab.setCellHeight(sp, "100%");
mainTab.setCellHeight(menu, "30px");
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes in project perun by CESNET.
the class UserDetailTabItem method loadMemberSubContent.
private void loadMemberSubContent(final SimplePanel subContent, final Hyperlink voLabel, final ListBoxWithObjects<VirtualOrganization> listbox) {
subContent.setWidget(new AjaxLoaderImage());
final GetMemberByUser gmbu = new GetMemberByUser(listbox.getSelectedObject().getId(), user.getId());
JsonCallbackEvents loadEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// get member
final Member member = jso.cast();
// create content panel and put it on page
final VerticalPanel entryPanel = new VerticalPanel();
entryPanel.setStyleName("perun-table");
entryPanel.setSize("100%", "100%");
subContent.setWidget(entryPanel);
voLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + SafeHtmlUtils.fromString((listbox.getSelectedObject().getName() != null) ? listbox.getSelectedObject().getName() : "").asString() + "</h2>"));
voLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new VoDetailTabItem(listbox.getSelectedObject())));
// detail header
Widget memberHeader = new HTML("<h2>" + "Member details" + "</h2>");
entryPanel.add(memberHeader);
entryPanel.setCellHeight(memberHeader, "30px");
// detail content
FlexTable layout = new FlexTable();
layout.setCellSpacing(6);
// Add some standard form options
layout.setHTML(0, 0, "<strong>Member ID:</strong>");
layout.setHTML(0, 1, String.valueOf(member.getId()));
ImageResource ir = null;
// member status
if (member.getStatus().equalsIgnoreCase("VALID")) {
ir = SmallIcons.INSTANCE.acceptIcon();
} else if (member.getStatus().equalsIgnoreCase("INVALID")) {
ir = SmallIcons.INSTANCE.flagRedIcon();
} else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
ir = SmallIcons.INSTANCE.flagYellowIcon();
} else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
ir = SmallIcons.INSTANCE.binClosedIcon();
}
HTML status = new HTML("<a>" + member.getStatus() + " " + new Image(ir) + "</a>");
layout.setHTML(1, 0, "<strong>Member status: </strong>");
layout.setWidget(1, 1, status);
// member status - on click action
status.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
PerunWebSession.getInstance().getTabManager().addTabToCurrentTab(new ChangeStatusTabItem(member, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
loadMemberSubContent(subContent, voLabel, listbox);
}
}));
}
});
final ListBoxWithObjects<Resource> resList = new ListBoxWithObjects<Resource>();
GetAssignedResources res = new GetAssignedResources(member.getId(), PerunEntity.MEMBER, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
resList.clear();
ArrayList<Resource> list = JsonUtils.jsoAsList(jso);
if (list == null || list.isEmpty()) {
resList.addItem("No resources found");
} else {
list = new TableSorter<Resource>().sortByName(list);
resList.addNotSelectedOption();
resList.addAllItems(list);
}
}
@Override
public void onError(PerunError error) {
resList.clear();
resList.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
resList.clear();
resList.addItem("Loading...");
}
});
res.retrieveData();
// link to member's detail
Hyperlink link = new Hyperlink();
link.setText("View detail");
layout.setHTML(2, 0, "<strong>Member's detail page:</strong>");
layout.setWidget(2, 1, link);
link.setTargetHistoryToken(session.getTabManager().getLinkForTab(new MemberDetailTabItem(member.getId(), 0)));
// wrap the content in a DecoratorPanel
DecoratorPanel decPanel = new DecoratorPanel();
decPanel.setWidget(layout);
entryPanel.add(decPanel);
entryPanel.setCellHeight(decPanel, "50px");
// tables
// detail header
Widget groupHeader = new HTML("<h2>" + "Member groups" + "</h2>");
entryPanel.add(groupHeader);
entryPanel.setCellHeight(groupHeader, "30px");
final GetMemberGroups groups = new GetMemberGroups(member.getId());
groups.setCheckable(false);
groups.setEditable(false);
CellTable<Group> table = groups.getTable();
table.addStyleName("perun-table");
table.setWidth("100%");
entryPanel.add(table);
// detail header
Widget attrHeader = new HTML("<h2>" + "Member / Member-resource attributes" + "</h2>");
entryPanel.add(attrHeader);
entryPanel.setCellHeight(attrHeader, "30px");
final GetAttributesV2 attributes = new GetAttributesV2();
attributes.getMemberAttributes(member.getId());
resList.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (resList.getSelectedIndex() == 0) {
attributes.getMemberAttributes(member.getId());
attributes.retrieveData();
} else {
attributes.getMemberResourceAttributes(member.getId(), resList.getSelectedObject().getId());
attributes.retrieveData();
}
}
});
TabMenu menu = new TabMenu();
final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for member");
saveAttrButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attributes.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.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 for member", new ClickHandler() {
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.getSelectedObject().getId());
}
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
}
}));
final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes from member");
removeAttrButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attributes.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.getSelectedObject().getId());
}
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(removeAttrButton);
menu.addWidget(new HTML("<strong>Resource:</strong>"));
menu.addWidget(resList);
entryPanel.add(menu);
CellTable<Attribute> attrTable = attributes.getTable();
attrTable.addStyleName("perun-table");
attrTable.setWidth("100%");
entryPanel.add(attrTable);
}
@Override
public void onError(PerunError error) {
subContent.setWidget(new AjaxLoaderImage().loadingError(error));
}
};
// set events & load data
gmbu.setEvents(loadEvent);
gmbu.retrieveData();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes in project perun by CESNET.
the class UserExtSourceSettingsTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(userExtSource.getLogin().trim()));
// MAIN TAB PANEL
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// MENU
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
final GetAttributesV2 callback = new GetAttributesV2(true);
callback.getUserExtSourceAttributes(userExtSource.getId());
final CellTable<Attribute> table = callback.getEmptyTable();
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
menu.addWidget(UiElements.getRefreshButton(this));
// save changes in attributes
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
callback.getUserExtSourceAttributes(userExtSourceId);
callback.retrieveData();
}
}));
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("userExtSource", userExtSourceId);
request.setAttributes(ids, callback.getTableSelectedList());
}
}
});
menu.addWidget(saveChangesButton);
// buttons
CustomButton setNewMemberAttributeButton = 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("userExtSource", userExtSource.getId());
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids), true);
}
});
menu.addWidget(setNewMemberAttributeButton);
// REMOVE ATTRIBUTES BUTTON
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// if selected
if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("userExtSource", userExtSource.getId());
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
callback.getUserExtSourceAttributes(userExtSource.getId());
callback.retrieveData();
}
}));
// make removeAttributes call
request.removeAttributes(ids, callback.getTableSelectedList());
}
}
});
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, removeButton);
menu.addWidget(removeButton);
callback.retrieveData();
// ATTRIBUTES TABLE
vp.add(sp);
vp.setCellHeight(sp, "100%");
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes 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.SetAttributes in project perun by CESNET.
the class SelfResourcesSettingsTabItem method loadContent.
private void loadContent(final FlexTable layoutx, final Resource resource, final boolean disableOptOut) {
// get member
final GetMemberByUser callMember = new GetMemberByUser(resource.getVoId(), userId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// member
final Member mem = jso.cast();
// set ids
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", mem.getId());
ids.put("resource", resource.getId());
// to filter empty values
ids.put("resourceToGetServicesFrom", resource.getId());
ids.put("workWithUserAttributes", 1);
// get req. attrs - to filter eg. if quota is used or not
final GetRequiredAttributes attributes = new GetRequiredAttributes(ids);
final JsonCallbackEvents refreshEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// / reload resource settings data
attributes.retrieveData();
}
};
attributes.setEvents(new JsonCallbackEvents() {
public void onLoadingStart() {
AjaxLoaderImage loader = new AjaxLoaderImage(true);
layoutx.setWidget(0, 0, loader.loadingStart());
}
public void onError(PerunError error) {
AjaxLoaderImage loader = new AjaxLoaderImage(true);
layoutx.setWidget(0, 0, loader.loadingError(error));
}
public void onFinished(JavaScriptObject jso) {
// fill layout
ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
// check if any attributes displayed
boolean empty = true;
// remove loading image
layoutx.getWidget(0, 0).removeFromParent();
int row = 0;
// process shell
for (final Attribute a : attrs) {
// user's shell on facility (DEF is exception from default VIRT so display them)
if (a.getFriendlyName().equalsIgnoreCase("shell") && !a.getDefinition().equalsIgnoreCase("virt")) {
layoutx.setHTML(row, 0, "<strong>Shell: </strong>");
empty = false;
// change button
CustomButton cb = new CustomButton("Change…", SmallIcons.INSTANCE.cogIcon());
layoutx.setWidget(row, 2, cb);
// click handler
cb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new ShellChangeTabItem(resource, userId, a, refreshEvent));
}
});
if (!a.getValue().equalsIgnoreCase("null")) {
// FIXME - we can't offer what default would be, since virt value is always same as def value
layoutx.setHTML(row, 1, SafeHtmlUtils.fromString((a.getValue() != null) ? a.getValue() : "").asString());
row++;
layoutx.setHTML(row, 1, "You are using specific shell for this resource overriding your global preferences.<br />To get back to default use change button.");
layoutx.getFlexCellFormatter().setStyleName(row, 1, "inputFormInlineComment");
layoutx.getFlexCellFormatter().setColSpan(row, 1, 2);
}
for (Attribute ia : attrs) {
if (ia.getFriendlyName().equalsIgnoreCase("shell") && ia.getDefinition().equalsIgnoreCase("virt")) {
if (a.getValue().equalsIgnoreCase("null") && ia.getValue().equalsIgnoreCase("null")) {
layoutx.setHTML(row, 1, "Using default (default: Not set)");
} else if (a.getValue().equalsIgnoreCase("null")) {
layoutx.setHTML(row, 1, "Using default (default: " + SafeHtmlUtils.fromString((a.getValue() != null) ? a.getValue() : "").asString() + ")");
row++;
layoutx.setHTML(row, 1, "You are using default shell taken from your global preferences.<br />Use change button to set specific shell for this resource.");
layoutx.getFlexCellFormatter().setStyleName(row, 1, "inputFormInlineComment");
layoutx.getFlexCellFormatter().setColSpan(row, 1, 2);
}
break;
}
}
row++;
break;
}
}
for (final Attribute a : attrs) {
if (a.getFriendlyName().equalsIgnoreCase("dataQuotas") && !a.getValueAsMap().isEmpty()) {
final int rowDataLimit = row;
final CustomButton quotaChangeButton = new CustomButton("Request change…", SmallIcons.INSTANCE.databaseIcon());
// display value
layoutx.setHTML(row, 0, "<strong>Data quota: </strong>");
// get default
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resource.getId());
GetAttributes defaultAttr = new GetAttributes(new JsonCallbackEvents() {
public void onError(PerunError error) {
if (a.getValueAsMap().isEmpty()) {
layoutx.setHTML(rowDataLimit, 1, "Using default (default: error while loading)");
} else {
layoutx.setHTML(rowDataLimit, 1, SafeHtmlUtils.fromString(convertMapToNiceString(a.getValueAsMap())).asString() + " (default: error while loading)");
}
quotaChangeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.DATA, convertMapToNiceString(a.getValueAsMap()), convertMapToNiceString(new HashMap<String, JSONValue>())));
}
});
}
public void onFinished(JavaScriptObject jso) {
ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
boolean empty = true;
for (final Attribute resAttr : attrs) {
if (resAttr.getFriendlyName().equalsIgnoreCase("defaultDataQuotas")) {
if (a.getValueAsMap().isEmpty()) {
// null private + default
layoutx.setHTML(rowDataLimit, 1, "Using default (default: " + SafeHtmlUtils.fromString(convertMapToNiceString(resAttr.getValueAsMap())).asString() + ")");
} else {
// private - default
layoutx.setHTML(rowDataLimit, 1, SafeHtmlUtils.fromString(convertMapToNiceString(a.getValueAsMap())).asString() + " (default: " + SafeHtmlUtils.fromString(convertMapToNiceString(resAttr.getValueAsMap())).asString() + ")");
}
empty = false;
quotaChangeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.DATA, convertMapToNiceString(a.getValueAsMap()), convertMapToNiceString(resAttr.getValueAsMap())));
}
});
}
}
// if no default found, write down at least private
if (empty) {
if (a.getValueAsMap().isEmpty()) {
layoutx.setHTML(rowDataLimit, 1, "Using default (default: Not set)");
} else {
layoutx.setHTML(rowDataLimit, 1, SafeHtmlUtils.fromString(convertMapToNiceString(a.getValueAsMap())).asString() + " (default: Not set)");
}
quotaChangeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.DATA, convertMapToNiceString(a.getValueAsMap()), convertMapToNiceString(new HashMap<String, JSONValue>())));
}
});
}
}
});
defaultAttr.setIds(ids);
defaultAttr.retrieveData();
empty = false;
layoutx.setWidget(row, 2, quotaChangeButton);
row++;
layoutx.setHTML(row, 1, "Quotas are using \"soft limit : hard limit\" notation and are bound to specific volume.");
layoutx.getFlexCellFormatter().setStyleName(row, 1, "inputFormInlineComment");
layoutx.getFlexCellFormatter().setColSpan(row, 1, 2);
row++;
break;
}
}
for (final Attribute a : attrs) {
if (a.getFriendlyName().equalsIgnoreCase("filesQuotas") && !a.getValueAsMap().isEmpty()) {
layoutx.setHTML(row, 0, "<strong>Files quota: </strong>");
final int rowFilesQuota = row;
// get default
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resource.getId());
final CustomButton quotaChangeButton = new CustomButton("Request change…", SmallIcons.INSTANCE.databaseIcon());
GetAttributes defaultAttr = new GetAttributes(new JsonCallbackEvents() {
public void onError(PerunError error) {
if (a.getValueAsMap().isEmpty()) {
layoutx.setHTML(rowFilesQuota, 1, "Using default (default: error while loading)");
} else {
layoutx.setHTML(rowFilesQuota, 1, SafeHtmlUtils.fromString(convertMapToNiceString(a.getValueAsMap())).asString() + " (default: error while loading)");
}
quotaChangeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.FILES, convertMapToNiceString(a.getValueAsMap()), convertMapToNiceString(new HashMap<String, JSONValue>())));
}
});
}
public void onFinished(JavaScriptObject jso) {
ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
boolean empty = true;
for (final Attribute resAttr : attrs) {
if (resAttr.getFriendlyName().equalsIgnoreCase("defaultFilesQuotas")) {
if (a.getValueAsMap().isEmpty()) {
// null private + default
layoutx.setHTML(rowFilesQuota, 1, "Using default (default: " + SafeHtmlUtils.fromString(convertMapToNiceString(resAttr.getValueAsMap())).asString() + ")");
} else {
// private + default
layoutx.setHTML(rowFilesQuota, 1, SafeHtmlUtils.fromString(convertMapToNiceString(a.getValueAsMap())).asString() + " (default: " + SafeHtmlUtils.fromString(convertMapToNiceString(resAttr.getValueAsMap())).asString() + ")");
}
empty = false;
quotaChangeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.FILES, convertMapToNiceString(a.getValueAsMap()), convertMapToNiceString(resAttr.getValueAsMap())));
}
});
}
}
// if no default found, write down at least private
if (empty) {
if (a.getValueAsMap().isEmpty()) {
layoutx.setHTML(rowFilesQuota, 1, "Using default (default: Not set)");
} else {
layoutx.setHTML(rowFilesQuota, 1, SafeHtmlUtils.fromString(convertMapToNiceString(a.getValueAsMap())).asString() + " (default: Not set)");
}
quotaChangeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.FILES, convertMapToNiceString(a.getValueAsMap()), convertMapToNiceString(new HashMap<String, JSONValue>())));
}
});
}
layoutx.setWidget(rowFilesQuota, 2, quotaChangeButton);
}
});
defaultAttr.setIds(ids);
defaultAttr.retrieveData();
empty = false;
row++;
layoutx.setHTML(row, 1, "Quotas are using \"soft limit : hard limit\" notation and are bound to specific volume.");
layoutx.getFlexCellFormatter().setStyleName(row, 1, "inputFormInlineComment");
layoutx.getFlexCellFormatter().setColSpan(row, 1, 2);
row++;
break;
}
}
for (final Attribute a : attrs) {
if (a.getFriendlyName().equalsIgnoreCase("optOutMailingList")) {
layoutx.setHTML(row, 0, "<strong>Mailing: </strong>");
// find attribute with settings
final CheckBox exclude = new CheckBox("Exclude me from this mailing list");
exclude.setValue(Boolean.parseBoolean(a.getValue()));
final int rowMail = row;
exclude.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (exclude.getValue()) {
a.setValue("true");
} else {
a.setValue(null);
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resource.getId());
ids.put("member", mem.getId());
ArrayList<Attribute> ls = new ArrayList<Attribute>();
ls.add(a);
SetAttributes set = new SetAttributes(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
layoutx.setWidget(rowMail, 1, exclude);
}
@Override
public void onLoadingStart() {
layoutx.setWidget(rowMail, 1, new AjaxLoaderImage(true));
}
@Override
public void onError(PerunError error) {
layoutx.setWidget(rowMail, 1, exclude);
// change back since we were not able to change value in Perun
exclude.setValue(!exclude.getValue());
}
});
set.setAttributes(ids, ls);
}
});
// enable only if opt-out is allowed
if (disableOptOut) {
layoutx.setHTML(row, 1, "Your membership in this mailing list is mandatory.");
} else {
layoutx.setWidget(row, 1, exclude);
}
empty = false;
}
}
if (empty) {
layoutx.setHTML(0, 0, "<strong>No settings available for this resource.</strong>");
layoutx.getFlexCellFormatter().setColSpan(0, 0, 3);
}
}
});
attributes.retrieveData();
}
public void onLoadingStart() {
AjaxLoaderImage loader = new AjaxLoaderImage(true);
layoutx.setWidget(0, 0, loader.loadingStart());
}
public void onError(PerunError error) {
AjaxLoaderImage loader = new AjaxLoaderImage(true);
layoutx.setWidget(0, 0, loader.loadingError(error));
}
});
callMember.retrieveData();
}
Aggregations