Search in sources :

Example 31 with FlexCellFormatter

use of com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter in project perun by CESNET.

the class GetFormItems method prepareApplicationForm.

/**
	 * Prepares the widgets from the items as A DISPLAY FOR THE USER
	 * DEPRECATED: Use GetFormItemsWithPrefilledValues instead
	 *
	 * @param items
	 */
@Deprecated
public void prepareApplicationForm(final ArrayList<ApplicationFormItem> items) {
    FlexTable ft = new FlexTable();
    FlexCellFormatter fcf = ft.getFlexCellFormatter();
    String locale = "en";
    if (!Utils.getNativeLanguage().isEmpty() && !LocaleInfo.getCurrentLocale().getLocaleName().equals("default") && !LocaleInfo.getCurrentLocale().getLocaleName().equals("en")) {
        locale = Utils.getNativeLanguage().get(0);
    }
    int i = 0;
    for (final ApplicationFormItem item : items) {
        String value = "";
        if (item.getShortname().equals("affiliation") || item.getShortname().equals("mail") || item.getShortname().equals("displayName")) {
            value = "from federation";
        }
        RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, value, locale);
        this.applFormGenerators.add(gen);
        if (!gen.isVisible()) {
            continue;
        }
        ItemTexts itemTexts = item.getItemTexts(locale);
        // WITH LABEL (input box ...)
        if (gen.isLabelShown()) {
            // 0 = label
            ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "</strong>");
            // 1 = widget
            Widget w = gen.getWidget();
            w.setTitle(itemTexts.getHelp());
            ft.setWidget(i, 1, w);
        // ELSE HTML COMMENT
        } else {
            ft.setWidget(i, 0, gen.getWidget());
            // colspan = 2
            fcf.setColSpan(i, 0, 2);
        }
        // format
        fcf.setHeight(i, 0, "35px");
        fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_TOP);
        fcf.setVerticalAlignment(i, 1, HasVerticalAlignment.ALIGN_MIDDLE);
        i++;
    }
    contents.setWidget(ft);
}
Also used : RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)

Example 32 with FlexCellFormatter

use of com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter in project perun by CESNET.

the class GetFormItemsWithPrefilledValues method prepareApplicationForm.

/**
	 * Prepares the widgets from the items as A DISPLAY FOR THE USER
	 */
public void prepareApplicationForm() {
    FlexTable ft = new FlexTable();
    ft.setCellPadding(10);
    ft.setWidth("100%");
    FlexCellFormatter fcf = ft.getFlexCellFormatter();
    String locale;
    if (!Utils.getNativeLanguage().isEmpty() && LocaleInfo.getCurrentLocale().getLocaleName().equals(Utils.getNativeLanguage().get(0))) {
        locale = Utils.getNativeLanguage().get(0);
    } else {
        locale = "en";
    }
    int i = 0;
    for (final ApplicationFormItemWithPrefilledValue item : applFormItems) {
        RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, locale);
        this.applFormGenerators.add(gen);
        gen.addValidationTrigger(new FormValidator() {

            public void triggerValidation() {
                validateFormValues(false);
            }
        });
        // if button, add onclick
        if (item.getFormItem().getType().equals("SUBMIT_BUTTON") || item.getFormItem().getType().equals("AUTO_SUBMIT_BUTTON")) {
            this.sendButton = (CustomButton) gen.getWidget();
            sendButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    // revalidate again, with force validation
                    if (!validateFormValues(true)) {
                        Element elem = DOM.getElementById("input-status-error");
                        elem.scrollIntoView();
                        return;
                    }
                    if (sendFormHandler != null) {
                        sendFormHandler.sendApplicationForm(sendButton);
                    }
                }
            });
        }
        // get localized texts
        ItemTexts itemTexts = item.getFormItem().getItemTexts(locale);
        if (!gen.isVisible()) {
            continue;
        }
        // WITH LABEL (input box ...)
        if (gen.isLabelShown()) {
            // 0 = label
            if (item.getFormItem().isRequired() == true) {
                // required
                ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "*</strong>");
            } else {
                // optional
                ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "</strong>");
            }
            // 1 = widget
            Widget w = gen.getWidget();
            w.setTitle(itemTexts.getHelp());
            ft.setWidget(i, 1, w);
            // 2 = status
            ft.setWidget(i, 2, gen.getStatusWidget());
            // 3 = HELP
            if (itemTexts.getHelp() != null && itemTexts.getHelp().length() > 0) {
                Label help = new Label(itemTexts.getHelp());
                ft.setWidget(i, 3, help);
            }
            // format
            fcf.setStyleName(i, 0, "applicationFormLabel");
            fcf.setStyleName(i, 1, "applicationFormWidget");
            fcf.setStyleName(i, 2, "applicationFormCheck");
            fcf.setStyleName(i, 3, "applicationFormHelp");
            ft.setWidth("100%");
        // ELSE HTML COMMENT, SUBMIT BUTTON, HEADING
        } else {
            ft.setWidget(i, 0, gen.getWidget());
            // colspan = 2
            fcf.setColSpan(i, 0, 4);
            fcf.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_LEFT);
            fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_MIDDLE);
        }
        i++;
    }
    contents.setWidget(ft);
}
Also used : FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Element(com.google.gwt.user.client.Element) FormValidator(cz.metacentrum.perun.webgui.client.applicationresources.FormValidator) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)

