@Test public void testGetFieldTypeForAnonymousInstanceOfGenericField() { @SuppressWarnings("serial") RadioButtonGroup<TestEnum> r = new RadioButtonGroup<TestEnum>() {}; assertTrue(binder.getPresentationTypeForField(r).isPresent()); assertEquals(TestEnum.class, binder.getPresentationTypeForField(r).get()); }
@Test public void testGetFieldTypeForGenericFieldWithValue() { RadioButtonGroup<TestEnum> r = new RadioButtonGroup<TestEnum>(); r.setValue(TestEnum.Test1); assertTrue(binder.getPresentationTypeForField(r).isPresent()); assertEquals(TestEnum.class, binder.getPresentationTypeForField(r).get()); }
@Test public void testGetFieldTypeForGenericFieldWithItems() { EnumSet<TestEnum> set = EnumSet.allOf(TestEnum.class); RadioButtonGroup<TestEnum> r = new RadioButtonGroup<TestEnum>("", set); assertTrue(binder.getPresentationTypeForField(r).isPresent()); assertEquals(TestEnum.class, binder.getPresentationTypeForField(r).get()); }
@Test public void testGetFieldTypeForGenericFieldWithNoItems() { EnumSet<TestEnum> set = EnumSet.noneOf(TestEnum.class); RadioButtonGroup<TestEnum> r = new RadioButtonGroup<TestEnum>("", set); // We don't expect any more than an empty optional assertNotNull(binder.getPresentationTypeForField(r)); }
@Test public void testBindTypeErasure() { when(converterRegistry.getConverter(String.class, String.class)).thenReturn(null); EasyBinding<TestEntity, String, String> binding = binder.bind(new RadioButtonGroup<String>(), "testString"); assertNotNull(binding); verify(converterRegistry, never()).getConverter(any(), any()); Result<String> res = binding.converterValidatorChain.convertToModel("giraf", null); assertFalse(res.isError()); res.ifOk(e -> assertEquals("giraf", e)); assertEquals("bird", binding.converterValidatorChain.convertToPresentation("bird", null)); }
@Test(expected = RuntimeException.class) public void testBindTypeErasureUnrelatedTypes() { when(converterRegistry.getConverter(Double.class, Integer.class)).thenReturn(null); EasyBinding<TestEntity, Double, Integer> binding = binder.bind(new RadioButtonGroup<Double>(), "testInt"); assertNotNull(binding); verify(converterRegistry, never()).getConverter(any(), any()); binding.converterValidatorChain.convertToModel(new Double(10.0), null); }
@Override protected Component createContent() { Messages messages = Messages.getInstance(); layout = new FormLayout(); layout.setMargin(new MarginInfo(true, true)); name = new FTextField(messages.getMessage("informationStep.name.label")).withWidth("250px"); gender = new RadioButtonGroup<Gender>(messages.getMessage("informationStep.sex.label"), EnumSet.allOf(Gender.class)); age = new DSIntegerField(messages.getMessage("informationStep.age.label")); weight = new DSIntegerField(messages.getMessage("informationStep.weight.label")); height = new TextField(messages.getMessage("informationStep.height.label")); alignment = new ComboBox<>(messages.getMessage("informationStep.alignment.label"), alignmentService.findAllPlayable()); region = new ComboBox<>(messages.getMessage("informationStep.region.label"), regionService.findAllOrderBy("name", "ASC")); getBinder().forMemberField(age).withValidator((value, context) -> { int minAge = getEntity().getRace().getMinAge(); int maxAge = getEntity().getRace().getMaxAge(); if (value.intValue() < minAge || value.intValue() > maxAge) { return ValidationResult.error(messages.getMessage("informationStep.age.validator", minAge, maxAge, getEntity().getRace().getName())); } return ValidationResult.ok(); }); gender.addValueChangeListener(event -> initImageSelector(event.getValue())); layout.addComponents(name, gender, age, weight, height, alignment, region); initImageSelector(null); return layout; }
@Test public void testGetFieldTypeForGenericFieldWithNoInfo() { RadioButtonGroup<TestEnum> r = new RadioButtonGroup<TestEnum>(""); // We don't expect any more than an empty optional assertNotNull(binder.getPresentationTypeForField(r)); }
public SelectionControlsView() { setAlignItems(FlexLayout.AlignItems.FLEX_START); setAlignSelf(AlignSelf.BASELINE); setFlexWrap(FlexLayout.FlexWrap.WRAP); setJustifyContent(JustifyContent.CENTER); addStyleName(Spacings.All.LARGE); // Checkboxes MDCheckbox cb1 = new MDCheckbox("Light On"); MDCheckbox cb2 = new MDCheckbox("Light Off"); MDCheckbox cb3 = new MDCheckbox("Light Disabled"); cb3.setEnabled(false); FlexLayout light1 = new FlexLayout(cb1, cb2, cb3); light1.setFlexDirection(FlexLayout.FlexDirection.COLUMN); light1.addStyleName("card " + Paddings.All.LARGE); MDCheckbox cb4 = new MDCheckbox("Dark On", false); MDCheckbox cb5 = new MDCheckbox("Dark Off", false); MDCheckbox cb6 = new MDCheckbox("Dark Disabled", false); cb6.setEnabled(false); FlexLayout dark1 = new FlexLayout(cb4, cb5, cb6); dark1.setFlexDirection(FlexLayout.FlexDirection.COLUMN); dark1.addStyleName("card " + MaterialColor.GREY_900.getBackgroundColorStyle() + " " + Paddings.All.LARGE); // Radio buttons RadioButtonGroup<String> rbg1 = new RadioButtonGroup(); rbg1.setItems("One", "Two"); rbg1.setPrimaryStyleName(Styles.OptionGroups.LIGHT); RadioButtonGroup<String> rbg2 = new RadioButtonGroup(); rbg2.setItems("Disabled One", "Disabled Two"); rbg2.setPrimaryStyleName(Styles.OptionGroups.LIGHT); rbg2.setEnabled(false); FlexLayout light2 = new FlexLayout(rbg1, rbg2); light2.setFlexDirection(FlexLayout.FlexDirection.COLUMN); light2.addStyleName("card " + Paddings.All.LARGE); RadioButtonGroup<String> rbg3 = new RadioButtonGroup(); rbg3.setItems("One", "Two"); rbg3.setPrimaryStyleName(Styles.OptionGroups.DARK); RadioButtonGroup<String> rbg4 = new RadioButtonGroup(); rbg4.setItems("Disabled One", "Disabled Two"); rbg4.setPrimaryStyleName(Styles.OptionGroups.DARK); rbg4.setEnabled(false); FlexLayout dark2 = new FlexLayout(rbg3, rbg4); dark2.setFlexDirection(FlexLayout.FlexDirection.COLUMN); dark2.addStyleName("card " + MaterialColor.GREY_900.getBackgroundColorStyle() + " " + Paddings.All.LARGE); // Switches MDSwitch sw1 = new MDSwitch("Light On"); MDSwitch sw2 = new MDSwitch("Light Off"); MDSwitch sw3 = new MDSwitch("Light Disabled"); sw3.setEnabled(false); FlexLayout light3 = new FlexLayout(sw1, sw2, sw3); light3.setFlexDirection(FlexLayout.FlexDirection.COLUMN); light3.addStyleName("card " + Paddings.All.LARGE); MDSwitch sw4 = new MDSwitch("Dark On", false); MDSwitch sw5 = new MDSwitch("Dark Off", false); MDSwitch sw6 = new MDSwitch("Dark Disabled", false); sw6.setEnabled(false); FlexLayout dark3 = new FlexLayout(sw4, sw5, sw6); dark3.setFlexDirection(FlexLayout.FlexDirection.COLUMN); dark3.addStyleName("card " + MaterialColor.GREY_900.getBackgroundColorStyle() + " " + Paddings.All.LARGE); addComponents(light1, dark1, light2, dark2, light3, dark3); }
public void setHtmlContentAllowed(boolean htmlContentAllowed) { if (getInternalField() instanceof RadioButtonGroup) { ((RadioButtonGroup<?>) getInternalField()).setHtmlContentAllowed(htmlContentAllowed); } }
@SuppressWarnings("unchecked") public void setItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider) { if (getInternalField() instanceof RadioButtonGroup) { ((RadioButtonGroup<T>) getInternalField()).setItemEnabledProvider(itemEnabledProvider); } }
@Override protected Component createContent() { Messages messages = Messages.getInstance(); Component content = super.createContent(); featLayout = new FHorizontalLayout().withFullWidth(); updateType = new RadioButtonGroup<UpdateType>(messages.getMessage("abilityScoreStep.updateType.label")); updateType.setItems(Arrays.asList(UpdateType.values())); updateType.addValueChangeListener(event -> { if (event.getValue() != null) { abilityLayout.setVisible(event.getValue() == UpdateType.ABILITY); featLayout.setVisible(event.getValue() == UpdateType.FEAT); if (event.getValue() == UpdateType.ABILITY) { featChoice.setValue(null); } else { resetPointToSpend(); strength.setValue(backupEntity.getStrength()); dexterity.setValue(backupEntity.getDexterity()); constitution.setValue(backupEntity.getConstitution()); intelligence.setValue(backupEntity.getIntelligence()); wisdom.setValue(backupEntity.getWisdom()); charisma.setValue(backupEntity.getCharisma()); } adjustButtons(); } }); getLayout().addComponentAsFirst(updateType); resetPointToSpend(); featChoice = new FComboBox<Feat>(messages.getMessage("abilityScoreStep.feat.label")).withFullWidth(); featDescription = new DSLabel(); featLayout.addComponents(featChoice, featDescription); getLayout().addComponent(featLayout); return content; }
protected void createExportLayout() { exportLayout = new VerticalLayout(); exportLayout.setSizeFull(); exportLayout.setMargin(true); exportLayout.setSpacing(true); HorizontalLayout exportOptionsLayout = new HorizontalLayout(); exportOptionsLayout.setSpacing(true); Label optionGroupLabel = new Label("Export Format <span style='padding-left:0px; color: red'>*</span>", ContentMode.HTML); exportOptionsLayout.addComponent(optionGroupLabel); oGroup = new RadioButtonGroup<String>(); List<String> options = Arrays.asList("CSV", "Excel"); oGroup.setItems(options); oGroup.setValue("CSV"); exportOptionsLayout.addComponent(oGroup); exportLayout.addComponent(exportOptionsLayout); exportLayout.setExpandRatio(exportOptionsLayout, 1); cancelButton = new Button("Cancel", new Button.ClickListener() { static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { UI.getCurrent().removeWindow(ExportDialog.this); } }); exportButton = CommonUiUtils.createPrimaryButton("Export", new Button.ClickListener() { static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { if (oGroup.getValue().toString().equals("CSV")) { csvExport(); } else { excelExport(); } UI.getCurrent().removeWindow(ExportDialog.this); } }); exportButton.setClickShortcut(KeyCode.ENTER); exportLayout.addComponent(buildButtonFooter(cancelButton, exportButton)); }
/** * Sets whether html is allowed in the item captions. If set to true, the * captions are passed to the browser as html and the developer is * responsible for ensuring no harmful html is used. If set to false, the * content is passed to the browser as plain text. * * @param htmlContentAllowed * true if the captions are used as html, false if used as plain text * @return this for method chaining * @see RadioButtonGroup#setHtmlContentAllowed(boolean) */ @SuppressWarnings("unchecked") public default THIS withHtmlContentAllowed(boolean htmlContentAllowed) { ((RadioButtonGroup<ITEM>) this).setHtmlContentAllowed(htmlContentAllowed); return (THIS) this; }
/** * Sets the item caption generator that is used to produce the strings shown * in the radio button group for each item. By default, * {@link String#valueOf(Object)} is used. * * @param itemCaptionGenerator * the item caption provider to use, not null * @return this for method chaining * @see RadioButtonGroup#setItemCaptionGenerator(ItemCaptionGenerator) */ @SuppressWarnings("unchecked") public default THIS withItemCaptionGenerator(ItemCaptionGenerator<ITEM> itemCaptionGenerator) { ((RadioButtonGroup<ITEM>) this).setItemCaptionGenerator(itemCaptionGenerator); return (THIS) this; }
/** * @see IconGenerator * @see RadioButtonGroup#setItemIconGenerator(IconGenerator) * * @param itemIconGenerator * the item icon generator to set, not null * @return this for method chaining */ @SuppressWarnings("unchecked") public default THIS withItemIconGenerator(IconGenerator<ITEM> itemIconGenerator) { ((RadioButtonGroup<ITEM>) this).setItemIconGenerator(itemIconGenerator); return (THIS) this; }
/** * Sets the item enabled predicate for this radiobutton group. The predicate * is applied to each item to determine whether the item should be enabled * (true) or disabled (false). Disabled items are displayed as grayed out * and the user cannot select them. The default predicate always returns * true (all the items are enabled). * * @param itemEnabledProvider * the item enable predicate, not null * @return this for method chaining * @see RadioButtonGroup#setItemEnabledProvider(SerializablePredicate) */ @SuppressWarnings("unchecked") public default THIS withItemEnabledProvider(SerializablePredicate<ITEM> itemEnabledProvider) { ((RadioButtonGroup<ITEM>) this).setItemEnabledProvider(itemEnabledProvider); return (THIS) this; }
/** * Constructs a new RadioButtonGroup. * * @since 0.1 */ // Copied from Vaadin Framework public CheckBoxSingleGroup() { this(new RadioButtonGroup<>()); }
/** * Constructs a new RadioButtonGroup with caption. * * @param caption caption text * @since 0.1 */ // Copied from Vaadin Framework public CheckBoxSingleGroup(String caption) { this(new RadioButtonGroup<>(caption)); }
/** * Constructs a new RadioButtonGroup with caption and DataProvider * containing given items. * * @param caption the caption text * @param items the data items to use, not null * @see #setItems(Collection) * @since 0.1 */ // Copied from Vaadin Framework public CheckBoxSingleGroup(String caption, Collection<V> items) { this(new RadioButtonGroup<>(caption, items)); }
/** * Constructs a new RadioButtonGroup with caption and DataProvider. * * @param caption the caption text * @param dataProvider the data provider, not null * @see HasDataProvider#setDataProvider(DataProvider) * @since 0.1 */ // Copied from Vaadin Framework public CheckBoxSingleGroup(String caption, DataProvider<V, ?> dataProvider) { this(new RadioButtonGroup<>(caption, dataProvider)); }
/** * Uses the given <code>RadioButtonGroup</code> as base for the component. * * @param field the <code>RadioButtonGroup</code> used in the component, not {@code null} * @since 0.1 */ public CheckBoxSingleGroup(RadioButtonGroup<V> field) { super(field); }