com.vaadin.flow.component.textfield.TextField Java Examples

The following examples show how to use com.vaadin.flow.component.textfield.TextField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserGroupsView.java    From radman with MIT License 6 votes vote down vote up
UserGroupFormDialog() {

            TextField username = new TextField("Name");
            username.setValueChangeMode(ValueChangeMode.EAGER);
            TextField description = new TextField("Description");
            description.setValueChangeMode(ValueChangeMode.EAGER);

            binder = new BeanValidationBinder<>(RadiusGroupDto.class);
            binder.bind(username, "name");
            binder.bind(description, "description");

            HorizontalLayout controlsLayout = new HorizontalLayout();
            controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
            controlsLayout.add(new Button("Cancel", event -> setOpened(false)));
            controlsLayout.add(getConfirmBtn());
            controlsLayout.setWidthFull();

            add(new H3(getDialogTitle()));
            add(new FormLayout(username, description));
            add(new Hr());
            add(controlsLayout);
        }
 
Example #2
Source File: UsersView.java    From radman with MIT License 6 votes vote down vote up
UserFormDialog() {
    TextField username = new TextField("Username");
    username.setValueChangeMode(ValueChangeMode.EAGER);
    TextField description = new TextField("Description");
    description.setValueChangeMode(ValueChangeMode.EAGER);

    binder = new BeanValidationBinder<>(RadiusUserDto.class);
    binder.bind(username, "username");
    binder.bind(description, "description");

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    controlsLayout.add(new Button("Cancel", event -> setOpened(false)));
    controlsLayout.add(getConfirmBtn());
    controlsLayout.setWidthFull();

    add(new H3(getDialogTitle()));
    add(new FormLayout(username, description));
    add(new Hr());
    add(controlsLayout);
}
 
Example #3
Source File: DefaultFieldProvider.java    From crudui with Apache License 2.0 6 votes vote down vote up
@Override
public HasValueAndElement buildField() {
    if (Boolean.class.isAssignableFrom(type) || boolean.class == type) {
        return new Checkbox();
    }

    if (LocalDate.class.isAssignableFrom(type) || Date.class.isAssignableFrom(type)) {
        return new DatePicker();
    }

    if (Enum.class.isAssignableFrom(type)) {
        Object[] values = type.getEnumConstants();
        ComboBox comboBox = new ComboBox<>();
        comboBox.setItems(Arrays.asList(values));
        return comboBox;
    }

    if (String.class.isAssignableFrom(type) || Character.class.isAssignableFrom(type) || Byte.class.isAssignableFrom(type)
            || Number.class.isAssignableFrom(type) || type.isPrimitive()) {
        return new TextField();
    }

    return null;
}
 
Example #4
Source File: NasGroupsView.java    From radman with MIT License 6 votes vote down vote up
NasGroupFormDialog(NasService nasService) {
    this.nasService = nasService;

    TextField groupname = new TextField("Group name");
    groupname.setValueChangeMode(ValueChangeMode.EAGER);
    TextField nasIpAddress = new TextField("IP address");
    nasIpAddress.setValueChangeMode(ValueChangeMode.EAGER);
    TextField nasPortId = new TextField("Port ID");
    nasPortId.setValueChangeMode(ValueChangeMode.EAGER);

    binder = new BeanValidationBinder<>(NasGroupDto.class);
    binder.bind(groupname, "groupName");
    binder.bind(nasIpAddress, "nasIpAddress");
    binder.bind(nasPortId, "nasPortId");

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    controlsLayout.add(new Button("Cancel", event -> setOpened(false)));
    controlsLayout.add(getConfirmBtn());
    controlsLayout.setWidthFull();

    add(new H3(getDialogTitle()));
    add(new FormLayout(groupname, nasIpAddress, nasPortId));
    add(new Hr());
    add(controlsLayout);
}
 
Example #5
Source File: MainView.java    From tutorials with MIT License 5 votes vote down vote up
public MainView(EmployeeRepository repo, EmployeeEditor editor) {
    this.employeeRepository = repo;
    this.editor = editor;
    this.grid = new Grid<>(Employee.class);
    this.filter = new TextField();
    this.addNewBtn = new Button("New employee", VaadinIcon.PLUS.create());

    HorizontalLayout actions = new HorizontalLayout(filter, addNewBtn);
    add(actions, grid, editor);

    grid.setHeight("200px");
    grid.setColumns("id", "firstName", "lastName");
    grid.getColumnByKey("id").setWidth("50px").setFlexGrow(0);

    filter.setPlaceholder("Filter by last name");

    filter.setValueChangeMode(ValueChangeMode.EAGER);
    filter.addValueChangeListener(e -> listEmployees(e.getValue()));

    grid.asSingleSelect().addValueChangeListener(e -> {
        editor.editEmployee(e.getValue());
    });

    addNewBtn.addClickListener(e -> editor.editEmployee(new Employee("", "")));

    editor.setChangeHandler(() -> {
        editor.setVisible(false);
        listEmployees(filter.getValue());
    });

    listEmployees(null);
}
 
Example #6
Source File: AppConfigView.java    From alibaba-rsocket-broker with Apache License 2.0 5 votes vote down vote up
VerticalLayout makeConfigForm() {
    VerticalLayout content = new VerticalLayout();
    appName = new TextField("App Name");
    appName.setWidth("300px");
    configName = new TextField("Key");
    configName.setWidth("300px");
    configValue = new TextArea("Value");
    configValue.setWidth("600px");
    HorizontalLayout buttons = new HorizontalLayout();
    saveButton = new Button("Save", buttonClickEvent -> {
        String key = appName.getValue() + ":" + configName.getValue();
        AppConfigEvent appConfigEvent = new AppConfigEvent(appName.getValue(), configName.getValue(), configValue.getValue());
        configurationService.put(key, configValue.getValue())
                .doOnSuccess(aVoid -> Notification.show("Saved Successfully"))
                .then(brokerManager.broadcast(appConfigEvent.toCloudEvent(URI.create("broker:" + brokerManager.localBroker().getIp()))))
                .subscribe();
    });
    content.add(new H3("Key/Value"));
    content.add(appName);
    content.add(configName);
    content.add(configValue);
    buttons.add(saveButton);
    buttons.add(new Button("New Configuration", buttonClickEvent -> {
        clearForm();
    }));
    content.add(buttons);
    return content;
}
 
Example #7
Source File: AuthView.java    From radman with MIT License 5 votes vote down vote up
private AbstractSinglePropertyField<? extends AbstractField<?, ?>, String> buildTextValueField() {
    binder.removeBinding("value");
    TextField valueField = new TextField("Value");
    valueField.setValueChangeMode(ValueChangeMode.EAGER);
    valueField.setClearButtonVisible(false);
    binder.bind(valueField, "value");
    return valueField;
}
 
Example #8
Source File: AccountingView.java    From radman with MIT License 4 votes vote down vote up
SetAcctStopTimeDialog(UpdateListener<AccountingDto> updateListener) {
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setPadding(false);
    verticalLayout.setMargin(false);

    timestampField = new TextField("Timestamp");
    timestampField.setErrorMessage("Timestamp number is required");
    timestampField.setValueChangeMode(ValueChangeMode.EAGER);
    timestampField.addValueChangeListener(event -> isValid(event.getValue()));

    checkboxNow = new Checkbox("Now");
    Button setBtn = new Button("Set");
    Button cancelBtn = new Button("Cancel", event -> setOpened(false));

    checkboxNow.addValueChangeListener(event -> {
        if (event.getValue()) {
            timestampField.setValue(String.valueOf(Instant.now().getEpochSecond()));
        }
        timestampField.setEnabled(!event.getValue());
    });
    timestampField.addValueChangeListener(event -> setBtn.setEnabled(Objects.nonNull(event.getValue())));

    setBtn.setEnabled(false);
    setBtn.addClickListener(event -> {
        if (isValid(timestampField.getValue())) {
            try {
                long timestamp = Long.valueOf(timestampField.getValue());
                AccountingDto updatedAccountingDto = accountingService.setAcctStopTime(accountingDto,
                        new Date(timestamp * 1000));
                updateListener.onUpdated(this, updatedAccountingDto);
                setOpened(false);
            } catch (NotFoundException e) {
                e.printStackTrace();
            }
        }
    });

    HorizontalLayout controls = new HorizontalLayout();
    controls.add(cancelBtn, setBtn);
    verticalLayout.add(new H3("Set Acct Stop Time"), timestampField, checkboxNow, new Hr(), controls);
    verticalLayout.setHorizontalComponentAlignment(Alignment.END, controls);
    add(verticalLayout);

}
 
