Search in sources :

Example 6 with RichMember

use of cz.metacentrum.perun.webgui.model.RichMember in project perun by CESNET.

the class VoMembersTabItem method draw.

public Widget draw() {
    // SET TAB NAME
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": members");
    // MAIN PANEL
    final VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // MENU
    TabMenu tabMenu = new TabMenu();
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // DISABLED CHECKBOX
    final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
    disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
    disabled.setValue(wasDisabled);
    disabled.setVisible(false);
    // CALLBACKS
    final GetCompleteRichMembers members = new GetCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, null);
    final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, "", null);
    members.excludeDisabled(!wasDisabled);
    final CustomButton searchButton = TabMenu.getPredefinedButton(ButtonType.SEARCH, ButtonTranslation.INSTANCE.searchMemberInVo());
    final CustomButton listAllButton = TabMenu.getPredefinedButton(ButtonType.LIST_ALL_MEMBERS, ButtonTranslation.INSTANCE.listAllMembersInVo());
    if (!session.isVoAdmin(voId))
        findMembers.setCheckable(false);
    final CellTable<RichMember> table = findMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {

        // when user click on a row -> open new tab
        public void update(int index, RichMember object, RichMember value) {
            session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), 0));
        }
    });
    // refresh
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // ADD
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMemberToVo(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AddMemberToVoTabItem(voId), true);
        }
    });
    if (!session.isVoAdmin(voId))
        addButton.setEnabled(false);
    tabMenu.addWidget(addButton);
    // REMOVE
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMemberFromVo());
    if (!session.isVoAdmin(voId))
        removeButton.setEnabled(false);
    tabMenu.addWidget(removeButton);
    /*
		final CustomButton addServiceButton = new CustomButton(ButtonTranslation.INSTANCE.createServiceMemberButton(), ButtonTranslation.INSTANCE.createServiceMember(), SmallIcons.INSTANCE.addIcon(), new ClickHandler() {
			public void onClick(ClickEvent clickEvent) {
				session.getTabManager().addTabToCurrentTab(new CreateServiceMemberInVoTabItem(vo));
			}
		});
		if (!session.isVoAdmin(voId)) addServiceButton.setEnabled(false);
		tabMenu.addWidget(addServiceButton);
		*/
    // refreshMembers
    final JsonCallbackEvents refreshEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            if (search) {
                findMembers.searchFor(searchString);
            } else {
                findMembers.clearTable();
                members.retrieveData();
            }
        }
    };
    // add click handler for remove button
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // state specific events
            final ArrayList<RichMember> membersForRemoving = findMembers.getTableSelectedList();
            String text = "Following members will be removed from VO and their settings will be lost.<p>You can consider changing their status to \"DISABLED\", which will prevent them from accessing VO resources.";
            UiElements.showDeleteConfirm(membersForRemoving, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < membersForRemoving.size(); i++) {
                        DeleteMember request;
                        if (i == membersForRemoving.size() - 1) {
                            request = new DeleteMember(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
                        } else {
                            request = new DeleteMember(JsonCallbackEvents.disableButtonEvents(removeButton));
                        }
                        request.deleteMember(membersForRemoving.get(i).getId());
                    }
                }
            });
        }
    });
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        public void searchFor(String text) {
            searchString = text;
            search = true;
            findMembers.searchFor(text);
        }
    }, searchButton);
    searchBox.getTextBox().setText(searchString);
    // checkbox click handler
    disabled.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            wasDisabled = disabled.getValue();
            if (search) {
                // case when update but not triggered by button
                searchString = searchBox.getTextBox().getText();
                members.excludeDisabled(!disabled.getValue());
            } else {
                members.excludeDisabled(!disabled.getValue());
                members.retrieveData();
            }
        }
    });
    findMembers.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(searchButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            searchBox.getTextBox().setEnabled(true);
            listAllButton.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            searchBox.getTextBox().setEnabled(true);
            listAllButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            searchBox.getTextBox().setEnabled(false);
            listAllButton.setEnabled(false);
            disabled.setVisible(false);
        }
    }));
    members.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(listAllButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // pass data to table handling callback
            findMembers.onFinished(jso);
            ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("VO has no members.");
            searchBox.getTextBox().setEnabled(true);
            searchButton.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            // pass data to table handling callback
            findMembers.onError(error);
            searchBox.getTextBox().setEnabled(true);
            searchButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            searchBox.getTextBox().setEnabled(false);
            searchButton.setEnabled(false);
            disabled.setVisible(true);
            // to show progress when reloading
            ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
        }
    }));
    // LIST ALL BUTTON
    listAllButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            search = false;
            searchString = "";
            searchBox.getTextBox().setText("");
            findMembers.clearTable();
            members.retrieveData();
        }
    });
    tabMenu.addWidget(listAllButton);
    tabMenu.addWidget(disabled);
    /* WHEN TAB RELOADS, CHECK THE STATE */
    if (search) {
        findMembers.searchFor(searchString);
    } else {
        members.excludeDisabled(!disabled.getValue());
        members.retrieveData();
    }
    ScrollPanel tableWrapper = new ScrollPanel();
    table.addStyleName("perun-table");
    tableWrapper.setWidget(table);
    tableWrapper.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(tableWrapper, 350, this);
    // add menu and the table to the main panel
    firstTabPanel.add(tableWrapper);
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findMembers, table, removeButton);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AddMemberToVoTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.AddMemberToVoTabItem) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) RichMember(cz.metacentrum.perun.webgui.model.RichMember) DeleteMember(cz.metacentrum.perun.webgui.json.membersManager.DeleteMember) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Example 7 with RichMember

