use of com.canoo.dp.impl.platform.projector.base.WithLayoutMetadata in project dolphin-platform by canoo.
the class ViewFactory method recreateContent.
private void recreateContent(Pane pane, View projectable, Projector projector, ControllerProxy controllerProxy) {
pane.getChildren().clear();
projectable.getContent().forEach(c -> {
Node content = projector.create(c, controllerProxy);
if (c instanceof WithLayoutMetadata) {
WithLayoutMetadata metadata = (WithLayoutMetadata) c;
MetadataUtilities.addListenerToMetadata(metadata, () -> updateContentByMetadata(metadata, content));
updateContentByMetadata(metadata, content);
}
pane.getChildren().add(content);
});
}
use of com.canoo.dp.impl.platform.projector.base.WithLayoutMetadata in project dolphin-platform by canoo.
the class ViewFactory method updateContentByMetadata.
private void updateContentByMetadata(WithLayoutMetadata bean, Node content) {
Priority priority = MetadataUtilities.getMetadata(ViewMetadata.JAVAFX_LAYOUT_CONTENT_GROW, bean).map(m -> Priority.valueOf(Optional.ofNullable(m.getValue()).orElse("").toString())).orElse(Priority.SOMETIMES);
HBox.setHgrow(content, priority);
VBox.setVgrow(content, priority);
double margin = MetadataUtilities.getMetadata(ViewMetadata.JAVAFX_LAYOUT_MARGIN, bean).map(m -> Double.parseDouble(Optional.ofNullable(m.getValue()).orElse("0.0").toString())).orElse(0.0);
HBox.setMargin(content, new Insets(margin));
VBox.setMargin(content, new Insets(margin));
}
use of com.canoo.dp.impl.platform.projector.base.WithLayoutMetadata in project dolphin-platform by canoo.
the class MetadataUtilities method addListenerToMetadata.
public static Subscription addListenerToMetadata(WithLayoutMetadata metadata, Runnable onChange) {
final Map<KeyValue, List<Subscription>> subscriptionMap = new HashMap<>();
Subscription mainSubscription = metadata.getLayoutMetadata().onChanged(e -> {
e.getChanges().forEach(c -> {
if (c.isRemoved()) {
c.getRemovedElements().forEach(m -> {
List<Subscription> subscriptions = subscriptionMap.computeIfAbsent(m, key -> new ArrayList<>());
subscriptions.forEach(s -> s.unsubscribe());
subscriptions.clear();
});
}
if (c.isAdded()) {
metadata.getLayoutMetadata().subList(c.getFrom(), c.getTo()).forEach(m -> {
List<Subscription> subscriptions = subscriptionMap.computeIfAbsent(m, key -> new ArrayList<>());
subscriptions.add(m.keyProperty().onChanged(event -> onChange.run()));
subscriptions.add(m.valueProperty().onChanged(event -> onChange.run()));
});
}
});
});
metadata.getLayoutMetadata().forEach(m -> {
List<Subscription> subscriptions = subscriptionMap.computeIfAbsent(m, key -> new ArrayList<>());
subscriptions.add(m.keyProperty().onChanged(event -> onChange.run()));
subscriptions.add(m.valueProperty().onChanged(event -> onChange.run()));
});
return () -> {
mainSubscription.unsubscribe();
subscriptionMap.forEach((k, v) -> {
v.forEach(s -> s.unsubscribe());
});
};
}
Aggregations