Search in sources :

Example 1 with CellTable

use of com.google.gwt.user.cellview.client.CellTable in project perun by CESNET.

the class AddAutoRegGroupTabItem method draw.

@Override
public Widget draw() {
    titleWidget.setText("Add group for auto registration");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    menu.addWidget(new HTML(""));
    final GetAllGroups groups = new GetAllGroups(vo.getId());
    groups.setCoreGroupsCheckable(false);
    // remove already added union groups from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // second callback
            final GetAutoRegistrationGroups alreadySet = new GetAutoRegistrationGroups(vo.getId(), new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<Group> esToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < esToRemove.length(); i++) {
                        groups.removeFromTable(esToRemove.get(i));
                    }
                }
            });
            alreadySet.retrieveData();
        }
    };
    groups.setEvents(localEvents);
    final ExtendedSuggestBox box = new ExtendedSuggestBox(groups.getOracle());
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedExtSource());
    final TabItem tab = this;
    assignButton.addClickHandler(event -> {
        final ArrayList<Group> availableGroups = groups.getTableSelectedList();
        if (UiElements.cantSaveEmptyListDialogBox(availableGroups)) {
            AddAutoRegGroups request = new AddAutoRegGroups(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // clear search
                    box.getSuggestBox().setText("");
                    groups.retrieveData();
                }
            }));
            request.setAutoRegGroups(availableGroups);
        }
    });
    menu.addFilterWidget(box, new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            groups.filterTable(text);
        }
    }, "Filter by name");
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", clickEvent -> session.getTabManager().closeTab(tab, isRefreshParentOnClose())));
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<Group> table = groups.getTable();
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(groups, table, assignButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    // do not use resizePerunTable() when tab is in overlay - wrong width is calculated
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ImageResource(com.google.gwt.resources.client.ImageResource) SmallIcons(cz.metacentrum.perun.webgui.client.resources.SmallIcons) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) AddAutoRegGroups(cz.metacentrum.perun.webgui.json.registrarManager.AddAutoRegGroups) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) HTML(com.google.gwt.user.client.ui.HTML) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) ArrayList(java.util.ArrayList) Label(com.google.gwt.user.client.ui.Label) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel) ButtonTranslation(cz.metacentrum.perun.webgui.client.localization.ButtonTranslation) UiElements(cz.metacentrum.perun.webgui.client.UiElements) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) GetAutoRegistrationGroups(cz.metacentrum.perun.webgui.json.registrarManager.GetAutoRegistrationGroups) Group(cz.metacentrum.perun.webgui.model.Group) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) MainMenu(cz.metacentrum.perun.webgui.client.mainmenu.MainMenu) PerunWebSession(cz.metacentrum.perun.webgui.client.PerunWebSession) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) JsArray(com.google.gwt.core.client.JsArray) Widget(com.google.gwt.user.client.ui.Widget) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ButtonType(cz.metacentrum.perun.webgui.client.resources.ButtonType) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) CellTable(com.google.gwt.user.cellview.client.CellTable) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) Group(cz.metacentrum.perun.webgui.model.Group) JsArray(com.google.gwt.core.client.JsArray) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) HTML(com.google.gwt.user.client.ui.HTML) AddAutoRegGroups(cz.metacentrum.perun.webgui.json.registrarManager.AddAutoRegGroups) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetAutoRegistrationGroups(cz.metacentrum.perun.webgui.json.registrarManager.GetAutoRegistrationGroups) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Example 2 with CellTable

use of com.google.gwt.user.cellview.client.CellTable in project perun by CESNET.

the class CreateServiceMemberInVoTabItem method draw.

