Package: JavaFXWorker
JavaFXWorker
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
childrenPm(PresentationModel) |
|
|
|
|
|
||||||||||||||||||||
childrenPm(PresentationModel, int) |
|
|
|
|
|
||||||||||||||||||||
extractBadItems(List) |
|
|
|
|
|
||||||||||||||||||||
lambda$childrenPm$2(String, Optional, SimpleComposite) |
|
|
|
|
|
||||||||||||||||||||
lambda$childrenPm$3(SimpleComposite) |
|
|
|
|
|
||||||||||||||||||||
lambda$childrenPm$4(Object) |
|
|
|
|
|
||||||||||||||||||||
lambda$extractBadItems$5(Object) |
|
|
|
|
|
||||||||||||||||||||
lambda$run$0(Consumer, Object) |
|
|
|
|
|
||||||||||||||||||||
lambda$run$1(Supplier, Consumer) |
|
|
|
|
|
||||||||||||||||||||
run(Executor, Supplier, Consumer) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * SteelBlue: DCI User Interfaces
5: * http://tidalwave.it/projects/steelblue
6: *
7: * Copyright (C) 2015 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/steelblue-src
22: * git clone https://github.com/tidalwave-it/steelblue-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.ui.javafx.impl.common;
27:
28: import javax.annotation.Nonnegative;
29: import jakarta.annotation.Nonnull;
30: import java.util.ArrayList;
31: import java.util.List;
32: import java.util.concurrent.Executor;
33: import java.util.concurrent.RejectedExecutionException;
34: import java.util.function.Consumer;
35: import java.util.function.Supplier;
36: import javafx.collections.ObservableList;
37: import javafx.application.Platform;
38: import it.tidalwave.util.As;
39: import it.tidalwave.util.annotation.VisibleForTesting;
40: import it.tidalwave.ui.core.role.PresentationModel;
41: import it.tidalwave.ui.javafx.impl.util.Logging;
42: import it.tidalwave.role.Composite;
43: import it.tidalwave.role.SimpleComposite;
44: import lombok.experimental.UtilityClass;
45: import lombok.extern.slf4j.Slf4j;
46: import static java.util.Collections.emptyList;
47: import static javafx.collections.FXCollections.*;
48: import static it.tidalwave.ui.javafx.impl.util.Logging.INDENT;
49:
50: /***************************************************************************************************************************************************************
51: *
52: * @author Fabrizio Giudici
53: *
54: **************************************************************************************************************************************************************/
55: @UtilityClass @Slf4j
56: public class JavaFXWorker
57: {
58: private static final As.Type<SimpleComposite<PresentationModel>> _PresentationModel_Composite_ = As.type(Composite.class);
59:
60: public static <T> void run (@Nonnull final Executor executor, @Nonnull final Supplier<T> backgroundSupplier, @Nonnull final Consumer<T> javaFxFinalizer)
61: {
62: try
63: {
64: executor.execute(() ->
65: {
66: final var value = backgroundSupplier.get();
67: Platform.runLater(() -> javaFxFinalizer.accept(value));
68: log.trace("JavaFX finalizer submitted");
69: });
70: }
71: catch (RejectedExecutionException e)
72: {
73: log.error("Background task failed: {}", e.getMessage());
74: }
75: }
76:
77: @Nonnull
78: public static ObservableList<PresentationModel> childrenPm (@Nonnull final PresentationModel pm)
79: {
80: return childrenPm(pm, 0);
81: }
82:
83: @Nonnull
84: public static ObservableList<PresentationModel> childrenPm (@Nonnull final PresentationModel pm, @Nonnegative final int depth)
85: {
86: final var indent = INDENT.substring(0, depth * 8);
87: final var composite = pm.maybeAs(_PresentationModel_Composite_);
88: composite.ifPresent(c -> Logging.logObject(indent, composite));
89: final var items = composite.map(c -> c.findChildren().results()).orElse(emptyList());
90: final var badItems = extractBadItems(items);
91:
92:• if (!badItems.isEmpty()) // defensive
93: {
94: log.error("Child object are not PresentationModel: (only 10 are shown)");
95: log.error("This happens when the PresentationModel doesn't have its own Composite role that decorates the" +
96: " owner entity Composite - see SimpleCompositePresentable for instance.");
97: badItems.stream().limit(10).forEach(item -> log.error(" {}", item));
98: return emptyObservableList();
99: }
100:
101: Logging.logObjects(indent, items);
102: return observableArrayList(items);
103: }
104:
105: @Nonnull
106: @VisibleForTesting static List<Object> extractBadItems (@Nonnull final List<PresentationModel> items)
107: {
108: final List<Object> badItems = new ArrayList<>(items);
109: badItems.removeIf(item -> item instanceof PresentationModel);
110: return badItems;
111: // return items.stream()
112: // .map(item -> (Object)item)
113: // .filter(item -> !(item instanceof PresentationModel))
114: // .peek(item -> log.error(">>>> {}", item))
115: // .collect(toList());
116: }
117: }
118: