Search in sources :

Example 26 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class SetNewAttributeTabItem method draw.

public Widget draw() {
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    // correct IDS for getting attrDefs
    if (ids.containsKey("resourceToGetServicesFrom")) {
        if (!ids.containsKey("resource")) {
            ids.put("resource", ids.get("resourceToGetServicesFrom"));
            ids.remove("resourceToGetServicesFrom");
        }
    }
    if (ids.containsKey("workWithUserAttributes")) {
        ids.remove("workWithUserAttributes");
    }
    if (ids.containsKey("workWithGroupAttributes")) {
        ids.remove("workWithGroupAttributes");
    }
    // set tab name
    String label = titleWidget.getText() + " (";
    for (Map.Entry<String, Integer> entry : ids.entrySet()) {
        label += entry.getKey() + ":" + String.valueOf(entry.getValue()) + " ";
    }
    label = label.substring(0, label.length() - 1) + ")";
    titleWidget.setText(label);
    // helper text
    String entityIds = "";
    for (Map.Entry<String, Integer> item : ids.entrySet()) {
        entityIds = entityIds.concat(" " + item.getKey() + ": " + item.getValue());
    }
    HTML helper = new HTML();
    String helperInside = "<p>Enter new values and press Enter key. Save changes by clicking on \"Save changes\" button. Values will be set for<strong>" + entityIds + ".</strong></p>";
    helper.setHTML(helperInside);
    // callback
    final GetAttributesDefinitionWithRights attrDef = new GetAttributesDefinitionWithRights(ids);
    // remove already used attributes from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            if (!inUse.isEmpty()) {
                for (Attribute a : inUse) {
                    attrDef.removeFromTable(a);
                }
            }
        }
    };
    attrDef.setEvents(localEvents);
    // filter core attributes
    attrDef.switchCore();
    // which entities to show
    Set<String> namespaces = getNamespacesForEntities(ids.keySet());
    // show only these attributes
    attrDef.setEntities(namespaces);
    // get table
    CellTable<Attribute> table = attrDef.getTable();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    // add save button
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, buttonTranslation.saveNewAttributes());
    final JsonCallbackEvents events = JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab);
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // Save the attributes
            ArrayList<Attribute> list = attrDef.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // separated list by entity
                ArrayList<Attribute> facilityList = new ArrayList<Attribute>();
                ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
                ArrayList<Attribute> userList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberGroupList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> resourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> hostList = new ArrayList<Attribute>();
                ArrayList<Attribute> voList = new ArrayList<Attribute>();
                ArrayList<Attribute> uesList = new ArrayList<Attribute>();
                for (Attribute a : list) {
                    if (a.getEntity().equalsIgnoreCase("facility")) {
                        facilityList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("user_facility")) {
                        userFacilityList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("resource")) {
                        resourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("user")) {
                        userList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member_resource")) {
                        memberResourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member")) {
                        memberList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("group")) {
                        groupList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("group_resource")) {
                        groupResourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("host")) {
                        hostList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("vo")) {
                        voList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member_group")) {
                        memberGroupList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("ues")) {
                        uesList.add(a);
                    }
                }
                // GROUPING BY IDS
                // GROUPING BY IDS
                SetAttributes request = new SetAttributes(events);
                if (ids.size() == 4 && ids.containsKey("facility") && ids.containsKey("user") && ids.containsKey("member") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(userList);
                    sendList.addAll(memberResourceList);
                    sendList.addAll(userFacilityList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("facility") && ids.containsKey("user")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(userList);
                    sendList.addAll(userFacilityList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("member") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(memberResourceList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("group") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(groupList);
                    sendList.addAll(groupResourceList);
                    // call proper method in RPC
                    ids.put("workWithGroupAttributes", 1);
                    request.setAttributes(ids, sendList);
                    ids.remove("workWithGroupAttributes");
                } else if (ids.size() == 2 && ids.containsKey("member") && ids.containsKey("user")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(userList);
                    // call proper method in RPC
                    ids.put("workWithUserAttributes", 1);
                    request.setAttributes(ids, sendList);
                    ids.remove("workWithUserAttributes");
                } else if (ids.size() == 2 && ids.containsKey("group") && ids.containsKey("member")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberGroupList);
                    // call proper method in RPC
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 1 && ids.containsKey("group")) {
                    request.setAttributes(ids, groupList);
                } else if (ids.size() == 1 && ids.containsKey("resource")) {
                    request.setAttributes(ids, resourceList);
                } else if (ids.size() == 1 && ids.containsKey("facility")) {
                    request.setAttributes(ids, facilityList);
                } else if (ids.size() == 1 && ids.containsKey("vo")) {
                    request.setAttributes(ids, voList);
                } else if (ids.size() == 1 && ids.containsKey("host")) {
                    request.setAttributes(ids, hostList);
                } else if (ids.size() == 1 && ids.containsKey("member")) {
                    request.setAttributes(ids, memberList);
                } else if (ids.size() == 1 && ids.containsKey("user")) {
                    request.setAttributes(ids, userList);
                } else if (ids.size() == 1 && ids.containsKey("userExtSource")) {
                    request.setAttributes(ids, uesList);
                } else {
                    String combination = "";
                    for (String key : ids.keySet()) {
                        combination += key + ": " + ids.get(key) + " | ";
                    }
                    UiElements.generateAlert("Wrong entities combination", "Unsupported combination of attributes to set: " + combination);
                }
            }
        }
    });
    menu.addWidget(saveButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addWidget(helper);
    mainTab.add(menu);
    mainTab.setCellHeight(menu, "30px");
    // table wrapper
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // do not resize like perun table to prevent wrong width in inner tab
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    // add table to the page
    mainTab.add(sp);
    //saveButton.setEnabled(false);
    //JsonUtils.addTableManagedButton(attrDef, table, saveButton);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) GetAttributesDefinitionWithRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinitionWithRights) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 27 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class AddAuthorTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add author");
    this.users = new FindCompleteRichUsers("", null);
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // PUB-INFO
    TabMenu info = new TabMenu();
    info.addWidget(new HTML("<strong>FULL&nbsp;CITE: </strong>" + publication.getMain()));
    firstTabPanel.add(info);
    // HORIZONTAL MENU
    TabMenu tabMenu = new TabMenu();
    // get the table
    final CellTable<User> table;
    if (session.isPerunAdmin()) {
        table = users.getTable(new FieldUpdater<User, String>() {

            public void update(int index, User object, String value) {
                session.getTabManager().addTab(new UserDetailTabItem(object));
            }
        });
    } else {
        table = users.getTable();
    }
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected user(s) as author(s) of publication: " + publication.getTitle());
    tabMenu.addWidget(addButton);
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(users, table, addButton);
    final TabItem tab = this;
    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<User> list = users.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // proceed
                for (int i = 0; i < list.size(); i++) {
                    final String name = list.get(i).getFullNameWithTitles();
                    // add name events
                    JsonCallbackEvents authorshipEvents = new JsonCallbackEvents() {

                        public void onFinished(JavaScriptObject jso) {
                            updateAlreadyAdded(name);
                        }
                    };
                    // merge with refresh?
                    if (i == list.size() - 1 && events != null) {
                        authorshipEvents = JsonCallbackEvents.mergeEvents(authorshipEvents, events);
                    }
                    // call
                    CreateAuthorship request = new CreateAuthorship(JsonCallbackEvents.disableButtonEvents(addButton, authorshipEvents));
                    request.createAuthorship(publicationId, list.get(i).getId());
                    if (i == list.size() - 1) {
                        users.clearTableSelectedSet();
                    }
                }
            }
        }
    });
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // trigger refresh of sub-tab via event
            events.onFinished(null);
            session.getTabManager().closeTab(tab, false);
        }
    }));
    tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            users.searchFor(text);
            searchString = text;
        }
    }, ButtonTranslation.INSTANCE.searchUsers());
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // add already added
    firstTabPanel.add(alreadyAddedAuthors);
    firstTabPanel.setCellHeight(alreadyAddedAuthors, "30px");
    // add table to the main panel
    firstTabPanel.add(sp);
    // do not resize like perun table to prevent wrong width in inner tab
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) User(cz.metacentrum.perun.webgui.model.User) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CreateAuthorship(cz.metacentrum.perun.webgui.json.cabinetManager.CreateAuthorship) FindCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 28 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class FacilitiesPropagationsTabItem method draw.

