Search in sources :

Example 1 with ExtendedTextArea

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextArea in project perun by CESNET.

the class AddHostsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": add hosts");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final ExtendedTextArea newHosts = new ExtendedTextArea();
    newHosts.getTextArea().setSize("335px", "150px");
    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);
    final CustomButton addHostsButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addHost());
    // close tab, disable button
    final TabItem tab = this;
    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.closeTabDisableButtonEvents(addHostsButton, tab, true));
                request.addHosts(hosts);
            }
        }
    });
    TabMenu menu = new TabMenu();
    menu.addWidget(addHostsButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    // layout
    final FlexTable layout = new FlexTable();
    layout.setWidth("350px");
    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");
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : AddHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.AddHosts) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextArea(cz.metacentrum.perun.webgui.widgets.ExtendedTextArea) 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 2 with ExtendedTextArea

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextArea in project perun by CESNET.

the class RequestQuotaChangeTabItem method draw.

public Widget draw() {
    new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, resource.getVoId(), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            vo = jso.cast();
        }
    }).retrieveData();
    VerticalPanel vp = new VerticalPanel();
    // set tab name
    this.titleWidget.setText(getQuotaTypeAsString() + " quota change request");
    // quota string
    // String quotaStr = getQuotaTypeAsString();
    // new quota input
    final ExtendedTextBox newQuota = new ExtendedTextBox();
    final ExtendedTextArea reason = new ExtendedTextArea();
    final ListBox units = new ListBox();
    units.addItem("M");
    units.addItem("G");
    units.addItem("T");
    // default G
    units.setSelectedIndex(1);
    FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    ft.setWidget(0, 0, new HTML("Resource:"));
    ft.setWidget(1, 0, new HTML("Current quota:"));
    ft.setWidget(2, 0, new HTML("Requested quota:"));
    ft.setWidget(3, 0, new HTML("Reason:"));
    for (int i = 0; i < ft.getRowCount(); i++) {
        ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    ft.setText(0, 1, resource.getName());
    ft.setText(1, 1, oldQuota + " (default: " + defaultQuota + ")");
    ft.setWidget(2, 1, newQuota);
    ft.getFlexCellFormatter().setColSpan(3, 1, 2);
    ft.setWidget(3, 1, reason);
    final CustomButton requestQuotaButton = new CustomButton("Send request", "Send quota change request", SmallIcons.INSTANCE.emailIcon());
    if (this.quotaType.equals(QuotaType.DATA)) {
        ft.setWidget(2, 2, units);
        ft.getFlexCellFormatter().setColSpan(4, 0, 3);
    } else {
        ft.getFlexCellFormatter().setColSpan(4, 0, 2);
    }
    final ExtendedTextBox.TextBoxValidator quotaValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (newQuota.getTextBox().getValue().trim().isEmpty()) {
                newQuota.setError("You must enter requested quota!");
            } else if (!JsonUtils.checkParseInt(newQuota.getTextBox().getValue().trim())) {
                newQuota.setError("Requested quota must be a number!");
            } else {
                newQuota.setOk();
                return true;
            }
            return false;
        }
    };
    newQuota.setValidator(quotaValidator);
    final ExtendedTextArea.TextAreaValidator reasonValidator = new ExtendedTextArea.TextAreaValidator() {

        @Override
        public boolean validateTextArea() {
            if (reason.getTextArea().getValue().trim().isEmpty()) {
                reason.setError("You must specify reason for quota change!");
                return false;
            }
            reason.setOk();
            return true;
        }
    };
    reason.setValidator(reasonValidator);
    reason.getTextArea().setSize("205px", "100px");
    requestQuotaButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (!quotaValidator.validateTextBox() && !reasonValidator.validateTextArea())
                return;
            if (quotaType.equals(QuotaType.DATA)) {
                requestQuotaChange(newQuota.getTextBox().getValue().trim() + units.getItemText(units.getSelectedIndex()), reason.getTextArea().getText());
            } else {
                requestQuotaChange(newQuota.getTextBox().getValue().trim(), reason.getTextArea().getText());
            }
        }
    });
    vp.add(ft);
    TabMenu menu = new TabMenu();
    menu.addWidget(requestQuotaButton);
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextArea(cz.metacentrum.perun.webgui.widgets.ExtendedTextArea) 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) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 ExtendedTextArea (cz.metacentrum.perun.webgui.widgets.ExtendedTextArea)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 GetEntityById (cz.metacentrum.perun.webgui.json.GetEntityById)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 AddHosts (cz.metacentrum.perun.webgui.json.facilitiesManager.AddHosts)1 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)1