/** * Gets the OpenNMS bean. * * @param itemId the item id * @return the OpenNMS bean */ public T getOnmsBean(Object itemId) { BeanItem<T> item = getItem(itemId); return item == null ? null : item.getBean(); }
/** * Create a BeanItem for a bean using pre-parsed bean metadata (based on * {@link #getBeanType()}). * * @param bean * @return created {@link BeanItem} or null if bean is null */ protected BeanItem<BEANTYPE> createBeanItem(BEANTYPE bean) { return bean == null ? null : new BeanItem<BEANTYPE>(bean, model); }
Class<?> propertyType = getType(propertyId); LinkedHashMap<String, VaadinPropertyDescriptor<Object>> pds = BeanItem .getPropertyDescriptors((Class<Object>) propertyType); for (String subPropertyId : pds.keySet()) { String qualifiedPropertyId = propertyId + "." + subPropertyId; model.remove(propertyId); for (BeanItem<BEANTYPE> item : itemIdToItem.values()) { item.addItemProperty(qualifiedPropertyId, pd.createProperty(item.getBean())); item.removeItemProperty(propertyId);
/** * Adds a nested property to the item. The property must not exist in the * item already and must of form "field1.field2" where field2 is a field in * the object referenced to by field1. If an intermediate property returns * null, the property will return a null value * * @param nestedPropertyId * property id to add. */ public void addNestedProperty(String nestedPropertyId) { addItemProperty(nestedPropertyId, new NestedMethodProperty<Object>(getBean(), nestedPropertyId)); }
/** * Expands nested bean properties by replacing a top-level property with * some or all of its sub-properties. The expansion is not recursive. * * @param propertyId * property id for the property whose sub-properties are to be * expanded, * @param subPropertyIds * sub-properties to expand, all sub-properties are expanded if * not specified */ public void expandProperty(String propertyId, String... subPropertyIds) { Set<String> subPropertySet = new HashSet<String>( Arrays.asList(subPropertyIds)); if (0 == subPropertyIds.length) { // Enumerate all sub-properties Class<?> propertyType = getItemProperty(propertyId).getType(); Map<String, ?> pds = getPropertyDescriptors(propertyType); subPropertySet.addAll(pds.keySet()); } for (String subproperty : subPropertySet) { String qualifiedPropertyId = propertyId + "." + subproperty; addNestedProperty(qualifiedPropertyId); } removeItemProperty(propertyId); }
private synchronized void loadPropertiesIfNull() { if (m_properties == null) { m_properties = new TreeMap<Object,Class<?>>(); BeanItem<T> item = null; try { item = new BeanItem<T>(m_datasource.createInstance(m_itemClass)); } catch (InstantiationException e) { LoggerFactory.getLogger(getClass()).error("Class {} does not have a default constructor. Cannot create an instance.", getItemClass()); } catch (IllegalAccessException e) { LoggerFactory.getLogger(getClass()).error("Class {} does not have a public default constructor. Cannot create an instance.", getItemClass()); } for (Object key : item.getItemPropertyIds()) { m_properties.put(key, item.getItemProperty(key).getType()); } } } }
if (getBean().getClass() != bean.getClass()) { throw new IllegalArgumentException( "The new bean class " + bean.getClass().getName() + " does not match the old bean class " + getBean().getClass()); for (Object propertyId : getItemPropertyIds()) { Property p = getItemProperty(propertyId); if (p instanceof MethodProperty) { MethodProperty mp = (MethodProperty) p; assert (mp.getInstance() == getBean()); mp.setInstance(bean); } else if (p instanceof NestedMethodProperty) { NestedMethodProperty nmp = (NestedMethodProperty) p; assert (nmp.getInstance() == getBean()); nmp.setInstance(bean);
@Override public void selectionChanged(SelectionChangedEvent changeEvent) { if (parameter != null) { try { blockListenerOrValidators = true; setData(changeEvent.getSelectedBean()); setItemId(changeEvent.getSelectedItemId()); final BeanItem beanItem = new BeanItem(changeEvent.getSelectedBean(), parameter.getEditablePropertyName(), parameter.getNonEditablePropertyName()); // this is a hack, but we need to know if the selection changed beanItem.addItemProperty("selected", changeEvent.getSelectedItem().getItemProperty("selected")); captionLabel.setValue(String.format("<b>%s</b>", parameter.getCaption())); fieldGroup = new FieldGroup(); fieldGroup.setBuffered(false); fieldGroup.bind(selectedField, "selected"); fieldGroup.bind(editableField, parameter.getEditablePropertyName()); fieldGroup.bind(nonEditableField, parameter.getNonEditablePropertyName()); fieldGroup.setItemDataSource(beanItem); fieldGroup.getField(parameter.getNonEditablePropertyName()).setCaption(parameter.getNonEditablePropertyCaption()); fieldGroup.getField(parameter.getNonEditablePropertyName()).setReadOnly(true); fieldGroup.getField(parameter.getEditablePropertyName()).setCaption(parameter.getEditablePropertyCaption()); fieldGroup.getField(parameter.getEditablePropertyName()).setReadOnly(false); updateEnabledState(); UIHelper.validateField(editableField, true); } finally { blockListenerOrValidators = false; } } }
LinkedHashMap<String, VaadinPropertyDescriptor<BT>> pds = getPropertyDescriptors( (Class<BT>) bean.getClass()); VaadinPropertyDescriptor<BT> pd = pds.get(id); if (pd != null) { addItemProperty(pd.getName(), pd.createProperty(bean));
/** * <p> * Creates a new instance of <code>BeanItem</code> using a pre-computed set * of properties. The properties are identified by their respective bean * names. * </p> * * @param bean * the Java Bean to copy properties from. * @param propertyDescriptors * pre-computed property descriptors */ BeanItem(BT bean, Map<String, VaadinPropertyDescriptor<BT>> propertyDescriptors) { this.bean = bean; for (VaadinPropertyDescriptor<BT> pd : propertyDescriptors.values()) { addItemProperty(pd.getName(), pd.createProperty(bean)); } }
private void ensureNestedPropertyAdded(Object propertyId) { if (getItemDataSource() != null) { // The data source is set so the property must be found in the item. // If it is not we try to add it. try { getItemProperty(propertyId); } catch (BindException e) { // Not found, try to add a nested property; // BeanItem property ids are always strings so this is safe getItemDataSource().addNestedProperty((String) propertyId); } } }
/** * Adds a property for the container and all its items. * * Primarily for internal use, may change in future versions. * * @param propertyId * @param propertyDescriptor * @return true if the property was added */ protected final boolean addContainerProperty(String propertyId, VaadinPropertyDescriptor<BEANTYPE> propertyDescriptor) { if (null == propertyId || null == propertyDescriptor) { return false; } // Fails if the Property is already present if (model.containsKey(propertyId)) { return false; } model.put(propertyId, propertyDescriptor); for (BeanItem<BEANTYPE> item : itemIdToItem.values()) { item.addItemProperty(propertyId, propertyDescriptor.createProperty(item.getBean())); } // Sends a change event fireContainerPropertySetChange(); return true; }
@Override protected BeanItem<?> getItem() { BeanItem<?> item = super.getItem(); Property property = new TextField(); property.setValue(version); item.addItemProperty(VersionName.PROPERTY_NAME_VERSION_NAME, property); return item; }
public static <T> MBeanFieldGroup<T> bind(T bean, Object objectWithMemberFields, String... nestedProperties) { MBeanFieldGroup<T> beanFieldGroup = new MBeanFieldGroup<>((Class<T>) bean.getClass()); beanFieldGroup.setItemDataSource(bean); if(nestedProperties != null) { for (String nestedPropertyId : nestedProperties) { beanFieldGroup.getItemDataSource().addNestedProperty(nestedPropertyId); } } beanFieldGroup.setBuffered(false); beanFieldGroup.bindMemberFields(objectWithMemberFields); beanFieldGroup.configureMaddonDefaults(); return beanFieldGroup; }
/** * Gets the group. * * @return the group */ public Group getGroup() { return groupEditor.getItemDataSource().getBean(); }
@Override public Item getItem() { return new BeanItem<AbstractVertex>(this); }
/** * Gets the resource type. * * @param resourceTypeId the resourceType ID (the Item ID associated with the container) * @return the resource type */ public ResourceType getResourceType(Object resourceTypeId) { return container.getItem(resourceTypeId).getBean(); }
@Override public Item getItem() { return new BeanItem<AbstractEdge>(this); }
/** * Gets the resource type. * * @return the resource type */ public ResourceType getResourceType() { return resourceTypeEditor.getItemDataSource().getBean(); }
/** * Helper method for setting the data source directly using a bean. This * method wraps the bean in a {@link BeanItem} and calls * {@link #setItemDataSource(Item)}. * <p> * For null values, a null item is passed to * {@link #setItemDataSource(Item)} to be properly clear fields. * * @param bean * The bean to use as data source. */ public void setItemDataSource(T bean) { if (bean == null) { setItemDataSource((Item) null); } else { setItemDataSource(new BeanItem<T>(bean, beanType)); } }