use of cz.metacentrum.perun.webgui.model.RichMember in project perun by CESNET.

the class PerunStatusWidget method getChangeStatusButton.

/**
	 * Changing status button
	 * @return the widget
	 */
private Widget getChangeStatusButton() {
    Anchor button = new Anchor("change");
    button.setTitle("Change status for " + objectName + ".");
    button.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            RichMember member = object.cast();
            JsonCallbackEvents newEvent = JsonCallbackEvents.mergeEvents(events, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    Member m = jso.cast();
                    object.setStatus(m.getStatus());
                    build();
                }
            });
            PerunWebSession.getInstance().getTabManager().addTabToCurrentTab(new ChangeStatusTabItem(member, newEvent));
        }
    });
    return button;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ChangeStatusTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.ChangeStatusTabItem) RichMember(cz.metacentrum.perun.webgui.model.RichMember) Member(cz.metacentrum.perun.webgui.model.Member) RichMember(cz.metacentrum.perun.webgui.model.RichMember)

Example 8 with RichMember

use of cz.metacentrum.perun.webgui.model.RichMember in project perun by CESNET.

the class AddRemoveItemsTable method buildWidget.

/**
	 * Rebuild widget GUI
	 */
private void buildWidget() {
    FlexTable ft = new FlexTable();
    ft.setStyleName("perun-table");
    widget.clear();
    widget.add(ft);
    if (list.isEmpty()) {
        ft.setHTML(0, 0, "<strong>No items found.</strong>");
        ft.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP);
    }
    int row = 0;
    int column = 0;
    for (final T object : list) {
        GeneralObject go = object.cast();
        String name = "";
        if ("User".equalsIgnoreCase(go.getObjectType())) {
            User u = go.cast();
            name = u.getFullNameWithTitles();
        } else if ("RichUser".equalsIgnoreCase(go.getObjectType())) {
            User u = go.cast();
            name = u.getFullNameWithTitles();
        } else if ("RichMember".equalsIgnoreCase(go.getObjectType())) {
            RichMember m = go.cast();
            name = m.getUser().getFullNameWithTitles();
        } else {
            name = ((GeneralObject) object).getName();
        }
        CustomButton rb = new CustomButton("", "Remove item", SmallIcons.INSTANCE.deleteIcon());
        rb.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent clickEvent) {
                removeItem(object);
            }
        });
        if (vertical) {
            ft.setHTML(row, 0, name);
            ft.setWidget(row, 1, rb);
            row++;
        } else {
            ft.setHTML(row, column, name);
            ft.setWidget(row, column + 1, rb);
            column = column + 2;
        }
    }
    widget.setSize("100%", "100%");
    widget.setStyleName("perun-tableScrollPanel", true);
    UiElements.runResizeCommands(true);
}
Also used : User(cz.metacentrum.perun.webgui.model.User) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject) RichMember(cz.metacentrum.perun.webgui.model.RichMember)

