@Override public FeatureDescriptor next() { Object key = keys.next(); FeatureDescriptor feature = new FeatureDescriptor(); feature.setDisplayName(key == null ? "null" : key.toString()); feature.setName(feature.getDisplayName()); feature.setShortDescription(""); feature.setExpert(true); feature.setHidden(false); feature.setPreferred(true); feature.setValue(TYPE, key == null ? "null" : key.getClass()); feature.setValue(RESOLVABLE_AT_DESIGN_TIME, true); return feature; }
public static Map<String, Object> introspect(Object obj) throws Exception { Map<String, Object> result = new HashMap<String, Object>(); BeanInfo info = Introspector.getBeanInfo(obj.getClass()); for (PropertyDescriptor pd : info.getPropertyDescriptors()) { Method reader = pd.getReadMethod(); if (reader != null) result.put(pd.getName(), reader.invoke(obj)); } return result; }
@Override public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { return getAttributed(base).map(attributed -> { List<FeatureDescriptor> result = new LinkedList<>(); Collection<String> attributeNames = attributed.abacAttributeNames(); for (String name : attributeNames) { FeatureDescriptor fd = new FeatureDescriptor(); fd.setDisplayName(name); fd.setName(name); result.add(fd); } return result.iterator(); }).orElse(null); }
/** Create a property set. * @param name system name of the property set * @param displayName human presentable name * @param shortDescription description for the set */ public PropertySet(String name, String displayName, String shortDescription) { super.setName(name); super.setDisplayName(displayName); super.setShortDescription(shortDescription); }
private Class<?> getPropertyType(Class<?> clazz, String property) { BeanInfo beanInfo = Introspector.getBeanInfo(clazz); PropertyDescriptor[] propDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor propDescriptor : propDescriptors) { // String name of a property if (property.equals(propDescriptor.getName())) { // Class the getter corresponds to. return propDescriptor.getPropertyType(); } } ... }
public FeatureDescriptor next() { PropertyDescriptor property = properties[next++]; FeatureDescriptor feature = new FeatureDescriptor(); feature.setDisplayName(property.getDisplayName()); feature.setName(property.getName()); feature.setShortDescription(property.getShortDescription()); feature.setExpert(property.isExpert()); feature.setHidden(property.isHidden()); feature.setPreferred(property.isPreferred()); feature.setValue(TYPE, property.getPropertyType()); feature.setValue(RESOLVABLE_AT_DESIGN_TIME, true); return feature; }
public class SimpleBean { private final String name = "SimpleBean"; private int size; public String getName() { return this.name; } public int getSize() { return this.size; } public void setSize( int size ) { this.size = size; } public static void main( String[] args ) throws IntrospectionException { BeanInfo info = Introspector.getBeanInfo( SimpleBean.class ); for ( PropertyDescriptor pd : info.getPropertyDescriptors() ) System.out.println( pd.getName() ); } }
BeanInfo info = Introspector.getBeanInfo(JTextField.class); PropertyDescriptor[] propertyDescriptors = info.getPropertyDescriptors(); for (int i = 0; i < propertyDescriptors.length; ++i) { PropertyDescriptor pd = propertyDescriptors[i]; if (pd.getName().equals("text")) { pd.setValue("transient", Boolean.TRUE); } }
import java.beans.*; // ... MyBean bean = ...; BeanInfo beanInfo = Introspector.getBeanInfo(MyBean.class, Object.class); for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { System.out.println("Property: " + pd.getName()); // Get the getter method of a property Method getter = pd.getReadMethod(); // Call it to get the value in an instance of the bean class Object value = getter.invoke(bean); System.out.println("Value: " + value); }
for (PropertyDescriptor prop : Introspector.getBeanInfo(some_class.getClass()).getPropertyDescriptors()) { if (prop.getName().equals(property_name)) { prop.getWriteMethod().invoke(some_class, value) } }
import java.beans.* for (PropertyDescriptor pd : Introspector.getBeanInfo(Foo.class).getPropertyDescriptors()) { if (pd.getReadMethod() != null && !"class".equals(pd.getName())) System.out.println(pd.getReadMethod().invoke(foo)); }
public void attachEnv(PropertyEnv env) { /* LATER CountLimitEditorComponent is an attempt to workaround the problems described in IZ 76522. It essentially starts reproducing org.openide.explorer.propertysheet.ComboInplaceEditor but the focus stuff just got too complicated. CountLimitEditorComponent clec = new CountLimitEditorComponent(); env.getFeatureDescriptor().setValue("inplaceEditor", clec); */ env.getFeatureDescriptor().setValue("canEditAsText", true); // NOI18N }
public void attachEnv(PropertyEnv env){ // Add the help button String name = (String)getDesignProperty().getPropertyDescriptor().getValue(REFERENCE_DATA_NAME); if (name.equals(ReferenceDataManager.STYLE_CLASSES)){ FeatureDescriptor desc = env.getFeatureDescriptor(); desc.setValue(ExPropertyEditor.PROPERTY_HELP_ID, "projrave_ui_elements_propeditors_styleclass_prop_ed"); } }
/** Set the system name. Fires a property change event. * @param s the new name * @exception IllegalArgumentException if the new name cannot represent * a valid node name */ @Override public void setName(String s) { String name = super.getName(); if ((name == null) || !name.equals(s)) { super.setName(s); fireNameChange(name, s); } }
/** Set the display name. Fires a property change event. * @param s the new name */ @Override public void setDisplayName(String s) { String displayName = super.getDisplayName(); if ((displayName == null) || !displayName.equals(s)) { super.setDisplayName(s); fireDisplayNameChange(displayName, s); } }
Object obj = env.getFeatureDescriptor ().getValue (PROP_SUPERCLASS); if (obj instanceof Class) { @SuppressWarnings("unchecked") Class<Object> clz = (Class<Object>)obj; obj = env.getFeatureDescriptor ().getValue (PROP_NULL); if (Boolean.TRUE.equals (obj)) { nullValue = NbBundle.getMessage (ObjectEditor.class, "CTL_NullValue"); obj = env.getFeatureDescriptor ().getValue (PROP_LOOKUP); lookup = obj instanceof Lookup ? (Lookup)obj : null; env.getFeatureDescriptor().setValue("canEditAsText",Boolean.FALSE); //NOI18N
/** Set the short description of the node. Fires a property change event. * <p>This description may be used for tool tips, etc. * @param s the new description */ @Override public void setShortDescription(String s) { String descr = super.getShortDescription(); if ((descr == null) || !descr.equals(s)) { super.setShortDescription(s); fireShortDescriptionChange(descr, s); } }
/** Constructor. * @param valueType type of the property */ public Property(Class<T> valueType) { this.type = valueType; super.setName(""); // NOI18N }
/** * @deprecated Has no effect. To make a node disappear, simply remove it from the * children of its parent. For example, you might call * {@link Children.Keys#setKeys(Collection)} with a smaller collection. */ @Deprecated @Override public void setHidden(boolean hidden) { super.setHidden(hidden); }
public static void copyBeanProperties( final Object source, final Object target, final Collection<String> includes){ final Collection<String> excludes = new ArrayList<String>(); final PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(source.getClass()); for(final PropertyDescriptor propertyDescriptor : propertyDescriptors){ String propName = propertyDescriptor.getName(); if(!includes.contains(propName)){ excludes.add(propName); } } BeanUtils.copyProperties( source, target, excludes.toArray(new String[excludes.size()])); }