Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 4a398696 by tchemit at 2019-02-19T11:44:14Z [PS] Formulaire FOB : les contrôles de saisie ne sont pas appliqués - Closes #1234 - - - - - 5 changed files: - client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/FloatingObjectUIHandler.java - client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/FloatingObjectUIModel.java - client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/dcp/FloatingObjectPartsTreeNode.java - client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/dcp/FloatingObjectPartsTreeTable.java - client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/dcp/FloatingObjectPartsTreeTableModel.java Changes: ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/FloatingObjectUIHandler.java ===================================== @@ -209,6 +209,6 @@ public class FloatingObjectUIHandler extends ContentEditUIHandler<FloatingObject getModel().setLeaving(operation.isWhenLeaving()); } FloatingObjectPartsTreeTableModel treeModel = getUi().getTable().getTreeTableModel(); - treeModel.reset(); + treeModel.reset(true); } } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/FloatingObjectUIModel.java ===================================== @@ -159,6 +159,16 @@ public class FloatingObjectUIModel extends ContentEditUIModel<FloatingObjectDto, whenLeaving.put(dto, value); } + public Object getWhenArriving(String id) { + ObjectMaterialDto dto = Objects.requireNonNull(referentialMap.get(id)); + return whenArriving.get(dto); + } + + public Object getWhenLeaving(String id) { + ObjectMaterialDto dto = Objects.requireNonNull(referentialMap.get(id)); + return whenLeaving.get(dto); + } + public Optional<FloatingObjectPreset> getReference() { return Optional.ofNullable(reference); } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/dcp/FloatingObjectPartsTreeNode.java ===================================== @@ -73,7 +73,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im } boolean isNotValid() { - return !(getUserObject().validWhenArriving && getUserObject().validWhenLeaving); + return !(isValid(1) && isValid(2)); } @Override @@ -153,6 +153,10 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im return getUserObject().dto.isFloat(); } + public boolean withValidation() { + return getUserObject().dto.withValidation(); + } + ObjectMaterialTypeReference getObjectMaterialType() { return getUserObject().dto.getObjectMaterialType(); } @@ -304,6 +308,10 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im return dto != null && !dto.isChildrenMultiSelectable() && !isLeaf(); } + public void computeValidationValidState() { + getUserObject().computeValidationValidState(); + } + //TODO Improve the design, we should not store anything in uiModel and separate leaving and arriving data private static class FloatingObjectPartsTreeNodeContext { @@ -344,8 +352,6 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im this.editable = false; this.exclusive = false; this.useValidation = false; - this.valueValidOnArriving = true; - this.valueValidOnLeaving = true; this.referentialLocale = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale(); } @@ -357,10 +363,6 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im // editable if dto is selectable (we also make sure that the object material type is here too) this.editable = dto.getObjectMaterialType() != null; this.useValidation = enabled && editable && dto.withValidation(); - if (!useValidation) { - valueValidOnArriving = true; - valueValidOnLeaving = true; - } // exclusive if his parent requires it this.exclusive = parent.dto != null && !parent.dto.isChildrenMultiSelectable(); this.referentialLocale = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale(); @@ -411,9 +413,9 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im boolean isValid(int column) { switch (column) { case 1: // when arriving - return validWhenArriving; + return validWhenArriving && (!useValidation || valueValidOnArriving); case 2: // when leaving - return validWhenLeaving; + return validWhenLeaving && (!useValidation || valueValidOnLeaving); } throw new IllegalStateException(); } @@ -429,5 +431,15 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im return text; } + public void computeValidationValidState() { + if (uiModel.isArriving()) { + Object value = uiModel.getWhenArriving(dto.getId()); + valueValidOnArriving = dto.isValid(value); + } + if (uiModel.isLeaving()) { + Object value = uiModel.getWhenLeaving(dto.getId()); + valueValidOnLeaving = dto.isValid(value); + } + } } } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/dcp/FloatingObjectPartsTreeTable.java ===================================== @@ -83,7 +83,7 @@ public class FloatingObjectPartsTreeTable extends JXTreeTable { } FloatingObjectPartsTreeTableModel treeTableModel = getTreeTableModel(); - treeTableModel.reset(); + treeTableModel.reset(true); if (expandTree) { expandAll(); ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/ps/observation/dcp/FloatingObjectPartsTreeTableModel.java ===================================== @@ -50,6 +50,7 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { private ImmutableSet<FloatingObjectPartsTreeNode> allNodes; private ImmutableSet<FloatingObjectPartsTreeNode> needOneSelectionNodes; private ImmutableSet<FloatingObjectPartsTreeNode> mandatoryNodes; + private ImmutableSet<FloatingObjectPartsTreeNode> validationNodes; private boolean adjusting; public FloatingObjectPartsTreeTableModel(FloatingObjectUIModel uiModel) { @@ -73,6 +74,7 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { ImmutableSet.Builder<FloatingObjectPartsTreeNode> needOneSelectionNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<FloatingObjectPartsTreeNode> mandatoryNodesBuilder = ImmutableSet.builder(); + ImmutableSet.Builder<FloatingObjectPartsTreeNode> validationNodesBuilder = ImmutableSet.builder(); for (FloatingObjectPartsTreeNode node : allNodes) { if (!node.isEnabled()) { @@ -83,9 +85,13 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { if (node.withMandatoryConstraintsOnChildren()) { needOneSelectionNodesBuilder.add(node); } + if (node.withValidation()) { + validationNodesBuilder.add(node); + } } needOneSelectionNodes = needOneSelectionNodesBuilder.build(); mandatoryNodes = mandatoryNodesBuilder.build(); + validationNodes = validationNodesBuilder.build(); } public void rebuildRootNode(ObjectMaterialHierarchyDto materials) { @@ -120,12 +126,15 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { if (adjusting) { return; } - reset(); + reset(false); uiModel.setModified(true); } - public void reset() { + public void reset(boolean computeValidation) { allNodes.forEach(FloatingObjectPartsTreeNode::resetStates); + if (computeValidation) { + validationNodes.forEach(FloatingObjectPartsTreeNode::computeValidationValidState); + } boolean whenArriving = uiModel.isArriving(); boolean whenLeaving = uiModel.isLeaving(); @@ -144,7 +153,7 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { public void setAdjusting(boolean adjusting) { this.adjusting = adjusting; if (!adjusting) { - reset(); + reset(false); uiModel.setModified(true); } } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/4a398696450824a3ccce0d58276e... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/4a398696450824a3ccce0d58276e... You're receiving this email because of your account on gitlab.com.