Created
November 15, 2015 01:45
-
-
Save Groostav/7a2bf1ca876cbd7c54c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void hackPropertiesInViaReflection(javafx.fxml.FXMLLoader fxmlLoader, FXController propertySource) { | |
Map<String, Object> namespace = ExceptionUtilities.<Map<String, Object>>tryGetAndLogOnException( | |
log, | |
"get field 'namespace' on javafx.fxml.FXMLLoader reflectively", | |
() -> getFieldValue(fxmlLoader, "namespace") | |
).orElse(new HashMap<>()); | |
Queryable<Field> propertyFieldsOnController = from(propertySource.getClass().getDeclaredFields()) | |
.where(field -> Property.class.isAssignableFrom(field.getType())) | |
// if not for type erasure, this could be ofType(Field<Property>.class) | |
// --which gives me back something that would've stopped me from casting an optional incorrectly! | |
.select(field -> { | |
field.setAccessible(true); | |
return field; | |
}) | |
.immediately(/*for debugger*/); | |
Queryable<Property> javafxPropsOnController = propertyFieldsOnController | |
.select(field -> getFieldValueAsProperty(field, propertySource)) | |
.where(Optional::isPresent) | |
.select(Optional::get) | |
.cast(Property.class) | |
.immediately(/*for debugger*/); | |
javafxPropsOnController = javafxPropsOnController | |
.where(prop -> prop.getName() != null && ! prop.getName().isEmpty()) | |
.where(prop -> prop.getBean() == propertySource) | |
.immediately(/*for debugger*/); | |
for(Property property : javafxPropsOnController){ | |
namespace.put(property.getName(), property.getValue()); | |
ChangeListener listener = (observable, oldValue, newValue) -> namespace.put(property.getName(), newValue); | |
doWeakUntypedListenerAdd(property, listener); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment