Search in sources :

Example 1 with ServiceDetailTabItem

use of cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem 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);
    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, 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 ((!def.getDescription().equals(description.getTextBox().getText().trim()) || !def.getDisplayName().equals(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);
    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>VO</strong>");
    rightsTable.setHTML(0, 3, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 4, "<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, voRead);
    rightsTable.setWidget(2, 2, voWrite);
    rightsTable.setWidget(1, 3, groupRead);
    rightsTable.setWidget(2, 3, groupWrite);
    rightsTable.setWidget(1, 4, facilityRead);
    rightsTable.setWidget(2, 4, 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, false);
        }
    }));
    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, 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) 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) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) GetServicesByAttrDefinition(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition)

Example 2 with ServiceDetailTabItem

use of cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem 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)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 Service (cz.metacentrum.perun.webgui.model.Service)2 ServiceDetailTabItem (cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 ArrayList (java.util.ArrayList)2 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 GetAttributeRights (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights)1 SetAttributeRights (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights)1 UpdateAttribute (cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute)1 GetAssignedServices (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices)1 RemoveService (cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService)1 GetServicesByAttrDefinition (cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition)1 AttributeRights (cz.metacentrum.perun.webgui.model.AttributeRights)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1