use of java.beans.PropertyDescriptor in project core-java by SpineEventEngine.
the class Columns method addToCache.
/**
* Caches the {@linkplain Entity entity type} for further {@link Column Columns} retrieving.
*/
private static void addToCache(Class<? extends Entity> entityType) {
final BeanInfo entityDescriptor;
try {
entityDescriptor = Introspector.getBeanInfo(entityType);
} catch (IntrospectionException e) {
throw new IllegalStateException(e);
}
for (PropertyDescriptor property : entityDescriptor.getPropertyDescriptors()) {
final Method getter = property.getReadMethod();
if (!ExcludedMethod.contain(getter.getName())) {
final Column<?> storageField = Column.from(getter);
knownEntityProperties.put(entityType, storageField);
}
}
}
use of java.beans.PropertyDescriptor in project ACS by ACS-Community.
the class BeanNode method computeProperties.
/**
* Computes a descriptor for properties from a bean info.
* @param bean bean to create properties for
* @param info about the bean
* @param ignoreHiddenProperties true if hidden property should be ignored completely
* @param propertyInfo extra information of some properties (possibly null)
* @return three property lists
*/
private static Descriptor computeProperties(Object bean, BeanInfo info, boolean ignoreHiddenProperties, Boolean nodePropertiesCacheable, PropertyInfo[] propertyInfo) {
java.util.List property = null;
java.util.List expert = null;
java.util.List hidden = null;
PropertyDescriptor[] propertyDescriptor = info.getPropertyDescriptors();
int k = propertyDescriptor.length;
for (int i = 0; i < k; i++) {
if (propertyDescriptor[i].getPropertyType() == null)
continue;
String propName = propertyDescriptor[i].getName();
// we first update the PropertyDescriptor with the PropertyInfo
// that update may make non hidden a property that was hidden
PropertyInfo propInfo = findPropertyInfoByName(propertyInfo, propName);
if (propInfo != null)
propInfo.updatePropertyDescriptor(propertyDescriptor[i]);
// after the update we can test whether the property is hidden or not
if (ignoreHiddenProperties && propertyDescriptor[i].isHidden()) {
continue;
}
CachingStrategy strategy = createCachingStrategy(nodePropertiesCacheable, BeanTagger.isCacheable(propertyDescriptor[i]));
Node.Property prop;
if (propertyDescriptor[i] instanceof IndexedPropertyDescriptor) {
prop = createIndexedNodeProperty(bean, (IndexedPropertyDescriptor) propertyDescriptor[i], strategy);
} else {
prop = createNodeProperty(bean, propertyDescriptor[i], strategy);
}
if (prop == null)
continue;
if (propertyDescriptor[i].isHidden()) {
if (hidden == null)
hidden = new java.util.ArrayList();
hidden.add(prop);
} else if (propertyDescriptor[i].isExpert()) {
if (expert == null)
expert = new java.util.ArrayList();
expert.add(prop);
} else {
if (property == null)
property = new java.util.ArrayList();
property.add(prop);
}
}
// for
return new Descriptor(property, expert, hidden);
}
use of java.beans.PropertyDescriptor in project intellij-community by JetBrains.
the class Palette method getIntrospectedProperties.
/**
* @return arrays of all properties that can be introspected from the
* specified class. Only properties with getter and setter methods are
* returned.
*/
@NotNull
public IntrospectedProperty[] getIntrospectedProperties(@NotNull final Class aClass, @NotNull final Class delegeeClass) {
// TODO[vova, anton] update cache after class reloading (its properties could be hanged).
if (myClass2Properties.containsKey(aClass)) {
return myClass2Properties.get(aClass);
}
final ArrayList<IntrospectedProperty> result = new ArrayList<>();
try {
final BeanInfo beanInfo = Introspector.getBeanInfo(aClass);
final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (final PropertyDescriptor descriptor : descriptors) {
Method readMethod = descriptor.getReadMethod();
Method writeMethod = descriptor.getWriteMethod();
Class propertyType = descriptor.getPropertyType();
if (writeMethod == null || readMethod == null || propertyType == null) {
continue;
}
boolean storeAsClient = false;
try {
delegeeClass.getMethod(readMethod.getName(), readMethod.getParameterTypes());
delegeeClass.getMethod(writeMethod.getName(), writeMethod.getParameterTypes());
} catch (NoSuchMethodException e) {
storeAsClient = true;
}
@NonNls final String name = descriptor.getName();
final IntrospectedProperty property;
final Properties properties = (myProject == null) ? new Properties() : Properties.getInstance();
if (int.class.equals(propertyType)) {
// int
IntEnumEditor.Pair[] enumPairs = properties.getEnumPairs(aClass, name);
if (enumPairs != null) {
property = createIntEnumProperty(name, readMethod, writeMethod, enumPairs);
} else if (JLabel.class.isAssignableFrom(aClass)) {
// special handling for javax.swing.JLabel
if (JLabel.class.isAssignableFrom(aClass) && ("displayedMnemonic".equals(name) || "displayedMnemonicIndex".equals(name))) {
// skip JLabel#displayedMnemonic and JLabel#displayedMnemonicIndex
continue;
} else {
property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
}
} else if (AbstractButton.class.isAssignableFrom(aClass)) {
// special handling AbstractButton subclasses
if ("mnemonic".equals(name) || "displayedMnemonicIndex".equals(name)) {
// AbstractButton#mnemonic
continue;
} else {
property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
}
} else if (JTabbedPane.class.isAssignableFrom(aClass)) {
if (SwingProperties.SELECTED_INDEX.equals(name)) {
continue;
}
property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
} else {
property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
}
} else if (boolean.class.equals(propertyType)) {
// boolean
property = new IntroBooleanProperty(name, readMethod, writeMethod, storeAsClient);
} else if (double.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Double.class);
} else if (float.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Float.class);
} else if (long.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Long.class);
} else if (byte.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Byte.class);
} else if (short.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Short.class);
} else if (char.class.equals(propertyType)) {
// java.lang.String
property = new IntroCharProperty(name, readMethod, writeMethod, storeAsClient);
} else if (String.class.equals(propertyType)) {
// java.lang.String
property = new IntroStringProperty(name, readMethod, writeMethod, myProject, storeAsClient);
} else if (Insets.class.equals(propertyType)) {
// java.awt.Insets
property = new IntroInsetsProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Dimension.class.equals(propertyType)) {
// java.awt.Dimension
property = new IntroDimensionProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Rectangle.class.equals(propertyType)) {
// java.awt.Rectangle
property = new IntroRectangleProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Component.class.isAssignableFrom(propertyType)) {
if (JSplitPane.class.isAssignableFrom(aClass) && (name.equals("leftComponent") || name.equals("rightComponent") || name.equals("topComponent") || name.equals("bottomComponent"))) {
// these properties are set through layout
continue;
}
if (JTabbedPane.class.isAssignableFrom(aClass) && name.equals(SwingProperties.SELECTED_COMPONENT)) {
// can't set selectedComponent because of set property / add child sequence
continue;
}
if (JMenuBar.class.isAssignableFrom(propertyType) || JPopupMenu.class.isAssignableFrom(propertyType)) {
// no menu editing yet
continue;
}
Condition<RadComponent> filter = null;
if (name.equals(SwingProperties.LABEL_FOR)) {
filter = t -> {
ComponentItem item = getItem(t.getComponentClassName());
return item != null && item.isCanAttachLabel();
};
}
property = new IntroComponentProperty(name, readMethod, writeMethod, propertyType, filter, storeAsClient);
} else if (Color.class.equals(propertyType)) {
property = new IntroColorProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Font.class.equals(propertyType)) {
property = new IntroFontProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Icon.class.equals(propertyType)) {
property = new IntroIconProperty(name, readMethod, writeMethod, storeAsClient);
} else if (ListModel.class.isAssignableFrom(propertyType)) {
property = new IntroListModelProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Enum.class.isAssignableFrom(propertyType)) {
property = new IntroEnumProperty(name, readMethod, writeMethod, storeAsClient, propertyType);
} else {
// other types are not supported (yet?)
continue;
}
result.add(property);
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
final IntrospectedProperty[] properties = result.toArray(new IntrospectedProperty[result.size()]);
myClass2Properties.put(aClass, properties);
return properties;
}
use of java.beans.PropertyDescriptor in project kotlin by JetBrains.
the class Args method usage.
/**
* Generate usage information based on the target annotations.
*
* @param errStream A {@link java.io.PrintStream} to print the usage information to.
* @param target An instance or class.
*/
public static void usage(PrintStream errStream, Object target) {
Class<?> clazz;
if (target instanceof Class) {
clazz = (Class) target;
} else {
clazz = target.getClass();
}
errStream.println("Usage: " + clazz.getName());
for (Class<?> currentClazz = clazz; currentClazz != null; currentClazz = currentClazz.getSuperclass()) {
for (Field field : currentClazz.getDeclaredFields()) {
fieldUsage(errStream, target, field);
}
}
try {
BeanInfo info = Introspector.getBeanInfo(clazz);
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
propertyUsage(errStream, target, pd);
}
} catch (IntrospectionException e) {
// If its not a JavaBean we ignore it
}
}
use of java.beans.PropertyDescriptor in project ACS by ACS-Community.
the class TableHolderImpl method calcPropertyDescriptorsFor.
/**
* a helper method that determines the types of the properties by looking them up in the beanClass
* @deprecated -- not needed anymore, use setTableColumns(Object bean, String[] propNames)
*/
public static PropertyDescriptor[] calcPropertyDescriptorsFor(Class beanClass, String[] propNames) throws IntrospectionException {
// [PENDING] we should not depend on BeanInfo here. Otheriwse NullPointerEx If someon wants to expose a column that is not declared inthe BI.
// TODO BUG: Introspector does not find the DisplayName of the properties, that's why it's missing in the Table headers
PropertyDescriptor[] propDescr = Introspector.getBeanInfo(beanClass).getPropertyDescriptors();
java.util.ArrayList listNonHidden = new java.util.ArrayList(propDescr.length);
for (int i = 0; i < propDescr.length; i++) {
if (!propDescr[i].isHidden()) {
listNonHidden.add(propDescr[i]);
}
}
propDescr = (PropertyDescriptor[]) listNonHidden.toArray(new PropertyDescriptor[listNonHidden.size()]);
if (propNames == null) {
return propDescr;
}
if (propNames.length > propDescr.length) {
System.err.println("Error: more propNames than beanClass properties!");
System.err.println("PropNames = ");
ArrayUtil.printArray(propNames, 8);
System.err.println("PropDescr = ");
ArrayUtil.printArray(propDescr, 8);
return null;
}
//PropertyDescriptor[] resultDescr = new PropertyDescriptor[propNames.length];
// find common ones:
ArrayList resultList = new ArrayList();
for (int ix = 0; ix < propNames.length; ix++) {
for (int jx = 0; jx < propDescr.length; jx++) {
if (propNames[ix].equals(propDescr[jx].getName())) {
resultList.add(propDescr[jx]);
}
}
}
return (PropertyDescriptor[]) resultList.toArray(new PropertyDescriptor[resultList.size()]);
}
Aggregations