-
Task
-
Resolution: Fixed
-
Neutral
-
None
-
-
Empty show more show less
-
Empty show more show less
-
Basel 50, Basel 50
-
5
For MGNLUI-3428, we introduced info.magnolia.ui.contentapp.DefinitionCloner to workaround problems we found when cloning definitions.
Really though, those definitions should never have been cloned in the first place. The use-case is to slightly "customize" a given configured definition and reuse it in a slightly different context (e.g reuse a workbench config in a choose dialog)
Not only does this cause unnecessary complexity (e.g doesn't play well with proxies), it's also just really unnecessary and unportable. Many usages explicitly cast to the Configured* implementation of their definition, to be able to call setter methods. This will thus obviously never work with any other implementation of the interfaces.
Instead, we should introduce simple decorators for our definition interfaces. Let them delegate all getters to a delegatee. And in place of cloning, we could do something along these lines:
diff --git a/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/MoveDialogPresenterImpl.java b/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/MoveDialogPresenterImpl.java index f24d597..0ec973c 100644 --- a/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/MoveDialogPresenterImpl.java +++ b/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/MoveDialogPresenterImpl.java @@ -222,13 +223,12 @@ public class MoveDialogPresenterImpl extends BaseDialogPresenter implements Move } private ContentPresenterDefinition prepareTreePresenter(ContentPresenterDefinition treePresenter) { - ContentPresenterDefinition def = cloner.deepClone(treePresenter); - if (!def.getColumns().isEmpty()) { - ColumnDefinition column = def.getColumns().get(0); - def.getColumns().clear(); - def.getColumns().add(column); - } - return def; + return new ContentPresenterDefinitionDecorator(treePresenter) { + @Override + public List<ColumnDefinition> getColumns() { + return Collections.singletonList(delegate().getColums().get(0)); + } + }; }
(and of course using a non-anonymous class to do this would provide greater debuggability)
This goes hand-in-hand with tasks related to "use interfaces everywhere" and "builders for definitions".
- depends upon
-
MAGNOLIA-6693 Introduce proxy-based mutable wrapper utility as alternative to Cloner functionality
- Closed
- is depended upon by
-
MAGNOLIA-6654 Decorating the definition of an app will cause the choose dialog to fail
- Closed
-
MGNLPN-291 Preview app: get rid of Cloner and ConfiguredFieldDefinition usages in favor of MutableWrapper utility
- Closed
- supersedes
-
MGNLUI-3755 Possible StackOverflow when DefinitionCloner tries to clone i18n proxies
- Closed