Skip to content

Package: PresentationModel

PresentationModel

nameinstructionbranchcomplexitylinemethod
empty()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isVerboseToString()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$ofMaybePresentable$0(Collection, Presentable)
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%
lambda$ofMaybePresentable$1(As, Collection)
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%
of(Object)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
of(Object, Collection)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
of(Object, Object)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
ofMaybePresentable(As)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
ofMaybePresentable(As, Collection)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setVerboseToString(boolean)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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 - 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;
27:
28: import jakarta.annotation.Nonnull;
29: import java.util.Collection;
30: import java.util.Collections;
31: import it.tidalwave.ui.core.Mutable;
32: import it.tidalwave.ui.core.role.impl.DefaultPresentationModel;
33: import org.apiguardian.api.API;
34: import it.tidalwave.util.As;
35: import it.tidalwave.util.NamedCallback;
36: import it.tidalwave.util.Parameters;
37: import it.tidalwave.role.Aggregate;
38: import it.tidalwave.role.SimpleComposite;
39: import static it.tidalwave.ui.core.role.Presentable._Presentable_;
40: import static org.apiguardian.api.API.Status.EXPERIMENTAL;
41: import static it.tidalwave.util.Parameters.r;
42:
43: /***************************************************************************************************************************************************************
44: *
45: * TODO: As the NetBeans Node, it should allow children, have event listeners for children added/removed/changed.
46: * This class so becomes the true M in MVC.
47: *
48: * @stereotype Role
49: * @since 2.0-ALPHA-1
50: * @author Fabrizio Giudici
51: *
52: **************************************************************************************************************************************************************/
53: public interface PresentationModel extends As, Mutable
54: {
55: /** Shortcut for {@link it.tidalwave.util.As}. */
56: public static final Class<PresentationModel> _PresentationModel_ = PresentationModel.class;
57:
58: /** Shortcut for {@link it.tidalwave.util.As}. */
59: public static final As.Type<SimpleComposite<PresentationModel>> _CompositeOfPresentationModel_ = As.type(SimpleComposite.class);
60:
61: /** Shortcut for {@link it.tidalwave.util.As}. */
62: public static final As.Type<Aggregate<PresentationModel>> _AggregateOfPresentationModel_ = new As.Type<>(Aggregate.class);
63:
64: public static final String PROPERTY_CHILDREN = "children";
65:
66: /** This is an undocumented feature. If you add a {@link NamedCallback} with this name as a role in this object, it will be called back when
67: {@link #dispose()} is called. */
68: public static final String CALLBACK_DISPOSE = "dispose";
69:
70: public static final String P_VERBOSE_TOSTRING = PresentationModel.class.getCanonicalName() + ".verboseToString";
71:
72: public static final String PARAM_OWNER = "owner";
73: public static final String PARAM_ROLE = "role";
74:
75: /***********************************************************************************************************************************************************
76: * Disposes this object.
77: **********************************************************************************************************************************************************/
78: public void dispose();
79:
80: /***********************************************************************************************************************************************************
81: * {@return a new instance given an owner and no roles}.
82: * @param owner the owner
83: * @since 3.2-ALPHA-3
84: **********************************************************************************************************************************************************/
85: @Nonnull
86: public static PresentationModel of (@Nonnull final Object owner)
87: {
88: Parameters.mustNotBeArrayOrCollection(owner, PARAM_OWNER);
89: return of(owner, Collections.emptyList());
90: }
91:
92: /***********************************************************************************************************************************************************
93: * {@return a new instance given an owner and a single role}.
94: * @param owner the owner
95: * @param role the role (or a {@link it.tidalwave.util.RoleFactory})
96: * @since 3.2-ALPHA-3
97: **********************************************************************************************************************************************************/
98: @Nonnull
99: public static PresentationModel of (@Nonnull final Object owner, @Nonnull final Object role)
100: {
101: Parameters.mustNotBeArrayOrCollection(owner, PARAM_OWNER);
102: Parameters.mustNotBeArrayOrCollection(role, PARAM_ROLE);
103: return of(owner, r(role));
104: }
105:
106: /***********************************************************************************************************************************************************
107: * {@return a new instance given an owner and multiple roles}.
108: * @param owner the owner
109: * @param roles roles or {@link it.tidalwave.util.RoleFactory} instances
110: * @since 3.2-ALPHA-1
111: * @since 3.2-ALPHA-3 (refactored)
112: **********************************************************************************************************************************************************/
113: @Nonnull
114: public static PresentationModel of (@Nonnull final Object owner, @Nonnull final Collection<Object> roles)
115: {
116: Parameters.mustNotBeArrayOrCollection(owner, PARAM_OWNER);
117: return new DefaultPresentationModel(owner, roles);
118: }
119:
120: /***********************************************************************************************************************************************************
121: * {@return an empty instance (no roles, with the exception of a dummy {@link Displayable})}.
122: * @since 3.2-ALPHA-3
123: **********************************************************************************************************************************************************/
124: @Nonnull
125: public static PresentationModel empty()
126: {
127: // TODO: cache a singleton, but don't do eager initialization (e.g. a final static), as it would deadlock
128: return of("", Displayable.of("<empty presentation model>"));
129: }
130:
131: /***********************************************************************************************************************************************************
132: * {@return a new instance from an owner which might have the {@link Presentable} role}. If it is present, it is called to create the
133: * {@code PresentationModel}; otherwise a default one is created. Additional roles are added.
134: * @param owner the owner
135: * @param roles roles or {@link it.tidalwave.util.RoleFactory} instances
136: * @since 3.2-ALPHA-8
137: **********************************************************************************************************************************************************/
138: @API(status = EXPERIMENTAL) // TODO: perhaps it could be merged to of().
139: @Nonnull
140: public static PresentationModel ofMaybePresentable (@Nonnull final As owner, @Nonnull final Collection<Object> roles)
141: {
142: Parameters.mustNotBeArrayOrCollection(owner, PARAM_OWNER);
143: return owner.maybeAs(_Presentable_)
144: .map(p -> p.createPresentationModel(roles))
145: .orElseGet(() -> of(owner, roles));
146: }
147:
148: /***********************************************************************************************************************************************************
149: * {@return a new instance from an owner which might have the {@link Presentable} role}. If it is present, it is called to create the
150: * {@code PresentationModel}; otherwise a default one is created.
151: * @param owner the owner
152: * @since 3.2-ALPHA-8
153: **********************************************************************************************************************************************************/
154: @API(status = EXPERIMENTAL) // TODO: perhaps it could be merged to of().
155: @Nonnull
156: public static PresentationModel ofMaybePresentable (@Nonnull final As owner)
157: {
158: return ofMaybePresentable(owner, Collections.emptyList());
159: }
160:
161: /***********************************************************************************************************************************************************
162: * Sets the verbose mode for {@link java.lang.Object#toString} implementations of {@code PresentationModel}. Looking at the implementation of
163: * {@link javafx.scene.control.cell.DefaultTreeCell}, the code always calls {@code toString()} during an update, even though the text value is later
164: * overridden; hence, this method should be as fast as possible. By default, the shortened class name and system id of the owner object is returned;
165: * set verbosity to have the owner object {@code toString()} called instead.
166: * It is also possible to set system the property {@code it.tidalwave.ui.core.role.PresentationModel.verboseToString}.
167: * @param verbose the verbosity
168: * @since 2.0-ALPHA-4
169: * @see #isVerboseToString()
170: **********************************************************************************************************************************************************/
171: public static void setVerboseToString (final boolean verbose)
172: {
173: DefaultPresentationModel.setVerboseToString(verbose);
174: }
175:
176: /***********************************************************************************************************************************************************
177: * {@return the verbose mode for {@link java.lang.Object#toString} implementations of {@code PresentationModel}}.
178: * @since 2.0-ALPHA-4
179: * @see #setVerboseToString(boolean)
180: **********************************************************************************************************************************************************/
181: public static boolean isVerboseToString()
182: {
183: return DefaultPresentationModel.isVerboseToString();
184: }
185: }