Skip to content

Package: ToolBarModelSupport

ToolBarModelSupport

nameinstructionbranchcomplexitylinemethod
ToolBarModelSupport()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
lambda$new$0()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
populate(Object, Object)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

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.spi;
27:
28: import javax.annotation.Nonnull;
29: import java.util.Collection;
30: import java.util.function.Supplier;
31: import it.tidalwave.util.As;
32: import it.tidalwave.role.ui.ToolBarModel;
33: import it.tidalwave.role.ui.UserAction;
34: import it.tidalwave.role.ui.UserActionProvider;
35: import lombok.AccessLevel;
36: import lombok.RequiredArgsConstructor;
37: import lombok.experimental.Delegate;
38: import static java.util.Collections.emptyList;
39: import static it.tidalwave.role.ui.UserActionProvider._UserActionProvider_;
40:
41: /***************************************************************************************************************************************************************
42: *
43: * A support implementation for {@link ToolBarModel}.
44: *
45: * @param <B> the concrete type of the binder
46: * @param <T> the concrete type of the toolbar
47: * @since 1.1-ALPHA-6
48: * @author Fabrizio Giudici
49: *
50: **************************************************************************************************************************************************************/
51: @RequiredArgsConstructor(access = AccessLevel.PROTECTED)
52: public abstract class ToolBarModelSupport<B, T> implements ToolBarModel
53: {
54: @Delegate
55: private final As as = As.forObject(this);
56:
57: /** The default supplier of {@link UserAction}s, can be injected for testing. */
58: @Nonnull
59: protected final Supplier<Collection<? extends UserAction>> userActionsSupplier;
60:
61: /***********************************************************************************************************************************************************
62: * Default constructor.
63: **********************************************************************************************************************************************************/
64: protected ToolBarModelSupport()
65: {
66: userActionsSupplier = () -> maybeAs(_UserActionProvider_).map(UserActionProvider::getActions).orElse(emptyList());
67: }
68:
69: /***********************************************************************************************************************************************************
70: * {@inheritDoc}
71: **********************************************************************************************************************************************************/
72: @SuppressWarnings("unchecked")
73: public final void populate (@Nonnull final Object binder, @Nonnull final Object toolBar)
74: {
75: populateImpl((B)binder, (T)toolBar);
76: }
77:
78: /***********************************************************************************************************************************************************
79: * Populates the menu bar with menus.
80: * @param binder the binder
81: * @param toolBar the toolbar
82: **********************************************************************************************************************************************************/
83: protected abstract void populateImpl (@Nonnull B binder, @Nonnull T toolBar);
84: }