All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.extjs.gxt.ui.client.data.BeanModel Maven / Gradle / Ivy

There is a newer version: 2.3.1-gwt22
Show newest version
/*
 * Sencha GXT 2.3.1a - Sencha for GWT
 * Copyright(c) 2007-2013, Sencha, Inc.
 * [email protected]
 * 
 * http://www.sencha.com/products/gxt/license/
 */
 package com.extjs.gxt.ui.client.data;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.core.FastMap;

/**
 * A ModelData instance that wraps a bean. BeanModels cannot be
 * instantiated directly, rather, they are returned by {@link BeanModelFactory}.
 * 
 * 

* Nested beans are supported when creating BeanModel instances with limited * support for nested lists of beans. Any child lists must be defined with * java.util.List and must be paramertized with a BeanModelTag class or * subclass. * *

* When working with bean models, avoid setting beans as values, rather, set the * wrapping bean model instance. * * @see BeanModelFactory */ public class BeanModel extends BaseModel { transient protected Object bean; protected Map nestedModels = new FastMap(); protected List beanProperties = new ArrayList(); protected BeanModel() { } /** * Returns the bean. * * @return the bean */ @SuppressWarnings("unchecked") public X getBean() { return (X) bean; } @Override public Map getProperties() { Map newMap = new FastMap(); for (String s : getPropertyNames()) { newMap.put(s, get(s)); } return newMap; } @Override public Collection getPropertyNames() { Collection c = super.getPropertyNames(); for (String s : beanProperties) { c.add(s); } return c; } @Override public String toString() { return ((Object) getBean()).toString(); } protected Object processValue(Object value) { return value; } /** * Sets the bean. * * @param bean the bean */ protected void setBean(Object bean) { this.bean = bean; } }