Skip to content

Package: ChangeListenerSelectableAdapter

ChangeListenerSelectableAdapter

nameinstructionbranchcomplexitylinemethod
asTreeItemChangeListener()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
changed(ObservableValue, PresentationModel, PresentationModel)
M: 0 C: 8
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$changed$1(PresentationModel)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$new$0(ObservableValue, TreeItem, TreeItem)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
safe(TreeItem)
M: 1 C: 7
88%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * SteelBlue: DCI User Interfaces
5: * http://tidalwave.it/projects/steelblue
6: *
7: * Copyright (C) 2015 - 2024 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.role.ui.javafx.impl.common;
27:
28: import javax.annotation.CheckForNull;
29: import javax.annotation.Nonnull;
30: import javax.annotation.Nullable;
31: import java.util.concurrent.Executor;
32: import javafx.beans.value.ChangeListener;
33: import javafx.beans.value.ObservableValue;
34: import javafx.scene.control.TreeItem;
35: import it.tidalwave.role.ui.PresentationModel;
36: import it.tidalwave.role.ui.Selectable;
37: import lombok.RequiredArgsConstructor;
38: import lombok.extern.slf4j.Slf4j;
39: import static it.tidalwave.role.ui.Selectable._Selectable_;
40:
41: /***************************************************************************************************************************************************************
42: *
43: * @author Fabrizio Giudici
44: *
45: **************************************************************************************************************************************************************/
46: @RequiredArgsConstructor @Slf4j
47: public class ChangeListenerSelectableAdapter implements ChangeListener<PresentationModel>
48: {
49: @Nonnull
50: protected final Executor executor;
51:
52: private final ChangeListener<TreeItem<PresentationModel>> treeItemChangeListener =
53: // FIXME: test null oldValue, newValue?
54: (observable, oldValue, newValue) -> changed(null, safe(oldValue), safe(newValue));
55:
56: @Override
57: public void changed (@Nonnull final ObservableValue<? extends PresentationModel> ov,
58: @Nonnull final PresentationModel oldPm,
59: @CheckForNull final PresentationModel newPm)
60: {
61:• if (newPm != null) // no selection
62: {
63: executor.execute(() -> newPm.maybeAs(_Selectable_).ifPresent(Selectable::select));
64: }
65: }
66:
67: @Nonnull
68: public ChangeListener<TreeItem<PresentationModel>> asTreeItemChangeListener()
69: {
70: return treeItemChangeListener;
71: }
72:
73: @Nullable
74: private static PresentationModel safe (@Nullable final TreeItem<PresentationModel> value)
75: {
76:• return (value != null) ? value.getValue() : null;
77: }
78: }