Presentable.java

  1. /*
  2.  * *********************************************************************************************************************
  3.  *
  4.  * TheseFoolishThings: Miscellaneous utilities
  5.  * http://tidalwave.it/projects/thesefoolishthings
  6.  *
  7.  * Copyright (C) 2009 - 2023 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
  12.  * the License. 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
  17.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations under the License.
  19.  *
  20.  * *********************************************************************************************************************
  21.  *
  22.  * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
  23.  * git clone https://github.com/tidalwave-it/thesefoolishthings-src
  24.  *
  25.  * *********************************************************************************************************************
  26.  */
  27. package it.tidalwave.role.ui;

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

  47.     /*******************************************************************************************************************
  48.      *
  49.      * Creates a {@link PresentationModel}.
  50.      *
  51.      * @return                  the {@code PresentationModel}
  52.      * @since                   3.2-ALPHA-3 (refactored)
  53.      *
  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.      ******************************************************************************************************************/
  68.     @Nonnull
  69.     public PresentationModel createPresentationModel (@Nonnull Collection<Object> instanceRoles);

  70.     /*******************************************************************************************************************
  71.      *
  72.      * Creates a {@link PresentationModel} with a single role.
  73.      *
  74.      * @param  instanceRole     the role
  75.      * @return                  the {@code PresentationModel}
  76.      * @since                   3.2-ALPHA-3
  77.      *
  78.      ******************************************************************************************************************/
  79.     @Nonnull
  80.     public default PresentationModel createPresentationModel (@Nonnull final Object instanceRole)
  81.       {
  82.         Parameters.mustNotBeArrayOrCollection(instanceRole, "instanceRole");
  83.         return createPresentationModel(r(instanceRole));
  84.       }

  85.     /*******************************************************************************************************************
  86.      *
  87.      * Creates a default {@link Presentable} for the given object.
  88.      *
  89.      * @param   owner           the object
  90.      * @return                  the new instance
  91.      * @since                   3.2-ALPHA-2
  92.      *
  93.      ******************************************************************************************************************/
  94.     @Nonnull
  95.     public static Presentable of (@Nonnull final Object owner)
  96.       {
  97.         return new DefaultPresentable(owner);
  98.       }
  99.   }