public Widget draw() {
    mainrow = 0;
    okCounter = 0;
    errorCounter = 0;
    notDeterminedCounter = 0;
    procesingCounter = 0;
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setWidth("100%");
    final TabItem tab = this;
    // MAIN PANEL
    final ScrollPanel firstTabPanel = new ScrollPanel();
    firstTabPanel.setSize("100%", "100%");
    firstTabPanel.setStyleName("perun-tableScrollPanel");
    final FlexTable help = new FlexTable();
    help.setCellPadding(4);
    help.setWidth("100%");
    help.setHTML(0, 0, "<strong>Color&nbsp;notation:</strong>");
    help.getFlexCellFormatter().setWidth(0, 0, "100px");
    help.setHTML(0, 1, "<strong>OK</strong>");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setWidth(0, 1, "50px");
    help.getFlexCellFormatter().setStyleName(0, 1, "green");
    help.setHTML(0, 2, "<strong>Error</strong>");
    help.getFlexCellFormatter().setWidth(0, 2, "50px");
    help.getFlexCellFormatter().setStyleName(0, 2, "red");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
    help.setHTML(0, 3, "<strong>Not&nbsp;determined</strong>");
    help.getFlexCellFormatter().setWidth(0, 3, "50px");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setStyleName(0, 3, "notdetermined");
    /*
			 help.setHTML(0, 4, "<strong>Processing</strong>");
			 help.getFlexCellFormatter().setWidth(0, 4, "50px");
			 help.getFlexCellFormatter().setStyleName(0, 4, "yellow");
			 help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
			 */
    final CustomButton cb = new CustomButton(ButtonTranslation.INSTANCE.refreshButton(), ButtonTranslation.INSTANCE.refreshPropagationResults(), SmallIcons.INSTANCE.updateIcon(), new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().reloadTab(tab);
        }
    });
    help.setWidget(0, 5, cb);
    help.getFlexCellFormatter().setWidth(0, 5, "200px");
    help.setHTML(0, 6, "&nbsp;");
    help.getFlexCellFormatter().setWidth(0, 6, "50%");
    mainTab.add(help);
    mainTab.add(new HTML("<hr size=\"2\" />"));
    mainTab.add(firstTabPanel);
    final FlexTable content = new FlexTable();
    content.setWidth("100%");
    content.setBorderWidth(0);
    firstTabPanel.add(content);
    content.setStyleName("propagationTable", true);
    final AjaxLoaderImage im = new AjaxLoaderImage();
    content.setWidget(0, 0, im);
    content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    final GetFacilityState callback = new GetFacilityState(0, 0, new JsonCallbackEvents() {

        public void onLoadingStart() {
            im.loadingStart();
            cb.setProcessing(true);
        }

        public void onError(PerunError error) {
            im.loadingError(error);
            cb.setProcessing(false);
        }

        public void onFinished(JavaScriptObject jso) {
            im.loadingFinished();
            cb.setProcessing(false);
            content.clear();
            content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
            ArrayList<FacilityState> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                list = new TableSorter<FacilityState>().sortByNumberOfDestinations(list);
                ArrayList<FacilityState> clusters = new ArrayList<FacilityState>();
                ArrayList<FacilityState> hosts = new ArrayList<FacilityState>();
                for (final FacilityState state : list) {
                    if (state.getDestinations().size() > 1) {
                        clusters.add(state);
                    } else {
                        hosts.add(state);
                    }
                }
                clusters = new TableSorter<FacilityState>().sortByFacilityName(clusters);
                hosts = new TableSorter<FacilityState>().sortByFacilityName(hosts);
                for (final FacilityState state : clusters) {
                    content.setHTML(mainrow, 0, "<strong>" + state.getFacility().getName() + "</strong>");
                    final FlowPanel inner = new FlowPanel();
                    content.setWidget(mainrow + 1, 0, inner);
                    content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    int width = 0;
                    for (String dest : destinations) {
                        destList.add(dest);
                        if (dest.indexOf(".") * 8 > width) {
                            width = dest.indexOf(".") * 8;
                        }
                    }
                    Collections.sort(destList);
                    for (final String dest : destList) {
                        String show = dest.substring(0, dest.indexOf("."));
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + show + "</span>");
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
                            }
                        });
                        inner.add(hyp);
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        notDeterminedCounter++;
                    }
                    mainrow++;
                    mainrow++;
                }
                // PROCESS HOSTS (with one or less destination)
                // FIX WIDTH
                int width = 0;
                for (FacilityState state : hosts) {
                    if (state.getDestinations().size() < 2) {
                        if (state.getFacility().getName().length() * 8 > width) {
                            width = state.getFacility().getName().length() * 8;
                        }
                    }
                }
                FlowPanel inner = new FlowPanel();
                for (final FacilityState state : hosts) {
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    for (String dest : destinations) {
                        destList.add(dest);
                    }
                    Collections.sort(destList);
                    for (final String dest : destList) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + dest + "</span>");
                        inner.add(hyp);
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
                            }
                        });
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + state.getFacility().getName() + "</span>");
                        inner.add(hyp);
                        hyp.addStyleName("notdetermined");
                        notDeterminedCounter++;
                    }
                }
                if (!hosts.isEmpty()) {
                    content.setHTML(mainrow, 0, "<strong>Single hosts</strong>");
                    mainrow++;
                }
                content.setWidget(mainrow, 0, inner);
                content.getFlexCellFormatter().setStyleName(mainrow, 0, "propagationTablePadding");
                mainrow++;
            }
            // set counters
            help.setHTML(0, 1, "<strong>Ok&nbsp;(" + okCounter + ")</strong>");
            help.setHTML(0, 2, "<strong>Error&nbsp;(" + errorCounter + ")</strong>");
            help.setHTML(0, 3, "<strong>Not&nbsp;determined&nbsp;(" + notDeterminedCounter + ")</strong>");
        //help.setHTML(0, 4, "<strong>Processing&nbsp;(" + procesingCounter + ")</strong>");
        }
    });
    // get for all facilities
    callback.retrieveData();
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Set(java.util.Set) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString) GetFacilityState(cz.metacentrum.perun.webgui.json.propagationStatsReader.GetFacilityState) FacilityState(cz.metacentrum.perun.webgui.model.FacilityState) GetFacilityState(cz.metacentrum.perun.webgui.json.propagationStatsReader.GetFacilityState) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError) JSONString(com.google.gwt.json.client.JSONString)

