Search in sources :

Example 6 with GetAssignedServices

use of cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices 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();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.webgui.model.Service) RemoveService(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RemoveService(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)6 GetAssignedServices (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices)6 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)6 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)6 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)5 ArrayList (java.util.ArrayList)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 Service (cz.metacentrum.perun.webgui.model.Service)4 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)4 GetServices (cz.metacentrum.perun.webgui.json.servicesManager.GetServices)3 SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AssignService (cz.metacentrum.perun.webgui.json.resourcesManager.AssignService)2 RemoveService (cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2