1 /*
2 * *************************************************************************************************************************************************************
3 *
4 * TheseFoolishThings: Miscellaneous utilities
5 * http://tidalwave.it/projects/thesefoolishthings
6 *
7 * Copyright (C) 2009 - 2024 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/thesefoolishthings-src
22 * git clone https://github.com/tidalwave-it/thesefoolishthings-src
23 *
24 * *************************************************************************************************************************************************************
25 */
26 package it.tidalwave.role.ui;
27
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 *
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 **********************************************************************************************************************************************************/
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 @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 @Nonnull
70 public static UserAction of (@Nonnull final Callback callback, @Nonnull final Collection<Object> roles)
71 {
72 return new DefaultUserAction(callback, roles);
73 }
74
75 /***********************************************************************************************************************************************************
76 * Creates a new instance out of a callback and a role (typically a {@link Displayable}).
77 *
78 * @param callback the callback
79 * @param role the role (or role factory)
80 * @return the new instance
81 * @since 3.2-ALPHA-3
82 **********************************************************************************************************************************************************/
83 @Nonnull
84 public static UserAction of (@Nonnull final Callback callback, @Nonnull final Object role)
85 {
86 Parameters.mustNotBeArrayOrCollection(role, "role");
87 return of(callback, List.of(role));
88 }
89
90 /***********************************************************************************************************************************************************
91 * Creates a new instance out of a callback.
92 *
93 * @param callback the callback
94 * @return the new instance
95 * @since 3.2-ALPHA-3
96 **********************************************************************************************************************************************************/
97 @Nonnull
98 public static UserAction of (@Nonnull final Callback callback)
99 {
100 return of(callback, Collections.emptyList());
101 }
102 }