/** * Instantiates a new collect field. * * @param caption the caption * @param groups the available groups */ public CollectField(String caption, List<String> groups) { setCaption(caption); selectField.setRows(10); selectField.setLeftColumnCaption("Available"); selectField.setRightColumnCaption("Selected"); for (String group : groups) { selectField.addItem(group); } }
/** * @param caption * @param dataSource */ public TwinColSelect(String caption, Container dataSource) { super(caption, dataSource); setMultiSelect(true); }
@Override public Component createEditor() { TwinColSelect ret = new TwinColSelect(); ret.setMultiSelect(true); ret.setNullSelectionAllowed(true); ret.setLeftColumnCaption( MNls.find(getForm(), getName() + ".available=Available options") ); ret.setRightColumnCaption( MNls.find(getForm(), getName() + ".selected=Selected options") ); return ret; }
@Override public void doUpdateMetadata() throws MException { TwinColSelect cb = (TwinColSelect)getComponentEditor(); cb.removeAllItems(); String itemsName = getConfig().getString("itemdef", getName() + "." + DataSource.ITEMS); Item[] items = (Item[]) getForm().getDataSource().getObject(itemsName, null); if (items != null) for (Item item : items) cb.addItem(item); }
@SuppressWarnings("unchecked") @Override protected Object getValue() throws MException { Set<String> ret = (Set<String>)((TwinColSelect)getComponentEditor()).getValue(); if (ret == null) return null; return ret; }
@Override protected void setInternalValue(Collect value) { selectField.setValue(new TreeSet<String>(value.getIncludeGroups())); }
@Override public void paintContent(PaintTarget target) throws PaintException { target.addAttribute("type", "twincol"); // Adds the number of columns if (columns != 0) { target.addAttribute("cols", columns); } // Adds the number of rows if (rows != 0) { target.addAttribute("rows", rows); } // Right and left column captions and/or icons (if set) String lc = getLeftColumnCaption(); String rc = getRightColumnCaption(); if (lc != null) { target.addAttribute(TwinColSelectConstants.ATTRIBUTE_LEFT_CAPTION, lc); } if (rc != null) { target.addAttribute(TwinColSelectConstants.ATTRIBUTE_RIGHT_CAPTION, rc); } super.paintContent(target); }
@Test @Ignore("See http://dev.vaadin.com/ticket/10663") public void simpleTwinColFieldTest() throws Exception { // GIVEN definition.setMultiselect(true); twinSelect = new TwinColSelectFieldFactory(definition, baseItem, null, null, new MockComponentProvider()); // WHEN Field field = twinSelect.createField(); // THEN assertThat(field, instanceOf(TwinColSelect.class)); Collection<?> items = ((TwinColSelect) field).getItemIds(); assertEquals(3, items.size()); assertEquals("[]", field.getValue().toString()); }
@Override @SuppressWarnings("unchecked") protected Collect getInternalValue() { Collect collect = new Collect(); if (selectField.getValue() instanceof Set) { Set<String> selected = (Set<String>) selectField.getValue(); for (String value : selected) { collect.addIncludeGroup(value); } } else { collect.addIncludeGroup((String)selectField.getValue()); } return collect; }
@Override protected void setValue(Object value) throws MException { if (value == null) { ((TwinColSelect)getComponentEditor()).setValue(new TreeSet<String>()); return; } if (!(value instanceof Set)) value = MCollection.toTreeSet(String.valueOf(value).split(",")); ((TwinColSelect)getComponentEditor()).setValue(value); }
/** * @param caption */ public TwinColSelect(String caption) { super(caption); setMultiSelect(true); }
/** * */ public TwinColSelect() { super(); setMultiSelect(true); }
/** * @param caption * @param options */ public TwinColSelect(String caption, Collection<?> options) { super(caption, options); setMultiSelect(true); }