Search in sources :

Example 26 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class UsersTabItem method draw.

public Widget draw() {
    CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
    this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton));
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu tabMenu = new TabMenu();
    // search textbox
    ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            startSearching(text);
            searchString = text;
        }
    }, searchButton);
    // get the table
    final CellTable<User> table = users.getTable(new FieldUpdater<User, String>() {

        public void update(int index, User object, String value) {
            // opens the tab
            session.getTabManager().addTab(new UserDetailTabItem(object));
        }
    });
    // if some text has been searched before
    if (!searchString.equals("")) {
        searchBox.getTextBox().setText(searchString);
        startSearching(searchString);
    }
    /*
			 Button b1 = tabMenu.addButton("List all", SmallIcons.INSTANCE.userGrayIcon(), new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 GetCompleteRichUsers callback = new GetCompleteRichUsers(new JsonCallbackEvents(){
			 public void onLoadingStart() {
			 table.setEmptyTableWidget(new AjaxLoaderImage().loadingStart());
			 }
			 public void onFinished(JavaScriptObject jso) {
			 users.setList(JsonUtils.<User>jsoAsList(jso));
			 users.sortTable();
			 table.setEmptyTableWidget(new AjaxLoaderImage().loadingFinished());
			 }
			 public void onError(PerunError error){
			 users.clearTable();
			 table.setEmptyTableWidget(new AjaxLoaderImage().loadingError(error));
			 }
			 });
			 callback.retrieveData();
			 }
			 });
			 b1.setTitle("List of all users in Perun");
			 */
    final CustomButton withoutVoButton = new CustomButton(ButtonTranslation.INSTANCE.listUsersWithoutVoButton(), ButtonTranslation.INSTANCE.listUsersWithoutVo(), SmallIcons.INSTANCE.userRedIcon());
    withoutVoButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            GetCompleteRichUsers callback = new GetCompleteRichUsers(null, new JsonCallbackEvents() {

                public void onLoadingStart() {
                    users.clearTable();
                    table.setEmptyTableWidget(new AjaxLoaderImage().loadingStart());
                    withoutVoButton.setProcessing(true);
                }

                public void onFinished(JavaScriptObject jso) {
                    users.setList(JsonUtils.<User>jsoAsList(jso));
                    users.sortTable();
                    table.setEmptyTableWidget(new AjaxLoaderImage().loadingFinished());
                    withoutVoButton.setProcessing(false);
                }

                public void onError(PerunError error) {
                    table.setEmptyTableWidget(new AjaxLoaderImage().loadingError(error));
                    withoutVoButton.setProcessing(false);
                }
            });
            callback.getWithoutVo(true);
            callback.retrieveData();
        }
    });
    tabMenu.addWidget(withoutVoButton);
    // 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(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) User(cz.metacentrum.perun.webgui.model.User) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FindCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) 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) GetCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.GetCompleteRichUsers)

Example 27 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class AddUserToBlacklistTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add to blacklist");
    final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
    this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // if found 1 item, select
            ArrayList<User> list = JsonUtils.jsoAsList(jso);
            if (list != null && list.size() == 1) {
                users.getSelectionModel().setSelected(list.get(0), true);
            }
        }
    }));
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // 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 i, User user, String s) {
                session.getTabManager().addTab(new UserDetailTabItem(user));
            }
        });
    } else {
        table = users.getTable();
    }
    rebuildAlreadyAddedWidget();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedUsersToBlacklist());
    final TabItem tab = this;
    // search textbox
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            startSearching(text);
            searchString = text;
        }
    }, searchButton);
    tabMenu.addWidget(addButton);
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
        }
    }));
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<User> list = users.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                FlexTable layout = new FlexTable();
                layout.setStyleName("inputFormFlexTable");
                final TextArea textArea = new TextArea();
                textArea.setSize("250px", "120px");
                layout.getFlexCellFormatter().addStyleName(0, 0, "itemName");
                layout.setHTML(0, 0, "Reason:");
                layout.setWidget(1, 0, textArea);
                layout.setHTML(2, 0, "Please specify why users are blacklisted.");
                layout.getFlexCellFormatter().addStyleName(2, 0, "inputFormInlineComment");
                Confirm c = new Confirm("Add user(s) to blacklist", layout, new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        for (int i = 0; i < list.size(); i++) {
                            // FIXME - Should have only one callback to core
                            final int n = i;
                            AddUserToBlacklist request = new AddUserToBlacklist(securityTeamId, JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    // put names to already added
                                    alreadyAddedList.add(list.get(n));
                                    rebuildAlreadyAddedWidget();
                                    // unselect added person
                                    users.getSelectionModel().setSelected(list.get(n), false);
                                    // clear search
                                    searchBox.getTextBox().setText("");
                                }
                            }));
                            request.addUserToBlacklist(list.get(i).getId(), textArea.getText().trim());
                        }
                    }
                }, "Add", true);
                c.show();
            }
        }
    });
    // if some text has been searched before
    if (!searchString.equals("")) {
        searchBox.getTextBox().setText(searchString);
        startSearching(searchString);
    }
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(users, table, addButton);
    // 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(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    firstTabPanel.add(alreadyAdded);
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(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) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) AddUserToBlacklist(cz.metacentrum.perun.webgui.json.securityTeamsManager.AddUserToBlacklist) FindCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers) ArrayList(java.util.ArrayList) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) 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 ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class RequestQuotaChangeTabItem method draw.