public Widget draw() {
    titleWidget.setText("Create service member");
    final TabItem tab = this;
    // draw the main tab
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    final ExtendedTextBox serviceUserName = new ExtendedTextBox();
    final ExtendedTextBox serviceUserEmail = new ExtendedTextBox();
    final ExtendedTextBox serviceUserLogin = new ExtendedTextBox();
    final ExtendedPasswordBox serviceUserPassword = new ExtendedPasswordBox();
    final ExtendedPasswordBox serviceUserPassword2 = new ExtendedPasswordBox();
    final ListBox namespace = new ListBox();
    final ExtendedTextBox certDN = new ExtendedTextBox();
    final ExtendedTextBox cacertDN = new ExtendedTextBox();
    final String serviceType = "SERVICE";
    serviceUserPassword.getTextBox().setWidth("200px");
    serviceUserPassword2.getTextBox().setWidth("200px");
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (serviceUserName.getTextBox().getValue().trim().isEmpty()) {
                serviceUserName.setError("Name can't be empty!");
                return false;
            }
            serviceUserName.setOk();
            return true;
        }
    };
    serviceUserName.setValidator(nameValidator);
    final ExtendedTextBox.TextBoxValidator loginValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (namespace.getSelectedIndex() == 0) {
                // do not validate if namespace is not selected
                serviceUserLogin.getTextBox().setValue(null);
                serviceUserLogin.setOk();
                return true;
            }
            if (serviceUserLogin.getTextBox().getValue().trim().isEmpty()) {
                serviceUserLogin.setError("Login can't be empty!");
                return false;
            }
            RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
            boolean match = regExp.test(serviceUserLogin.getTextBox().getValue().trim());
            if (!match) {
                serviceUserLogin.setError("Invalid format!");
                return false;
            }
            if (serviceUserLogin.isProcessing() || serviceUserLogin.isHardError()) {
                // keep original message
                return false;
            }
            serviceUserLogin.setOk();
            return true;
        }
    };
    serviceUserLogin.setValidator(loginValidator);
    final ExtendedTextBox.TextBoxValidator emailValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!JsonUtils.isValidEmail(serviceUserEmail.getTextBox().getValue().trim())) {
                serviceUserEmail.setError("Wrong email format!");
                return false;
            }
            serviceUserEmail.setOk();
            return true;
        }
    };
    serviceUserEmail.setValidator(emailValidator);
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (serviceUserPassword.getTextBox().getValue().trim().equals("")) {
                serviceUserPassword.setError("Password can't be empty!");
                return false;
            }
            // einfra check
            if ("einfra".equals(namespace.getSelectedValue())) {
                RegExp regExp2 = RegExp.compile("^[\\x20-\\x7E]{1,}$");
                if (regExp2.exec(serviceUserPassword.getTextBox().getValue()) == null) {
                    serviceUserPassword.setError("Password <b>can`t contain accented characters (diacritics)</b> or non-printing and control characters!");
                    return false;
                }
                // check on login in password if login is longer than 2 chars
                // TODO - check for name/surname too
                String pass = serviceUserPassword.getTextBox().getValue();
                String login = serviceUserLogin.getTextBox().getValue();
                if (login.length() > 2) {
                    if (Utils.normalizeString(pass).contains(Utils.normalizeString(login)) || Utils.normalizeString(pass).contains(Utils.normalizeString(Utils.reverseString((login))))) {
                        serviceUserPassword.setError("Password <b>can't contain login, name or surname</b>, not even backwards!");
                        return false;
                    }
                }
                // Check that password contains at least 3 of 4 character groups
                RegExp regExpDigit = RegExp.compile("^.*[0-9].*$");
                RegExp regExpLower = RegExp.compile("^.*[a-z].*$");
                RegExp regExpUpper = RegExp.compile("^.*[A-Z].*$");
                // FIXME - are those correct printable specific chars?
                RegExp regExpSpec = RegExp.compile("^.*[\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E].*$");
                int matchCounter = 0;
                if (regExpDigit.exec(serviceUserPassword.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpLower.exec(serviceUserPassword.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpUpper.exec(serviceUserPassword.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpSpec.exec(serviceUserPassword.getTextBox().getValue()) != null)
                    matchCounter++;
                if (matchCounter < 3) {
                    serviceUserPassword.setError("Password must consist of <b>at least 3 of 4</b> character groups<ul><li>lower-case letters</li><li>upper-case letters</li><li>digits</li><li>special characters</li></ul>");
                    return false;
                }
                // check length
                if (serviceUserPassword.getTextBox().getValue().length() < 10) {
                    serviceUserPassword.setError("Password must be <b>at least 10 characters</b> long!");
                    return false;
                }
            }
            if (!serviceUserPassword.getTextBox().getValue().equals(serviceUserPassword2.getTextBox().getValue())) {
                serviceUserPassword.setOk();
                serviceUserPassword2.setError("Password in both textboxes must be the same!");
                return false;
            }
            serviceUserPassword.setOk();
            return true;
        }
    };
    serviceUserPassword.setValidator(validator);
    final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!serviceUserPassword2.getTextBox().getValue().equals(serviceUserPassword.getTextBox().getValue())) {
                serviceUserPassword2.setError("Password in both textboxes must be the same!");
                return false;
            } else {
                serviceUserPassword2.setOk();
                return true;
            }
        }
    };
    serviceUserPassword2.setValidator(validator2);
    /*
		final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
			@Override
			public boolean validateTextBox() {
				if (serviceUserPassword.getTextBox().getValue().trim().isEmpty()) {
					serviceUserPassword.setError("Password can't be empty !");
					return false;
				} else if (!serviceUserPassword.getTextBox().getValue().equals(serviceUserPassword2.getTextBox().getValue())) {
					serviceUserPassword.setError("Password in both textboxes must be the same !");
					return false;
				} else {
					serviceUserPassword.setOk();
					serviceUserPassword2.setOk();
					return true;
				}
			}
		};
		serviceUserPassword.setValidator(validator);

		final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {
			@Override
			public boolean validateTextBox() {
				if (serviceUserPassword2.getTextBox().getValue().trim().isEmpty()) {
					serviceUserPassword2.setError("Password can't be empty !");
					return false;
				} else if (!serviceUserPassword2.getTextBox().getValue().equals(serviceUserPassword.getTextBox().getValue())) {
					serviceUserPassword2.setError("Password in both textboxes must be the same !");
					return false;
				} else {
					serviceUserPassword2.setOk();
					serviceUserPassword.setOk();
					return true;
				}
			}
		};
		serviceUserPassword2.setValidator(validator2);
		*/
    final ExtendedTextBox.TextBoxValidator certDNValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if ((certDN.getTextBox().getValue().trim().isEmpty() && cacertDN.getTextBox().getValue().trim().isEmpty()) || (!certDN.getTextBox().getValue().trim().isEmpty() && !cacertDN.getTextBox().getValue().trim().isEmpty())) {
                certDN.setOk();
                cacertDN.setOk();
                return true;
            } else {
                if (certDN.getTextBox().getValue().trim().isEmpty()) {
                    certDN.setError("Value can't be empty!");
                }
                if (cacertDN.getTextBox().getValue().trim().isEmpty()) {
                    cacertDN.setError("Value can't be empty!");
                }
            }
            return false;
        }
    };
    certDN.setValidator(certDNValidator);
    cacertDN.setValidator(certDNValidator);
    // make value empty
    namespace.addItem("Not selected", "");
    for (String name : Utils.getSupportedPasswordNamespaces()) {
        namespace.addItem(name.toUpperCase(), name);
    }
    final FlexTable layout = new FlexTable();
    layout.setCellPadding(5);
    layout.setHTML(0, 0, "<h3>1. Create service identity</h3>");
    layout.getFlexCellFormatter().setColSpan(0, 0, 3);
    layout.setHTML(1, 0, "<strong>Member's name: </strong>");
    layout.setWidget(1, 1, serviceUserName);
    layout.setHTML(2, 0, "<strong>Member's email: </strong>");
    layout.setWidget(2, 1, serviceUserEmail);
    layout.setHTML(3, 0, "<strong>Namespace: </strong>");
    layout.setWidget(3, 1, namespace);
    layout.setHTML(4, 0, "<strong>Login: </strong>");
    layout.setWidget(4, 1, serviceUserLogin);
    final Label label = new Label("You will be assigned with available login");
    label.setVisible(false);
    layout.setWidget(5, 0, label);
    layout.getFlexCellFormatter().setStyleName(5, 0, "inputFormInlineComment");
    layout.getFlexCellFormatter().setColSpan(5, 0, 2);
    layout.setHTML(6, 0, "<strong>Subject DN: </strong>");
    layout.setWidget(6, 1, certDN);
    layout.setHTML(7, 0, "<strong>Issuer DN: </strong>");
    layout.setWidget(7, 1, cacertDN);
    final FlexTable firstTabLayout = new FlexTable();
    firstTabLayout.setSize("100%", "100%");
    firstTabLayout.setVisible(false);
    final AddRemoveItemsTable<User> itemsTable = new AddRemoveItemsTable<User>(true);
    itemsTable.addItem(session.getUser());
    final VerticalPanel secondTabPanel = new VerticalPanel();
    secondTabPanel.setSize("100%", "100%");
    secondTabPanel.setVisible(false);
    mainTab.add(layout);
    mainTab.add(firstTabLayout);
    mainTab.add(secondTabPanel);
    // disable login by default (first option)
    serviceUserLogin.getTextBox().setEnabled(false);
    final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.addIcon(), new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            // check
            if (!namespace.getSelectedValue().equals("mu") && namespace.getSelectedIndex() != 0 && !loginValidator.validateTextBox())
                return;
            if (!nameValidator.validateTextBox())
                return;
            if (!emailValidator.validateTextBox())
                return;
            if (!certDNValidator.validateTextBox())
                return;
            // change to lager tab
            session.getTabManager().changeStyleOfInnerTab(true);
            // first tab panel
            firstTabLayout.setHTML(0, 0, "<h3>2. Associate real users</h3>");
            firstTabLayout.getFlexCellFormatter().setColSpan(0, 0, 2);
            layout.setVisible(false);
            firstTabLayout.setVisible(true);
            final FindUsersInVo callback = new FindUsersInVo();
            // Service users can't own another Service or Guest (Sponsored) account.
            callback.hideService(true);
            // HORIZONTAL MENU
            TabMenu tabMenu = new TabMenu();
            // get the table
            final CellTable<User> table = callback.getTable();
            // search textbox
            ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

                @Override
                public void searchFor(String text) {
                    callback.searchFor(text, voId);
                    searchString = text;
                }
            }, ButtonTranslation.INSTANCE.searchUsers());
            final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.arrowRightIcon());
            cb.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent clickEvent) {
                    // check
                    if (itemsTable.getList().isEmpty()) {
                        new Confirm("No user associated", new HTML("You must associate at least one real user to service member."), true).show();
                        return;
                    }
                    // create member + user
                    CreateSpecificMember request = new CreateSpecificMember(JsonCallbackEvents.disableButtonEvents(cb, new JsonCallbackEvents() {

                        public void onFinished(JavaScriptObject jso) {
                            final Member member = jso.cast();
                            for (User u : itemsTable.getList()) {
                                if (u.getId() == session.getUser().getId()) {
                                    // set local authz if one of associated users is us
                                    session.addEditableUser(member.getUserId());
                                }
                            }
                            if (namespace.getSelectedIndex() == 0) {
                                // we didn't set login, hence skip password setting
                                session.getTabManager().closeTab(tab, true);
                                return;
                            }
                            // change to small tab
                            session.getTabManager().changeStyleOfInnerTab(false);
                            secondTabPanel.add(new HTML("<h3>3.Set password for: " + serviceUserLogin.getTextBox().getValue().trim() + "</h3>"));
                            final CustomButton button = new CustomButton("Set password", SmallIcons.INSTANCE.keyIcon());
                            button.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent clickEvent) {
                                    if (!validator.validateTextBox() || !validator2.validateTextBox()) {
                                        // one of input boxes for passwords is wrong
                                        return;
                                    }
                                    final String namespaceValue = namespace.getSelectedValue();
                                    if ("mu".equals(namespaceValue)) {
                                        final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                BasicOverlayType basic = jso.cast();
                                                final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                                                SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                    @Override
                                                    public void onFinished(JavaScriptObject jso) {
                                                        // VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
                                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                            @Override
                                                            public void onFinished(JavaScriptObject jso) {
                                                                // validate member when all kerberos logins are set
                                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                                req2.validateMemberAsync(member);
                                                            }
                                                        }));
                                                        // validate login returned from account generation
                                                        req.validatePassword(member.getUserId(), login, namespaceValue);
                                                        // show assigned login
                                                        UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                                    }

                                                    @Override
                                                    public void onError(PerunError error) {
                                                        UiElements.generateError(error, "Saving login failed", "You were assigned with login <b>" + login + "</b> in namespace MU but saving it to user failed. <b>Please copy your login and contact support at <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">" + Utils.perunReportEmailAddress() + "</a>.</b>");
                                                        // validate member when all logins are set
                                                        ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                        req2.validateMemberAsync(member);
                                                    }
                                                }));
                                                setLogin.setLogin(member.getUserId(), "mu", login);
                                            }
                                        }));
                                        final Map<String, String> params = new HashMap<String, String>();
                                        GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                RichMember rm = jso.cast();
                                                params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
                                                params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
                                                params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
                                                req.generateAccount(namespaceValue, serviceUserPassword.getTextBox().getValue(), params);
                                            }
                                        }));
                                        get.retrieveData();
                                    } else {
                                        // create password which sets also user ext sources
                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                // validate member when all kerberos logins are set
                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                req2.validateMemberAsync(member);
                                            }
                                        }));
                                        req.createPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue, serviceUserPassword.getTextBox().getValue());
                                    }
                                }
                            });
                            final CustomButton skipButton = new CustomButton("Skip", SmallIcons.INSTANCE.arrowRightIcon());
                            skipButton.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent clickEvent) {
                                    final String namespaceValue = namespace.getSelectedValue();
                                    if ("mu".equals(namespaceValue)) {
                                        final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                BasicOverlayType basic = jso.cast();
                                                final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                                                SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                    @Override
                                                    public void onFinished(JavaScriptObject jso) {
                                                        // VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
                                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                            @Override
                                                            public void onFinished(JavaScriptObject jso) {
                                                                // validate member when all kerberos logins are set
                                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                                req2.validateMemberAsync(member);
                                                            }
                                                        }));
                                                        // validate login returned from account generation
                                                        req.validatePassword(member.getUserId(), login, namespaceValue);
                                                        // show assigned login
                                                        UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                                    }

                                                    @Override
                                                    public void onError(PerunError error) {
                                                        // validate member when all logins are set
                                                        ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab, true));
                                                        req2.validateMemberAsync(member);
                                                    }
                                                }));
                                                setLogin.setLogin(member.getUserId(), "mu", login);
                                            }
                                        }));
                                        final Map<String, String> params = new HashMap<String, String>();
                                        GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                RichMember rm = jso.cast();
                                                params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
                                                params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
                                                params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
                                                req.generateAccount(namespaceValue, null, params);
                                            }
                                        }));
                                        get.retrieveData();
                                    } else {
                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(skipButton, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                // validate member when all kerberos logins are set
                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(skipButton, tab, true));
                                                req2.validateMemberAsync(member);
                                            }
                                        }));
                                        // set empty password for service member if "skipped"
                                        req.createRandomPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue);
                                    }
                                }
                            });
                            FlexTable ft = new FlexTable();
                            ft.setStyleName("inputFormFlexTable");
                            ft.setWidth("400px");
                            ft.setHTML(0, 0, "Password:");
                            ft.setWidget(0, 1, serviceUserPassword);
                            ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
                            ft.setHTML(1, 0, "Re-type&nbsp;password:");
                            ft.setWidget(1, 1, serviceUserPassword2);
                            ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
                            if ("einfra".equals(namespace.getSelectedValue())) {
                                ft.setHTML(2, 0, "Password must <ul><li>contain only printing (non-accented) characters<li>be at least 10 characters long<li>consist of at least 3 of 4 character groups<ul><li>lower-case letters<li>upper-case letters<li>digits<li>special characters</ul></ul>");
                            } else {
                                ft.setHTML(2, 0, "Please <b>avoid using accented characters</b>. It might not be supported by all backend components and services.");
                            }
                            ft.getFlexCellFormatter().setColSpan(2, 0, 2);
                            ft.getCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
                            ft.setWidget(3, 1, skipButton);
                            ft.getFlexCellFormatter().addStyleName(3, 1, "align-right");
                            ft.setWidget(4, 1, button);
                            ft.getFlexCellFormatter().addStyleName(4, 1, "align-right");
                            secondTabPanel.add(ft);
                            // hide 2nd panel
                            firstTabLayout.setVisible(false);
                            // show 3rd panel
                            secondTabPanel.setVisible(true);
                        }
                    }));
                    request.createMember(voId, serviceUserName.getTextBox().getValue().trim(), serviceUserEmail.getTextBox().getValue().trim(), itemsTable.getList(), namespace.getValue(namespace.getSelectedIndex()), serviceUserLogin.getTextBox().getValue().trim(), certDN.getTextBox().getValue().trim(), cacertDN.getTextBox().getValue().trim(), serviceType);
                }
            });
            // we have ourselves already assigned
            // cb.setEnabled(false);
            CustomButton button = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected users to service member");
            button.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent clickEvent) {
                    ArrayList<User> list = callback.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        // skip self
                        ArrayList<User> list2 = new ArrayList<User>();
                        for (User user : list) {
                            if (user != null && user.getId() != session.getUser().getId()) {
                                list2.add(user);
                            }
                        }
                        itemsTable.addItems(list2);
                        cb.setEnabled(true);
                        callback.clearTableSelectedSet();
                    }
                }
            });
            button.setEnabled(false);
            tabMenu.addWidget(button);
            JsonUtils.addTableManagedButton(callback, table, button);
            // add finish button to menu
            tabMenu.addWidget(cb);
            // if some text has been searched before
            if (!searchString.equals("")) {
                searchBox.getTextBox().setText(searchString);
                callback.searchFor(searchString, voId);
            }
            final ScrollPanel sp = new ScrollPanel(table);
            table.addStyleName("perun-table");
            sp.addStyleName("perun-tableScrollPanel");
            session.getUiElements().resizeSmallTabPanel(sp, 350, tab);
            firstTabLayout.setWidget(1, 0, tabMenu);
            firstTabLayout.setWidget(2, 0, sp);
            firstTabLayout.setHTML(1, 1, "<h3>To be associated:</h3>");
            firstTabLayout.setWidget(2, 1, itemsTable);
            firstTabLayout.getFlexCellFormatter().setWidth(2, 0, "75%");
            firstTabLayout.getFlexCellFormatter().setWidth(2, 1, "25%");
            firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 1, HasVerticalAlignment.ALIGN_TOP);
            firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_TOP);
            // actions when added items or removed items
            itemsTable.setEvents(new AddRemoveItemsTable.HandleItemsAction<User>() {

                @Override
                public void onAdd(User object) {
                    cb.setEnabled(true);
                }

                @Override
                public void onRemove(User object) {
                    if (object.equals(session.getUser())) {
                        itemsTable.addItem(object);
                        UiElements.generateInfo("Can't remove yourself", "<p>You can't remove yourself yet. You wouldn't be able to finish service member configuration. Please remove yourself afterwards.");
                    }
                    if (itemsTable.getList().isEmpty()) {
                        cb.setEnabled(false);
                    }
                }
            });
        }
    });
    // check login availability
    serviceUserLogin.getTextBox().addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent keyUpEvent) {
            if (keyUpEvent.isDownArrow() || keyUpEvent.isUpArrow() || keyUpEvent.isLeftArrow() || keyUpEvent.isRightArrow()) {
                // do not trigger when no text input
                return;
            }
            final String login = serviceUserLogin.getTextBox().getValue().trim();
            final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
            // trigger new validation on checked input or if previously was hard error
            if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
                new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            BasicOverlayType bo = jso.cast();
                            serviceUserLogin.setProcessing(false);
                            if (!bo.getBoolean()) {
                                serviceUserLogin.setHardError("Login is already in use!");
                            } else {
                                serviceUserLogin.removeHardError();
                                loginValidator.validateTextBox();
                            }
                        }
                    }

                    @Override
                    public void onLoadingStart() {
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            serviceUserLogin.removeHardError();
                            serviceUserLogin.setProcessing(true);
                        }
                    }

                    @Override
                    public void onError(PerunError error) {
                        // response is relevant to current value
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
                                serviceUserLogin.setProcessing(false);
                                String text = error.getErrorInfo();
                                text = text.split(":", 2)[1];
                                text = (text == null || text.isEmpty()) ? error.getErrorInfo() : text;
                                serviceUserLogin.setHardError(text);
                            } else {
                                // generic error
                                serviceUserLogin.setProcessing(false);
                                serviceUserLogin.setHardError("Unable to check if login is available!");
                            }
                        }
                    }
                }).retrieveData();
            }
        }
    });
    namespace.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (namespace.getSelectedIndex() == 0) {
                // do not set login
                serviceUserLogin.getTextBox().setEnabled(false);
                serviceUserLogin.getTextBox().setValue(null);
                loginValidator.validateTextBox();
                label.setVisible(false);
            } else if (namespace.getSelectedValue().equals("mu")) {
                serviceUserLogin.getTextBox().setEnabled(false);
                label.setVisible(true);
            } else {
                serviceUserLogin.getTextBox().setEnabled(true);
                label.setVisible(false);
            }
            if (namespace.getSelectedIndex() != 0) {
                // do not check login if not desired to set
                final String login = serviceUserLogin.getTextBox().getValue().trim();
                final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
                if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
                    new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
                            if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                                serviceUserLogin.setProcessing(false);
                                BasicOverlayType bo = jso.cast();
                                if (!bo.getBoolean()) {
                                    serviceUserLogin.setHardError("Login is already in use!");
                                } else {
                                    serviceUserLogin.removeHardError();
                                    loginValidator.validateTextBox();
                                }
                            }
                        }

                        @Override
                        public void onLoadingStart() {
                            if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                                serviceUserLogin.removeHardError();
                                serviceUserLogin.setProcessing(true);
                                loginValidator.validateTextBox();
                            }
                        }

                        @Override
                        public void onError(PerunError error) {
                            // response is relevant to current value
                            if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                                if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
                                    serviceUserLogin.setProcessing(false);
                                    String text = error.getErrorInfo();
                                    text = text.split(":", 2)[1];
                                    text = (text == null || text.isEmpty()) ? error.getErrorInfo() : text;
                                    serviceUserLogin.setHardError(text);
                                } else {
                                    // generic error
                                    serviceUserLogin.setProcessing(false);
                                    serviceUserLogin.setHardError("Unable to check if login is available!");
                                }
                            }
                        }
                    }).retrieveData();
                }
            }
        }
    });
    if (session.isPerunAdmin()) {
        layout.setWidget(9, 0, cb);
        layout.getFlexCellFormatter().setHorizontalAlignment(9, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        layout.getFlexCellFormatter().setColSpan(9, 0, 2);
    } else {
        layout.setWidget(8, 0, cb);
        layout.getFlexCellFormatter().setHorizontalAlignment(8, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        layout.getFlexCellFormatter().setColSpan(8, 0, 2);
    }
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) IsLoginAvailable(cz.metacentrum.perun.webgui.json.usersManager.IsLoginAvailable) CellTable(com.google.gwt.user.cellview.client.CellTable) GenerateAccount(cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount) CreatePassword(cz.metacentrum.perun.webgui.json.usersManager.CreatePassword) ValidateMemberAsync(cz.metacentrum.perun.webgui.json.membersManager.ValidateMemberAsync) CreateSpecificMember(cz.metacentrum.perun.webgui.json.membersManager.CreateSpecificMember) RegExp(com.google.gwt.regexp.shared.RegExp) CreateSpecificMember(cz.metacentrum.perun.webgui.json.membersManager.CreateSpecificMember) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) HashMap(java.util.HashMap) Map(java.util.Map) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FindUsersInVo(cz.metacentrum.perun.webgui.json.membersManager.FindUsersInVo) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) SetLogin(cz.metacentrum.perun.webgui.json.usersManager.SetLogin) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 3 with CellTable

