Search in sources :

Example 86 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class ResourceMemberSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": member settings");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final ListBoxWithObjects<RichMember> memberListBox = new ListBoxWithObjects<>();
    final ListBoxWithObjects<Service> serviceListBox = new ListBoxWithObjects<>();
    // load
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    // to get attributes for all services
    final GetResourceRequiredAttributesV2 resReqAttrs = new GetResourceRequiredAttributesV2();
    final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2(ids, JsonCallbackEvents.passDataToAnotherCallback(resReqAttrs));
    // puts first table
    final CellTable<Attribute> table = resReqAttrs.getEmptyTable();
    // get assigned members
    final GetAssignedRichMembers members = new GetAssignedRichMembers(resourceId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            memberListBox.removeAllOption();
            memberListBox.clear();
            ArrayList<RichMember> grp = JsonUtils.jsoAsList(jso);
            grp = new TableSorter<RichMember>().sortByName(grp);
            if (grp == null || grp.isEmpty()) {
                memberListBox.addItem("No members assigned");
                lastSelectedMember = 0;
                ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see member-resource setting.");
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                return;
            }
            memberListBox.addAllItems(grp);
            for (RichMember g : memberListBox.getAllObjects()) {
                if (lastSelectedMember != 0 && g.getId() == lastSelectedMember)
                    memberListBox.setSelected(g, true);
            }
            memberCallDone = true;
            if (lastSelectedService == 0) {
                // load resource-required
                if (servCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                // load resource-service-member
                if (servCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            memberListBox.removeAllOption();
            memberListBox.clear();
            memberListBox.addItem("Error while loading");
            memberCallDone = true;
        }

        @Override
        public void onLoadingStart() {
            memberListBox.removeAllOption();
            memberListBox.clear();
            memberListBox.addItem("Loading...");
            memberCallDone = false;
        }
    });
    members.retrieveData();
    GetAssignedServices services = new GetAssignedServices(resourceId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            if (srv == null || srv.isEmpty()) {
                serviceListBox.addItem("No services assigned");
                lastSelectedService = 0;
                ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see member-resource setting.");
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                return;
            }
            serviceListBox.addAllItems(srv);
            serviceListBox.addAllOption();
            if (lastSelectedService == 0)
                serviceListBox.setSelectedIndex(0);
            for (Service s : serviceListBox.getAllObjects()) {
                if (lastSelectedService != 0 && s.getId() == lastSelectedService)
                    serviceListBox.setSelected(s, true);
            }
            servCallDone = true;
            if (lastSelectedService == 0) {
                if (memberCallDone) {
                    // load resource-required
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                if (memberCallDone) {
                    // load resource-service-member
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            serviceListBox.addItem("Error while loading");
            servCallDone = true;
        }

        @Override
        public void onLoadingStart() {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            serviceListBox.addItem("Loading...");
            servCallDone = false;
        }
    });
    services.retrieveData();
    ChangeHandler changeHandler = new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (memberCallDone && servCallDone) {
                if (memberListBox.getSelectedObject() != null) {
                    lastSelectedMember = memberListBox.getSelectedObject().getId();
                } else {
                    lastSelectedMember = 0;
                }
                if (serviceListBox.getSelectedIndex() > 0) {
                    lastSelectedService = serviceListBox.getSelectedObject().getId();
                } else {
                    lastSelectedService = 0;
                }
                if (lastSelectedService == 0) {
                    // load resource-required
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                } else {
                    // load resource-service-member
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }
    };
    memberListBox.addChangeHandler(changeHandler);
    serviceListBox.addChangeHandler(changeHandler);
    final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resReqAttrs);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        resReqAttrs.setCheckable(false);
    // add save changes to menu
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(saveChangesButton);
    // set button disable event
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                ids.put("member", memberListBox.getSelectedObject().getId());
                ids.put("workWithUserAttributes", 1);
                SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    // add set new to menu
    CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("resource", resourceId);
            ids.put("member", memberListBox.getSelectedObject().getId());
            ids.put("user", memberListBox.getSelectedObject().getUserId());
            ids.put("facility", resource.getFacilityId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, resReqAttrs.getList()), true);
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        setNewAttributeButton.setEnabled(false);
    menu.addWidget(setNewAttributeButton);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        removeButton.setEnabled(false);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                ids.put("member", memberListBox.getSelectedObject().getId());
                ids.put("facility", resource.getFacilityId());
                ids.put("user", memberListBox.getSelectedObject().getUserId());
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add member selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;member: </strong>"));
    menu.addWidget(memberListBox);
    // add service selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
    menu.addWidget(serviceListBox);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetAssignedRichMembers(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedRichMembers) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 87 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class ResourceSettingsTabItem method draw.

