Search in sources :

Example 11 with Service

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

Example 12 with Service

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

the class GetRequiredAttributesV2 method retrieveData.

/**
 * Retrieves data from the RPC
 */
public void retrieveData() {
    String params = "";
    // serialize parameters
    for (Map.Entry<String, Integer> attr : this.ids.entrySet()) {
        params += attr.getKey() + "=" + attr.getValue() + "&";
    }
    // serialize services
    if (servicesToGetAttributesFor != null && !servicesToGetAttributesFor.isEmpty()) {
        for (Service s : servicesToGetAttributesFor) {
            params += "services[]=" + s.getId() + "&";
        }
    }
    if (params.endsWith("&")) {
        params = params.substring(0, params.length() - 1);
    }
    JsonClient js = new JsonClient();
    js.retrieveData(GetRequiredAttributesV2.JSON_URL, params, this);
}
Also used : Service(cz.metacentrum.perun.webgui.model.Service)

Example 13 with Service

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

the class AddFacilityDestinationTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add destination");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    layout.setWidth("350px");
    final ExtendedSuggestBox destination = new ExtendedSuggestBox();
    final ListBox type = new ListBox();
    type.addItem("HOST", "host");
    type.addItem("USER@HOST", "user@host");
    type.addItem("USER@HOST:PORT", "user@host:port");
    type.addItem("USER@HOST-WINDOWS", "user@host-windows");
    type.addItem("HOST-WINDOWS-PROXY", "host-windows-proxy");
    type.addItem("URL", "url");
    type.addItem("MAIL", "email");
    type.addItem("SIGNED MAIL", "semail");
    type.addItem("SERVICE SPECIFIC", "service-specific");
    final ListBox propTypeSelect = new ListBox();
    propTypeSelect.addItem("PARALLEL");
    propTypeSelect.addItem("DUMMY");
    // propTypeSelect.addItem("SERIAL"); TODO - will we ever use it ?
    final HTML propTypeHelp = new HTML("PARALLEL - Data for all destinations of one service are pushed in parallel.");
    final ListBoxWithObjects<Service> services = new ListBoxWithObjects<Service>();
    final CheckBox useHosts = new CheckBox(WidgetTranslation.INSTANCE.useFacilityHostnames(), false);
    useHosts.setTitle(WidgetTranslation.INSTANCE.useFacilityHostnamesTitle());
    final CheckBox onlyAssignedServices = new CheckBox("Show only services on facility", false);
    onlyAssignedServices.setTitle("Click to show all possible services");
    onlyAssignedServices.setValue(true);
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDestination());
    // fill oracle with hosts of facility
    GetHosts getHosts = new GetHosts(facilityId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<Host> ho = JsonUtils.jsoAsList(jso);
            for (Host h : ho) {
                hosts.addAll(ho);
                destination.getSuggestOracle().add(h.getName());
            }
        }
    });
    getHosts.retrieveData();
    JsonCallbackEvents fillAssignedServices = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            services.removeAllOption();
            services.clear();
            ArrayList<Service> ses = JsonUtils.jsoAsList(jso);
            if (ses != null && !ses.isEmpty()) {
                ses = new TableSorter<Service>().sortByName(ses);
                services.addAllItems(ses);
                services.addAllOption();
                services.setSelectedIndex(0);
            } else {
                services.addItem("No service available");
            }
            addButton.setEnabled(true);
            type.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            services.removeAllOption();
            services.clear();
            services.addItem("Error while loading");
            addButton.setEnabled(true);
            type.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            services.removeAllOption();
            services.clear();
            services.addItem("Loading...");
            addButton.setEnabled(false);
            type.setEnabled(false);
        }
    };
    final GetFacilityAssignedServices getAssignedServices = new GetFacilityAssignedServices(facility.getId(), fillAssignedServices);
    getAssignedServices.retrieveData();
    final GetServices getAllServices = new GetServices(fillAssignedServices);
    onlyAssignedServices.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            if (onlyAssignedServices.getValue() == false) {
                onlyAssignedServices.setTitle("Click to show only services on facility");
                getAllServices.retrieveData();
            } else {
                onlyAssignedServices.setTitle("Click to show all possible services");
                getAssignedServices.retrieveData();
            }
        }
    });
    final Label destinationLabel = new Label();
    destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
    final ExtendedSuggestBox.SuggestBoxValidator validator = new ExtendedSuggestBox.SuggestBoxValidator() {

        @Override
        public boolean validateSuggestBox() {
            if (destination.getSuggestBox().getText().trim().isEmpty() && useHosts.getValue() == false) {
                destination.setError("Destination value can't be empty.");
                return false;
            }
            // check as email
            if (type.getSelectedIndex() > 5 && type.getSelectedIndex() < 8) {
                if (!JsonUtils.isValidEmail(destination.getSuggestBox().getText().trim())) {
                    destination.setError("Not valid email address.");
                    return false;
                } else {
                    destination.setOk();
                    return true;
                }
            }
            destination.setOk();
            return true;
        }
    };
    destination.setValidator(validator);
    type.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            // if hosts - checkbox visible
            if (type.getSelectedIndex() == 0) {
                useHosts.setVisible(true);
            } else {
                useHosts.setVisible(false);
                useHosts.setValue(false);
                destination.getSuggestBox().setEnabled(true);
            }
            if (type.getSelectedIndex() < 5) {
                destination.getSuggestOracle().clear();
                for (Host h : hosts) {
                    destination.getSuggestOracle().add(h.getName());
                }
            } else {
                destination.getSuggestOracle().clear();
            }
            // set label
            if (type.getSelectedIndex() == 0) {
                destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
            } else if (type.getSelectedIndex() == 1) {
                destinationLabel.getElement().setInnerHTML("<strong>User@host:</strong>");
            } else if (type.getSelectedIndex() == 2) {
                destinationLabel.getElement().setInnerHTML("<strong>User@host:port:</strong>");
            } else if (type.getSelectedIndex() == 3) {
                destinationLabel.getElement().setInnerHTML("<strong>User@host-windows:</strong>");
            } else if (type.getSelectedIndex() == 4) {
                destinationLabel.getElement().setInnerHTML("<strong>Host-Windows-Proxy:</strong>");
            } else if (type.getSelectedIndex() == 5) {
                destinationLabel.getElement().setInnerHTML("<strong>URL:</strong>");
            } else if (type.getSelectedIndex() == 6) {
                destinationLabel.getElement().setInnerHTML("<strong>Mail:</strong>");
            } else if (type.getSelectedIndex() == 7) {
                destinationLabel.getElement().setInnerHTML("<strong>Signed mail:</strong>");
            } else if (type.getSelectedIndex() == 8) {
                destinationLabel.getElement().setInnerHTML("<strong>Service specific:</strong>");
            }
            // run validation
            validator.validateSuggestBox();
        }
    });
    useHosts.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (useHosts.getValue() == true) {
                destination.getSuggestBox().setEnabled(false);
                destination.setOk();
                // use only PARALLEL since API doesn't read it
                propTypeSelect.setSelectedIndex(0);
                propTypeHelp.setHTML("PARALLEL - Data for all destinations and one service are pushed in parallel.");
            } else {
                destination.getSuggestBox().setEnabled(true);
            }
        }
    });
    propTypeSelect.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (propTypeSelect.getSelectedIndex() == 0) {
                propTypeHelp.setHTML("PARALLEL - Data for all destinations and one service are pushed in parallel.");
            } else {
                propTypeHelp.setHTML("DUMMY - Service provisioning data is generated by Perun, but not pushed to destination. Destinations can pull data by themselves.");
                // allow to set custom value - can't use facility hosts
                useHosts.setValue(false);
                destination.getSuggestBox().setEnabled(true);
            }
        }
    });
    cellFormatter.setColSpan(0, 0, 2);
    HTML text = new HTML("Please add destinations for service configuration delivery. New service configuration can be performed directly on facility (dest. type HOST) or sent to URL or by an email.");
    text.setStyleName("inputFormInlineComment");
    layout.setWidget(0, 0, text);
    layout.setHTML(1, 0, "Service:");
    layout.setWidget(1, 1, services);
    layout.setWidget(2, 1, onlyAssignedServices);
    layout.setHTML(3, 0, "Type:");
    layout.setWidget(3, 1, type);
    layout.setWidget(4, 0, destinationLabel);
    layout.setWidget(4, 1, destination);
    layout.setWidget(5, 1, useHosts);
    layout.setHTML(6, 0, "Propagation:");
    layout.setWidget(6, 1, propTypeSelect);
    for (int i = 1; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    propTypeHelp.setStyleName("inputFormInlineComment");
    layout.setWidget(7, 0, propTypeHelp);
    cellFormatter.setColSpan(7, 0, 2);
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    menu.addWidget(addButton);
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (services.isEmpty()) {
                // no services available
                addButton.setEnabled(false);
            }
            if (validator.validateSuggestBox()) {
                if (services.getSelectedIndex() == 0) {
                    // selected all
                    if (useHosts.getValue() == true) {
                        // auto by hosts
                        AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab, true));
                        request.addDestinationByHosts(services.getAllObjects());
                    } else {
                        // default
                        AddDestination request = new AddDestination(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab, true));
                        request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getAllObjects(), propTypeSelect.getSelectedValue());
                    }
                } else {
                    // selected one
                    if (useHosts.getValue() == true) {
                        // auto by hosts
                        AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab, true));
                        request.addDestinationByHosts(services.getSelectedObject());
                    } else {
                        // default
                        AddDestination request = new AddDestination(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab, true));
                        request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getSelectedObject(), propTypeSelect.getSelectedValue());
                    }
                }
            }
        }
    });
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) TableSorter(cz.metacentrum.perun.webgui.client.resources.TableSorter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Service(cz.metacentrum.perun.webgui.model.Service) Host(cz.metacentrum.perun.webgui.model.Host) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 14 with Service

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

the class AttributeDefinitionDetailTabItem method draw.

public Widget draw() {
    titleWidget.setText(def.getName());
    final TabItem tab = this;
    // create main panel for content
    final FlexTable mainPage = new FlexTable();
    mainPage.setWidth("100%");
    final ExtendedTextBox description = new ExtendedTextBox();
    description.setWidth("100%");
    description.getTextBox().setText(def.getDescription());
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (description.getTextBox().getText().trim().isEmpty()) {
                description.setError("Description can't be empty.");
                return false;
            }
            description.setOk();
            return true;
        }
    };
    final ExtendedTextBox displayName = new ExtendedTextBox();
    displayName.setWidth("100%");
    displayName.getTextBox().setText(def.getDisplayName());
    final ExtendedTextBox.TextBoxValidator validatorName = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (displayName.getTextBox().getText().trim().isEmpty()) {
                displayName.setError("Display name can't be empty.");
                return false;
            }
            displayName.setOk();
            return true;
        }
    };
    description.setValidator(validator);
    displayName.setValidator(validatorName);
    CheckBox unique = new CheckBox();
    unique.setValue(def.isUnique());
    if (Arrays.asList("core", "virt").contains(def.getDefinition()) || def.getEntity().equals("entityless")) {
        unique.setEnabled(false);
    } else {
        unique.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

            @Override
            public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
                if (valueChangeEvent.getValue()) {
                    UiElements.generateAlert("Change confirmation", "Changing attribute to UNIQUE might take a lot of time if there is large number of entities with set values. Perun will check uniqueness during the process. If values are not unique, conversion will be stopped.<p style=\"color:red;\">We strongly recommend to refresh whole browser window after conversion is DONE to prevent errors when modifying attributes from GUI.", new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            ConvertAttributeToUnique convert = new ConvertAttributeToUnique(new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    unique.setValue(true);
                                    unique.setEnabled(true);
                                    def.setUnique(true);
                                }

                                @Override
                                public void onError(PerunError error) {
                                    unique.setValue(false);
                                    unique.setEnabled(true);
                                    def.setUnique(false);
                                }

                                @Override
                                public void onLoadingStart() {
                                    unique.setEnabled(false);
                                }
                            });
                            convert.convertAttributeDefinitionToUnique(def.getId());
                        }
                    }, new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            // action canceled
                            unique.setValue(false);
                        }
                    });
                } else {
                    ConvertAttributeToNonUnique convert = new ConvertAttributeToNonUnique(new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            unique.setValue(false);
                            unique.setEnabled(true);
                            def.setUnique(false);
                        }

                        @Override
                        public void onError(PerunError error) {
                            unique.setValue(true);
                            unique.setEnabled(true);
                            def.setUnique(true);
                        }

                        @Override
                        public void onLoadingStart() {
                            unique.setEnabled(false);
                        }
                    });
                    convert.convertAttributeDefinitionToNonUnique(def.getId());
                }
            }
        });
    }
    FlexTable attributeDetailTable = new FlexTable();
    attributeDetailTable.setStyleName("inputFormFlexTable");
    final CustomButton updateButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save attribute details");
    updateButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
            for (AttributeRights r : rights) {
                if (r.getRole().equalsIgnoreCase("SELF")) {
                    list.add(getRightsFromWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, r));
                } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                    list.add(getRightsFromWidgets(voRead, voWrite, r));
                } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                    list.add(getRightsFromWidgets(groupRead, groupWrite, r));
                } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                    list.add(getRightsFromWidgets(facilityRead, facilityWrite, r));
                }
            }
            if ((!Objects.equals(def.getDescription(), description.getTextBox().getText().trim()) || !Objects.equals(def.getDisplayName(), displayName.getTextBox().getText().trim()))) {
                if (!validator.validateTextBox() || !validatorName.validateTextBox())
                    return;
                def.setDescription(description.getTextBox().getText().trim());
                def.setDisplayName(displayName.getTextBox().getText().trim());
                UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // after update - update rights
                        SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                enableDisableWidgets(true);
                            }

                            @Override
                            public void onLoadingStart() {
                                enableDisableWidgets(false);
                            }

                            @Override
                            public void onError(PerunError error) {
                                enableDisableWidgets(true);
                            }
                        }));
                        request.setAttributeRights(list);
                    }
                }));
                request.updateAttribute(def);
            } else {
                // after update - update rights
                SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        enableDisableWidgets(true);
                    }

                    @Override
                    public void onLoadingStart() {
                        enableDisableWidgets(false);
                    }

                    @Override
                    public void onError(PerunError error) {
                        enableDisableWidgets(true);
                    }
                }));
                request.setAttributeRights(list);
            }
        }
    });
    attributeDetailTable.setHTML(0, 0, "Display name:");
    attributeDetailTable.setWidget(0, 1, displayName);
    attributeDetailTable.setHTML(1, 0, "Description:");
    attributeDetailTable.setWidget(1, 1, description);
    attributeDetailTable.setHTML(2, 0, "Unique:");
    attributeDetailTable.setWidget(2, 1, unique);
    for (int i = 0; i < attributeDetailTable.getRowCount(); i++) {
        attributeDetailTable.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");
    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>SELF_PUBLIC</strong>");
    rightsTable.setHTML(0, 3, "<strong>SELF_VO</strong>");
    rightsTable.setHTML(0, 4, "<strong>VO</strong>");
    rightsTable.setHTML(0, 5, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 6, "<strong>FACILITY</strong>");
    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, selfReadPublic);
    rightsTable.setWidget(2, 2, selfWritePublic);
    rightsTable.setWidget(1, 3, selfReadVo);
    rightsTable.setWidget(2, 3, selfWriteVo);
    rightsTable.setWidget(1, 4, voRead);
    rightsTable.setWidget(2, 4, voWrite);
    rightsTable.setWidget(1, 5, groupRead);
    rightsTable.setWidget(2, 5, groupWrite);
    rightsTable.setWidget(1, 6, facilityRead);
    rightsTable.setWidget(2, 6, facilityWrite);
    rightsTable.addStyleName("centeredTable");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(updateButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    GetAttributeRights rightsCall = new GetAttributeRights(def.getId(), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            rights = JsonUtils.jsoAsList(jso);
            for (AttributeRights r : rights) {
                if (r.getRole().equalsIgnoreCase("SELF")) {
                    setRightsToWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, r);
                } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                    setRightsToWidgets(voRead, voWrite, r);
                } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                    setRightsToWidgets(groupRead, groupWrite, r);
                } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                    setRightsToWidgets(facilityRead, facilityWrite, r);
                }
            }
            enableDisableWidgets(true);
            rightsTable.setVisible(true);
        }

        @Override
        public void onError(PerunError error) {
            enableDisableWidgets(true);
            rightsTable.setVisible(false);
        }

        @Override
        public void onLoadingStart() {
            enableDisableWidgets(false);
            rightsTable.setVisible(false);
        }
    });
    rightsCall.retrieveData();
    // create new instance for jsonCall
    final GetServicesByAttrDefinition services = new GetServicesByAttrDefinition(def.getId());
    services.setCheckable(false);
    CellTable<Service> attrDefTable = services.getTable(new FieldUpdater<Service, String>() {

        @Override
        public void update(int index, Service object, String value) {
            session.getTabManager().addTab(new ServiceDetailTabItem(object));
        }
    });
    attrDefTable.setStyleName("perun-table");
    ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
    scrollTable.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(scrollTable, 350, this);
    // set content to page
    mainPage.setWidget(0, 0, menu);
    mainPage.getFlexCellFormatter().setColSpan(0, 0, 2);
    mainPage.setWidget(1, 0, attributeDetailTable);
    mainPage.setWidget(1, 1, rightsTable);
    mainPage.getFlexCellFormatter().setWidth(1, 0, "50%");
    mainPage.getFlexCellFormatter().setWidth(1, 1, "50%");
    HTML title = new HTML("<p>Required by service</p>");
    title.setStyleName("subsection-heading");
    mainPage.setWidget(2, 0, title);
    mainPage.getFlexCellFormatter().setColSpan(2, 0, 2);
    // put page into scroll panel
    mainPage.setWidget(3, 0, scrollTable);
    mainPage.getFlexCellFormatter().setColSpan(3, 0, 2);
    mainPage.getFlexCellFormatter().setHeight(3, 0, "100%");
    this.contentWidget.setWidget(mainPage);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) UpdateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) ArrayList(java.util.ArrayList) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) ConvertAttributeToNonUnique(cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToNonUnique) Service(cz.metacentrum.perun.webgui.model.Service) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ConvertAttributeToUnique(cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) GetServicesByAttrDefinition(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition)

Example 15 with Service

use of cz.metacentrum.perun.webgui.model.Service 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) {
                    RemoveServices request = new RemoveServices(JsonCallbackEvents.disableButtonEvents(removeServicesButton, localEvents));
                    request.removeServices(resourceId, servicesForRemoving);
                }
            });
        }
    });
    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) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) RemoveServices(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveServices) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

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