Search in sources :

Example 41 with TextArea

use of com.vaadin.flow.component.textfield.TextArea in project komunumo-server by komunumo.

the class MemberDialog method createForm.

@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<Member> binder) {
    final var firstName = new TextField("First name");
    final var lastName = new TextField("Last name");
    final var company = new TextField("Company");
    final var email = new EmailField("Email");
    final var active = new Checkbox("Active");
    final var address = new TextField("Address");
    final var zipCode = new TextField("Zip code");
    final var city = new TextField("City");
    final var state = new TextField("State");
    final var country = new TextField("Country");
    final var admin = new Checkbox("Member is Admin");
    final var blocked = new Checkbox("Account Blocked");
    final var blockedReason = new TextField("Reason");
    final var comment = new TextArea("Comment");
    firstName.setRequiredIndicatorVisible(true);
    firstName.setValueChangeMode(EAGER);
    lastName.setRequiredIndicatorVisible(true);
    lastName.setValueChangeMode(EAGER);
    blocked.addValueChangeListener(event -> {
        final var isBlocked = event.getValue();
        blockedReason.setEnabled(isBlocked);
        blockedReason.setRequiredIndicatorVisible(isBlocked);
        if (isBlocked) {
            blockedReason.focus();
        } else {
            blockedReason.setValue("");
        }
        binder.validate();
    });
    blockedReason.setValueChangeMode(EAGER);
    blockedReason.setEnabled(false);
    formLayout.add(firstName, lastName, company, email, active, address, zipCode, city, state, country, admin, blocked, blockedReason, comment);
    binder.forField(firstName).withValidator(new StringLengthValidator("Please enter the first name of the member (max. 255 chars)", 1, 255)).bind(Member::getFirstName, Member::setFirstName);
    binder.forField(lastName).withValidator(new StringLengthValidator("Please enter the last name of the member (max. 255 chars)", 1, 255)).bind(Member::getLastName, Member::setLastName);
    binder.forField(company).bind(Member::getCompany, Member::setCompany);
    binder.forField(email).withValidator(new EmailValidator("Please enter a correct email address or leave this field empty", true)).withValidator(new StringLengthValidator("The email address is too long (max. 255 chars)", 0, 255)).bind(Member::getEmail, Member::setEmail);
    binder.forField(active).bind(Member::getAccountActive, Member::setAccountActive);
    binder.forField(address).withValidator(new StringLengthValidator("The address is too long (max. 255 chars)", 0, 255)).bind(Member::getAddress, Member::setAddress);
    binder.forField(zipCode).withValidator(new StringLengthValidator("The zip code is too long (max. 255 chars)", 0, 255)).bind(Member::getZipCode, Member::setZipCode);
    binder.forField(city).withValidator(new StringLengthValidator("The city is too long (max. 255 chars)", 0, 255)).bind(Member::getCity, Member::setCity);
    binder.forField(state).withValidator(new StringLengthValidator("The state is too long (max. 255 chars)", 0, 255)).bind(Member::getState, Member::setState);
    binder.forField(country).withValidator(new StringLengthValidator("The country is too long (max. 255 chars)", 0, 255)).bind(Member::getCountry, Member::setCountry);
    binder.forField(admin).bind(Member::getAdmin, Member::setAdmin);
    binder.forField(blocked).bind(Member::getAccountBlocked, Member::setAccountBlocked);
    binder.forField(blockedReason).withValidator(value -> !blocked.getValue() || blocked.getValue() && !value.isBlank(), "If you want to block this member, you must enter a reason").withValidator(new StringLengthValidator("The reason is too long (max. 255 chars)", 0, 255)).bind(Member::getAccountBlockedReason, Member::setAccountBlockedReason);
    binder.forField(comment).bind(Member::getComment, Member::setComment);
}
Also used : EmailValidator(com.vaadin.flow.data.validator.EmailValidator) TextArea(com.vaadin.flow.component.textfield.TextArea) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) Member(org.komunumo.data.entity.Member)

Example 42 with TextArea

use of com.vaadin.flow.component.textfield.TextArea in project SODevelopment by syampillai.

the class SystemUtility method clicked.