public Widget draw() {
    if (service != null) {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": " + service.getName() + " configuration");
    } else {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": service configuration");
    }
    vp.setSize("100%", "100%");
    vp.clear();
    // menu
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    // callback
    final GetRequiredAttributesV2 resAttrs = new GetRequiredAttributesV2();
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resource", resourceId);
    resAttrs.setIds(ids);
    final GetAttributesV2 attrs = new GetAttributesV2();
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        resAttrs.setCheckable(false);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        attrs.setCheckable(false);
    // puts first table
    final CellTable<Attribute> table = resAttrs.getEmptyTable();
    final CellTable<Attribute> table2 = attrs.getEmptyTable();
    // if for one service only modify empty table message
    if (service != null) {
        AjaxLoaderImage empty = (AjaxLoaderImage) table.getEmptyTableWidget();
        empty.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
        AjaxLoaderImage empty2 = (AjaxLoaderImage) table2.getEmptyTableWidget();
        empty2.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
    }
    final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
    sp.setWidget(table);
    sp2.setWidget(table2);
    // switch between assigned and all
    final CheckBox chb = new CheckBox();
    chb.setText(WidgetTranslation.INSTANCE.offerAvailableServicesOnly());
    chb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
    // default true
    chb.setValue(lastOfferAvailableOnly);
    // event which fills the listbox and call getRequiredAttributes
    JsonCallbackEvents event = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // clear services list
            servList.clear();
            // process services
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            for (int i = 0; i < srv.size(); i++) {
                // fill listbox
                servList.addItem(srv.get(i));
            }
            if (servList.isEmpty()) {
                servList.addNotSelectedOption();
                lastSelectedService = 0;
                indexInList = 0;
                attrs.retrieveData();
                setTable(false);
                return;
            }
            if (lastSelectedService == 0 && chb.getValue() == true) {
                servList.addNotSelectedOption();
                servList.addAllOption();
                if (indexInList == 0) {
                    servList.setSelectedIndex(0);
                    attrs.retrieveData();
                    setTable(false);
                    return;
                } else if (indexInList == 1) {
                    servList.setSelectedIndex(1);
                }
            } else if (lastSelectedService == 0 && chb.getValue() == false) {
                servList.addNotSelectedOption();
                servList.setSelectedIndex(0);
                attrs.retrieveData();
                setTable(false);
                return;
            } else if (lastSelectedService != 0) {
                if (chb.getValue() == true) {
                    servList.addNotSelectedOption();
                    servList.addAllOption();
                } else {
                    servList.addNotSelectedOption();
                }
                // remove last service, we can't be sure it was loaded again
                ids.remove("service");
                // either all or specific service
                servList.setSelectedIndex(1);
                for (Service s : servList.getAllObjects()) {
                    if (s.getId() == lastSelectedService) {
                        // service selected last time was found in a list
                        servList.setSelected(s, true);
                        ids.put("service", s.getId());
                        break;
                    }
                }
            }
            // make call
            resAttrs.clearTable();
            resAttrs.setIds(ids);
            resAttrs.retrieveData();
            setTable(true);
        }

        ;

        @Override
        public void onError(PerunError error) {
            servList.clear();
            servList.addItem("Error while loading");
            if (required) {
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
            } else {
                ((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
            }
        }

        ;

        @Override
        public void onLoadingStart() {
            servList.removeAllOption();
            servList.removeNotSelectedOption();
            servList.clear();
            servList.addItem("Loading...");
        }
    };
    final GetAssignedServices services = new GetAssignedServices(resourceId, event);
    final GetServices allServices = new GetServices(event);
    // offer services selection
    if (serviceId == 0) {
        // services listbox
        servList.setTitle("Services");
        attrs.setIds(ids);
        // on change of service update table
        servList.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                // if service selected
                if (servList.getSelectedIndex() == 0) {
                    attrs.retrieveData();
                    setTable(false);
                    lastSelectedService = 0;
                    indexInList = 0;
                    return;
                } else if (chb.getValue() == true && servList.getSelectedIndex() == 1) {
                    ids.remove("service");
                    lastSelectedService = 0;
                    indexInList = 1;
                } else if ((chb.getValue() == true && servList.getSelectedIndex() > 1) || (chb.getValue() == false && servList.getSelectedIndex() > 0)) {
                    ids.put("service", servList.getSelectedObject().getId());
                    lastSelectedService = servList.getSelectedObject().getId();
                }
                lastOfferAvailableOnly = chb.getValue();
                resAttrs.clearTable();
                resAttrs.setIds(ids);
                resAttrs.retrieveData();
                setTable(true);
            }
        });
        if (chb.getValue() == false) {
            allServices.retrieveData();
        } else {
            services.retrieveData();
        }
    } else {
        // retrieve data for selected service only
        lastSelectedService = serviceId;
        lastOfferAvailableOnly = chb.getValue();
        ids.put("service", serviceId);
        resAttrs.setIds(ids);
        resAttrs.retrieveData();
        setTable(true);
    }
    // refresh table event - refresh only on finished / on error keep selected
    final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resAttrs);
    final JsonCallbackEvents refreshTable2 = JsonCallbackEvents.refreshTableEvents(attrs);
    // add save changes to menu
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(saveChangesButton);
    // set button disable event
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
    final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable2);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getTableSelectedList();
            } else {
                list = attrs.getTableSelectedList();
            }
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
                request.setAttributes(ids, list);
            }
        }
    });
    // add set new to menu
    CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getList();
            } else {
                list = attrs.getList();
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("resource", resourceId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, list), true);
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        setNewAttributeButton.setEnabled(false);
    if (service == null) {
        menu.addWidget(setNewAttributeButton);
    }
    // fill button
    final CustomButton fillDefaultButton = TabMenu.getPredefinedButton(ButtonType.FILL, ButtonTranslation.INSTANCE.fillResourceAttributes());
    menu.addWidget(fillDefaultButton);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
    final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable2);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        removeButton.setEnabled(false);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getTableSelectedList();
            } else {
                list = attrs.getTableSelectedList();
            }
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add service selection to menu and switcher
    if (serviceId == 0) {
        menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
        menu.addWidget(servList);
        menu.addWidget(chb);
    }
    // checkbox switcher on click
    chb.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (chb.getValue() == false) {
                lastOfferAvailableOnly = false;
                allServices.retrieveData();
            } else {
                lastOfferAvailableOnly = true;
                services.retrieveData();
            }
        }
    });
    fillDefaultButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // automatically try to fill all attributes
            ArrayList<Attribute> prepareList = new ArrayList<Attribute>();
            if (required) {
                prepareList = resAttrs.getTableSelectedList();
            } else {
                prepareList = attrs.getTableSelectedList();
            }
            final ArrayList<Attribute> list = prepareList;
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                FillAttributes request = new FillAttributes(JsonCallbackEvents.disableButtonEvents(fillDefaultButton, new JsonCallbackEvents() {

                    boolean wasRequiredTable = required;

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // remove attribute from original table and put new ones
                        ArrayList<Attribute> newList = JsonUtils.jsoAsList(jso);
                        for (Attribute a : newList) {
                            for (Attribute oldA : list) {
                                // deselect old
                                if (a.getId() == oldA.getId()) {
                                    if (wasRequiredTable) {
                                        resAttrs.getSelectionModel().setSelected(oldA, false);
                                        resAttrs.removeFromTable(oldA);
                                    } else {
                                        attrs.getSelectionModel().setSelected(oldA, false);
                                        attrs.removeFromTable(oldA);
                                    }
                                }
                            }
                            if (wasRequiredTable) {
                                //add new
                                resAttrs.addToTable(a);
                                // select returned
                                resAttrs.getSelectionModel().setSelected(a, true);
                            } else {
                                //add new
                                attrs.addToTable(a);
                                // select returned
                                attrs.getSelectionModel().setSelected(a, true);
                            }
                        }
                        if (wasRequiredTable) {
                            resAttrs.sortTable();
                        } else {
                            attrs.sortTable();
                        }
                    }
                }));
                request.fillAttributes(ids, list);
            }
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        fillDefaultButton.setEnabled(false);
    /* TODO - not implemented

			 Button checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon());
			 menu.addWidget(checkValuesButton);
			 checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");


			 checkValuesButton.addClickHandler(new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });

*/
    table.addStyleName("perun-table");
    table.setWidth("100%");
    table2.addStyleName("perun-table");
    table2.setWidth("100%");
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    sp2.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp2, 350, this);
    // default is required attributes
    setTable(true);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) Service(cz.metacentrum.perun.webgui.model.Service) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) 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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 88 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject 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);
        }
    });
    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 89 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class UserDetailTabItem method loadCertificatesLoginsPasswords.

