use of cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService in project perun by CESNET.
the class CreateFacilityResourceManageServicesTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Create resource: Assign and configure services");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
vp.add(alreadyAdded);
vp.add(new HTML("<hr>"));
// buttons
final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Assign selected service to resource");
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove selected service from resource");
CustomButton finishButton = TabMenu.getPredefinedButton(ButtonType.FINISH, "Finishes services assigning and configuration");
finishButton.setImageAlign(true);
// listbox with services
final ListBoxWithObjects<Service> servicesListbox = new ListBoxWithObjects<Service>();
// checkbox to swith offered services
final CheckBox switchBox = new CheckBox("Show assigned", false);
switchBox.setTitle("Switching between 'all' and 'already assigned' services in menu.");
// fill menu
menu.addWidget(new HTML("<strong>Selected service: </strong>"));
menu.addWidget(servicesListbox);
menu.addWidget(switchBox);
menu.addWidget(assignButton);
menu.addWidget(removeButton);
menu.addWidget(finishButton);
// fill listbox with services (used for both callbacks)
JsonCallbackEvents fillEvents = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<Service> services = JsonUtils.jsoAsList(jso);
services = new TableSorter<Service>().sortByName(services);
servicesListbox.clear();
for (Service serv : services) {
servicesListbox.addItem(serv);
}
if (servicesListbox.isEmpty()) {
servicesListbox.addItem("No service assigned");
if (vp.getWidgetCount() > 3) {
vp.remove(3);
}
return;
}
if (vp.getWidgetCount() > 3) {
vp.remove(3);
}
vp.add(new ResourceSettingsTabItem(resource, servicesListbox.getSelectedObject()).draw());
vp.setCellHeight(vp.getWidget(3), "100%");
}
@Override
public void onError(PerunError error) {
servicesListbox.clear();
servicesListbox.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
servicesListbox.clear();
servicesListbox.addItem("Loading...");
}
};
// callbacks
final GetServices services = new GetServices(fillEvents);
final GetAssignedServices assignedServices = new GetAssignedServices(resource.getId(), fillEvents);
services.retrieveData();
// switching event between services
servicesListbox.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
// remove attributes management if there was
if (vp.getWidgetCount() > 3) {
vp.remove(3);
}
// add attributes management
vp.add(new ResourceSettingsTabItem(resource, servicesListbox.getSelectedObject()).draw());
vp.setCellHeight(vp.getWidget(3), "100%");
}
});
// switching between offered services (assigned - all)
switchBox.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (switchBox.getValue() == false) {
servicesListbox.clear();
services.retrieveData();
} else {
servicesListbox.clear();
assignedServices.retrieveData();
}
}
});
// button events
assignButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (servicesListbox.isEmpty()) {
UiElements.generateInfo("No Service selected", "You must select a service first.");
return;
}
final Service service = servicesListbox.getSelectedObject();
AssignService request = new AssignService(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
alreadyAddedList.add(service);
rebuildAlreadyAddedWidget();
}
}));
request.assignService(service.getId(), resource.getId());
}
});
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (servicesListbox.isEmpty()) {
UiElements.generateInfo("No Service selected", "You must select a service first.");
return;
}
final Service service = servicesListbox.getSelectedObject();
RemoveService request = new RemoveService(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
Iterator<Service> iter = alreadyAddedList.iterator();
while (iter.hasNext()) {
Service s = iter.next();
if (s.getId() == service.getId()) {
iter.remove();
}
}
rebuildAlreadyAddedWidget();
}
}));
request.removeService(servicesListbox.getSelectedObject().getId(), resource.getId());
}
});
final TabItem tab = this;
finishButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab);
}
});
this.contentWidget.setWidget(vp);
rebuildAlreadyAddedWidget();
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService in project perun by CESNET.
the class ResourceAssignedServicesTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": manage assigned services");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
final GetAssignedServices resourceServices = new GetAssignedServices(resourceId);
final JsonCallbackEvents localEvents = JsonCallbackEvents.refreshTableEvents(resourceServices);
CustomButton assignServicesButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.assignServiceToResource(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AssignServiceTabItem(resourceId), true);
}
});
final CustomButton removeServicesButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeServiceFromResource());
removeServicesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<Service> servicesForRemoving = resourceServices.getTableSelectedList();
String text = "Following services will be removed from resource.";
UiElements.showDeleteConfirm(servicesForRemoving, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD USE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < servicesForRemoving.size(); i++) {
if (i == servicesForRemoving.size() - 1) {
RemoveService request = new RemoveService(JsonCallbackEvents.disableButtonEvents(removeServicesButton, localEvents));
request.removeService(servicesForRemoving.get(i).getId(), resourceId);
} else {
RemoveService request = new RemoveService(JsonCallbackEvents.disableButtonEvents(removeServicesButton));
request.removeService(servicesForRemoving.get(i).getId(), resourceId);
}
}
}
});
}
});
menu.addWidget(assignServicesButton);
menu.addWidget(removeServicesButton);
menu.addFilterWidget(new ExtendedSuggestBox(resourceServices.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
resourceServices.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterServices());
// display menu only to facility admin
if (session.isFacilityAdmin(resource.getFacilityId())) {
resourceServices.setCheckable(true);
vp.add(menu);
vp.setCellHeight(menu, "30px");
} else {
resourceServices.setCheckable(false);
}
CellTable<Service> table;
if (session.isPerunAdmin()) {
table = resourceServices.getTable(new FieldUpdater<Service, String>() {
public void update(int index, Service object, String value) {
// load detail only for perun admin
session.getTabManager().addTab(new ServiceDetailTabItem(object));
}
});
} else {
// not clickable
table = resourceServices.getTable();
}
removeServicesButton.setEnabled(false);
JsonUtils.addTableManagedButton(resourceServices, table, removeServicesButton);
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 400, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations