Search in sources :

Example 1 with GetVoExtSources

use of cz.metacentrum.perun.webgui.json.extSourcesManager.GetVoExtSources in project perun by CESNET.

the class AddVoExtSourceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add external source");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    final GetExtSources extSources = new GetExtSources();
    // remove already assigned ext sources from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // second callback
            final GetVoExtSources alreadyAssigned = new GetVoExtSources(voId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<ExtSource> esToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < esToRemove.length(); i++) {
                        extSources.removeFromTable(esToRemove.get(i));
                    }
                }
            });
            alreadyAssigned.retrieveData();
        }
    };
    extSources.setEvents(localEvents);
    extSources.setExtSourceTypeFilter("cz.metacentrum.perun.core.impl.ExtSourceX509");
    extSources.setExtSourceTypeFilter("cz.metacentrum.perun.core.impl.ExtSourceKerberos");
    extSources.setExtSourceTypeFilter("cz.metacentrum.perun.core.impl.ExtSourceIdp");
    final ExtendedSuggestBox box = new ExtendedSuggestBox(extSources.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<ExtSource> extSourcesToAdd = extSources.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(extSourcesToAdd)) {
                // FIXME - Should have only one callback to core
                for (int i = 0; i < extSourcesToAdd.size(); i++) {
                    final int n = i;
                    AddExtSource request = new AddExtSource(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {

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

        @Override
        public void searchFor(String text) {
            extSources.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<ExtSource> table = extSources.getTable();
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(extSources, table, assignButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    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().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JsArray(com.google.gwt.core.client.JsArray) GetExtSources(cz.metacentrum.perun.webgui.json.extSourcesManager.GetExtSources) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GetVoExtSources(cz.metacentrum.perun.webgui.json.extSourcesManager.GetVoExtSources) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) AddExtSource(cz.metacentrum.perun.webgui.json.extSourcesManager.AddExtSource) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtSource(cz.metacentrum.perun.webgui.model.ExtSource) AddExtSource(cz.metacentrum.perun.webgui.json.extSourcesManager.AddExtSource)

Example 2 with GetVoExtSources

use of cz.metacentrum.perun.webgui.json.extSourcesManager.GetVoExtSources in project perun by CESNET.

the class VoExtSourcesTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": " + "ext sources");
    // main panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    // refresh
    menu.addWidget(UiElements.getRefreshButton(this));
    // get VO resources
    final GetVoExtSources extSources = new GetVoExtSources(voId);
    // refresh table event
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(extSources);
    // create ext source button
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addExtSource(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AddVoExtSourceTabItem(voId), true);
        }
    });
    menu.addWidget(addButton);
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeExtSource());
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<ExtSource> extSourcesToRemove = extSources.getTableSelectedList();
            String text = "Following external sources will be removed from VO. You won't be able to import members from them anymore.";
            UiElements.showDeleteConfirm(extSourcesToRemove, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < extSourcesToRemove.size(); i++) {
                        RemoveExtSource request;
                        if (i == extSourcesToRemove.size() - 1) {
                            request = new RemoveExtSource(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                        } else {
                            request = new RemoveExtSource(JsonCallbackEvents.disableButtonEvents(removeButton));
                        }
                        request.removeVoExtSource(voId, extSourcesToRemove.get(i).getId());
                    }
                }
            });
        }
    });
    menu.addWidget(removeButton);
    // authorization - enable buttons for perun admin only.
    if (!session.isPerunAdmin()) {
        addButton.setEnabled(false);
        removeButton.setEnabled(false);
        extSources.setCheckable(false);
    }
    menu.addFilterWidget(new ExtendedSuggestBox(extSources.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            extSources.filterTable(text);
        }
    }, "Filter external sources by name or type");
    // add menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<ExtSource> table = extSources.getTable();
    if (session.isPerunAdmin()) {
        removeButton.setEnabled(false);
        JsonUtils.addTableManagedButton(extSources, table, removeButton);
    }
    table.addStyleName("perun-table");
    table.setWidth("100%");
    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) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GetVoExtSources(cz.metacentrum.perun.webgui.json.extSourcesManager.GetVoExtSources) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) ExtSource(cz.metacentrum.perun.webgui.model.ExtSource) RemoveExtSource(cz.metacentrum.perun.webgui.json.extSourcesManager.RemoveExtSource) RemoveExtSource(cz.metacentrum.perun.webgui.json.extSourcesManager.RemoveExtSource)

Example 3 with GetVoExtSources

use of cz.metacentrum.perun.webgui.json.extSourcesManager.GetVoExtSources in project perun by CESNET.

the class AddGroupExtSourceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add external source");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    menu.addWidget(new HTML(""));
    final GetVoExtSources extSources = new GetVoExtSources(group.getVoId());
    // remove already assigned ext sources from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // second callback
            final GetGroupExtSources alreadyAssigned = new GetGroupExtSources(groupId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<ExtSource> esToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < esToRemove.length(); i++) {
                        extSources.removeFromTable(esToRemove.get(i));
                    }
                }
            });
            alreadyAssigned.retrieveData();
        }
    };
    extSources.setEvents(localEvents);
    final ExtendedSuggestBox box = new ExtendedSuggestBox(extSources.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<ExtSource> extSourcesToAdd = extSources.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(extSourcesToAdd)) {
                // FIXME - Should have only one callback to core
                for (int i = 0; i < extSourcesToAdd.size(); i++) {
                    final int n = i;
                    AddExtSource request = new AddExtSource(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {

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

        @Override
        public void searchFor(String text) {
            extSources.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<ExtSource> table = extSources.getTable();
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(extSources, table, assignButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    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().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JsArray(com.google.gwt.core.client.JsArray) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GetVoExtSources(cz.metacentrum.perun.webgui.json.extSourcesManager.GetVoExtSources) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) AddExtSource(cz.metacentrum.perun.webgui.json.extSourcesManager.AddExtSource) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtSource(cz.metacentrum.perun.webgui.model.ExtSource) AddExtSource(cz.metacentrum.perun.webgui.json.extSourcesManager.AddExtSource) GetGroupExtSources(cz.metacentrum.perun.webgui.json.extSourcesManager.GetGroupExtSources)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 GetVoExtSources (cz.metacentrum.perun.webgui.json.extSourcesManager.GetVoExtSources)3 ExtSource (cz.metacentrum.perun.webgui.model.ExtSource)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)3 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 ArrayList (java.util.ArrayList)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 JsArray (com.google.gwt.core.client.JsArray)2 AddExtSource (cz.metacentrum.perun.webgui.json.extSourcesManager.AddExtSource)2 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 GetExtSources (cz.metacentrum.perun.webgui.json.extSourcesManager.GetExtSources)1 GetGroupExtSources (cz.metacentrum.perun.webgui.json.extSourcesManager.GetGroupExtSources)1 RemoveExtSource (cz.metacentrum.perun.webgui.json.extSourcesManager.RemoveExtSource)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1