| ... |
... |
@@ -22,10 +22,11 @@ package fr.ird.observe.client.datasource.editor.api.content.actions.move.layout; |
|
22
|
22
|
* #L%
|
|
23
|
23
|
*/
|
|
24
|
24
|
|
|
25
|
|
-import fr.ird.observe.client.ClientUIContextApplicationComponent;
|
|
|
25
|
+import fr.ird.observe.client.WithClientUIContextApi;
|
|
26
|
26
|
import fr.ird.observe.client.datasource.editor.api.DataSourceEditor;
|
|
27
|
27
|
import fr.ird.observe.client.datasource.editor.api.ObserveKeyStrokesEditorApi;
|
|
28
|
28
|
import fr.ird.observe.client.datasource.editor.api.content.actions.mode.ChangeMode;
|
|
|
29
|
+import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTreeModel;
|
|
29
|
30
|
import fr.ird.observe.client.datasource.usage.UsageUIHandlerSupport;
|
|
30
|
31
|
import fr.ird.observe.client.util.DtoIconHelper;
|
|
31
|
32
|
import fr.ird.observe.client.util.UIHelper;
|
| ... |
... |
@@ -33,7 +34,9 @@ import fr.ird.observe.dto.BusinessDto; |
|
33
|
34
|
import fr.ird.observe.dto.ToolkitIdDtoBean;
|
|
34
|
35
|
import fr.ird.observe.dto.ToolkitIdLabel;
|
|
35
|
36
|
import fr.ird.observe.dto.data.DataDto;
|
|
|
37
|
+import fr.ird.observe.dto.data.DataGroupByDto;
|
|
36
|
38
|
import fr.ird.observe.dto.data.DataGroupByParameter;
|
|
|
39
|
+import fr.ird.observe.dto.reference.DataGroupByDtoSet;
|
|
37
|
40
|
import fr.ird.observe.navigation.id.CloseNodeVetoException;
|
|
38
|
41
|
import fr.ird.observe.navigation.id.IdNode;
|
|
39
|
42
|
import fr.ird.observe.services.service.data.MoveLayoutRequest;
|
| ... |
... |
@@ -49,6 +52,7 @@ import javax.swing.ActionMap; |
|
49
|
52
|
import javax.swing.InputMap;
|
|
50
|
53
|
import javax.swing.JButton;
|
|
51
|
54
|
import javax.swing.JCheckBox;
|
|
|
55
|
+import javax.swing.JComboBox;
|
|
52
|
56
|
import javax.swing.JComponent;
|
|
53
|
57
|
import javax.swing.JLabel;
|
|
54
|
58
|
import javax.swing.JLayeredPane;
|
| ... |
... |
@@ -62,6 +66,7 @@ import java.awt.BorderLayout; |
|
62
|
66
|
import java.awt.Font;
|
|
63
|
67
|
import java.awt.GridLayout;
|
|
64
|
68
|
import java.awt.event.ActionEvent;
|
|
|
69
|
+import java.awt.event.ItemEvent;
|
|
65
|
70
|
import java.util.LinkedHashSet;
|
|
66
|
71
|
import java.util.List;
|
|
67
|
72
|
import java.util.Objects;
|
| ... |
... |
@@ -79,7 +84,7 @@ import static io.ultreia.java4all.i18n.I18n.t; |
|
79
|
84
|
* @since 8.0.1
|
|
80
|
85
|
*/
|
|
81
|
86
|
@SuppressWarnings("UnusedReturnValue")
|
|
82
|
|
-public class MoveLayoutRequestBuilder {
|
|
|
87
|
+public class MoveLayoutRequestBuilder implements WithClientUIContextApi {
|
|
83
|
88
|
|
|
84
|
89
|
private static final Logger log = LogManager.getLogger(MoveLayoutRequestBuilder.class);
|
|
85
|
90
|
/**
|
| ... |
... |
@@ -102,6 +107,10 @@ public class MoveLayoutRequestBuilder { |
|
102
|
107
|
* Apply action.
|
|
103
|
108
|
*/
|
|
104
|
109
|
private final AbstractAction applyAction;
|
|
|
110
|
+ /**
|
|
|
111
|
+ * Apply action.
|
|
|
112
|
+ */
|
|
|
113
|
+ private final AbstractAction configureAction;
|
|
105
|
114
|
/**
|
|
106
|
115
|
* Optional edit node.
|
|
107
|
116
|
*/
|
| ... |
... |
@@ -215,12 +224,23 @@ public class MoveLayoutRequestBuilder { |
|
215
|
224
|
applyAction = new AbstractAction() {
|
|
216
|
225
|
@Override
|
|
217
|
226
|
public void actionPerformed(ActionEvent e) {
|
|
218
|
|
- log.info("Apply :)");
|
|
219
|
227
|
jButton.doClick();
|
|
220
|
228
|
}
|
|
221
|
229
|
};
|
|
222
|
230
|
applyAction.putValue(Action.ACCELERATOR_KEY, keyStroke);
|
|
223
|
231
|
applyAction.putValue(Action.NAME, t);
|
|
|
232
|
+ keyStroke = ObserveKeyStrokesEditorApi.KEY_STROKE_INSERT_CONFIGURE;
|
|
|
233
|
+ t = ObserveKeyStrokesEditorApi.suffixTextWithKeyStroke(t("observe.ui.tree.action.configure.tip"), keyStroke);
|
|
|
234
|
+ configureAction = new AbstractAction() {
|
|
|
235
|
+ @Override
|
|
|
236
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
237
|
+ log.info("Do configure :)");
|
|
|
238
|
+
|
|
|
239
|
+ }
|
|
|
240
|
+ };
|
|
|
241
|
+ configureAction.putValue(Action.LARGE_ICON_KEY, UIHelper.getUIManagerActionIcon("generate"));
|
|
|
242
|
+ configureAction.putValue(Action.ACCELERATOR_KEY, keyStroke);
|
|
|
243
|
+ configureAction.putValue(Action.NAME, t);
|
|
224
|
244
|
}
|
|
225
|
245
|
|
|
226
|
246
|
private MoveLayoutRequestBuilder setEditNode(IdNode<?> editNode) {
|
| ... |
... |
@@ -256,7 +276,7 @@ public class MoveLayoutRequestBuilder { |
|
256
|
276
|
Objects.requireNonNull(availableLayoutTypes, "No availableLayoutTypes declared in builder");
|
|
257
|
277
|
DataGroupByParameter groupBy = Objects.requireNonNull(this.groupByValueSupplier, "No groupByValue supplier set.").get();
|
|
258
|
278
|
List<ToolkitIdLabel> parentCandidates = Objects.requireNonNull(this.parentCandidates, "No parent candidates set.").apply(groupBy, oldParentId.getId());
|
|
259
|
|
- ToolkitIdLabel newParentId = askNewParent(parentCandidates, askNewParentTitle, askNewParentMessage).orElse(null);
|
|
|
279
|
+ ToolkitIdLabel newParentId = askNewParent(dataSourceEditor, groupBy, this.parentCandidates, parentCandidates, askNewParentTitle, askNewParentMessage).orElse(null);
|
|
260
|
280
|
if (newParentId == null) {
|
|
261
|
281
|
return Optional.empty();
|
|
262
|
282
|
}
|
| ... |
... |
@@ -274,15 +294,15 @@ public class MoveLayoutRequestBuilder { |
|
274
|
294
|
return Optional.of(new MoveLayoutRequest(selectedLayoutTypes, oldParentId.getId(), newParentId.getId(), selectTarget.isSelected()));
|
|
275
|
295
|
}
|
|
276
|
296
|
|
|
277
|
|
- private Optional<ToolkitIdLabel> askNewParent(List<ToolkitIdLabel> parentCandidates, String dialogTitle, String dialogMessage) {
|
|
278
|
|
- Decorator decorator = ClientUIContextApplicationComponent.value().getDecoratorService().getToolkitIdLabelDecoratorByType(parentTargetDtoType);
|
|
|
297
|
+ private Optional<ToolkitIdLabel> askNewParent(DataSourceEditor dataSourceEditor, DataGroupByParameter navigationGroupBy, BiFunction<DataGroupByParameter, String, List<ToolkitIdLabel>> candidates, List<ToolkitIdLabel> parentCandidates, String dialogTitle, String dialogMessage) {
|
|
|
298
|
+ Decorator decorator = getDecoratorService().getToolkitIdLabelDecoratorByType(parentTargetDtoType);
|
|
279
|
299
|
FilterableComboBox<ToolkitIdLabel> editor = UIHelper.newToolkitIdLabelFilterableComboBox(parentTargetDtoType, decorator, parentCandidates);
|
|
280
|
300
|
|
|
281
|
301
|
String continueActionText = (String) applyAction.getValue(Action.NAME);
|
|
282
|
302
|
Object[] options = {continueActionText};
|
|
283
|
303
|
JPanel panel = new JPanel(new BorderLayout(3, 3));
|
|
284
|
304
|
|
|
285
|
|
- JPanel panelNorth = new JPanel(new BorderLayout());
|
|
|
305
|
+
|
|
286
|
306
|
JPanel panelMessages = new JPanel(new BorderLayout(3, 3));
|
|
287
|
307
|
boolean single = availableLayoutTypes.size() == 1;
|
|
288
|
308
|
|
| ... |
... |
@@ -297,20 +317,59 @@ public class MoveLayoutRequestBuilder { |
|
297
|
317
|
|
|
298
|
318
|
panelMessages.add(BorderLayout.NORTH, new JLabel(message));
|
|
299
|
319
|
|
|
300
|
|
- JPanel panelMessage2 = new JPanel(new GridLayout(0, 1));
|
|
301
|
|
- panelMessage2.add(new JLabel());
|
|
302
|
|
- panelMessage2.add(new JLabel(t(dialogMessage)));
|
|
303
|
|
- panelMessages.add(BorderLayout.SOUTH, panelMessage2);
|
|
304
|
320
|
|
|
305
|
|
- panelNorth.add(BorderLayout.NORTH, panelMessages);
|
|
306
|
|
- panelNorth.add(BorderLayout.CENTER, editor);
|
|
|
321
|
+ NavigationTreeModel navigationTreeModel = dataSourceEditor.getNavigationUI().getTree().getModel();
|
|
|
322
|
+
|
|
|
323
|
+ DataGroupByParameter dataGroupByParameter = groupByValueSupplier.get();
|
|
|
324
|
+
|
|
|
325
|
+ String statisticsText = dataSourceEditor.getNavigationUI().getStatisticsText();
|
|
|
326
|
+
|
|
|
327
|
+ DataGroupByDtoSet<?, ?> groupBy = navigationTreeModel.getRoot().getInitializer().getGroupBy();
|
|
|
328
|
+ List<?> groupByValues = groupBy.toList();
|
|
|
329
|
+ String groupByParameterValue = dataGroupByParameter.getValue();
|
|
|
330
|
+
|
|
|
331
|
+ JPanel panelConfiguration = new JPanel(new GridLayout(0, 1));
|
|
|
332
|
+
|
|
|
333
|
+ JPanel groupByNamePanel = new JPanel(new BorderLayout());
|
|
|
334
|
+ JButton configurationGroupByNameChange = new JButton(configureAction);
|
|
|
335
|
+ //FIXME Implements the action
|
|
|
336
|
+ configurationGroupByNameChange.setEnabled(false);
|
|
|
337
|
+ //FIXME I18n
|
|
|
338
|
+ groupByNamePanel.add(BorderLayout.WEST, new JLabel("Configuration des critères : "));
|
|
|
339
|
+ groupByNamePanel.add(BorderLayout.CENTER, new JLabel(statisticsText.substring(0, statisticsText.lastIndexOf(" /"))));
|
|
|
340
|
+ groupByNamePanel.add(BorderLayout.EAST, configurationGroupByNameChange);
|
|
|
341
|
+ panelConfiguration.add(groupByNamePanel);
|
|
|
342
|
+ JComboBox<Object> groupByValuesEditor = new JComboBox<>(groupByValues.toArray());
|
|
|
343
|
+ Object selectedGroupByValue = groupBy.tryGetReferenceById(groupByParameterValue).orElse(null);
|
|
|
344
|
+ groupByValuesEditor.setSelectedItem(selectedGroupByValue);
|
|
|
345
|
+ panelConfiguration.add(groupByValuesEditor);
|
|
|
346
|
+ panelConfiguration.add(new JLabel(t(dialogMessage)));
|
|
|
347
|
+ panelConfiguration.add(editor);
|
|
|
348
|
+
|
|
|
349
|
+ groupByValuesEditor.addItemListener(e -> {
|
|
|
350
|
+ if (e.getStateChange() != ItemEvent.SELECTED) {
|
|
|
351
|
+ return;
|
|
|
352
|
+ }
|
|
|
353
|
+ DataGroupByDto<?> newGroupByValue = (DataGroupByDto<?>) e.getItem();
|
|
|
354
|
+ DataGroupByParameter newGroupBy = new DataGroupByParameter(navigationGroupBy.getGroupByName(), navigationGroupBy.getGroupByFlavor(), newGroupByValue.getFilterValue());
|
|
|
355
|
+
|
|
|
356
|
+ List<ToolkitIdLabel> newParentCandidates = candidates.apply(newGroupBy, oldParentId.getId());
|
|
|
357
|
+ ToolkitIdLabel selectedItem = editor.getModel().getSelectedItem();
|
|
|
358
|
+ editor.setData(newParentCandidates);
|
|
|
359
|
+ editor.setSelectedItem(newParentCandidates.contains(selectedItem) ? selectedItem : null);
|
|
|
360
|
+
|
|
|
361
|
+ if (editor.getCombobox().getModel().getSize() == 1) {
|
|
|
362
|
+ // auto-select unique data
|
|
|
363
|
+ editor.setSelectedItem(newParentCandidates.get(0));
|
|
|
364
|
+ }
|
|
|
365
|
+ SwingUtilities.invokeLater(editor.getCombobox()::requestFocus);
|
|
|
366
|
+ });
|
|
307
|
367
|
|
|
308
|
368
|
JPanel panelSelectTarget = new JPanel(new GridLayout(0, 1));
|
|
309
|
369
|
//FIXME:Move Add a default client configuration option to set this value
|
|
310
|
370
|
selectTarget.setSelected(true);
|
|
311
|
371
|
panelSelectTarget.add(new JLabel());
|
|
312
|
372
|
panelSelectTarget.add(selectTarget);
|
|
313
|
|
- panelNorth.add(BorderLayout.SOUTH, panelSelectTarget);
|
|
314
|
373
|
|
|
315
|
374
|
JPanel panelSouth = new JPanel(new GridLayout(0, 1));
|
|
316
|
375
|
panelSouth.add(BorderLayout.NORTH, new JSeparator(SwingConstants.HORIZONTAL));
|
| ... |
... |
@@ -318,19 +377,27 @@ public class MoveLayoutRequestBuilder { |
|
318
|
377
|
information.setFont(information.getFont().deriveFont(Font.ITALIC).deriveFont(11f));
|
|
319
|
378
|
panelSouth.add(BorderLayout.CENTER, information);
|
|
320
|
379
|
|
|
|
380
|
+ JPanel panelNorth = new JPanel(new BorderLayout());
|
|
|
381
|
+ panelNorth.add(BorderLayout.NORTH, panelMessages);
|
|
|
382
|
+ panelNorth.add(BorderLayout.CENTER, panelConfiguration);
|
|
|
383
|
+ panelNorth.add(BorderLayout.SOUTH, panelSelectTarget);
|
|
|
384
|
+
|
|
321
|
385
|
panel.add(BorderLayout.NORTH, panelNorth);
|
|
322
|
386
|
panel.add(BorderLayout.SOUTH, panelSouth);
|
|
323
|
387
|
|
|
324
|
388
|
InputMap inputMap1 = panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
|
325
|
389
|
inputMap1.put((KeyStroke) selectTargetAction.getValue(Action.ACCELERATOR_KEY), "selectTarget");
|
|
|
390
|
+ inputMap1.put((KeyStroke) configureAction.getValue(Action.ACCELERATOR_KEY), "configure");
|
|
326
|
391
|
|
|
327
|
392
|
InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
|
328
|
393
|
inputMap.put((KeyStroke) selectTargetAction.getValue(Action.ACCELERATOR_KEY), "selectTarget");
|
|
329
|
394
|
inputMap.put((KeyStroke) applyAction.getValue(Action.ACCELERATOR_KEY), "apply");
|
|
|
395
|
+ inputMap.put((KeyStroke) configureAction.getValue(Action.ACCELERATOR_KEY), "configure");
|
|
330
|
396
|
|
|
331
|
397
|
ActionMap actionMap = panel.getActionMap();
|
|
332
|
398
|
actionMap.put("selectTarget", selectTargetAction);
|
|
333
|
399
|
actionMap.put("apply", applyAction);
|
|
|
400
|
+ actionMap.put("configure", configureAction);
|
|
334
|
401
|
|
|
335
|
402
|
|
|
336
|
403
|
optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[0]) {
|
| ... |
... |
@@ -354,7 +421,6 @@ public class MoveLayoutRequestBuilder { |
|
354
|
421
|
Objects.requireNonNull(jButton).setIcon(UIHelper.getUIManagerActionIcon("move"));
|
|
355
|
422
|
jButton.setEnabled(false);
|
|
356
|
423
|
editor.getModel().addPropertyChangeListener("selectedItem", evt -> jButton.setEnabled(canMove(evt.getNewValue())));
|
|
357
|
|
-
|
|
358
|
424
|
if (!single) {
|
|
359
|
425
|
JPanel typesPanel = new JPanel(new GridLayout(0, 1));
|
|
360
|
426
|
int index = 1;
|
| ... |
... |
@@ -382,10 +448,10 @@ public class MoveLayoutRequestBuilder { |
|
382
|
448
|
typesPanel.add(typeEditor);
|
|
383
|
449
|
index++;
|
|
384
|
450
|
}
|
|
385
|
|
-
|
|
386
|
451
|
panelMessages.add(BorderLayout.CENTER, typesPanel);
|
|
387
|
452
|
}
|
|
388
|
|
- int response = UIHelper.askUser(ClientUIContextApplicationComponent.value().getMainUI(), optionPane, t(dialogTitle), options);
|
|
|
453
|
+ panelMessages.add(BorderLayout.SOUTH, new JSeparator(SwingConstants.HORIZONTAL));
|
|
|
454
|
+ int response = UIHelper.askUser(getMainUI(), optionPane, t(dialogTitle), options);
|
|
389
|
455
|
|
|
390
|
456
|
ToolkitIdLabel newParent = null;
|
|
391
|
457
|
if (response == 0) {
|