Example #9
Source File: AccountingView.java    From radman with MIT License 4 votes vote down vote up
private void buildView() {
    setHeightFull();
    setSpacing(false);

    Grid<AccountingDto> grid = new Grid<>(AccountingDto.class, false);
    grid.addColumns("username", "callingStationId", "nasIpAddress", "serviceType");
    grid.addColumn(new LocalDateTimeRenderer<>((ValueProvider<AccountingDto, LocalDateTime>)
            accountingDto -> {
                if (Objects.isNull(accountingDto.getAcctStartTime())) {
                    return null;
                }
                return LocalDateTime.ofInstant(accountingDto.getAcctStartTime().toInstant(),
                        TimeZone.getDefault().toZoneId());
            })).setSortProperty("acctStartTime").setHeader("Acct Start Time");
    grid.addColumn(new LocalDateTimeRenderer<>((ValueProvider<AccountingDto, LocalDateTime>)
            accountingDto -> {
                if (Objects.isNull(accountingDto.getAcctStopTime())) {
                    return null;
                }
                return LocalDateTime.ofInstant(accountingDto.getAcctStopTime().toInstant(),
                        TimeZone.getDefault().toZoneId());
            })).setSortProperty("acctStopTime").setHeader("Acct Stop Time");
    grid.addColumns("acctTerminateCause", "framedIpAddress", "framedProtocol");
    grid.addColumns("acctAuthentic", "acctInputOctets", "acctInterval", "acctOutputOctets",
            "acctSessionId");
    grid.addColumn(accountingDto -> {
        if (Objects.isNull(accountingDto.getAcctSessionTime())) {
            return null;
        }
        return DurationFormatUtils.formatDurationHMS(accountingDto.getAcctSessionTime());
    }).setSortProperty("acctSessionTime").setHeader("Acct Session Time");
    grid.addColumns("acctUniqueId", "acctUpdateTime", "calledStationId",
            "connectInfoStart", "connectInfoStop", "nasPortId", "nasPortType", "radAcctId", "realm");

    DataProvider<AccountingDto, Object> dataProvider = new SpringDataProviderBuilder<>(
            (pageable, o) -> accountingService.pageAccountingRecords(filter, pageable),
            value -> accountingService.countAccountingRecords(filter))
            .withDefaultSort("acctStartTime", SortDirection.DESCENDING)
            .build();
    grid.setDataProvider(dataProvider);
    grid.getColumns().forEach(column -> column.setResizable(true));
    grid.setColumnReorderingAllowed(true);
    grid.setMinHeight("500px");
    grid.setHeight("100%");

    TextField search = new TextField(event -> {
        filter.setSearchText(event.getValue());
        grid.getDataProvider().refreshAll();
    });
    search.setValueChangeMode(ValueChangeMode.EAGER);
    search.setPlaceholder("Search...");

    SetAcctStopTimeDialog setAcctStopTimeDialog = new SetAcctStopTimeDialog((source, bean)
            -> grid.getDataProvider().refreshItem(bean));
    Button setAcctStopTimeButton = new Button("Set Acct Stop Time", event -> {
        Optional<AccountingDto> optional = grid.getSelectionModel().getFirstSelectedItem();
        optional.ifPresent(setAcctStopTimeDialog::set);
    });
    setAcctStopTimeButton.setEnabled(false);

    grid.asSingleSelect().addValueChangeListener(event
            -> setAcctStopTimeButton.setEnabled(Objects.nonNull(event.getValue())));

    Checkbox onlyActiveSessions = new Checkbox("Filter only active sessions");
    onlyActiveSessions.setValue(filter.isSearchOnlyActiveSessions());
    onlyActiveSessions.addValueChangeListener(event -> {
        filter.setSearchOnlyActiveSessions(event.getValue());
        grid.getDataProvider().refreshAll();
    });

    add(new H4("Data from Radius DB - \"radacct\" table"));
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.BASELINE);
    horizontalLayout.add(new H3("Accounting"));
    horizontalLayout.add(setAcctStopTimeButton);
    horizontalLayout.add(search);
    horizontalLayout.add(onlyActiveSessions);
    add(horizontalLayout);
    add(grid);
}
 