public Widget draw() {
    new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, resource.getVoId(), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            vo = jso.cast();
        }
    }).retrieveData();
    VerticalPanel vp = new VerticalPanel();
    // set tab name
    this.titleWidget.setText(getQuotaTypeAsString() + " quota change request");
    // quota string
    //String quotaStr = getQuotaTypeAsString();
    // new quota input
    final ExtendedTextBox newQuota = new ExtendedTextBox();
    final ExtendedTextArea reason = new ExtendedTextArea();
    final ListBox units = new ListBox();
    units.addItem("M");
    units.addItem("G");
    units.addItem("T");
    // default G
    units.setSelectedIndex(1);
    FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    ft.setWidget(0, 0, new HTML("Resource:"));
    ft.setWidget(1, 0, new HTML("Current quota:"));
    ft.setWidget(2, 0, new HTML("Requested quota:"));
    ft.setWidget(3, 0, new HTML("Reason:"));
    for (int i = 0; i < ft.getRowCount(); i++) {
        ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    ft.setText(0, 1, resource.getName());
    ft.setText(1, 1, oldQuota + " (default: " + defaultQuota + ")");
    ft.setWidget(2, 1, newQuota);
    ft.getFlexCellFormatter().setColSpan(3, 1, 2);
    ft.setWidget(3, 1, reason);
    final CustomButton requestQuotaButton = new CustomButton("Send request", "Send quota change request", SmallIcons.INSTANCE.emailIcon());
    if (this.quotaType.equals(QuotaType.DATA)) {
        ft.setWidget(2, 2, units);
        ft.getFlexCellFormatter().setColSpan(4, 0, 3);
    } else {
        ft.getFlexCellFormatter().setColSpan(4, 0, 2);
    }
    final ExtendedTextBox.TextBoxValidator quotaValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (newQuota.getTextBox().getValue().trim().isEmpty()) {
                newQuota.setError("You must enter requested quota!");
            } else if (!JsonUtils.checkParseInt(newQuota.getTextBox().getValue().trim())) {
                newQuota.setError("Requested quota must be a number!");
            } else {
                newQuota.setOk();
                return true;
            }
            return false;
        }
    };
    newQuota.setValidator(quotaValidator);
    final ExtendedTextArea.TextAreaValidator reasonValidator = new ExtendedTextArea.TextAreaValidator() {

        @Override
        public boolean validateTextArea() {
            if (reason.getTextArea().getValue().trim().isEmpty()) {
                reason.setError("You must specify reason for quota change!");
                return false;
            }
            reason.setOk();
            return true;
        }
    };
    reason.setValidator(reasonValidator);
    reason.getTextArea().setSize("205px", "100px");
    requestQuotaButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (!quotaValidator.validateTextBox() && !reasonValidator.validateTextArea())
                return;
            if (quotaType.equals(QuotaType.DATA)) {
                requestQuotaChange(newQuota.getTextBox().getValue().trim() + units.getItemText(units.getSelectedIndex()), reason.getTextArea().getText());
            } else {
                requestQuotaChange(newQuota.getTextBox().getValue().trim(), reason.getTextArea().getText());
            }
        }
    });
    vp.add(ft);
    TabMenu menu = new TabMenu();
    menu.addWidget(requestQuotaButton);
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextArea(cz.metacentrum.perun.webgui.widgets.ExtendedTextArea) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) 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) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById)

