Search in sources :

Example 6 with SetNewAttributeTabItem

use of cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem in project perun by CESNET.

the class FacilitySettingsTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Service settings");
    // content
    vp.setSize("100%", "100%");
    vp.clear();
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    // Get Attributes method
    final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2();
    final GetAttributesV2 attrs = new GetAttributesV2();
    attrs.getFacilityAttributes(facilityId);
    // get empty table
    final CellTable<Attribute> table = reqAttrs.getEmptyTable();
    final CellTable<Attribute> table2 = attrs.getEmptyTable();
    sp.setWidget(table);
    sp2.setWidget(table2);
    // ids to retrieve data from rpc
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("facility", facility.getId());
    // service switcher checkbox
    final CheckBox switchServicesChb = new CheckBox(WidgetTranslation.INSTANCE.offerAvailableServicesOnly(), false);
    // selected by default - unselected if switch hidden
    switchServicesChb.setValue(lastCheckBoxValue);
    switchServicesChb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
    // services listbox
    final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
    // on change of service update table
    servList.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            if (servList.getSelectedIndex() == 0) {
                // show all facility attributes
                attrs.retrieveData();
                setTable(false);
                lastServiceId = 0;
                indexInList = 0;
                return;
            }
            if (switchServicesChb.getValue() == true && servList.getSelectedIndex() == 1) {
                // show required attrs for all assigned services
                ids.remove("service");
                lastServiceId = 0;
                indexInList = 1;
            } else if ((switchServicesChb.getValue() == true && servList.getSelectedIndex() > 1) || (switchServicesChb.getValue() == false && servList.getSelectedIndex() > 0)) {
                // show required attrs for selected service
                // >0 when listing all services
                // >1 when listing assigned services
                ids.put("service", servList.getSelectedObject().getId());
                lastServiceId = servList.getSelectedObject().getId();
            }
            // load req attrs
            reqAttrs.setIds(ids);
            reqAttrs.clearTable();
            reqAttrs.retrieveData();
            setTable(true);
        }
    });
    // event which fills the listbox and call getRequiredAttributes
    final JsonCallbackEvents event = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            servList.clear();
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            for (int i = 0; i < srv.size(); i++) {
                servList.addItem(srv.get(i));
            }
            // no services available - load all facility attrs
            if (servList.isEmpty()) {
                servList.addNotSelectedOption();
                lastServiceId = 0;
                indexInList = 0;
                attrs.retrieveData();
                setTable(false);
                return;
            }
            // offer only available
            if (switchServicesChb.getValue() == true) {
                servList.addNotSelectedOption();
                servList.addAllOption();
                if (lastServiceId == 0) {
                    if (indexInList == 1) {
                        // all
                        servList.setSelectedIndex(1);
                    } else if (indexInList == 0) {
                        // not selected - load all fac attrs
                        servList.setSelectedIndex(0);
                        attrs.retrieveData();
                        setTable(false);
                        return;
                    }
                }
            } else {
                // offer all services
                servList.addNotSelectedOption();
                if (lastServiceId == 0) {
                    // if no service selected, load all fac attrs
                    servList.setSelectedIndex(0);
                    attrs.retrieveData();
                    setTable(false);
                    return;
                }
            }
            // if some service was selected
            if (lastServiceId != 0) {
                // remove service since we can't be sure, it was loaded again
                ids.remove("service");
                // either all or first service in a list
                servList.setSelectedIndex(1);
                for (Service s : servList.getAllObjects()) {
                    if (s.getId() == lastServiceId) {
                        // if found, select it
                        servList.setSelected(s, true);
                        ids.put("service", lastServiceId);
                        break;
                    }
                }
            }
            // get required attrs for service
            reqAttrs.clearTable();
            reqAttrs.setIds(ids);
            reqAttrs.retrieveData();
            setTable(true);
        }

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

        @Override
        public void onLoadingStart() {
            servList.removeAllOption();
            servList.removeNotSelectedOption();
            servList.clear();
            servList.addItem("Loading...");
        }
    };
    final GetServices allServices = new GetServices(event);
    final GetFacilityAssignedServices assignedServices = new GetFacilityAssignedServices(facility.getId(), event);
    // if hide and unchecked or just unchecked
    if (!lastCheckBoxValue) {
        allServices.retrieveData();
    } else {
        assignedServices.retrieveData();
    }
    // Save changes button
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    final JsonCallbackEvents refreshEvents = JsonCallbackEvents.refreshTableEvents(reqAttrs);
    final JsonCallbackEvents refreshEvents2 = JsonCallbackEvents.refreshTableEvents(attrs);
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents);
    final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents2);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
                request.setAttributes(ids, list);
            }
        }
    });
    // Remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents);
    final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents2);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("facility", facilityId);
                RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
                request.removeAttributes(ids, list);
            }
        }
    });
    // switch serv checkbox
    switchServicesChb.addClickHandler(new ClickHandler() {

        // load proper set of services on click
        public void onClick(ClickEvent event) {
            lastCheckBoxValue = switchServicesChb.getValue();
            if (switchServicesChb.getValue() == true) {
                assignedServices.retrieveData();
            } else {
                allServices.retrieveData();
            }
        }
    });
    // allow to set new (currently unused facility attribute)
    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("facility", facility.getId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, (required) ? reqAttrs.getList() : attrs.getList()), true);
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    menu.addWidget(setNewAttributeButton);
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Service: </strong>"));
    menu.addWidget(servList);
    if (!hide) {
        menu.addWidget(switchServicesChb);
    }
    /* TODO - not yet implemented

			 CustomButton fillDefaultButton = new CustomButton("Fill default values", SmallIcons.INSTANCE.scriptGoIcon(), new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });
			 fillDefaultButton.setTitle("Fill default values for this service/facility - nothing is saved unless you click on 'Save changes'");
			 CustomButton checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon(), new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });
			 checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");

			 menu.addWidget(fillDefaultButton);
			 menu.addWidget(checkValuesButton);

*/
    // add a class to the table and wrap it into scroll panel
    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);
    // add menu and the table to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // 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) Attribute(cz.metacentrum.perun.webgui.model.Attribute) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) 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) GetRequiredAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetRequiredAttributesV2) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) 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) GetFacilityAssignedServices(cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 7 with SetNewAttributeTabItem