Example #10
Source File: JwtGeneratorView.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
VerticalLayout makeGeneratorForm() {
    VerticalLayout content = new VerticalLayout();
    appNameText = new TextField("App Name");
    appNameText.setWidth("300px");
    appNameText.setPlaceholder("your-app-name");
    ownersText = new TextField("Owners");
    ownersText.setWidth("300px");
    orgIdsText = new TextField("Org IDs");
    orgIdsText.setPlaceholder("1");
    orgIdsText.setWidth("300px");
    serviceAccountsText = new TextField("Service Accounts");
    serviceAccountsText.setValue("default");
    serviceAccountsText.setWidth("300px");
    rolesText = new TextField("Roles");
    rolesText.setWidth("300px");
    rolesText.setValue("user");
    authoritiesText = new TextField("Authorities");
    rolesText.setWidth("300px");
    rolesText.setValue("");
    tokenTextArea = new TextArea("JWT Token");
    tokenTextArea.setWidth("800px");
    tokenTextArea.setHeight("240px");
    tokenTextArea.setReadOnly(true);
    rolesText.setWidth("200px");
    HorizontalLayout buttons = new HorizontalLayout();
    generateBtn = new Button("Generate", buttonClickEvent -> {
        String appName = appNameText.getValue();
        String[] orgIds = orgIdsText.getValue().trim().split("[,;\\s]*");
        String[] serviceAccounts = serviceAccountsText.getValue().trim().split("[,;\\s]*");
        String[] owners = ownersText.getValue().trim().split("[,;\\s]*");
        String[] roles = rolesText.getValue().trim().split("[,;\\s]*");
        String[] authorities = authoritiesText.getValue().trim().split("[,;\\s]*");
        try {
            String token = authenticationService.generateCredentials(UUID.randomUUID().toString(), orgIds, serviceAccounts, roles, authorities, appName, owners);
            tokenTextArea.setValue(token);
        } catch (Exception ignore) {

        }

    });
    content.add(appNameText);
    content.add(ownersText);
    content.add(orgIdsText);
    content.add(serviceAccountsText);
    content.add(rolesText);
    content.add(authoritiesText);
    content.add(tokenTextArea);
    buttons.add(generateBtn);
    buttons.add(new Button("Clear", buttonClickEvent -> {
        clearForm();
    }));
    content.add(buttons);
    return content;
}
 