use of com.google.gwt.user.cellview.client.CellTable in project perun by CESNET.

the class CreateFacilityTabItem method draw.

public Widget draw() {
    final TabItemWithUrl tab = this;
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // FOOTER
    FlexTable header = new FlexTable();
    header.setStyleName("wizardHeader");
    final CustomButton back = TabMenu.getPredefinedButton(ButtonType.BACK, ButtonTranslation.INSTANCE.backButton());
    final CustomButton next = TabMenu.getPredefinedButton(ButtonType.CONTINUE, ButtonTranslation.INSTANCE.continueButton());
    back.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // skipped services selection
            if (selectedPage == 8 && selectedServices.isEmpty()) {
                selectedPage = 5;
            } else if (selectedPage > 2) {
                selectedPage--;
            }
            draw();
        }
    });
    int column = 0;
    header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.databaseServerIcon()));
    column++;
    Label title = new Label();
    title.getElement().setAttribute("style", "font-size: 1.35em;");
    header.setWidget(0, column, title);
    column++;
    // do not get back to first page
    if (selectedPage > 2) {
        header.setWidget(0, column, back);
        column++;
    }
    if (selectedPage > 1 && selectedPage != numberOfPages) {
        header.setWidget(0, column, next);
    }
    // MAIN CONTENT
    SimplePanel content = new SimplePanel();
    content.getElement().setId("centered-wrapper-outer");
    if (selectedPage == 1) {
        // header
        title.setText("Create facility " + selectedPage + " of " + numberOfPages + ": Create definition");
        // content
        FlexTable layout = new FlexTable();
        layout.setStyleName("inputFormFlexTable");
        FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
        // widgets
        final ExtendedTextBox name = new ExtendedTextBox();
        final ExtendedTextBox description = new ExtendedTextBox();
        final ListBoxWithObjects<Facility> copyOfFacility = new ListBoxWithObjects<Facility>();
        final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

            @Override
            public boolean validateTextBox() {
                if (name.getTextBox().getText().trim().isEmpty()) {
                    name.setError("Facility name can't be empty.");
                    return false;
                } else if (!name.getTextBox().getText().trim().matches(Utils.FACILITY_NAME_MATCHER)) {
                    name.setError("Name can contain only letters, numbers, dash, dot and underscore.");
                    return false;
                } else {
                    name.setOk();
                    return true;
                }
            }
        };
        name.setValidator(validator);
        // default
        if (facilitiesToCopyFrom != null && !facilitiesToCopyFrom.isEmpty()) {
            copyOfFacility.addNotSelectedOption();
            copyOfFacility.addAllItems(new TableSorter<Facility>().sortByName(facilitiesToCopyFrom));
            copyOfFacility.setSelectedIndex(0);
        }
        // Add some standard form options
        layout.setHTML(0, 0, "Name:");
        layout.setWidget(0, 1, name);
        layout.setHTML(1, 0, "Description:");
        layout.setWidget(1, 1, description);
        layout.setHTML(2, 0, "As copy of:");
        layout.setWidget(2, 1, copyOfFacility);
        final CustomButton create = TabMenu.getPredefinedButton(ButtonType.CREATE, "Create new facility");
        TabMenu menu = new TabMenu();
        menu.addWidget(create);
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                UiElements.generateAlert("Confirmation", "Do you really want to exit create facility wizard ?", new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent clickEvent) {
                        session.getTabManager().closeTab(tab);
                    }
                });
            }
        }));
        VerticalPanel innerContent = new VerticalPanel();
        innerContent.add(layout);
        innerContent.add(menu);
        innerContent.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
        content.setWidget(innerContent);
        for (int i = 0; i < layout.getRowCount(); i++) {
            cellFormatter.addStyleName(i, 0, "itemName");
        }
        final GetFacilities getFacs = new GetFacilities(false, new JsonCallbackEvents() {

            public void onFinished(JavaScriptObject jso) {
                copyOfFacility.removeNotSelectedOption();
                copyOfFacility.clear();
                ArrayList<Facility> fac = JsonUtils.jsoAsList(jso);
                if (fac.isEmpty() || fac == null) {
                    copyOfFacility.addItem("No facilities available");
                    return;
                }
                fac = new TableSorter<Facility>().sortByName(fac);
                facilitiesToCopyFrom.addAll(fac);
                copyOfFacility.addNotSelectedOption();
                copyOfFacility.addAllItems(fac);
                copyOfFacility.setSelectedIndex(0);
                next.setEnabled(true);
            }

            public void onError(PerunError error) {
                next.setEnabled(true);
                copyOfFacility.removeNotSelectedOption();
                copyOfFacility.clear();
                copyOfFacility.addItem("Error while loading");
            }

            public void onLoadingStart() {
                next.setEnabled(false);
                copyOfFacility.removeNotSelectedOption();
                copyOfFacility.clear();
                copyOfFacility.addItem("Loading...");
            }
        });
        // load facilities if empty
        if (facilitiesToCopyFrom == null || facilitiesToCopyFrom.isEmpty()) {
            getFacs.retrieveData();
        }
        // next button
        create.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                if (!visitedBasic) {
                    if (validator.validateTextBox()) {
                        CreateFacility request = new CreateFacility(JsonCallbackEvents.disableButtonEvents(create, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                facility = jso.cast();
                                // set new facility as editable in GUI
                                session.getEditableFacilities().add(facility.getId());
                                if (copyOfFacility.getSelectedIndex() > 0) {
                                    sourceFacility = copyOfFacility.getSelectedObject();
                                }
                                visitedBasic = true;
                                selectedPage++;
                                draw();
                            }

                            public void onLoadingStart() {
                                copyOfFacility.setEnabled(false);
                            }

                            public void onError(PerunError error) {
                                copyOfFacility.setEnabled(true);
                            }
                        }));
                        request.createFacility(name.getTextBox().getText().trim(), description.getTextBox().getText().trim());
                    }
                } else {
                    // facility created - continue
                    selectedPage++;
                    draw();
                }
            }
        });
        if (visitedBasic) {
            // if tab was visited
            name.getTextBox().setValue(facility.getName());
            if (facility.getDescription() != null) {
                description.getTextBox().setValue(facility.getDescription());
            }
            name.getTextBox().setEnabled(false);
            description.getTextBox().setEnabled(false);
            copyOfFacility.setEnabled(false);
            if (sourceFacility != null) {
                copyOfFacility.setVisible(true);
                copyOfFacility.addItem(sourceFacility);
                copyOfFacility.setSelected(sourceFacility, true);
            }
        }
    } else if (selectedPage == 2) {
        // header
        title.setText("Create facility " + selectedPage + " of " + numberOfPages + ": Add managers");
        // content
        VerticalPanel innerContent = new VerticalPanel();
        innerContent.setSize("100%", "100%");
        // HORIZONTAL MENU
        final TabMenu menu = new TabMenu();
        final ListBox box = new ListBox();
        box.addItem("Users");
        box.addItem("Groups");
        box.setSelectedIndex(selectedDropDownIndex);
        final ScrollPanel sp = new ScrollPanel();
        sp.addStyleName("perun-tableScrollPanel");
        // request
        final GetRichAdminsWithAttributes admins = new GetRichAdminsWithAttributes(PerunEntity.FACILITY, facility.getId(), null);
        final GetAdminGroups adminGroups = new GetAdminGroups(PerunEntity.FACILITY, facility.getId());
        box.addChangeHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent event) {
                if (box.getSelectedIndex() == 0) {
                    selectedDropDownIndex = 0;
                    sp.setWidget(fillContentUsers(admins, menu));
                } else {
                    selectedDropDownIndex = 1;
                    sp.setWidget(fillContentGroups(adminGroups, menu));
                }
            }
        });
        // if first and copy from
        if (!visitedAdmins && sourceFacility != null) {
            CopyManagers copy = new CopyManagers(new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    if (selectedDropDownIndex == 0) {
                        sp.setWidget(fillContentUsers(admins, menu));
                    } else {
                        sp.setWidget(fillContentGroups(adminGroups, menu));
                    }
                    menu.addWidget(2, new HTML("<strong>Select mode: </strong>"));
                    menu.addWidget(3, box);
                    menu.addWidget(4, new Image(SmallIcons.INSTANCE.helpIcon()));
                    menu.addWidget(5, new HTML("<strong>People with privilege to manage this facility in Perun.</strong>"));
                }

                @Override
                public void onError(PerunError error) {
                    if (selectedDropDownIndex == 0) {
                        sp.setWidget(fillContentUsers(admins, menu));
                    } else {
                        sp.setWidget(fillContentGroups(adminGroups, menu));
                    }
                    menu.addWidget(2, new HTML("<strong>Select mode: </strong>"));
                    menu.addWidget(3, box);
                    menu.addWidget(4, new Image(SmallIcons.INSTANCE.helpIcon()));
                    menu.addWidget(5, new HTML("<strong>People with privilege to manage this facility in Perun.</strong>"));
                }
            });
            copy.copyFacilityManagers(sourceFacility.getId(), facility.getId());
        } else {
            if (selectedDropDownIndex == 0) {
                sp.setWidget(fillContentUsers(admins, menu));
            } else {
                sp.setWidget(fillContentGroups(adminGroups, menu));
            }
            menu.addWidget(2, new HTML("<strong>Select mode: </strong>"));
            menu.addWidget(3, box);
            menu.addWidget(4, new Image(SmallIcons.INSTANCE.helpIcon()));
            menu.addWidget(5, new HTML("<strong>People with privilege to manage this facility in Perun. They aren't automatically \"roots\" on machine.</strong>"));
        }
        visitedAdmins = true;
        session.getUiElements().resizePerunTable(sp, 300, this);
        // add menu and the table to the main panel
        innerContent.add(menu);
        innerContent.setCellHeight(menu, "30px");
        innerContent.add(sp);
        content.setWidget(innerContent);
        next.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                selectedPage++;
                draw();
            }
        });
    } else if (selectedPage == 3) {
        // header
        title.setText("Create facility " + selectedPage + " of " + numberOfPages + ": Add owners");
        // CONTENT
        VerticalPanel innerContent = new VerticalPanel();
        innerContent.setSize("100%", "100%");
        // MENU
        TabMenu menu = new TabMenu();
        // CALLBACK
        final GetFacilityOwners jsonCallback = new GetFacilityOwners(facility);
        innerContent.add(menu);
        innerContent.setCellHeight(menu, "30px");
        // add button
        CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addNewOwners());
        addButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                session.getTabManager().addTabToCurrentTab(new AddFacilityOwnerTabItem(facility), true);
            }
        });
        // remove button
        final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedOwners());
        removeButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                final ArrayList<Owner> list = jsonCallback.getTableSelectedList();
                UiElements.showDeleteConfirm(list, new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent clickEvent) {
                        // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                        for (int i = 0; i < list.size(); i++) {
                            if (i == list.size() - 1) {
                                RemoveOwner request = new RemoveOwner(JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(jsonCallback)));
                                request.removeFacilityOwner(facility.getId(), list.get(i).getId());
                            } else {
                                RemoveOwner request = new RemoveOwner(JsonCallbackEvents.disableButtonEvents(removeButton));
                                request.removeFacilityOwner(facility.getId(), list.get(i).getId());
                            }
                        }
                    }
                });
            }
        });
        menu.addWidget(addButton);
        menu.addWidget(removeButton);
        // TABLE
        CellTable<Owner> table = jsonCallback.getEmptyTable();
        table.addStyleName("perun-table");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        innerContent.add(sp);
        // call for data
        if (!visitedOwners && sourceFacility != null) {
            // copy owners
            CopyOwners copy = new CopyOwners(new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    jsonCallback.retrieveData();
                }

                @Override
                public void onError(PerunError error) {
                    jsonCallback.retrieveData();
                }
            });
            copy.copyFacilityOwners(sourceFacility.getId(), facility.getId());
        } else {
            jsonCallback.retrieveData();
        }
        removeButton.setEnabled(false);
        JsonUtils.addTableManagedButton(jsonCallback, table, removeButton);
        session.getUiElements().resizePerunTable(sp, 300, this);
        visitedOwners = true;
        next.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                selectedPage++;
                draw();
            }
        });
        content.add(innerContent);
    } else if (selectedPage == 4) {
        // header
        title.setText("Create facility " + selectedPage + " of " + numberOfPages + ": Add hosts");
        // SPLIT
        FlexTable hp = new FlexTable();
        hp.setSize("100%", "100%");
        // HOSTS WIDGET
        VerticalPanel hostsWidget = new VerticalPanel();
        hostsWidget.setSize("100%", "100%");
        final GetHosts hosts = new GetHosts(facility.getId(), new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                // store hosts for future use
                newFacilityHosts.clear();
                newFacilityHosts.addAll(JsonUtils.<Host>jsoAsList(jso));
            }
        });
        final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(hosts);
        // menu
        TabMenu menu = new TabMenu();
        final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeHosts());
        removeButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                final ArrayList<Host> hostsForRemoving = hosts.getTableSelectedList();
                String text = "Following hosts will be removed from facility.";
                UiElements.showDeleteConfirm(hostsForRemoving, text, new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent clickEvent) {
                        // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                        for (int i = 0; i < hostsForRemoving.size(); i++) {
                            if (i == hostsForRemoving.size() - 1) {
                                RemoveHosts request = new RemoveHosts(facility.getId(), JsonCallbackEvents.disableButtonEvents(removeButton, events));
                                request.removeHost(hostsForRemoving.get(i).getId());
                            } else {
                                RemoveHosts request = new RemoveHosts(facility.getId(), JsonCallbackEvents.disableButtonEvents(removeButton));
                                request.removeHost(hostsForRemoving.get(i).getId());
                            }
                        }
                    }
                });
            }
        });
        menu.addWidget(removeButton);
        // Hosts table
        CellTable<Host> table = hosts.getTable(new FieldUpdater<Host, String>() {

            @Override
            public void update(int index, Host object, String value) {
                session.getTabManager().addTab(new FacilityHostsSettingsTabItem(facility, object));
            }
        });
        removeButton.setEnabled(false);
        JsonUtils.addTableManagedButton(hosts, 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 menu and the table to the main panel
        hostsWidget.add(menu);
        hostsWidget.setCellHeight(menu, "30px");
        hostsWidget.add(sp);
        session.getUiElements().resizePerunTable(sp, 300, 50, this);
        // ADD WIDGET
        final ExtendedTextArea newHosts = new ExtendedTextArea();
        newHosts.getTextArea().setSize("335px", "200px");
        newHosts.getTextArea().setText(newHostInput);
        final ExtendedTextArea.TextAreaValidator validator = new ExtendedTextArea.TextAreaValidator() {

            @Override
            public boolean validateTextArea() {
                if (newHosts.getTextArea().getText().trim().isEmpty()) {
                    newHosts.setError("Please enter at least one hostname to add it to facility.");
                    return false;
                } else {
                    newHosts.setOk();
                    return true;
                }
            }
        };
        newHosts.setValidator(validator);
        newHosts.getTextArea().addKeyUpHandler(new KeyUpHandler() {

            @Override
            public void onKeyUp(KeyUpEvent event) {
                newHostInput = newHosts.getTextArea().getText();
            }
        });
        final CustomButton addHostsButton = new CustomButton("Add", ButtonTranslation.INSTANCE.addHost(), SmallIcons.INSTANCE.arrowRightIcon());
        addHostsButton.setImageAlign(true);
        addHostsButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                if (validator.validateTextArea()) {
                    String hostnames = newHosts.getTextArea().getText().trim();
                    String[] hosts = hostnames.split("\n");
                    // trim whitespace
                    for (int i = 0; i < hosts.length; i++) {
                        hosts[i] = hosts[i].trim();
                    }
                    AddHosts request = new AddHosts(facility.getId(), JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(addHostsButton, events), new JsonCallbackEvents() {

                        public void onFinished(JavaScriptObject jso) {
                            // clear input
                            newHosts.getTextArea().setText("");
                            newHostInput = "";
                        }
                    }));
                    request.addHosts(hosts);
                }
            }
        });
        // layout
        FlexTable layout = new FlexTable();
        layout.setStyleName("inputFormFlexTable");
        FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
        layout.setHTML(0, 0, "Hostnames:");
        layout.setWidget(1, 0, newHosts);
        cellFormatter.addStyleName(0, 0, "itemName");
        layout.setHTML(2, 0, "Enter one host per line. You can use \"[x-y]\" in hostname to generate hosts with numbers from x to y. This replacer can be specified multiple times in one hostname to generate MxN combinations.");
        cellFormatter.addStyleName(2, 0, "inputFormInlineComment");
        cellFormatter.setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        layout.setWidget(3, 0, addHostsButton);
        addHostsButton.getElement().setAttribute("style", addHostsButton.getElement().getAttribute("style") + " float: right;");
        // FILL LAYOUT
        hp.setWidget(0, 0, layout);
        hp.setWidget(0, 1, hostsWidget);
        hp.getFlexCellFormatter().setWidth(0, 0, "350px");
        hp.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
        hp.getFlexCellFormatter().setStyleName(0, 0, "border-right");
        content.add(hp);
        next.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                selectedPage++;
                draw();
            }
        });
    } else if (selectedPage == 5) {
        // header
        title.setText("Create facility " + selectedPage + " of " + numberOfPages + ": Select services");
        // SPLIT
        FlexTable hp = new FlexTable();
        hp.setSize("100%", "100%");
        // create widget for the whole page
        VerticalPanel mainTab = new VerticalPanel();
        mainTab.setSize("100%", "100%");
        // get services
        final GetServices services = new GetServices();
        services.setEvents(new JsonCallbackEvents() {

            public void onFinished(JavaScriptObject jso) {
                if (selectedServices != null && !selectedServices.isEmpty()) {
                    for (Service s : selectedServices) {
                        services.getSelectionModel().setSelected(s, true);
                    }
                }
            }

            public void onLoadingStart() {
            }

            public void onError(PerunError error) {
            }
        });
        // get the table of services with custom field updater (lines are clickable and open service details)
        CellTable<Service> table = services.getTable();
        // add styling to table with services
        table.addStyleName("perun-table");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        mainTab.add(sp);
        final VerticalPanel helpWidget = new VerticalPanel();
        helpWidget.setSpacing(5);
        final FlowPanel fw = new FlowPanel();
        CustomButton clearButton = new CustomButton("Clear selection", "Clear services selection.", SmallIcons.INSTANCE.deleteIcon());
        clearButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                services.clearTableSelectedSet();
            }
        });
        clearButton.addStyleName("margin");
        fw.add(clearButton);
        fw.add(new AjaxLoaderImage(true));
        GetServicesPackages packs = new GetServicesPackages(new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                // remove loader
                fw.remove(1);
                // fill buttons based on packages
                ArrayList<ServicesPackage> packages = JsonUtils.jsoAsList(jso);
                for (final ServicesPackage pack : packages) {
                    final CustomButton button = new CustomButton(pack.getName(), pack.getDescription(), SmallIcons.INSTANCE.addIcon());
                    button.addStyleName("margin");
                    fw.add(button);
                    button.addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            GetServicesFromServicesPackage serv = new GetServicesFromServicesPackage(pack.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    for (Service s : JsonUtils.<Service>jsoAsList(jso)) {
                                        // select services from pack in table
                                        services.getSelectionModel().setSelected(s, true);
                                    }
                                }
                            }));
                            serv.retrieveData();
                        }
                    });
                }
                if (packages == null || packages.isEmpty()) {
                    fw.add(new HTML("There are no services packages defined in Perun. Use manual selection."));
                }
            }

            @Override
            public void onError(PerunError error) {
                // remove loader
                fw.remove(1);
                fw.add(new HTML("Error when loading services packages defined in Perun. Use manual selection."));
            }
        });
        packs.retrieveData();
        HTML helpText = new HTML("Please select set of services, which will be managed by Perun. You can use buttons below to help you select proper set of services.");
        helpText.setStyleName("inputFormInlineComment");
        helpWidget.add(helpText);
        helpWidget.add(fw);
        // select by source if not already set
        if (sourceFacility != null && (selectedServices == null || selectedServices.isEmpty())) {
            GetFacilityAssignedServices getCall = new GetFacilityAssignedServices(sourceFacility.getId(), new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    ArrayList<Service> serv = JsonUtils.jsoAsList(jso);
                    services.clearTableSelectedSet();
                    for (Service s : serv) {
                        services.getSelectionModel().setSelected(s, true);
                    }
                }
            });
            getCall.retrieveData();
        }
        hp.setWidget(0, 0, helpWidget);
        hp.setWidget(0, 1, mainTab);
        hp.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
        hp.getFlexCellFormatter().setWidth(0, 0, "350px");
        hp.getFlexCellFormatter().setStyleName(0, 0, "border-right");
        content.setWidget(hp);
        next.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                if (services.getTableSelectedList() == null || services.getTableSelectedList().isEmpty()) {
                    FlexTable layout = new FlexTable();
                    layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.informationIcon())));
                    layout.setHTML(0, 1, "<p>" + "You didn't select any service. Do you wish to skip services configuration ?");
                    layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                    layout.getFlexCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                    layout.getFlexCellFormatter().setStyleName(0, 0, "alert-box-image");
                    final Confirm c = new Confirm("No service selected", layout, true);
                    c.setOkButtonText("Yes");
                    c.setCancelButtonText("No");
                    c.setOkClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            selectedServices.clear();
                            // draw
                            selectedPage = 8;
                            draw();
                        }
                    });
                    c.setCancelClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            c.hide();
                        }
                    });
                    c.setNonScrollable(true);
                    c.show();
                } else {
                    // set selected services
                    selectedServices.clear();
                    for (Service s : new TableSorter<Service>().sortByName(services.getTableSelectedList())) {
                        selectedServices.add(s);
                    }
                    // draw
                    selectedPage++;
                    draw();
                }
            }
        });
        session.getUiElements().resizePerunTable(sp, 350, this);
    } else if (selectedPage == 6) {
        // header
        title.setText("Create facility " + selectedPage + " of " + numberOfPages + ": Configure services");
        // content
        VerticalPanel settingsTab = new VerticalPanel();
        settingsTab.setSize("100%", "100%");
        // HORIZONTAL MENU
        TabMenu menu = new TabMenu();
        // Get Attributes method
        final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2();
        final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
        // get empty table
        final CellTable<Attribute> table = reqAttrs.getEmptyTable();
        // ids to retrieve data from rpc
        final Map<String, Integer> ids = new HashMap<String, Integer>();
        ids.put("facility", facility.getId());
        final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
        final JsonCallbackEvents refreshEvents = JsonCallbackEvents.refreshTableEvents(reqAttrs);
        final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents);
        saveChangesButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(list)) {
                    SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                    // set to new facility
                    ids.put("facility", facility.getId());
                    request.setAttributes(ids, reqAttrs.getTableSelectedList());
                }
            }
        });
        // clear
        servList.removeAllOption();
        servList.clear();
        // fill
        if (selectedServices == null || selectedServices.isEmpty()) {
            // wizard shouldn't allow to get there
            servList.addItem("No service selected");
            servList.setEnabled(false);
        } else if (!visitedConfigure && sourceFacility != null) {
            // first visit and copy
            ids.put("facility", sourceFacility.getId());
            servList.addAllItems(selectedServices);
            servList.addAllOption();
            // default all
            servList.setSelectedIndex(0);
            reqAttrs.setEvents(new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    for (Attribute a : reqAttrs.getList()) {
                        if (!a.getDefinition().equals("virt") && a.getValue() != null && !a.getValue().isEmpty()) {
                            // pre-select non-virt attributes with some value
                            reqAttrs.getSelectionModel().setSelected(a, true);
                        } else {
                            reqAttrs.getSelectionModel().setSelected(a, false);
                        }
                    }
                }
            });
            reqAttrs.setServicesToGetAttributesFor(servList.getAllObjects());
            reqAttrs.setIds(ids);
            reqAttrs.clearTable();
            reqAttrs.retrieveData();
            // inform user about it
            UiElements.generateInfo("Pre-filled values", "Services configuration was pre-filled from facility you selected to copy. <p><strong>Nothing is saved to new facility until you click on \"Save\" button.</strong>");
        } else {
            servList.addAllItems(selectedServices);
            servList.addAllOption();
            // default all
            servList.setSelectedIndex(0);
            reqAttrs.setServicesToGetAttributesFor(servList.getAllObjects());
            reqAttrs.setIds(ids);
            reqAttrs.clearTable();
            reqAttrs.retrieveData();
        }
        servList.addChangeHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent event) {
                if (servList.getSelectedIndex() == 0) {
                    ids.remove("service");
                    reqAttrs.setServicesToGetAttributesFor(servList.getAllObjects());
                } else {
                    ids.put("service", servList.getSelectedObject().getId());
                    reqAttrs.setServicesToGetAttributesFor(null);
                }
                reqAttrs.setIds(ids);
                reqAttrs.clearTable();
                reqAttrs.retrieveData();
            }
        });
        visitedConfigure = true;
        menu.addWidget(saveChangesButton);
        menu.addWidget(new HTML("<strong>Filter view by Service: </strong>"));
        menu.addWidget(servList);
        table.addStyleName("perun-table");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        // add menu and the table to the main panel
        settingsTab.add(menu);
        settingsTab.setCellHeight(menu, "30px");
        settingsTab.add(sp);
        session.getUiElements().resizePerunTable(sp, 350, this);
        content.add(settingsTab);
        next.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                selectedPage++;
                draw();
            }
        });
    } else if (selectedPage == 7) {
        // header
        title.setText("Create facility " + selectedPage + " of " + numberOfPages + ": Configure service destinations");
        // SPLIT
        FlexTable hp = new FlexTable();
        hp.setSize("100%", "100%");
        FlexTable layout = new FlexTable();
        layout.setStyleName("inputFormFlexTable");
        FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
        layout.setWidth("350px");
        final ExtendedSuggestBox destination = new ExtendedSuggestBox();
        final ListBox type = new ListBox();
        type.addItem("HOST", "host");
        type.addItem("USER@HOST", "user@host");
        type.addItem("USER@HOST:PORT", "user@host:port");
        type.addItem("URL", "url");
        type.addItem("MAIL", "email");
        type.addItem("SIGNED MAIL", "semail");
        type.addItem("SERVICE SPECIFIC", "service-specific");
        final ListBox propTypeSelect = new ListBox();
        propTypeSelect.addItem("PARALLEL");
        propTypeSelect.addItem("DUMMY");
        // propTypeSelect.addItem("SERIAL"); TODO - will we ever use it ?
        final HTML propTypeHelp = new HTML("PARALLEL - Data for all destinations of one service are pushed in parallel.");
        destination.getSuggestOracle().clear();
        for (Host h : newFacilityHosts) {
            destination.getSuggestOracle().add(h.getName());
        }
        final Label destinationLabel = new Label();
        destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
        final CustomButton addButton = new CustomButton("Add", ButtonTranslation.INSTANCE.addDestination(), SmallIcons.INSTANCE.arrowRightIcon());
        addButton.setImageAlign(true);
        final ListBoxWithObjects<Service> services = new ListBoxWithObjects<Service>();
        final CheckBox useHosts = new CheckBox(WidgetTranslation.INSTANCE.useFacilityHostnames(), false);
        useHosts.setTitle(WidgetTranslation.INSTANCE.useFacilityHostnamesTitle());
        final ExtendedSuggestBox.SuggestBoxValidator validator = new ExtendedSuggestBox.SuggestBoxValidator() {

            @Override
            public boolean validateSuggestBox() {
                if (destination.getSuggestBox().getText().trim().isEmpty() && useHosts.getValue() == false) {
                    destination.setError("Destination value can't be empty.");
                    return false;
                }
                // check as email
                if (type.getSelectedIndex() > 3 && type.getSelectedIndex() < 6) {
                    if (!JsonUtils.isValidEmail(destination.getSuggestBox().getText().trim())) {
                        destination.setError("Not valid email address.");
                        return false;
                    } else {
                        destination.setOk();
                        return true;
                    }
                }
                destination.setOk();
                return true;
            }
        };
        destination.setValidator(validator);
        type.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                // if hosts - checkbox visible
                if (type.getSelectedIndex() == 0) {
                    useHosts.setVisible(true);
                } else {
                    useHosts.setVisible(false);
                    useHosts.setValue(false);
                    destination.getSuggestBox().setEnabled(true);
                }
                if (type.getSelectedIndex() < 3) {
                    destination.getSuggestOracle().clear();
                    for (Host h : newFacilityHosts) {
                        destination.getSuggestOracle().add(h.getName());
                    }
                } else {
                    destination.getSuggestOracle().clear();
                }
                // set label
                if (type.getSelectedIndex() == 0) {
                    destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
                } else if (type.getSelectedIndex() == 1) {
                    destinationLabel.getElement().setInnerHTML("<strong>User@host:</strong>");
                } else if (type.getSelectedIndex() == 2) {
                    destinationLabel.getElement().setInnerHTML("<strong>User@host:port:</strong>");
                } else if (type.getSelectedIndex() == 3) {
                    destinationLabel.getElement().setInnerHTML("<strong>URL:</strong>");
                } else if (type.getSelectedIndex() == 4) {
                    destinationLabel.getElement().setInnerHTML("<strong>Mail:</strong>");
                } else if (type.getSelectedIndex() == 5) {
                    destinationLabel.getElement().setInnerHTML("<strong>Signed mail:</strong>");
                } else if (type.getSelectedIndex() == 6) {
                    destinationLabel.getElement().setInnerHTML("<strong>Service specific:</strong>");
                }
            }
        });
        useHosts.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                if (useHosts.getValue() == true) {
                    destination.getSuggestBox().setEnabled(false);
                    destination.setOk();
                    // use only PARALLEL since API doesn't read it
                    propTypeSelect.setSelectedIndex(0);
                    propTypeHelp.setHTML("PARALLEL - Data for all destinations and one service are pushed in parallel.");
                } else {
                    destination.getSuggestBox().setEnabled(true);
                }
            }
        });
        propTypeSelect.addChangeHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent changeEvent) {
                if (propTypeSelect.getSelectedIndex() == 0) {
                    propTypeHelp.setHTML("PARALLEL - Data for all destinations and one service are pushed in parallel.");
                } else {
                    propTypeHelp.setHTML("DUMMY - Service provisioning data is generated by Perun, but not pushed to destination. Destinations can pull data by themselves.");
                    // allow to set custom value - can't use facility hosts
                    useHosts.setValue(false);
                    destination.getSuggestBox().setEnabled(true);
                }
            }
        });
        services.removeAllOption();
        services.clear();
        if (selectedServices == null || selectedServices.isEmpty()) {
            // wizard shouldn't allow
            services.addItem("No service available");
        } else {
            services.addAllItems(selectedServices);
            services.addAllOption();
            services.setSelectedIndex(0);
        }
        cellFormatter.setColSpan(0, 0, 2);
        HTML text = new HTML("Please add destinations for service configuration delivery. New service configuration can be performed directly on facility (dest. type HOST) or sent to URL or by an email.");
        text.setStyleName("inputFormInlineComment");
        layout.setWidget(0, 0, text);
        layout.setHTML(1, 0, "Service:");
        layout.setWidget(1, 1, services);
        layout.setHTML(2, 0, "Type:");
        layout.setWidget(2, 1, type);
        layout.setWidget(3, 0, destinationLabel);
        layout.setWidget(3, 1, destination);
        layout.setWidget(4, 1, useHosts);
        layout.setHTML(5, 0, "Propagation:");
        layout.setWidget(5, 1, propTypeSelect);
        for (int i = 1; i < layout.getRowCount(); i++) {
            cellFormatter.addStyleName(i, 0, "itemName");
        }
        propTypeHelp.setStyleName("inputFormInlineComment");
        layout.setWidget(6, 0, propTypeHelp);
        cellFormatter.setColSpan(6, 0, 2);
        // callback
        final GetAllRichDestinations callback = new GetAllRichDestinations(facility, null);
        addButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                if (services.isEmpty()) {
                    // no services available
                    addButton.setEnabled(false);
                }
                if (validator.validateSuggestBox()) {
                    if (services.getSelectedIndex() == 0) {
                        // selected all
                        if (useHosts.getValue() == true) {
                            // auto by hosts
                            AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.refreshTableEvents(callback));
                            request.addDestinationByHosts(services.getAllObjects());
                        } else {
                            // default
                            // FIXME - there are no services on facility at the moment, use list of services
                            AddDestination request = new AddDestination(facility, JsonCallbackEvents.refreshTableEvents(callback));
                            request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getAllObjects(), propTypeSelect.getSelectedValue());
                        }
                    } else {
                        // selected one
                        if (useHosts.getValue() == true) {
                            // auto by hosts
                            AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.refreshTableEvents(callback));
                            request.addDestinationByHosts(services.getSelectedObject());
                        } else {
                            // default
                            AddDestination request = new AddDestination(facility, JsonCallbackEvents.refreshTableEvents(callback));
                            request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getSelectedObject(), propTypeSelect.getSelectedValue());
                        }
                    }
                }
            }
        });
        cellFormatter.setColSpan(5, 0, 2);
        layout.setWidget(5, 0, addButton);
        addButton.getElement().setAttribute("style", addButton.getElement().getAttribute("style") + " float: right;");
        // DESTINATIONS WIDGET
        // main content
        final VerticalPanel destWidget = new VerticalPanel();
        destWidget.setSize("100%", "100%");
        // menu
        final TabMenu menu = new TabMenu();
        destWidget.add(menu);
        destWidget.setCellHeight(menu, "30px");
        // do not make callback yet
        final CellTable<Destination> table = callback.getTable();
        // refresh table events
        final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback);
        // style table
        table.addStyleName("perun-table");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        destWidget.add(sp);
        session.getUiElements().resizePerunTable(sp, 300, 50, this);
        final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedDestinations());
        menu.addWidget(removeButton);
        removeButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                final ArrayList<Destination> destForRemoving = callback.getTableSelectedList();
                String text = "Following destinations will be removed. <strong>Removing destination will stop propagation of service configuration for this destination/service.</strong>";
                UiElements.showDeleteConfirm(destForRemoving, text, new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent clickEvent) {
                        // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                        for (int i = 0; i < destForRemoving.size(); i++) {
                            if (i == destForRemoving.size() - 1) {
                                RemoveDestination request = new RemoveDestination(facility.getId(), destForRemoving.get(i).getService().getId(), JsonCallbackEvents.disableButtonEvents(removeButton, events));
                                request.removeDestination(destForRemoving.get(i).getDestination(), destForRemoving.get(i).getType());
                            } else {
                                RemoveDestination request = new RemoveDestination(facility.getId(), destForRemoving.get(i).getService().getId(), JsonCallbackEvents.disableButtonEvents(removeButton));
                                request.removeDestination(destForRemoving.get(i).getDestination(), destForRemoving.get(i).getType());
                            }
                        }
                    }
                });
            }
        });
        removeButton.setEnabled(false);
        JsonUtils.addTableManagedButton(callback, table, removeButton);
        // filter box
        menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {

            public void searchFor(String text) {
                callback.filterTable(text);
            }
        }, ButtonTranslation.INSTANCE.filterDestination());
        // FILL LAYOUT
        hp.setWidget(0, 0, layout);
        hp.setWidget(0, 1, destWidget);
        hp.getFlexCellFormatter().setWidth(0, 0, "350px");
        hp.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
        hp.getFlexCellFormatter().setStyleName(0, 0, "border-right");
        content.add(hp);
        next.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                selectedPage++;
                draw();
            }
        });
    } else if (selectedPage == 8) {
        // header
        title.setText("Create facility " + selectedPage + " of " + numberOfPages + ": Finish");
        SimplePanel sp = new SimplePanel();
        sp.getElement().setId("centered-wrapper-inner");
        session.getUiElements().resizePerunTable(sp, 350, this);
        FlexTable ft = new FlexTable();
        ft.setSize("100%", "100%");
        ft.setCellPadding(5);
        ft.getElement().setId("centered-content");
        HTML text = new HTML("Your facility was created and configured.<p>You can exit or continue by creating resource(s) for VOs.");
        text.setStyleName("now-managing");
        ft.setWidget(0, 0, text);
        if (sourceFacility != null) {
            CustomButton copyResources = new CustomButton("Copy resources from source facility", SmallIcons.INSTANCE.copyIcon());
            copyResources.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                // session.getTabManager().closeTab(tab);
                }
            });
            CustomButton createResource = new CustomButton("Create new resource…", SmallIcons.INSTANCE.addIcon());
            createResource.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceTabItem(facility), false);
                // session.getTabManager().closeTab(tab);
                }
            });
            // TODO - when there will be new copy resources wizard
            // ft.setWidget(1, 0, copyResources);
            ft.setWidget(2, 0, createResource);
        } else {
            CustomButton createResource = new CustomButton("Create new resource…", SmallIcons.INSTANCE.addIcon());
            createResource.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceTabItem(facility), false);
                // session.getTabManager().closeTab(tab);
                }
            });
            ft.setWidget(1, 0, createResource);
        }
        CustomButton finish = new CustomButton("Exit", "Exit wizard", SmallIcons.INSTANCE.doorOutIcon());
        finish.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                session.getTabManager().closeTab(tab);
            }
        });
        ft.setWidget(3, 0, finish);
        sp.add(ft);
        content.add(sp);
    }
    vp.add(header);
    vp.add(new HTML("<hr size=\"1\" color=\"#ccc\">"));
    vp.add(content);
    vp.setCellHeight(content, "100%");
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) CellTable(com.google.gwt.user.cellview.client.CellTable) GetRequiredAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetRequiredAttributesV2) GetRichAdminsWithAttributes(cz.metacentrum.perun.webgui.json.authzResolver.GetRichAdminsWithAttributes) HashMap(java.util.HashMap) Map(java.util.Map) TabItemWithUrl(cz.metacentrum.perun.webgui.tabs.TabItemWithUrl) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) GetAdminGroups(cz.metacentrum.perun.webgui.json.authzResolver.GetAdminGroups) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CreateFacilityResourceTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.CreateFacilityResourceTabItem)

