UserAction.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 java.util.List;
  32. import it.tidalwave.util.As;
  33. import it.tidalwave.util.Callback;
  34. import it.tidalwave.util.Parameters;
  35. import it.tidalwave.role.ui.impl.DefaultUserAction;
  36. // import javafx.beans.property.BooleanProperty;

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

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

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

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

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

  92.     /*******************************************************************************************************************
  93.      *
  94.      * Creates a new instance out of a callback.
  95.      *
  96.      * @param   callback    the callback
  97.      * @return              the new instance
  98.      * @since 3.2-ALPHA-3
  99.      *
  100.      ******************************************************************************************************************/
  101.     @Nonnull
  102.     public static UserAction of (@Nonnull final Callback callback)
  103.       {
  104.         return of(callback, Collections.emptyList());
  105.       }
  106.   }