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.ui.core.BoundProperty;
  32. import it.tidalwave.ui.core.role.impl.DefaultUserAction;
  33. import it.tidalwave.util.As;
  34. import it.tidalwave.util.Callback;
  35. import it.tidalwave.util.Parameters;
  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.     /** Shortcut for {@link it.tidalwave.util.As}. */
  46.     public static final Class<UserAction> _UserAction_ = UserAction.class;

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

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

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

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

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