UserAction.java

  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. import jakarta.annotation.Nonnull;
  28. import java.util.Collection;
  29. import java.util.Collections;
  30. import java.util.List;
  31. import it.tidalwave.util.As;
  32. import it.tidalwave.util.Callback;
  33. import it.tidalwave.util.Parameters;
  34. import it.tidalwave.ui.core.BoundProperty;
  35. import it.tidalwave.ui.core.role.impl.DefaultUserAction;
  36. // import javafx.beans.property.BooleanProperty;

  37. /***************************************************************************************************************************************************************
  38.  *
  39.  * @since   2.0-ALPHA-1
  40.  * @author  Fabrizio Giudici
  41.  *
  42.  **************************************************************************************************************************************************************/
  43. public interface UserAction extends As
  44.   {
  45.     public static final Class<UserAction> _UserAction_ = UserAction.class;

  46.     /***********************************************************************************************************************************************************
  47.      *
  48.      **********************************************************************************************************************************************************/
  49.     public void actionPerformed();

  50.     /***********************************************************************************************************************************************************
  51.      * Returns the property describing the enabled status of this action.
  52.      *
  53.      * @return      the enabled property
  54.      **********************************************************************************************************************************************************/
  55.     @Nonnull
  56.     public BoundProperty<Boolean> enabled(); // TODO: rename to enabledProperty()

  57.     /***********************************************************************************************************************************************************
  58.      * Creates a new instance out of a callback and a collection of roles.
  59.      *
  60.      * @param   callback    the callback
  61.      * @param   roles       the roles (or role factories)
  62.      * @return              the new instance
  63.      * @since               3.2-ALPHA-1 (replaces {@code new UserActionSupport()}
  64.      * @since               3.2-ALPHA-3 (refactored)
  65.      **********************************************************************************************************************************************************/
  66.     @Nonnull
  67.     public static UserAction of (@Nonnull final Callback callback, @Nonnull final Collection<Object> roles)
  68.       {
  69.         return new DefaultUserAction(callback, roles);
  70.       }

  71.     /***********************************************************************************************************************************************************
  72.      * Creates a new instance out of a callback and a role (typically a {@link Displayable}).
  73.      *
  74.      * @param   callback    the callback
  75.      * @param   role        the role (or role factory)
  76.      * @return              the new instance
  77.      * @since               3.2-ALPHA-3
  78.      **********************************************************************************************************************************************************/
  79.     @Nonnull
  80.     public static UserAction of (@Nonnull final Callback callback, @Nonnull final Object role)
  81.       {
  82.         Parameters.mustNotBeArrayOrCollection(role, "role");
  83.         return of(callback, List.of(role));
  84.       }

  85.     /***********************************************************************************************************************************************************
  86.      * Creates a new instance out of a callback.
  87.      *
  88.      * @param   callback    the callback
  89.      * @return              the new instance
  90.      * @since 3.2-ALPHA-3
  91.      **********************************************************************************************************************************************************/
  92.     @Nonnull
  93.     public static UserAction of (@Nonnull final Callback callback)
  94.       {
  95.         return of(callback, Collections.emptyList());
  96.       }
  97.   }