Search in sources :

Example 1 with GetAttributesV2

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.

the class UserDetailTabItem method loadMemberSubContent.

private void loadMemberSubContent(final SimplePanel subContent, final Hyperlink voLabel, final ListBoxWithObjects<VirtualOrganization> listbox) {
    subContent.setWidget(new AjaxLoaderImage());
    final GetMemberByUser gmbu = new GetMemberByUser(listbox.getSelectedObject().getId(), user.getId());
    JsonCallbackEvents loadEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // get member
            final Member member = jso.cast();
            // create content panel and put it on page
            final VerticalPanel entryPanel = new VerticalPanel();
            entryPanel.setStyleName("perun-table");
            entryPanel.setSize("100%", "100%");
            subContent.setWidget(entryPanel);
            voLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + SafeHtmlUtils.fromString((listbox.getSelectedObject().getName() != null) ? listbox.getSelectedObject().getName() : "").asString() + "</h2>"));
            voLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new VoDetailTabItem(listbox.getSelectedObject())));
            // detail header
            Widget memberHeader = new HTML("<h2>" + "Member details" + "</h2>");
            entryPanel.add(memberHeader);
            entryPanel.setCellHeight(memberHeader, "30px");
            // detail content
            FlexTable layout = new FlexTable();
            layout.setCellSpacing(6);
            // Add some standard form options
            layout.setHTML(0, 0, "<strong>Member&nbsp;ID:</strong>");
            layout.setHTML(0, 1, String.valueOf(member.getId()));
            ImageResource ir = null;
            // member status
            if (member.getStatus().equalsIgnoreCase("VALID")) {
                ir = SmallIcons.INSTANCE.acceptIcon();
            } else if (member.getStatus().equalsIgnoreCase("INVALID")) {
                ir = SmallIcons.INSTANCE.flagRedIcon();
            } else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
                ir = SmallIcons.INSTANCE.flagYellowIcon();
            } else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
                ir = SmallIcons.INSTANCE.binClosedIcon();
            }
            HTML status = new HTML("<a>" + member.getStatus() + " " + new Image(ir) + "</a>");
            layout.setHTML(1, 0, "<strong>Member status: </strong>");
            layout.setWidget(1, 1, status);
            // member status - on click action
            status.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    PerunWebSession.getInstance().getTabManager().addTabToCurrentTab(new ChangeStatusTabItem(member, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            loadMemberSubContent(subContent, voLabel, listbox);
                        }
                    }));
                }
            });
            final ListBoxWithObjects<Resource> resList = new ListBoxWithObjects<Resource>();
            GetAssignedResources res = new GetAssignedResources(member.getId(), PerunEntity.MEMBER, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    resList.clear();
                    ArrayList<Resource> list = JsonUtils.jsoAsList(jso);
                    if (list == null || list.isEmpty()) {
                        resList.addItem("No resources found");
                    } else {
                        list = new TableSorter<Resource>().sortByName(list);
                        resList.addNotSelectedOption();
                        resList.addAllItems(list);
                    }
                }

                @Override
                public void onError(PerunError error) {
                    resList.clear();
                    resList.addItem("Error while loading");
                }

                @Override
                public void onLoadingStart() {
                    resList.clear();
                    resList.addItem("Loading...");
                }
            });
            res.retrieveData();
            // link to member's detail
            Hyperlink link = new Hyperlink();
            link.setText("View detail");
            layout.setHTML(2, 0, "<strong>Member's detail page:</strong>");
            layout.setWidget(2, 1, link);
            link.setTargetHistoryToken(session.getTabManager().getLinkForTab(new MemberDetailTabItem(member.getId(), 0)));
            // wrap the content in a DecoratorPanel
            DecoratorPanel decPanel = new DecoratorPanel();
            decPanel.setWidget(layout);
            entryPanel.add(decPanel);
            entryPanel.setCellHeight(decPanel, "50px");
            // tables
            // detail header
            Widget groupHeader = new HTML("<h2>" + "Member groups" + "</h2>");
            entryPanel.add(groupHeader);
            entryPanel.setCellHeight(groupHeader, "30px");
            final GetMemberGroups groups = new GetMemberGroups(member.getId());
            groups.setCheckable(false);
            groups.setEditable(false);
            CellTable<Group> table = groups.getTable();
            table.addStyleName("perun-table");
            table.setWidth("100%");
            entryPanel.add(table);
            // detail header
            Widget attrHeader = new HTML("<h2>" + "Member / Member-resource attributes" + "</h2>");
            entryPanel.add(attrHeader);
            entryPanel.setCellHeight(attrHeader, "30px");
            final GetAttributesV2 attributes = new GetAttributesV2();
            attributes.getMemberAttributes(member.getId());
            resList.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(ChangeEvent event) {
                    if (resList.getSelectedIndex() == 0) {
                        attributes.getMemberAttributes(member.getId());
                        attributes.retrieveData();
                    } else {
                        attributes.getMemberResourceAttributes(member.getId(), resList.getSelectedObject().getId());
                        attributes.retrieveData();
                    }
                }
            });
            TabMenu menu = new TabMenu();
            final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for member");
            saveAttrButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    ArrayList<Attribute> list = attributes.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        Map<String, Integer> ids = new HashMap<String, Integer>();
                        ids.put("member", member.getId());
                        if (resList.getSelectedIndex() > 0) {
                            ids.put("resource", resList.getSelectedObject().getId());
                        }
                        SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
                        request.setAttributes(ids, list);
                    }
                }
            });
            menu.addWidget(saveAttrButton);
            menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Set new attributes for member", new ClickHandler() {

                public void onClick(ClickEvent event) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("member", member.getId());
                    if (resList.getSelectedIndex() > 0) {
                        ids.put("resource", resList.getSelectedObject().getId());
                    }
                    session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
                }
            }));
            final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes from member");
            removeAttrButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    ArrayList<Attribute> list = attributes.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        Map<String, Integer> ids = new HashMap<String, Integer>();
                        ids.put("member", member.getId());
                        if (resList.getSelectedIndex() > 0) {
                            ids.put("resource", resList.getSelectedObject().getId());
                        }
                        RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
                        request.removeAttributes(ids, list);
                    }
                }
            });
            menu.addWidget(removeAttrButton);
            menu.addWidget(new HTML("<strong>Resource:</strong>"));
            menu.addWidget(resList);
            entryPanel.add(menu);
            CellTable<Attribute> attrTable = attributes.getTable();
            attrTable.addStyleName("perun-table");
            attrTable.setWidth("100%");
            entryPanel.add(attrTable);
        }

        @Override
        public void onError(PerunError error) {
            subContent.setWidget(new AjaxLoaderImage().loadingError(error));
        }
    };
    // set events & load data
    gmbu.setEvents(loadEvent);
    gmbu.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) ImageResource(com.google.gwt.resources.client.ImageResource) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ChangeStatusTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.ChangeStatusTabItem) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ImageResource(com.google.gwt.resources.client.ImageResource) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) GetAssignedResources(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources) HashMap(java.util.HashMap) Map(java.util.Map) GetMemberGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 2 with GetAttributesV2

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.