Example 29 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class CreateServicePackageTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final ExtendedTextBox packageName = new ExtendedTextBox();
    final ExtendedTextBox packageDescription = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (packageName.getTextBox().getText().trim().isEmpty()) {
                packageName.setError("Name can't be empty");
                return false;
            } else {
                packageName.setOk();
                return true;
            }
        }
    };
    packageName.setValidator(validator);
    final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (packageDescription.getTextBox().getText().trim().isEmpty()) {
                packageDescription.setError("Description can't be empty");
                return false;
            } else {
                packageDescription.setOk();
                return true;
            }
        }
    };
    packageDescription.setValidator(validator);
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    // fill form
    layout.setHTML(0, 0, "Name:");
    layout.setWidget(0, 1, packageName);
    layout.setHTML(1, 0, "Description:");
    layout.setWidget(1, 1, packageDescription);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    // create button
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createServicePackage());
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (validator.validateTextBox() && validator2.validateTextBox()) {
                CreateServicePackage request = new CreateServicePackage(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
                request.createServicePackage(packageName.getTextBox().getText().trim(), packageDescription.getTextBox().getText().trim());
            }
        }
    });
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    menu.addWidget(createButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    // add tabs to the main panel
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) CreateServicePackage(cz.metacentrum.perun.webgui.json.servicesManager.CreateServicePackage)