Example 4 with CellTable

use of com.google.gwt.user.cellview.client.CellTable in project perun by CESNET.

the class EntitylessAttributesDetailTabItem method draw.

@Override
public Widget draw() {
    titleWidget.setText(def.getName());
    final TabItem tab = this;
    // create main panel for content
    final FlexTable mainPage = new FlexTable();
    mainPage.setWidth("100%");
    final ExtendedTextBox description = new ExtendedTextBox();
    description.setWidth("100%");
    description.getTextBox().setText(def.getDescription());
    final ExtendedTextBox.TextBoxValidator validator = () -> {
        if (description.getTextBox().getText().trim().isEmpty()) {
            description.setError("Description can't be empty.");
            return false;
        }
        description.setOk();
        return true;
    };
    final ExtendedTextBox displayName = new ExtendedTextBox();
    displayName.setWidth("100%");
    displayName.getTextBox().setText(def.getDisplayName());
    final ExtendedTextBox.TextBoxValidator validatorName = () -> {
        if (displayName.getTextBox().getText().trim().isEmpty()) {
            displayName.setError("Display name can't be empty.");
            return false;
        }
        displayName.setOk();
        return true;
    };
    description.setValidator(validator);
    displayName.setValidator(validatorName);
    // unique.setEnabled(false);
    unique.setValue(def.isUnique());
    if (Arrays.asList("core", "virt").contains(def.getDefinition()) || def.getEntity().equals("entityless")) {
        unique.setEnabled(false);
    } else {
        unique.addValueChangeHandler(valueChangeEvent -> {
            if (valueChangeEvent.getValue()) {
                UiElements.generateAlert("Change confirmation", "Changing attribute to UNIQUE might take a lot of time if there is large number of entities with set values. Perun will check uniqueness during the process. If values are not unique, conversion will be stopped.<p style=\"color:red;\">We strongly recommend to refresh whole browser window after conversion is DONE to prevent errors when modyfying attributes from GUI.", clickEvent -> {
                    ConvertAttributeToUnique convert = new ConvertAttributeToUnique(new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            unique.setValue(true);
                            unique.setEnabled(false);
                            def.setUnique(true);
                        }

                        @Override
                        public void onError(PerunError error) {
                            unique.setValue(false);
                            unique.setEnabled(true);
                            def.setUnique(false);
                        }

                        @Override
                        public void onLoadingStart() {
                            unique.setEnabled(false);
                        }
                    });
                    convert.convertAttributeDefinitionToUnique(def.getId());
                }, clickEvent -> {
                    // action canceled
                    unique.setValue(false);
                });
            } else {
                UiElements.generateInfo("Change not allowed", "Once converted to UNIQUE, attributes can't be converted back to non-unique.");
                unique.setValue(true);
            }
        });
    }
    FlexTable attributeDetailTable = new FlexTable();
    attributeDetailTable.setStyleName("inputFormFlexTable");
    final CustomButton updateButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save attribute details");
    updateButton.addClickHandler(event -> {
        final ArrayList<AttributeRights> list = new ArrayList<>();
        for (AttributeRights r : rights) {
            if (r.getRole().equalsIgnoreCase("SELF")) {
                list.add(getRightsFromWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, r));
            } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                list.add(getRightsFromWidgets(voRead, voWrite, r));
            } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                list.add(getRightsFromWidgets(groupRead, groupWrite, r));
            } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                list.add(getRightsFromWidgets(facilityRead, facilityWrite, r));
            }
        }
        if ((!Objects.equals(def.getDescription(), description.getTextBox().getText().trim()) || !Objects.equals(def.getDisplayName(), displayName.getTextBox().getText().trim()))) {
            if (!validator.validateTextBox() || !validatorName.validateTextBox())
                return;
            def.setDescription(description.getTextBox().getText().trim());
            def.setDisplayName(displayName.getTextBox().getText().trim());
            UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // after update - update rights
                    SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            enableDisableWidgets(true);
                        }

                        @Override
                        public void onLoadingStart() {
                            enableDisableWidgets(false);
                        }

                        @Override
                        public void onError(PerunError error) {
                            enableDisableWidgets(true);
                        }
                    }));
                    request.setAttributeRights(list);
                }
            }));
            request.updateAttribute(def);
        } else {
            // after update - update rights
            SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(updateButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    enableDisableWidgets(true);
                }

                @Override
                public void onLoadingStart() {
                    enableDisableWidgets(false);
                }

                @Override
                public void onError(PerunError error) {
                    enableDisableWidgets(true);
                }
            }));
            request.setAttributeRights(list);
        }
    });
    attributeDetailTable.setHTML(0, 0, "Display name:");
    attributeDetailTable.setWidget(0, 1, displayName);
    attributeDetailTable.setHTML(1, 0, "Description:");
    attributeDetailTable.setWidget(1, 1, description);
    attributeDetailTable.setHTML(2, 0, "Unique:");
    attributeDetailTable.setWidget(2, 1, unique);
    for (int i = 0; i < attributeDetailTable.getRowCount(); i++) {
        attributeDetailTable.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");
    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>SELF_PUBLIC</strong>");
    rightsTable.setHTML(0, 3, "<strong>SELF_VO</strong>");
    rightsTable.setHTML(0, 4, "<strong>VO</strong>");
    rightsTable.setHTML(0, 5, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 6, "<strong>FACILITY</strong>");
    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, selfReadPublic);
    rightsTable.setWidget(2, 2, selfWritePublic);
    rightsTable.setWidget(1, 3, selfReadVo);
    rightsTable.setWidget(2, 3, selfWriteVo);
    rightsTable.setWidget(1, 4, voRead);
    rightsTable.setWidget(2, 4, voWrite);
    rightsTable.setWidget(1, 5, groupRead);
    rightsTable.setWidget(2, 5, groupWrite);
    rightsTable.setWidget(1, 6, facilityRead);
    rightsTable.setWidget(2, 6, facilityWrite);
    rightsTable.addStyleName("centeredTable");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(updateButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", event -> session.getTabManager().closeTab(tab, isRefreshParentOnClose())));
    CustomButton showKeys = new CustomButton();
    showKeys.setText("show keys");
    showKeys.addClickHandler(clickEvent -> session.getTabManager().addTab(new EntitylessAttributeEditKeyTabItem(def)));
    menu.addWidget(showKeys);
    GetAttributeRights rightsCall = new GetAttributeRights(def.getId(), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            rights = JsonUtils.jsoAsList(jso);
            for (AttributeRights r : rights) {
                if (r.getRole().equalsIgnoreCase("SELF")) {
                    setRightsToWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, r);
                } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                    setRightsToWidgets(voRead, voWrite, r);
                } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                    setRightsToWidgets(groupRead, groupWrite, r);
                } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                    setRightsToWidgets(facilityRead, facilityWrite, r);
                }
            }
            enableDisableWidgets(true);
            rightsTable.setVisible(true);
        }

        @Override
        public void onError(PerunError error) {
            enableDisableWidgets(true);
            rightsTable.setVisible(false);
        }

        @Override
        public void onLoadingStart() {
            enableDisableWidgets(false);
            rightsTable.setVisible(false);
        }
    });
    rightsCall.retrieveData();
    // create new instance for jsonCall
    final GetServicesByAttrDefinition services = new GetServicesByAttrDefinition(def.getId());
    services.setCheckable(false);
    CellTable<Service> attrDefTable = services.getTable((index, object, value) -> session.getTabManager().addTab(new ServiceDetailTabItem(object)));
    attrDefTable.setStyleName("perun-table");
    ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
    scrollTable.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(scrollTable, 350, this);
    // set content to page
    mainPage.setWidget(0, 0, menu);
    mainPage.getFlexCellFormatter().setColSpan(0, 0, 2);
    mainPage.setWidget(1, 0, attributeDetailTable);
    mainPage.setWidget(1, 1, rightsTable);
    mainPage.getFlexCellFormatter().setWidth(1, 0, "50%");
    mainPage.getFlexCellFormatter().setWidth(1, 1, "50%");
    HTML title = new HTML("<p>Required by service</p>");
    title.setStyleName("subsection-heading");
    mainPage.setWidget(2, 0, title);
    mainPage.getFlexCellFormatter().setColSpan(2, 0, 2);
    // put page into scroll panel
    mainPage.setWidget(3, 0, scrollTable);
    mainPage.getFlexCellFormatter().setColSpan(3, 0, 2);
    mainPage.getFlexCellFormatter().setHeight(3, 0, "100%");
    this.contentWidget.setWidget(mainPage);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Arrays(java.util.Arrays) Service(cz.metacentrum.perun.webgui.model.Service) ImageResource(com.google.gwt.resources.client.ImageResource) SmallIcons(cz.metacentrum.perun.webgui.client.resources.SmallIcons) com.google.gwt.user.client.ui(com.google.gwt.user.client.ui) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) ArrayList(java.util.ArrayList) GetServicesByAttrDefinition(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) UiElements(cz.metacentrum.perun.webgui.client.UiElements) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) ConvertAttributeToUnique(cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) PerunWebSession(cz.metacentrum.perun.webgui.client.PerunWebSession) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Objects(java.util.Objects) PerunError(cz.metacentrum.perun.webgui.model.PerunError) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) UpdateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ButtonType(cz.metacentrum.perun.webgui.client.resources.ButtonType) CellTable(com.google.gwt.user.cellview.client.CellTable) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) UpdateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) ArrayList(java.util.ArrayList) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) Service(cz.metacentrum.perun.webgui.model.Service) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ConvertAttributeToUnique(cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) GetServicesByAttrDefinition(cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition)

