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

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

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

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

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

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

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