Search in sources :

Example 1 with VoDetailTabItem

use of cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem 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>" + listbox.getSelectedObject().getName() + "</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("SUSPENDED")) {
                ir = SmallIcons.INSTANCE.stopIcon();
            } 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) {
                    FlexTable widget = new FlexTable();
                    final ListBox lb = new ListBox(false);
                    lb.addItem("VALID", "VALID");
                    lb.addItem("INVALID", "INVALID");
                    lb.addItem("SUSPENDED", "SUSPENDED");
                    lb.addItem("EXPIRED", "EXPIRED");
                    lb.addItem("DISABLED", "DISABLED");
                    widget.setHTML(0, 0, "<strong>Status: </strong>");
                    widget.setWidget(0, 1, lb);
                    // pick which one is already set
                    for (int i = 0; i < lb.getItemCount(); i++) {
                        if (lb.getItemText(i).equalsIgnoreCase(member.getStatus())) {
                            lb.setSelectedIndex(i);
                        }
                    }
                    Confirm conf = new Confirm("Change member's status", widget, true);
                    conf.setCancelButtonText("Cancel");
                    conf.setOkButtonText("Change status");
                    conf.setOkClickHandler(new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            SetStatus call = new SetStatus(member.getId(), new JsonCallbackEvents() {

                                @Override
                                public void onLoadingStart() {
                                    subContent.setWidget(new AjaxLoaderImage());
                                }

                                public void onFinished(JavaScriptObject jso) {
                                    subContent.setWidget(entryPanel);
                                    gmbu.retrieveData();
                                }

                                public void onError(PerunError error) {
                                    subContent.setWidget(entryPanel);
                                    gmbu.retrieveData();
                                }
                            });
                            call.setStatus(lb.getValue(lb.getSelectedIndex()));
                        }
                    });
                    conf.show();
                }
            });
            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) SetStatus(cz.metacentrum.perun.webgui.json.membersManager.SetStatus) 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 VoDetailTabItem

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

the class TestDataGridTabItem method draw.

public Widget draw() {
    //contentWidget.setSize("100%", "100%");
    DockLayoutPanel ft = new DockLayoutPanel(Style.Unit.PX);
    contentWidget.setWidget(ft);
    final DataGrid gridTable = new DataGrid();
    gridTable.setSize("100%", "100%");
    final ArrayList<VirtualOrganization> vosList = new ArrayList<VirtualOrganization>();
    final GetVos getVos = new GetVos(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosList.addAll(new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso)));
            gridTable.setRowData(vosList);
            gridTable.redraw();
        }
    });
    getVos.retrieveData();
    gridTable.setSelectionModel(new MultiSelectionModel<VirtualOrganization>(new GeneralKeyProvider<VirtualOrganization>()));
    final SelectionModel<VirtualOrganization> selectionModel = gridTable.getSelectionModel();
    Column<VirtualOrganization, Boolean> checkBoxColumn = new Column<VirtualOrganization, Boolean>(new CheckboxCell(true, true)) {

        @Override
        public Boolean getValue(VirtualOrganization object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkBoxColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, Boolean>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, Boolean aBoolean) {
            selectionModel.setSelected(virtualOrganization, aBoolean);
        }
    });
    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {

        public Boolean getValue() {
            //return true to see a checked checkbox.
            return false;
        }
    };
    checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {

        public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (VirtualOrganization obj : vosList) {
                selectionModel.setSelected(obj, value);
            }
        }
    });
    gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
    gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
    TextColumn<VirtualOrganization> idColumn = new TextColumn<VirtualOrganization>() {

        @Override
        public String getValue(VirtualOrganization object) {
            return String.valueOf(object.getId());
        }
    };
    gridTable.addColumn(idColumn, "Id", "Id");
    gridTable.setColumnWidth(idColumn, "90px");
    Column<VirtualOrganization, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<VirtualOrganization, String>() {

        public String getValue(VirtualOrganization object) {
            return object.getName();
        }
    }, new FieldUpdater<VirtualOrganization, String>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, String s) {
            session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
        }
    });
    gridTable.addColumn(nameColumn, "Name", "Name");
    TextColumn<VirtualOrganization> shortnameColumn = new TextColumn<VirtualOrganization>() {

        @Override
        public String getValue(VirtualOrganization object) {
            return object.getShortName();
        }
    };
    gridTable.addColumn(shortnameColumn, "Short name", "Short name");
    shortnameColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, String s) {
            session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
        }
    });
    idColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, String s) {
            session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
        }
    });
    nameColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, String s) {
            session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
        }
    });
    TabMenu tabMenu = new TabMenu();
    // CREATE & DELETE ONLY WITH PERUN ADMIN
    if (session.isPerunAdmin()) {
        tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createVo(), new ClickHandler() {

            public void onClick(ClickEvent event) {
                session.getTabManager().addTabToCurrentTab(new CreateVoTabItem());
            }
        }));
        final cz.metacentrum.perun.webgui.widgets.CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteVo());
        removeButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                final ArrayList<VirtualOrganization> itemsToRemove = getVos.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(itemsToRemove)) {
                    VerticalPanel removePanel = new VerticalPanel();
                    removePanel.add(new Label("These VOs will be removed:"));
                    for (int i = 0; i < itemsToRemove.size(); i++) {
                        VirtualOrganization vo = itemsToRemove.get(i);
                        removePanel.add(new Label(" - " + vo.getName()));
                    }
                    // confirmation
                    Confirm c = new Confirm("Remove VOs", removePanel, new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            for (int i = 0; i < itemsToRemove.size(); i++) {
                                DeleteVo request;
                                // if last, refresh
                                if (i == itemsToRemove.size() - 1) {
                                    request = new DeleteVo(JsonCallbackEvents.disableButtonEvents(removeButton));
                                } else {
                                    request = new DeleteVo(JsonCallbackEvents.disableButtonEvents(removeButton));
                                }
                                request.deleteVo(itemsToRemove.get(i).getId(), false);
                            }
                            getVos.clearTableSelectedSet();
                        }
                    }, true);
                    c.show();
                }
            }
        });
        tabMenu.addWidget(removeButton);
    }
    // filter
    tabMenu.addFilterWidget(new ExtendedSuggestBox(getVos.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            getVos.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterVo());
    ft.addNorth(tabMenu, 50);
    ft.add(gridTable);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) DataGrid(com.google.gwt.user.cellview.client.DataGrid) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) DeleteVo(cz.metacentrum.perun.webgui.json.vosManager.DeleteVo) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) CreateVoTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.CreateVoTabItem) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) TextColumn(com.google.gwt.user.cellview.client.TextColumn) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) GeneralKeyProvider(cz.metacentrum.perun.webgui.json.keyproviders.GeneralKeyProvider) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Header(com.google.gwt.user.cellview.client.Header) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem)

