Search in sources :

Example 1 with AssignService

use of cz.metacentrum.perun.webgui.json.resourcesManager.AssignService 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();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JsArray(com.google.gwt.core.client.JsArray) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.webgui.model.Service) AssignService(cz.metacentrum.perun.webgui.json.resourcesManager.AssignService) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) AssignService(cz.metacentrum.perun.webgui.json.resourcesManager.AssignService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Example 2 with AssignService

use of cz.metacentrum.perun.webgui.json.resourcesManager.AssignService 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&nbsp;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();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) AssignService(cz.metacentrum.perun.webgui.json.resourcesManager.AssignService) RemoveService(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Iterator(java.util.Iterator) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) Service(cz.metacentrum.perun.webgui.model.Service) RemoveService(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService) AssignService(cz.metacentrum.perun.webgui.json.resourcesManager.AssignService) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 AssignService (cz.metacentrum.perun.webgui.json.resourcesManager.AssignService)2 GetAssignedServices (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices)2 GetServices (cz.metacentrum.perun.webgui.json.servicesManager.GetServices)2 Service (cz.metacentrum.perun.webgui.model.Service)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 JsArray (com.google.gwt.core.client.JsArray)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 RemoveService (cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1