1 /*
2 * *************************************************************************************************************************************************************
3 *
4 * TheseFoolishThings: Miscellaneous utilities
5 * http://tidalwave.it/projects/thesefoolishthings
6 *
7 * Copyright (C) 2009 - 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/thesefoolishthings-src
22 * git clone https://github.com/tidalwave-it/thesefoolishthings-src
23 *
24 * *************************************************************************************************************************************************************
25 */
26 package it.tidalwave.role.ui;
27
28 import javax.annotation.Nonnull;
29 import java.util.Collection;
30 import java.util.Collections;
31 import it.tidalwave.util.Parameters;
32 import it.tidalwave.role.ui.impl.DefaultPresentable;
33 import static it.tidalwave.util.Parameters.r;
34
35 /***************************************************************************************************************************************************************
36 *
37 * The role of an object that can be presented on a UI, thus is capable of creating a {@link PresentationModel}.
38 *
39 * @stereotype Role
40 *
41 * @author Fabrizio Giudici
42 *
43 **************************************************************************************************************************************************************/
44 @FunctionalInterface
45 public interface Presentable
46 {
47 public static final Class<Presentable> _Presentable_ = Presentable.class;
48
49 /***********************************************************************************************************************************************************
50 * Creates a {@link PresentationModel}.
51 *
52 * @return the {@code PresentationModel}
53 * @since 3.2-ALPHA-3 (refactored)
54 **********************************************************************************************************************************************************/
55 public default PresentationModel createPresentationModel()
56 {
57 return createPresentationModel(Collections.emptyList());
58 }
59
60 /***********************************************************************************************************************************************************
61 * Creates a {@link PresentationModel} with some roles.
62 *
63 * @param instanceRoles the roles
64 * @return the {@code PresentationModel}
65 * @since 3.2-ALPHA-3 (refactored)
66 **********************************************************************************************************************************************************/
67 @Nonnull
68 public PresentationModel createPresentationModel (@Nonnull Collection<Object> instanceRoles);
69
70 /***********************************************************************************************************************************************************
71 * Creates a {@link PresentationModel} with a single role.
72 *
73 * @param instanceRole the role
74 * @return the {@code PresentationModel}
75 * @since 3.2-ALPHA-3
76 **********************************************************************************************************************************************************/
77 @Nonnull
78 public default PresentationModel createPresentationModel (@Nonnull final Object instanceRole)
79 {
80 Parameters.mustNotBeArrayOrCollection(instanceRole, "instanceRole");
81 return createPresentationModel(r(instanceRole));
82 }
83
84 /***********************************************************************************************************************************************************
85 * Creates a default {@link Presentable} for the given object.
86 *
87 * @param owner the object
88 * @return the new instance
89 * @since 3.2-ALPHA-2
90 **********************************************************************************************************************************************************/
91 @Nonnull
92 public static Presentable of (@Nonnull final Object owner)
93 {
94 return new DefaultPresentable(owner);
95 }
96 }