Example 3 with VoDetailTabItem

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

the class PerunWebSession method setActiveVo.

/**
	 * Sets currently active VO (refresh links in menu)
	 *
	 * @param vo VO which user is editing now
	 */
public void setActiveVo(VirtualOrganization vo) {
    this.activeVo = vo;
    addObjectToEntitiesHistory(vo.cast());
    // change default from list to active vo
    getUiElements().getMenu().setMenuTabItem(MainMenu.VO_ADMIN, new VoDetailTabItem(vo));
    // vo must refresh both
    getUiElements().getMenu().updateLinks(MainMenu.VO_ADMIN);
    getUiElements().getMenu().updateLinks(MainMenu.GROUP_ADMIN);
}
Also used : VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem)

Example 4 with VoDetailTabItem

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

the class UserDetailTabItem method loadInformationOverview.

// FIXME and TODO - all private methods should be separate TabItems !!! Connect them with user menu etc. ?
private Widget loadInformationOverview() {
    // content
    ScrollPanel scroll = new ScrollPanel();
    VerticalPanel extendedInfoVp = new VerticalPanel();
    extendedInfoVp.setStyleName("perun-table");
    scroll.setWidget(extendedInfoVp);
    scroll.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(scroll, 350, this);
    extendedInfoVp.setWidth("100%");
    // detail header
    Widget userHeader = new HTML("<h2>" + "User details" + "</h2>");
    extendedInfoVp.add(userHeader);
    extendedInfoVp.setCellHeight(userHeader, "30px");
    final TabItem tab = this;
    final JsonCallbackEvents events = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            user = jso.cast();
            tab.draw();
        }
    };
    CustomButton change = new CustomButton("", "Edit user", SmallIcons.INSTANCE.applicationFormEditIcon());
    change.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new EditUserDetailsTabItem(user, events));
        }
    });
    // detail content
    FlexTable layout = new FlexTable();
    layout.setCellSpacing(6);
    // Add some standard form options
    layout.setHTML(0, 0, "<strong>Full&nbsp;name:</strong>");
    layout.setHTML(0, 1, user.getFullNameWithTitles());
    layout.setWidget(0, 2, change);
    layout.setHTML(0, 3, "<strong>User&nbsp;ID:</strong>");
    layout.setHTML(0, 4, String.valueOf(user.getId()));
    layout.setHTML(0, 5, "<strong>User&nbsp;type:</strong>");
    if (user.isServiceUser()) {
        layout.setHTML(0, 6, "Service");
    } else if (user.isSponsoredUser()) {
        layout.setHTML(0, 6, "Sponsored");
    } else {
        layout.setHTML(0, 6, "Person");
    }
    // wrap the content in a DecoratorPanel
    DecoratorPanel decPanel = new DecoratorPanel();
    decPanel.setWidget(layout);
    extendedInfoVp.add(decPanel);
    // user attributes
    final GetAttributesV2 attributes = new GetAttributesV2();
    attributes.getUserAttributes(user.getId());
    CellTable<Attribute> tableAttributes = attributes.getTable();
    tableAttributes.addStyleName("perun-table");
    tableAttributes.setWidth("100%");
    Widget attributesHeader = new HTML("<h2>" + "User attributes" + "</h2>");
    extendedInfoVp.add(attributesHeader);
    extendedInfoVp.setCellHeight(attributesHeader, "30px");
    TabMenu menu = new TabMenu();
    final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for user");
    saveAttrButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            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 user", new ClickHandler() {

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

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
            request.removeAttributes(ids, list);
        }
    });
    menu.addWidget(removeAttrButton);
    extendedInfoVp.add(menu);
    extendedInfoVp.add(tableAttributes);
    // VOS
    GetVosWhereUserIsMember vos = new GetVosWhereUserIsMember(user.getId());
    vos.setCheckable(false);
    // get the table with custom onclick
    CellTable<VirtualOrganization> simpeVosTable = vos.getTable(new FieldUpdater<VirtualOrganization, VirtualOrganization>() {

        public void update(int index, VirtualOrganization object, VirtualOrganization value) {
            session.getTabManager().addTab(new VoDetailTabItem(object));
        }
    });
    // format the table
    simpeVosTable.addStyleName("perun-table");
    simpeVosTable.setWidth("100%");
    // simple table
    Widget vosHeader = new HTML("<h2>" + "Virtual organizations" + "</h2>");
    extendedInfoVp.add(vosHeader);
    extendedInfoVp.setCellHeight(vosHeader, "30px");
    extendedInfoVp.add(simpeVosTable);
    return scroll;
}
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) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) UsersPublicationsTabItem(cz.metacentrum.perun.webgui.tabs.cabinettabs.UsersPublicationsTabItem) ResourceDetailTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) FacilityDetailTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 5 with VoDetailTabItem

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

