Search in sources :

Example 1 with CreateCategory

use of cz.metacentrum.perun.webgui.json.cabinetManager.CreateCategory in project perun by CESNET.

the class CreateCategoryTabItem method draw.

public Widget draw() {
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    final CustomButton addCategory = TabMenu.getPredefinedButton(ButtonType.ADD, "Add category");
    menu.addWidget(addCategory);
    FlexTable table = new FlexTable();
    table.setStyleName("inputFormFlexTable");
    // textboxes which set the class data when updated
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    final ExtendedTextBox rankTextBox = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

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

        @Override
        public boolean validateTextBox() {
            if (rankTextBox.getTextBox().getText().trim().isEmpty()) {
                rankTextBox.setError("Rank value can't be empty.");
                return false;
            } else {
                try {
                    Double.parseDouble(rankTextBox.getTextBox().getText().trim());
                } catch (Exception e) {
                    rankTextBox.setError("Value must be in like: 0.5, 1.0 etc.");
                    return false;
                }
            }
            rankTextBox.setOk();
            return true;
        }
    };
    nameTextBox.setValidator(validator);
    rankTextBox.setValidator(validator2);
    final TabItem tab = this;
    addCategory.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (validator.validateTextBox() && validator2.validateTextBox()) {
                CreateCategory request = new CreateCategory(JsonCallbackEvents.closeTabDisableButtonEvents(addCategory, tab));
                request.createCategory(nameTextBox.getTextBox().getText().trim(), Double.parseDouble(rankTextBox.getTextBox().getText().trim()));
            }
        }
    });
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(table);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    table.setHTML(0, 0, "Name:");
    table.setWidget(0, 1, nameTextBox);
    table.setHTML(1, 0, "Rank:");
    table.setWidget(1, 1, rankTextBox);
    for (int i = 0; i < table.getRowCount(); i++) {
        table.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    table.setHTML(2, 1, "Values like: 0.0 , 0.5 , 1.2 , etc.");
    table.getFlexCellFormatter().setStyleName(2, 1, "inputFormInlineComment");
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) CreateCategory(cz.metacentrum.perun.webgui.json.cabinetManager.CreateCategory)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 CreateCategory (cz.metacentrum.perun.webgui.json.cabinetManager.CreateCategory)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