use of cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem in project perun by CESNET.

the class FacilityHostsSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts settings");
    // main panel
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    final GetAttributesV2 attrs = new GetAttributesV2();
    final ListBoxWithObjects<Host> listbox = new ListBoxWithObjects<Host>();
    // refresh attributes for hosts
    listbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (listbox.getSelectedObject() != null) {
                lastSelectedHostId = listbox.getSelectedObject().getId();
                attrs.getHostAttributes(lastSelectedHostId);
                attrs.retrieveData();
            } else {
                lastSelectedHostId = 0;
            }
        }
    });
    // retrieve hosts
    final GetHosts hosts = new GetHosts(facilityId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            listbox.clear();
            ArrayList<Host> result = JsonUtils.jsoAsList(jso);
            if (result != null && !result.isEmpty()) {
                for (Host h : result) {
                    listbox.addItem(h);
                    if (h.getId() == lastSelectedHostId) {
                        listbox.setSelected(h, true);
                    }
                }
                if (lastSelectedHostId == 0) {
                    lastSelectedHostId = listbox.getSelectedObject().getId();
                }
                attrs.getHostAttributes(lastSelectedHostId);
                attrs.retrieveData();
            }
        }

        @Override
        public void onError(PerunError error) {
            listbox.clear();
            listbox.addItem("Error while loading");
        }

        @Override
        public void onLoadingStart() {
            listbox.clear();
            listbox.addItem("Loading...");
        }
    });
    hosts.retrieveData();
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(attrs);
    // menu
    TabMenu menu = new TabMenu();
    // Save changes button
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, events);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("host", lastSelectedHostId);
                SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    // Remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("host", lastSelectedHostId);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("host", lastSelectedHostId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attrs.getList()), true);
        }
    }));
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Select host:</strong>"));
    menu.addWidget(listbox);
    // attrs table
    CellTable<Attribute> table = attrs.getEmptyTable();
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu and the table to the main panel
    firstTabPanel.add(menu);
    firstTabPanel.setCellHeight(menu, "30px");
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) GetHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts) 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) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) Host(cz.metacentrum.perun.webgui.model.Host) 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) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 8 with SetNewAttributeTabItem

