Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
2a76de06
by Tony Chemit at 2022-09-11T17:53:48+02:00
-
bd51e3a9
by Tony Chemit at 2022-09-11T18:11:06+02:00
-
e0df1a24
by Tony Chemit at 2022-09-11T18:17:39+02:00
-
d685e4aa
by Tony Chemit at 2022-09-11T18:17:48+02:00
5 changed files:
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/delete/DeleteRootTreeAdapter.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/reset/DefaultResetAdapter.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/ropen/ContentRootOpenableUINavigationInitializer.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/ropen/actions/SaveContentRootOpenableUIAdapter.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/root/RootNavigationNode.java
Changes:
| ... | ... | @@ -45,10 +45,14 @@ public abstract class DeleteRootTreeAdapter<OldParent extends NavigationNode> ex |
| 45 | 45 | @Override
|
| 46 | 46 | public void removeChildren(NavigationUI navigationUI, OldParent parentNode, Set<String> ids) {
|
| 47 | 47 | super.removeChildren(navigationUI, parentNode, ids);
|
| 48 | - RootNavigationInitializer initializer = (RootNavigationInitializer) parentNode.getRoot().getInitializer();
|
|
| 48 | + NavigationNode rootNode = parentNode.getRoot();
|
|
| 49 | + RootNavigationInitializer initializer = (RootNavigationInitializer) rootNode.getInitializer();
|
|
| 49 | 50 | boolean removeGroupBy = parentNode.getChildCount() == 0 && !initializer.getRequest().isLoadEmptyGroupBy();
|
| 50 | 51 | if (removeGroupBy) {
|
| 51 | 52 | parentNode.removeFromParent();
|
| 53 | + if (rootNode.isNotLeaf()) {
|
|
| 54 | + navigationUI.getTree().selectFirstNode();
|
|
| 55 | + }
|
|
| 52 | 56 | }
|
| 53 | 57 | NavigationUIHandler.updateStatistics(navigationUI, removeGroupBy ? -1 : 0, -ids.size());
|
| 54 | 58 | }
|
| ... | ... | @@ -25,9 +25,11 @@ package fr.ird.observe.client.datasource.editor.api.content.actions.reset; |
| 25 | 25 | import fr.ird.observe.client.datasource.editor.api.content.ContentUI;
|
| 26 | 26 | import fr.ird.observe.client.datasource.editor.api.content.ContentUIHandler;
|
| 27 | 27 | import fr.ird.observe.client.datasource.editor.api.content.ContentUIModel;
|
| 28 | +import fr.ird.observe.client.datasource.editor.api.content.data.rlist.ContentRootListUINavigationNode;
|
|
| 28 | 29 | import fr.ird.observe.client.datasource.editor.api.content.data.table.ContentTableUI;
|
| 29 | 30 | import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTree;
|
| 30 | 31 | import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode;
|
| 32 | +import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationInitializer;
|
|
| 31 | 33 | |
| 32 | 34 | /**
|
| 33 | 35 | * Created on 19/10/2020.
|
| ... | ... | @@ -45,6 +47,18 @@ public class DefaultResetAdapter<U extends ContentUI> implements ResetAdapter<U> |
| 45 | 47 | NavigationTree tree = handler.getNavigationTree();
|
| 46 | 48 | NavigationNode parentNode = tree.getSelectedNode().getParent();
|
| 47 | 49 | tree.getSelectedNode().removeFromParent();
|
| 50 | + if (parentNode instanceof ContentRootListUINavigationNode) {
|
|
| 51 | + NavigationNode rootNode = parentNode.getRoot();
|
|
| 52 | + RootNavigationInitializer initializer = (RootNavigationInitializer) rootNode.getInitializer();
|
|
| 53 | + boolean removeGroupBy = parentNode.getChildCount() == 0 && !initializer.getRequest().isLoadEmptyGroupBy();
|
|
| 54 | + if (removeGroupBy) {
|
|
| 55 | + parentNode.removeFromParent();
|
|
| 56 | + if (rootNode.isNotLeaf()) {
|
|
| 57 | + tree.selectFirstNode();
|
|
| 58 | + }
|
|
| 59 | + return;
|
|
| 60 | + }
|
|
| 61 | + }
|
|
| 48 | 62 | tree.reloadAndSelectSafeNode(parentNode);
|
| 49 | 63 | }
|
| 50 | 64 | }
|
| ... | ... | @@ -40,7 +40,7 @@ import java.util.function.Supplier; |
| 40 | 40 | */
|
| 41 | 41 | public final class ContentRootOpenableUINavigationInitializer extends NavigationInitializer<ContentRootOpenableUINavigationContext> {
|
| 42 | 42 | |
| 43 | - private final Supplier<? extends DataGroupByDto<?>> parentReference;
|
|
| 43 | + private Supplier<? extends DataGroupByDto<?>> parentReference;
|
|
| 44 | 44 | private DataDtoReference reference;
|
| 45 | 45 | private Decorator decorator;
|
| 46 | 46 | |
| ... | ... | @@ -104,6 +104,10 @@ public final class ContentRootOpenableUINavigationInitializer extends Navigation |
| 104 | 104 | return getSelectId() == null;
|
| 105 | 105 | }
|
| 106 | 106 | |
| 107 | + public void setParentReference(Supplier<? extends DataGroupByDto<?>> parentReference) {
|
|
| 108 | + this.parentReference = Objects.requireNonNull(parentReference);
|
|
| 109 | + }
|
|
| 110 | + |
|
| 107 | 111 | public void setReference(DataDtoReference reference) {
|
| 108 | 112 | this.reference = Objects.requireNonNull(reference);
|
| 109 | 113 | }
|
| ... | ... | @@ -24,6 +24,7 @@ package fr.ird.observe.client.datasource.editor.api.content.data.ropen.actions; |
| 24 | 24 | |
| 25 | 25 | import fr.ird.observe.client.datasource.editor.api.DataSourceEditor;
|
| 26 | 26 | import fr.ird.observe.client.datasource.editor.api.content.actions.save.SaveUIAdapter;
|
| 27 | +import fr.ird.observe.client.datasource.editor.api.content.data.rlist.ContentRootListUINavigationNode;
|
|
| 27 | 28 | import fr.ird.observe.client.datasource.editor.api.content.data.ropen.ContentRootOpenableUI;
|
| 28 | 29 | import fr.ird.observe.client.datasource.editor.api.content.data.ropen.ContentRootOpenableUIModel;
|
| 29 | 30 | import fr.ird.observe.client.datasource.editor.api.content.data.ropen.ContentRootOpenableUINavigationNode;
|
| ... | ... | @@ -31,11 +32,15 @@ import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTree; |
| 31 | 32 | import fr.ird.observe.client.datasource.editor.api.navigation.NavigationUIHandler;
|
| 32 | 33 | import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode;
|
| 33 | 34 | import fr.ird.observe.client.datasource.editor.api.navigation.tree.capability.ReferenceContainerCapability;
|
| 35 | +import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationNode;
|
|
| 36 | +import fr.ird.observe.dto.data.DataGroupByDto;
|
|
| 34 | 37 | import fr.ird.observe.dto.data.RootOpenableDto;
|
| 35 | 38 | import fr.ird.observe.dto.reference.DataDtoReference;
|
| 36 | 39 | import org.apache.logging.log4j.LogManager;
|
| 37 | 40 | import org.apache.logging.log4j.Logger;
|
| 38 | 41 | |
| 42 | +import java.util.Objects;
|
|
| 43 | + |
|
| 39 | 44 | /**
|
| 40 | 45 | * Created on 16/10/2020.
|
| 41 | 46 | *
|
| ... | ... | @@ -53,9 +58,17 @@ public class SaveContentRootOpenableUIAdapter<D extends RootOpenableDto, U exten |
| 53 | 58 | ui.stopEdit();
|
| 54 | 59 | |
| 55 | 60 | ContentRootOpenableUINavigationNode node = model.getSource();
|
| 61 | + |
|
| 62 | + // get old groupBy dto
|
|
| 63 | + @SuppressWarnings("unchecked") DataGroupByDto<D> oldGroupByDto = (DataGroupByDto<D>) node.getParentReference();
|
|
| 64 | + |
|
| 65 | + // new groupBy value
|
|
| 66 | + String newGroupByValue = oldGroupByDto.definition().toGroupByValue(bean, ((RootNavigationNode) node.getRoot()).getInitializer().getRequest().getGroupByFlavor());
|
|
| 67 | + // is groupBy has changed?
|
|
| 68 | + boolean groupByChanged = !Objects.equals(oldGroupByDto.getFilterValue(), newGroupByValue);
|
|
| 56 | 69 | // We need to inject ot node the new reference (it could does not know the id if not persisted)
|
| 57 | 70 | // As I prefer to use a unique code (for persisted or not, keep it like this)
|
| 58 | - updateReference(node, bean.getId());
|
|
| 71 | + updateReference(node, bean.getId(), oldGroupByDto, groupByChanged ? newGroupByValue : null);
|
|
| 59 | 72 | |
| 60 | 73 | NavigationTree tree = dataSourceEditor.getNavigationUI().getTree();
|
| 61 | 74 | tree.reSelectSafeNodeThen(node, () -> {
|
| ... | ... | @@ -67,11 +80,32 @@ public class SaveContentRootOpenableUIAdapter<D extends RootOpenableDto, U exten |
| 67 | 80 | });
|
| 68 | 81 | }
|
| 69 | 82 | |
| 70 | - |
|
| 71 | - public void updateReference(ContentRootOpenableUINavigationNode node, String id) {
|
|
| 83 | + public void updateReference(ContentRootOpenableUINavigationNode node,
|
|
| 84 | + String id,
|
|
| 85 | + DataGroupByDto<D> oldGroupByDto,
|
|
| 86 | + String newGroupByValue) {
|
|
| 72 | 87 | boolean notPersisted = node.getInitializer().isNotPersisted();
|
| 73 | 88 | NavigationNode parent = node.getParent();
|
| 74 | - int oldPosition = parent.getIndex(node);
|
|
| 89 | + boolean groupByChanged = newGroupByValue != null;
|
|
| 90 | + if (groupByChanged) {
|
|
| 91 | + // groupBy has changed (remove node from parent)
|
|
| 92 | + RootNavigationNode rootNode = (RootNavigationNode) node.getRoot();
|
|
| 93 | + node.removeFromParent();
|
|
| 94 | + // remove old parent node if navigation tree config requires it
|
|
| 95 | + boolean removeGroupBy = parent.getChildCount() == 0 && !rootNode.getInitializer().getRequest().isLoadEmptyGroupBy();
|
|
| 96 | + if (removeGroupBy) {
|
|
| 97 | + parent.removeFromParent();
|
|
| 98 | + } else {
|
|
| 99 | + // update old parent to root
|
|
| 100 | + parent.reloadNodeDataToRoot();
|
|
| 101 | + }
|
|
| 102 | + // find new parent
|
|
| 103 | + parent = rootNode.findChildById(newGroupByValue, true);
|
|
| 104 | + // update parent reference in node
|
|
| 105 | + DataGroupByDto<?> parentReference = ((ContentRootListUINavigationNode) parent).getInitializer().getParentReference();
|
|
| 106 | + node.getInitializer().setParentReference(() -> parentReference);
|
|
| 107 | + }
|
|
| 108 | + |
|
| 75 | 109 | DataDtoReference reference = node.getInitializer().updateReference(node.getContext(), id);
|
| 76 | 110 | if (notPersisted) {
|
| 77 | 111 | node.getInitializer().updateEditNodeId(id);
|
| ... | ... | @@ -86,12 +120,24 @@ public class SaveContentRootOpenableUIAdapter<D extends RootOpenableDto, U exten |
| 86 | 120 | }
|
| 87 | 121 | |
| 88 | 122 | ReferenceContainerCapability<?> capability = (ReferenceContainerCapability<?>) parent.getCapability();
|
| 89 | - int newPosition = capability.getNodePosition(reference);
|
|
| 90 | - if (oldPosition != newPosition) {
|
|
| 91 | - log.info(String.format("Move node from: %d to %d", oldPosition, newPosition));
|
|
| 92 | - parent.moveNode(node, newPosition);
|
|
| 123 | + if (groupByChanged) {
|
|
| 124 | + if (parent.isNotLoaded()) {
|
|
| 125 | + // will load all children even the updated one
|
|
| 126 | + parent.populateChildrenIfNotLoaded();
|
|
| 127 | + } else {
|
|
| 128 | + // need to add updated node
|
|
| 129 | + int newPosition = capability.getNodePosition(reference);
|
|
| 130 | + log.info(String.format("Change groupBy node from: %s to %s (position: %d)", oldGroupByDto.getFilterValue(), newGroupByValue, newPosition));
|
|
| 131 | + parent.insert(node, newPosition);
|
|
| 132 | + }
|
|
| 133 | + } else {
|
|
| 134 | + int oldPosition = parent.getIndex(node);
|
|
| 135 | + int newPosition = capability.getNodePosition(reference);
|
|
| 136 | + if (oldPosition != newPosition) {
|
|
| 137 | + log.info(String.format("Move node from: %d to %d", oldPosition, newPosition));
|
|
| 138 | + parent.moveNode(node, newPosition);
|
|
| 139 | + }
|
|
| 93 | 140 | }
|
| 94 | - |
|
| 95 | 141 | // repaint selected node and his children
|
| 96 | 142 | node.nodeChangedDeep();
|
| 97 | 143 |
| ... | ... | @@ -130,16 +130,13 @@ public class RootNavigationNode extends NavigationNode { |
| 130 | 130 | return result;
|
| 131 | 131 | }
|
| 132 | 132 | |
| 133 | - public <N extends NavigationNode> N findChildByTypeWithNoCreate(Class<N> childType, String id) {
|
|
| 134 | - return super.findChildByType(childType, id);
|
|
| 135 | - }
|
|
| 136 | - |
|
| 137 | 133 | protected NavigationNode createMissingNode(String id) {
|
| 138 | 134 | // limit case : node does not exist (was empty previously), need to create it
|
| 139 | 135 | DataGroupByDto<?> reference = getInitializer().getNavigationResult().getGroupBy(id);
|
| 140 | 136 | if (reference == null) {
|
| 141 | 137 | ToolkitTreeFlatModelRootRequest request = getInitializer().getRequest();
|
| 142 | 138 | reference = getDataSourcesManager().getMainDataSource().getRootOpenableService().getGroupByDtoValue(getInitializer().getNavigationResult().getData().getType(), new DataGroupByParameter(request.getGroupByName(), request.getGroupByFlavor(), id));
|
| 139 | + getDecoratorService().installDecorator(reference);
|
|
| 143 | 140 | }
|
| 144 | 141 | NavigationNode result = getCapability().createChildNode(reference);
|
| 145 | 142 | int position = getCapability().getNodePosition(reference);
|