| ... |
... |
@@ -29,15 +29,21 @@ import fr.ird.observe.client.datasource.editor.api.content.data.ropen.ContentRoo |
|
29
|
29
|
import fr.ird.observe.client.datasource.editor.api.content.data.ropen.ContentRootOpenableUIModel;
|
|
30
|
30
|
import fr.ird.observe.client.datasource.editor.api.content.data.ropen.ContentRootOpenableUINavigationNode;
|
|
31
|
31
|
import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTree;
|
|
|
32
|
+import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTreeModel;
|
|
32
|
33
|
import fr.ird.observe.client.datasource.editor.api.navigation.NavigationUI;
|
|
33
|
34
|
import fr.ird.observe.client.datasource.editor.api.navigation.tree.capability.ReferenceContainerCapability;
|
|
34
|
35
|
import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationNode;
|
|
35
|
36
|
import fr.ird.observe.dto.data.DataGroupByDto;
|
|
36
|
37
|
import fr.ird.observe.dto.data.RootOpenableDto;
|
|
37
|
38
|
import fr.ird.observe.dto.reference.DataDtoReference;
|
|
|
39
|
+import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
|
38
|
40
|
import fr.ird.observe.navigation.tree.NavigationResult;
|
|
|
41
|
+import fr.ird.observe.navigation.tree.io.request.ToolkitTreeFlatModelRootRequest;
|
|
|
42
|
+import fr.ird.observe.navigation.tree.navigation.NavigationTreeConfig;
|
|
|
43
|
+import io.ultreia.java4all.i18n.I18n;
|
|
39
|
44
|
import org.apache.logging.log4j.LogManager;
|
|
40
|
45
|
import org.apache.logging.log4j.Logger;
|
|
|
46
|
+import org.nuiton.jaxx.runtime.swing.JOptionPanes;
|
|
41
|
47
|
|
|
42
|
48
|
import java.util.Objects;
|
|
43
|
49
|
|
| ... |
... |
@@ -63,13 +69,13 @@ public class SaveContentRootOpenableUIAdapter<D extends RootOpenableDto, U exten |
|
63
|
69
|
// get old groupBy dto
|
|
64
|
70
|
@SuppressWarnings("unchecked") DataGroupByDto<D> oldGroupByDto = (DataGroupByDto<D>) node.getParentReference();
|
|
65
|
71
|
|
|
66
|
|
- // new groupBy value
|
|
67
|
|
- String newGroupByValue = oldGroupByDto.definition().toGroupByValue(bean, ((RootNavigationNode) node.getRoot()).getInitializer().getRequest().getGroupByFlavor());
|
|
68
|
|
- // is groupBy has changed?
|
|
69
|
|
- boolean groupByChanged = !Objects.equals(oldGroupByDto.getFilterValue(), newGroupByValue);
|
|
|
72
|
+ ToolkitTreeFlatModelRootRequest navigationRequest = ((RootNavigationNode) node.getRoot()).getInitializer().getRequest();
|
|
|
73
|
+ ComputeNavigationRequestChange<D,U> computeNavigationRequestChange = new ComputeNavigationRequestChange<>(oldGroupByDto, navigationRequest, bean);
|
|
|
74
|
+ computeNavigationRequestChange.warnUserIfNecessary(ui);
|
|
|
75
|
+
|
|
70
|
76
|
// We need to inject ot node the new reference (it could does not know the id if not persisted)
|
|
71
|
77
|
// As I prefer to use a unique code (for persisted or not, keep it like this)
|
|
72
|
|
- node = updateReference(dataSourceEditor.getNavigationUI(), node, bean.getId(), oldGroupByDto, groupByChanged, newGroupByValue);
|
|
|
78
|
+ node = updateReference(dataSourceEditor.getNavigationUI(), node, computeNavigationRequestChange);
|
|
73
|
79
|
|
|
74
|
80
|
tree.reSelectSafeNodeThen(node, () -> {
|
|
75
|
81
|
dataSourceEditor.getModel().resetFromPreviousUi(ui);
|
| ... |
... |
@@ -79,17 +85,125 @@ public class SaveContentRootOpenableUIAdapter<D extends RootOpenableDto, U exten |
|
79
|
85
|
});
|
|
80
|
86
|
}
|
|
81
|
87
|
|
|
|
88
|
+ public static class ComputeNavigationRequestChange<D extends RootOpenableDto, U extends ContentRootOpenableUI<D, U>> {
|
|
|
89
|
+ private final DataGroupByDto<D> oldGroupByDto;
|
|
|
90
|
+ private final ToolkitTreeFlatModelRootRequest navigationRequest;
|
|
|
91
|
+ private final D bean;
|
|
|
92
|
+ private final String newGroupByValue;
|
|
|
93
|
+ private final boolean groupByChanged;
|
|
|
94
|
+ private final boolean changeNavigationRequest;
|
|
|
95
|
+ private final boolean addNullGroupBy;
|
|
|
96
|
+ private final boolean addDisabledGroupBy;
|
|
|
97
|
+
|
|
|
98
|
+ ComputeNavigationRequestChange(DataGroupByDto<D> oldGroupByDto, ToolkitTreeFlatModelRootRequest navigationRequest, D bean) {
|
|
|
99
|
+ this.oldGroupByDto = oldGroupByDto;
|
|
|
100
|
+ this.navigationRequest = navigationRequest;
|
|
|
101
|
+ this.bean = bean;
|
|
|
102
|
+ this.newGroupByValue = oldGroupByDto.definition().toGroupByValue(bean, navigationRequest.getGroupByFlavor());
|
|
|
103
|
+ this.groupByChanged = !Objects.equals(oldGroupByDto.getFilterValue(), newGroupByValue);
|
|
|
104
|
+ boolean changeNavigationRequest = false;
|
|
|
105
|
+ boolean addNullGroupBy = false;
|
|
|
106
|
+ boolean addDisabledGroupBy = false;
|
|
|
107
|
+ if (groupByChanged) {
|
|
|
108
|
+ // check if old navigation request is compliant with new groupBy value
|
|
|
109
|
+ if (newGroupByValue == null) {
|
|
|
110
|
+ if (!navigationRequest.isLoadNullGroupBy()) {
|
|
|
111
|
+ // need to add null groupBy in navigation request
|
|
|
112
|
+ changeNavigationRequest = true;
|
|
|
113
|
+ addNullGroupBy = true;
|
|
|
114
|
+ }
|
|
|
115
|
+ } else {
|
|
|
116
|
+ if (oldGroupByDto.definition().isQualitative() && !navigationRequest.isLoadDisabledGroupBy()) {
|
|
|
117
|
+ ReferentialDtoReference groupByObjectValue = (ReferentialDtoReference) oldGroupByDto.definition().toGroupByObjectValue(bean);
|
|
|
118
|
+ if (groupByObjectValue.isDisabled()) {
|
|
|
119
|
+ // need to add disabled groupBy in navigation request
|
|
|
120
|
+ changeNavigationRequest = true;
|
|
|
121
|
+ addDisabledGroupBy = true;
|
|
|
122
|
+ }
|
|
|
123
|
+ }
|
|
|
124
|
+ }
|
|
|
125
|
+ }
|
|
|
126
|
+ this.changeNavigationRequest = changeNavigationRequest;
|
|
|
127
|
+ this.addNullGroupBy = addNullGroupBy;
|
|
|
128
|
+ this.addDisabledGroupBy = addDisabledGroupBy;
|
|
|
129
|
+ }
|
|
|
130
|
+
|
|
|
131
|
+ public void warnUserIfNecessary(U ui) {
|
|
|
132
|
+ if (!isChangeNavigationRequest()) {
|
|
|
133
|
+ return;
|
|
|
134
|
+ }
|
|
|
135
|
+ // display message to user
|
|
|
136
|
+ if (isAddNullGroupBy()) {
|
|
|
137
|
+ // add null groupBy in navigation request
|
|
|
138
|
+ JOptionPanes.displayWarning(ui, I18n.t("observe.ui.tree.need.reload.title"), I18n.t("observe.ui.tree.need.reload.message"));
|
|
|
139
|
+ return;
|
|
|
140
|
+ }
|
|
|
141
|
+ if (isAddDisabledGroupBy()) {
|
|
|
142
|
+ // add disabled groupBy in navigation request
|
|
|
143
|
+ JOptionPanes.displayWarning(ui, I18n.t("observe.ui.tree.need.reload.title"), I18n.t("observe.ui.tree.need.reload.message"));
|
|
|
144
|
+ }
|
|
|
145
|
+ }
|
|
|
146
|
+
|
|
|
147
|
+ public DataGroupByDto<D> getOldGroupByDto() {
|
|
|
148
|
+ return oldGroupByDto;
|
|
|
149
|
+ }
|
|
|
150
|
+
|
|
|
151
|
+ public ToolkitTreeFlatModelRootRequest getNavigationRequest() {
|
|
|
152
|
+ return navigationRequest;
|
|
|
153
|
+ }
|
|
|
154
|
+
|
|
|
155
|
+ public D getBean() {
|
|
|
156
|
+ return bean;
|
|
|
157
|
+ }
|
|
|
158
|
+
|
|
|
159
|
+ public String getNewGroupByValue() {
|
|
|
160
|
+ return newGroupByValue;
|
|
|
161
|
+ }
|
|
|
162
|
+
|
|
|
163
|
+ public boolean isGroupByChanged() {
|
|
|
164
|
+ return groupByChanged;
|
|
|
165
|
+ }
|
|
|
166
|
+
|
|
|
167
|
+ public boolean isChangeNavigationRequest() {
|
|
|
168
|
+ return changeNavigationRequest;
|
|
|
169
|
+ }
|
|
|
170
|
+
|
|
|
171
|
+ public boolean isAddNullGroupBy() {
|
|
|
172
|
+ return addNullGroupBy;
|
|
|
173
|
+ }
|
|
|
174
|
+
|
|
|
175
|
+ public boolean isAddDisabledGroupBy() {
|
|
|
176
|
+ return addDisabledGroupBy;
|
|
|
177
|
+ }
|
|
|
178
|
+
|
|
|
179
|
+ NavigationResult updateNavigationResult(NavigationTreeModel navigationTreeModel) {
|
|
|
180
|
+ NavigationTreeConfig navigationTreeConfig = navigationTreeModel.getConfig();
|
|
|
181
|
+ if (isAddNullGroupBy()) {
|
|
|
182
|
+ navigationTreeConfig.setLoadNullGroupBy(true);
|
|
|
183
|
+ navigationTreeModel.getClientConfig().saveTreeConfig(navigationTreeConfig);
|
|
|
184
|
+ navigationRequest.setLoadNullGroupBy(true);
|
|
|
185
|
+ }
|
|
|
186
|
+ if (isAddDisabledGroupBy()) {
|
|
|
187
|
+ navigationTreeConfig.setLoadDisabledGroupBy(true);
|
|
|
188
|
+ navigationRequest.setLoadDisabledGroupBy(true);
|
|
|
189
|
+ navigationTreeModel.getClientConfig().saveTreeConfig(navigationTreeConfig);
|
|
|
190
|
+ }
|
|
|
191
|
+ return navigationTreeModel.updateNavigationResult();
|
|
|
192
|
+ }
|
|
|
193
|
+ }
|
|
|
194
|
+
|
|
82
|
195
|
public ContentRootOpenableUINavigationNode updateReference(NavigationUI navigationUI,
|
|
83
|
196
|
ContentRootOpenableUINavigationNode node,
|
|
84
|
|
- String id,
|
|
85
|
|
- DataGroupByDto<D> oldGroupByDto,
|
|
86
|
|
- boolean groupByChanged,
|
|
87
|
|
- String newGroupByValue) {
|
|
|
197
|
+ ComputeNavigationRequestChange<D, U> computeNavigationRequestChange) {
|
|
88
|
198
|
boolean notPersisted = node.getInitializer().isNotPersisted();
|
|
|
199
|
+ String id = computeNavigationRequestChange.getBean().getId();
|
|
|
200
|
+ DataGroupByDto<D> oldGroupByDto = computeNavigationRequestChange.getOldGroupByDto();
|
|
|
201
|
+ boolean groupByChanged = computeNavigationRequestChange.isGroupByChanged();
|
|
|
202
|
+ String newGroupByValue = computeNavigationRequestChange.getNewGroupByValue();
|
|
89
|
203
|
ContentRootListUINavigationNode parent = node.getParent();
|
|
90
|
204
|
if (groupByChanged) {
|
|
91
|
205
|
// the navigation must be updated, new parent groupBy value has changed
|
|
92
|
|
- NavigationResult navigationResult = navigationUI.getTree().getModel().updateNavigationResult();
|
|
|
206
|
+ NavigationResult navigationResult = computeNavigationRequestChange.updateNavigationResult(navigationUI.getTree().getModel());
|
|
93
|
207
|
// groupBy has changed (remove node from parent)
|
|
94
|
208
|
RootNavigationNode rootNode = (RootNavigationNode) node.getRoot();
|
|
95
|
209
|
node.removeFromParent();
|