use of cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem in project perun by CESNET.

the class UserDetailTabItem method loadFacilitySubContent.

private void loadFacilitySubContent(final SimplePanel subContent, final Hyperlink facilityLabel, final ListBoxWithObjects<Facility> listbox) {
    final VerticalPanel entryPanel = new VerticalPanel();
    entryPanel.setSize("100%", "100%");
    subContent.setWidget(entryPanel);
    facilityLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + listbox.getSelectedObject().getName() + "</h2>"));
    facilityLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new FacilityDetailTabItem(listbox.getSelectedObject())));
    final GetAttributesV2 attributes = new GetAttributesV2();
    attributes.getUserFacilityAttributes(listbox.getSelectedObject().getId(), user.getId());
    TabMenu menu = new TabMenu();
    final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes");
    saveAttrButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", listbox.getSelectedObject().getId());
            SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
            request.setAttributes(ids, list);
        }
    });
    menu.addWidget(saveAttrButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Set new attributes", new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", listbox.getSelectedObject().getId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
        }
    }));
    final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes");
    removeAttrButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", listbox.getSelectedObject().getId());
            RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
            request.removeAttributes(ids, list);
        }
    });
    menu.addWidget(removeAttrButton);
    entryPanel.add(menu);
    CellTable<Attribute> table = attributes.getTable();
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    entryPanel.add(sp);
    // better format
    entryPanel.add(new SimplePanel());
    entryPanel.setCellHeight(entryPanel.getWidget(entryPanel.getWidgetCount() - 1), "100%");
    session.getUiElements().resizeSmallTabPanel(sp, 320, this);
}
Also used : HashMap(java.util.HashMap) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) FacilityDetailTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 9 with SetNewAttributeTabItem

use of cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem in project perun by CESNET.

the class UserDetailTabItem method loadInformationOverview.

