Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: cb682d54 by Tony CHEMIT at 2018-07-12T15:56:13Z Improve FOB Form - See #948 - - - - - 4 changed files: - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeNode.java - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeTableModel.java - dto/src/main/java/fr/ird/observe/dto/data/seine/ObjectMaterialHierarchyDto.java Changes: ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java ===================================== @@ -196,6 +196,14 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, SwingUtilities.invokeLater(this::forceGrabFocusOnForm); } + @Override + public void stopEditUI() { + if (ui.getMainTabbedPane().getSelectedIndex() == 1) { + ui.getTable().editingCanceled(null); + } + super.stopEditUI(); + } + @Override public void startEditUI(String... binding) { ContentUIModel<FloatingObjectDto> contentUIModel = getModel(); ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeNode.java ===================================== @@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableSet; import fr.ird.observe.client.ObserveSwingApplicationContext; import fr.ird.observe.client.ui.content.data.seine.FloatingObjectUIModel; import fr.ird.observe.dto.data.seine.ObjectMaterialHierarchyDto; -import fr.ird.observe.dto.referential.FormulaHelper; import fr.ird.observe.dto.referential.ReferentialLocale; import fr.ird.observe.dto.referential.seine.ObjectMaterialTypeReference; import org.apache.commons.logging.Log; @@ -62,13 +61,13 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im static FloatingObjectPartsTreeNode createRoot(FloatingObjectUIModel model, ObjectMaterialHierarchyDto dto) { FloatingObjectPartsTreeNode root; FloatingObjectPartsTreeNodeContext rootModel = new FloatingObjectPartsTreeNodeContext(model); - if (dto != null) { + if (dto == null) { + root = new FloatingObjectPartsTreeNode(rootModel); + } else { FloatingObjectPartsTreeNodeContext childModel = new FloatingObjectPartsTreeNodeContext(dto, rootModel); root = new FloatingObjectPartsTreeNode(childModel); root.computeCompanions(null); root.setCompanions(null); - } else { - root = new FloatingObjectPartsTreeNode(rootModel); } return root; } @@ -166,6 +165,8 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im getUserObject().text = null; getUserObject().validWhenArriving = true; getUserObject().validWhenLeaving = true; + getUserObject().needOneSelectionOnArriving = false; + getUserObject().needOneSelectionOnLeaving = false; } @Override @@ -173,44 +174,68 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im return (FloatingObjectPartsTreeNode) super.getParent(); } - void fillNodeSets(ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder, - ImmutableSet.Builder<FloatingObjectPartsTreeNode> needOneSelectionNodesBuilder, - ImmutableSet.Builder<FloatingObjectPartsTreeNode> mandatoryNodesBuilder) { + ImmutableSet<FloatingObjectPartsTreeNode> getShell() { - allNodesBuilder.add(this); - if (getUserObject().needOneSelection) { - needOneSelectionNodesBuilder.add(this); - } - if (getUserObject().mandatory) { - mandatoryNodesBuilder.add(this); - } + ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder = ImmutableSet.builder(); + getShell(allNodesBuilder); + return allNodesBuilder.build(); + } + private void getShell(ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder) { + allNodesBuilder.add(this); for (FloatingObjectPartsTreeNode child : this) { - child.fillNodeSets(allNodesBuilder, needOneSelectionNodesBuilder, mandatoryNodesBuilder); + child.getShell(allNodesBuilder); } + } + boolean withMandatoryConstraintsOnChildren() { + ObjectMaterialHierarchyDto userObject = getUserObject().dto; + return userObject == null || userObject.isChildSelectionMandatory(); } void computeNeedAtLeastOnSelectValidState(boolean whenArriving, boolean whenLeaving) { - + boolean needSelect = isEditable(); + FloatingObjectPartsTreeNodeContext userObject = getUserObject(); if (whenArriving) { - getUserObject().validWhenArriving = isAtLeastOneSelected(1); + userObject.needOneSelectionOnArriving = (!needSelect || withValue(1)) && isAtLeastOneSelected(1); } if (whenLeaving) { - getUserObject().validWhenLeaving = isAtLeastOneSelected(2); + userObject.needOneSelectionOnLeaving = (!needSelect || withValue(2)) && isAtLeastOneSelected(2); + } + if (userObject.needOneSelectionOnArriving || userObject.needOneSelectionOnLeaving) { + log.info("Validate node " + this); } - log.info("Validate node " + this); + } + private FloatingObjectPartsTreeNode getFirstAncestorNeedOneSelection(int column) { + if (withMandatoryConstraintsOnChildren()) { + if (parent == null) { + return this; + } + if (withValue(column)) { + return this; + } + } + return getParent().getFirstAncestorNeedOneSelection(column); } void computeMandatoryValidState(boolean whenArriving, boolean whenLeaving) { FloatingObjectPartsTreeNodeContext userObject = getUserObject(); + FloatingObjectPartsTreeNode parent = getParent(); if (whenArriving) { - userObject.validWhenArriving = getParent().getUserObject().validWhenArriving; + if (parent != null && !parent.getUserObject().validWhenArriving) { + userObject.validWhenArriving = false; + } else { + userObject.validWhenArriving = getFirstAncestorNeedOneSelection(1).getUserObject().needOneSelectionOnArriving; + } } if (whenLeaving) { - userObject.validWhenLeaving = getParent().getUserObject().validWhenLeaving; + if (parent != null && !parent.getUserObject().validWhenLeaving) { + userObject.validWhenLeaving = false; + } else { + userObject.validWhenLeaving = getFirstAncestorNeedOneSelection(2).getUserObject().needOneSelectionOnLeaving; + } } if (userObject.getValueAt(1) != null || userObject.getValueAt(2) != null) { @@ -218,41 +243,19 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im } } - void computeFormulaValidState(boolean whenArriving, boolean whenLeaving) { - if (getUserObject().dto == null || getUserObject().dto.isBoolean()) { - return; - } - String validation = getUserObject().dto.getValidation(); - if (whenArriving && getUserObject().validWhenArriving) { - Object value = getUserObject().getValueAt(1); - if (value != null) { - if (getUserObject().dto.isText()) { - getUserObject().validWhenArriving = FormulaHelper.validateObjectMaterialValidation(validation, value); - } else if (getUserObject().dto.isInteger()) { - getUserObject().validWhenArriving = FormulaHelper.validateObjectMaterialValidation(validation, Integer.valueOf(value.toString())); - } else if (getUserObject().dto.isFloat()) { - getUserObject().validWhenArriving = FormulaHelper.validateObjectMaterialValidation(validation, Float.valueOf(value.toString())); - } - } - } - if (whenLeaving && getUserObject().validWhenLeaving) { - Object value = getUserObject().getValueAt(2); - if (value != null) { - if (getUserObject().dto.isText()) { - getUserObject().validWhenLeaving = FormulaHelper.validateObjectMaterialValidation(validation, value); - } else if (getUserObject().dto.isInteger()) { - getUserObject().validWhenLeaving = FormulaHelper.validateObjectMaterialValidation(validation, Integer.valueOf(value.toString())); - } else if (getUserObject().dto.isFloat()) { - getUserObject().validWhenLeaving = FormulaHelper.validateObjectMaterialValidation(validation, Float.valueOf(value.toString())); - } - } - } - - } - - boolean withValidation() { - return getUserObject().dto != null && getUserObject().dto.withValidation(); - } +// void computeFormulaValidState(boolean whenArriving, boolean whenLeaving) { +// FloatingObjectPartsTreeNodeContext userObject = getUserObject(); +// ObjectMaterialHierarchyDto dto = Objects.requireNonNull(userObject.dto); +// if (whenArriving && userObject.validWhenArriving) { +// Object value = userObject.getValueAt(1); +// userObject.validWhenArriving = dto.isValid(value); +// } +// if (whenLeaving && userObject.validWhenLeaving) { +// Object value = userObject.getValueAt(2); +// userObject.validWhenLeaving = dto.isValid(value); +// } +// +// } private void setCompanions(ImmutableSet.Builder<FloatingObjectPartsTreeNode> companionsBuilder) { if (companionsBuilder != null) { @@ -263,12 +266,21 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im } } + private boolean withValue(int column) { + return getValueAt(column) != null; + } + + private boolean withValidValue(int column) { + return withValue(column) && (column == 1 ? getUserObject().valueValidOnArriving : getUserObject().valueValidOnLeaving); + } + private boolean isAtLeastOneSelected(int column) { - if (getValueAt(column) != null) { - return true; - } for (FloatingObjectPartsTreeNode child : this) { - if (child.isAtLeastOneSelected(column)) { + if (child.withValidValue(column)) { + return true; + } + boolean result = child.isAtLeastOneSelected(column); + if (result) { return true; } } @@ -293,6 +305,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im return dto != null && !dto.isChildrenMultiSelectable() && !isLeaf(); } + //TODO Improve the design, we should not store anything in uiModel and separate leaving and arriving data private static class FloatingObjectPartsTreeNodeContext { // main model to get and store values @@ -303,16 +316,22 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im private final boolean enabled; // Is this node editable ? private final boolean editable; - // Is this node need at least one child selected ? - private final boolean needOneSelection; - // Is this node in the path of at least one mandatory child ancestor ? - private final boolean mandatory; // Is the node is exclusive (means only one value possible for him and his brothers) ? private final boolean exclusive; + // Is the node use validation on his value ? + private final boolean useValidation; private final ReferentialLocale referentialLocale; - // Is the node valid for whenArriving column ? + // Is this node (on arriving) need at least one child selected ? (if editable then node must be selected) + private boolean needOneSelectionOnLeaving; + // Is this node (on leaving) need at least one child selected ? (if editable then node must be selected) + private boolean needOneSelectionOnArriving; + // for a validation node (on arriving), is value valid (if no value then it is valid) + private boolean valueValidOnLeaving = true; + // for a validation node (on leaving), is value valid (if no value then it is valid) + private boolean valueValidOnArriving = true; + // Is the node valid (on arriving) column ? private boolean validWhenArriving = true; - // Is the node valid for whenLeaving column ? + // Is the node valid (on leeaving) column ? private boolean validWhenLeaving = true; // Set of brothers of this node that is in a exclusive group of node (only one value among all of them) private ImmutableSet<FloatingObjectPartsTreeNode> companions; @@ -320,35 +339,33 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im private String text; FloatingObjectPartsTreeNodeContext(FloatingObjectUIModel uiModel) { - Objects.requireNonNull(uiModel); - this.uiModel = uiModel; + this.uiModel = Objects.requireNonNull(uiModel); this.dto = null; this.enabled = true; this.editable = false; - this.mandatory = false; this.exclusive = false; - this.needOneSelection = false; - this.referentialLocale=ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale(); + this.useValidation = false; + this.valueValidOnArriving = true; + this.valueValidOnLeaving = true; + this.referentialLocale = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale(); } FloatingObjectPartsTreeNodeContext(ObjectMaterialHierarchyDto dto, FloatingObjectPartsTreeNodeContext parent) { - Objects.requireNonNull(dto); - Objects.requireNonNull(parent); - this.uiModel = parent.uiModel; - this.dto = dto; + this.uiModel = Objects.requireNonNull(parent).uiModel; + this.dto = Objects.requireNonNull(dto); // enabled if parent is enabled and dto is enabled this.enabled = parent.enabled && dto.isEnabled(); - // need one selection if is enabled and dto requires it - this.needOneSelection = enabled && dto.isChildSelectionMandatory(); // editable if dto is selectable (we also make sure that the object material type is here too) this.editable = dto.isSelectable() && dto.getObjectMaterialType() != null; - - // mandatory if enabled parent is so or parent makes this child to be - this.mandatory = parent.mandatory || parent.needOneSelection; + 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(); - log.info(String.format("New node: %s - mandatory %s - needOneSelection %s - exclusive %s", dto.getLabel(referentialLocale), mandatory, needOneSelection, exclusive)); + this.referentialLocale = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale(); + log.info(String.format("New node: %s %s - needOneSelection %b-%b - exclusive %s", dto.getCode(), dto.getLabel(referentialLocale), needOneSelectionOnArriving, needOneSelectionOnLeaving, exclusive)); } Object getValueAt(int column) { @@ -368,9 +385,15 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im switch (column) { case 1: // when arriving uiModel.setWhenArriving(dto.getId(), aValue == null ? null : String.valueOf(aValue)); + if (useValidation) { + valueValidOnArriving = dto.isValid(aValue); + } return; case 2: // when leaving uiModel.setWhenLeaving(dto.getId(), aValue == null ? null : String.valueOf(aValue)); + if (useValidation) { + valueValidOnLeaving = dto.isValid(aValue); + } return; } throw new IllegalStateException(); ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeTableModel.java ===================================== @@ -33,7 +33,6 @@ import org.nuiton.i18n.I18n; import java.util.Arrays; import java.util.Optional; -import java.util.stream.Collectors; /** * Created by tchemit on 05/08/17. @@ -51,7 +50,6 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { private ImmutableSet<FloatingObjectPartsTreeNode> allNodes; private ImmutableSet<FloatingObjectPartsTreeNode> needOneSelectionNodes; private ImmutableSet<FloatingObjectPartsTreeNode> mandatoryNodes; - private ImmutableSet<FloatingObjectPartsTreeNode> withValidationNodes; private boolean adjusting; public FloatingObjectPartsTreeTableModel(FloatingObjectUIModel uiModel) { @@ -71,18 +69,22 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { public void setRoot(TreeTableNode root) { super.setRoot(root); - FloatingObjectPartsTreeNode myRoot = (FloatingObjectPartsTreeNode) root; + allNodes = ((FloatingObjectPartsTreeNode) root).getShell(); - ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<FloatingObjectPartsTreeNode> needOneSelectionNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<FloatingObjectPartsTreeNode> mandatoryNodesBuilder = ImmutableSet.builder(); - myRoot.fillNodeSets(allNodesBuilder, needOneSelectionNodesBuilder, mandatoryNodesBuilder); - - allNodes = allNodesBuilder.build(); + for (FloatingObjectPartsTreeNode node : allNodes) { + if (!node.isEnabled()) { + continue; + } + mandatoryNodesBuilder.add(node); + if (node.withMandatoryConstraintsOnChildren()) { + needOneSelectionNodesBuilder.add(node); + } + } needOneSelectionNodes = needOneSelectionNodesBuilder.build(); mandatoryNodes = mandatoryNodesBuilder.build(); - withValidationNodes = ImmutableSet.copyOf(allNodes.stream().filter(FloatingObjectPartsTreeNode::withValidation).collect(Collectors.toSet())); } public void rebuildRootNode(ObjectMaterialHierarchyDto materials) { @@ -129,7 +131,6 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { needOneSelectionNodes.forEach(n -> n.computeNeedAtLeastOnSelectValidState(whenArriving, whenLeaving)); mandatoryNodes.forEach(n -> n.computeMandatoryValidState(whenArriving, whenLeaving)); - withValidationNodes.forEach(n -> n.computeFormulaValidState(whenArriving, whenLeaving)); boolean notValid = allNodes.stream().anyMatch(FloatingObjectPartsTreeNode::isNotValid); uiModel.getBean().setMaterialsValid(!notValid); ===================================== dto/src/main/java/fr/ird/observe/dto/data/seine/ObjectMaterialHierarchyDto.java ===================================== @@ -22,6 +22,7 @@ package fr.ird.observe.dto.data.seine; * #L% */ +import fr.ird.observe.dto.referential.FormulaHelper; import fr.ird.observe.dto.referential.seine.ObjectMaterialDto; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -60,6 +61,20 @@ public class ObjectMaterialHierarchyDto extends ObjectMaterialDto { return result; } + public boolean isValid(Object value) { + if (value==null) { + return true; + } + if (isText()) { + return FormulaHelper.validateObjectMaterialValidation(validation, value); + } else if (isInteger()) { + return FormulaHelper.validateObjectMaterialValidation(validation, Integer.valueOf(value.toString())); + } else if (isFloat()) { + return FormulaHelper.validateObjectMaterialValidation(validation, Float.valueOf(value.toString())); + } + throw new IllegalStateException("Can't validate this dto... "+this); + } + private void getAllDtos(ObjectMaterialHierarchyDto hierarchyDto, Set<ObjectMaterialHierarchyDto> result) { result.add(hierarchyDto); hierarchyDto.getChildren().forEach(c -> getAllDtos(c, result)); View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/cb682d5495dac9538a460a4c4ef5... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/cb682d5495dac9538a460a4c4ef5... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT