Skip to contentPackage: PanelGroupControl$DefaultGroups
PanelGroupControl$DefaultGroups
Coverage
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;
27:
28: import jakarta.annotation.Nonnull;
29: import java.util.ArrayList;
30: import java.util.HashMap;
31: import java.util.List;
32: import java.util.Map;
33: import org.apiguardian.api.API;
34: import lombok.Getter;
35: import lombok.RequiredArgsConstructor;
36: import lombok.ToString;
37: import static org.apiguardian.api.API.Status.EXPERIMENTAL;
38: import static lombok.AccessLevel.PRIVATE;
39:
40: /***************************************************************************************************************************************************************
41: *
42: * This service looks up {@link PanelGroupProvider}s that describe portions of the User Interface and places them in the desired region of the main window.
43: * Calling the method {@link #setup(Configuration)} with the proper configuration, the desired panel groups can be bound to existing UI controls. The runtime
44: * will scan for instances of {@link PanelGroupProvider} that declare and instantiate panels to be associated to each group.
45: * Calling the method {@link #show(Object)} one of possibly many panels in the same group is brought to visibility. If the system includes a
46: * message bus implementing {@link it.tidalwave.messagebus.MessageBus}, it is also possible to pick the shown panel by publishing the event
47: * {@link it.tidalwave.ui.core.message.PanelShowRequest}; the event {@link it.tidalwave.ui.core.message.PanelShownNotification} will be published back to
48: * confirm the operation.
49: *
50: * @param <T> the concrete type of the top container (depending on the UI technology)
51: * @since 2.0-ALPHA-3
52: * @see PanelGroupProvider
53: * @author Fabrizio Giudici
54: *
55: **************************************************************************************************************************************************************/
56: @API(status = EXPERIMENTAL)
57: public interface PanelGroupControl<T>
58: {
59: /***********************************************************************************************************************************************************
60: * The group in the main window.
61: **********************************************************************************************************************************************************/
62: public static interface Group {}
63:
64: /***********************************************************************************************************************************************************
65: * Standard groups.
66: **********************************************************************************************************************************************************/
67: public enum DefaultGroups implements Group
68: {
69: LEFT, RIGHT, CENTER, BOTTOM
70: }
71:
72: /***********************************************************************************************************************************************************
73: * A bag of configuration settings for {@code PanelGroupProvider}.
74: **********************************************************************************************************************************************************/
75: @RequiredArgsConstructor(access = PRIVATE) @Getter @ToString
76: public static class Configuration<T>
77: {
78: @Nonnull
79: private final Map<Group, T> topContainersByGroup;
80:
81: @Nonnull
82: private final Map<Group, List<Options>> groupOptions;
83:
84: @Nonnull
85: private final List<Options> options;
86:
87: /*******************************************************************************************************************************************************
88: * Specifies the configuration for a group.
89: * @see Options
90: * @param group the group
91: * @param topContainer the concrete UI container that will be associated to the group
92: * @param groupOptions {@link Options} for this group
93: * @return a copy of itself in chaining invocation fashion
94: ******************************************************************************************************************************************************/
95: @Nonnull
96: public Configuration<T> withGroup (@Nonnull final Group group, @Nonnull final T topContainer, @Nonnull final Options ... groupOptions)
97: {
98: final var tcbs = new HashMap<>(topContainersByGroup);
99: final var so = new HashMap<>(this.groupOptions);
100: tcbs.put(group, topContainer);
101: so.computeIfAbsent(group, s -> new ArrayList<>()).addAll(List.of(groupOptions));
102: return new Configuration<>(tcbs, so, this.options);
103: }
104:
105: /*******************************************************************************************************************************************************
106: * Specifies global configuration {@link Options} that are applied to all groups.
107: * @see Options
108: * @param options the options
109: * @return a copy of itself in chaining invocation fashion
110: ******************************************************************************************************************************************************/
111: @Nonnull
112: public final Configuration<T> withOptions (@Nonnull final Options ... options)
113: {
114: return new Configuration<>(topContainersByGroup, groupOptions, List.of(options));
115: }
116: }
117:
118: /***********************************************************************************************************************************************************
119: * Options for the {@link #setup(Configuration)} method.
120: * @see Configuration#withGroup(Group, Object, Options...)
121: * @see Configuration#withOptions(Options...)
122: **********************************************************************************************************************************************************/
123: public static enum Options
124: {
125: /** Use a wrapper container even when there is a single element in a group. */
126: ALWAYS_WRAP,
127: /** Use an Accordion wrapper. */
128: USE_ACCORDION,
129: /** Disable animation when expanding/collapsing the Accordion. */
130: DISABLE_ACCORDION_ANIMATION
131: }
132:
133: /***********************************************************************************************************************************************************
134: * Sets up panel groups according to the given {@link Configuration}.
135: * @param configuration the configuration
136: **********************************************************************************************************************************************************/
137: public void setup (@Nonnull final Configuration<T> configuration);
138:
139: /***********************************************************************************************************************************************************
140: * Sets the shown object in a group.
141: * @param object the object to show
142: **********************************************************************************************************************************************************/
143: public void show (@Nonnull Object object);
144:
145: /***********************************************************************************************************************************************************
146: * {@return an empty {@link Configuration}}.
147: **********************************************************************************************************************************************************/
148: @Nonnull
149: public default Configuration<T> config()
150: {
151: return new Configuration<>(Map.of(), Map.of(), List.of());
152: }
153: }