in kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/MetadataIntrospector.java [181:307]
private PropertyMetadata makePropertyMetadata(PropertyName name,
PropertyDescriptor propertyDescriptor, Object sample) {
PropertyMetadata result;
if (propertyDescriptor.getPropertyType() == null) {
result = null;
} else if (propertyDescriptor.getReadMethod() == null) {
result = null;
} else {
final Class<?> propertyType = canonizeClass(propertyDescriptor.getPropertyType());
final boolean readWrite = propertyDescriptor.getWriteMethod() != null;
final InspectorPath inspectorPath
= new InspectorPath(CUSTOM_SECTION, CUSTOM_SUB_SECTION, counter++);
if (propertyType.isArray()) {
result = null;
} else if (propertyType.isEnum()) {
final Object fallback = propertyType.getEnumConstants()[0];
result = new EnumerationPropertyMetadata(
name,
propertyType,
readWrite,
(Enum<?>)getDefaultValue(sample, propertyDescriptor.getReadMethod(), fallback),
inspectorPath);
} else if (propertyType == Boolean.class) {
result = new BooleanPropertyMetadata(
name,
readWrite,
(Boolean)getDefaultValue(sample, propertyDescriptor.getReadMethod(), false),
inspectorPath);
} else if (propertyType == Integer.class) {
result = new IntegerPropertyMetadata(
name,
readWrite,
(Integer)getDefaultValue(sample, propertyDescriptor.getReadMethod(), 0),
inspectorPath);
} else if (propertyType == Double.class) {
result = new DoublePropertyMetadata(
name,
DoubleKind.COORDINATE,
readWrite,
(Double)getDefaultValue(sample, propertyDescriptor.getReadMethod(), 0.0),
inspectorPath);
} else if (propertyType == String.class) {
result = new StringPropertyMetadata(
name,
readWrite,
(String)getDefaultValue(sample, propertyDescriptor.getReadMethod(), null),
inspectorPath);
} else if (propertyType == javafx.scene.paint.Color.class) {
result = new ColorPropertyMetadata(
name,
readWrite,
(Color)getDefaultValue(sample, propertyDescriptor.getReadMethod(), null),
inspectorPath);
} else if (propertyType == javafx.scene.paint.Paint.class) {
result = new PaintPropertyMetadata(
name,
readWrite,
(Paint) getDefaultValue(sample, propertyDescriptor.getReadMethod(), null),
inspectorPath);
} else if (propertyType == javafx.scene.text.Font.class) {
result = new FontPropertyMetadata(
name,
readWrite,
(Font) getDefaultValue(sample, propertyDescriptor.getReadMethod(), null),
inspectorPath);
} else if (propertyType == javafx.scene.image.Image.class) {
result = new ImagePropertyMetadata(
name,
readWrite,
null,
inspectorPath);
} else if (propertyType == javafx.util.Duration.class) {
Duration defaultValue = (Duration)getDefaultValue(sample, propertyDescriptor.getReadMethod(), null);
result = new DurationPropertyMetadata(
name,
readWrite,
defaultValue == null? null : new SBDuration(defaultValue),
inspectorPath);
} else if (propertyType == javafx.event.EventHandler.class) {
result = new EventHandlerPropertyMetadata(
name,
readWrite,
null,
inspectorPath);
// The following doesn't work because FXMLLoader is only prepared to load 'function' types
// of type EventHandler
//
// } else if (propertyType == java.util.function.Function.class) {
// result = new FunctionalInterfacePropertyMetadata(
// name,
// readWrite,
// null,
// inspectorPath, FUNCTION);
} else if (propertyType == javafx.collections.ObservableList.class) {
String propertyName = name.getName();
String methodName = "get" + propertyName.substring(0, 1).toUpperCase(Locale.ROOT) + propertyName.substring(1);
result = null;
try {
Method method = sample.getClass().getMethod(methodName);
Type type = method.getGenericReturnType();
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
Type genericType = parameterizedType.getActualTypeArguments()[0];
if (genericType instanceof Class) {
Class genericClass = (Class) parameterizedType.getActualTypeArguments()[0];
if (genericClass.equals(java.lang.String.class)) {
result = new StringListPropertyMetadata(
name,
readWrite,
Collections.emptyList(),
inspectorPath);
}
}
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
} else {
result = null;
}
}
return result;
}