the class UserExtSourceSettingsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(userExtSource.getLogin().trim()));
    // MAIN TAB PANEL
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // MENU
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    final GetAttributesV2 callback = new GetAttributesV2(true);
    callback.getUserExtSourceAttributes(userExtSource.getId());
    final CellTable<Attribute> table = callback.getEmptyTable();
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    menu.addWidget(UiElements.getRefreshButton(this));
    // save changes in attributes
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
                SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        callback.clearTable();
                        callback.getUserExtSourceAttributes(userExtSourceId);
                        callback.retrieveData();
                    }
                }));
                final Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("userExtSource", userExtSourceId);
                request.setAttributes(ids, callback.getTableSelectedList());
            }
        }
    });
    menu.addWidget(saveChangesButton);
    // buttons
    CustomButton setNewMemberAttributeButton = 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("userExtSource", userExtSource.getId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids), true);
        }
    });
    menu.addWidget(setNewMemberAttributeButton);
    // REMOVE ATTRIBUTES BUTTON
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // if selected
            if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("userExtSource", userExtSource.getId());
                RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        callback.clearTable();
                        callback.getUserExtSourceAttributes(userExtSource.getId());
                        callback.retrieveData();
                    }
                }));
                // make removeAttributes call
                request.removeAttributes(ids, callback.getTableSelectedList());
            }
        }
    });
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeButton);
    menu.addWidget(removeButton);
    callback.retrieveData();
    // ATTRIBUTES TABLE
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 3 with GetAttributesV2

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.

the class SelfResourcesSettingsTabItem method loadSettings.

/**
 * Load settings for each resource (loaded only once onClick on header)
 *
 * @return settings content for each resource
 */