private Widget loadCertificatesLoginsPasswords() {
    // set content
    final VerticalPanel attributesTable = new VerticalPanel();
    final TabMenu menu = new TabMenu();
    attributesTable.add(menu);
    attributesTable.setWidth("100%");
    final ScrollPanel sp = new ScrollPanel();
    sp.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    sp.setWidth("100%");
    //attributesTable.setStyleName("userDetailTable");
    // clear logins when page refreshed
    userLoginAttrs.clear();
    // ids used for attribute handling
    Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("user", userId);
    // attribute table
    final PerunAttributeTableWidget table = new PerunAttributeTableWidget(ids);
    table.setDescriptionShown(true);
    table.setDisplaySaveButton(false);
    // load data
    GetListOfAttributes attributes = new GetListOfAttributes(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            userLoginAttrs.addAll(JsonUtils.<Attribute>jsoAsList(jso));
            userLoginAttrs = new TableSorter<Attribute>().sortByAttrNameTranslation(userLoginAttrs);
            for (Attribute a : userLoginAttrs) {
                if (a.getFriendlyName().equalsIgnoreCase("userCertificates")) {
                    table.add(a);
                } else if (a.getFriendlyName().equalsIgnoreCase("sshPublicKey")) {
                    table.add(a);
                } else if (a.getFriendlyName().equalsIgnoreCase("kerberosAdminPrincipal")) {
                    table.add(a);
                } else if (a.getFriendlyName().equalsIgnoreCase("sshPublicAdminKey")) {
                    table.add(a);
                }
            }
            // build attr table
            table.build();
            menu.addWidget(table.getSaveButton());
            // content
            VerticalPanel vpContent = new VerticalPanel();
            vpContent.add(table.asWidget());
            FlexTable innerTable = new FlexTable();
            innerTable.setCellPadding(5);
            vpContent.add(innerTable);
            // set content to page
            sp.add(vpContent);
            attributesTable.add(sp);
            int rowCount = 0;
            for (final Attribute a : userLoginAttrs) {
                if (a.getBaseFriendlyName().equalsIgnoreCase("login-namespace")) {
                    if (a.getValueAsObject() != null) {
                        // name
                        innerTable.setHTML(rowCount, 0, "<strong>" + a.getDisplayName() + "</strong>");
                        // value
                        innerTable.setHTML(rowCount, 1, a.getValue());
                        // change password
                        if (Utils.getSupportedPasswordNamespaces().contains(a.getFriendlyNameParameter())) {
                            CustomButton cb = new CustomButton("Change password…", SmallIcons.INSTANCE.keyIcon(), new ClickHandler() {

                                public void onClick(ClickEvent event) {
                                    session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, a.getFriendlyNameParameter(), a.getValue(), SelfPasswordTabItem.Actions.CHANGE));
                                }
                            });
                            innerTable.setWidget(rowCount, 2, cb);
                        }
                        rowCount++;
                    }
                }
            }
        }
    });
    HashSet<String> set = new HashSet<String>();
    set.add("urn:perun:user:attribute-def:def:userCertificates");
    set.add("urn:perun:user:attribute-def:def:kerberosAdminPrincipal");
    set.add("urn:perun:user:attribute-def:def:sshPublicKey");
    set.add("urn:perun:user:attribute-def:def:sshPublicAdminKey");
    set.add("urn:perun:user:attribute-def:def:login-namespace:mu");
    set.add("urn:perun:user:attribute-def:def:login-namespace:einfra");
    set.add("urn:perun:user:attribute-def:def:login-namespace:sitola");
    set.add("urn:perun:user:attribute-def:def:login-namespace:egi-ui");
    set.add("urn:perun:user:attribute-def:def:login-namespace:cesnet");
    set.add("urn:perun:user:attribute-def:def:login-namespace:meta");
    set.add("urn:perun:user:attribute-def:def:login-namespace:einfra-services");
    set.add("urn:perun:user:attribute-def:def:login-namespace:shongo");
    // TODO - FIXME - must be dynamic !!
    for (String namespace : Utils.getSupportedPasswordNamespaces()) {
        set.add("urn:perun:user:attribute-def:def:login-namespace:" + namespace);
    }
    // TODO - remove SHONGO
    ArrayList<String> list = JsonUtils.setToList(set);
    attributes.getListOfAttributes(ids, list);
    return attributesTable;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) HashSet(java.util.HashSet)

