Search in sources :

Example 1 with WithLayoutMetadata

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);
    });
}
Also used : Node(javafx.scene.Node) WithLayoutMetadata(com.canoo.dp.impl.platform.projector.base.WithLayoutMetadata)

Example 2 with WithLayoutMetadata

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));
}
Also used : HBox(javafx.scene.layout.HBox) ControllerProxy(com.canoo.platform.remoting.client.ControllerProxy) Node(javafx.scene.Node) MetadataUtilities(com.canoo.dp.impl.platform.projector.metadata.MetadataUtilities) StackPane(javafx.scene.layout.StackPane) View(com.canoo.dp.impl.platform.projector.view.View) ViewMetadata(com.canoo.dp.impl.platform.projector.view.ViewMetadata) ClientContext(com.canoo.platform.remoting.client.ClientContext) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Parent(javafx.scene.Parent) Priority(javafx.scene.layout.Priority) List(java.util.List) Insets(javafx.geometry.Insets) Optional(java.util.Optional) WithLayoutMetadata(com.canoo.dp.impl.platform.projector.base.WithLayoutMetadata) Pane(javafx.scene.layout.Pane) Insets(javafx.geometry.Insets) Priority(javafx.scene.layout.Priority)

Example 3 with WithLayoutMetadata

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());
        });
    };
}
Also used : List(java.util.List) DoubleKeyValueBean(com.canoo.dp.impl.platform.projector.metadata.concrete.DoubleKeyValueBean) Subscription(com.canoo.platform.core.functional.Subscription) Map(java.util.Map) BeanManager(com.canoo.platform.remoting.BeanManager) Optional(java.util.Optional) StringKeyValueBean(com.canoo.dp.impl.platform.projector.metadata.concrete.StringKeyValueBean) HashMap(java.util.HashMap) BooleanKeyValueBean(com.canoo.dp.impl.platform.projector.metadata.concrete.BooleanKeyValueBean) WithLayoutMetadata(com.canoo.dp.impl.platform.projector.base.WithLayoutMetadata) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) Subscription(com.canoo.platform.core.functional.Subscription)

Aggregations

WithLayoutMetadata (com.canoo.dp.impl.platform.projector.base.WithLayoutMetadata)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Node (javafx.scene.Node)2 MetadataUtilities (com.canoo.dp.impl.platform.projector.metadata.MetadataUtilities)1 BooleanKeyValueBean (com.canoo.dp.impl.platform.projector.metadata.concrete.BooleanKeyValueBean)1 DoubleKeyValueBean (com.canoo.dp.impl.platform.projector.metadata.concrete.DoubleKeyValueBean)1 StringKeyValueBean (com.canoo.dp.impl.platform.projector.metadata.concrete.StringKeyValueBean)1 View (com.canoo.dp.impl.platform.projector.view.View)1 ViewMetadata (com.canoo.dp.impl.platform.projector.view.ViewMetadata)1 Subscription (com.canoo.platform.core.functional.Subscription)1 BeanManager (com.canoo.platform.remoting.BeanManager)1 ClientContext (com.canoo.platform.remoting.client.ClientContext)1 ControllerProxy (com.canoo.platform.remoting.client.ControllerProxy)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Insets (javafx.geometry.Insets)1 Parent (javafx.scene.Parent)1 HBox (javafx.scene.layout.HBox)1