Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: 1f822451 by Tony CHEMIT at 2018-06-18T23:58:39Z Fix global actoins when no data source - - - - - 7dcff733 by Tony CHEMIT at 2018-06-18T23:59:52Z [PS] Formulaire DCP / matériaux / champs numériques - Closes #968 [PS] Formulaire DCP / matériaux / recopie de l'état départ <-> arrivée - See #971 (more improvements) - - - - - 7 changed files: - client/src/main/java/fr/ird/observe/client/ui/actions/main/global/ChangeFocusGlobalUIAction.java - client/src/main/java/fr/ird/observe/client/ui/actions/main/global/GlobalUIActionSupport.java - 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/FloatingObjectUIModel.java - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeNode.java - dto/src/main/java/fr/ird/observe/dto/referential/seine/ObjectMaterialDto.java - persistence/src/main/java/fr/ird/observe/binder/referential/seine/ObjectMaterialEntityReferenceBinder.java Changes: ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/main/global/ChangeFocusGlobalUIAction.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/actions/main/global/ChangeFocusGlobalUIAction.java +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/main/global/ChangeFocusGlobalUIAction.java @@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.actions.main.global; * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. @@ -24,6 +24,7 @@ package fr.ird.observe.client.ui.actions.main.global; import fr.ird.observe.client.ui.ObserveKeyStrokes; import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.ObserveUIMode; import fr.ird.observe.client.ui.actions.UIActionSupport; import fr.ird.observe.client.ui.content.ContentUI; import org.apache.commons.logging.Log; @@ -43,10 +44,8 @@ import java.util.Objects; */ public class ChangeFocusGlobalUIAction extends UIActionSupport { - /** Logger */ - private static final Log log = LogFactory.getLog(ChangeFocusGlobalUIAction.class); - public static final String ACTION_NAME = ChangeFocusGlobalUIAction.class.getName(); + private static final Log log = LogFactory.getLog(ChangeFocusGlobalUIAction.class); public ChangeFocusGlobalUIAction(ObserveMainUI mainUI) { super(mainUI, ACTION_NAME, "<NONE>", "<NONE>", null, ObserveKeyStrokes.KEY_STROKE_CHANGE_FOCUS); @@ -54,6 +53,9 @@ public class ChangeFocusGlobalUIAction extends UIActionSupport { @Override public void actionPerformed(ActionEvent e) { + if (!Objects.equals(getMainUI().getModel().getMode(), ObserveUIMode.DB)) { + return; + } boolean navigation = getMainUI().getModel().isFocusOnNavigation(); JComponent focusComponent; ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/main/global/GlobalUIActionSupport.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/actions/main/global/GlobalUIActionSupport.java +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/main/global/GlobalUIActionSupport.java @@ -24,6 +24,7 @@ package fr.ird.observe.client.ui.actions.main.global; import fr.ird.observe.client.ObserveSwingApplicationContext; import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.ObserveUIMode; import fr.ird.observe.client.ui.actions.UIActionSupport; import fr.ird.observe.client.ui.content.ContentUI; @@ -31,6 +32,7 @@ import javax.swing.JComponent; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import java.awt.event.ActionEvent; +import java.util.Objects; /** * Created on 11/11/16. @@ -47,7 +49,9 @@ public abstract class GlobalUIActionSupport extends UIActionSupport { protected abstract UIActionSupport getDelegateAction(ContentUI<?, ?> contentUI); public void actionPerformed(ActionEvent e) { - + if (!Objects.equals(getMainUI().getModel().getMode(), ObserveUIMode.DB)) { + return; + } boolean focusOnNavigation = getMainUI().getModel().isFocusOnNavigation(); JComponent focusOwner = (JComponent) getMainUI().getFocusOwner(); ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java @@ -187,7 +187,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, getModel().reset(); - openTable(partsSet, getUi().getTable(),bean.isPersisted()); + openTable(partsSet, getUi().getTable(), bean.isPersisted()); setContentMode(mode); @@ -263,11 +263,10 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, saveResult.toDto(bean); ImmutableSet<FloatingObjectPartDto> parts = getModel().toParts(); - getFloatingObjectService().saveParts(saveResult.getId(), parts); + log.info(String.format("will persist %d part(s).", parts.size())); + saveResult = getFloatingObjectService().saveParts(saveResult.getId(), parts); saveResult.toDto(bean); - return true; - } @Override @@ -326,7 +325,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, ObjectMaterialHierarchyDto detailedForm = getFloatingObjectService().getObjectMaterialHierarchy(); - ObjectMaterialTypeReference booleanType = getReferentialReferences(ObjectMaterialTypeReference.class).stream().filter(e->e.getTopiaId().equals("fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#0")).findFirst().orElseThrow(IllegalStateException::new); + ObjectMaterialTypeReference booleanType = getReferentialReferences(ObjectMaterialTypeReference.class).stream().filter(e -> e.getTopiaId().equals("fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#0")).findFirst().orElseThrow(IllegalStateException::new); for (ObjectMaterialHierarchyDto objectMaterialHierarchyDto : detailedForm.getChildren()) { objectMaterialHierarchyDto.setObjectMaterialType(booleanType); @@ -414,6 +413,9 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, treeModel.addTreeModelListener(new TreeModelAdapter() { @Override public void treeNodesChanged(TreeModelEvent e) { + if (treeModel.isAdjusting()) { + return; + } getModel().setModified(true); getModel().setPartsModified(); } ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java @@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.content.data.seine; * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. @@ -44,6 +44,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -55,48 +56,41 @@ import static org.nuiton.i18n.I18n.t; */ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { - private static final long serialVersionUID = 1L; - - static final String PROPERTY_PARTS_MODIFIED = "partsModified"; public static final String PROPERTY_GENERAL_TAB_VALID = "generalTabValid"; - private static final String PROPERTY_MATERIALS_TAB_VALID = "materialsTabValid"; + public static final Set<String> GENERAL_TAB_PROPERTIES = + ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_OBJECT_OPERATION, + FloatingObjectDto.PROPERTY_SUPPORT_VESSEL_NAME, + FloatingObjectDto.PROPERTY_COMMENT).build(); + static final String PROPERTY_PARTS_MODIFIED = "partsModified"; static final String PROPERTY_REFERENCE = "reference"; + static final Set<String> MATERIALS_TAB_PROPERTIES = + ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_COMMENT, FloatingObjectDto.PROPERTY_MATERIALS_VALID).build(); + private static final long serialVersionUID = 1L; + private static final String PROPERTY_MATERIALS_TAB_VALID = "materialsTabValid"; private static final String PROPERTY_ARRIVING = "arriving"; private static final String PROPERTY_LEAVING = "leaving"; - + /** Logger. */ + private static final Log log = LogFactory.getLog(FloatingObjectUIModel.class); private final ReferentialLocale referentialLocale; - + private final ReferentialDtoReferenceBinder<ObjectMaterialDto, ObjectMaterialReference> binder; + private final Map<ObjectMaterialDto, String> whenArriving; + private final Map<ObjectMaterialDto, String> whenLeaving; + protected boolean generalTabValid; private Map<String, ObjectMaterialDto> referentialMap; private FloatingObjectPreset reference; private boolean arriving; private boolean leaving; - private final ReferentialDtoReferenceBinder<ObjectMaterialDto, ObjectMaterialReference> binder; - + private boolean materialsTabValid; public FloatingObjectUIModel() { super(FloatingObjectDto.class); - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); this.referentialLocale = applicationContext.getDecoratorService().getReferentialLocale(); this.whenArriving = new LinkedHashMap<>(); this.whenLeaving = new LinkedHashMap<>(); - binder = DtoModelHelper.fromReferentialDto(ObjectMaterialDto.class).toReferenceBinder(); + this.binder = DtoModelHelper.fromReferentialDto(ObjectMaterialDto.class).toReferenceBinder(); } - public static final Set<String> GENERAL_TAB_PROPERTIES = - ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_OBJECT_OPERATION, - FloatingObjectDto.PROPERTY_SUPPORT_VESSEL_NAME, - FloatingObjectDto.PROPERTY_COMMENT).build(); - - static final Set<String> MATERIALS_TAB_PROPERTIES = - ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_COMMENT, FloatingObjectDto.PROPERTY_MATERIALS_VALID).build(); - - protected boolean generalTabValid; - private boolean materialsTabValid; - - private final Map<ObjectMaterialDto, String> whenArriving; - private final Map<ObjectMaterialDto, String> whenLeaving; - public boolean isMaterialsTabValid() { return materialsTabValid; } @@ -119,11 +113,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { ImmutableSet<FloatingObjectPartDto> toParts() { ImmutableSet.Builder<FloatingObjectPartDto> result = ImmutableSet.builder(); - for (ObjectMaterialDto o : getAll()) { - if (o.getParent()!=null && o.getParent().getParentId()==null) { - // first level node, can't be send - continue; - } + for (ObjectMaterialDto o : getAllWithData()) { FloatingObjectPartDto partDto = new FloatingObjectPartDto(); partDto.setObjectMaterial(binder.toReference(referentialLocale, o)); if (arriving) { @@ -165,10 +155,10 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { return whenLeaving; } - public Set<ObjectMaterialDto> getAll() { + public Set<ObjectMaterialDto> getAllWithData() { Set<ObjectMaterialDto> all = new LinkedHashSet<>(whenArriving.keySet()); all.addAll(whenLeaving.keySet()); - return all; + return all.stream().filter(ObjectMaterialDto::withData).collect(Collectors.toSet()); } void setReferentialMap(Map<String, ObjectMaterialDto> referentialMap) { @@ -234,9 +224,6 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { return arriving; } - /** Logger. */ - private static final Log log = LogFactory.getLog(FloatingObjectUIModel.class); - public void setArriving(boolean arriving) { this.arriving = arriving; log.debug("setArriving: " + arriving); @@ -253,17 +240,4 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { firePropertyChange(PROPERTY_LEAVING, leaving); } - void recomputeComputedValues() { - FloatingObjectDto bean = getBean(); - - log.info("Computed values need to be recomputed."); - bean.setComputedWhenArrivingBiodegradable(null); - bean.setComputedWhenArrivingNonEntangling(null); - bean.setComputedWhenArrivingSimplifiedObjectType(null); - bean.setComputedWhenLeavingBiodegradable(null); - bean.setComputedWhenLeavingNonEntangling(null); - bean.setComputedWhenLeavingSimplifiedObjectType(null); - fireComputedValuesChanged(); - } - } ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeNode.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeNode.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeNode.java @@ -63,9 +63,8 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im if (dto != null) { FloatingObjectPartsTreeNodeContext childModel = new FloatingObjectPartsTreeNodeContext(dto, rootModel); root = new FloatingObjectPartsTreeNode(childModel); - ImmutableSet.Builder<FloatingObjectPartsTreeNode> companionsBuilder = dto.isChildrenMultiSelectable() ? ImmutableSet.builder() : null; - root.computeCompanions(companionsBuilder); - root.setCompanions(companionsBuilder); + root.computeCompanions(null); + root.setCompanions(null); } else { root = new FloatingObjectPartsTreeNode(rootModel); } @@ -276,13 +275,19 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im companionsBuilder.add(this); } - ImmutableSet.Builder<FloatingObjectPartsTreeNode> childCompanionsBuilder = getUserObject().dto.isChildrenMultiSelectable() ? ImmutableSet.builder() : null; + ImmutableSet.Builder<FloatingObjectPartsTreeNode> childCompanionsBuilder = needCompanions() ? ImmutableSet.builder() : null; for (FloatingObjectPartsTreeNode child : this) { child.computeCompanions(childCompanionsBuilder); } setCompanions(childCompanionsBuilder); } + + private boolean needCompanions() { + ObjectMaterialHierarchyDto dto = getUserObject().dto; + return dto != null && !dto.isChildrenMultiSelectable() && !isLeaf(); + } + private static class FloatingObjectPartsTreeNodeContext { // main model to get and store values @@ -334,7 +339,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im // mandatory if enabled parent is so or parent makes this child to be this.mandatory = parent.mandatory || parent.needOneSelection; // exclusive if his parent requires it - this.exclusive = parent.dto != null && parent.dto.isChildrenMultiSelectable(); + this.exclusive = parent.dto != null && !parent.dto.isChildrenMultiSelectable(); log.info(String.format("New node: %s - mandatory %s - needOneSelection %s - exclusive %s", dto.getLabel2(), mandatory, needOneSelection, exclusive)); } ===================================== dto/src/main/java/fr/ird/observe/dto/referential/seine/ObjectMaterialDto.java ===================================== --- a/dto/src/main/java/fr/ird/observe/dto/referential/seine/ObjectMaterialDto.java +++ b/dto/src/main/java/fr/ird/observe/dto/referential/seine/ObjectMaterialDto.java @@ -10,19 +10,18 @@ package fr.ird.observe.dto.referential.seine; * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -import fr.ird.observe.dto.referential.FormulaHelper; import org.apache.commons.lang3.StringUtils; public class ObjectMaterialDto extends GeneratedObjectMaterialDto { @@ -45,14 +44,15 @@ public class ObjectMaterialDto extends GeneratedObjectMaterialDto { return objectMaterialType != null && "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#1".equals(objectMaterialType.getId()); } - @Override - public void setValidation(String validation) { - super.setValidation(validation); - boolean result = FormulaHelper.validateObjectMaterialValidation(validation, 10); - setValidationValid(result); - } - public boolean withValidation() { return StringUtils.isNoneEmpty(validation); } + + /** + * @return {code true} if node contains no data to persist, {@code false} otherwise. + */ + public boolean withData() { + ObjectMaterialReference parent = getParent(); + return parent != null && parent.getParentId() != null; + } } ===================================== persistence/src/main/java/fr/ird/observe/binder/referential/seine/ObjectMaterialEntityReferenceBinder.java ===================================== --- a/persistence/src/main/java/fr/ird/observe/binder/referential/seine/ObjectMaterialEntityReferenceBinder.java +++ b/persistence/src/main/java/fr/ird/observe/binder/referential/seine/ObjectMaterialEntityReferenceBinder.java @@ -45,7 +45,7 @@ public class ObjectMaterialEntityReferenceBinder extends ReferentialEntityRefere @Override public ObjectMaterialReference toReference(ReferentialLocale referentialLocale, ObjectMaterial dto) { return new ObjectMaterialReference(dto, dto.getCode(), dto.getLabel(referentialLocale), - Optional.ofNullable(dto.getParent()).map(ObjectMaterial::getParent).map(TopiaEntity::getTopiaId).orElse(null), + Optional.ofNullable(dto.getParent()).map(TopiaEntity::getTopiaId).orElse(null), Optional.ofNullable(dto.getObjectMaterialType()).map(TopiaEntity::getTopiaId).orElse(null), dto.getValidation(), dto.isBiodegradable(), View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/106dfb41d501317fea7476b5e8f... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/106dfb41d501317fea7476b5e8f... You're receiving this email because of your account on gitlab.com.