Search in sources :

Example 16 with ListBoxWithObjects

use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.

the class AddVoManagerGroupTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add manager group");
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    final TabMenu tabMenu = new TabMenu();
    final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
    // get the table
    final ScrollPanel sp = new ScrollPanel();
    sp.addStyleName("perun-tableScrollPanel");
    box.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
        }
    });
    if (box.getAllObjects().isEmpty()) {
        GetVos vos = new GetVos(new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                box.clear();
                ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
                if (list != null && !list.isEmpty()) {
                    box.addAllItems(list);
                    sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
                } else {
                    box.addItem("No VOs found");
                }
            }

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

            @Override
            public void onLoadingStart() {
                box.clear();
                box.addItem("Loading...");
            }
        });
        vos.retrieveData();
    }
    // add menu and the table to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    firstTabPanel.add(sp);
    // pass empty first item to tab menu to ensure rest is added
    tabMenu.addWidget(new HTML(""));
    final TabItem tab = this;
    tabMenu.addWidget(1, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    tabMenu.addWidget(2, new HTML("<strong>Select VO:</strong>"));
    tabMenu.addWidget(3, box);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 17 with ListBoxWithObjects

use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.

the class ManageGroupsBeforeAssigning method draw.

public Widget draw() {
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    final ListBoxWithObjects<Group> groupsDropDown = new ListBoxWithObjects<Group>();
    for (Group grp : groupsToAssign) {
        groupsDropDown.addItem(grp);
    }
    final ListBoxWithObjects<Group> subgroupsDropDown = new ListBoxWithObjects<Group>();
    subgroupsDropDown.addNotSelectedOption();
    final CustomButton finishAssigningButton = TabMenu.getPredefinedButton(ButtonType.FINISH, ButtonTranslation.INSTANCE.finishGroupAssigning());
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(finishAssigningButton, this, true);
    final JsonCallbackEvents disableButtonEvents = JsonCallbackEvents.disableButtonEvents(finishAssigningButton);
    finishAssigningButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // assign all
            if (groupsDropDown.getSelectedIndex() == 0) {
                AssignGroupsToResource request = new AssignGroupsToResource(closeTabEvents);
                request.assignGroupsToResource(groupsToAssign, resource);
            } else {
                // assign selected
                if (groupsDropDown.getSelectedObject() == null) {
                    Window.alert("No group selected");
                    return;
                }
                JsonCallbackEvents localEvents = new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        // call previus events
                        closeTabEvents.onFinished(null);
                        // removed finished group
                        groupsDropDown.removeSelectedItem();
                        if (groupsDropDown.isEmpty()) {
                            // if no group left - close windows
                            closeTabEvents.onFinished(null);
                        }
                    }
                };
                AssignGroupToResources request = new AssignGroupToResources(JsonCallbackEvents.disableButtonEvents(finishAssigningButton, localEvents));
                request.assignGroupToResources(groupsDropDown.getSelectedObject(), JsonUtils.<RichResource>toList(resource));
            }
        }
    });
    menu.addWidget(finishAssigningButton);
    menu.addWidget(new HTML("<strong>Selected group: </strong>"));
    menu.addWidget(groupsDropDown);
    // TODO - get subgroups correctly too
    // menu.addWidget(new HTML("<strong>Configure sub-groups: </strong>"));
    // menu.addWidget(subgroupsDropDown);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    groupsDropDown.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            // removes previous table
            if (vp.getWidgetCount() == 2) {
                vp.remove(1);
            }
            if (groupsDropDown.getSelectedIndex() > 0) {
                /*
					// fill subgroups listbox with groups
					subgroupsDropDown.removeAllOption();
					subgroupsDropDown.removeNotSelectedOption();
					subgroupsDropDown.clear();
					subgroupsDropDown.addNotSelectedOption();
					for (Group grp : findSubgroups(groupsDropDown.getSelectedObject())){
					subgroupsDropDown.addItem(grp);
					}
					subgroupsDropDown.addAllOption();
					*/
                // some group selected
                TabItem ti = new GroupResourceRequiredAttributesTabItem(resourceId, groupsDropDown.getSelectedObject().getId());
                ti.draw();
                Widget w = ti.getWidget();
                vp.add(w);
                vp.setCellHeight(w, "100%");
            } else {
                /*
					//clear listbox
					subgroupsDropDown.removeAllOption();
					subgroupsDropDown.removeNotSelectedOption();
					subgroupsDropDown.clear();
					subgroupsDropDown.addNotSelectedOption();
					subgroupsDropDown.addItem("All");
					*/
                // all groups tab
                TabItem ti = new GroupsResourceRequiredAttributesTabItem(resourceId, groupsToAssign);
                ti.draw();
                Widget w = ti.getWidget();
                vp.add(w);
                vp.setCellHeight(w, "100%");
            }
        }
    });
    /*

			 subgroupsDropDown.addChangeHandler(new ChangeHandler(){
			 public void onChange(ChangeEvent event) {
			 if (vp.getWidgetCount() == 2) { vp.remove(1); } // removes previous table
			 if (subgroupsDropDown.getSelectedIndex() > 1){
// sub-group selected
TabItem ti = new GroupResourceRequiredAttributesTabItem(session, resourceId, subgroupsDropDown.getSelectedObject().getId());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
} else if (subgroupsDropDown.getSelectedIndex() == 1){
// all selected
if (groupsDropDown.getSelectedIndex() > 0) {
// all subgroups of selected group
TabItem ti = new GroupsResourceRequiredAttributesTabItem(session, resourceId, subgroupsDropDown.getAllObjects());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
} else {
		// all groups and subgroups
		TabItem ti = new GroupsResourceRequiredAttributesTabItem(session, resourceId, allGroups);
		ti.draw();
		Widget w = ti.getWidget();
		vp.add(w);
		vp.setCellHeight(w, "100%");
}
} else {
		// parent-group selected / subgroup not selected
		TabItem ti = new GroupResourceRequiredAttributesTabItem(session, resourceId, groupsDropDown.getSelectedObject().getId());
		ti.draw();
		Widget w = ti.getWidget();
		vp.add(w);
		vp.setCellHeight(w, "100%");
}
			 }
			 });

*/
    TabItem ti = new GroupResourceRequiredAttributesTabItem(resourceId, groupsDropDown.getSelectedObject().getId());
    ti.draw();
    Widget w = ti.getWidget();
    vp.add(w);
    vp.setCellHeight(w, "100%");
    groupsDropDown.addAllOption();
    /*
// if some group selected
if (groupsDropDown.getSelectedObject() != null){
// fill subgroups listbox with groups
subgroupsDropDown.addNotSelectedOption();
for (Group grp : findSubgroups(groupsDropDown.getSelectedObject())){
subgroupsDropDown.addItem(grp);
}
subgroupsDropDown.addAllOption();
}
*/
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) RichResource(cz.metacentrum.perun.webgui.model.RichResource) AssignGroupToResources(cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupToResources) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) AssignGroupsToResource(cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GroupsResourceRequiredAttributesTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupsResourceRequiredAttributesTabItem) GroupResourceRequiredAttributesTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupResourceRequiredAttributesTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) GroupsResourceRequiredAttributesTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupsResourceRequiredAttributesTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GroupResourceRequiredAttributesTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupResourceRequiredAttributesTabItem)

Example 18 with ListBoxWithObjects

use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects 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)

Example 19 with ListBoxWithObjects

use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.

the class CopyMailsTabItem method draw.

public Widget draw() {
    final FlexTable content = new FlexTable();
    content.setStyleName("inputFormFlexTable");
    // boxes
    final ListBoxWithObjects<VirtualOrganization> vosBox = new ListBoxWithObjects<VirtualOrganization>();
    final ListBoxWithObjects<Group> groupsBox = new ListBoxWithObjects<Group>();
    final CustomButton save;
    final TabItem tab = this;
    VerticalPanel vp = new VerticalPanel();
    TabMenu menu = new TabMenu();
    titleWidget.setText("Copy form items from VO / group");
    save = TabMenu.getPredefinedButton(ButtonType.OK, ButtonTranslation.INSTANCE.copyFromVo());
    // get them
    final GetVos vos = new GetVos(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            vosBox.clear();
            ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
            vos = new TableSorter<VirtualOrganization>().sortByName(vos);
            vosBox.addAllItems(vos);
            // get them
            GetAllGroups getGroups = new GetAllGroups(voId, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    groupsBox.clear();
                    ArrayList<Group> groups = JsonUtils.jsoAsList(jso);
                    groups = new TableSorter<Group>().sortByName(groups);
                    groupsBox.addNotSelectedOption();
                    groupsBox.addAllItems(groups);
                    save.setEnabled(true);
                }

                @Override
                public void onError(PerunError error) {
                    groupsBox.removeNotSelectedOption();
                    groupsBox.clear();
                    groupsBox.addItem("Error while loading");
                    save.setEnabled(false);
                }

                @Override
                public void onLoadingStart() {
                    groupsBox.removeNotSelectedOption();
                    groupsBox.clear();
                    groupsBox.addItem("Loading...");
                    save.setEnabled(false);
                }
            });
            getGroups.retrieveData();
        }

        @Override
        public void onError(PerunError error) {
            vosBox.addItem("Error while loading");
            save.setEnabled(false);
        }

        @Override
        public void onLoadingStart() {
            vosBox.addItem("Loading...");
            save.setEnabled(false);
        }
    });
    vos.retrieveData();
    vosBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (vosBox.getSelectedObject() != null) {
                // get them
                GetAllGroups getGroups = new GetAllGroups(vosBox.getSelectedObject().getId(), new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        groupsBox.clear();
                        ArrayList<Group> groups = JsonUtils.jsoAsList(jso);
                        groups = new TableSorter<Group>().sortByName(groups);
                        groupsBox.addNotSelectedOption();
                        groupsBox.addAllItems(groups);
                        save.setEnabled(true);
                    }

                    @Override
                    public void onError(PerunError error) {
                        groupsBox.removeNotSelectedOption();
                        groupsBox.clear();
                        groupsBox.addItem("Error while loading");
                        save.setEnabled(false);
                    }

                    @Override
                    public void onLoadingStart() {
                        groupsBox.removeNotSelectedOption();
                        groupsBox.clear();
                        groupsBox.addItem("Loading...");
                        save.setEnabled(false);
                    }
                });
                getGroups.retrieveData();
            }
        }
    });
    content.setHTML(0, 0, "Source VO:");
    content.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    content.setWidget(0, 1, vosBox);
    content.setHTML(1, 0, "Source group:");
    content.getFlexCellFormatter().setStyleName(1, 0, "itemName");
    content.setWidget(1, 1, groupsBox);
    save.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            CopyMails request = null;
            if (groupsBox.getSelectedIndex() != 0 && voId != 0 && groupId == 0) {
                // from group to VO
                request = new CopyMails(PerunEntity.GROUP, groupsBox.getSelectedObject().getId(), PerunEntity.VIRTUAL_ORGANIZATION, voId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            } else if (groupsBox.getSelectedIndex() != 0 && voId != 0 && groupId != 0) {
                // from group to group
                request = new CopyMails(PerunEntity.GROUP, groupsBox.getSelectedObject().getId(), PerunEntity.GROUP, groupId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            } else if (groupsBox.getSelectedIndex() == 0 && voId != 0 && groupId == 0) {
                // from VO to VO
                request = new CopyMails(PerunEntity.VIRTUAL_ORGANIZATION, vosBox.getSelectedObject().getId(), PerunEntity.VIRTUAL_ORGANIZATION, voId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            } else if (groupsBox.getSelectedIndex() == 0 && voId != 0 && groupId != 0) {
                // from VO to group
                request = new CopyMails(PerunEntity.VIRTUAL_ORGANIZATION, vosBox.getSelectedObject().getId(), PerunEntity.GROUP, groupId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            }
            request.copyMails();
        }
    });
    content.setHTML(2, 0, "All mail definitions will be added to yours.");
    content.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
    content.getFlexCellFormatter().setColSpan(2, 0, 2);
    menu.addWidget(save);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    vp.add(content);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) TableSorter(cz.metacentrum.perun.webgui.client.resources.TableSorter) Group(cz.metacentrum.perun.webgui.model.Group) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) CopyMails(cz.metacentrum.perun.webgui.json.registrarManager.CopyMails) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 20 with ListBoxWithObjects