private void loadSettings(final DisclosurePanel settings, final Resource resource) {
    // create content table
    final FlexTable layoutx = new FlexTable();
    layoutx.setCellSpacing(5);
    GetAttributesV2 resourceAttrsCall = new GetAttributesV2();
    Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resource", resource.getId());
    resourceAttrsCall.setIds(ids);
    resourceAttrsCall.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            boolean disableOptOut = false;
            ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
            for (Attribute a : attrs) {
                if ("urn:perun:resource:attribute-def:def:disableMailingListOptOut".equals(a.getName())) {
                    disableOptOut = true;
                    break;
                }
            }
            loadContent(layoutx, resource, disableOptOut);
        }

        public void onLoadingStart() {
            AjaxLoaderImage loader = new AjaxLoaderImage(true);
            layoutx.setWidget(0, 0, loader.loadingStart());
        }

        public void onError(PerunError error) {
            AjaxLoaderImage loader = new AjaxLoaderImage(true);
            layoutx.setWidget(0, 0, loader.loadingError(error));
        }
    });
    // load content on open
    settings.addOpenHandler(new OpenHandler<DisclosurePanel>() {

        public void onOpen(OpenEvent<DisclosurePanel> event) {
            if (settings.getContent() == null) {
                resourceAttrsCall.retrieveData();
                // set content
                settings.setContent(layoutx);
            }
        }
    });
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) HashMap(java.util.HashMap) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ArrayList(java.util.ArrayList) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 4 with GetAttributesV2

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.

the class FacilityHostsSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts settings");
    // main panel
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    final GetAttributesV2 attrs = new GetAttributesV2();
    final ListBoxWithObjects<Host> listbox = new ListBoxWithObjects<Host>();
    // refresh attributes for hosts
    listbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (listbox.getSelectedObject() != null) {
                lastSelectedHostId = listbox.getSelectedObject().getId();
                attrs.getHostAttributes(lastSelectedHostId);
                attrs.retrieveData();
            } else {
                lastSelectedHostId = 0;
            }
        }
    });
    // retrieve hosts
    final GetHosts hosts = new GetHosts(facilityId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            listbox.clear();
            ArrayList<Host> result = JsonUtils.jsoAsList(jso);
            if (result != null && !result.isEmpty()) {
                for (Host h : result) {
                    listbox.addItem(h);
                    if (h.getId() == lastSelectedHostId) {
                        listbox.setSelected(h, true);
                    }
                }
                if (lastSelectedHostId == 0) {
                    lastSelectedHostId = listbox.getSelectedObject().getId();
                }
                attrs.getHostAttributes(lastSelectedHostId);
                attrs.retrieveData();
            }
        }

        @Override
        public void onError(PerunError error) {
            listbox.clear();
            listbox.addItem("Error while loading");
        }

        @Override
        public void onLoadingStart() {
            listbox.clear();
            listbox.addItem("Loading...");
        }
    });
    hosts.retrieveData();
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(attrs);
    // menu
    TabMenu menu = new TabMenu();
    // Save changes button
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, events);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("host", lastSelectedHostId);
                SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    // Remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("host", lastSelectedHostId);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("host", lastSelectedHostId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attrs.getList()), true);
        }
    }));
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Select host:</strong>"));
    menu.addWidget(listbox);
    // attrs table
    CellTable<Attribute> table = attrs.getEmptyTable();
    // 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 and the table to the main panel
    firstTabPanel.add(menu);
    firstTabPanel.setCellHeight(menu, "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) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) GetHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts) 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) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) Host(cz.metacentrum.perun.webgui.model.Host) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) 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) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 5 with GetAttributesV2

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.

the class VoSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": settings");
    // MAIN PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    // refresh
    menu.addWidget(UiElements.getRefreshButton(this));
    // Get Attributes
    final GetAttributesV2 jsonCallback = new GetAttributesV2();
    // We want VO attributes
    jsonCallback.getVoAttributes(voId);
    // get the table
    CellTable<Attribute> table = jsonCallback.getTable();
    if (!session.isVoAdmin(voId))
        jsonCallback.setCheckable(false);
    final CustomButton setButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(setButton);
    if (!session.isVoAdmin(voId))
        setButton.setEnabled(false);
    // refresh table
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(jsonCallback);
    // set button event with button disable
    final JsonCallbackEvents setButtonEvent = JsonCallbackEvents.disableButtonEvents(setButton, events);
    setButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("vo", voId);
                SetAttributes request = new SetAttributes(setButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("vo", voId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, jsonCallback.getList()), true);
        }
    });
    menu.addWidget(addButton);
    if (!session.isVoAdmin(voId))
        addButton.setEnabled(false);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    menu.addWidget(removeButton);
    if (!session.isVoAdmin(voId))
        removeButton.setEnabled(false);
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("vo", voId);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    // 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");
    if (session.isVoAdmin(voId))
        JsonUtils.addTableManagedButton(jsonCallback, table, removeButton);
    // add menu and the table to the main panel
    firstTabPanel.add(menu);
    firstTabPanel.setCellHeight(menu, "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) Attribute(cz.metacentrum.perun.webgui.model.Attribute) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Aggregations

GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)10 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)8 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)8 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)8 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)8 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)8 SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)8 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)8 Map (java.util.Map)8 Attribute (cz.metacentrum.perun.webgui.model.Attribute)5 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)3 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)3 ImageResource (com.google.gwt.resources.client.ImageResource)2 GetAssignedResources (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 FacilityDetailTabItem (cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem)2