|
26 | 26 | import java.util.Map; |
27 | 27 |
|
28 | 28 | /** |
29 | | - * Basic interface for CrudController, normaly use it in UIs |
30 | | - * @param <E> |
| 29 | + * Core API for managing CRUD operations on domain entities within user interface contexts. |
| 30 | + * This interface provides a comprehensive set of methods for creating, reading, updating, and deleting entities, |
| 31 | + * along with query capabilities, pagination support, and lifecycle hooks. |
| 32 | + * |
| 33 | + * <p>Implementations of this interface are typically used in UI controllers to handle entity operations |
| 34 | + * with minimal boilerplate code. It integrates seamlessly with the CrudService layer and provides |
| 35 | + * state management for current entity, selected entity, and query results.</p> |
| 36 | + * |
| 37 | + * <p>Example usage:</p> |
| 38 | + * <pre>{@code |
| 39 | + * CrudControllerAPI<Customer> controller = new CrudController<>(Customer.class, crudService); |
| 40 | + * controller.doCreate(); |
| 41 | + * controller.getEntity().setName("John Doe"); |
| 42 | + * controller.doSave(); |
| 43 | + * }</pre> |
| 44 | + * |
| 45 | + * @param <E> the type of the domain entity managed by this controller |
31 | 46 | */ |
32 | 47 | public interface CrudControllerAPI<E> { |
33 | 48 |
|
| 49 | + /** |
| 50 | + * Sets the CrudService used to perform database operations. |
| 51 | + * |
| 52 | + * @param crudService the service instance to handle persistence operations |
| 53 | + */ |
34 | 54 | void setCrudService(CrudService crudService); |
35 | 55 |
|
| 56 | + /** |
| 57 | + * Gets the current CrudService instance. |
| 58 | + * |
| 59 | + * @return the service responsible for CRUD operations |
| 60 | + */ |
36 | 61 | CrudService getCrudService(); |
37 | 62 |
|
| 63 | + /** |
| 64 | + * Saves the current entity using the configured CrudService. |
| 65 | + * This method typically triggers validation and persistence operations. |
| 66 | + * Use {@link #doSave()} for the complete save workflow including UI feedback. |
| 67 | + */ |
38 | 68 | void save(); |
39 | 69 |
|
| 70 | + /** |
| 71 | + * Deletes the current entity using the configured CrudService. |
| 72 | + * This method performs the deletion without confirmation or UI feedback. |
| 73 | + * Use {@link #doDelete()} for the complete deletion workflow. |
| 74 | + */ |
40 | 75 | void delete(); |
41 | 76 |
|
| 77 | + /** |
| 78 | + * Executes a query using the current example entity and query parameters. |
| 79 | + * Results are stored in the query result dataset. |
| 80 | + * Use {@link #doQuery()} for the complete query workflow with UI updates. |
| 81 | + */ |
42 | 82 | void query(); |
43 | 83 |
|
44 | 84 | /** |
45 | | - * Helper method to do a programatic delete |
| 85 | + * Performs a programmatic deletion of a specific entity. |
| 86 | + * This is a convenience method for deleting entities without setting them as the current entity. |
46 | 87 | * |
47 | | - */ |
48 | | - void delete(E entity); |
| 88 | + * @param entity the entity to delete |
| 89 | + */ |
| 90 | + void delete(E entity); |
49 | 91 |
|
50 | 92 | /** |
51 | | - * Helper method to do a programatic edit |
| 93 | + * Performs a programmatic edit operation on a specific entity. |
| 94 | + * Sets the given entity as the current entity and prepares it for editing. |
52 | 95 | * |
53 | | - */ |
54 | | - void edit(E entity); |
| 96 | + * @param entity the entity to edit |
| 97 | + */ |
| 98 | + void edit(E entity); |
55 | 99 |
|
| 100 | + /** |
| 101 | + * Creates a new instance of the managed entity class and sets it as the current entity. |
| 102 | + * The new entity is initialized with default values if configured. |
| 103 | + */ |
56 | 104 | void newEntity(); |
57 | 105 |
|
| 106 | + /** |
| 107 | + * Creates a new example entity instance for query-by-example operations. |
| 108 | + * The example entity is used to specify search criteria. |
| 109 | + */ |
58 | 110 | void newExample(); |
59 | 111 |
|
| 112 | + /** |
| 113 | + * Reloads the current entity from the database, discarding any unsaved changes. |
| 114 | + * This is useful to refresh the entity state after external modifications. |
| 115 | + */ |
60 | 116 | void reloadEntity(); |
61 | 117 |
|
| 118 | + /** |
| 119 | + * Gets the current entity being managed by this controller. |
| 120 | + * |
| 121 | + * @return the current entity, or null if no entity is set |
| 122 | + */ |
62 | 123 | E getEntity(); |
63 | 124 |
|
| 125 | + /** |
| 126 | + * Sets the current entity to be managed by this controller. |
| 127 | + * |
| 128 | + * @param entity the entity to set as current |
| 129 | + */ |
64 | 130 | void setEntity(E entity); |
65 | 131 |
|
| 132 | + /** |
| 133 | + * Gets the example entity used for query-by-example operations. |
| 134 | + * |
| 135 | + * @return the example entity, or null if no example is set |
| 136 | + */ |
66 | 137 | E getExample(); |
67 | 138 |
|
| 139 | + /** |
| 140 | + * Gets the currently selected entity from the query results. |
| 141 | + * This is typically used in list/table views where users can select a row. |
| 142 | + * |
| 143 | + * @return the selected entity, or null if no entity is selected |
| 144 | + */ |
68 | 145 | E getSelected(); |
69 | 146 |
|
| 147 | + /** |
| 148 | + * Checks if the current entity has been successfully saved. |
| 149 | + * |
| 150 | + * @return true if the entity was saved in the last operation, false otherwise |
| 151 | + */ |
70 | 152 | boolean isSaved(); |
71 | 153 |
|
| 154 | + /** |
| 155 | + * Checks if the current entity has been successfully deleted. |
| 156 | + * |
| 157 | + * @return true if the entity was deleted in the last operation, false otherwise |
| 158 | + */ |
72 | 159 | boolean isDeleted(); |
73 | 160 |
|
| 161 | + /** |
| 162 | + * Sets the currently selected entity from query results. |
| 163 | + * |
| 164 | + * @param selected the entity to mark as selected |
| 165 | + */ |
74 | 166 | void setSelected(E selected); |
75 | 167 |
|
| 168 | + /** |
| 169 | + * Gets the query parameters used for searching and filtering entities. |
| 170 | + * |
| 171 | + * @return the current query parameters |
| 172 | + */ |
76 | 173 | QueryParameters getParams(); |
77 | 174 |
|
| 175 | + /** |
| 176 | + * Sets the query parameters for searching and filtering entities. |
| 177 | + * |
| 178 | + * @param params the query parameters to use |
| 179 | + */ |
78 | 180 | void setParams(QueryParameters params); |
79 | 181 |
|
| 182 | + /** |
| 183 | + * Gets a specific parameter value from the query parameters. |
| 184 | + * |
| 185 | + * @param param the parameter name |
| 186 | + * @return the parameter value, or null if not found |
| 187 | + */ |
80 | 188 | Object getParameter(String param); |
81 | 189 |
|
| 190 | + /** |
| 191 | + * Sets a specific parameter value in the query parameters. |
| 192 | + * |
| 193 | + * @param key the parameter name |
| 194 | + * @param value the parameter value |
| 195 | + */ |
82 | 196 | void setParemeter(String key, Object value); |
83 | 197 |
|
| 198 | + /** |
| 199 | + * Gets the dataset containing the results of the last query operation. |
| 200 | + * |
| 201 | + * @return the query result dataset |
| 202 | + */ |
84 | 203 | DataSet getQueryResult(); |
85 | 204 |
|
| 205 | + /** |
| 206 | + * Sets the dataset containing query results. |
| 207 | + * |
| 208 | + * @param queryResult the dataset to set |
| 209 | + */ |
86 | 210 | void setQueryResult(DataSet queryResult); |
87 | 211 |
|
| 212 | + /** |
| 213 | + * Checks if the query results are empty. |
| 214 | + * |
| 215 | + * @return true if no results were found in the last query, false otherwise |
| 216 | + */ |
88 | 217 | boolean isQueryResultEmpty(); |
89 | 218 |
|
| 219 | + /** |
| 220 | + * Gets the paginator for handling large query result sets. |
| 221 | + * |
| 222 | + * @return the data paginator instance |
| 223 | + */ |
90 | 224 | DataPaginator getDataPaginator(); |
91 | 225 |
|
| 226 | + /** |
| 227 | + * Gets the sorter used to order query results. |
| 228 | + * |
| 229 | + * @return the bean sorter instance |
| 230 | + */ |
92 | 231 | BeanSorter getSorter(); |
93 | 232 |
|
| 233 | + /** |
| 234 | + * Gets the class type of the entity managed by this controller. |
| 235 | + * |
| 236 | + * @return the entity class |
| 237 | + */ |
94 | 238 | Class<E> getEntityClass(); |
95 | 239 |
|
| 240 | + /** |
| 241 | + * Sets the class type of the entity to be managed by this controller. |
| 242 | + * |
| 243 | + * @param entityClass the entity class to manage |
| 244 | + */ |
96 | 245 | void setEntityClass(Class<E> entityClass); |
97 | 246 |
|
| 247 | + /** |
| 248 | + * Executes a complete query workflow including UI updates and feedback. |
| 249 | + * This method triggers the query operation and updates the view accordingly. |
| 250 | + */ |
98 | 251 | void doQuery(); |
99 | 252 |
|
| 253 | + /** |
| 254 | + * Executes a complete save workflow including validation, persistence, and UI feedback. |
| 255 | + * This is the main method to persist entity changes from the user interface. |
| 256 | + */ |
100 | 257 | void doSave(); |
101 | 258 |
|
| 259 | + /** |
| 260 | + * Executes a save operation and immediately switches to edit mode for the saved entity. |
| 261 | + * Useful for workflows where users want to continue editing after saving. |
| 262 | + */ |
102 | 263 | void doSaveAndEdit(); |
103 | 264 |
|
| 265 | + /** |
| 266 | + * Executes a complete edit workflow, preparing the selected entity for modification. |
| 267 | + * This method sets up the UI for editing the currently selected entity. |
| 268 | + */ |
104 | 269 | void doEdit(); |
105 | 270 |
|
| 271 | + /** |
| 272 | + * Executes a complete delete workflow including confirmation prompts and UI feedback. |
| 273 | + * This is the main method to delete entities from the user interface. |
| 274 | + */ |
106 | 275 | void doDelete(); |
107 | 276 |
|
| 277 | + /** |
| 278 | + * Executes a complete create workflow, initializing a new entity and preparing the UI. |
| 279 | + * This method sets up the form for creating a new entity instance. |
| 280 | + */ |
108 | 281 | void doCreate(); |
109 | 282 |
|
| 283 | + /** |
| 284 | + * Gets the default values to be applied to new entities. |
| 285 | + * These values are automatically set when creating new entity instances. |
| 286 | + * |
| 287 | + * @return a map containing default field names and their values |
| 288 | + */ |
110 | 289 | Map<String, Object> getDefaultEntityValues(); |
111 | 290 |
|
| 291 | + /** |
| 292 | + * Sets whether to show a confirmation dialog before saving entities. |
| 293 | + * |
| 294 | + * @param confirm true to require confirmation, false to save directly |
| 295 | + */ |
112 | 296 | void setConfirmBeforeSave(boolean confirm); |
113 | 297 |
|
| 298 | + /** |
| 299 | + * Checks if confirmation is required before saving entities. |
| 300 | + * |
| 301 | + * @return true if confirmation is enabled, false otherwise |
| 302 | + */ |
114 | 303 | boolean isConfirmBeforeSave(); |
115 | 304 |
|
| 305 | + /** |
| 306 | + * Registers a callback to be executed after successful save operations. |
| 307 | + * This allows custom logic to be triggered post-save. |
| 308 | + * |
| 309 | + * @param onSave the callback to execute after saving |
| 310 | + */ |
116 | 311 | void onSave(Callback onSave); |
117 | 312 |
|
| 313 | + /** |
| 314 | + * Clears the controller state, resetting all entities and query results. |
| 315 | + * This method is useful for resetting the controller to its initial state. |
| 316 | + */ |
118 | 317 | void clear(); |
119 | 318 | } |
0 commit comments