Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
4b04e28c
by Tony Chemit at 2023-02-07T10:52:59+01:00
-
cd14da91
by Tony Chemit at 2023-02-07T10:55:12+01:00
-
6a7efe35
by Tony Chemit at 2023-02-07T11:54:18+01:00
-
b863e557
by Tony Chemit at 2023-02-07T11:57:23+01:00
6 changed files:
- client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/dcp/DcpUIAdapter.java
- client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/dcp/FloatingObjectPartsTreeNode.java
- client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/logbook/FloatingObjectUI.jaxx
- client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUI.jaxx
- core/api/dto/src/main/java/fr/ird/observe/dto/data/ps/TypeTransmittingBuoyOperation.java
- core/persistence/migration/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_1.java
Changes:
| ... | ... | @@ -162,7 +162,7 @@ public interface DcpUIAdapter<T extends TransmittingBuoyAware> extends JAXXObjec |
| 162 | 162 | default void onOpenAfterOpenModel(DcpUIModelStates<?, ?> states) {
|
| 163 | 163 | processDataBinding("typeOperation.selectedItem");
|
| 164 | 164 | TypeTransmittingBuoyOperation typeOperation = getTypeOperation().getSelectedValue();
|
| 165 | - changeTypeOperation(states, typeOperation, false);
|
|
| 165 | + changeTypeTransmittingBuoyOperation(states, typeOperation, false);
|
|
| 166 | 166 | }
|
| 167 | 167 | |
| 168 | 168 | default void stopEditUI() {
|
| ... | ... | @@ -173,9 +173,9 @@ public interface DcpUIAdapter<T extends TransmittingBuoyAware> extends JAXXObjec |
| 173 | 173 | getValidatorBuoy2().setBean(null);
|
| 174 | 174 | }
|
| 175 | 175 | |
| 176 | - default void changeTypeOperation(ItemEvent event, DcpUIModelStates<?, ?> states) {
|
|
| 176 | + default void changeTypeTransmittingBuoyOperation(ItemEvent event, DcpUIModelStates<?, ?> states) {
|
|
| 177 | 177 | if (event.getStateChange() == ItemEvent.SELECTED && states.isEditing()) {
|
| 178 | - changeTypeOperation(states, getTypeOperation().getSelectedValue(), true);
|
|
| 178 | + changeTypeTransmittingBuoyOperation(states, getTypeOperation().getSelectedValue(), true);
|
|
| 179 | 179 | states.setModified(true);
|
| 180 | 180 | }
|
| 181 | 181 | }
|
| ... | ... | @@ -191,7 +191,7 @@ public interface DcpUIAdapter<T extends TransmittingBuoyAware> extends JAXXObjec |
| 191 | 191 | states.setModified(states.isCreatingMode());
|
| 192 | 192 | }
|
| 193 | 193 | |
| 194 | - default void changeTypeOperation(DcpUIModelStates<?, ?> states, TypeTransmittingBuoyOperation typeOperation, boolean reset) {
|
|
| 194 | + default void changeTypeTransmittingBuoyOperation(DcpUIModelStates<?, ?> states, TypeTransmittingBuoyOperation typeOperation, boolean reset) {
|
|
| 195 | 195 | |
| 196 | 196 | if (Objects.requireNonNull(typeOperation).isWithCoordinate()) {
|
| 197 | 197 | addTransmittingBuoyCoordinate();
|
| ... | ... | @@ -208,7 +208,7 @@ public interface DcpUIAdapter<T extends TransmittingBuoyAware> extends JAXXObjec |
| 208 | 208 | }
|
| 209 | 209 | |
| 210 | 210 | if (withBuoy) {
|
| 211 | - // always reset balise lues of editBean to avoid side-effects
|
|
| 211 | + // always reset buoys of editBean to avoid side-effects
|
|
| 212 | 212 | bean.getTransmittingBuoy().clear();
|
| 213 | 213 | }
|
| 214 | 214 | |
| ... | ... | @@ -221,45 +221,47 @@ public interface DcpUIAdapter<T extends TransmittingBuoyAware> extends JAXXObjec |
| 221 | 221 | getValidatorBuoy2().setBean(null);
|
| 222 | 222 | }
|
| 223 | 223 | |
| 224 | - String[] codeOperations = typeOperation.getCodeOperation();
|
|
| 225 | - JComponent focusOwner = null;
|
|
| 226 | - switch (typeOperation) {
|
|
| 227 | - case noBuoy:
|
|
| 224 | + String[] transmittingBuoyOperationCodes = typeOperation.getTransmittingBuoyOperationCodes();
|
|
| 225 | + JComponent focusOwner;
|
|
| 226 | + switch (typeOperation.getBuoyCount()) {
|
|
| 227 | + case 0:
|
|
| 228 | + // no buoy
|
|
| 228 | 229 | editorPanel.add(getNoBuoyEditor());
|
| 229 | 230 | focusOwner = getComment();
|
| 230 | 231 | break;
|
| 231 | - case grabAndChange:
|
|
| 232 | + case 1:
|
|
| 233 | + // one buoy
|
|
| 232 | 234 | if (reset) {
|
| 233 | - states.bindEmptyBuoy(states.getReferenceCache(), bean, getTransmittingBuoy1(), states.getBuoyOperation(codeOperations[0]));
|
|
| 234 | - states.bindEmptyBuoy(states.getReferenceCache(), bean, getTransmittingBuoy2(), states.getBuoyOperation(codeOperations[1]));
|
|
| 235 | + states.bindEmptyBuoy(states.getReferenceCache(), bean, getTransmittingBuoy1(), states.getBuoyOperation(transmittingBuoyOperationCodes[0]));
|
|
| 235 | 236 | } else {
|
| 236 | 237 | states.bindExistingBuoy(bean, getTransmittingBuoy1(), modelBuoyList.get(0));
|
| 237 | - states.bindExistingBuoy(bean, getTransmittingBuoy2(), modelBuoyList.get(1));
|
|
| 238 | 238 | }
|
| 239 | 239 | editorPanel.add(getTransmittingBuoy1EditorPanel());
|
| 240 | - editorPanel.add(getTransmittingBuoy2EditorPanel());
|
|
| 241 | 240 | if (states.isEditing()) {
|
| 242 | 241 | getValidatorBuoy1().setBean(getTransmittingBuoy1());
|
| 243 | - getValidatorBuoy2().setBean(getTransmittingBuoy2());
|
|
| 244 | 242 | }
|
| 245 | 243 | focusOwner = getTransmittingBuoyType1();
|
| 246 | 244 | break;
|
| 247 | - case visit:
|
|
| 248 | - case grab:
|
|
| 249 | - case posing:
|
|
| 250 | - case lost:
|
|
| 251 | - case endOfUse:
|
|
| 245 | + case 2:
|
|
| 246 | + // two buoy
|
|
| 252 | 247 | if (reset) {
|
| 253 | - states.bindEmptyBuoy(states.getReferenceCache(), bean, getTransmittingBuoy1(), states.getBuoyOperation(codeOperations[0]));
|
|
| 248 | + states.bindEmptyBuoy(states.getReferenceCache(), bean, getTransmittingBuoy1(), states.getBuoyOperation(transmittingBuoyOperationCodes[0]));
|
|
| 249 | + states.bindEmptyBuoy(states.getReferenceCache(), bean, getTransmittingBuoy2(), states.getBuoyOperation(transmittingBuoyOperationCodes[1]));
|
|
| 254 | 250 | } else {
|
| 255 | 251 | states.bindExistingBuoy(bean, getTransmittingBuoy1(), modelBuoyList.get(0));
|
| 252 | + states.bindExistingBuoy(bean, getTransmittingBuoy2(), modelBuoyList.get(1));
|
|
| 256 | 253 | }
|
| 257 | 254 | editorPanel.add(getTransmittingBuoy1EditorPanel());
|
| 255 | + editorPanel.add(getTransmittingBuoy2EditorPanel());
|
|
| 258 | 256 | if (states.isEditing()) {
|
| 259 | 257 | getValidatorBuoy1().setBean(getTransmittingBuoy1());
|
| 258 | + getValidatorBuoy2().setBean(getTransmittingBuoy2());
|
|
| 260 | 259 | }
|
| 261 | 260 | focusOwner = getTransmittingBuoyType1();
|
| 262 | 261 | break;
|
| 262 | + default:
|
|
| 263 | + // can't happen
|
|
| 264 | + throw new IllegalArgumentException(String.format("Can't have %d buoy count", typeOperation.getBuoyCount()));
|
|
| 263 | 265 | }
|
| 264 | 266 | //FIXME:Focus update zone focus owner
|
| 265 | 267 | JComponent finalFocusOwner = focusOwner;
|
| ... | ... | @@ -119,19 +119,19 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 119 | 119 | throw new IllegalStateException();
|
| 120 | 120 | }
|
| 121 | 121 | |
| 122 | - void setValueAt(Object aValue, int column) {
|
|
| 122 | + void setValueAt(String value, int column) {
|
|
| 123 | 123 | text = null;
|
| 124 | 124 | switch (column) {
|
| 125 | 125 | case 1: // when arriving
|
| 126 | - uiModelStates.setWhenArriving(dto.getId(), aValue == null ? null : String.valueOf(aValue));
|
|
| 126 | + uiModelStates.setWhenArriving(dto.getId(), value);
|
|
| 127 | 127 | if (useValidation) {
|
| 128 | - valueValidOnArriving = dto.isValid(aValue);
|
|
| 128 | + valueValidOnArriving = dto.isValid(value);
|
|
| 129 | 129 | }
|
| 130 | 130 | return;
|
| 131 | 131 | case 2: // when leaving
|
| 132 | - uiModelStates.setWhenLeaving(dto.getId(), aValue == null ? null : String.valueOf(aValue));
|
|
| 132 | + uiModelStates.setWhenLeaving(dto.getId(), value);
|
|
| 133 | 133 | if (useValidation) {
|
| 134 | - valueValidOnLeaving = dto.isValid(aValue);
|
|
| 134 | + valueValidOnLeaving = dto.isValid(value);
|
|
| 135 | 135 | }
|
| 136 | 136 | return;
|
| 137 | 137 | }
|
| ... | ... | @@ -250,7 +250,11 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 250 | 250 | |
| 251 | 251 | @Override
|
| 252 | 252 | public void setValueAt(Object aValue, int column) {
|
| 253 | - getUserObject().setValueAt(aValue, column);
|
|
| 253 | + String value = aValue == null ? null : String.valueOf(aValue).trim();
|
|
| 254 | + if (Objects.equals("", value)) {
|
|
| 255 | + value = null;
|
|
| 256 | + }
|
|
| 257 | + getUserObject().setValueAt(value, column);
|
|
| 254 | 258 | }
|
| 255 | 259 | |
| 256 | 260 | @Override
|
| ... | ... | @@ -199,7 +199,7 @@ |
| 199 | 199 | <cell anchor='east' weightx="1" fill="both">
|
| 200 | 200 | <BeanEnumEditor id='typeOperation' genericType='TypeTransmittingBuoyOperation'
|
| 201 | 201 | constructorParams='TypeTransmittingBuoyOperation.class'
|
| 202 | - onItemStateChanged='changeTypeOperation(event,getStates());'/>
|
|
| 202 | + onItemStateChanged='changeTypeTransmittingBuoyOperation(event,getStates());'/>
|
|
| 203 | 203 | </cell>
|
| 204 | 204 | </row>
|
| 205 | 205 | </Table>
|
| ... | ... | @@ -199,7 +199,7 @@ |
| 199 | 199 | <cell anchor='east' weightx="1" fill="both">
|
| 200 | 200 | <BeanEnumEditor id='typeOperation' genericType='TypeTransmittingBuoyOperation'
|
| 201 | 201 | constructorParams='TypeTransmittingBuoyOperation.class'
|
| 202 | - onItemStateChanged='changeTypeOperation(event,getStates());'/>
|
|
| 202 | + onItemStateChanged='changeTypeTransmittingBuoyOperation(event,getStates());'/>
|
|
| 203 | 203 | </cell>
|
| 204 | 204 | </row>
|
| 205 | 205 | </Table>
|
| ... | ... | @@ -26,6 +26,8 @@ import fr.ird.observe.dto.referential.ps.common.TransmittingBuoyOperationReferen |
| 26 | 26 | import io.ultreia.java4all.i18n.spi.enumeration.TranslateEnumeration;
|
| 27 | 27 | |
| 28 | 28 | import java.util.List;
|
| 29 | +import java.util.Set;
|
|
| 30 | +import java.util.TreeSet;
|
|
| 29 | 31 | |
| 30 | 32 | /**
|
| 31 | 33 | * @author Tony Chemit - dev@tchemit.fr
|
| ... | ... | @@ -34,71 +36,74 @@ import java.util.List; |
| 34 | 36 | public enum TypeTransmittingBuoyOperation {
|
| 35 | 37 | // no buoy
|
| 36 | 38 | noBuoy(false),
|
| 37 | - |
|
| 38 | 39 | // one buoy
|
| 39 | 40 | visit(false, "1"),
|
| 40 | 41 | grab(false, "2"),
|
| 41 | 42 | posing(false, "3"),
|
| 42 | 43 | lost(true, "4"),
|
| 43 | - unknown(false, "99"),
|
|
| 44 | 44 | endOfUse(true, "5"),
|
| 45 | - |
|
| 45 | + unknown(false, "99"),
|
|
| 46 | 46 | // two buoy
|
| 47 | 47 | grabAndChange(false, "2", "3");
|
| 48 | - |
|
| 49 | 48 | /**
|
| 50 | 49 | * TransmittingBuoyOperation codes associated to this type.
|
| 51 | 50 | */
|
| 52 | - private final String[] codeOperation;
|
|
| 51 | + private final String[] transmittingBuoyOperationCodes;
|
|
| 52 | + /**
|
|
| 53 | + * Number of buoy authorized for this type.
|
|
| 54 | + */
|
|
| 55 | + private final int buoyCount;
|
|
| 53 | 56 | /**
|
| 54 | 57 | * Use coordinate?
|
| 55 | 58 | */
|
| 56 | 59 | private final boolean withCoordinate;
|
| 57 | 60 | |
| 58 | 61 | public static TypeTransmittingBuoyOperation guessTransmittingBuoyOperation(List<TransmittingBuoyOperationReference> transmittingBuoy) {
|
| 59 | - if (transmittingBuoy.isEmpty()) {
|
|
| 60 | - |
|
| 61 | - // no buoy
|
|
| 62 | - return TypeTransmittingBuoyOperation.noBuoy;
|
|
| 63 | - }
|
|
| 64 | - if (transmittingBuoy.size() == 1) {
|
|
| 65 | - // one buoy
|
|
| 66 | - TransmittingBuoyOperationReference operation = transmittingBuoy.iterator().next();
|
|
| 67 | - String code = operation.getCode();
|
|
| 68 | - switch (Integer.parseInt(code)) {
|
|
| 69 | - case 1:
|
|
| 70 | - return TypeTransmittingBuoyOperation.visit;
|
|
| 71 | - case 2:
|
|
| 72 | - return TypeTransmittingBuoyOperation.grab;
|
|
| 73 | - case 3:
|
|
| 74 | - return TypeTransmittingBuoyOperation.posing;
|
|
| 75 | - case 4:
|
|
| 76 | - return TypeTransmittingBuoyOperation.lost;
|
|
| 77 | - case 5:
|
|
| 78 | - return TypeTransmittingBuoyOperation.endOfUse;
|
|
| 79 | - default:
|
|
| 80 | - throw new IllegalStateException(String.format("operation must be between 1 to 5, but was %s", code));
|
|
| 81 | - }
|
|
| 82 | - }
|
|
| 83 | - if (transmittingBuoy.size() == 2) {
|
|
| 84 | - // two buoy
|
|
| 85 | - return TypeTransmittingBuoyOperation.grabAndChange;
|
|
| 62 | + int transmittingBuoyCount = transmittingBuoy.size();
|
|
| 63 | + switch (transmittingBuoyCount) {
|
|
| 64 | + case 0:
|
|
| 65 | + // no buoy
|
|
| 66 | + return TypeTransmittingBuoyOperation.noBuoy;
|
|
| 67 | + case 1:
|
|
| 68 | + // one buoy
|
|
| 69 | + TransmittingBuoyOperationReference operation = transmittingBuoy.iterator().next();
|
|
| 70 | + String code = operation.getCode();
|
|
| 71 | + for (TypeTransmittingBuoyOperation typeTransmittingBuoyOperation : TypeTransmittingBuoyOperation.values()) {
|
|
| 72 | + if (typeTransmittingBuoyOperation.getBuoyCount() == 1 && typeTransmittingBuoyOperation.getTransmittingBuoyOperationCodes()[0].equals(code)) {
|
|
| 73 | + return typeTransmittingBuoyOperation;
|
|
| 74 | + }
|
|
| 75 | + }
|
|
| 76 | + Set<String> availableCodes = new TreeSet<>();
|
|
| 77 | + for (TypeTransmittingBuoyOperation typeTransmittingBuoyOperation : TypeTransmittingBuoyOperation.values()) {
|
|
| 78 | + if (typeTransmittingBuoyOperation.getBuoyCount() == 1) {
|
|
| 79 | + availableCodes.add(typeTransmittingBuoyOperation.getTransmittingBuoyOperationCodes()[0]);
|
|
| 80 | + }
|
|
| 81 | + }
|
|
| 82 | + throw new IllegalStateException(String.format("When having a single buoy, TransmittingBuoyOperation code must be among: %s, but was %s", availableCodes, code));
|
|
| 83 | + case 2:
|
|
| 84 | + // two buoy
|
|
| 85 | + return TypeTransmittingBuoyOperation.grabAndChange;
|
|
| 86 | + default:
|
|
| 87 | + throw new IllegalStateException(String.format("A floating object, can only have 0, 1 or 2 buoy(s) but found %d buoys", transmittingBuoyCount));
|
|
| 86 | 88 | }
|
| 87 | - throw new IllegalStateException(String.format("A dcp, can only have 0, 1 or 2 buoys, found %d", transmittingBuoy.size()));
|
|
| 88 | - |
|
| 89 | 89 | }
|
| 90 | 90 | |
| 91 | - TypeTransmittingBuoyOperation(boolean withCoordinate, String... codeOperation) {
|
|
| 92 | - this.codeOperation = codeOperation;
|
|
| 91 | + TypeTransmittingBuoyOperation(boolean withCoordinate, String... transmittingBuoyOperationCodes) {
|
|
| 92 | + this.transmittingBuoyOperationCodes = transmittingBuoyOperationCodes;
|
|
| 93 | 93 | this.withCoordinate = withCoordinate;
|
| 94 | + this.buoyCount = transmittingBuoyOperationCodes.length;
|
|
| 94 | 95 | }
|
| 95 | 96 | |
| 96 | 97 | public boolean isWithCoordinate() {
|
| 97 | 98 | return withCoordinate;
|
| 98 | 99 | }
|
| 99 | 100 | |
| 100 | - public String[] getCodeOperation() {
|
|
| 101 | - return codeOperation;
|
|
| 101 | + public String[] getTransmittingBuoyOperationCodes() {
|
|
| 102 | + return transmittingBuoyOperationCodes;
|
|
| 103 | + }
|
|
| 104 | + |
|
| 105 | + public int getBuoyCount() {
|
|
| 106 | + return buoyCount;
|
|
| 102 | 107 | }
|
| 103 | 108 | |
| 104 | 109 | public String getLabel() {
|
| ... | ... | @@ -288,7 +288,8 @@ public class DataSourceMigrationForVersion_9_1 extends ByMajorMigrationVersionRe |
| 288 | 288 | // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2619
|
| 289 | 289 | addNewTable(executor, withIds, "07", "table-ps_localmarket_buyer");
|
| 290 | 290 | executor.addScript("07", "adapt-table-ps_localmarket_batch");
|
| 291 | - if (withIds && isForTck()) {
|
|
| 291 | + //FIXME Set this back to tck (or remove simply it when we will have some data)
|
|
| 292 | + if (withIds /**&& isForTck()**/) {
|
|
| 292 | 293 | // Add some referential with no usage inside others referential to make possible delete test
|
| 293 | 294 | // See fr.ird.observe.persistence.test.request.DeleteReferentialRequestTest
|
| 294 | 295 | executor.addScript("07-tck", "fill-table-ps_localmarket_buyer");
|