Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: cdce373b by Tony Chemit at 2022-04-19T15:55:20+02:00 Amélioration de la sélection des marées dans les interfaces graphiques de déplacement. - See #2270 - - - - - 3ae09217 by Tony Chemit at 2022-04-19T15:57:59+02:00 Amélioration de la sélection des marées dans les interfaces graphiques de déplacement. - See #2270 - - - - - 2 changed files: - client/datasource/actions/src/main/i18n/getters/java.getter - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/move/layout/MoveLayoutRequestBuilder.java Changes: ===================================== client/datasource/actions/src/main/i18n/getters/java.getter ===================================== @@ -15,6 +15,7 @@ observe.ui.action.close observe.ui.action.close.synchro.tip observe.ui.action.config.export.required.write.data observe.ui.action.config.left.datasource.required.write.data + observe.ui.action.configuration.tip observe.ui.action.continue observe.ui.action.copy.to.clipBoard observe.ui.action.do.backup.tip @@ -25,7 +26,6 @@ observe.ui.action.goto.previous.stage.tip observe.ui.action.info.storage.tip observe.ui.choice.cancel observe.ui.choice.replace -observe.ui.content.action.configure.tip observe.ui.datasource.actions.config.data.sources.equals observe.ui.datasource.editor.actions.activity.pairing observe.ui.datasource.editor.actions.consolidate ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/move/layout/MoveLayoutRequestBuilder.java ===================================== @@ -22,10 +22,11 @@ package fr.ird.observe.client.datasource.editor.api.content.actions.move.layout; * #L% */ -import fr.ird.observe.client.ClientUIContextApplicationComponent; +import fr.ird.observe.client.WithClientUIContextApi; import fr.ird.observe.client.datasource.editor.api.DataSourceEditor; import fr.ird.observe.client.datasource.editor.api.ObserveKeyStrokesEditorApi; import fr.ird.observe.client.datasource.editor.api.content.actions.mode.ChangeMode; +import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTreeModel; import fr.ird.observe.client.datasource.usage.UsageUIHandlerSupport; import fr.ird.observe.client.util.DtoIconHelper; import fr.ird.observe.client.util.UIHelper; @@ -33,7 +34,9 @@ import fr.ird.observe.dto.BusinessDto; import fr.ird.observe.dto.ToolkitIdDtoBean; import fr.ird.observe.dto.ToolkitIdLabel; import fr.ird.observe.dto.data.DataDto; +import fr.ird.observe.dto.data.DataGroupByDto; import fr.ird.observe.dto.data.DataGroupByParameter; +import fr.ird.observe.dto.reference.DataGroupByDtoSet; import fr.ird.observe.navigation.id.CloseNodeVetoException; import fr.ird.observe.navigation.id.IdNode; import fr.ird.observe.services.service.data.MoveLayoutRequest; @@ -49,6 +52,7 @@ import javax.swing.ActionMap; import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JLayeredPane; @@ -62,6 +66,7 @@ import java.awt.BorderLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; import java.util.LinkedHashSet; import java.util.List; import java.util.Objects; @@ -79,7 +84,7 @@ import static io.ultreia.java4all.i18n.I18n.t; * @since 8.0.1 */ @SuppressWarnings("UnusedReturnValue") -public class MoveLayoutRequestBuilder { +public class MoveLayoutRequestBuilder implements WithClientUIContextApi { private static final Logger log = LogManager.getLogger(MoveLayoutRequestBuilder.class); /** @@ -102,6 +107,10 @@ public class MoveLayoutRequestBuilder { * Apply action. */ private final AbstractAction applyAction; + /** + * Apply action. + */ + private final AbstractAction configureAction; /** * Optional edit node. */ @@ -215,12 +224,23 @@ public class MoveLayoutRequestBuilder { applyAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { - log.info("Apply :)"); jButton.doClick(); } }; applyAction.putValue(Action.ACCELERATOR_KEY, keyStroke); applyAction.putValue(Action.NAME, t); + keyStroke = ObserveKeyStrokesEditorApi.KEY_STROKE_INSERT_CONFIGURE; + t = ObserveKeyStrokesEditorApi.suffixTextWithKeyStroke(t("observe.ui.tree.action.configure.tip"), keyStroke); + configureAction = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + log.info("Do configure :)"); + + } + }; + configureAction.putValue(Action.LARGE_ICON_KEY, UIHelper.getUIManagerActionIcon("generate")); + configureAction.putValue(Action.ACCELERATOR_KEY, keyStroke); + configureAction.putValue(Action.NAME, t); } private MoveLayoutRequestBuilder setEditNode(IdNode<?> editNode) { @@ -256,7 +276,7 @@ public class MoveLayoutRequestBuilder { Objects.requireNonNull(availableLayoutTypes, "No availableLayoutTypes declared in builder"); DataGroupByParameter groupBy = Objects.requireNonNull(this.groupByValueSupplier, "No groupByValue supplier set.").get(); List<ToolkitIdLabel> parentCandidates = Objects.requireNonNull(this.parentCandidates, "No parent candidates set.").apply(groupBy, oldParentId.getId()); - ToolkitIdLabel newParentId = askNewParent(parentCandidates, askNewParentTitle, askNewParentMessage).orElse(null); + ToolkitIdLabel newParentId = askNewParent(dataSourceEditor, groupBy, this.parentCandidates, parentCandidates, askNewParentTitle, askNewParentMessage).orElse(null); if (newParentId == null) { return Optional.empty(); } @@ -274,15 +294,15 @@ public class MoveLayoutRequestBuilder { return Optional.of(new MoveLayoutRequest(selectedLayoutTypes, oldParentId.getId(), newParentId.getId(), selectTarget.isSelected())); } - private Optional<ToolkitIdLabel> askNewParent(List<ToolkitIdLabel> parentCandidates, String dialogTitle, String dialogMessage) { - Decorator decorator = ClientUIContextApplicationComponent.value().getDecoratorService().getToolkitIdLabelDecoratorByType(parentTargetDtoType); + private Optional<ToolkitIdLabel> askNewParent(DataSourceEditor dataSourceEditor, DataGroupByParameter navigationGroupBy, BiFunction<DataGroupByParameter, String, List<ToolkitIdLabel>> candidates, List<ToolkitIdLabel> parentCandidates, String dialogTitle, String dialogMessage) { + Decorator decorator = getDecoratorService().getToolkitIdLabelDecoratorByType(parentTargetDtoType); FilterableComboBox<ToolkitIdLabel> editor = UIHelper.newToolkitIdLabelFilterableComboBox(parentTargetDtoType, decorator, parentCandidates); String continueActionText = (String) applyAction.getValue(Action.NAME); Object[] options = {continueActionText}; JPanel panel = new JPanel(new BorderLayout(3, 3)); - JPanel panelNorth = new JPanel(new BorderLayout()); + JPanel panelMessages = new JPanel(new BorderLayout(3, 3)); boolean single = availableLayoutTypes.size() == 1; @@ -297,20 +317,59 @@ public class MoveLayoutRequestBuilder { panelMessages.add(BorderLayout.NORTH, new JLabel(message)); - JPanel panelMessage2 = new JPanel(new GridLayout(0, 1)); - panelMessage2.add(new JLabel()); - panelMessage2.add(new JLabel(t(dialogMessage))); - panelMessages.add(BorderLayout.SOUTH, panelMessage2); - panelNorth.add(BorderLayout.NORTH, panelMessages); - panelNorth.add(BorderLayout.CENTER, editor); + NavigationTreeModel navigationTreeModel = dataSourceEditor.getNavigationUI().getTree().getModel(); + + DataGroupByParameter dataGroupByParameter = groupByValueSupplier.get(); + + String statisticsText = dataSourceEditor.getNavigationUI().getStatisticsText(); + + DataGroupByDtoSet<?, ?> groupBy = navigationTreeModel.getRoot().getInitializer().getGroupBy(); + List<?> groupByValues = groupBy.toList(); + String groupByParameterValue = dataGroupByParameter.getValue(); + + JPanel panelConfiguration = new JPanel(new GridLayout(0, 1)); + + JPanel groupByNamePanel = new JPanel(new BorderLayout()); + JButton configurationGroupByNameChange = new JButton(configureAction); + //FIXME Implements the action + configurationGroupByNameChange.setEnabled(false); + //FIXME I18n + groupByNamePanel.add(BorderLayout.WEST, new JLabel("Configuration des critères : ")); + groupByNamePanel.add(BorderLayout.CENTER, new JLabel(statisticsText.substring(0, statisticsText.lastIndexOf(" /")))); + groupByNamePanel.add(BorderLayout.EAST, configurationGroupByNameChange); + panelConfiguration.add(groupByNamePanel); + JComboBox<Object> groupByValuesEditor = new JComboBox<>(groupByValues.toArray()); + Object selectedGroupByValue = groupBy.tryGetReferenceById(groupByParameterValue).orElse(null); + groupByValuesEditor.setSelectedItem(selectedGroupByValue); + panelConfiguration.add(groupByValuesEditor); + panelConfiguration.add(new JLabel(t(dialogMessage))); + panelConfiguration.add(editor); + + groupByValuesEditor.addItemListener(e -> { + if (e.getStateChange() != ItemEvent.SELECTED) { + return; + } + DataGroupByDto<?> newGroupByValue = (DataGroupByDto<?>) e.getItem(); + DataGroupByParameter newGroupBy = new DataGroupByParameter(navigationGroupBy.getGroupByName(), navigationGroupBy.getGroupByFlavor(), newGroupByValue.getFilterValue()); + + List<ToolkitIdLabel> newParentCandidates = candidates.apply(newGroupBy, oldParentId.getId()); + ToolkitIdLabel selectedItem = editor.getModel().getSelectedItem(); + editor.setData(newParentCandidates); + editor.setSelectedItem(newParentCandidates.contains(selectedItem) ? selectedItem : null); + + if (editor.getCombobox().getModel().getSize() == 1) { + // auto-select unique data + editor.setSelectedItem(newParentCandidates.get(0)); + } + SwingUtilities.invokeLater(editor.getCombobox()::requestFocus); + }); JPanel panelSelectTarget = new JPanel(new GridLayout(0, 1)); //FIXME:Move Add a default client configuration option to set this value selectTarget.setSelected(true); panelSelectTarget.add(new JLabel()); panelSelectTarget.add(selectTarget); - panelNorth.add(BorderLayout.SOUTH, panelSelectTarget); JPanel panelSouth = new JPanel(new GridLayout(0, 1)); panelSouth.add(BorderLayout.NORTH, new JSeparator(SwingConstants.HORIZONTAL)); @@ -318,19 +377,27 @@ public class MoveLayoutRequestBuilder { information.setFont(information.getFont().deriveFont(Font.ITALIC).deriveFont(11f)); panelSouth.add(BorderLayout.CENTER, information); + JPanel panelNorth = new JPanel(new BorderLayout()); + panelNorth.add(BorderLayout.NORTH, panelMessages); + panelNorth.add(BorderLayout.CENTER, panelConfiguration); + panelNorth.add(BorderLayout.SOUTH, panelSelectTarget); + panel.add(BorderLayout.NORTH, panelNorth); panel.add(BorderLayout.SOUTH, panelSouth); InputMap inputMap1 = panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap1.put((KeyStroke) selectTargetAction.getValue(Action.ACCELERATOR_KEY), "selectTarget"); + inputMap1.put((KeyStroke) configureAction.getValue(Action.ACCELERATOR_KEY), "configure"); InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put((KeyStroke) selectTargetAction.getValue(Action.ACCELERATOR_KEY), "selectTarget"); inputMap.put((KeyStroke) applyAction.getValue(Action.ACCELERATOR_KEY), "apply"); + inputMap.put((KeyStroke) configureAction.getValue(Action.ACCELERATOR_KEY), "configure"); ActionMap actionMap = panel.getActionMap(); actionMap.put("selectTarget", selectTargetAction); actionMap.put("apply", applyAction); + actionMap.put("configure", configureAction); optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[0]) { @@ -354,7 +421,6 @@ public class MoveLayoutRequestBuilder { Objects.requireNonNull(jButton).setIcon(UIHelper.getUIManagerActionIcon("move")); jButton.setEnabled(false); editor.getModel().addPropertyChangeListener("selectedItem", evt -> jButton.setEnabled(canMove(evt.getNewValue()))); - if (!single) { JPanel typesPanel = new JPanel(new GridLayout(0, 1)); int index = 1; @@ -382,10 +448,10 @@ public class MoveLayoutRequestBuilder { typesPanel.add(typeEditor); index++; } - panelMessages.add(BorderLayout.CENTER, typesPanel); } - int response = UIHelper.askUser(ClientUIContextApplicationComponent.value().getMainUI(), optionPane, t(dialogTitle), options); + panelMessages.add(BorderLayout.SOUTH, new JSeparator(SwingConstants.HORIZONTAL)); + int response = UIHelper.askUser(getMainUI(), optionPane, t(dialogTitle), options); ToolkitIdLabel newParent = null; if (response == 0) { View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/89ef5bec7e5a959077cc2510a... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/89ef5bec7e5a959077cc2510a... You're receiving this email because of your account on gitlab.com.