Example #11
Source File: ServiceTestingView.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
VerticalLayout makeServiceCallForm() {
    VerticalLayout content = new VerticalLayout();
    this.serviceNameFiled = new TextField("Service Name");
    serviceNameFiled.setWidth("300px");
    this.methodNameField = new TextField("Method Name");
    methodNameField.setWidth("300px");
    TextArea jsonDataTextArea = new TextArea("JSON Data");
    jsonDataTextArea.setWidth("600px");
    jsonDataTextArea.setHeight("200px");
    Pre responsePre = new Pre();
    HorizontalLayout buttons = new HorizontalLayout();
    Button callButton = new Button("Invoke", buttonClickEvent -> {
        String serviceName = serviceNameFiled.getValue();
        String methodName = methodNameField.getValue();
        String jsonData = jsonDataTextArea.getValue();
        if (serviceName == null || serviceName.isEmpty()) {
            serviceNameFiled.setErrorMessage("Please input service name");
        }
        if (methodName == null || methodName.isEmpty()) {
            methodNameField.setErrorMessage("Please input service name");
        }
        if (jsonData != null) {
            jsonData = jsonData.trim();
            if (!jsonData.isEmpty() && !jsonData.startsWith("[")) {
                jsonData = "[" + jsonData + "]";
            }
        }
        callRSocketService(serviceName, methodName, jsonData, responsePre);
    });
    content.add(new H3("RSocket Service Testing"));
    content.add(serviceNameFiled);
    content.add(methodNameField);
    content.add(jsonDataTextArea);
    content.add(new H4("Response"));
    content.add(responsePre);
    buttons.add(callButton);
    buttons.add(new Button("Clear", buttonClickEvent -> {
        serviceNameFiled.clear();
        serviceNameFiled.setInvalid(false);
        methodNameField.clear();
        jsonDataTextArea.clear();
        responsePre.setText("");
    }));
    content.add(buttons);
    return content;
}
 
Example #12
Source File: SearchButton.java    From vaadin-app-layout with Apache License 2.0 4 votes vote down vote up
public SearchButton withValueChangeListener(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<TextField, String>> listener) {
    addValueChangeListener(listener);
    return this;
}
 
Example #13
Source File: SearchButton.java    From vaadin-app-layout with Apache License 2.0 4 votes vote down vote up
public void addValueChangeListener(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<TextField, String>> listener) {
    searchView.addValueChangeListener(listener);
}
 
Example #14
Source File: SearchOverlayView.java    From vaadin-app-layout with Apache License 2.0 4 votes vote down vote up
public TextField getSearchField() {
    return searchField;
}
 
Example #15
Source File: SearchView.java    From vaadin-app-layout with Apache License 2.0 4 votes vote down vote up
public TextField getSearchField() {
    return searchField;
}
 
Example #16
Source File: SearchView.java    From vaadin-app-layout with Apache License 2.0 4 votes vote down vote up
public void addValueChangeListener(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<TextField, String>> listener) {
    searchField.addValueChangeListener(listener);
}
 
Example #17
Source File: CrudWithFilterView.java    From crudui with Apache License 2.0 4 votes vote down vote up
public CrudWithFilterView(UserService userService, GroupService groupService) {
    // crud instance
    GridCrud<User> crud = new GridCrud<>(User.class);

    // additional components
    TextField filter = new TextField();
    filter.setPlaceholder("Filter by name");
    filter.setClearButtonVisible(true);
    crud.getCrudLayout().addFilterComponent(filter);

    // grid configuration
    crud.getGrid().setColumns("name", "birthDate", "maritalStatus", "email", "phoneNumber", "active");
    crud.getGrid().setColumnReorderingAllowed(true);

    // form configuration
    crud.getCrudFormFactory().setUseBeanValidation(true);
    crud.getCrudFormFactory().setVisibleProperties(
            CrudOperation.ADD,
            "name", "birthDate", "email", "salary", "phoneNumber", "maritalStatus", "groups", "active", "mainGroup",
            "password");
    crud.getCrudFormFactory().setVisibleProperties(
            "name", "birthDate", "email", "salary", "phoneNumber", "maritalStatus", "groups", "active", "mainGroup");
    crud.getCrudFormFactory().setFieldProvider("mainGroup",
            new ComboBoxProvider<>(groupService.findAll()));
    crud.getCrudFormFactory().setFieldProvider("groups",
            new CheckBoxGroupProvider<>(groupService.findAll()));
    crud.getCrudFormFactory().setFieldProvider("groups",
            new CheckBoxGroupProvider<>("Groups", groupService.findAll(), Group::getName));
    crud.getCrudFormFactory().setFieldProvider("mainGroup",
            new ComboBoxProvider<>("Main Group", groupService.findAll(), new TextRenderer<>(Group::getName), Group::getName));

    // layout configuration
    setSizeFull();
    add(crud);

    // logic configuration
    crud.setOperations(
            () -> userService.findByNameContainingIgnoreCase(filter.getValue()),
            user -> userService.save(user),
            user -> userService.save(user),
            user -> userService.delete(user)
    );

    filter.addValueChangeListener(e -> crud.refreshGrid());
}
 