Example 30 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class AddMemberToGroupTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add member(s)");
    // MAIN PANEL
    final VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    boolean isMembersGroup = group.isCoreGroup();
    // if members or admins group, hide
    if (isMembersGroup) {
        firstTabPanel.add(new HTML("<p>Group \"" + group.getName() + "\" can't have members managed from Group admin. Please use VO admin section.</p>"));
        this.contentWidget.setWidget(firstTabPanel);
        return getWidget();
    }
    // MENU
    TabMenu tabMenu = new TabMenu();
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // for resize
    final TabItem tab = this;
    // CALLBACKS
    // for both
    final FindCompleteRichMembers findMembers;
    // for both
    final GetCompleteRichMembers getAllMembers;
    // for VO/group admin differs search
    final FindCandidatesOrUsersToAddToVo findCandidatesOrUsersToAddToVo;
    // elements handled by callback events
    final CustomButton searchButton = new CustomButton("Search in VO", ButtonTranslation.INSTANCE.searchMemberInVo(), SmallIcons.INSTANCE.findIcon());
    final CustomButton searchGloballyButton = new CustomButton("Search globally", ButtonTranslation.INSTANCE.searchForMembersInExtSources(), SmallIcons.INSTANCE.findIcon());
    final CustomButton listAllButton = new CustomButton("List all VO members", ButtonTranslation.INSTANCE.listAllMembersInVo(), SmallIcons.INSTANCE.userGreenIcon());
    final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
    // search through whole VO
    findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), "", null);
    getAllMembers = new GetCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), null);
    if (session.isVoAdmin(group.getVoId())) {
        // will search vo ext sources and users
        findCandidatesOrUsersToAddToVo = new FindCandidatesOrUsersToAddToVo(group.getVoId(), 0, "", null);
    } else {
        // will search group ext sources only
        findCandidatesOrUsersToAddToVo = new FindCandidatesOrUsersToAddToVo(group.getVoId(), group.getId(), "", null);
    }
    final CellTable<Candidate> candidatesTable = findCandidatesOrUsersToAddToVo.getEmptyTable();
    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(), groupId));
        }
    });
    final CustomButton inviteButton = new CustomButton("Invite selected", SmallIcons.INSTANCE.emailIcon());
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedMemberToGroup());
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        public void searchFor(String text) {
            searchString = text;
            findMembers.searchFor(searchString);
            search = true;
            searchCandidates = false;
            // remove previous table
            firstTabPanel.getWidget(2).removeFromParent();
            firstTabPanel.add(sp);
            UiElements.runResizeCommands(tab);
        }
    }, searchButton);
    searchBox.getTextBox().setText(searchString);
    // bind text box also to search globally
    searchBox.getTextBox().addKeyUpHandler(new KeyUpHandler() {

        public void onKeyUp(KeyUpEvent event) {
            if (!searchBox.getTextBox().getText().trim().isEmpty()) {
                searchGloballyButton.setEnabled(true);
            // do not trigger search on both !!
            } else {
                searchGloballyButton.setEnabled(false);
            }
        }
    });
    searchBox.getTextBox().addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(BlurEvent event) {
            // fake some meaningless KeyUpEvent
            DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_DOWN), searchBox.getTextBox());
        }
    });
    searchBox.getTextBox().addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            // fake some meaningless KeyUpEvent
            DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_DOWN), searchBox.getTextBox());
        }
    });
    // button click triggers action
    searchGloballyButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            if (UiElements.searchStingCantBeEmpty(searchBox.getTextBox().getText().trim())) {
                new PerunSearchEvent() {

                    public void searchFor(String text) {
                        searchString = text;
                        findCandidatesOrUsersToAddToVo.searchFor(searchString);
                        searchCandidates = true;
                        search = false;
                        // remove previous table
                        firstTabPanel.getWidget(2).removeFromParent();
                        firstTabPanel.add(sp2);
                        UiElements.runResizeCommands(tab);
                    }
                }.searchFor(searchBox.getTextBox().getText().trim());
            }
        }
    });
    searchGloballyButton.setEnabled(false);
    findMembers.setEvents(JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // if found 1 item, select
            listAllButton.setEnabled(true);
            searchGloballyButton.setEnabled(true);
            searchBox.getTextBox().setEnabled(true);
            ArrayList<RichMember> list = JsonUtils.jsoAsList(jso);
            if (list != null && list.size() == 1) {
                findMembers.getSelectionModel().setSelected(list.get(0), true);
            }
        }

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

        @Override
        public void onLoadingStart() {
            listAllButton.setEnabled(false);
            searchGloballyButton.setEnabled(false);
            disabled.setVisible(false);
            searchBox.getTextBox().setEnabled(false);
            addButton.setEnabled(false);
            inviteButton.setEnabled(false);
        }
    }));
    getAllMembers.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.");
            searchButton.setEnabled(true);
            searchBox.getTextBox().setEnabled(true);
        }

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

        @Override
        public void onLoadingStart() {
            searchButton.setEnabled(false);
            disabled.setVisible(true);
            searchBox.getTextBox().setEnabled(false);
            addButton.setEnabled(false);
            inviteButton.setEnabled(false);
        }
    }));
    findCandidatesOrUsersToAddToVo.setEvents(JsonCallbackEvents.disableButtonEvents(searchGloballyButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // if found 1 item, select
            listAllButton.setEnabled(true);
            searchButton.setEnabled(true);
            searchBox.getTextBox().setEnabled(true);
            ArrayList<Candidate> list = JsonUtils.jsoAsList(jso);
            if (list != null && list.size() == 1) {
                findCandidatesOrUsersToAddToVo.setSelected(list.get(0));
            }
        }

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

        @Override
        public void onLoadingStart() {
            disabled.setVisible(false);
            listAllButton.setEnabled(false);
            searchButton.setEnabled(false);
            searchBox.getTextBox().setEnabled(false);
            addButton.setEnabled(false);
            inviteButton.setEnabled(false);
        }
    }));
    // DISABLED CHECKBOX
    disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
    disabled.setVisible(false);
    // checkbox click handler
    disabled.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            getAllMembers.excludeDisabled(!disabled.getValue());
            findMembers.clearTable();
            getAllMembers.retrieveData();
        }
    });
    listAllButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            search = false;
            searchCandidates = false;
            searchString = "";
            searchBox.getTextBox().setText("");
            findMembers.clearTable();
            findCandidatesOrUsersToAddToVo.clearTable();
            getAllMembers.retrieveData();
            // remove previous table
            firstTabPanel.getWidget(2).removeFromParent();
            firstTabPanel.add(sp);
            UiElements.runResizeCommands(tab);
        }
    });
    // click handler
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (searchCandidates) {
                // searched users or candidates
                Candidate candidateToBeAdded = findCandidatesOrUsersToAddToVo.getSelected();
                if (candidateToBeAdded == null) {
                    UiElements.cantSaveEmptyListDialogBox(null);
                } else {
                    if (candidateToBeAdded.getObjectType().equalsIgnoreCase("Candidate")) {
                        CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                            private Candidate saveSelected;

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                // put names to already added
                                if (saveSelected != null) {
                                    GeneralObject go = saveSelected.cast();
                                    alreadyAddedList.add(go);
                                }
                                findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
                                rebuildAlreadyAddedWidget();
                                // clear search
                                searchBox.getTextBox().setText("");
                            }

                            @Override
                            public void onLoadingStart() {
                                saveSelected = findCandidatesOrUsersToAddToVo.getSelected();
                            }
                        }));
                        request.createMember(group.getVoId(), group, candidateToBeAdded);
                    } else {
                        CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                            private User saveSelected;

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                // put names to already added
                                if (saveSelected != null) {
                                    GeneralObject go = saveSelected.cast();
                                    alreadyAddedList.add(go);
                                    findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
                                    rebuildAlreadyAddedWidget();
                                    // clear search
                                    searchBox.getTextBox().setText("");
                                }
                            }

                            @Override
                            public void onLoadingStart() {
                                Candidate cand = findCandidatesOrUsersToAddToVo.getSelected();
                                saveSelected = cand.cast();
                            }
                        }));
                        User user = candidateToBeAdded.cast();
                        request.createMember(group.getVoId(), group, user);
                    }
                }
            } else {
                // searched members / all members
                final ArrayList<RichMember> membersToAdd = findMembers.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(membersToAdd)) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < membersToAdd.size(); i++) {
                        final int n = i;
                        AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                            private RichMember saveSelected;

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                // unselect added person
                                findMembers.getSelectionModel().setSelected(saveSelected, false);
                                // put names to already added
                                GeneralObject go = saveSelected.cast();
                                alreadyAddedList.add(go);
                                rebuildAlreadyAddedWidget();
                                // clear search
                                searchBox.getTextBox().setText("");
                            }

                            @Override
                            public void onLoadingStart() {
                                saveSelected = membersToAdd.get(n);
                            }
                        }));
                        request.addMemberToGroup(group, membersToAdd.get(i));
                    }
                }
            }
        }
    });
    tabMenu.addWidget(searchGloballyButton);
    tabMenu.addWidget(listAllButton);
    tabMenu.addWidget(addButton);
    tabMenu.addWidget(inviteButton);
    inviteButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (searchCandidates) {
                // we expect, that candidate is always single
                Candidate candid = findCandidatesOrUsersToAddToVo.getSelected();
                if (candid != null) {
                    if (candid.getObjectType().equalsIgnoreCase("Candidate")) {
                        SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
                        invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
                            }
                        }));
                        invite.inviteUser(candid);
                    } else {
                        SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
                        invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
                            }
                        }));
                        User user = candid.cast();
                        invite.inviteUser(user);
                    }
                }
            } else {
                // members / all members
                SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
                ArrayList<RichMember> usrs = findMembers.getTableSelectedList();
                for (int i = 0; i < usrs.size(); i++) {
                    if (i == usrs.size() - 1) {
                        invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                findMembers.clearTableSelectedSet();
                            }
                        }));
                    } else {
                        invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton));
                    }
                    invite.inviteUser(usrs.get(i).getUser());
                }
            }
        }
    });
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            // with refresh if somebody was added
            session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
        }
    }));
    tabMenu.addWidget(disabled);
    rebuildAlreadyAddedWidget();
    firstTabPanel.add(alreadyAdded);
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findMembers, table, addButton);
    inviteButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findMembers, table, inviteButton);
    JsonUtils.addTableManagedButton(findCandidatesOrUsersToAddToVo, candidatesTable, addButton);
    JsonUtils.addTableManagedButton(findCandidatesOrUsersToAddToVo, candidatesTable, inviteButton);
    table.addStyleName("perun-table");
    sp.setWidget(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    candidatesTable.addStyleName("perun-table");
    sp2.setWidget(candidatesTable);
    sp2.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp2, 350, this);
    // if not empty - start searching
    if (search) {
        findMembers.searchFor(searchString);
        firstTabPanel.add(sp);
    } else if (searchCandidates) {
        findCandidatesOrUsersToAddToVo.searchFor(searchString);
        firstTabPanel.add(sp2);
    } else {
        getAllMembers.excludeDisabled(!disabled.getValue());
        getAllMembers.retrieveData();
        firstTabPanel.add(sp);
    }
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) BlurHandler(com.google.gwt.event.dom.client.BlurHandler) User(cz.metacentrum.perun.webgui.model.User) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) CreateMember(cz.metacentrum.perun.webgui.json.membersManager.CreateMember) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AddMember(cz.metacentrum.perun.webgui.json.groupsManager.AddMember) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject) Candidate(cz.metacentrum.perun.webgui.model.Candidate) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) RichMember(cz.metacentrum.perun.webgui.model.RichMember) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) FindCandidatesOrUsersToAddToVo(cz.metacentrum.perun.webgui.json.vosManager.FindCandidatesOrUsersToAddToVo) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) SendInvitation(cz.metacentrum.perun.webgui.json.registrarManager.SendInvitation) BlurEvent(com.google.gwt.event.dom.client.BlurEvent) PerunError(cz.metacentrum.perun.webgui.model.PerunError) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Aggregations

ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)32 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)32 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)31 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)31 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)31 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)29 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)17 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)17 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)14 ArrayList (java.util.ArrayList)12 PerunError (cz.metacentrum.perun.webgui.model.PerunError)8 User (cz.metacentrum.perun.webgui.model.User)8 FindCompleteRichUsers (cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers)7 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)6 UserDetailTabItem (cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem)5 AddAdmin (cz.metacentrum.perun.webgui.json.authzResolver.AddAdmin)4 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)4 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)3 FindCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)3 GetCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers)3