Search in sources :

Example 16 with Service

use of cz.metacentrum.perun.webgui.model.Service 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();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) DeleteService(cz.metacentrum.perun.webgui.json.servicesManager.DeleteService) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.webgui.model.Service) DeleteService(cz.metacentrum.perun.webgui.json.servicesManager.DeleteService) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Example 17 with Service

use of cz.metacentrum.perun.webgui.model.Service 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();
            AssignServices request = new AssignServices(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();
            RemoveServices request = new RemoveServices(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) AssignServices(cz.metacentrum.perun.webgui.json.resourcesManager.AssignServices) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) RemoveServices(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveServices) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) 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) 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)

Example 18 with Service

use of cz.metacentrum.perun.webgui.model.Service in project perun by CESNET.

the class GetServicesFromServicesPackage method setList.

public void setList(ArrayList<Service> list) {
    clearTable();
    this.list.addAll(list);
    for (Service s : list) {
        oracle.add(s.getName());
    }
    dataProvider.flush();
    dataProvider.refresh();
}
Also used : Service(cz.metacentrum.perun.webgui.model.Service)

Example 19 with Service

use of cz.metacentrum.perun.webgui.model.Service in project perun by CESNET.

the class GetServices method setList.

public void setList(ArrayList<Service> list) {
    clearTable();
    this.list.addAll(list);
    for (Service s : list) {
        oracle.add(s.getName());
    }
    dataProvider.flush();
    dataProvider.refresh();
}
Also used : Service(cz.metacentrum.perun.webgui.model.Service)

Example 20 with Service

use of cz.metacentrum.perun.webgui.model.Service in project perun by CESNET.

the class GetServicesByAttrDefinition method filterTable.

@Override
public void filterTable(String filter) {
    // store list only for first time
    if (backupList.isEmpty() || backupList == null) {
        backupList.addAll(list);
    }
    // always clear selected items
    selectionModel.clear();
    list.clear();
    if (filter.equalsIgnoreCase("")) {
        list.addAll(backupList);
    } else {
        for (Service s : backupList) {
            // store facility by filter
            if (s.getName().toLowerCase().startsWith(filter.toLowerCase())) {
                list.add(s);
            }
        }
    }
    dataProvider.flush();
    dataProvider.refresh();
    loaderImage.loadingFinished();
}
Also used : Service(cz.metacentrum.perun.webgui.model.Service)

Aggregations

Service (cz.metacentrum.perun.webgui.model.Service)21 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)11 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)10 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)10 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)10 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)10 ArrayList (java.util.ArrayList)9 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)8 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)7 GetServices (cz.metacentrum.perun.webgui.json.servicesManager.GetServices)6 PerunError (cz.metacentrum.perun.webgui.model.PerunError)6 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 GetAssignedServices (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices)4 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)4 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)2 ConvertAttributeToUnique (cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique)2 GetAttributeRights (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights)2 SetAttributeRights (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights)2 UpdateAttribute (cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute)2