use of cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects in project perun by CESNET.

the class CreateFacilityResourceManageServicesTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Create resource: Assign and configure services");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.add(alreadyAdded);
    vp.add(new HTML("<hr>"));
    // buttons
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Assign selected service to resource");
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove selected service from resource");
    CustomButton finishButton = TabMenu.getPredefinedButton(ButtonType.FINISH, "Finishes services assigning and configuration");
    finishButton.setImageAlign(true);
    // listbox with services
    final ListBoxWithObjects<Service> servicesListbox = new ListBoxWithObjects<Service>();
    // checkbox to swith offered services
    final CheckBox switchBox = new CheckBox("Show assigned", false);
    switchBox.setTitle("Switching between 'all' and 'already assigned' services in menu.");
    // fill menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
    menu.addWidget(servicesListbox);
    menu.addWidget(switchBox);
    menu.addWidget(assignButton);
    menu.addWidget(removeButton);
    menu.addWidget(finishButton);
    // fill listbox with services (used for both callbacks)
    JsonCallbackEvents fillEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<Service> services = JsonUtils.jsoAsList(jso);
            services = new TableSorter<Service>().sortByName(services);
            servicesListbox.clear();
            for (Service serv : services) {
                servicesListbox.addItem(serv);
            }
            if (servicesListbox.isEmpty()) {
                servicesListbox.addItem("No service assigned");
                if (vp.getWidgetCount() > 3) {
                    vp.remove(3);
                }
                return;
            }
            if (vp.getWidgetCount() > 3) {
                vp.remove(3);
            }
            vp.add(new ResourceSettingsTabItem(resource, servicesListbox.getSelectedObject()).draw());
            vp.setCellHeight(vp.getWidget(3), "100%");
        }

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

        @Override
        public void onLoadingStart() {
            servicesListbox.clear();
            servicesListbox.addItem("Loading...");
        }
    };
    // callbacks
    final GetServices services = new GetServices(fillEvents);
    final GetAssignedServices assignedServices = new GetAssignedServices(resource.getId(), fillEvents);
    services.retrieveData();
    // switching event between services
    servicesListbox.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            // remove attributes management if there was
            if (vp.getWidgetCount() > 3) {
                vp.remove(3);
            }
            // add attributes management
            vp.add(new ResourceSettingsTabItem(resource, servicesListbox.getSelectedObject()).draw());
            vp.setCellHeight(vp.getWidget(3), "100%");
        }
    });
    // switching between offered services (assigned - all)
    switchBox.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (switchBox.getValue() == false) {
                servicesListbox.clear();
                services.retrieveData();
            } else {
                servicesListbox.clear();
                assignedServices.retrieveData();
            }
        }
    });
    // button events
    assignButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (servicesListbox.isEmpty()) {
                UiElements.generateInfo("No Service selected", "You must select a service first.");
                return;
            }
            final Service service = servicesListbox.getSelectedObject();
            AssignServices request = new AssignServices(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    alreadyAddedList.add(service);
                    rebuildAlreadyAddedWidget();
                }
            }));
            request.assignService(service.getId(), resource.getId());
        }
    });
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (servicesListbox.isEmpty()) {
                UiElements.generateInfo("No Service selected", "You must select a service first.");
                return;
            }
            final Service service = servicesListbox.getSelectedObject();
            RemoveServices request = new RemoveServices(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    Iterator<Service> iter = alreadyAddedList.iterator();
                    while (iter.hasNext()) {
                        Service s = iter.next();
                        if (s.getId() == service.getId()) {
                            iter.remove();
                        }
                    }
                    rebuildAlreadyAddedWidget();
                }
            }));
            request.removeService(servicesListbox.getSelectedObject().getId(), resource.getId());
        }
    });
    final TabItem tab = this;
    finishButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab);
        }
    });
    this.contentWidget.setWidget(vp);
    rebuildAlreadyAddedWidget();
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) AssignServices(cz.metacentrum.perun.webgui.json.resourcesManager.AssignServices) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) RemoveServices(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveServices) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Iterator(java.util.Iterator) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) Service(cz.metacentrum.perun.webgui.model.Service) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)24 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)24 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)24 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)23 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)21 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)21 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)18 PerunError (cz.metacentrum.perun.webgui.model.PerunError)17 ArrayList (java.util.ArrayList)17 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)16 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)16 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)12 GetVos (cz.metacentrum.perun.webgui.json.vosManager.GetVos)8 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)8 HashMap (java.util.HashMap)8 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)6 SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)5 Map (java.util.Map)5 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)4 GetAssignedServices (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices)4