Search in sources :

Example 6 with GetAllGroups

use of cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups in project perun by CESNET.

the class CreateGroupTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    // used for closing
    final TabItem tab = this;
    // form inputs
    final ExtendedTextBox groupNameTextBox = new ExtendedTextBox();
    final TextBox groupDescriptionTextBox = new TextBox();
    final ListBoxWithObjects<Group> vosGroups = new ListBoxWithObjects<Group>();
    vosGroups.setVisible(false);
    final CheckBox asSubGroup = new CheckBox("", false);
    TabMenu menu = new TabMenu();
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "");
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    final HTML parentGroupText = new HTML("Parent group:");
    parentGroupText.setVisible(false);
    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);
            for (Group g : retGroups) {
                if (!g.isCoreGroup()) {
                    // SKIP CORE GROUPS !!
                    vosGroups.addItem(g);
                    if (g.getId() == groupId) {
                        // select default if passed to tab
                        vosGroups.setSelected(g, true);
                    }
                }
            }
            if (vosGroups.getAllObjects().isEmpty()) {
                vosGroups.addItem("No groups found");
            } else {
                createButton.setEnabled(true);
            }
            // call finished when user changed his mind
            if (!asSubGroup.getValue()) {
                createButton.setEnabled(true);
            }
        }

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

        public void onError(PerunError error) {
            vosGroups.clear();
            vosGroups.addItem("Error while loading");
            if (!asSubGroup.getValue()) {
                createButton.setEnabled(true);
            }
        }
    });
    // set title
    if (PerunEntity.GROUP.equals(entity)) {
        this.titleWidget.setText("Create sub-group");
        asSubGroup.setValue(true);
        createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
        parentGroupText.setVisible(true);
        vosGroups.setVisible(true);
        groupsCall.retrieveData();
    } else {
        this.titleWidget.setText("Create group");
        createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
    }
    asSubGroup.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
            if (booleanValueChangeEvent.getValue() == true) {
                // set title
                titleWidget.setText("Create sub-group");
                vosGroups.setVisible(true);
                parentGroupText.setVisible(true);
                groupsCall.retrieveData();
                createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
            } else {
                titleWidget.setText("Create group");
                vosGroups.setVisible(false);
                parentGroupText.setVisible(false);
                createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
                createButton.setEnabled(true);
            }
        }
    });
    // layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (groupNameTextBox.getTextBox().getText().trim().isEmpty()) {
                groupNameTextBox.setError("Name can't be empty.");
            } else if (!groupNameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
                groupNameTextBox.setError("Name can contain only a-z, A-Z, numbers, spaces, dots, '_' and '-'.");
            } else {
                groupNameTextBox.setOk();
                return true;
            }
            return false;
        }
    };
    groupNameTextBox.setValidator(validator);
    // send button
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (!validator.validateTextBox())
                return;
            // creates a new request
            CreateGroup cg = new CreateGroup(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
            if (asSubGroup.getValue()) {
                if (vosGroups.getSelectedObject() != null) {
                    cg.createGroupInGroup(vosGroups.getSelectedObject().getId(), groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText().trim());
                } else {
                    UiElements.generateInfo("No parent group selected", "You checked create this group as sub-group, but no parent group is selected. Please select parent group.");
                }
            } else {
                cg.createGroupInVo(voId, groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText().trim());
            }
        }
    });
    // cancel button
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    // Add some standard form options
    layout.setHTML(0, 0, "Name:");
    layout.setWidget(0, 1, groupNameTextBox);
    layout.setHTML(1, 0, "Description:");
    layout.setWidget(1, 1, groupDescriptionTextBox);
    layout.setHTML(2, 0, "As sub-group:");
    layout.setWidget(2, 1, asSubGroup);
    layout.setWidget(3, 0, parentGroupText);
    layout.setWidget(3, 1, vosGroups);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    // button align
    menu.addWidget(createButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) CreateGroup(cz.metacentrum.perun.webgui.json.groupsManager.CreateGroup) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) CreateGroup(cz.metacentrum.perun.webgui.json.groupsManager.CreateGroup) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 7 with GetAllGroups

use of cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups 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) {
            if (refreshEvents != null)
                refreshEvents.onFinished(null);
            session.getTabManager().closeTab(tab, false);
        }
    }));
    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 8 with GetAllGroups

use of cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups 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
            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) {
            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));
            } 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));
            } 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));
            } 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));
            }
            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, false);
        }
    }));
    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)

Example 9 with GetAllGroups

use of cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups 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));
            } 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));
            } 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));
            } 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));
            }
            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, false);
        }
    }));
    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 10 with GetAllGroups

use of cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups in project perun by CESNET.

the class AssignGroupTabItem method draw.

public Widget draw() {
    titleWidget.setText("Assign group");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    final GetAllGroups voGroups = new GetAllGroups(resource.getVoId());
    voGroups.setCoreGroupsCheckable(true);
    final CellTable<Group> table = voGroups.getEmptyTable(new FieldUpdater<Group, String>() {

        public void update(int index, Group object, String value) {
            session.getTabManager().addTab(new GroupDetailTabItem(object));
        }
    });
    // remove already assigned groups from offering
    voGroups.setEvents(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            final GetAssignedGroups alreadyAssigned = new GetAssignedGroups(resourceId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<Group> groupsToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < groupsToRemove.length(); i++) {
                        voGroups.removeFromTable(groupsToRemove.get(i));
                    }
                    // if single group, select
                    if (voGroups.getList().size() == 1) {
                        table.getSelectionModel().setSelected(voGroups.getList().get(0), true);
                    }
                }
            });
            alreadyAssigned.retrieveData();
        }
    });
    // checbox is selected by default
    final CheckBox chb = new CheckBox();
    chb.setText(WidgetTranslation.INSTANCE.configureGroupBeforeAssign());
    chb.setTitle(WidgetTranslation.INSTANCE.configureGroupBeforeAssignTitle());
    chb.setValue(false);
    final TabItem tab = this;
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedGroupsToResource());
    assignButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Group> groupsToAssign = voGroups.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(groupsToAssign)) {
                if (chb.getValue() == false) {
                    AssignGroupsToResource request = new AssignGroupsToResource(JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
                    request.assignGroupsToResource(groupsToAssign, resource);
                }
                if (chb.getValue() == true) {
                    session.getTabManager().addTabToCurrentTab(new ManageGroupsBeforeAssigning(resource, groupsToAssign), true);
                }
            }
        }
    });
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addFilterWidget(new ExtendedSuggestBox(voGroups.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            voGroups.filterTable(text);
            // if single group, select
            if (voGroups.getList().size() == 1) {
                table.getSelectionModel().setSelected(voGroups.getList().get(0), true);
            }
        }
    }, ButtonTranslation.INSTANCE.filterGroup());
    if (session.isPerunAdmin()) {
        // TODO - now is for testing so perun admin only
        menu.addWidget(chb);
    }
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(voGroups, table, assignButton);
    voGroups.retrieveData();
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) GetAssignedGroups(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups) AssignGroupsToResource(cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)10 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)10 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)10 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)10 ArrayList (java.util.ArrayList)10 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)9 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)9 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)8 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)7 Group (cz.metacentrum.perun.webgui.model.Group)6 PerunError (cz.metacentrum.perun.webgui.model.PerunError)6 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)5 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)5 GetVos (cz.metacentrum.perun.webgui.json.vosManager.GetVos)5 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)5 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)5 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)3 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)3 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)2 TableSorter (cz.metacentrum.perun.webgui.client.resources.TableSorter)2