Example 33 with FlexCellFormatter

use of com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter in project perun by CESNET.

the class EditVoDetailsTabItem method draw.

public Widget draw() {
    titleWidget = new Label("Edit VO name");
    VerticalPanel vp = new VerticalPanel();
    // textboxes which set the class data when updated
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    nameTextBox.getTextBox().setText(vo.getName());
    nameTextBox.getTextBox().setMaxLength(128);
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!nameTextBox.getTextBox().getText().trim().isEmpty()) {
                nameTextBox.setOk();
                return true;
            } else {
                nameTextBox.setError("Name can't be empty.");
                return false;
            }
        }
    };
    nameTextBox.setValidator(nameValidator);
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    // send button
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes of VO name");
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (!nameValidator.validateTextBox())
                return;
            VirtualOrganization v = JsonUtils.clone(vo).cast();
            v.setName(nameTextBox.getTextBox().getText().trim());
            UpdateVo request = new UpdateVo(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
            request.updateVo(v);
        }
    });
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    // Add some standard form options
    layout.setHTML(0, 0, "Short name:");
    layout.setHTML(0, 1, vo.getShortName());
    layout.setHTML(1, 0, "Name:");
    layout.setWidget(1, 1, nameTextBox);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(saveButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) UpdateVo(cz.metacentrum.perun.webgui.json.vosManager.UpdateVo) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 34 with FlexCellFormatter

use of com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter in project perun by CESNET.

the class CreateGroupTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    // used for closing
    final TabItem tab = this;
    // form inputs
    final ExtendedTextBox groupNameTextBox = new ExtendedTextBox();
    final TextBox groupDescriptionTextBox = new TextBox();
    final ListBoxWithObjects<Group> vosGroups = new ListBoxWithObjects<Group>();
    vosGroups.setVisible(false);
    final CheckBox asSubGroup = new CheckBox("", false);
    TabMenu menu = new TabMenu();
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "");
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    final HTML parentGroupText = new HTML("Parent group:");
    parentGroupText.setVisible(false);
    final GetAllGroups groupsCall = new GetAllGroups(voId, new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosGroups.clear();
            ArrayList<Group> retGroups = JsonUtils.jsoAsList(jso);
            retGroups = new TableSorter<Group>().sortByName(retGroups);
            for (Group g : retGroups) {
                if (!g.isCoreGroup()) {
                    // SKIP CORE GROUPS !!
                    vosGroups.addItem(g);
                    if (g.getId() == groupId) {
                        // select default if passed to tab
                        vosGroups.setSelected(g, true);
                    }
                }
            }
            if (vosGroups.getAllObjects().isEmpty()) {
                vosGroups.addItem("No groups found");
            } else {
                createButton.setEnabled(true);
            }
            // call finished when user changed his mind
            if (!asSubGroup.getValue()) {
                createButton.setEnabled(true);
            }
        }

        public void onLoadingStart() {
            vosGroups.clear();
            vosGroups.addItem("Loading...");
            createButton.setEnabled(false);
        }

        public void onError(PerunError error) {
            vosGroups.clear();
            vosGroups.addItem("Error while loading");
            if (!asSubGroup.getValue()) {
                createButton.setEnabled(true);
            }
        }
    });
    // set title
    if (PerunEntity.GROUP.equals(entity)) {
        this.titleWidget.setText("Create sub-group");
        asSubGroup.setValue(true);
        createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
        parentGroupText.setVisible(true);
        vosGroups.setVisible(true);
        groupsCall.retrieveData();
    } else {
        this.titleWidget.setText("Create group");
        createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
    }
    asSubGroup.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
            if (booleanValueChangeEvent.getValue() == true) {
                // set title
                titleWidget.setText("Create sub-group");
                vosGroups.setVisible(true);
                parentGroupText.setVisible(true);
                groupsCall.retrieveData();
                createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
            } else {
                titleWidget.setText("Create group");
                vosGroups.setVisible(false);
                parentGroupText.setVisible(false);
                createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
                createButton.setEnabled(true);
            }
        }
    });
    // layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (groupNameTextBox.getTextBox().getText().trim().isEmpty()) {
                groupNameTextBox.setError("Name can't be empty.");
            } else if (!groupNameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
                groupNameTextBox.setError("Name can contain only a-z, A-Z, numbers, spaces, dots, '_' and '-'.");
            } else {
                groupNameTextBox.setOk();
                return true;
            }
            return false;
        }
    };
    groupNameTextBox.setValidator(validator);
    // send button
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (!validator.validateTextBox())
                return;
            // creates a new request
            CreateGroup cg = new CreateGroup(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
            if (asSubGroup.getValue()) {
                if (vosGroups.getSelectedObject() != null) {
                    cg.createGroupInGroup(vosGroups.getSelectedObject().getId(), groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText().trim());
                } else {
                    UiElements.generateInfo("No parent group selected", "You checked create this group as sub-group, but no parent group is selected. Please select parent group.");
                }
            } else {
                cg.createGroupInVo(voId, groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText().trim());
            }
        }
    });
    // cancel button
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    // Add some standard form options
    layout.setHTML(0, 0, "Name:");
    layout.setWidget(0, 1, groupNameTextBox);
    layout.setHTML(1, 0, "Description:");
    layout.setWidget(1, 1, groupDescriptionTextBox);
    layout.setHTML(2, 0, "As sub-group:");
    layout.setWidget(2, 1, asSubGroup);
    layout.setWidget(3, 0, parentGroupText);
    layout.setWidget(3, 1, vosGroups);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    // button align
    menu.addWidget(createButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) CreateGroup(cz.metacentrum.perun.webgui.json.groupsManager.CreateGroup) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) CreateGroup(cz.metacentrum.perun.webgui.json.groupsManager.CreateGroup) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 35 with FlexCellFormatter

