Search in sources :

Example 1 with AddGroupUnion

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

the class AddGroupUnionTabItem method draw.

@Override
public Widget draw() {
    titleWidget.setText("Add group union");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    menu.addWidget(new HTML(""));
    final GetAllGroups groups = new GetAllGroups(group.getVoId());
    groups.setCoreGroupsCheckable(true);
    // remove already added union groups from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // second callback
            final GetGroupUnions alreadyAssigned = new GetGroupUnions(group, false, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<Group> esToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < esToRemove.length(); i++) {
                        groups.removeFromTable(esToRemove.get(i));
                    }
                    // remove itself
                    groups.removeFromTable(group);
                }
            });
            alreadyAssigned.retrieveData();
        }
    };
    groups.setEvents(localEvents);
    final ExtendedSuggestBox box = new ExtendedSuggestBox(groups.getOracle());
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedExtSource());
    final TabItem tab = this;
    assignButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<Group> groupsToAdd = groups.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(groupsToAdd)) {
                // FIXME - Should have only one callback to core
                for (int i = 0; i < groupsToAdd.size(); i++) {
                    final int n = i;
                    AddGroupUnion request = new AddGroupUnion(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // unselect added person
                            groups.getSelectionModel().setSelected(groupsToAdd.get(n), false);
                            alreadyAddedList.add(groupsToAdd.get(n));
                            rebuildAlreadyAddedWidget();
                            // clear search
                            box.getSuggestBox().setText("");
                        }
                    }));
                    request.createGroupUnion(group, groupsToAdd.get(i));
                }
            }
        }
    });
    menu.addFilterWidget(box, new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            groups.filterTable(text);
        }
    }, "Filter by ext source name or type");
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.add(alreadyAdded);
    CellTable<Group> table = groups.getTable();
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(groups, table, assignButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    // do not use resizePerunTable() when tab is in overlay - wrong width is calculated
    session.getUiElements().resizePerunTable(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) JsArray(com.google.gwt.core.client.JsArray) AddGroupUnion(cz.metacentrum.perun.webgui.json.groupsManager.AddGroupUnion) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) HTML(com.google.gwt.user.client.ui.HTML) 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) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetGroupUnions(cz.metacentrum.perun.webgui.json.groupsManager.GetGroupUnions) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsArray (com.google.gwt.core.client.JsArray)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 HTML (com.google.gwt.user.client.ui.HTML)1 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 AddGroupUnion (cz.metacentrum.perun.webgui.json.groupsManager.AddGroupUnion)1 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)1 GetGroupUnions (cz.metacentrum.perun.webgui.json.groupsManager.GetGroupUnions)1 Group (cz.metacentrum.perun.webgui.model.Group)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1