use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class AddDependencyTabItem method draw.
public Widget draw() {
// TITLE
titleWidget.setText("Add dependency");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
final ListBoxWithObjects<ExecService> listBox = new ListBoxWithObjects<ExecService>();
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDependantExecService());
// fill listbox after callback finishes
final JsonCallbackEvents localEvents = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
listBox.clear();
ArrayList<ExecService> execs = JsonUtils.jsoAsList(jso);
if (execs != null && !execs.isEmpty()) {
execs = new TableSorter<ExecService>().sortByService(execs);
for (int i = 0; i < execs.size(); i++) {
listBox.addItem(execs.get(i));
if (execService.getService().getName().equals(execs.get(i).getService().getName()) && !execService.getType().equals(execs.get(i).getType())) {
// preselect different type of exec service from same service
listBox.setSelected(execs.get(i), true);
}
}
addButton.setEnabled(true);
} else {
listBox.addItem("No exec service available");
}
}
@Override
public void onLoadingStart() {
listBox.clear();
listBox.addItem("Loading...");
addButton.setEnabled(false);
}
@Override
public void onError(PerunError error) {
listBox.addItem("Error while loading");
addButton.setEnabled(false);
}
};
// callback for all services
ListExecServices callback = new ListExecServices(0, localEvents);
callback.retrieveData();
// layout
layout.setHTML(0, 0, "ExecService:");
layout.setHTML(1, 0, "Depend On:");
layout.setHTML(0, 1, execService.getService().getName() + " " + execService.getType());
layout.setWidget(1, 1, listBox);
final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab);
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
CreateDependency request = new CreateDependency(closeTabEvents);
request.createDependancy(execServiceId, listBox.getSelectedObject().getId());
}
});
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(addButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class ResourceSettingsTabItem method draw.
public Widget draw() {
if (service != null) {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": " + service.getName() + " configuration");
} else {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": service configuration");
}
vp.setSize("100%", "100%");
vp.clear();
// menu
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// callback
final GetRequiredAttributesV2 resAttrs = new GetRequiredAttributesV2();
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
resAttrs.setIds(ids);
final GetAttributesV2 attrs = new GetAttributesV2();
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
resAttrs.setCheckable(false);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
attrs.setCheckable(false);
// puts first table
final CellTable<Attribute> table = resAttrs.getEmptyTable();
final CellTable<Attribute> table2 = attrs.getEmptyTable();
// if for one service only modify empty table message
if (service != null) {
AjaxLoaderImage empty = (AjaxLoaderImage) table.getEmptyTableWidget();
empty.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
AjaxLoaderImage empty2 = (AjaxLoaderImage) table2.getEmptyTableWidget();
empty2.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
}
final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
sp.setWidget(table);
sp2.setWidget(table2);
// switch between assigned and all
final CheckBox chb = new CheckBox();
chb.setText(WidgetTranslation.INSTANCE.offerAvailableServicesOnly());
chb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
// default true
chb.setValue(lastOfferAvailableOnly);
// event which fills the listbox and call getRequiredAttributes
JsonCallbackEvents event = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// clear services list
servList.clear();
// process services
ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
srv = new TableSorter<Service>().sortByName(srv);
for (int i = 0; i < srv.size(); i++) {
// fill listbox
servList.addItem(srv.get(i));
}
if (servList.isEmpty()) {
servList.addNotSelectedOption();
lastSelectedService = 0;
indexInList = 0;
attrs.retrieveData();
setTable(false);
return;
}
if (lastSelectedService == 0 && chb.getValue() == true) {
servList.addNotSelectedOption();
servList.addAllOption();
if (indexInList == 0) {
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
} else if (indexInList == 1) {
servList.setSelectedIndex(1);
}
} else if (lastSelectedService == 0 && chb.getValue() == false) {
servList.addNotSelectedOption();
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
} else if (lastSelectedService != 0) {
if (chb.getValue() == true) {
servList.addNotSelectedOption();
servList.addAllOption();
} else {
servList.addNotSelectedOption();
}
// remove last service, we can't be sure it was loaded again
ids.remove("service");
// either all or specific service
servList.setSelectedIndex(1);
for (Service s : servList.getAllObjects()) {
if (s.getId() == lastSelectedService) {
// service selected last time was found in a list
servList.setSelected(s, true);
ids.put("service", s.getId());
break;
}
}
}
// make call
resAttrs.clearTable();
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
@Override
public void onError(PerunError error) {
servList.clear();
servList.addItem("Error while loading");
if (required) {
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
} else {
((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
}
}
@Override
public void onLoadingStart() {
servList.removeAllOption();
servList.removeNotSelectedOption();
servList.clear();
servList.addItem("Loading...");
}
};
final GetAssignedServices services = new GetAssignedServices(resourceId, event);
final GetServices allServices = new GetServices(event);
// offer services selection
if (serviceId == 0) {
// services listbox
servList.setTitle("Services");
attrs.setIds(ids);
// on change of service update table
servList.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
// if service selected
if (servList.getSelectedIndex() == 0) {
attrs.retrieveData();
setTable(false);
lastSelectedService = 0;
indexInList = 0;
return;
} else if (chb.getValue() == true && servList.getSelectedIndex() == 1) {
ids.remove("service");
lastSelectedService = 0;
indexInList = 1;
} else if ((chb.getValue() == true && servList.getSelectedIndex() > 1) || (chb.getValue() == false && servList.getSelectedIndex() > 0)) {
ids.put("service", servList.getSelectedObject().getId());
lastSelectedService = servList.getSelectedObject().getId();
}
lastOfferAvailableOnly = chb.getValue();
resAttrs.clearTable();
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
});
if (chb.getValue() == false) {
allServices.retrieveData();
} else {
services.retrieveData();
}
} else {
// retrieve data for selected service only
lastSelectedService = serviceId;
lastOfferAvailableOnly = chb.getValue();
ids.put("service", serviceId);
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
// refresh table event - refresh only on finished / on error keep selected
final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resAttrs);
final JsonCallbackEvents refreshTable2 = JsonCallbackEvents.refreshTableEvents(attrs);
// add save changes to menu
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
menu.addWidget(saveChangesButton);
// set button disable event
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable2);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
saveChangesButton.setEnabled(false);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getTableSelectedList();
} else {
list = attrs.getTableSelectedList();
}
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
request.setAttributes(ids, list);
}
}
});
// add set new to menu
CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getList();
} else {
list = attrs.getList();
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, list), true);
}
});
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
setNewAttributeButton.setEnabled(false);
if (service == null) {
menu.addWidget(setNewAttributeButton);
}
// fill button
final CustomButton fillDefaultButton = TabMenu.getPredefinedButton(ButtonType.FILL, ButtonTranslation.INSTANCE.fillResourceAttributes());
menu.addWidget(fillDefaultButton);
// remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
// remove button event
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable2);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
removeButton.setEnabled(false);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getTableSelectedList();
} else {
list = attrs.getTableSelectedList();
}
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(removeButton);
// add service selection to menu and switcher
if (serviceId == 0) {
menu.addWidget(new HTML("<strong>Selected service: </strong>"));
menu.addWidget(servList);
menu.addWidget(chb);
}
// checkbox switcher on click
chb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (chb.getValue() == false) {
lastOfferAvailableOnly = false;
allServices.retrieveData();
} else {
lastOfferAvailableOnly = true;
services.retrieveData();
}
}
});
fillDefaultButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// automatically try to fill all attributes
ArrayList<Attribute> prepareList = new ArrayList<Attribute>();
if (required) {
prepareList = resAttrs.getTableSelectedList();
} else {
prepareList = attrs.getTableSelectedList();
}
final ArrayList<Attribute> list = prepareList;
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
FillAttributes request = new FillAttributes(JsonCallbackEvents.disableButtonEvents(fillDefaultButton, new JsonCallbackEvents() {
boolean wasRequiredTable = required;
@Override
public void onFinished(JavaScriptObject jso) {
// remove attribute from original table and put new ones
ArrayList<Attribute> newList = JsonUtils.jsoAsList(jso);
for (Attribute a : newList) {
for (Attribute oldA : list) {
// deselect old
if (a.getId() == oldA.getId()) {
if (wasRequiredTable) {
resAttrs.getSelectionModel().setSelected(oldA, false);
resAttrs.removeFromTable(oldA);
} else {
attrs.getSelectionModel().setSelected(oldA, false);
attrs.removeFromTable(oldA);
}
}
}
if (wasRequiredTable) {
// add new
resAttrs.addToTable(a);
// select returned
resAttrs.getSelectionModel().setSelected(a, true);
} else {
// add new
attrs.addToTable(a);
// select returned
attrs.getSelectionModel().setSelected(a, true);
}
}
if (wasRequiredTable) {
resAttrs.sortTable();
} else {
attrs.sortTable();
}
}
}));
request.fillAttributes(ids, list);
}
}
});
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
fillDefaultButton.setEnabled(false);
/* TODO - not implemented
Button checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon());
menu.addWidget(checkValuesButton);
checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");
checkValuesButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("not yet implemented");
}
});
*/
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);
// default is required attributes
setTable(true);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class CreateFacilityResourceTabItem method draw.
public Widget draw() {
titleWidget.setText("Create resource");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// form inputs
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
final TextBox descriptionTextBox = new TextBox();
final ListBoxWithObjects<VirtualOrganization> vosDropDown = new ListBoxWithObjects<VirtualOrganization>();
// send button
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createResource());
// local events fills the listbox of Vos and Slds
JsonCallbackEvents event = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// fill VOs listbox
vosDropDown.clear();
ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
vos = new TableSorter<VirtualOrganization>().sortByName(vos);
for (VirtualOrganization vo : vos) {
vosDropDown.addItem(vo);
}
if (!vos.isEmpty())
createButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
vosDropDown.clear();
vosDropDown.addItem("Loading...");
createButton.setEnabled(false);
}
@Override
public void onError(PerunError error) {
vosDropDown.clear();
vosDropDown.addItem("Error while loading");
createButton.setEnabled(false);
}
};
// load available VOs
final GetVos vos = new GetVos(event);
vos.setForceAll(true);
vos.retrieveData();
// layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// Add some standard form options
layout.setHTML(0, 0, "On facility:");
layout.setHTML(0, 1, SafeHtmlUtils.fromString((facility.getName() != null) ? facility.getName() : "").asString());
layout.setHTML(1, 0, "For VO:");
layout.setWidget(1, 1, vosDropDown);
layout.setHTML(2, 0, "Name:");
layout.setWidget(2, 1, nameTextBox);
layout.setHTML(3, 0, "Description:");
layout.setWidget(3, 1, descriptionTextBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
layout.setWidth("350px");
TabMenu menu = new TabMenu();
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
nameTextBox.setError("Name can't be empty.");
return false;
}
nameTextBox.setOk();
return true;
}
};
nameTextBox.setValidator(validator);
createButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// loads new tab when creating successful, also disable button
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onLoadingStart() {
(JsonCallbackEvents.disableButtonEvents(createButton)).onLoadingStart();
}
public void onFinished(JavaScriptObject jso) {
(JsonCallbackEvents.disableButtonEvents(createButton)).onFinished(jso);
Resource res = (Resource) jso;
session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceManageServicesTabItem(facility, res), true);
}
public void onError(PerunError error) {
(JsonCallbackEvents.disableButtonEvents(createButton)).onError(error);
}
};
if (validator.validateTextBox()) {
// request
CreateResource request = new CreateResource(localEvents);
request.createResource(nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getText().trim(), facility.getId(), vosDropDown.getSelectedObject().getId());
}
}
});
menu.addWidget(createButton);
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class ResourceMemberSettingsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": member settings");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// menu
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
final ListBoxWithObjects<RichMember> memberListBox = new ListBoxWithObjects<>();
final ListBoxWithObjects<Service> serviceListBox = new ListBoxWithObjects<>();
final ListBoxWithObjects<Group> groupListBox = new ListBoxWithObjects<>();
// load
final Map<String, Integer> ids = new HashMap<String, Integer>();
// to get attributes for all services
final GetResourceRequiredAttributesV2 resReqAttrs = new GetResourceRequiredAttributesV2();
final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2(ids, JsonCallbackEvents.passDataToAnotherCallback(resReqAttrs));
// puts first table
final CellTable<Attribute> table = resReqAttrs.getEmptyTable();
// get groups of member assigned to resource - MEMBER IS SET BEFORE EVERY CALL !
final GetAssignedGroups groups = new GetAssignedGroups(resourceId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
groupListBox.removeNotSelectedOption();
groupListBox.clear();
ArrayList<Group> grp = JsonUtils.jsoAsList(jso);
grp = new TableSorter<Group>().sortByName(grp);
groupListBox.addNotSelectedOption();
groupListBox.addAllItems(grp);
for (Group g : groupListBox.getAllObjects()) {
if (lastSelectedGroup != 0 && g.getId() == lastSelectedGroup)
groupListBox.setSelected(g, true);
}
groupsCallDone = true;
if (lastSelectedService == 0) {
// load resource-required
if (servCallDone && memberCallDone) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("workWithUserAttributes", 1);
resReqAttrs.setIds(ids);
resReqAttrs.retrieveData();
}
} else {
// load resource-service-member
if (servCallDone && memberCallDone) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("service", lastSelectedService);
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
}
}
}
@Override
public void onError(PerunError error) {
groupListBox.removeNotSelectedOption();
groupListBox.clear();
groupListBox.addItem("Error while loading");
groupsCallDone = true;
}
@Override
public void onLoadingStart() {
groupListBox.removeNotSelectedOption();
groupListBox.clear();
groupListBox.addItem("Loading...");
groupsCallDone = false;
}
});
// get assigned members
final GetAssignedRichMembers members = new GetAssignedRichMembers(resourceId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
memberListBox.removeAllOption();
memberListBox.clear();
ArrayList<RichMember> grp = JsonUtils.jsoAsList(jso);
grp = new TableSorter<RichMember>().sortByName(grp);
if (grp == null || grp.isEmpty()) {
memberListBox.addItem("No members assigned");
lastSelectedMember = 0;
((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see member-resource setting.");
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
return;
}
memberListBox.addAllItems(grp);
for (RichMember g : memberListBox.getAllObjects()) {
if (lastSelectedMember != 0 && g.getId() == lastSelectedMember)
memberListBox.setSelected(g, true);
}
memberCallDone = true;
if (memberListBox.getSelectedObject() != null) {
// if resource has members -> they are there throught groups
groups.setMemberId(memberListBox.getSelectedObject().getId());
groups.retrieveData();
}
if (lastSelectedService == 0) {
// load resource-required
if (servCallDone && groupsCallDone) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("workWithUserAttributes", 1);
resReqAttrs.setIds(ids);
resReqAttrs.retrieveData();
}
} else {
// load resource-service-member
if (servCallDone && groupsCallDone) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("service", lastSelectedService);
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
}
}
}
@Override
public void onError(PerunError error) {
memberListBox.removeAllOption();
memberListBox.clear();
memberListBox.addItem("Error while loading");
memberCallDone = true;
}
@Override
public void onLoadingStart() {
memberListBox.removeAllOption();
memberListBox.clear();
memberListBox.addItem("Loading...");
memberCallDone = false;
}
});
members.retrieveData();
GetAssignedServices services = new GetAssignedServices(resourceId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
serviceListBox.removeAllOption();
serviceListBox.clear();
ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
srv = new TableSorter<Service>().sortByName(srv);
if (srv == null || srv.isEmpty()) {
serviceListBox.addItem("No services assigned");
lastSelectedService = 0;
((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see member-resource setting.");
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
return;
}
serviceListBox.addAllItems(srv);
serviceListBox.addAllOption();
if (lastSelectedService == 0)
serviceListBox.setSelectedIndex(0);
for (Service s : serviceListBox.getAllObjects()) {
if (lastSelectedService != 0 && s.getId() == lastSelectedService)
serviceListBox.setSelected(s, true);
}
servCallDone = true;
if (lastSelectedService == 0) {
if (memberCallDone && groupsCallDone) {
// load resource-required
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("workWithUserAttributes", 1);
resReqAttrs.setIds(ids);
resReqAttrs.retrieveData();
}
} else {
if (memberCallDone && groupsCallDone) {
// load resource-service-member
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("service", lastSelectedService);
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
}
}
}
@Override
public void onError(PerunError error) {
serviceListBox.removeAllOption();
serviceListBox.clear();
serviceListBox.addItem("Error while loading");
servCallDone = true;
}
@Override
public void onLoadingStart() {
serviceListBox.removeAllOption();
serviceListBox.clear();
serviceListBox.addItem("Loading...");
servCallDone = false;
}
});
services.retrieveData();
ChangeHandler changeHandler = new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (memberCallDone && servCallDone && groupsCallDone) {
if (memberListBox.getSelectedObject() != null) {
lastSelectedMember = memberListBox.getSelectedObject().getId();
} else {
lastSelectedMember = 0;
}
if (serviceListBox.getSelectedIndex() > 0) {
lastSelectedService = serviceListBox.getSelectedObject().getId();
} else {
lastSelectedService = 0;
}
if (groupListBox.getSelectedIndex() > 0) {
lastSelectedGroup = groupListBox.getSelectedObject().getId();
} else {
lastSelectedGroup = 0;
}
if (lastSelectedService == 0) {
// load resource-required
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("workWithUserAttributes", 1);
resReqAttrs.setIds(ids);
resReqAttrs.retrieveData();
} else {
// load resource-service-member
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("service", lastSelectedService);
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
}
}
}
};
serviceListBox.addChangeHandler(changeHandler);
groupListBox.addChangeHandler(changeHandler);
memberListBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (memberCallDone && servCallDone && groupsCallDone) {
if (memberListBox.getSelectedObject() != null) {
// selected member - get groups
lastSelectedMember = memberListBox.getSelectedObject().getId();
groups.setMemberId(lastSelectedMember);
groups.retrieveData();
} else {
// no member in a box -> no group
lastSelectedMember = 0;
lastSelectedGroup = 0;
groupListBox.removeNotSelectedOption();
groupListBox.clear();
groupListBox.addNotSelectedOption();
}
}
}
});
// refresh proper table based on selection
final JsonCallbackEvents refreshTable = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
if (lastSelectedService == 0) {
resReqAttrs.clearTable();
resReqAttrs.retrieveData();
} else {
resReqAttrs.clearTable();
reqAttrs.retrieveData();
}
}
};
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
resReqAttrs.setCheckable(false);
// add save changes to menu
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
menu.addWidget(saveChangesButton);
// set button disable event
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
saveChangesButton.setEnabled(false);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("facility", resource.getFacilityId());
ids.put("member", memberListBox.getSelectedObject().getId());
if (groupListBox.getSelectedIndex() != 0) {
// group is selected
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("user", memberListBox.getSelectedObject().getUserId());
SetAttributes request = new SetAttributes(saveChangesButtonEvent);
request.setAttributes(ids, list);
}
}
});
// add set new to menu
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("resource", resourceId);
ids.put("member", memberListBox.getSelectedObject().getId());
ids.put("user", memberListBox.getSelectedObject().getUserId());
if (groupListBox.getSelectedIndex() != 0) {
ids.put("group", groupListBox.getSelectedObject().getId());
}
ids.put("facility", resource.getFacilityId());
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, resReqAttrs.getList()), true);
}
});
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
setNewAttributeButton.setEnabled(false);
menu.addWidget(setNewAttributeButton);
// remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
// remove button event
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
removeButton.setEnabled(false);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
ids.put("member", memberListBox.getSelectedObject().getId());
ids.put("facility", resource.getFacilityId());
ids.put("user", memberListBox.getSelectedObject().getUserId());
if (groupListBox.getSelectedIndex() != 0) {
ids.put("group", groupListBox.getSelectedObject().getId());
}
RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(removeButton);
// add member selection to menu
menu.addWidget(new HTML("<strong>Selected member: </strong>"));
menu.addWidget(memberListBox);
// add group selection to menu
menu.addWidget(new HTML("<strong>Selected group: </strong>"));
menu.addWidget(groupListBox);
// add service selection to menu
menu.addWidget(new HTML("<strong>Selected service: </strong>"));
menu.addWidget(serviceListBox);
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
vp.add(sp);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.
the class SearcherTabItem method loadMembersTab.
private Widget loadMembersTab() {
// request
final GetMembers request = new GetMembers(0);
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
PerunSearchParametersWidget params = new PerunSearchParametersWidget(PerunEntity.MEMBER, new PerunSearchParametersWidget.SearchEvent() {
public void search(Map<String, String> map) {
request.clearParameters();
for (Map.Entry<String, String> entry : map.entrySet()) {
request.addSearchParameter(entry.getKey(), entry.getValue());
}
request.search();
}
});
final ListBoxWithObjects<VirtualOrganization> vos = new ListBoxWithObjects<VirtualOrganization>();
vos.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
request.setVoId(vos.getSelectedObject().getId());
}
});
// initial fill listbox and trigger groups loading
GetVos vosCall = new GetVos(new JsonCallbackEvents() {
public void onLoadingStart() {
vos.clear();
vos.addItem("Loading...");
}
public void onFinished(JavaScriptObject jso) {
vos.clear();
ArrayList<VirtualOrganization> returnedVos = JsonUtils.jsoAsList(jso);
returnedVos = new TableSorter<VirtualOrganization>().sortByName(returnedVos);
if (returnedVos == null || returnedVos.isEmpty()) {
vos.addItem("No VO available");
return;
}
vos.addAllItems(returnedVos);
request.setVoId(vos.getSelectedObject().getId());
}
public void onError(PerunError error) {
vos.clear();
vos.addItem("Error while loading");
}
});
vosCall.retrieveData();
TabMenu menu = new TabMenu();
menu.addWidget(new HTML("<strong>Selected VO:</strong>"));
menu.addWidget(vos);
firstTabPanel.add(menu);
firstTabPanel.add(params);
// get the table
final CellTable<Member> table = request.getEmptyTable(new FieldUpdater<Member, String>() {
public void update(int index, Member object, String value) {
// opens the tab
session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), object.getSourceGroupId()));
}
});
// 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");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
return firstTabPanel;
}
Aggregations