Skip to content

Package: DefaultUserAction

DefaultUserAction

nameinstructionbranchcomplexitylinemethod
DefaultUserAction(Callback, Collection)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
actionPerformed()
M: 5 C: 5
50%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 3
60%
M: 0 C: 1
100%
lambda$toString$0(Displayable)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
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%
toString()
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
withRoles(Collection)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 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 - 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.core.role.impl;
27:
28: import jakarta.annotation.Nonnull;
29: import java.util.Collection;
30: import it.tidalwave.util.As;
31: import it.tidalwave.util.Callback;
32: import it.tidalwave.ui.core.BoundProperty;
33: import it.tidalwave.ui.core.role.UserAction;
34: import lombok.Getter;
35: import lombok.RequiredArgsConstructor;
36: import lombok.experimental.Accessors;
37: import lombok.experimental.Delegate;
38: import lombok.extern.slf4j.Slf4j;
39: import static it.tidalwave.ui.core.role.Displayable._Displayable_;
40:
41: /***************************************************************************************************************************************************************
42: *
43: * @author Fabrizio Giudici
44: *
45: **************************************************************************************************************************************************************/
46: @RequiredArgsConstructor(staticName = "withCallback") @Slf4j @SuppressWarnings("this-escape")
47: public class DefaultUserAction implements UserAction
48: {
49: @Getter @Accessors(fluent = true)
50: private final BoundProperty<Boolean> enabled = new BoundProperty<>(true);
51:
52: @Delegate @Nonnull
53: private final As as;
54:
55: @Nonnull
56: private final Callback callback;
57:
58: /***********************************************************************************************************************************************************
59: * @since 3.2-ALPHA-1 (was previously in {@code UserAction8}
60: * @since 3.2-ALPHA-3 (refactored)
61: **********************************************************************************************************************************************************/
62: public DefaultUserAction (@Nonnull final Callback callback, @Nonnull final Collection<Object> roles)
63: {
64: this.callback = callback;
65: this.as = As.forObject(this, roles);
66: }
67:
68: /***********************************************************************************************************************************************************
69: * @since 3.2-ALPHA-1 (was previously in {@code UserAction8}
70: * @since 3.2-ALPHA-3 (refactored)
71: **********************************************************************************************************************************************************/
72: @Nonnull
73: public DefaultUserAction withRoles (@Nonnull final Collection<Object> roles)
74: {
75: return new DefaultUserAction(callback, roles);
76: }
77:
78: @Override
79: public void actionPerformed() // FIXME: change with composition
80: {
81: try
82: {
83: callback.call();
84: }
85: catch (Throwable e)
86: {
87: log.error("", e);
88: }
89: }
90:
91: /***********************************************************************************************************************************************************
92: * {@inheritDoc}
93: **********************************************************************************************************************************************************/
94: @Override @Nonnull
95: public String toString ()
96: {
97: final var id = "@" + Integer.toHexString(System.identityHashCode(this));
98: var details = id;
99:
100: try
101: {
102: details = this.maybeAs(_Displayable_)
103: .map(d -> String.format("[\"%s\"]", d.getDisplayName()))
104: .orElse(id);
105: }
106: catch (RuntimeException e)
107: {
108: details += ",broken";
109: log.error("In DefaultDisplayable.toString()", e);
110: }
111:
112: return String.format("DefaultUserAction%s", details);
113: }
114: }