@Test public void testGetFieldTypeForAnonymousInstanceOfGenericCollectionField() { @SuppressWarnings("serial") TwinColSelect<String> r = new TwinColSelect<String>() {}; assertTrue(binder.getPresentationTypeForField(r).isPresent()); assertEquals(Set.class, binder.getPresentationTypeForField(r).get()); }
@Test public void testGetFieldTypeForHasGenericTypeOfGenericCollectionField() { @SuppressWarnings({ "rawtypes" }) EGTypeComponentAdapter<Set> r = new EGTypeComponentAdapter<>(Set.class, new TwinColSelect<String>()); assertTrue(binder.getPresentationTypeForField(r).isPresent()); assertEquals(Set.class, binder.getPresentationTypeForField(r).get()); }
@Test public void testBindSet() { when(converterRegistry.getConverter(Set.class, Set.class)).thenReturn(null); @SuppressWarnings("serial") EasyBinding<TestEntity, Set<String>, Set<String>> binding = binder.bind(new TwinColSelect<String>(){}, "testSet"); assertNotNull(binding); verify(converterRegistry, times(1)).getConverter(Set.class, Set.class); }
@Test public void testBindEnumSetToSet() { @SuppressWarnings({ "unchecked", "rawtypes" }) Converter<Set, EnumSet> c = mock(Converter.class); when(converterRegistry.getConverter(Set.class, EnumSet.class)).thenReturn(c); @SuppressWarnings("serial") EasyBinding<TestEntity, Set<TestEnum>, EnumSet<TestEnum>> binding = binder.bind(new TwinColSelect<TestEnum>(){}, "testEnumSet"); assertNotNull(binding); verify(converterRegistry, times(1)).getConverter(Set.class, EnumSet.class); }
@Test public void testBindWithConverter() { when(converterRegistry.getConverter(Set.class, EnumSet.class)).thenReturn(null); @SuppressWarnings({ "unchecked" }) Converter<Set<TestEnum>, EnumSet<TestEnum>> c = mock(Converter.class); @SuppressWarnings("serial") EasyBinding<TestEntity, Set<TestEnum>, EnumSet<TestEnum>> binding = binder.bind(new TwinColSelect<TestEnum>(){}, "testEnumSet", c); assertNotNull(binding); verify(converterRegistry, never()).getConverter(Set.class, EnumSet.class); }
/** * @param list * @param tcs */ private void fillLeftDefault(List<String> list, TwinColSelect tcs) { for (String item : list) { if (tcs.getItem(item) == null) { // not presented -> add tcs.addItem(item); } } }
/** * {@inheritDoc} */ @Override protected Component initContent() { final TwinColSelect twin = new TwinColSelect(); twin.setRows(10); twin.setNullSelectionAllowed(true); twin.setMultiSelect(true); twin.setImmediate(true); twin.setLeftColumnCaption("Доступные бренды"); twin.setRightColumnCaption("Бренды юр.лица"); twin.addValueChangeListener(event -> { final Set selected = (Set) twin.getValue(); setValue(selected); }); final Property dataSource = getPropertyDataSource(); final Set<String> set = dataSource != null ? (Set<String>) dataSource.getValue() : null; if (set != null) { twin.setValue(newHashSet(set)); } for (final String item : lookup(MotorBrandRepository.class).loadAllNames()) { twin.addItem(item); } return twin; }
/** * Crate a {@link TwinColSelect} */ public static TwinColSelect newTwinColSelect() { TwinColSelect select = new TwinColSelect(); select.setLocale(LocaleContextHolder.getLocale()); return select; }
public GroupEditPanel(ApplicationContext context, Group group) { this.context = context; this.group = group; FormLayout layout = new FormLayout(); TextField nameField = new TextField("Group Name", StringUtils.trimToEmpty(group.getName())); nameField.addValueChangeListener(new NameChangeListener()); layout.addComponent(nameField); nameField.focus(); readOnly = new CheckBox("Read Only"); readOnly.setEnabled(isNotBlank(group.getName())); readOnly.setImmediate(true); readOnly.setValue(group.isReadOnly()); readOnly.addValueChangeListener(new ReadOnlyChangeListener()); layout.addComponent(readOnly); privSelect = new TwinColSelect(); privSelect.setEnabled(isNotBlank(group.getName())); for (Privilege priv : Privilege.values()) { privSelect.addItem(priv.name()); } lastPrivs = new HashSet<String>(); for (GroupPrivilege groupPriv : group.getGroupPrivileges()) { lastPrivs.add(groupPriv.getName()); } privSelect.setValue(lastPrivs); privSelect.setRows(20); privSelect.setNullSelectionAllowed(true); privSelect.setMultiSelect(true); privSelect.setImmediate(true); privSelect.setLeftColumnCaption("Available privileges"); privSelect.setRightColumnCaption("Selected privileges"); privSelect.addValueChangeListener(new PrivilegeChangeListener()); layout.addComponent(privSelect); addComponent(layout); setMargin(true); }
@AutoGenerated private AbsoluteLayout buildMainLayout() { // common part: create layout mainLayout = new AbsoluteLayout(); mainLayout.setImmediate(false); mainLayout.setWidth("700px"); mainLayout.setHeight("480px"); // top-level component properties setWidth("700px"); setHeight("480px"); // resutadoAprendizajeSelect resutadoAprendizajeSelect = new TwinColSelect(); resutadoAprendizajeSelect.setImmediate(false); resutadoAprendizajeSelect.setWidth("100.0%"); resutadoAprendizajeSelect.setHeight("-1px"); mainLayout.addComponent(resutadoAprendizajeSelect, "top:60.0px;right:63.0px;left:80.0px;"); // label_1 label_1 = new Label(); label_1.setImmediate(false); label_1.setWidth("229px"); label_1.setHeight("-1px"); label_1.setValue("Resultados de Aprendizaje Disponibles:"); mainLayout.addComponent(label_1, "top:20.0px;left:80.0px;"); // label_2 label_2 = new Label(); label_2.setImmediate(false); label_2.setWidth("229px"); label_2.setHeight("-1px"); label_2.setValue("Resultados de Aprendizaje Asociados:"); mainLayout.addComponent(label_2, "top:20.0px;left:380.0px;"); // label_3 label_3 = new Label(); label_3.setImmediate(false); label_3.setWidth("89px"); label_3.setHeight("18px"); label_3.setValue("Competencia:"); mainLayout.addComponent(label_3, "top:222.0px;left:80.0px;"); // btGuardarCompetencia btGuardarCompetencia = new NativeButton(); btGuardarCompetencia.setCaption("Guardar"); btGuardarCompetencia.setImmediate(true); btGuardarCompetencia.setWidth("-1px"); btGuardarCompetencia.setHeight("-1px"); mainLayout.addComponent(btGuardarCompetencia, "top:418.0px;left:566.0px;"); // textDescripcion textDescripcion = new TextArea(); textDescripcion.setImmediate(false); textDescripcion.setWidth("560px"); textDescripcion.setHeight("140px"); textDescripcion.setMaxLength(100); mainLayout.addComponent(textDescripcion, "top:260.0px;left:80.0px;"); return mainLayout; }
/** * <p> * Returns a Vaadin TwinColSelect object with an implicit * ValueChangeListener that writes the selected options directly to the R * workspace. See {@link RContainer#getListSelect} for examples, and how to * (re)set the values and set the listener explicitly. * </p> * * @param optionsInName * The R character vector name to contain the different choices. * Repeated elements will be ignored. * @param selectedOutName * The R character variable to immediately write the selection * to. * @return Vaadin TwinColSelect object. */ public TwinColSelect getTwinColSelect(String optionsInName, final String selectedOutName) { final TwinColSelect tcs = new TwinColSelect(); buildSelectOptions(tcs, optionsInName); buildSelectListener(tcs, selectedOutName); return tcs; }
/** * Sets the number of rows in the selects. If the number of rows is set to 0 * or less, the actual number of displayed rows is determined implicitly by * the selects. * <p> * If a height if set (using {@link #setHeight(String)} or * {@link #setHeight(float, Unit)}) it overrides the number of rows. Leave * the height undefined to use this method. * * @param rows * the number of rows to set. * @return this (for method chaining) * @see TwinColSelect#setRows(int) */ @SuppressWarnings("unchecked") public default THIS withRows(int rows) { ((TwinColSelect<ITEM>) this).setRows(rows); return (THIS) this; }
/** * Sets the text shown above the left column. {@code null} clears the * caption. * * @param leftColumnCaption * The text to show, {@code null} to clear * @return this (for method chaining) * @see TwinColSelect#setLeftColumnCaption(String) */ @SuppressWarnings("unchecked") public default THIS withLeftColumnCaption(String leftColumnCaption) { ((TwinColSelect<ITEM>) this).setLeftColumnCaption(leftColumnCaption); return (THIS) this; }
/** * Sets the text shown above the right column. {@code null} clears the * caption. * * @param rightColumnCaption * The text to show, {@code null} to clear * @return this (for method chaining) * @see TwinColSelect#setRightColumnCaption(String) */ @SuppressWarnings("unchecked") public default THIS withRightColumnCaption(String rightColumnCaption) { ((TwinColSelect<ITEM>) this).setRightColumnCaption(rightColumnCaption); return (THIS) this; }