Search in sources :

Example 1 with UpdateGroup

use of cz.metacentrum.perun.webgui.json.groupsManager.UpdateGroup 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

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)1 UpdateGroup (cz.metacentrum.perun.webgui.json.groupsManager.UpdateGroup)1 Group (cz.metacentrum.perun.webgui.model.Group)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1