Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
ee03d54b
by Tony Chemit at 2023-11-28T17:19:37+01:00
-
b5b89df8
by Tony Chemit at 2023-11-28T17:20:29+01:00
-
b3f7a158
by Tony Chemit at 2023-11-28T17:33:20+01:00
-
c4dec149
by Tony Chemit at 2023-11-28T17:34:08+01:00
-
cfc0c2f3
by Tony Chemit at 2023-11-28T17:34:26+01:00
3 changed files:
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/mode/ChangeModeProducer.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/list/ContentListUIHandler.java
- client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationTreeShowPopupHandler.java
Changes:
| ... | ... | @@ -45,6 +45,8 @@ public class ChangeModeProducer<U extends ContentUI> { |
| 45 | 45 | private final U ui;
|
| 46 | 46 | private final PropertyChangeListener listener;
|
| 47 | 47 | |
| 48 | + private boolean adjusting;
|
|
| 49 | + |
|
| 48 | 50 | public ChangeModeProducer(U ui, ChangeModeRequest request, String... properties) {
|
| 49 | 51 | this.ui = Objects.requireNonNull(ui);
|
| 50 | 52 | this.request = Objects.requireNonNull(request);
|
| ... | ... | @@ -57,7 +59,16 @@ public class ChangeModeProducer<U extends ContentUI> { |
| 57 | 59 | |
| 58 | 60 | listener = (PropertyChangeEvent evt) -> {
|
| 59 | 61 | if (modelStates.contains(evt.getPropertyName())) {
|
| 60 | - doRebuildChangeMode();
|
|
| 62 | + if (adjusting) {
|
|
| 63 | + return;
|
|
| 64 | + }
|
|
| 65 | + try {
|
|
| 66 | + adjusting = true;
|
|
| 67 | + doRebuildChangeMode();
|
|
| 68 | + } finally {
|
|
| 69 | + adjusting = false;
|
|
| 70 | + }
|
|
| 71 | + |
|
| 61 | 72 | }
|
| 62 | 73 | };
|
| 63 | 74 | ui.getModel().getStates().addPropertyChangeListener(ContentUIModelStates.PROPERTY_OPENED, evt -> {
|
| ... | ... | @@ -46,6 +46,7 @@ import org.apache.logging.log4j.Logger; |
| 46 | 46 | |
| 47 | 47 | import javax.swing.JComponent;
|
| 48 | 48 | import javax.swing.JMenuItem;
|
| 49 | +import javax.swing.SwingUtilities;
|
|
| 49 | 50 | import java.awt.BorderLayout;
|
| 50 | 51 | import java.awt.Container;
|
| 51 | 52 | import java.awt.event.MouseEvent;
|
| ... | ... | @@ -126,6 +127,16 @@ public abstract class ContentListUIHandler<D extends OpenableDto, R extends Data |
| 126 | 127 | ShowTechnicalInformations.installAction(ui);
|
| 127 | 128 | }
|
| 128 | 129 | |
| 130 | + @Override
|
|
| 131 | + public void onEndOpenUI() {
|
|
| 132 | + super.onEndOpenUI();
|
|
| 133 | + SwingUtilities.invokeLater(()-> {
|
|
| 134 | + if (!ui.getModel().getStates().isEmpty() && ui.getList().isSelectionEmpty()) {
|
|
| 135 | + ui.getList().setSelectedIndex(0);
|
|
| 136 | + }
|
|
| 137 | + });
|
|
| 138 | + }
|
|
| 139 | + |
|
| 129 | 140 | @Override
|
| 130 | 141 | public void installChangeModeAction() {
|
| 131 | 142 | ChangeModeRequest request = ui.getModel().toChangeModeRequest();
|
| ... | ... | @@ -194,6 +205,26 @@ public abstract class ContentListUIHandler<D extends OpenableDto, R extends Data |
| 194 | 205 | ui.getActions().setVisible(false);
|
| 195 | 206 | super.rebuildNotEditableZone(ui);
|
| 196 | 207 | }
|
| 208 | + |
|
| 209 | + @Override
|
|
| 210 | + protected void rebuildAction(U ui, ContentMode newValue) {
|
|
| 211 | + ContentListUIModelStates<R> states = ui.getModel().getStates();
|
|
| 212 | + boolean editable = states.isEditable();
|
|
| 213 | + if (editable && ContentMode.READ.equals(newValue)) {
|
|
| 214 | + boolean disableAction = false;
|
|
| 215 | + if (!states.isOneSelectedData()) {
|
|
| 216 | + disableAction = true;
|
|
| 217 | + states.setEditable(false);
|
|
| 218 | + }
|
|
| 219 | + super.rebuildAction(ui, newValue);
|
|
| 220 | + if(disableAction) {
|
|
| 221 | + states.setEditable(true);
|
|
| 222 | + setEnabled(false);
|
|
| 223 | + }
|
|
| 224 | + } else {
|
|
| 225 | + super.rebuildAction(ui, newValue);
|
|
| 226 | + }
|
|
| 227 | + }
|
|
| 197 | 228 | };
|
| 198 | 229 | ChangeMode.installAction(ui, action);
|
| 199 | 230 | }
|
| ... | ... | @@ -25,6 +25,7 @@ package fr.ird.observe.client.datasource.editor.api.navigation; |
| 25 | 25 | import fr.ird.observe.client.datasource.editor.api.DataSourceEditorModel;
|
| 26 | 26 | import fr.ird.observe.client.datasource.editor.api.content.ContentUI;
|
| 27 | 27 | import fr.ird.observe.client.datasource.editor.api.content.ContentUIHandler;
|
| 28 | +import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUI;
|
|
| 28 | 29 | import fr.ird.observe.client.datasource.editor.api.content.referential.ReferentialHomeUI;
|
| 29 | 30 | import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode;
|
| 30 | 31 | import org.apache.logging.log4j.LogManager;
|
| ... | ... | @@ -92,7 +93,7 @@ public class NavigationTreeShowPopupHandler implements KeyListener, MouseListene |
| 92 | 93 | actions.forEach(a -> ContentUIMenuAction.createWithKeyStroke(popup, a).init());
|
| 93 | 94 | length = popup.getSubElements().length;
|
| 94 | 95 | } else {
|
| 95 | - if (selectedContentUI.getMode().isEnabled()) {
|
|
| 96 | + if (selectedContentUI.getMode().isEnabled() || selectedContentUI instanceof ContentListUI) {
|
|
| 96 | 97 | ContentUIMenuAction.createWithKeyStroke(popup, selectedContentUI.getMode()).init();
|
| 97 | 98 | actions.forEach(a -> ContentUIMenuAction.createWithKeyStroke(popup, a).init());
|
| 98 | 99 | popup.addSeparator();
|