Skip to content

Method: of(Callback)

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:
29: import javax.annotation.Nonnull;
30: import java.util.Collection;
31: import java.util.Collections;
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: *
51: ******************************************************************************************************************/
52: public void actionPerformed();
53:
54: /*******************************************************************************************************************
55: *
56: * Returns the property describing the enabled status of this action.
57: *
58: * @return the enabled property
59: *
60: ******************************************************************************************************************/
61: @Nonnull
62: public BoundProperty<Boolean> enabled(); // TODO: rename to enabledProperty()
63:
64: /*******************************************************************************************************************
65: *
66: * Creates a new instance out of a callback and a collection of roles.
67: *
68: * @param callback the callback
69: * @param roles the roles (or role factories)
70: * @return the new instance
71: * @since 3.2-ALPHA-1 (replaces {@code new UserActionSupport()}
72: * @since 3.2-ALPHA-3 (refactored)
73: *
74: ******************************************************************************************************************/
75: @Nonnull
76: public static UserAction of (@Nonnull final Callback callback, @Nonnull final Collection<Object> roles)
77: {
78: return new DefaultUserAction(callback, roles);
79: }
80:
81: /*******************************************************************************************************************
82: *
83: * Creates a new instance out of a callback and a role (typically a {@link Displayable}.
84: *
85: * @param callback the callback
86: * @param role the role (or role factory)
87: * @return the new instance
88: * @since 3.2-ALPHA-3
89: *
90: ******************************************************************************************************************/
91: @Nonnull
92: public static UserAction of (@Nonnull final Callback callback, @Nonnull final Object role)
93: {
94: Parameters.mustNotBeArrayOrCollection(role, "role");
95: return of(callback, Collections.singletonList(role));
96: }
97:
98: /*******************************************************************************************************************
99: *
100: * Creates a new instance out of a callback.
101: *
102: * @param callback the callback
103: * @return the new instance
104: * @since 3.2-ALPHA-3
105: *
106: ******************************************************************************************************************/
107: @Nonnull
108: public static UserAction of (@Nonnull final Callback callback)
109: {
110: return of(callback, Collections.emptyList());
111: }
112: }