Example 90 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class UserExtSourceSettingsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(userExtSource.getLogin().trim()));
    // MAIN TAB PANEL
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // MENU
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    final GetAttributesV2 callback = new GetAttributesV2(true);
    callback.getUserExtSourceAttributes(userExtSource.getId());
    final CellTable<Attribute> table = callback.getEmptyTable();
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    menu.addWidget(UiElements.getRefreshButton(this));
    // save changes in attributes
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
                SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        callback.clearTable();
                        callback.getUserExtSourceAttributes(userExtSourceId);
                        callback.retrieveData();
                    }
                }));
                final Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("userExtSource", userExtSourceId);
                request.setAttributes(ids, callback.getTableSelectedList());
            }
        }
    });
    menu.addWidget(saveChangesButton);
    // buttons
    CustomButton setNewMemberAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("userExtSource", userExtSource.getId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids), true);
        }
    });
    menu.addWidget(setNewMemberAttributeButton);
    // REMOVE ATTRIBUTES BUTTON
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // if selected
            if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("userExtSource", userExtSource.getId());
                RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        callback.clearTable();
                        callback.getUserExtSourceAttributes(userExtSource.getId());
                        callback.retrieveData();
                    }
                }));
                // make removeAttributes call
                request.removeAttributes(ids, callback.getTableSelectedList());
            }
        }
    });
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeButton);
    menu.addWidget(removeButton);
    callback.retrieveData();
    // ATTRIBUTES TABLE
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)357 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)286 PerunError (cz.metacentrum.perun.webgui.model.PerunError)173 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)149 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)105 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)105 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)98 ArrayList (java.util.ArrayList)86 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)67 JSONObject (com.google.gwt.json.client.JSONObject)54 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)54 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)28 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)28 HashMap (java.util.HashMap)27 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)22 JSONNumber (com.google.gwt.json.client.JSONNumber)19 User (cz.metacentrum.perun.webgui.model.User)18 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)18 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)18 Map (java.util.Map)18