@SuppressWarnings({ "rawtypes", "unchecked", "resource" })
@Override
public void clicked(Component c) {
    clearAlerts();
    if (c == downloadConnInfo) {
        TextContentProducer cp = new TextContentProducer() {

            @Override
            public void generateContent() {
                Writer w = getWriter();
                SQLConnector.getDebugInfo(connectionAge.getValue()).forEach(d -> {
                    try {
                        w.write(d);
                        w.write("\n\n");
                    } catch (IOException ignored) {
                    }
                });
            }
        };
        getApplication().view(cp);
        return;
    }
    if (c == clear) {
        select.setValue("");
        where.setValue("");
        orderBy.setValue("");
        from.focus();
        return;
    }
    if (c == loadRaw) {
        Id id = new Id(new BigInteger("" + rawId.getValue()));
        StoredObject so = StoredObject.get(id);
        if (so == null) {
            warning("No object found for Id = " + id);
            return;
        }
        if (so instanceof StreamData) {
            getApplication().view("Id " + so.getId() + ", Transaction " + so.getTransactionId(), (StreamData) so);
            return;
        }
        getApplication().view(StringUtility.makeLabel(so.getClass()) + " (Id " + so.getId() + ", Transaction " + so.getTransactionId() + ")", so);
        return;
    }
    if (c == viewTranRaw) {
        long t = rawTranId.getValue();
        TransactionInformation ti = TransactionInformation.get(new BigInteger("" + t));
        if (ti == null) {
            warning("Transaction not found: " + t);
            return;
        }
        StringBuilder s = new StringBuilder("Transaction: ");
        s.append(t).append("\n");
        ti.dump(s);
        TextArea ta = new TextArea();
        ta.setWidthFull();
        ta.setValue(s.toString());
        View.createCloseableView(ta, "Transaction " + t).execute();
        return;
    }
    if (c == executeRaw) {
        String command = rawCommand.getValue().trim();
        getApplication().getServer().execute(command);
        return;
    }
    if (objectClass() == null) {
        return;
    }
    if (c == edit) {
        ObjectEditor.create(objectClass).execute();
        return;
    }
    if (c == editRaw) {
        // noinspection rawtypes
        new ObjectEditor(objectClass).execute();
        return;
    }
    if (c == downloadData) {
        final Class<? extends StoredObject> clazz = objectClass;
        TextContentProducer cp = new TextContentProducer() {

            @Override
            public void generateContent() throws Exception {
                Writer w = getWriter();
                for (StoredObject so : StoredObject.list(clazz, where.getValue().trim(), any.getValue())) {
                    so.save(w);
                }
            }
        };
        getApplication().view(cp);
        return;
    }
    if (c == updateData) {
        new Update().execute();
        return;
    }
    String cols = select.getValue().trim();
    if (c == executeSQL) {
        StringList columns;
        if (cols.isEmpty()) {
            columns = StoredObjectUtility.browseColumns(objectClass);
            select.setValue(columns.toString(", "));
        } else {
            if (cols.startsWith("/")) {
                new QueryGrid(StoredObject.query(objectClass, cols)).execute();
                return;
            }
            columns = StringList.create(cols);
        }
        Browser b = new Browser(objectClass, columns);
        b.execute();
        b.load(where.getValue().trim(), orderBy.getValue().trim());
        return;
    }
    if (c == pdf) {
        new ObjectList(getApplication(), objectClass, any.getValue(), cols.startsWith("/") ? StringList.EMPTY : StringList.create(cols)) {

            @Override
            public String getOrderBy() {
                return orderBy.getValue().trim();
            }

            @Override
            public String getExtraCondition() {
                return where.getValue();
            }
        }.execute();
        return;
    }
    if (c == downloadExcelData) {
        if (cols.isEmpty()) {
            ClassAttribute<? extends StoredObject> ca = StoredObjectUtility.classAttribute(objectClass);
            StringBuilder sb = new StringBuilder();
            assert ca != null;
            for (String s : ca.getAttributes()) {
                sb.append(",").append(s);
            }
            cols = sb.substring(1);
            select.setValue(cols);
        }
        Query query = StoredObject.query(objectClass, cols, where.getValue().trim(), orderBy.getValue().trim(), any.getValue());
        if (cols.startsWith("/")) {
            cols = cols.substring(1);
        }
        StringList columns = StringList.create(cols);
        Excel excel = new Excel() {

            @Override
            public void generateContent() throws Exception {
                columns.forEach(c -> setCellValue(getNextCell(), c));
                getNextRow();
                Cell cell;
                Object value;
                boolean first = true;
                for (ResultSet rs : query) {
                    int colCount = rs.getMetaData().getColumnCount();
                    for (int c = 1; c <= colCount; c++) {
                        cell = getNextCell();
                        setCellValue(cell, value = rs.getObject(c));
                        if (Utility.isRightAligned(value)) {
                            cell.setCellStyle(getRightAlignedStyle());
                            if (first) {
                                getCell(getCellIndex(), getRowIndex() - 1).setCellStyle(getRightAlignedStyle());
                            }
                        }
                    }
                    first = false;
                    getNextRow();
                }
                workbook.setSheetName(0, StringUtility.makeLabel(objectClass));
            }
        };
        getApplication().view(excel);
    }
}
Also used : TextArea(com.vaadin.flow.component.textfield.TextArea) Excel(com.storedobject.office.Excel) ResultSet(java.sql.ResultSet) Cell(org.apache.poi.ss.usermodel.Cell) StringList(com.storedobject.common.StringList) IOException(java.io.IOException) BigInteger(java.math.BigInteger) ObjectList(com.storedobject.report.ObjectList) Writer(java.io.Writer)

