Skip to contentPackage: Layout$Builder$CallBack
Layout$Builder$CallBack
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.ui;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Optional;
31: import it.tidalwave.util.As;
32: import it.tidalwave.util.Id;
33: import it.tidalwave.util.NotFoundException;
34: import it.tidalwave.role.Composite;
35: import it.tidalwave.role.Identifiable;
36: import it.tidalwave.northernwind.core.model.HttpStatusException;
37: import it.tidalwave.northernwind.core.model.ModelFactory;
38: import it.tidalwave.northernwind.core.model.SiteNode;
39: import it.tidalwave.northernwind.frontend.ui.ViewFactory.ViewAndController;
40: import lombok.AccessLevel;
41: import lombok.AllArgsConstructor;
42: import lombok.Getter;
43: import lombok.RequiredArgsConstructor;
44: import lombok.ToString;
45: import lombok.With;
46:
47: /***********************************************************************************************************************
48: *
49: * A {@code Layout} contains the description of the visual structure of a {@link SiteNode}.
50: *
51: * @author Fabrizio Giudici
52: *
53: **********************************************************************************************************************/
54: public interface Layout extends As, Identifiable, Composite<Layout, LayoutFinder>
55: {
56: /*******************************************************************************************************************
57: *
58: * A builder of a {@link Layout}.
59: *
60: ******************************************************************************************************************/
61: @AllArgsConstructor(access = AccessLevel.PRIVATE) @RequiredArgsConstructor
62: @Getter @ToString(exclude = "callBack")
63: public final class Builder
64: {
65: // Workaround for a Lombok limitation with Wither and subclasses
66: @FunctionalInterface
67: public static interface CallBack
68: {
69: @Nonnull
70: public Layout build (@Nonnull Builder builder);
71: }
72:
73: @Nonnull
74: private final ModelFactory modelFactory;
75:
76: @Nonnull
77: private final CallBack callBack;
78:
79: @With
80: private Id id;
81:
82: @With
83: private String type;
84:
85: @Nonnull
86: public Layout build()
87: {
88: return callBack.build(this);
89: }
90: }
91:
92: /*******************************************************************************************************************
93: *
94: * Returns the type URI for this layout.
95: *
96: * @return the type URI
97: *
98: ******************************************************************************************************************/
99: @Nonnull
100: public String getTypeUri(); // FIXME: perhaps String should be a LayoutType wrapper? Or an Id?
101:
102: /*******************************************************************************************************************
103: *
104: * Creates a clone with another {@code Layout} as a child.
105: *
106: * @param child the child {@code Layout}
107: * @return the clone with the new child
108: *
109: ******************************************************************************************************************/
110: @Nonnull
111: public Layout withChild (@Nonnull Layout child);
112:
113: /*******************************************************************************************************************
114: *
115: * Creates a clone with another {@code Layout} overriding some parts.
116: *
117: * @param override the overriding {@code Layout}
118: * @return the clone with the override in effect
119: *
120: ******************************************************************************************************************/
121: @Nonnull
122: public Layout withOverride (@Nonnull Layout override);
123:
124: /*******************************************************************************************************************
125: *
126: * Accepts a {@link Visitor} to walk inside the structure and returns the (optional) computation product of the
127: * {@code Visitor}.
128: *
129: * @param visitor the {@code Visitor}
130: * @return the {@code Visitor} result
131: *
132: ******************************************************************************************************************/
133: @Nonnull // TODO: push up to Composite
134: public <T> Optional<T> accept (@Nonnull Visitor<? super Layout, T> visitor);
135:
136: /*******************************************************************************************************************
137: *
138: * Creates a new {@link View} with its {@link Controller} for the given {@link SiteNode}, typically because
139: * something needs to render it in response of a request.
140: *
141: * @param siteNode the {@code SiteNode}
142: * @return the {@code View} and its {@code Controller} within a {@link ViewAndController}
143: * @throws NotFoundException if no view component is found
144: * @throws HttpStatusException if a component asked to return a specific HTTP status
145: *
146: ******************************************************************************************************************/
147: @Nonnull
148: public ViewAndController createViewAndController (@Nonnull SiteNode siteNode)
149: throws NotFoundException, HttpStatusException;
150: }