Example 29 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class AddGroupManagerGroupTabItem 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>();
    // pass empty items to menu to ensure drawing of rest
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    tabMenu.addWidget(new HTML(""));
    tabMenu.addWidget(new HTML(""));
    tabMenu.addWidget(3, new HTML("<strong>Select VO:</strong>"));
    tabMenu.addWidget(4, box);
    // 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();
    }
    final TabItem tab = this;
    tabMenu.addWidget(2, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            if (refreshEvents != null)
                refreshEvents.onFinished(null);
            session.getTabManager().closeTab(tab, false);
        }
    }));
    // add menu and the table to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    firstTabPanel.add(sp);
    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 30 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class AddGroupManagerGroupTabItem method fillGroupsContent.

private Widget fillGroupsContent(GetAllGroups groups, TabMenu tabMenu, final ListBoxWithObjects<VirtualOrganization> box) {
    getAllGroups = groups;
    getAllGroups.setCoreGroupsCheckable(true);
    final CellTable<Group> table = getAllGroups.getTable();
    getAllGroups.getSelectionModel().addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        private boolean found = false;

        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            for (Group g : getAllGroups.getTableSelectedList()) {
                if (g.isCoreGroup()) {
                    if (!found) {
                        // display only once
                        UiElements.generateInfo("You have selected 'all vo members' group", "If this group will be added as 'manager group', all new members of VO " + box.getSelectedObject().getName() + " will be automatically managers of your Group and all removed members will lose management rights.");
                    }
                    found = true;
                    return;
                }
            }
            found = false;
        }
    });
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersGroupToGroup());
    tabMenu.addWidget(1, addButton);
    final TabItem tab = this;
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Group> list = getAllGroups.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    if (i == list.size() - 1) {
                        AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                // close tab and refresh table
                                if (refreshEvents != null)
                                    refreshEvents.onFinished(null);
                                session.getTabManager().closeTab(tab, false);
                            }
                        }));
                        request.addGroupAdminGroup(group, list.get(i));
                    } else {
                        AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton));
                        request.addGroupAdminGroup(group, list.get(i));
                    }
                }
            }
        }
    });
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(getAllGroups, table, addButton);
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    return table;
}
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) AddAdmin(cz.metacentrum.perun.webgui.json.authzResolver.AddAdmin) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Aggregations

TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)84 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)76 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)76 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)71 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)68 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)56 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)54 ArrayList (java.util.ArrayList)47 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)30 PerunError (cz.metacentrum.perun.webgui.model.PerunError)21 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)19 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)14 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)13 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)13 User (cz.metacentrum.perun.webgui.model.User)13 Group (cz.metacentrum.perun.webgui.model.Group)11 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)11 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)10 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)10 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)10