Search in sources :

Example 21 with ListBoxWithObjects

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

the class MoveGroupsTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    int voId = (vo != null) ? vo.getId() : group.getVoId();
    List<Group> backupGroups = new ArrayList<>();
    backupGroups.addAll(groups);
    // remove any subgroups of parent groups in a list of MOVED groups
    for (Group bg : backupGroups) {
        Iterator<? extends Group> iterator = groups.iterator();
        while (iterator.hasNext()) {
            // check if is subgroup
            Group moveGroup = iterator.next();
            if (moveGroup.getName().startsWith(bg.getName() + ":")) {
                iterator.remove();
            }
        }
    }
    // textboxes which set the class data when updated
    final ListBoxWithObjects<Group> vosGroups = new ListBoxWithObjects<Group>();
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    // send button
    final CustomButton moveButton = TabMenu.getPredefinedButton(ButtonType.MOVE, buttonTranslation.moveGroup());
    moveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final Group destinationGroup = vosGroups.getSelectedObject();
            final MoveGroup request = new MoveGroup();
            final JsonCallbackEvents nextEvent = JsonCallbackEvents.disableButtonEvents(moveButton, new JsonCallbackEvents() {

                int groupsCounter = 0;

                @Override
                public void onFinished(JavaScriptObject jso) {
                    if (groups.size() - 1 == groupsCounter) {
                        // there is another group to move
                        request.setEvents(JsonCallbackEvents.closeTabDisableButtonEvents(moveButton, tab, true));
                        request.moveGroup(groups.get(groupsCounter), destinationGroup);
                    } else if (groups.size() - 1 > groupsCounter) {
                        request.moveGroup(groups.get(groupsCounter), destinationGroup);
                    }
                // done
                }

                @Override
                public void onError(PerunError error) {
                    // close tab if failed
                    moveButton.setProcessing(false);
                    session.getTabManager().closeTab(tab);
                }

                @Override
                public void onLoadingStart() {
                    groupsCounter++;
                }
            });
            if (groups.size() == 1) {
                // single group
                request.setEvents(JsonCallbackEvents.closeTabDisableButtonEvents(moveButton, tab, true));
            } else {
                // iterate over more groups
                request.setEvents(nextEvent);
            }
            request.moveGroup(groups.get(0), destinationGroup);
        }
    });
    final GetAllGroups groupsCall = new GetAllGroups(voId, new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosGroups.clear();
            ArrayList<Group> retGroups = JsonUtils.jsoAsList(jso);
            retGroups = new TableSorter<Group>().sortByName(retGroups);
            // skip groups which are moving and their sub-groups and direct parents (since they would stayed at the same place)
            Iterator<Group> iterator = retGroups.iterator();
            while (iterator.hasNext()) {
                Group retGroup = iterator.next();
                for (Group g : groups) {
                    if (g.getId() == retGroup.getId() || retGroup.getName().startsWith(g.getName() + ":") || retGroup.getName().equals(g.getName()) || g.getParentGroupId() == retGroup.getId()) {
                        iterator.remove();
                        break;
                    }
                }
            }
            for (Group g : retGroups) {
                if (!g.isCoreGroup()) {
                    // SKIP CORE GROUPS !!
                    vosGroups.addItem(g);
                }
            }
            if (vosGroups.getAllObjects().isEmpty()) {
                for (Group g : groups) {
                    // at lease one of moving groups is a sub group, so we can offer move to top-level
                    if (g.getName().contains(":")) {
                        vosGroups.addNotSelectedOption();
                        moveButton.setEnabled(true);
                        return;
                    }
                }
                // can't move group anywhere
                vosGroups.addItem("No possible destination group was found or group is already top-level.");
            } else {
                vosGroups.addNotSelectedOption();
                moveButton.setEnabled(true);
            }
        }

        public void onLoadingStart() {
            vosGroups.clear();
            vosGroups.addItem("Loading...");
            moveButton.setEnabled(false);
        }

        public void onError(PerunError error) {
            vosGroups.clear();
            vosGroups.addItem("Error while loading");
        }
    });
    groupsCall.retrieveData();
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    });
    layout.setHTML(0, 0, "Following groups will be moved (including all their sub-groups):");
    layout.getFlexCellFormatter().setColSpan(0, 0, 2);
    String items = "<ul>";
    for (Group g : groups) {
        items = items.concat("<li>" + g.getName() + "</li>");
    }
    items = items.concat("</ul>");
    ScrollPanel sp = new ScrollPanel();
    sp.setStyleName("border");
    sp.setSize("100%", "100px");
    sp.add(new HTML(items));
    layout.setWidget(1, 0, sp);
    layout.getFlexCellFormatter().setColSpan(1, 0, 2);
    // Add some standard form options
    layout.setHTML(2, 0, "Destination&nbsp;group:");
    layout.setWidget(2, 1, vosGroups);
    for (int i = 2; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    layout.setHTML(3, 0, "Group(s) will be moved (including all their sub-groups) under destination group! If no destination group is selected, group will be moved to top-level.<p>We strongly recommend to move groups one by one.");
    layout.getFlexCellFormatter().setStyleName(3, 0, "inputFormInlineComment");
    layout.getFlexCellFormatter().setColSpan(3, 0, 2);
    vp.setWidth("400px");
    menu.addWidget(moveButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : MoveGroup(cz.metacentrum.perun.webgui.json.groupsManager.MoveGroup) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) MoveGroup(cz.metacentrum.perun.webgui.json.groupsManager.MoveGroup) Group(cz.metacentrum.perun.webgui.model.Group) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) HTML(com.google.gwt.user.client.ui.HTML) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Iterator(java.util.Iterator) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) FlexTable(com.google.gwt.user.client.ui.FlexTable) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Example 22 with ListBoxWithObjects

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