use of com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter in project perun by CESNET.

the class EditGroupDetailsTabItem method draw.

public Widget draw() {
    titleWidget = new Label("Edit group");
    VerticalPanel vp = new VerticalPanel();
    // textboxes which set the class data when updated
    final ExtendedTextBox descriptionTextBox = new ExtendedTextBox();
    descriptionTextBox.getTextBox().setText(group.getDescription());
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    nameTextBox.getTextBox().setText(group.getShortName());
    // disable name change for core groups
    nameTextBox.getTextBox().setEnabled(!group.isCoreGroup());
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    // send button
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, buttonTranslation.saveGroupDetails());
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
                nameTextBox.setError("Name can't be empty.");
            } else if (!nameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
                nameTextBox.setError("Name can contain only a-z, A-Z, numbers, spaces, dots, '_' and '-'.");
            } else {
                nameTextBox.setOk();
                return true;
            }
            return false;
        }
    };
    nameTextBox.setValidator(validator);
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (!validator.validateTextBox())
                return;
            Group g = JsonUtils.clone(group).cast();
            g.setDescription(descriptionTextBox.getTextBox().getText().trim());
            String value = nameTextBox.getTextBox().getText().trim();
            g.setShortName(value);
            int index = g.getName().lastIndexOf(":");
            if (index > 0) {
                // short name append to base name
                String baseName = g.getName().substring(0, index);
                baseName += ":" + g.getShortName();
                g.setName(baseName);
            } else {
                // short name is whole name
                g.setName(value);
            }
            ;
            UpdateGroup request = new UpdateGroup(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
            request.updateGroup(g);
        }
    });
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    // Add some standard form options
    layout.setHTML(0, 0, "Name:");
    layout.setWidget(0, 1, nameTextBox);
    layout.setHTML(1, 0, "Description:");
    layout.setWidget(1, 1, descriptionTextBox);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(saveButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : Group(cz.metacentrum.perun.webgui.model.Group) UpdateGroup(cz.metacentrum.perun.webgui.json.groupsManager.UpdateGroup) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) UpdateGroup(cz.metacentrum.perun.webgui.json.groupsManager.UpdateGroup)

Aggregations

FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)48 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)25 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)25 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)19 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)19 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)17 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)14 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)10 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)10 RegistrarFormItemGenerator (cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)6 PerunError (cz.metacentrum.perun.webgui.model.PerunError)5 JSONString (com.google.gwt.json.client.JSONString)3 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)3 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)3 ArrayList (java.util.ArrayList)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 ImageResource (com.google.gwt.resources.client.ImageResource)2 Anchor (com.google.gwt.user.client.ui.Anchor)2 Image (com.google.gwt.user.client.ui.Image)2