Example 43 with TextArea

use of com.vaadin.flow.component.textfield.TextArea in project docs by vaadin.

the class DialogDraggable method createDialogLayout.

private static VerticalLayout createDialogLayout(Dialog dialog) {
    H2 headline = new H2("Add note");
    headline.getStyle().set("margin", "0").set("font-size", "1.5em").set("font-weight", "bold");
    // tag::snippet2[]
    HorizontalLayout header = new HorizontalLayout(headline);
    header.getElement().getClassList().add("draggable");
    // end::snippet2[]
    header.setSpacing(false);
    header.getStyle().set("border-bottom", "1px solid var(--lumo-contrast-20pct)").set("cursor", "move");
    // Use negative margins to make draggable header stretch over full width,
    // covering the padding of the dialog
    header.getStyle().set("padding", "var(--lumo-space-m) var(--lumo-space-l)").set("margin", "calc(var(--lumo-space-s) * -1) calc(var(--lumo-space-l) * -1) 0");
    TextField titleField = new TextField("Title");
    TextArea descriptionArea = new TextArea("Description");
    VerticalLayout fieldLayout = new VerticalLayout(titleField, descriptionArea);
    fieldLayout.setSpacing(false);
    fieldLayout.setPadding(false);
    fieldLayout.setAlignItems(FlexComponent.Alignment.STRETCH);
    Button cancelButton = new Button("Cancel", e -> dialog.close());
    Button saveButton = new Button("Add note", e -> dialog.close());
    saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
    HorizontalLayout buttonLayout = new HorizontalLayout(cancelButton, saveButton);
    buttonLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    VerticalLayout dialogLayout = new VerticalLayout(header, fieldLayout, buttonLayout);
    dialogLayout.setPadding(false);
    dialogLayout.setAlignItems(FlexComponent.Alignment.STRETCH);
    dialogLayout.getStyle().set("width", "300px").set("max-width", "100%");
    return dialogLayout;
}
Also used : TextArea(com.vaadin.flow.component.textfield.TextArea) Button(com.vaadin.flow.component.button.Button) TextField(com.vaadin.flow.component.textfield.TextField) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H2(com.vaadin.flow.component.html.H2) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 44 with TextArea

use of com.vaadin.flow.component.textfield.TextArea in project docs by vaadin.

the class DialogNoPadding method createEmployeeInformationSection.

private static VerticalLayout createEmployeeInformationSection() {
    H3 employmentInformationTitle = new H3("Employment information");
    employmentInformationTitle.setId("employment-title");
    TextField positionField = new TextField("Position");
    TextArea informationArea = new TextArea("Additional information");
    VerticalLayout section = new VerticalLayout(employmentInformationTitle, positionField, informationArea);
    section.setPadding(false);
    section.setSpacing(false);
    section.setAlignItems(FlexComponent.Alignment.STRETCH);
    section.getElement().setAttribute("role", "region");
    section.getElement().setAttribute("aria-labelledby", employmentInformationTitle.getId().get());
    return section;
}
Also used : TextArea(com.vaadin.flow.component.textfield.TextArea) TextField(com.vaadin.flow.component.textfield.TextField) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H3(com.vaadin.flow.component.html.H3)

Example 45 with TextArea

use of com.vaadin.flow.component.textfield.TextArea in project karnak by OsiriX-Foundation.

the class DicomPane method buildContentField.

private void buildContentField() {
    contentFld = new TextArea();
    contentFld.setReadOnly(true);
    contentFld.setHeight("600px");
    contentFld.setWidth("600px");
    contentFld.setValue(dcm.toString(1500, 300));
}
Also used : TextArea(com.vaadin.flow.component.textfield.TextArea)

Aggregations

TextArea (com.vaadin.flow.component.textfield.TextArea)52 TextField (com.vaadin.flow.component.textfield.TextField)14 Test (org.junit.jupiter.api.Test)13 Div (com.vaadin.flow.component.html.Div)8 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)6 Test (org.junit.Test)6 Button (com.vaadin.flow.component.button.Button)5 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)5 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)4 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)4 H3 (com.vaadin.flow.component.html.H3)3 EmailField (com.vaadin.flow.component.textfield.EmailField)3 NumberField (com.vaadin.flow.component.textfield.NumberField)3 ValueChangeEvent (com.vaadin.flow.component.HasValue.ValueChangeEvent)2 ResponsiveStep (com.vaadin.flow.component.formlayout.FormLayout.ResponsiveStep)2 H2 (com.vaadin.flow.component.html.H2)2 NativeButton (com.vaadin.flow.component.html.NativeButton)2 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)2 Route (com.vaadin.flow.router.Route)2 EFieldTypeDefinition (ch.akros.marketplace.administration.constants.EFieldTypeDefinition)1