Presentable.java

  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. import javax.annotation.Nonnull;
  28. import java.util.Collection;
  29. import java.util.Collections;
  30. import it.tidalwave.util.Parameters;
  31. import it.tidalwave.role.ui.impl.DefaultPresentable;
  32. import static it.tidalwave.util.Parameters.r;

  33. /***************************************************************************************************************************************************************
  34.  *
  35.  * The role of an object that can be presented on a UI, thus is capable of creating a {@link PresentationModel}.
  36.  *
  37.  * @stereotype Role
  38.  *
  39.  * @author  Fabrizio Giudici
  40.  *
  41.  **************************************************************************************************************************************************************/
  42. @FunctionalInterface
  43. public interface Presentable
  44.   {
  45.     public static final Class<Presentable> _Presentable_ = Presentable.class;

  46.     /***********************************************************************************************************************************************************
  47.      * Creates a {@link PresentationModel}.
  48.      *
  49.      * @return                  the {@code PresentationModel}
  50.      * @since                   3.2-ALPHA-3 (refactored)
  51.      **********************************************************************************************************************************************************/
  52.     public default PresentationModel createPresentationModel()
  53.       {
  54.         return createPresentationModel(Collections.emptyList());
  55.       }

  56.     /***********************************************************************************************************************************************************
  57.      * Creates a {@link PresentationModel} with some roles.
  58.      *
  59.      * @param  instanceRoles    the roles
  60.      * @return                  the {@code PresentationModel}
  61.      * @since                   3.2-ALPHA-3 (refactored)
  62.      **********************************************************************************************************************************************************/
  63.     @Nonnull
  64.     public PresentationModel createPresentationModel (@Nonnull Collection<Object> instanceRoles);

  65.     /***********************************************************************************************************************************************************
  66.      * Creates a {@link PresentationModel} with a single role.
  67.      *
  68.      * @param  instanceRole     the role
  69.      * @return                  the {@code PresentationModel}
  70.      * @since                   3.2-ALPHA-3
  71.      **********************************************************************************************************************************************************/
  72.     @Nonnull
  73.     public default PresentationModel createPresentationModel (@Nonnull final Object instanceRole)
  74.       {
  75.         Parameters.mustNotBeArrayOrCollection(instanceRole, "instanceRole");
  76.         return createPresentationModel(r(instanceRole));
  77.       }

  78.     /***********************************************************************************************************************************************************
  79.      * Creates a default {@link Presentable} for the given object.
  80.      *
  81.      * @param   owner           the object
  82.      * @return                  the new instance
  83.      * @since                   3.2-ALPHA-2
  84.      **********************************************************************************************************************************************************/
  85.     @Nonnull
  86.     public static Presentable of (@Nonnull final Object owner)
  87.       {
  88.         return new DefaultPresentable(owner);
  89.       }
  90.   }