Example #18
Source File: NasView.java    From radman with MIT License 4 votes vote down vote up
NasFormDialog(NasService nasService) {
    this.nasService = nasService;

    TextField name = new TextField("Name");
    name.setValueChangeMode(ValueChangeMode.EAGER);
    TextField shortName = new TextField("Short name");
    shortName.setValueChangeMode(ValueChangeMode.EAGER);
    TextField type = new TextField("Type");
    type.setValueChangeMode(ValueChangeMode.EAGER);
    NumberField port = new NumberField("Port");
    port.setValueChangeMode(ValueChangeMode.EAGER);
    PasswordField secret = new PasswordField("Secret");
    secret.setValueChangeMode(ValueChangeMode.EAGER);
    TextField server = new TextField("Server");
    server.setValueChangeMode(ValueChangeMode.EAGER);
    TextField community = new TextField("Community");
    community.setValueChangeMode(ValueChangeMode.EAGER);
    TextArea description = new TextArea("Description");
    description.setValueChangeMode(ValueChangeMode.EAGER);

    FormLayout formLayout = new FormLayout();
    formLayout.setWidthFull();
    formLayout.setMaxWidth("700px");
    formLayout.add(name, shortName, server, port, secret, type, community, description);
    formLayout.setResponsiveSteps(
            new FormLayout.ResponsiveStep("0px", 1),
            new FormLayout.ResponsiveStep("450px", 2));

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
    controlsLayout.add(new Button("Cancel", event -> setOpened(false)));
    controlsLayout.add(getConfirmBtn());
    controlsLayout.setWidthFull();

    add(new H3(getDialogTitle()));
    add(formLayout);
    add(new Hr());
    add(controlsLayout);

    binder = new BeanValidationBinder<>(NasDto.class);
    binder.bind(name, "nasName");
    binder.bind(shortName, "shortName");
    binder.bind(type, "type");
    binder.forField(port)
            .withConverter(new DoubleToIntegerConverter("Port must be number " +
                    "between 1 and " + 65535 + "."))
            .bind("ports");
    binder.bind(secret, "secret");
    binder.bind(server, "server");
    binder.bind(community, "community");
    binder.bind(description, "description");
}
 
Example #19
Source File: AbstractAutoGeneratedCrudFormFactory.java    From crudui with Apache License 2.0 4 votes vote down vote up
protected void bindField(HasValue field, String property, Class<?> propertyType, CrudFormConfiguration configuration) {
    Binder.BindingBuilder bindingBuilder = binder.forField(field);

    if (TextField.class.isAssignableFrom(field.getClass()) || PasswordField.class.isAssignableFrom(field.getClass())
            || TextArea.class.isAssignableFrom(field.getClass())) {
        bindingBuilder = bindingBuilder.withNullRepresentation("");
    }

    if(configuration.getConverters().containsKey(property)) {
        bindingBuilder = bindingBuilder.withConverter(configuration.getConverters().get(property));

    } else if (Double.class.isAssignableFrom(propertyType) || double.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new StringToDoubleConverter(null, "Must be a number"));

    } else if (Long.class.isAssignableFrom(propertyType) || long.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new StringToLongConverter(null, "Must be a number"));

    } else if (BigDecimal.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new StringToBigDecimalConverter(null, "Must be a number"));

    } else if (BigInteger.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new StringToBigIntegerConverter(null, "Must be a number"));

    } else if (Integer.class.isAssignableFrom(propertyType) || int.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new StringToIntegerConverter(null, "Must be a number"));

    } else if (Byte.class.isAssignableFrom(propertyType) || byte.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new StringToByteConverter(null, "Must be a number"));

    } else if (Character.class.isAssignableFrom(propertyType) || char.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new StringToCharacterConverter());

    } else if (Float.class.isAssignableFrom(propertyType) || float.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new StringToFloatConverter(null, "Must be a number"));

    } else if (Date.class.isAssignableFrom(propertyType)) {
        bindingBuilder = bindingBuilder.withConverter(new LocalDateToDateConverter());
    }

    bindingBuilder.bind(property);
}
 
Example #20
Source File: UserToGroupView.java    From radman with MIT License 4 votes vote down vote up
private void buildView() {
    setHeightFull();
    setSpacing(false);

    RoleDto role = securityService.getLoggedUserRole();
    Grid<RadiusUserToGroupDto> grid = new Grid<>(RadiusUserToGroupDto.class, false);
    grid.addColumns("username", "groupName", "userInRadman", "groupInRadman");
    DataProvider<RadiusUserToGroupDto, Object> dataProvider = new SpringDataProviderBuilder<>(
            (pageable, o) -> userService.pageRadiusUserToGroupRecords(filter, pageable),
            value -> userService.countRadiusUserToGroupRecords(filter))
            .withDefaultSort("username", SortDirection.ASCENDING)
            .build();
    grid.setDataProvider(dataProvider);
    grid.setSortableColumns("username", "groupName");
    grid.setColumnReorderingAllowed(true);
    grid.setMinHeight("500px");
    grid.setHeight("100%");

    Button addUserToGroup = new Button("Add user to group", event -> {
        AddUserToGroupDialog addDialog = new AddUserToGroupDialog(
                (source, bean) -> grid.getDataProvider().refreshAll());
        addDialog.startAdding();
    });
    addUserToGroup.setEnabled(role == RoleDto.ADMIN);

    ConfirmationDialog deleteDialog = new ConfirmationDialog();
    deleteDialog.setTitle("Delete User to Group mapping");
    deleteDialog.setDescription("Are you sure?");
    deleteDialog.setConfirmButtonCaption("Delete");
    deleteDialog.setConfirmListener(() -> {
        Optional<RadiusUserToGroupDto> optional = grid.getSelectionModel().getFirstSelectedItem();
        try {
            optional.ifPresent(userService::removeRadiusUserFromGroup);
            grid.getDataProvider().refreshAll();
        } catch (Exception e) {
            log.warn("Failed to delete user to group mapping. Reason = '{}'", e.getMessage());
            ErrorNotification.show("Error",
                    "Ooops, something went wrong, try again please");
        }
        deleteDialog.setOpened(false);
    });
    Button removeUserFromGroup = new Button("Remove user from group", event -> deleteDialog.setOpened(true));
    removeUserFromGroup.setEnabled(false);

    grid.asSingleSelect().addValueChangeListener(event ->
            removeUserFromGroup.setEnabled(Objects.nonNull(event.getValue()) && role == RoleDto.ADMIN));

    TextField search = new TextField(event -> {
        filter.setSearchText(event.getValue());
        grid.getDataProvider().refreshAll();
    });
    search.setValueChangeMode(ValueChangeMode.EAGER);
    search.setPlaceholder("Search...");

    add(new H4("Data from Radius DB - \"radusergroup\" table"));
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.BASELINE);
    horizontalLayout.add(new H3("Users to Groups"));
    horizontalLayout.add(addUserToGroup);
    horizontalLayout.add(removeUserFromGroup);
    horizontalLayout.add(search);
    add(horizontalLayout);
    add(grid);
}