Search in sources :

Example 1 with CreateOwner

use of cz.metacentrum.perun.webgui.json.ownersManager.CreateOwner in project perun by CESNET.

the class CreateOwnerTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // textboxes which set the class data when updated
    final ExtendedTextBox ownerNameTextBox = new ExtendedTextBox();
    final ExtendedTextBox ownerContactTextBox = new ExtendedTextBox();
    final ListBox ownerType = new ListBox();
    ownerType.addItem(ObjectTranslation.INSTANCE.ownerTypeAdministrative(), "administrative");
    ownerType.addItem(ObjectTranslation.INSTANCE.ownerTypeTechnical(), "technical");
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

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

        @Override
        public boolean validateTextBox() {
            if (ownerContactTextBox.getTextBox().getText().trim().isEmpty()) {
                ownerContactTextBox.setError("Contact can't be empty.");
                return false;
            }
            ownerContactTextBox.setOk();
            return true;
        }
    };
    ownerNameTextBox.setValidator(nameValidator);
    ownerContactTextBox.setValidator(contactValidator);
    // layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // Add some standard form options
    layout.setHTML(0, 0, "Name:");
    layout.setWidget(0, 1, ownerNameTextBox);
    layout.setHTML(1, 0, "Contact:");
    layout.setWidget(1, 1, ownerContactTextBox);
    layout.setHTML(2, 0, "Type:");
    layout.setWidget(2, 1, ownerType);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    // buttons
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createOwner());
    createButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (nameValidator.validateTextBox() && contactValidator.validateTextBox()) {
                CreateOwner request = new CreateOwner(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
                request.createOwner(ownerNameTextBox.getTextBox().getText().trim(), ownerContactTextBox.getTextBox().getText().trim(), ownerType.getValue(ownerType.getSelectedIndex()));
            }
        }
    });
    menu.addWidget(createButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    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) CreateOwner(cz.metacentrum.perun.webgui.json.ownersManager.CreateOwner) 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)

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 CreateOwner (cz.metacentrum.perun.webgui.json.ownersManager.CreateOwner)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