the class GroupsTabItem method draw.

public Widget draw() {
    // main panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // Horizontal menu
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    // call
    ArrayList<String> attrNames = new ArrayList<>();
    attrNames.add("urn:perun:group:attribute-def:def:synchronizationEnabled");
    attrNames.add("urn:perun:group:attribute-def:def:synchronizationInterval");
    attrNames.add("urn:perun:group:attribute-def:def:lastSynchronizationState");
    attrNames.add("urn:perun:group:attribute-def:def:lastSuccessSynchronizationTimestamp");
    attrNames.add("urn:perun:group:attribute-def:def:lastSynchronizationTimestamp");
    attrNames.add("urn:perun:group:attribute-def:def:authoritativeGroup");
    attrNames.add("urn:perun:group:attribute-def:def:groupSynchronizationTimes");
    attrNames.add("urn:perun:group:attribute-def:def:startOfLastSuccessfulSynchronization");
    attrNames.add("urn:perun:group:attribute-def:def:startOfLastSynchronization");
    final GetAllRichGroups groups = new GetAllRichGroups(voId, attrNames);
    groups.setCheckable(false);
    // listbox
    final ListBoxWithObjects<VirtualOrganization> vos = new ListBoxWithObjects<VirtualOrganization>();
    menu.addWidget(new HTML("<strong>Selected VO: </strong>"));
    menu.addWidget(vos);
    menu.addFilterWidget(new ExtendedSuggestBox(groups.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            groups.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterGroup());
    menu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
    menu.addWidget(new HTML("<strong>Select VO to see groups that you can manage.</strong>"));
    final TabItem tab = this;
    // groups table
    CellTable<RichGroup> table = groups.getEmptyTable(new FieldUpdater<RichGroup, String>() {

        public void update(int index, RichGroup group, String value) {
            session.getTabManager().addTab(new GroupDetailTabItem(group));
            // close group selection tab when group is selected
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    });
    // listbox change => load vo's groups
    vos.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            groups.setVoId(vos.getSelectedObject().getId());
            groups.clearTable();
            groups.retrieveData();
        }
    });
    // initial fill listbox and trigger groups loading
    GetVos vosCall = new GetVos(new JsonCallbackEvents() {

        public void onLoadingStart() {
            vos.clear();
            vos.addItem("Loading...");
        }

        public void onFinished(JavaScriptObject jso) {
            vos.clear();
            ArrayList<VirtualOrganization> returnedVos = JsonUtils.jsoAsList(jso);
            returnedVos = new TableSorter<VirtualOrganization>().sortByName(returnedVos);
            if (returnedVos == null || returnedVos.isEmpty()) {
                vos.addItem("No VO available");
                return;
            }
            // put and set selected
            for (int i = 0; i < returnedVos.size(); i++) {
                vos.addItem(returnedVos.get(i));
                if (voId == returnedVos.get(i).getId()) {
                    vos.setSelected(returnedVos.get(i), true);
                }
            }
            // trigger loading of groups for selected VO
            groups.setVoId(vos.getSelectedObject().getId());
            groups.clearTable();
            groups.retrieveData();
        }

        public void onError(PerunError error) {
            vos.clear();
            vos.addItem("Error while loading");
        }
    });
    vosCall.retrieveData();
    // set width to 100%
    table.setWidth("100%");
    // add menu and table to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RichGroup(cz.metacentrum.perun.webgui.model.RichGroup) 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) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetAllRichGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllRichGroups) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 23 with ListBoxWithObjects

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

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

the class CopyFormTabItem 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
            int backupVoId = voId;
            if (vos.size() > 0) {
                backupVoId = vos.get(0).getId();
            }
            GetAllGroups getGroups = new GetAllGroups(backupVoId, 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) {
            CopyForm request = null;
            if (groupsBox.getSelectedIndex() != 0 && voId != 0 && groupId == 0) {
                // from group to VO
                request = new CopyForm(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 CopyForm(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 CopyForm(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 CopyForm(PerunEntity.VIRTUAL_ORGANIZATION, vosBox.getSelectedObject().getId(), PerunEntity.GROUP, groupId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            }
            request.copyForm();
        }
    });
    content.setHTML(2, 0, "All form items 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) CopyForm(cz.metacentrum.perun.webgui.json.registrarManager.CopyForm) 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) 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