use of cz.metacentrum.perun.webgui.json.servicesManager.GetServices in project perun by CESNET.
the class AssignServiceTabItem method draw.
public Widget draw() {
titleWidget.setText("Assign service");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// menu
TabMenu menu = new TabMenu();
final GetServices services = new GetServices();
final CellTable<Service> table = services.getEmptyTable(new FieldUpdater<Service, String>() {
public void update(int index, Service object, String value) {
session.getTabManager().addTab(new ResourceSettingsTabItem(resource, object));
}
});
// remove already assigned services from offering
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// second callback
final GetAssignedServices alreadyAssigned = new GetAssignedServices(resourceId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
JsArray<Service> srvToRemove = JsonUtils.jsoAsArray(jso);
for (int i = 0; i < srvToRemove.length(); i++) {
services.removeFromTable(srvToRemove.get(i));
}
if (services.getList().size() == 1) {
table.getSelectionModel().setSelected(services.getList().get(0), true);
}
}
});
alreadyAssigned.retrieveData();
}
};
services.setEvents(localEvents);
final TabItem tab = this;
// button
final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedServicesToResource());
assignButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Service> servicesToAssign = services.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(servicesToAssign)) {
for (int i = 0; i < servicesToAssign.size(); i++) {
if (i != servicesToAssign.size() - 1) {
// call json normaly
AssignService request = new AssignService(JsonCallbackEvents.disableButtonEvents(assignButton));
request.assignService(servicesToAssign.get(i).getId(), resourceId);
} else {
// last change - call json with update
AssignService request = new AssignService(JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
request.assignService(servicesToAssign.get(i).getId(), resourceId);
}
}
}
}
});
menu.addWidget(assignButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
menu.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
services.filterTable(text);
if (services.getList().size() == 1) {
table.getSelectionModel().setSelected(services.getList().get(0), true);
}
}
}, "Filter services by name");
vp.add(menu);
vp.setCellHeight(menu, "30px");
services.retrieveData();
assignButton.setEnabled(false);
JsonUtils.addTableManagedButton(services, table, assignButton);
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.servicesManager.GetServices 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.json.servicesManager.GetServices in project perun by CESNET.
the class ServicePackageDetailTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(servicesPackage.getName()) + ": assigned services");
// create widget for the whole page
HorizontalPanel mainTab = new HorizontalPanel();
mainTab.setSize("100%", "100%");
// get services
final GetServices services = new GetServices();
final GetServicesFromServicesPackage assignedServices = new GetServicesFromServicesPackage(servicePackageId);
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(services);
final JsonCallbackEvents events2 = JsonCallbackEvents.refreshTableEvents(assignedServices);
// get the table of services with custom field updater (lines are clickable and open service details)
CellTable<Service> table = services.getTable(new FieldUpdater<Service, String>() {
// when user click on a row -> open new tab
public void update(int index, Service object, String value) {
session.getTabManager().addTab(new ServiceDetailTabItem(object));
}
});
// get the table of services with custom field updater (lines are clickable and open service details)
CellTable<Service> table2 = assignedServices.getTable(new FieldUpdater<Service, String>() {
// when user click on a row -> open new tab
public void update(int index, Service object, String value) {
session.getTabManager().addTab(new ServiceDetailTabItem(object));
}
});
// add styling to table with services
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
VerticalPanel vp1 = new VerticalPanel();
vp1.setSize("100%", "100%");
TabMenu menu1 = new TabMenu();
menu1.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
services.filterTable(text);
}
}, "Filter services by name");
vp1.add(menu1);
vp1.setCellHeight(menu1, "30px");
vp1.add(sp);
mainTab.add(vp1);
mainTab.setCellWidth(vp1, "50%");
// middle content
final CustomButton add = new CustomButton("Add", "Add services to package", SmallIcons.INSTANCE.arrowRightIcon());
add.setImageAlign(true);
add.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Service> list = services.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < list.size(); i++) {
AddServiceToServicesPackage request;
final int ii = i;
if (i == list.size() - 1) {
request = new AddServiceToServicesPackage(JsonCallbackEvents.disableButtonEvents(add, JsonCallbackEvents.mergeEvents(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
services.getSelectionModel().setSelected(list.get(ii), false);
}
}, events2)));
} else {
request = new AddServiceToServicesPackage(JsonCallbackEvents.disableButtonEvents(add, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
services.getSelectionModel().setSelected(list.get(ii), false);
}
}));
}
request.addServiceToServicesPackage(servicePackageId, list.get(i).getId());
}
}
}
});
final CustomButton remove = new CustomButton("Remove", "Remove services from package", SmallIcons.INSTANCE.arrowLeftIcon());
remove.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ArrayList<Service> list = assignedServices.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < list.size(); i++) {
RemoveServiceFromServicesPackage request;
if (i == list.size() - 1) {
request = new RemoveServiceFromServicesPackage(JsonCallbackEvents.disableButtonEvents(remove, events2));
} else {
request = new RemoveServiceFromServicesPackage(JsonCallbackEvents.disableButtonEvents(remove));
}
request.removeServiceFromServicesPackage(servicePackageId, list.get(i).getId());
}
}
}
});
final TabItem tab = this;
CustomButton close = TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab);
}
});
FlexTable ft = new FlexTable();
ft.setWidget(0, 0, add);
ft.setWidget(1, 0, remove);
ft.setWidget(2, 0, close);
ft.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
ft.getFlexCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
ft.getFlexCellFormatter().setAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
ft.setWidth("130px");
ft.setCellSpacing(10);
mainTab.add(ft);
mainTab.setCellVerticalAlignment(ft, HasVerticalAlignment.ALIGN_MIDDLE);
// add styling to table2 with assigned services
table2.addStyleName("perun-table");
ScrollPanel sp2 = new ScrollPanel(table2);
sp2.addStyleName("perun-tableScrollPanel");
VerticalPanel vp2 = new VerticalPanel();
vp2.setSize("100%", "100%");
TabMenu menu2 = new TabMenu();
menu2.addFilterWidget(new ExtendedSuggestBox(assignedServices.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
assignedServices.filterTable(text);
}
}, "Filter services by name");
vp2.add(menu2);
vp2.setCellHeight(menu2, "30px");
vp2.add(sp2);
mainTab.add(vp2);
mainTab.setCellWidth(vp2, "50%");
add.setEnabled(false);
JsonUtils.addTableManagedButton(services, table, add);
remove.setEnabled(false);
JsonUtils.addTableManagedButton(assignedServices, table2, remove);
session.getUiElements().resizeSmallTabPanel(mainTab, 350, this);
session.getUiElements().resizePerunTable(sp, 350, this);
session.getUiElements().resizePerunTable(sp2, 350, this);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.servicesManager.GetServices 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.servicesManager.GetServices in project perun by CESNET.
the class ServicesTabItem method draw.
public Widget draw() {
// create widget for the whole page
VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
// create widget for menu on page
TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(UiElements.getRefreshButton(this));
// get services
final GetServices services = new GetServices();
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(services);
// get the table of services with custom field updater (lines are clickable and open service details)
CellTable<Service> table = services.getTable(new FieldUpdater<Service, String>() {
// when user click on a row -> open new tab
public void update(int index, Service object, String value) {
session.getTabManager().addTab(new ServiceDetailTabItem(object));
}
});
// create button
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createService(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new CreateServiceTabItem());
}
}));
final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteSelectedServices());
deleteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// get selected items
final ArrayList<Service> itemsToRemove = services.getTableSelectedList();
UiElements.showDeleteConfirm(itemsToRemove, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < itemsToRemove.size(); i++) {
DeleteService request;
if (i == itemsToRemove.size() - 1) {
request = new DeleteService(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
} else {
request = new DeleteService(JsonCallbackEvents.disableButtonEvents(deleteButton));
}
request.deleteService(itemsToRemove.get(i).getId());
}
}
});
}
});
tabMenu.addWidget(deleteButton);
tabMenu.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
services.filterTable(text);
}
}, "Filter services by name");
// add menu to page itself
mainTab.add(tabMenu);
mainTab.setCellHeight(tabMenu, "30px");
// add styling to table with services
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
mainTab.add(sp);
deleteButton.setEnabled(false);
JsonUtils.addTableManagedButton(services, table, deleteButton);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
Aggregations