Example 5 with CellTable

use of com.google.gwt.user.cellview.client.CellTable in project ovirt-engine by oVirt.

the class HostNetworkInterfaceBondedListViewItem method createSlavesContainer.

private Container createSlavesContainer() {
    Row content = new Row();
    Column gridColumn = new Column(ColumnSize.SM_12);
    content.add(gridColumn);
    Container container = createItemContainerPanel(content);
    CellTable<HostInterface> slavesTable = new CellTable<>(MAX_SLAVES, (Resources) GWT.create(CellTablePopupTableResources.class));
    slavesTable.getElement().addClassName(Styles.TABLE);
    slavesTable.getElement().addClassName(PatternflyConstants.PF_TABLE_STRIPED);
    slavesTable.getElement().addClassName(PatternflyConstants.PF_TABLE_BORDERED);
    ListDataProvider<HostInterface> logicalNetworkDataProvider = new ListDataProvider<>();
    logicalNetworkDataProvider.addDataDisplay(slavesTable);
    logicalNetworkDataProvider.setList(getEntity().getInterfaces());
    // Setup columns
    TextColumn<HostInterface> name = new TextColumn<HostInterface>() {

        @Override
        public String getValue(HostInterface hostInterface) {
            return hostInterface.getName();
        }
    };
    slavesTable.addColumn(name, constants.macInterface());
    TextColumn<HostInterface> macAddress = new TextColumn<HostInterface>() {

        @Override
        public String getValue(HostInterface hostInterface) {
            return hostInterface.getInterface().getMacAddress() != null ? hostInterface.getInterface().getMacAddress() : constants.unAvailablePropertyLabel();
        }
    };
    slavesTable.addColumn(macAddress, constants.macInterface());
    TextColumn<HostInterface> speed = new TextColumn<HostInterface>() {

        @Override
        public String getValue(HostInterface hostInterface) {
            return hostInterface.getInterface().hasSpeed() ? String.valueOf(hostInterface.getInterface().getSpeed()) : constants.unAvailablePropertyLabel();
        }
    };
    slavesTable.addColumn(speed, constants.speedInterface());
    TextColumn<HostInterface> rxRate = new TextColumn<HostInterface>() {

        @Override
        public String getValue(HostInterface hostInterface) {
            return rateRenderer.render(new Double[] { hostInterface.getRxRate(), hostInterface.getSpeed().doubleValue() });
        }
    };
    slavesTable.addColumn(rxRate, templates.sub(constants.rxRate(), constants.mbps()));
    TextColumn<HostInterface> txRate = new TextColumn<HostInterface>() {

        @Override
        public String getValue(HostInterface hostInterface) {
            return rateRenderer.render(new Double[] { hostInterface.getTxRate(), hostInterface.getSpeed().doubleValue() });
        }
    };
    slavesTable.addColumn(txRate, templates.sub(constants.txRate(), constants.mbps()));
    TextColumn<HostInterface> rxTotal = new TextColumn<HostInterface>() {

        @Override
        public String getValue(HostInterface hostInterface) {
            return totalRenderer.render(hostInterface.getRxTotal());
        }
    };
    slavesTable.addColumn(rxTotal, templates.sub(constants.rxTotal(), constants.mbps()));
    TextColumn<HostInterface> txTotal = new TextColumn<HostInterface>() {

        @Override
        public String getValue(HostInterface hostInterface) {
            return totalRenderer.render(hostInterface.getTxTotal());
        }
    };
    slavesTable.addColumn(txTotal, templates.sub(constants.txTotal(), constants.mbps()));
    TextColumn<HostInterface> dropRate = new TextColumn<HostInterface>() {

        @Override
        public String getValue(HostInterface hostInterface) {
            return String.valueOf(hostInterface.getRxDrop() + hostInterface.getTxDrop());
        }
    };
    slavesTable.addColumn(dropRate, templates.sub(constants.dropsInterface(), constants.pkts()));
    gridColumn.add(slavesTable);
    return container;
}
Also used : ListDataProvider(com.google.gwt.view.client.ListDataProvider) Container(org.gwtbootstrap3.client.ui.Container) Column(org.gwtbootstrap3.client.ui.Column) TextColumn(com.google.gwt.user.cellview.client.TextColumn) CellTable(com.google.gwt.user.cellview.client.CellTable) HostInterface(org.ovirt.engine.ui.uicommonweb.models.hosts.HostInterface) Row(org.gwtbootstrap3.client.ui.Row) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Aggregations

CellTable (com.google.gwt.user.cellview.client.CellTable)7 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)4 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 ArrayList (java.util.ArrayList)4 ListDataProvider (com.google.gwt.view.client.ListDataProvider)3 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)3 ImageResource (com.google.gwt.resources.client.ImageResource)2 TextColumn (com.google.gwt.user.cellview.client.TextColumn)2 PerunWebSession (cz.metacentrum.perun.webgui.client.PerunWebSession)2 UiElements (cz.metacentrum.perun.webgui.client.UiElements)2 ButtonType (cz.metacentrum.perun.webgui.client.resources.ButtonType)2 SmallIcons (cz.metacentrum.perun.webgui.client.resources.SmallIcons)2 JsonUtils (cz.metacentrum.perun.webgui.json.JsonUtils)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Column (org.gwtbootstrap3.client.ui.Column)2 Container (org.gwtbootstrap3.client.ui.Container)2 Row (org.gwtbootstrap3.client.ui.Row)2