/** * Queries a property value on a JavaBean instance * @param bean the bean to read * @param propertyName the name of the property to read * @return the property value */ public static Object getPropertyValue(Object bean, String propertyName) { return getPropertyValue(bean, propertyName, true); }
@SuppressWarnings("unchecked") public static <BEAN, PROP_TYPE> List<PROP_TYPE> extractProperties(Collection<BEAN> beans, String propertyName) { List<PROP_TYPE> result = new ArrayList<PROP_TYPE>(beans.size()); for (BEAN bean : beans) result.add((PROP_TYPE) getPropertyValue(bean, propertyName)); return result; }
public static Map<String, ?> getPropertyValues(Object bean, boolean includeClass) { Map<String, Object> result = new HashMap<String, Object>(); PropertyDescriptor[] descriptors = getPropertyDescriptors(bean.getClass()); for (PropertyDescriptor descriptor : descriptors) { String propertyName = descriptor.getName(); if (includeClass || !"class".equals(propertyName)) result.put(propertyName, getPropertyValue(bean, descriptor)); } return result; }
@SuppressWarnings("unchecked") public static <BEAN, PROP_TYPE> PROP_TYPE[] extractProperties(BEAN[] beans, String propertyName, Class<PROP_TYPE> propertyType) { PROP_TYPE[] result = ArrayUtil.newInstance(propertyType, beans.length); for (int i = 0; i < beans.length; i++) { BEAN bean = beans[i]; result[i] = (PROP_TYPE) getPropertyValue(bean, propertyName); } return result; }
public static Map<String, ?> getRWPropertyValues(Object bean, boolean includeClass) { Map<String, Object> result = new HashMap<String, Object>(); PropertyDescriptor[] descriptors = getPropertyDescriptors(bean.getClass()); for (PropertyDescriptor descriptor : descriptors) { String propertyName = descriptor.getName(); if (descriptor.getWriteMethod() != null && descriptor.getReadMethod() != null && (includeClass || !"class".equals(propertyName))) result.put(propertyName, getPropertyValue(bean, descriptor)); } return result; }
public static Object getPropertyValue(Object bean, String propertyName, boolean propertyRequired) { PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), propertyName); if (descriptor == null) { if (propertyRequired) throw new ConfigurationError("Property '" + propertyName + "' not found in class " + bean.getClass()); else return null; } return getPropertyValue(bean, descriptor); }
/** * Copies a Map's values to the properties of a JavaBean, * using the Map entries' key values as bean property names. * @param sourceBean the bean from which to read the properties * @param targetBean the bean on which to set the properties */ public static void copyPropertyValues(Object sourceBean, Object targetBean) { PropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(sourceBean.getClass()); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String name = propertyDescriptor.getName(); if (propertyDescriptor.getReadMethod() != null) { Object value = getPropertyValue(sourceBean, propertyDescriptor); setPropertyValue(targetBean, name, value, false, true); } } }
public static Object getPropertyGraph(String path, Object bean) { String[] tokens = StringUtil.splitOnFirstSeparator(path, '.'); Object tmp = BeanUtil.getPropertyValue(bean, tokens[0]); if (tokens[1] != null && tmp != null) return getPropertyGraph(tokens[1], tmp); else return tmp; }
/** * reads the current property value and writes it to the text field. */ void refresh() { if (!locked) { locked = true; boolean propertyValue = (Boolean) BeanUtil.getPropertyValue(bean, propertyName); boolean selected = isSelected(); if (selected != propertyValue) setSelected(propertyValue); locked = false; } }
/** * writes the current file field content to the property. */ void update() { if (!locked) { locked = true; File file = getFile(); if (!NullSafeComparator.equals(file, BeanUtil.getPropertyValue(bean, propertyName))) BeanUtil.setPropertyValue(bean, propertyName, file); locked = false; } }
/** * reads the current property value and writes it to the file field. */ void refresh() { if (!locked) { locked = true; Object propertyValue = BeanUtil.getPropertyValue(bean, propertyName); File file = (File) propertyValue; if (!NullSafeComparator.equals(getFile(), file)) setFile(file); locked = false; } }
/** * writes the current text field content to the property. */ void update() { if (!locked) { locked = true; Object propertyValue = BeanUtil.getPropertyValue(bean, propertyName); Object selectedItem = getSelectedItem(); if (!NullSafeComparator.equals(selectedItem, propertyValue)) BeanUtil.setPropertyValue(bean, propertyName, selectedItem); locked = false; } }
/** * reads the current property value and writes it to the text field. */ void refresh() { if (!locked) { locked = true; Object propertyValue = BeanUtil.getPropertyValue(bean, propertyName); Object selectedItem = getSelectedItem(); if (!NullSafeComparator.equals(selectedItem, propertyValue)) setSelectedItem(propertyValue); locked = false; } }
/** * writes the current text field content to the property. */ void update() { if (!locked) { locked = true; Boolean propertyValue = (Boolean) BeanUtil.getPropertyValue(bean, propertyName); Boolean selected = isSelected(); if (!NullSafeComparator.equals(selected, propertyValue)) BeanUtil.setPropertyValue(bean, propertyName, selected); locked = false; } }
/** * reads the current property value and writes it to the text field. */ void refresh() { if (!locked) { locked = true; Object propertyValue = BeanUtil.getPropertyValue(bean, propertyName); String text = toStringConverter.convert(propertyValue); text = StringUtil.escape(text); if (!getPassword().equals(text)) setText(text); locked = false; } }
/** * reads the current property value and writes it to the file list. */ void refresh() { if (!locked) { locked = true; Object propertyValue = BeanUtil.getPropertyValue(bean, propertyName); File[] files = (File[]) propertyValue; if (!CollectionUtil.ofEqualContent(getFiles(), files)) setFiles(files); locked = false; } }
/** * reads the current property value and writes it to the text field. */ void refresh() { if (!locked) { locked = true; Object propertyValue = BeanUtil.getPropertyValue(bean, propertyName); String text = toStringConverter.convert(propertyValue); text = StringUtil.escape(text); if (!getText().equals(text)) setText(text); locked = false; } }
/** * reads the current property value and writes it to the text field. */ void refresh() { if (!locked) { locked = true; Object propertyValue = BeanUtil.getPropertyValue(bean, propertyName); String text = toStringConverter.convert(propertyValue); text = StringUtil.escape(text); if (!getText().equals(text)) setText(text); locked = false; } }
/** * writes the current file field content to the property. */ void update() { if (!locked) { locked = true; File[] modelFiles = (File[]) BeanUtil.getPropertyValue(bean, propertyName); List<File> viewFiles = getFiles(); if (!CollectionUtil.ofEqualContent(viewFiles, modelFiles)) { File[] files = CollectionUtil.toArray(viewFiles, File.class); BeanUtil.setPropertyValue(bean, propertyName, files); } locked = false; } }
private void init(Object bean, String propertyName) { this.bean = bean; this.propertyName = propertyName; this.locked = true; refresh(); Listener listener = new Listener(); if (bean instanceof ObservableBean) ((ObservableBean) bean).addPropertyChangeListener(propertyName, listener); this.addActionListener(listener); this.locked = false; File value = (File) BeanUtil.getPropertyValue(bean, propertyName); if (value != null) setFile(value); }