the class VosTabItem method draw.

public Widget draw() {
    // MAIN PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // Get vos request
    final GetVos getVos = new GetVos();
    // Events for reloading when finished
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(getVos);
    // create new VO button
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // add menu to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, buttonTranslation.createVo(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateVoTabItem());
        }
    }));
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, buttonTranslation.deleteVo());
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<VirtualOrganization> itemsToRemove = getVos.getTableSelectedList();
            UiElements.showDeleteConfirm(itemsToRemove, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < itemsToRemove.size(); i++) {
                        DeleteVo request;
                        if (i == itemsToRemove.size() - 1) {
                            request = new DeleteVo(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                        } else {
                            request = new DeleteVo(JsonCallbackEvents.disableButtonEvents(removeButton));
                        }
                        request.deleteVo(itemsToRemove.get(i).getId(), false);
                    }
                }
            });
        }
    });
    tabMenu.addWidget(removeButton);
    // filter
    tabMenu.addFilterWidget(new ExtendedSuggestBox(getVos.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            getVos.filterTable(text);
        }
    }, buttonTranslation.filterVo());
    // get the table with custom onclick
    CellTable<VirtualOrganization> table = getVos.getTable(new FieldUpdater<VirtualOrganization, VirtualOrganization>() {

        @Override
        public void update(int index, VirtualOrganization object, VirtualOrganization value) {
            session.getTabManager().addTab(new VoDetailTabItem(object));
        }
    });
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(getVos, table, removeButton);
    // 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 the table to the main panel
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, 0, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) DeleteVo(cz.metacentrum.perun.webgui.json.vosManager.DeleteVo) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CreateVoTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.CreateVoTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem)

Aggregations

VoDetailTabItem (cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem)5 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 ArrayList (java.util.ArrayList)4 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)2 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)2 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)2 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)2 DeleteVo (cz.metacentrum.perun.webgui.json.vosManager.DeleteVo)2 GetVos (cz.metacentrum.perun.webgui.json.vosManager.GetVos)2 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)2 SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)2 MemberDetailTabItem (cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem)2 CreateVoTabItem (cz.metacentrum.perun.webgui.tabs.vostabs.CreateVoTabItem)2 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 HashMap (java.util.HashMap)2