// FIXME and TODO - all private methods should be separate TabItems !!! Connect them with user menu etc. ?
private Widget loadInformationOverview() {
    // content
    ScrollPanel scroll = new ScrollPanel();
    VerticalPanel extendedInfoVp = new VerticalPanel();
    extendedInfoVp.setStyleName("perun-table");
    scroll.setWidget(extendedInfoVp);
    scroll.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(scroll, 350, this);
    extendedInfoVp.setWidth("100%");
    // detail header
    Widget userHeader = new HTML("<h2>" + "User details" + "</h2>");
    extendedInfoVp.add(userHeader);
    extendedInfoVp.setCellHeight(userHeader, "30px");
    final TabItem tab = this;
    final JsonCallbackEvents events = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            user = jso.cast();
            tab.draw();
        }
    };
    CustomButton change = new CustomButton("", "Edit user", SmallIcons.INSTANCE.applicationFormEditIcon());
    change.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new EditUserDetailsTabItem(user, events));
        }
    });
    // detail content
    FlexTable layout = new FlexTable();
    layout.setCellSpacing(6);
    // Add some standard form options
    layout.setHTML(0, 0, "<strong>Full&nbsp;name:</strong>");
    layout.setHTML(0, 1, user.getFullNameWithTitles());
    layout.setWidget(0, 2, change);
    layout.setHTML(0, 3, "<strong>User&nbsp;ID:</strong>");
    layout.setHTML(0, 4, String.valueOf(user.getId()));
    layout.setHTML(0, 5, "<strong>User&nbsp;type:</strong>");
    if (user.isServiceUser()) {
        layout.setHTML(0, 6, "Service");
    } else if (user.isSponsoredUser()) {
        layout.setHTML(0, 6, "Sponsored");
    } else {
        layout.setHTML(0, 6, "Person");
    }
    // wrap the content in a DecoratorPanel
    DecoratorPanel decPanel = new DecoratorPanel();
    decPanel.setWidget(layout);
    extendedInfoVp.add(decPanel);
    // user attributes
    final GetAttributesV2 attributes = new GetAttributesV2();
    attributes.getUserAttributes(user.getId());
    CellTable<Attribute> tableAttributes = attributes.getTable();
    tableAttributes.addStyleName("perun-table");
    tableAttributes.setWidth("100%");
    Widget attributesHeader = new HTML("<h2>" + "User attributes" + "</h2>");
    extendedInfoVp.add(attributesHeader);
    extendedInfoVp.setCellHeight(attributesHeader, "30px");
    TabMenu menu = new TabMenu();
    final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for user");
    saveAttrButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
            request.setAttributes(ids, list);
        }
    });
    menu.addWidget(saveAttrButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Set new attributes for user", new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
        }
    }));
    final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes from user");
    removeAttrButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
            request.removeAttributes(ids, list);
        }
    });
    menu.addWidget(removeAttrButton);
    extendedInfoVp.add(menu);
    extendedInfoVp.add(tableAttributes);
    // VOS
    GetVosWhereUserIsMember vos = new GetVosWhereUserIsMember(user.getId());
    vos.setCheckable(false);
    // get the table with custom onclick
    CellTable<VirtualOrganization> simpeVosTable = vos.getTable(new FieldUpdater<VirtualOrganization, VirtualOrganization>() {

        public void update(int index, VirtualOrganization object, VirtualOrganization value) {
            session.getTabManager().addTab(new VoDetailTabItem(object));
        }
    });
    // format the table
    simpeVosTable.addStyleName("perun-table");
    simpeVosTable.setWidth("100%");
    // simple table
    Widget vosHeader = new HTML("<h2>" + "Virtual organizations" + "</h2>");
    extendedInfoVp.add(vosHeader);
    extendedInfoVp.setCellHeight(vosHeader, "30px");
    extendedInfoVp.add(simpeVosTable);
    return scroll;
}
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) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) UsersPublicationsTabItem(cz.metacentrum.perun.webgui.tabs.cabinettabs.UsersPublicationsTabItem) ResourceDetailTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) FacilityDetailTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 10 with SetNewAttributeTabItem

use of cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem in project perun by CESNET.

the class ResourceGroupSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": group 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<Group> groupListBox = 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 groups
    final GetAssignedGroups groups = new GetAssignedGroups(resourceId, new JsonCallbackEvents() {

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

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

        @Override
        public void onLoadingStart() {
            groupListBox.removeAllOption();
            groupListBox.clear();
            groupListBox.addItem("Loading...");
            groupCallDone = false;
        }
    });
    groups.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 their 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) {
                // load resource-required
                if (groupCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                if (groupCallDone) {
                    // load resource-service-group
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 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 (groupCallDone && servCallDone) {
                if (groupListBox.getSelectedObject() != null) {
                    lastSelectedGroup = groupListBox.getSelectedObject().getId();
                } else {
                    lastSelectedGroup = 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("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                } else {
                    // load resource-service-group
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }
    };
    groupListBox.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("group", groupListBox.getSelectedObject().getId());
                ids.put("workWithGroupAttributes", 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("group", groupListBox.getSelectedObject().getId());
            ids.put("workWithGroupAttributes", 1);
            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("group", groupListBox.getSelectedObject().getId());
                ids.put("workWithGroupAttributes", 1);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add group selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;group: </strong>"));
    menu.addWidget(groupListBox);
    // add group 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) GetAssignedGroups(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) 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) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)12 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)12 HashMap (java.util.HashMap)12 Map (java.util.Map)12 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)11 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)10 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)10 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)10 ArrayList (java.util.ArrayList)10 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)8 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)8 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)8 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)7 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)6 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)6 Attribute (cz.metacentrum.perun.webgui.model.Attribute)6 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)5 PerunError (cz.metacentrum.perun.webgui.model.PerunError)4 ImageResource (com.google.gwt.resources.client.ImageResource)3 GetAssignedResources (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources)3