Example 9 with RichMember

use of cz.metacentrum.perun.webgui.model.RichMember in project perun by CESNET.

the class MemberColumnProvider method addStatusColumn.

public void addStatusColumn(IsClickableCell authz, int width) {
    // Status column
    final Column<RichMember, String> statusColumn = new Column<RichMember, String>(new PerunStatusCell()) {

        @Override
        public String getValue(RichMember object) {
            return object.getStatus();
        }
    };
    // own onClick tab for changing member's status
    statusColumn.setFieldUpdater(new FieldUpdater<RichMember, String>() {

        @Override
        public void update(final int index, final RichMember object, final String value) {
            PerunWebSession.getInstance().getTabManager().addTabToCurrentTab(new ChangeStatusTabItem(object, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    Member m = jso.cast();
                    // set status to object in cell to change rendered value
                    object.setStatus(m.getStatus());
                    // because they are not updated during .update() on cell
                    for (RichMember rm : dataProvider.getList()) {
                        if (rm.getId() == m.getId()) {
                            rm.setStatus(m.getStatus());
                        }
                    }
                    if (backupList != null) {
                        for (RichMember rm : backupList) {
                            if (rm.getId() == m.getId()) {
                                rm.setStatus(m.getStatus());
                            }
                        }
                    }
                    dataProvider.refresh();
                    dataProvider.flush();
                }
            }));
        }
    });
    // add column
    table.addColumn(statusColumn, "Status");
    if (width != 0) {
        table.setColumnWidth(statusColumn, width, Style.Unit.PX);
    }
    // status column sortable
    statusColumn.setSortable(true);
    table.getColumnSortHandler().setComparator(statusColumn, new GeneralComparator<RichMember>(GeneralComparator.Column.STATUS));
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RichMember(cz.metacentrum.perun.webgui.model.RichMember) Column(com.google.gwt.user.cellview.client.Column) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunStatusCell(cz.metacentrum.perun.webgui.widgets.cells.PerunStatusCell) ChangeStatusTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.ChangeStatusTabItem) Member(cz.metacentrum.perun.webgui.model.Member) RichMember(cz.metacentrum.perun.webgui.model.RichMember)

Example 10 with RichMember

use of cz.metacentrum.perun.webgui.model.RichMember in project perun by CESNET.

the class MemberColumnProvider method addOrganizationColumn.

public void addOrganizationColumn(IsClickableCell authz, int width) {
    // create column
    Column<RichMember, RichMember> organizationColumn = JsonUtils.addColumn(new CustomClickableTextCellWithAuthz<RichMember>(authz, "organization"), new JsonUtils.GetValue<RichMember, RichMember>() {

        @Override
        public RichMember getValue(RichMember object) {
            return object;
        }
    }, fieldUpdater);
    // add column
    table.addColumn(organizationColumn, "Organization");
    if (width != 0) {
        table.setColumnWidth(organizationColumn, width, Style.Unit.PX);
    }
    // sort column
    organizationColumn.setSortable(true);
    table.getColumnSortHandler().setComparator(organizationColumn, new RichMemberComparator(RichMemberComparator.Column.ORGANIZATION));
}
Also used : JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) RichMemberComparator(cz.metacentrum.perun.webgui.json.comparators.RichMemberComparator) RichMember(cz.metacentrum.perun.webgui.model.RichMember)

Aggregations

RichMember (cz.metacentrum.perun.webgui.model.RichMember)20 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)7 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)7 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)7 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)6 RichMemberComparator (cz.metacentrum.perun.webgui.json.comparators.RichMemberComparator)6 JsonUtils (cz.metacentrum.perun.webgui.json.JsonUtils)5 PerunError (cz.metacentrum.perun.webgui.model.PerunError)5 Column (com.google.gwt.user.cellview.client.Column)4 Member (cz.metacentrum.perun.webgui.model.Member)4 User (cz.metacentrum.perun.webgui.model.User)4 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)4 ArrayList (java.util.ArrayList)4 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)3 FindCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)3 GetCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers)3 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)3 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)2