Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
45aa53d8
by Tony CHEMIT at 2017-08-05T12:36:08+02:00
-
dbd5e228
by Tony CHEMIT at 2017-08-05T19:27:48+02:00
29 changed files:
- client-validation/src/main/resources/fr/ird/observe/services/dto/seine/FloatingObjectDto-create-error-validation.xml
- client-validation/src/main/resources/fr/ird/observe/services/dto/seine/FloatingObjectDto-update-error-validation.xml
- client-validation/src/main/resources/i18n/client-validation_en_GB.properties
- client-validation/src/main/resources/i18n/client-validation_es_ES.properties
- client-validation/src/main/resources/i18n/client-validation_fr_FR.properties
- client/pom.xml
- client/src/main/java/fr/ird/observe/client/ui/actions/content/CopyFloatingObjectPartToLeftAction.java
- client/src/main/java/fr/ird/observe/client/ui/actions/content/CopyFloatingObjectPartToRightAction.java
- client/src/main/java/fr/ird/observe/client/ui/content/ContentUIHandler.java
- − client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectPartsTreeNode.java
- client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUI.jaxx
- client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUI.jcss
- client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIHandler.java
- client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIModel.java
- + client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/dcp/FloatingObjectPartLegendTreeCellRenderer.java
- + client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/dcp/FloatingObjectPartsTableCellEditor.java
- + client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/dcp/FloatingObjectPartsTableCellRenderer.java
- + client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/dcp/FloatingObjectPartsTreeNode.java
- + client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/dcp/FloatingObjectPartsTreeTableModel.java
- + client/src/main/java/fr/ird/observe/client/ui/util/treetable/JRadioButtonCellEditor.java
- + client/src/main/java/fr/ird/observe/client/ui/util/treetable/JRadioButtonProvider.java
- + client/src/main/java/fr/ird/observe/client/ui/util/treetable/JRendererRadioButton.java
- persistence/src/main/java/fr/ird/observe/persistence/ObserveTopiaPersistenceContext.java
- services/src/main/java/fr/ird/observe/services/decoration/ObserveI18nDecoratorHelper.java
- + services/src/main/java/fr/ird/observe/services/dto/referential/seine/ObjectMaterialDto.java
- services/src/main/models/Observe.model
- services/src/main/resources/i18n/services_en_GB.properties
- services/src/main/resources/i18n/services_es_ES.properties
- services/src/main/resources/i18n/services_fr_FR.properties
Changes:
| ... | ... | @@ -82,4 +82,16 @@ |
| 82 | 82 |
|
| 83 | 83 |
</field>
|
| 84 | 84 |
|
| 85 |
+ <field name="materialsValid">
|
|
| 86 |
+ |
|
| 87 |
+ <!-- erreurs sur les materiaux -->
|
|
| 88 |
+ <field-validator type="fieldexpression">
|
|
| 89 |
+ <param name="expression">
|
|
| 90 |
+ <![CDATA[ materialsValid ]]>
|
|
| 91 |
+ </param>
|
|
| 92 |
+ <message>observe.validation.floatingObject.invalid.parts</message>
|
|
| 93 |
+ </field-validator>
|
|
| 94 |
+ |
|
| 95 |
+ </field>
|
|
| 96 |
+ |
|
| 85 | 97 |
</validators>
|
| ... | ... | @@ -81,4 +81,16 @@ |
| 81 | 81 |
</field-validator>
|
| 82 | 82 |
</field>
|
| 83 | 83 |
|
| 84 |
+ <field name="materialsValid">
|
|
| 85 |
+ |
|
| 86 |
+ <!-- erreurs sur les materiaux -->
|
|
| 87 |
+ <field-validator type="fieldexpression">
|
|
| 88 |
+ <param name="expression">
|
|
| 89 |
+ <![CDATA[ materialsValid ]]>
|
|
| 90 |
+ </param>
|
|
| 91 |
+ <message>observe.validation.floatingObject.invalid.parts</message>
|
|
| 92 |
+ </field-validator>
|
|
| 93 |
+ |
|
| 94 |
+ </field>
|
|
| 95 |
+ |
|
| 84 | 96 |
</validators>
|
| ... | ... | @@ -102,6 +102,7 @@ observe.validation.encounter.required.species=Species must be filled. |
| 102 | 102 |
observe.validation.floatingObject.comment.tobig=Comment size can not exceed 1024 characters.
|
| 103 | 103 |
observe.validation.floatingObject.desactivated.objectOperation=Selected operation is disabled.
|
| 104 | 104 |
observe.validation.floatingObject.desactivated.type=Selected type is disabled.
|
| 105 |
+observe.validation.floatingObject.invalid.parts=There is some errors in materials table.
|
|
| 105 | 106 |
observe.validation.floatingObject.required.comment.for.balise1=A comment is required for the selected buoy.
|
| 106 | 107 |
observe.validation.floatingObject.required.comment.for.balise2=A comment is required for the selected buoy.
|
| 107 | 108 |
observe.validation.floatingObject.required.comment.for.objectFate=A comment is required for the selected object fate.
|
| ... | ... | @@ -102,6 +102,7 @@ observe.validation.encounter.required.species=La selección de una especie es ma |
| 102 | 102 |
observe.validation.floatingObject.comment.tobig=La longitud del campo de comentarios está limitada a 1024 carácteres.
|
| 103 | 103 |
observe.validation.floatingObject.desactivated.objectOperation=Al menos una de las operaciones seleccionadas está desactivada.
|
| 104 | 104 |
observe.validation.floatingObject.desactivated.type=El tipo de objeto seleccionado está desactivado.
|
| 105 |
+observe.validation.floatingObject.invalid.parts=There is some errors in materials table. \#TODO
|
|
| 105 | 106 |
observe.validation.floatingObject.required.comment.for.balise1=Se requiere un comentario para la primera baliza (étant donné son type).
|
| 106 | 107 |
observe.validation.floatingObject.required.comment.for.balise2=Se requiere un comentario para la segunda baliza (étant donné son type).
|
| 107 | 108 |
observe.validation.floatingObject.required.comment.for.objectFate=Se requiere un comentario para el devenir.
|
| ... | ... | @@ -102,6 +102,7 @@ observe.validation.encounter.required.species=La sélection d'une espèce est ob |
| 102 | 102 |
observe.validation.floatingObject.comment.tobig=La taille du commentaire est limitée à 1024 caractères.
|
| 103 | 103 |
observe.validation.floatingObject.desactivated.objectOperation=Au moins une des opérations sélectionnée est désactivée.
|
| 104 | 104 |
observe.validation.floatingObject.desactivated.type=Le type d'objet sélectionné est désactivé.
|
| 105 |
+observe.validation.floatingObject.invalid.parts=Erreurs détectées sur le tableau des matériaux.
|
|
| 105 | 106 |
observe.validation.floatingObject.required.comment.for.balise1=Un commentaire est requis pour la première balise (étant donné son type).
|
| 106 | 107 |
observe.validation.floatingObject.required.comment.for.balise2=Un commentaire est requis pour la seconde balise (étant donné son type).
|
| 107 | 108 |
observe.validation.floatingObject.required.comment.for.objectFate=Un commentaire est requis pour le devenir objet.
|
| ... | ... | @@ -588,6 +588,11 @@ |
| 588 | 588 |
<groupId>junit</groupId>
|
| 589 | 589 |
<artifactId>junit</artifactId>
|
| 590 | 590 |
</dependency>
|
| 591 |
+ <dependency>
|
|
| 592 |
+ <groupId>org.jetbrains</groupId>
|
|
| 593 |
+ <artifactId>annotations</artifactId>
|
|
| 594 |
+ <version>RELEASE</version>
|
|
| 595 |
+ </dependency>
|
|
| 591 | 596 |
|
| 592 | 597 |
</dependencies>
|
| 593 | 598 |
|
| ... | ... | @@ -25,7 +25,7 @@ package fr.ird.observe.client.ui.actions.content; |
| 25 | 25 |
import fr.ird.observe.client.ui.ObserveKeyStrokes;
|
| 26 | 26 |
import fr.ird.observe.client.ui.ObserveMainUI;
|
| 27 | 27 |
import fr.ird.observe.client.ui.content.ContentUI;
|
| 28 |
-import fr.ird.observe.client.ui.content.impl.seine.FloatingObjectPartsTreeNode;
|
|
| 28 |
+import fr.ird.observe.client.ui.content.impl.seine.dcp.FloatingObjectPartsTreeNode;
|
|
| 29 | 29 |
import fr.ird.observe.client.ui.content.impl.seine.FloatingObjectUI;
|
| 30 | 30 |
import java.util.Enumeration;
|
| 31 | 31 |
import org.apache.commons.logging.Log;
|
| ... | ... | @@ -25,7 +25,7 @@ package fr.ird.observe.client.ui.actions.content; |
| 25 | 25 |
import fr.ird.observe.client.ui.ObserveKeyStrokes;
|
| 26 | 26 |
import fr.ird.observe.client.ui.ObserveMainUI;
|
| 27 | 27 |
import fr.ird.observe.client.ui.content.ContentUI;
|
| 28 |
-import fr.ird.observe.client.ui.content.impl.seine.FloatingObjectPartsTreeNode;
|
|
| 28 |
+import fr.ird.observe.client.ui.content.impl.seine.dcp.FloatingObjectPartsTreeNode;
|
|
| 29 | 29 |
import fr.ird.observe.client.ui.content.impl.seine.FloatingObjectUI;
|
| 30 | 30 |
import java.util.Enumeration;
|
| 31 | 31 |
import org.apache.commons.logging.Log;
|
| ... | ... | @@ -563,9 +563,7 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U |
| 563 | 563 |
NavigationTreeNodeSupport parentNode = treeHelper.getSelectedNode();
|
| 564 | 564 |
String id = entity.getId();
|
| 565 | 565 |
NavigationTreeNodeSupport node = treeHelper.getChild(parentNode, id);
|
| 566 |
- if (log.isInfoEnabled()) {
|
|
| 567 |
- log.info("will go to node " + node + " for " + id);
|
|
| 568 |
- }
|
|
| 566 |
+ log.debug("will go to node " + node + " for " + id);
|
|
| 569 | 567 |
treeHelper.selectNode(node);
|
| 570 | 568 |
}
|
| 571 | 569 |
|
| ... | ... | @@ -602,7 +600,7 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U |
| 602 | 600 |
|
| 603 | 601 |
ImmutableMap.Builder<String, ReferentialReferenceSet<?>> modelReferentialReferenceSets = ImmutableMap.builder();
|
| 604 | 602 |
|
| 605 |
- log.info("Update referential reference sets for: " + requestName);
|
|
| 603 |
+ log.debug("Update referential reference sets for: " + requestName);
|
|
| 606 | 604 |
|
| 607 | 605 |
// mettre à jour le cache de référentiel
|
| 608 | 606 |
ImmutableMap<Class<?>, ReferentialReferenceSet<?>> referentialReferenceSetsByType = getDataSource().updateReferentialReferenceSetsCache(requestName);
|
| 1 |
-package fr.ird.observe.client.ui.content.impl.seine;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.services.dto.referential.seine.ObjectMaterialDto;
|
|
| 26 |
-import fr.ird.observe.services.dto.seine.ObjectMaterialHierarchyDto;
|
|
| 27 |
-import java.util.Iterator;
|
|
| 28 |
-import org.jdesktop.swingx.treetable.AbstractMutableTreeTableNode;
|
|
| 29 |
-import org.nuiton.decorator.Decorator;
|
|
| 30 |
- |
|
| 31 |
-/**
|
|
| 32 |
- * Created by tchemit on 30/05/17.
|
|
| 33 |
- *
|
|
| 34 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 35 |
- */
|
|
| 36 |
-public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode implements Iterable<FloatingObjectPartsTreeNode> {
|
|
| 37 |
- |
|
| 38 |
- private final FloatingObjectUIModel model;
|
|
| 39 |
- private final Decorator<ObjectMaterialDto> decorator;
|
|
| 40 |
- |
|
| 41 |
- FloatingObjectPartsTreeNode(Decorator<ObjectMaterialDto> decorator, FloatingObjectUIModel model, ObjectMaterialHierarchyDto userObject) {
|
|
| 42 |
- super(userObject);
|
|
| 43 |
- this.decorator = decorator;
|
|
| 44 |
- this.model = model;
|
|
| 45 |
- userObject.getChildren().forEach(u -> add(new FloatingObjectPartsTreeNode(decorator, model, u)));
|
|
| 46 |
- }
|
|
| 47 |
- |
|
| 48 |
- @Override
|
|
| 49 |
- public ObjectMaterialHierarchyDto getUserObject() {
|
|
| 50 |
- return (ObjectMaterialHierarchyDto) super.getUserObject();
|
|
| 51 |
- }
|
|
| 52 |
- |
|
| 53 |
- @Override
|
|
| 54 |
- public Object getValueAt(int column) {
|
|
| 55 |
- switch (column) {
|
|
| 56 |
- case 0: // label
|
|
| 57 |
- return decorator.toString(getUserObject());
|
|
| 58 |
- case 1: // when arriving
|
|
| 59 |
- return model.getWhenArriving().get(getUserObject());
|
|
| 60 |
- case 2: // when leaving
|
|
| 61 |
- return model.getWhenLeaving().get(getUserObject());
|
|
| 62 |
- |
|
| 63 |
- |
|
| 64 |
- }
|
|
| 65 |
- return null;
|
|
| 66 |
- }
|
|
| 67 |
- |
|
| 68 |
- @Override
|
|
| 69 |
- public void setValueAt(Object aValue, int column) {
|
|
| 70 |
- switch (column) {
|
|
| 71 |
- case 1: // when arriving
|
|
| 72 |
- model.setWhenArriving(getUserObject().getId(), aValue == null ? null : String.valueOf(aValue));
|
|
| 73 |
- break;
|
|
| 74 |
- case 2: // when leaving
|
|
| 75 |
- model.setWhenLeaving(getUserObject().getId(), aValue == null ? null : String.valueOf(aValue));
|
|
| 76 |
- break;
|
|
| 77 |
- }
|
|
| 78 |
- }
|
|
| 79 |
- |
|
| 80 |
- @Override
|
|
| 81 |
- public boolean isEditable(int column) {
|
|
| 82 |
- boolean result = column > 0 && getUserObject().isSelectable();
|
|
| 83 |
- if (result) {
|
|
| 84 |
- switch (column) {
|
|
| 85 |
- case 1: // when arriving
|
|
| 86 |
- result = model.isArriving();
|
|
| 87 |
- break;
|
|
| 88 |
- case 2: // when leaving
|
|
| 89 |
- result = model.isLeaving();
|
|
| 90 |
- break;
|
|
| 91 |
- }
|
|
| 92 |
- }
|
|
| 93 |
- return result;
|
|
| 94 |
- }
|
|
| 95 |
- |
|
| 96 |
- @Override
|
|
| 97 |
- public int getColumnCount() {
|
|
| 98 |
- return 3;
|
|
| 99 |
- }
|
|
| 100 |
- |
|
| 101 |
- @Override
|
|
| 102 |
- public Iterator<FloatingObjectPartsTreeNode> iterator() {
|
|
| 103 |
- return (Iterator) children.iterator();
|
|
| 104 |
- }
|
|
| 105 |
-}
|
| ... | ... | @@ -38,6 +38,8 @@ |
| 38 | 38 |
fr.ird.observe.client.ui.actions.global.DeleteDataGlobalUIAction
|
| 39 | 39 |
fr.ird.observe.client.ui.actions.global.ResetDataGlobalUIAction
|
| 40 | 40 |
fr.ird.observe.client.ui.actions.global.SaveDataGlobalUIAction
|
| 41 |
+ fr.ird.observe.client.ui.content.impl.seine.dcp.FloatingObjectPartsTreeTableModel
|
|
| 42 |
+ fr.ird.observe.client.ui.content.impl.seine.dcp.FloatingObjectPartLegendTreeCellRenderer
|
|
| 41 | 43 |
fr.ird.observe.client.ui.util.JComment
|
| 42 | 44 |
|
| 43 | 45 |
org.jdesktop.swingx.JXTreeTable
|
| ... | ... | @@ -46,6 +48,7 @@ |
| 46 | 48 |
org.nuiton.jaxx.widgets.select.BeanComboBox
|
| 47 | 49 |
|
| 48 | 50 |
java.awt.Dimension
|
| 51 |
+ javax.swing.ListSelectionModel
|
|
| 49 | 52 |
|
| 50 | 53 |
static fr.ird.observe.client.ui.UIHelper.getStringValue
|
| 51 | 54 |
static org.nuiton.i18n.I18n.n
|
| ... | ... | @@ -61,7 +64,9 @@ |
| 61 | 64 |
|
| 62 | 65 |
<!-- validator -->
|
| 63 | 66 |
<BeanValidator id='validator' autoField='true' context='create' errorTableModel='{getErrorTableModel()}'
|
| 64 |
- beanClass='fr.ird.observe.services.dto.seine.FloatingObjectDto'/>
|
|
| 67 |
+ beanClass='fr.ird.observe.services.dto.seine.FloatingObjectDto'>
|
|
| 68 |
+ <field name="materialsValid" component="tableScroll"/>
|
|
| 69 |
+ </BeanValidator>
|
|
| 65 | 70 |
|
| 66 | 71 |
<!-- formulaire -->
|
| 67 | 72 |
<JPanel id="body" layout='{new BorderLayout()}'>
|
| ... | ... | @@ -168,3 +168,9 @@ BeanComboBox { |
| 168 | 168 |
focusable:false;
|
| 169 | 169 |
}
|
| 170 | 170 |
|
| 171 |
+#table {
|
|
| 172 |
+ treeTableModel:{new FloatingObjectPartsTreeTableModel(getModel())};
|
|
| 173 |
+ treeCellRenderer:{new FloatingObjectPartLegendTreeCellRenderer()};
|
|
| 174 |
+ selectionMode:{ListSelectionModel.SINGLE_SELECTION};
|
|
| 175 |
+}
|
|
| 176 |
+ |
| ... | ... | @@ -29,6 +29,10 @@ import fr.ird.observe.client.db.constants.DataContextType; |
| 29 | 29 |
import fr.ird.observe.client.ui.content.ContentMode;
|
| 30 | 30 |
import fr.ird.observe.client.ui.content.ContentUIHandler;
|
| 31 | 31 |
import fr.ird.observe.client.ui.content.ContentUIModel;
|
| 32 |
+import fr.ird.observe.client.ui.content.impl.seine.dcp.FloatingObjectPartsTableCellEditor;
|
|
| 33 |
+import fr.ird.observe.client.ui.content.impl.seine.dcp.FloatingObjectPartsTableCellRenderer;
|
|
| 34 |
+import fr.ird.observe.client.ui.content.impl.seine.dcp.FloatingObjectPartsTreeNode;
|
|
| 35 |
+import fr.ird.observe.client.ui.content.impl.seine.dcp.FloatingObjectPartsTreeTableModel;
|
|
| 32 | 36 |
import fr.ird.observe.client.ui.tree.navigation.NavigationTree;
|
| 33 | 37 |
import fr.ird.observe.client.ui.tree.navigation.nodes.NavigationTreeNodeSupport;
|
| 34 | 38 |
import fr.ird.observe.services.dto.FloatingObjectReference;
|
| ... | ... | @@ -44,9 +48,7 @@ import fr.ird.observe.services.dto.seine.FloatingObjectHelper; |
| 44 | 48 |
import fr.ird.observe.services.dto.seine.FloatingObjectPartDto;
|
| 45 | 49 |
import fr.ird.observe.services.dto.seine.ObjectMaterialHierarchyDto;
|
| 46 | 50 |
import fr.ird.observe.services.service.data.seine.FloatingObjectService;
|
| 47 |
-import java.awt.Component;
|
|
| 48 |
-import java.util.Arrays;
|
|
| 49 |
-import java.util.EventObject;
|
|
| 51 |
+import java.awt.Color;
|
|
| 50 | 52 |
import java.util.HashSet;
|
| 51 | 53 |
import java.util.List;
|
| 52 | 54 |
import java.util.Map;
|
| ... | ... | @@ -55,25 +57,17 @@ import java.util.Optional; |
| 55 | 57 |
import java.util.Set;
|
| 56 | 58 |
import java.util.TreeMap;
|
| 57 | 59 |
import javax.swing.Icon;
|
| 58 |
-import javax.swing.JTable;
|
|
| 59 |
-import javax.swing.JTree;
|
|
| 60 | 60 |
import javax.swing.SwingUtilities;
|
| 61 |
-import javax.swing.event.CellEditorListener;
|
|
| 62 | 61 |
import javax.swing.event.TableModelListener;
|
| 63 | 62 |
import javax.swing.event.TreeModelEvent;
|
| 64 |
-import javax.swing.table.TableCellEditor;
|
|
| 65 |
-import javax.swing.table.TableCellRenderer;
|
|
| 66 | 63 |
import org.apache.commons.logging.Log;
|
| 67 | 64 |
import org.apache.commons.logging.LogFactory;
|
| 68 | 65 |
import org.apache.log4j.lf5.viewer.categoryexplorer.TreeModelAdapter;
|
| 69 | 66 |
import org.jdesktop.swingx.JXTable;
|
| 70 | 67 |
import org.jdesktop.swingx.JXTreeTable;
|
| 68 |
+import org.jdesktop.swingx.decorator.ColorHighlighter;
|
|
| 71 | 69 |
import org.jdesktop.swingx.table.ColumnFactory;
|
| 72 | 70 |
import org.jdesktop.swingx.table.TableColumnExt;
|
| 73 |
-import org.jdesktop.swingx.tree.DefaultXTreeCellRenderer;
|
|
| 74 |
-import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
|
|
| 75 |
-import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
|
|
| 76 |
-import org.nuiton.decorator.Decorator;
|
|
| 77 | 71 |
import org.nuiton.jaxx.runtime.spi.UIHandler;
|
| 78 | 72 |
import org.nuiton.jaxx.runtime.swing.SwingUtil;
|
| 79 | 73 |
import org.nuiton.jaxx.validator.swing.SwingValidatorMessage;
|
| ... | ... | @@ -219,13 +213,16 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 219 | 213 |
String objectMaterialId = (String) p.getPropertyValue(FloatingObjectPartDto.PROPERTY_OBJECT_MATERIAL + "Id");
|
| 220 | 214 |
String whenArriving = (String) p.getPropertyValue(FloatingObjectPartDto.PROPERTY_WHEN_ARRIVING);
|
| 221 | 215 |
String whenLeaving = (String) p.getPropertyValue(FloatingObjectPartDto.PROPERTY_WHEN_LEAVING);
|
| 222 |
- model.setWhenArriving(objectMaterialId, whenArriving);
|
|
| 223 |
- model.setWhenLeaving(objectMaterialId, whenLeaving);
|
|
| 216 |
+ if (whenArriving != null && !Objects.equals("false", whenArriving)) {
|
|
| 217 |
+ model.setWhenArriving(objectMaterialId, whenArriving);
|
|
| 218 |
+ }
|
|
| 219 |
+ if (whenLeaving != null && !Objects.equals("false", whenLeaving)) {
|
|
| 220 |
+ model.setWhenLeaving(objectMaterialId, whenLeaving);
|
|
| 221 |
+ }
|
|
| 224 | 222 |
}
|
| 225 | 223 |
|
| 226 |
- DefaultTreeTableModel treeTableModel = (DefaultTreeTableModel) table.getTreeTableModel();
|
|
| 227 |
- // force to reload model
|
|
| 228 |
- treeTableModel.setRoot(treeTableModel.getRoot());
|
|
| 224 |
+ FloatingObjectPartsTreeTableModel treeTableModel = (FloatingObjectPartsTreeTableModel) table.getTreeTableModel();
|
|
| 225 |
+ treeTableModel.reset();
|
|
| 229 | 226 |
|
| 230 | 227 |
table.expandAll();
|
| 231 | 228 |
}
|
| ... | ... | @@ -373,42 +370,8 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 373 | 370 |
|
| 374 | 371 |
private void initTable(List<ObjectMaterialHierarchyDto> materials, JXTreeTable table) {
|
| 375 | 372 |
|
| 376 |
- DefaultMutableTreeTableNode root = getModel().createRoot(getDecoratorService().getDecoratorByType(ObjectMaterialDto.class), materials);
|
|
| 377 |
- DefaultTreeTableModel treeModel = new DefaultTreeTableModel(root, Arrays.asList(
|
|
| 378 |
- t("observe.content.floatingObject.table.type"),
|
|
| 379 |
- t("observe.common.whenArriving"),
|
|
| 380 |
- t("observe.common.whenLeaving"))) {
|
|
| 381 |
- |
|
| 382 |
- @Override
|
|
| 383 |
- public int getColumnCount() {
|
|
| 384 |
- return 3;
|
|
| 385 |
- }
|
|
| 386 |
- |
|
| 387 |
- @Override
|
|
| 388 |
- public Class<?> getColumnClass(int column) {
|
|
| 389 |
- switch (column) {
|
|
| 390 |
- case 0:
|
|
| 391 |
- return String.class;
|
|
| 392 |
- case 1:
|
|
| 393 |
- case 2:
|
|
| 394 |
- return Object.class;
|
|
| 395 |
- |
|
| 396 |
- }
|
|
| 397 |
- throw new IllegalStateException();
|
|
| 398 |
- }
|
|
| 399 |
- |
|
| 400 |
- @Override
|
|
| 401 |
- public boolean isCellEditable(Object node, int column) {
|
|
| 402 |
- if (node instanceof FloatingObjectPartsTreeNode) {
|
|
| 403 |
- boolean rowEnabled = ((FloatingObjectPartsTreeNode) node).getUserObject().isEnabled();
|
|
| 404 |
- if (!rowEnabled) {
|
|
| 405 |
- return false;
|
|
| 406 |
- }
|
|
| 407 |
- }
|
|
| 408 |
- return super.isCellEditable(node, column);
|
|
| 409 |
- }
|
|
| 410 |
- };
|
|
| 411 |
- table.setTreeTableModel(treeModel);
|
|
| 373 |
+ FloatingObjectPartsTreeTableModel treeModel = (FloatingObjectPartsTreeTableModel) table.getTreeTableModel();
|
|
| 374 |
+ treeModel.rebuildRootNode(materials);
|
|
| 412 | 375 |
|
| 413 | 376 |
table.setColumnFactory(new ColumnFactory() {
|
| 414 | 377 |
|
| ... | ... | @@ -431,29 +394,26 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 431 | 394 |
}
|
| 432 | 395 |
|
| 433 | 396 |
});
|
| 434 |
- DefaultXTreeCellRenderer cellRenderer = new DefaultXTreeCellRenderer() {
|
|
| 435 | 397 |
|
| 436 |
- Decorator<ObjectMaterialDto> decorator = getDecoratorService().getDecoratorByType(ObjectMaterialDto.class);
|
|
| 437 |
- |
|
| 438 |
- @Override
|
|
| 439 |
- public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
|
| 440 |
- if (!(value instanceof FloatingObjectPartsTreeNode)) {
|
|
| 441 |
- return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
|
| 442 |
- }
|
|
| 443 |
- FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) value;
|
|
| 444 |
- Component result = super.getTreeCellRendererComponent(tree, decorator.toString(node.getUserObject()), sel, expanded, leaf, row, hasFocus);
|
|
| 445 |
- result.setEnabled(node.getUserObject().isEnabled());
|
|
| 446 |
- return result;
|
|
| 398 |
+ table.setDefaultRenderer(Object.class, new FloatingObjectPartsTableCellRenderer(table));
|
|
| 399 |
+ table.setDefaultEditor(Object.class, new FloatingObjectPartsTableCellEditor(table));
|
|
| 400 |
+ table.addHighlighter(new ColorHighlighter((renderer, adapter) -> {
|
|
| 401 |
+ JXTreeTable component = (JXTreeTable) adapter.getComponent();
|
|
| 402 |
+ int row = adapter.convertRowIndexToModel(adapter.row);
|
|
| 403 |
+ FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) component.getPathForRow(row).getLastPathComponent();
|
|
| 404 |
+ boolean valid1 = node.isValid(1);
|
|
| 405 |
+ boolean valid2 = node.isValid(2);
|
|
| 406 |
+ boolean valid = valid1 && valid2;
|
|
| 407 |
+ switch (adapter.convertRowIndexToModel(adapter.column)) {
|
|
| 408 |
+ case 0:
|
|
| 409 |
+ return !valid;
|
|
| 410 |
+ case 1:
|
|
| 411 |
+ return !valid1;
|
|
| 412 |
+ case 2:
|
|
| 413 |
+ return !valid2;
|
|
| 447 | 414 |
}
|
| 448 |
- };
|
|
| 449 |
- |
|
| 450 |
- cellRenderer.setLeafIcon(null);
|
|
| 451 |
- cellRenderer.setOpenIcon(null);
|
|
| 452 |
- cellRenderer.setClosedIcon(null);
|
|
| 453 |
- table.setTreeCellRenderer(cellRenderer);
|
|
| 454 |
- TableCellRenderer defaultRenderer = new MyRenderer(table.getDefaultRenderer(Boolean.class), table.getDefaultRenderer(String.class));
|
|
| 455 |
- table.setDefaultRenderer(Object.class, defaultRenderer);
|
|
| 456 |
- table.setDefaultEditor(Object.class, new MyTableCellEditor(table.getDefaultEditor(Boolean.class), table.getDefaultEditor(String.class)));
|
|
| 415 |
+ return true;
|
|
| 416 |
+ }, Color.RED, Color.WHITE));
|
|
| 457 | 417 |
}
|
| 458 | 418 |
|
| 459 | 419 |
private FloatingObjectService getFloatingObjectService() {
|
| ... | ... | @@ -486,117 +446,4 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 486 | 446 |
return (FloatingObjectUIModel) super.getModel();
|
| 487 | 447 |
}
|
| 488 | 448 |
|
| 489 |
- private static class MyRenderer implements TableCellRenderer {
|
|
| 490 |
- |
|
| 491 |
- private final TableCellRenderer editableRenderer;
|
|
| 492 |
- |
|
| 493 |
- private final TableCellRenderer notEditableRenderer;
|
|
| 494 |
- |
|
| 495 |
- private MyRenderer(TableCellRenderer editableRenderer, TableCellRenderer notEditableRenderer) {
|
|
| 496 |
- this.editableRenderer = editableRenderer;
|
|
| 497 |
- this.notEditableRenderer = notEditableRenderer;
|
|
| 498 |
- }
|
|
| 499 |
- |
|
| 500 |
- @Override
|
|
| 501 |
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
| 502 |
- FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) ((JXTreeTable) table).getPathForRow(row).getLastPathComponent();
|
|
| 503 |
- Objects.requireNonNull(node);
|
|
| 504 |
- TableCellRenderer renderer = notEditableRenderer;
|
|
| 505 |
- Object newValue = value;
|
|
| 506 |
- boolean enabled = true;
|
|
| 507 |
- if (node.getUserObject().getObjectMaterialType() != null && (!node.getUserObject().isEnabled() || table.isCellEditable(row, column))) {
|
|
| 508 |
- String objectMaterialType = node.getUserObject().getObjectMaterialType().getId();
|
|
| 509 |
- if ("fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#0".equals(objectMaterialType)) {
|
|
| 510 |
- newValue = value == null ? null : Boolean.valueOf(String.valueOf(value));
|
|
| 511 |
- renderer = editableRenderer;
|
|
| 512 |
- }
|
|
| 513 |
- enabled = node.getUserObject().isEnabled();
|
|
| 514 |
- } else {
|
|
| 515 |
- newValue = "";
|
|
| 516 |
- }
|
|
| 517 |
- |
|
| 518 |
- Component component = renderer.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column);
|
|
| 519 |
- component.setEnabled(enabled);
|
|
| 520 |
- return component;
|
|
| 521 |
- }
|
|
| 522 |
- }
|
|
| 523 |
- |
|
| 524 |
- private static class MyTableCellEditor implements TableCellEditor {
|
|
| 525 |
- |
|
| 526 |
- |
|
| 527 |
- private final TableCellEditor booleanEditor;
|
|
| 528 |
- private final TableCellEditor stringEditor;
|
|
| 529 |
- |
|
| 530 |
- TableCellEditor editor = null;
|
|
| 531 |
- |
|
| 532 |
- MyTableCellEditor(TableCellEditor booleanEditor, TableCellEditor StringEditor) {
|
|
| 533 |
- this.booleanEditor = booleanEditor;
|
|
| 534 |
- stringEditor = StringEditor;
|
|
| 535 |
- }
|
|
| 536 |
- |
|
| 537 |
- @Override
|
|
| 538 |
- public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
|
|
| 539 |
- FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) ((JXTreeTable) table).getPathForRow(row).getLastPathComponent();
|
|
| 540 |
- String objectMaterialType = node.getUserObject().getObjectMaterialType().getId();
|
|
| 541 |
- |
|
| 542 |
- switch (objectMaterialType) {
|
|
| 543 |
- case "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#0": //boolean
|
|
| 544 |
- editor = booleanEditor;
|
|
| 545 |
- break;
|
|
| 546 |
- case "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#1": // decimal one digit
|
|
| 547 |
- editor = stringEditor;
|
|
| 548 |
- break;
|
|
| 549 |
- case "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#2": // integer
|
|
| 550 |
- editor = stringEditor;
|
|
| 551 |
- break;
|
|
| 552 |
- case "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#3": // string
|
|
| 553 |
- editor = stringEditor;
|
|
| 554 |
- break;
|
|
| 555 |
- default:
|
|
| 556 |
- throw new IllegalStateException("Can't manage type: " + objectMaterialType);
|
|
| 557 |
- |
|
| 558 |
- }
|
|
| 559 |
- return editor.getTableCellEditorComponent(table, value, isSelected, row, column);
|
|
| 560 |
- }
|
|
| 561 |
- |
|
| 562 |
- @Override
|
|
| 563 |
- public Object getCellEditorValue() {
|
|
| 564 |
- Object o = editor == null ? null : editor.getCellEditorValue();
|
|
| 565 |
- return o == null ? null : String.valueOf(o);
|
|
| 566 |
- }
|
|
| 567 |
- |
|
| 568 |
- @Override
|
|
| 569 |
- public boolean isCellEditable(EventObject anEvent) {
|
|
| 570 |
- return stringEditor.isCellEditable(anEvent) || booleanEditor.isCellEditable(anEvent);
|
|
| 571 |
- }
|
|
| 572 |
- |
|
| 573 |
- @Override
|
|
| 574 |
- public boolean shouldSelectCell(EventObject anEvent) {
|
|
| 575 |
- return true;
|
|
| 576 |
- }
|
|
| 577 |
- |
|
| 578 |
- @Override
|
|
| 579 |
- public boolean stopCellEditing() {
|
|
| 580 |
- return editor != null && editor.stopCellEditing();
|
|
| 581 |
- }
|
|
| 582 |
- |
|
| 583 |
- @Override
|
|
| 584 |
- public void cancelCellEditing() {
|
|
| 585 |
- if (editor != null) {
|
|
| 586 |
- editor.cancelCellEditing();
|
|
| 587 |
- }
|
|
| 588 |
- }
|
|
| 589 |
- |
|
| 590 |
- @Override
|
|
| 591 |
- public void addCellEditorListener(CellEditorListener l) {
|
|
| 592 |
- stringEditor.addCellEditorListener(l);
|
|
| 593 |
- booleanEditor.addCellEditorListener(l);
|
|
| 594 |
- }
|
|
| 595 |
- |
|
| 596 |
- @Override
|
|
| 597 |
- public void removeCellEditorListener(CellEditorListener l) {
|
|
| 598 |
- stringEditor.removeCellEditorListener(l);
|
|
| 599 |
- booleanEditor.removeCellEditorListener(l);
|
|
| 600 |
- }
|
|
| 601 |
- }
|
|
| 602 | 449 |
}
|
| ... | ... | @@ -33,17 +33,14 @@ import fr.ird.observe.services.dto.constants.ReferentialLocale; |
| 33 | 33 |
import fr.ird.observe.services.dto.referential.seine.ObjectMaterialDto;
|
| 34 | 34 |
import fr.ird.observe.services.dto.seine.FloatingObjectDto;
|
| 35 | 35 |
import fr.ird.observe.services.dto.seine.FloatingObjectPartDto;
|
| 36 |
-import fr.ird.observe.services.dto.seine.ObjectMaterialHierarchyDto;
|
|
| 37 | 36 |
import java.util.LinkedHashMap;
|
| 38 | 37 |
import java.util.LinkedHashSet;
|
| 39 |
-import java.util.List;
|
|
| 40 | 38 |
import java.util.Map;
|
| 39 |
+import java.util.Objects;
|
|
| 41 | 40 |
import java.util.Optional;
|
| 42 | 41 |
import java.util.Set;
|
| 43 | 42 |
import org.apache.commons.logging.Log;
|
| 44 | 43 |
import org.apache.commons.logging.LogFactory;
|
| 45 |
-import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
|
|
| 46 |
-import org.nuiton.decorator.Decorator;
|
|
| 47 | 44 |
|
| 48 | 45 |
|
| 49 | 46 |
import static org.nuiton.i18n.I18n.t;
|
| ... | ... | @@ -52,12 +49,18 @@ import static org.nuiton.i18n.I18n.t; |
| 52 | 49 |
* Created on 9/28/14.
|
| 53 | 50 |
*
|
| 54 | 51 |
* @author Tony Chemit - dev@tchemit.fr
|
| 55 |
- * @since XXX
|
|
| 52 |
+ * @since 3.0
|
|
| 56 | 53 |
*/
|
| 57 | 54 |
public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> {
|
| 58 | 55 |
|
| 59 | 56 |
private static final long serialVersionUID = 1L;
|
| 57 |
+ |
|
| 60 | 58 |
static final String PROPERTY_PARTS_MODIFIED = "partsModified";
|
| 59 |
+ public static final String PROPERTY_GENERAL_TAB_VALID = "generalTabValid";
|
|
| 60 |
+ private static final String PROPERTY_MATERIALS_TAB_VALID = "materialsTabValid";
|
|
| 61 |
+ static final String PROPERTY_REFERENCE = "reference";
|
|
| 62 |
+ private static final String PROPERTY_ARRIVING = "arriving";
|
|
| 63 |
+ private static final String PROPERTY_LEAVING = "leaving";
|
|
| 61 | 64 |
|
| 62 | 65 |
private final ReferenceBinderEngine referenceBinderEngine;
|
| 63 | 66 |
private final ReferentialLocale referentialLocale;
|
| ... | ... | @@ -67,6 +70,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { |
| 67 | 70 |
private boolean arriving;
|
| 68 | 71 |
private boolean leaving;
|
| 69 | 72 |
|
| 73 |
+ |
|
| 70 | 74 |
public FloatingObjectUIModel() {
|
| 71 | 75 |
super(FloatingObjectDto.class);
|
| 72 | 76 |
|
| ... | ... | @@ -77,20 +81,13 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { |
| 77 | 81 |
this.whenLeaving = new LinkedHashMap<>();
|
| 78 | 82 |
}
|
| 79 | 83 |
|
| 80 |
- public static final String PROPERTY_GENERAL_TAB_VALID = "generalTabValid";
|
|
| 81 |
- |
|
| 82 |
- private static final String PROPERTY_MATERIALS_TAB_VALID = "materialsTabValid";
|
|
| 83 |
- static final String PROPERTY_REFERENCE = "reference";
|
|
| 84 |
- private static final String PROPERTY_ARRIVING = "arriving";
|
|
| 85 |
- private static final String PROPERTY_LEAVING = "leaving";
|
|
| 86 |
- |
|
| 87 | 84 |
public static final Set<String> GENERAL_TAB_PROPERTIES =
|
| 88 | 85 |
ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_OBJECT_OPERATION,
|
| 89 | 86 |
FloatingObjectDto.PROPERTY_SUPPORT_VESSEL_NAME,
|
| 90 | 87 |
FloatingObjectDto.PROPERTY_COMMENT).build();
|
| 91 | 88 |
|
| 92 | 89 |
static final Set<String> MATERIALS_TAB_PROPERTIES =
|
| 93 |
- ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_COMMENT).build();
|
|
| 90 |
+ ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_COMMENT, FloatingObjectDto.PROPERTY_MATERIALS_VALID).build();
|
|
| 94 | 91 |
|
| 95 | 92 |
protected boolean generalTabValid;
|
| 96 | 93 |
private boolean materialsTabValid;
|
| ... | ... | @@ -141,6 +138,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { |
| 141 | 138 |
public void reset() {
|
| 142 | 139 |
whenArriving.clear();
|
| 143 | 140 |
whenLeaving.clear();
|
| 141 |
+ getBean().setMaterialsValid(true);
|
|
| 144 | 142 |
fireComputedValuesChanged();
|
| 145 | 143 |
}
|
| 146 | 144 |
|
| ... | ... | @@ -162,39 +160,27 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { |
| 162 | 160 |
}
|
| 163 | 161 |
|
| 164 | 162 |
public Set<ObjectMaterialDto> getAll() {
|
| 165 |
- Set<ObjectMaterialDto> alls = new LinkedHashSet<>(whenArriving.keySet());
|
|
| 166 |
- alls.addAll(whenLeaving.keySet());
|
|
| 167 |
- return alls;
|
|
| 163 |
+ Set<ObjectMaterialDto> all = new LinkedHashSet<>(whenArriving.keySet());
|
|
| 164 |
+ all.addAll(whenLeaving.keySet());
|
|
| 165 |
+ return all;
|
|
| 168 | 166 |
}
|
| 169 | 167 |
|
| 170 | 168 |
void setReferentialMap(Map<String, ObjectMaterialDto> referentialMap) {
|
| 171 | 169 |
this.referentialMap = referentialMap;
|
| 172 | 170 |
}
|
| 173 | 171 |
|
| 174 |
- void setWhenArriving(String id, String value) {
|
|
| 172 |
+ public void setWhenArriving(String id, String value) {
|
|
| 175 | 173 |
ObjectMaterialDto dto = referentialMap.get(id);
|
| 176 |
- if (dto == null) {
|
|
| 177 |
- return;
|
|
| 178 |
- }
|
|
| 174 |
+ Objects.requireNonNull(dto);
|
|
| 179 | 175 |
whenArriving.put(dto, value);
|
| 180 | 176 |
}
|
| 181 | 177 |
|
| 182 |
- void setWhenLeaving(String id, String value) {
|
|
| 178 |
+ public void setWhenLeaving(String id, String value) {
|
|
| 183 | 179 |
ObjectMaterialDto dto = referentialMap.get(id);
|
| 184 |
- if (dto == null) {
|
|
| 185 |
- return;
|
|
| 186 |
- }
|
|
| 180 |
+ Objects.requireNonNull(dto);
|
|
| 187 | 181 |
whenLeaving.put(dto, value);
|
| 188 | 182 |
}
|
| 189 | 183 |
|
| 190 |
- DefaultMutableTreeTableNode createRoot(Decorator<ObjectMaterialDto> decoratorByType, List<ObjectMaterialHierarchyDto> referential) {
|
|
| 191 |
- DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode();
|
|
| 192 |
- for (ObjectMaterialHierarchyDto dto : referential) {
|
|
| 193 |
- root.add(new FloatingObjectPartsTreeNode(decoratorByType, this, dto));
|
|
| 194 |
- }
|
|
| 195 |
- return root;
|
|
| 196 |
- }
|
|
| 197 |
- |
|
| 198 | 184 |
public Optional<FloatingObjectReference> getReference() {
|
| 199 | 185 |
return Optional.ofNullable(reference);
|
| 200 | 186 |
}
|
| ... | ... | @@ -273,4 +259,5 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { |
| 273 | 259 |
bean.setComputedWhenLeavingSimplifiedObjectType(null);
|
| 274 | 260 |
fireComputedValuesChanged();
|
| 275 | 261 |
}
|
| 262 |
+ |
|
| 276 | 263 |
}
|
| 1 |
+package fr.ird.observe.client.ui.content.impl.seine.dcp;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import fr.ird.observe.client.ObserveSwingApplicationContext;
|
|
| 26 |
+import fr.ird.observe.services.dto.referential.seine.ObjectMaterialDto;
|
|
| 27 |
+import java.awt.Component;
|
|
| 28 |
+import javax.swing.JTree;
|
|
| 29 |
+import org.jdesktop.swingx.tree.DefaultXTreeCellRenderer;
|
|
| 30 |
+import org.nuiton.decorator.Decorator;
|
|
| 31 |
+ |
|
| 32 |
+/**
|
|
| 33 |
+ * Created by tchemit on 05/08/17.
|
|
| 34 |
+ *
|
|
| 35 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 36 |
+ * @since 7.0
|
|
| 37 |
+ */
|
|
| 38 |
+public class FloatingObjectPartLegendTreeCellRenderer extends DefaultXTreeCellRenderer {
|
|
| 39 |
+ |
|
| 40 |
+ private Decorator<ObjectMaterialDto> decorator;
|
|
| 41 |
+ |
|
| 42 |
+ public FloatingObjectPartLegendTreeCellRenderer() {
|
|
| 43 |
+ super();
|
|
| 44 |
+ setLeafIcon(null);
|
|
| 45 |
+ setOpenIcon(null);
|
|
| 46 |
+ setClosedIcon(null);
|
|
| 47 |
+ }
|
|
| 48 |
+ |
|
| 49 |
+ @Override
|
|
| 50 |
+ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
|
| 51 |
+ FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) value;
|
|
| 52 |
+ Component result = super.getTreeCellRendererComponent(tree, getDecorator().toString(node.getValueAt(0)), sel, expanded, leaf, row, hasFocus);
|
|
| 53 |
+ result.setEnabled(node.isEnabled());
|
|
| 54 |
+ return result;
|
|
| 55 |
+ }
|
|
| 56 |
+ |
|
| 57 |
+ private Decorator<ObjectMaterialDto> getDecorator() {
|
|
| 58 |
+ if (decorator == null) {
|
|
| 59 |
+ decorator = ObserveSwingApplicationContext.get().getDecoratorService().getDecoratorByType(ObjectMaterialDto.class);
|
|
| 60 |
+ }
|
|
| 61 |
+ return decorator;
|
|
| 62 |
+ }
|
|
| 63 |
+ |
|
| 64 |
+}
|
| 1 |
+package fr.ird.observe.client.ui.content.impl.seine.dcp;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import com.google.common.collect.ImmutableSet;
|
|
| 26 |
+import fr.ird.observe.client.ui.UIHelper;
|
|
| 27 |
+import fr.ird.observe.client.ui.util.treetable.JRadioButtonCellEditor;
|
|
| 28 |
+import java.awt.Component;
|
|
| 29 |
+import java.util.EventObject;
|
|
| 30 |
+import java.util.Objects;
|
|
| 31 |
+import javax.swing.JTable;
|
|
| 32 |
+import javax.swing.event.CellEditorListener;
|
|
| 33 |
+import javax.swing.table.TableCellEditor;
|
|
| 34 |
+import org.jdesktop.swingx.JXTreeTable;
|
|
| 35 |
+import org.nuiton.jaxx.widgets.number.NumberCellEditor;
|
|
| 36 |
+ |
|
| 37 |
+/**
|
|
| 38 |
+ * Created by tchemit on 05/08/17.
|
|
| 39 |
+ *
|
|
| 40 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 41 |
+ * @since 7.0
|
|
| 42 |
+ */
|
|
| 43 |
+public class FloatingObjectPartsTableCellEditor implements TableCellEditor {
|
|
| 44 |
+ |
|
| 45 |
+ private final TableCellEditor booleanEditor;
|
|
| 46 |
+ private final TableCellEditor stringEditor;
|
|
| 47 |
+ private final TableCellEditor radioEditor;
|
|
| 48 |
+ private final TableCellEditor intEditor;
|
|
| 49 |
+ private final TableCellEditor floatEditor;
|
|
| 50 |
+ private TableCellEditor editor;
|
|
| 51 |
+ |
|
| 52 |
+ private final ImmutableSet<TableCellEditor> editors;
|
|
| 53 |
+ |
|
| 54 |
+ public FloatingObjectPartsTableCellEditor(JXTreeTable table) {
|
|
| 55 |
+ // register as a default editors to get correct integration with ui
|
|
| 56 |
+ table.setDefaultEditor(boolean.class, new JRadioButtonCellEditor());
|
|
| 57 |
+ table.setDefaultEditor(int.class, new IntegerCellEditor());
|
|
| 58 |
+ table.setDefaultEditor(float.class, new FloatCellEditor());
|
|
| 59 |
+ |
|
| 60 |
+ ImmutableSet.Builder<TableCellEditor> editorBuilder = ImmutableSet.builder();
|
|
| 61 |
+ |
|
| 62 |
+ editorBuilder.add(this.booleanEditor = table.getDefaultEditor(Boolean.class));
|
|
| 63 |
+ editorBuilder.add(this.stringEditor = table.getDefaultEditor(Object.class));
|
|
| 64 |
+ editorBuilder.add(this.radioEditor = table.getDefaultEditor(boolean.class));
|
|
| 65 |
+ editorBuilder.add(this.intEditor = table.getDefaultEditor(int.class));
|
|
| 66 |
+ editorBuilder.add(this.floatEditor = table.getDefaultEditor(float.class));
|
|
| 67 |
+ this.editors = editorBuilder.build();
|
|
| 68 |
+ }
|
|
| 69 |
+ |
|
| 70 |
+ @Override
|
|
| 71 |
+ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
|
|
| 72 |
+ FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) ((JXTreeTable) table).getPathForRow(row).getLastPathComponent();
|
|
| 73 |
+ |
|
| 74 |
+ if (node.isBoolean()) {
|
|
| 75 |
+ editor = node.isExclusive() ? radioEditor : booleanEditor;
|
|
| 76 |
+ } else if (node.isText()) {
|
|
| 77 |
+ editor = stringEditor;
|
|
| 78 |
+ } else if (node.isFloat()) {
|
|
| 79 |
+ editor = floatEditor;
|
|
| 80 |
+ } else if (node.isInteger()) {
|
|
| 81 |
+ editor = intEditor;
|
|
| 82 |
+ } else {
|
|
| 83 |
+ throw new IllegalStateException("Can't manage type: " + node.getObjectMaterialType());
|
|
| 84 |
+ }
|
|
| 85 |
+ return editor.getTableCellEditorComponent(table, value, isSelected, row, column);
|
|
| 86 |
+ }
|
|
| 87 |
+ |
|
| 88 |
+ @Override
|
|
| 89 |
+ public Object getCellEditorValue() {
|
|
| 90 |
+ Object o = editor == null ? null : editor.getCellEditorValue();
|
|
| 91 |
+ return o == null ? null : Objects.equals(false, o) ? null : String.valueOf(o);
|
|
| 92 |
+ }
|
|
| 93 |
+ |
|
| 94 |
+ @Override
|
|
| 95 |
+ public boolean isCellEditable(EventObject anEvent) {
|
|
| 96 |
+ return editors.stream().anyMatch(e -> e.isCellEditable(anEvent));
|
|
| 97 |
+ }
|
|
| 98 |
+ |
|
| 99 |
+ @Override
|
|
| 100 |
+ public boolean shouldSelectCell(EventObject anEvent) {
|
|
| 101 |
+ return true;
|
|
| 102 |
+ }
|
|
| 103 |
+ |
|
| 104 |
+ @Override
|
|
| 105 |
+ public boolean stopCellEditing() {
|
|
| 106 |
+ return editor != null && editor.stopCellEditing();
|
|
| 107 |
+ }
|
|
| 108 |
+ |
|
| 109 |
+ @Override
|
|
| 110 |
+ public void cancelCellEditing() {
|
|
| 111 |
+ if (editor != null) {
|
|
| 112 |
+ editor.cancelCellEditing();
|
|
| 113 |
+ }
|
|
| 114 |
+ }
|
|
| 115 |
+ |
|
| 116 |
+ @Override
|
|
| 117 |
+ public void addCellEditorListener(CellEditorListener l) {
|
|
| 118 |
+ editors.forEach(e -> e.addCellEditorListener(l));
|
|
| 119 |
+ }
|
|
| 120 |
+ |
|
| 121 |
+ @Override
|
|
| 122 |
+ public void removeCellEditorListener(CellEditorListener l) {
|
|
| 123 |
+ editors.forEach(e -> e.removeCellEditorListener(l));
|
|
| 124 |
+ }
|
|
| 125 |
+ |
|
| 126 |
+ private static class IntegerCellEditor extends NumberCellEditor<Integer> {
|
|
| 127 |
+ IntegerCellEditor() {
|
|
| 128 |
+ super(Integer.class, false);
|
|
| 129 |
+ numberEditor.setNumberPattern(UIHelper.INT_6_DIGITS_PATTERN);
|
|
| 130 |
+ }
|
|
| 131 |
+ }
|
|
| 132 |
+ |
|
| 133 |
+ private static class FloatCellEditor extends NumberCellEditor<Float> {
|
|
| 134 |
+ FloatCellEditor() {
|
|
| 135 |
+ super(Float.class, false);
|
|
| 136 |
+ numberEditor.setNumberPattern(UIHelper.DECIMAL1_PATTERN);
|
|
| 137 |
+ }
|
|
| 138 |
+ }
|
|
| 139 |
+ |
|
| 140 |
+}
|
| 1 |
+package fr.ird.observe.client.ui.content.impl.seine.dcp;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import fr.ird.observe.client.ui.util.treetable.JRadioButtonProvider;
|
|
| 26 |
+import fr.ird.observe.services.dto.seine.ObjectMaterialHierarchyDto;
|
|
| 27 |
+import java.awt.Component;
|
|
| 28 |
+import java.util.Objects;
|
|
| 29 |
+import javax.swing.JTable;
|
|
| 30 |
+import javax.swing.table.TableCellRenderer;
|
|
| 31 |
+import org.jdesktop.swingx.JXTreeTable;
|
|
| 32 |
+import org.jdesktop.swingx.renderer.DefaultTableRenderer;
|
|
| 33 |
+ |
|
| 34 |
+/**
|
|
| 35 |
+ * Created by tchemit on 05/08/17.
|
|
| 36 |
+ *
|
|
| 37 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 38 |
+ * @since 7.0
|
|
| 39 |
+ */
|
|
| 40 |
+public class FloatingObjectPartsTableCellRenderer implements TableCellRenderer {
|
|
| 41 |
+ |
|
| 42 |
+ // Render booleans (inclusive)
|
|
| 43 |
+ private final TableCellRenderer booleanInclusiveRenderer;
|
|
| 44 |
+ // Render booleans (exclusive)
|
|
| 45 |
+ private final TableCellRenderer booleanExclusiveRenderer;
|
|
| 46 |
+ // Render anything else
|
|
| 47 |
+ private final TableCellRenderer objectRenderer;
|
|
| 48 |
+ |
|
| 49 |
+ public FloatingObjectPartsTableCellRenderer(JXTreeTable table) {
|
|
| 50 |
+ // register as a default renderer to get correct integration with ui
|
|
| 51 |
+ table.setDefaultRenderer(boolean.class, new DefaultTableRenderer(new JRadioButtonProvider()));
|
|
| 52 |
+ this.booleanInclusiveRenderer = table.getDefaultRenderer(Boolean.class);
|
|
| 53 |
+ this.objectRenderer = table.getDefaultRenderer(Object.class);
|
|
| 54 |
+ this.booleanExclusiveRenderer = table.getDefaultRenderer(boolean.class);
|
|
| 55 |
+ }
|
|
| 56 |
+ |
|
| 57 |
+ @Override
|
|
| 58 |
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
| 59 |
+ FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) ((JXTreeTable) table).getPathForRow(row).getLastPathComponent();
|
|
| 60 |
+ Objects.requireNonNull(node);
|
|
| 61 |
+ TableCellRenderer renderer = objectRenderer;
|
|
| 62 |
+ Object newValue = value;
|
|
| 63 |
+ boolean enabled = true;
|
|
| 64 |
+ if (node.isEditable() && table.isCellEditable(row, column)) {
|
|
| 65 |
+ if (node.isBoolean()) {
|
|
| 66 |
+ newValue = value == null ? null : Boolean.valueOf(String.valueOf(value));
|
|
| 67 |
+ renderer = node.isExclusive() ? booleanExclusiveRenderer : booleanInclusiveRenderer;
|
|
| 68 |
+ }
|
|
| 69 |
+ enabled = node.isEnabled();
|
|
| 70 |
+ } else {
|
|
| 71 |
+ newValue = "";
|
|
| 72 |
+ }
|
|
| 73 |
+ |
|
| 74 |
+ Component component = renderer.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column);
|
|
| 75 |
+ component.setEnabled(enabled);
|
|
| 76 |
+ return component;
|
|
| 77 |
+ }
|
|
| 78 |
+}
|
| 1 |
+package fr.ird.observe.client.ui.content.impl.seine.dcp;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import com.google.common.collect.ImmutableSet;
|
|
| 26 |
+import fr.ird.observe.client.ui.content.impl.seine.FloatingObjectUIModel;
|
|
| 27 |
+import fr.ird.observe.services.dto.reference.ReferentialReference;
|
|
| 28 |
+import fr.ird.observe.services.dto.referential.seine.ObjectMaterialTypeDto;
|
|
| 29 |
+import fr.ird.observe.services.dto.seine.ObjectMaterialHierarchyDto;
|
|
| 30 |
+import java.util.Collections;
|
|
| 31 |
+import java.util.Iterator;
|
|
| 32 |
+import java.util.List;
|
|
| 33 |
+import java.util.Objects;
|
|
| 34 |
+import java.util.Optional;
|
|
| 35 |
+import org.apache.commons.logging.Log;
|
|
| 36 |
+import org.apache.commons.logging.LogFactory;
|
|
| 37 |
+import org.jdesktop.swingx.treetable.AbstractMutableTreeTableNode;
|
|
| 38 |
+import org.jetbrains.annotations.NotNull;
|
|
| 39 |
+ |
|
| 40 |
+/**
|
|
| 41 |
+ * Created by tchemit on 30/05/17.
|
|
| 42 |
+ *
|
|
| 43 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 44 |
+ */
|
|
| 45 |
+public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode implements Iterable<FloatingObjectPartsTreeNode> {
|
|
| 46 |
+ |
|
| 47 |
+ /** Logger. */
|
|
| 48 |
+ private static final Log log = LogFactory.getLog(FloatingObjectPartsTreeNode.class);
|
|
| 49 |
+ |
|
| 50 |
+ static FloatingObjectPartsTreeNode createRoot(FloatingObjectUIModel model, List<ObjectMaterialHierarchyDto> referential) {
|
|
| 51 |
+ FloatingObjectPartsTreeNodeContext rootModel = new FloatingObjectPartsTreeNodeContext(model);
|
|
| 52 |
+ FloatingObjectPartsTreeNode root = new FloatingObjectPartsTreeNode(rootModel);
|
|
| 53 |
+ if (referential != null) {
|
|
| 54 |
+ for (ObjectMaterialHierarchyDto dto : referential) {
|
|
| 55 |
+ FloatingObjectPartsTreeNodeContext childModel = new FloatingObjectPartsTreeNodeContext(dto, rootModel);
|
|
| 56 |
+ FloatingObjectPartsTreeNode node = new FloatingObjectPartsTreeNode(childModel);
|
|
| 57 |
+ root.add(node);
|
|
| 58 |
+ ImmutableSet.Builder<FloatingObjectPartsTreeNode> companionsBuilder = dto.isChildrenMultiSelectable() ? ImmutableSet.builder() : null;
|
|
| 59 |
+ node.computeCompanions(companionsBuilder);
|
|
| 60 |
+ node.setCompanions(companionsBuilder);
|
|
| 61 |
+ }
|
|
| 62 |
+ }
|
|
| 63 |
+ return root;
|
|
| 64 |
+ }
|
|
| 65 |
+ |
|
| 66 |
+ boolean isNotValid() {
|
|
| 67 |
+ return !(getUserObject().validWhenArriving && getUserObject().validWhenLeaving);
|
|
| 68 |
+ }
|
|
| 69 |
+ |
|
| 70 |
+ private static class FloatingObjectPartsTreeNodeContext {
|
|
| 71 |
+ |
|
| 72 |
+ // main model to get and store values
|
|
| 73 |
+ private final FloatingObjectUIModel uiModel;
|
|
| 74 |
+ // dto (null for root)
|
|
| 75 |
+ private final ObjectMaterialHierarchyDto dto;
|
|
| 76 |
+ // Is the node is enabled (hierarchic value) ?
|
|
| 77 |
+ private final boolean enabled;
|
|
| 78 |
+ // Is this node editable ?
|
|
| 79 |
+ private final boolean editable;
|
|
| 80 |
+ // Is this node need at least one child selected ?
|
|
| 81 |
+ private final boolean needOneSelection;
|
|
| 82 |
+ // Is this node in the path of at least one mandatory child ancestor ?
|
|
| 83 |
+ private final boolean mandatory;
|
|
| 84 |
+ // Is the node is exclusive (means only one value possible for him and his brothers) ?
|
|
| 85 |
+ private final boolean exclusive;
|
|
| 86 |
+ // Is the node valid for whenArriving column ?
|
|
| 87 |
+ private boolean validWhenArriving = true;
|
|
| 88 |
+ // Is the node valid for whenLeaving column ?
|
|
| 89 |
+ private boolean validWhenLeaving = true;
|
|
| 90 |
+ // Set of brothers of this node that is in a exclusive group of node (only one value among all of them)
|
|
| 91 |
+ private ImmutableSet<FloatingObjectPartsTreeNode> companions;
|
|
| 92 |
+ // Internal to store debug node text
|
|
| 93 |
+ private String text;
|
|
| 94 |
+ |
|
| 95 |
+ FloatingObjectPartsTreeNodeContext(FloatingObjectUIModel uiModel) {
|
|
| 96 |
+ Objects.requireNonNull(uiModel);
|
|
| 97 |
+ this.uiModel = uiModel;
|
|
| 98 |
+ this.dto = null;
|
|
| 99 |
+ this.enabled = true;
|
|
| 100 |
+ this.editable = false;
|
|
| 101 |
+ this.mandatory = false;
|
|
| 102 |
+ this.exclusive = false;
|
|
| 103 |
+ this.needOneSelection = false;
|
|
| 104 |
+ }
|
|
| 105 |
+ |
|
| 106 |
+ FloatingObjectPartsTreeNodeContext(ObjectMaterialHierarchyDto dto, FloatingObjectPartsTreeNodeContext parent) {
|
|
| 107 |
+ Objects.requireNonNull(dto);
|
|
| 108 |
+ Objects.requireNonNull(parent);
|
|
| 109 |
+ this.uiModel = parent.uiModel;
|
|
| 110 |
+ this.dto = dto;
|
|
| 111 |
+ // enabled if parent is enabled and dto is enabled
|
|
| 112 |
+ this.enabled = parent.enabled && dto.isEnabled();
|
|
| 113 |
+ // need one selection if is enabled and dto requires it
|
|
| 114 |
+ this.needOneSelection = enabled && dto.isChildSelectionMandatory();
|
|
| 115 |
+ // editable if dto is selectable (we also make sure that the object material type is here too)
|
|
| 116 |
+ this.editable = dto.isSelectable() && dto.getObjectMaterialType() != null;
|
|
| 117 |
+ // mandatory if enabled parent is so or parent makes this child to be
|
|
| 118 |
+ this.mandatory = parent.mandatory || parent.needOneSelection;
|
|
| 119 |
+ // exclusive if his parent requires it
|
|
| 120 |
+ this.exclusive = parent.dto != null && parent.dto.isChildrenMultiSelectable();
|
|
| 121 |
+ log.info(String.format("New node: %s - mandatory %s - needOneSelection %s - exclusive %s", dto.getLabel2(), mandatory, needOneSelection, exclusive));
|
|
| 122 |
+ }
|
|
| 123 |
+ |
|
| 124 |
+ Object getValueAt(int column) {
|
|
| 125 |
+ switch (column) {
|
|
| 126 |
+ case 0: // dto
|
|
| 127 |
+ return dto;
|
|
| 128 |
+ case 1: // when arriving
|
|
| 129 |
+ return uiModel.getWhenArriving().get(dto);
|
|
| 130 |
+ case 2: // when leaving
|
|
| 131 |
+ return uiModel.getWhenLeaving().get(dto);
|
|
| 132 |
+ }
|
|
| 133 |
+ throw new IllegalStateException();
|
|
| 134 |
+ }
|
|
| 135 |
+ |
|
| 136 |
+ void setValueAt(Object aValue, int column) {
|
|
| 137 |
+ switch (column) {
|
|
| 138 |
+ case 1: // when arriving
|
|
| 139 |
+ uiModel.setWhenArriving(dto.getId(), aValue == null ? null : String.valueOf(aValue));
|
|
| 140 |
+ return;
|
|
| 141 |
+ case 2: // when leaving
|
|
| 142 |
+ uiModel.setWhenLeaving(dto.getId(), aValue == null ? null : String.valueOf(aValue));
|
|
| 143 |
+ return;
|
|
| 144 |
+ }
|
|
| 145 |
+ throw new IllegalStateException();
|
|
| 146 |
+ }
|
|
| 147 |
+ |
|
| 148 |
+ boolean isColumnEditable(int column) {
|
|
| 149 |
+ switch (column) {
|
|
| 150 |
+ case 1: // when arriving
|
|
| 151 |
+ return uiModel.isArriving();
|
|
| 152 |
+ case 2: // when leaving
|
|
| 153 |
+ return uiModel.isLeaving();
|
|
| 154 |
+ }
|
|
| 155 |
+ throw new IllegalStateException();
|
|
| 156 |
+ }
|
|
| 157 |
+ |
|
| 158 |
+ boolean isValid(int column) {
|
|
| 159 |
+ switch (column) {
|
|
| 160 |
+ case 1: // when arriving
|
|
| 161 |
+ return validWhenArriving;
|
|
| 162 |
+ case 2: // when leaving
|
|
| 163 |
+ return validWhenLeaving;
|
|
| 164 |
+ }
|
|
| 165 |
+ throw new IllegalStateException();
|
|
| 166 |
+ }
|
|
| 167 |
+ |
|
| 168 |
+ Optional<FloatingObjectPartsTreeNode> getSelectedCompanion(int column) {
|
|
| 169 |
+ return companions.stream().filter(n -> n.getValueAt(column) != null).findFirst();
|
|
| 170 |
+ }
|
|
| 171 |
+ |
|
| 172 |
+ public String getText() {
|
|
| 173 |
+ if (text == null && dto != null) {
|
|
| 174 |
+ text = String.format("%s [value: %s-%s] [valid: %s-%s]", dto.getLabel2(), getValueAt(1), getValueAt(2), isValid(1), isValid(2));
|
|
| 175 |
+ }
|
|
| 176 |
+ return text;
|
|
| 177 |
+ }
|
|
| 178 |
+ |
|
| 179 |
+ }
|
|
| 180 |
+ |
|
| 181 |
+ private FloatingObjectPartsTreeNode(FloatingObjectPartsTreeNodeContext context) {
|
|
| 182 |
+ super(context);
|
|
| 183 |
+ if (context.dto != null) {
|
|
| 184 |
+ for (ObjectMaterialHierarchyDto dto : context.dto.getChildren()) {
|
|
| 185 |
+ FloatingObjectPartsTreeNodeContext childContext = new FloatingObjectPartsTreeNodeContext(dto, context);
|
|
| 186 |
+ add(new FloatingObjectPartsTreeNode(childContext));
|
|
| 187 |
+ }
|
|
| 188 |
+ }
|
|
| 189 |
+ }
|
|
| 190 |
+ |
|
| 191 |
+ @Override
|
|
| 192 |
+ public String toString() {
|
|
| 193 |
+ return getUserObject().getText();
|
|
| 194 |
+ }
|
|
| 195 |
+ |
|
| 196 |
+ @Override
|
|
| 197 |
+ public FloatingObjectPartsTreeNodeContext getUserObject() {
|
|
| 198 |
+ return (FloatingObjectPartsTreeNodeContext) super.getUserObject();
|
|
| 199 |
+ }
|
|
| 200 |
+ |
|
| 201 |
+ @Override
|
|
| 202 |
+ public Object getValueAt(int column) {
|
|
| 203 |
+ return getUserObject().getValueAt(column);
|
|
| 204 |
+ }
|
|
| 205 |
+ |
|
| 206 |
+ @Override
|
|
| 207 |
+ public void setValueAt(Object aValue, int column) {
|
|
| 208 |
+ getUserObject().setValueAt(aValue, column);
|
|
| 209 |
+ }
|
|
| 210 |
+ |
|
| 211 |
+ @Override
|
|
| 212 |
+ public boolean isEditable(int column) {
|
|
| 213 |
+ return column > 0 && getUserObject().enabled && getUserObject().editable && isColumnEditable(column);
|
|
| 214 |
+ }
|
|
| 215 |
+ |
|
| 216 |
+ private boolean isColumnEditable(int column) {
|
|
| 217 |
+ return getUserObject().isColumnEditable(column);
|
|
| 218 |
+ }
|
|
| 219 |
+ |
|
| 220 |
+ @Override
|
|
| 221 |
+ public int getColumnCount() {
|
|
| 222 |
+ return 3;
|
|
| 223 |
+ }
|
|
| 224 |
+ |
|
| 225 |
+ @SuppressWarnings({"unchecked"})
|
|
| 226 |
+ @Override
|
|
| 227 |
+ @NotNull
|
|
| 228 |
+ public Iterator<FloatingObjectPartsTreeNode> iterator() {
|
|
| 229 |
+ return (Iterator) (children == null ? Collections.emptyIterator() : children.iterator());
|
|
| 230 |
+ }
|
|
| 231 |
+ |
|
| 232 |
+ public boolean isValid(int column) {
|
|
| 233 |
+ return getUserObject().isValid(column);
|
|
| 234 |
+ }
|
|
| 235 |
+ |
|
| 236 |
+ boolean isExclusive() {
|
|
| 237 |
+ return getUserObject().exclusive;
|
|
| 238 |
+ }
|
|
| 239 |
+ |
|
| 240 |
+ public boolean isEditable() {
|
|
| 241 |
+ return getUserObject().editable;
|
|
| 242 |
+ }
|
|
| 243 |
+ |
|
| 244 |
+ public boolean isEnabled() {
|
|
| 245 |
+ return getUserObject().enabled;
|
|
| 246 |
+ }
|
|
| 247 |
+ |
|
| 248 |
+ public String getId() {
|
|
| 249 |
+ return getUserObject().dto.getId();
|
|
| 250 |
+ }
|
|
| 251 |
+ |
|
| 252 |
+ public boolean isBoolean() {
|
|
| 253 |
+ return getUserObject().dto.isBoolean();
|
|
| 254 |
+ }
|
|
| 255 |
+ |
|
| 256 |
+ public boolean isText() {
|
|
| 257 |
+ return getUserObject().dto.isText();
|
|
| 258 |
+ }
|
|
| 259 |
+ |
|
| 260 |
+ public boolean isInteger() {
|
|
| 261 |
+ return getUserObject().dto.isInteger();
|
|
| 262 |
+ }
|
|
| 263 |
+ |
|
| 264 |
+ public boolean isFloat() {
|
|
| 265 |
+ return getUserObject().dto.isFloat();
|
|
| 266 |
+ }
|
|
| 267 |
+ |
|
| 268 |
+ ReferentialReference<ObjectMaterialTypeDto> getObjectMaterialType() {
|
|
| 269 |
+ return getUserObject().dto.getObjectMaterialType();
|
|
| 270 |
+ }
|
|
| 271 |
+ |
|
| 272 |
+ Optional<FloatingObjectPartsTreeNode> getSelectedCompanion(int column) {
|
|
| 273 |
+ return getUserObject().getSelectedCompanion(column);
|
|
| 274 |
+ }
|
|
| 275 |
+ |
|
| 276 |
+ void resetStates() {
|
|
| 277 |
+ getUserObject().text = null;
|
|
| 278 |
+ getUserObject().validWhenArriving = true;
|
|
| 279 |
+ getUserObject().validWhenLeaving = true;
|
|
| 280 |
+ }
|
|
| 281 |
+ |
|
| 282 |
+ @Override
|
|
| 283 |
+ public FloatingObjectPartsTreeNode getParent() {
|
|
| 284 |
+ return (FloatingObjectPartsTreeNode) super.getParent();
|
|
| 285 |
+ }
|
|
| 286 |
+ |
|
| 287 |
+ void fillNodeSets(ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder,
|
|
| 288 |
+ ImmutableSet.Builder<FloatingObjectPartsTreeNode> needOneSelectionNodesBuilder,
|
|
| 289 |
+ ImmutableSet.Builder<FloatingObjectPartsTreeNode> mandatoryNodesBuilder) {
|
|
| 290 |
+ |
|
| 291 |
+ allNodesBuilder.add(this);
|
|
| 292 |
+ if (getUserObject().needOneSelection) {
|
|
| 293 |
+ needOneSelectionNodesBuilder.add(this);
|
|
| 294 |
+ }
|
|
| 295 |
+ if (getUserObject().mandatory) {
|
|
| 296 |
+ mandatoryNodesBuilder.add(this);
|
|
| 297 |
+ }
|
|
| 298 |
+ |
|
| 299 |
+ for (FloatingObjectPartsTreeNode child : this) {
|
|
| 300 |
+ child.fillNodeSets(allNodesBuilder, needOneSelectionNodesBuilder, mandatoryNodesBuilder);
|
|
| 301 |
+ }
|
|
| 302 |
+ |
|
| 303 |
+ }
|
|
| 304 |
+ |
|
| 305 |
+ void computeNeedAtLeastOnSelectValidState(boolean whenArriving, boolean whenLeaving) {
|
|
| 306 |
+ |
|
| 307 |
+ if (whenArriving) {
|
|
| 308 |
+ getUserObject().validWhenArriving = isAtLeastOneSelected(1);
|
|
| 309 |
+ }
|
|
| 310 |
+ if (whenLeaving) {
|
|
| 311 |
+ getUserObject().validWhenLeaving = isAtLeastOneSelected(2);
|
|
| 312 |
+ }
|
|
| 313 |
+ |
|
| 314 |
+ log.info("Validate node " + this);
|
|
| 315 |
+ |
|
| 316 |
+ }
|
|
| 317 |
+ |
|
| 318 |
+ void computeMandatoryValidState(boolean whenArriving, boolean whenLeaving) {
|
|
| 319 |
+ if (whenArriving) {
|
|
| 320 |
+ getUserObject().validWhenArriving = getParent().getUserObject().validWhenArriving;
|
|
| 321 |
+ }
|
|
| 322 |
+ if (whenLeaving) {
|
|
| 323 |
+ getUserObject().validWhenLeaving = getParent().getUserObject().validWhenLeaving;
|
|
| 324 |
+ }
|
|
| 325 |
+ |
|
| 326 |
+ log.info("Validate node " + this);
|
|
| 327 |
+ }
|
|
| 328 |
+ |
|
| 329 |
+ private void setCompanions(ImmutableSet.Builder<FloatingObjectPartsTreeNode> companionsBuilder) {
|
|
| 330 |
+ if (companionsBuilder != null) {
|
|
| 331 |
+ ImmutableSet<FloatingObjectPartsTreeNode> companions = companionsBuilder.build();
|
|
| 332 |
+ for (FloatingObjectPartsTreeNode child : this) {
|
|
| 333 |
+ child.getUserObject().companions = companions;
|
|
| 334 |
+ }
|
|
| 335 |
+ }
|
|
| 336 |
+ }
|
|
| 337 |
+ |
|
| 338 |
+ private boolean isAtLeastOneSelected(int column) {
|
|
| 339 |
+ if (getValueAt(column) != null) {
|
|
| 340 |
+ return true;
|
|
| 341 |
+ }
|
|
| 342 |
+ for (FloatingObjectPartsTreeNode child : this) {
|
|
| 343 |
+ if (child.isAtLeastOneSelected(column)) {
|
|
| 344 |
+ return true;
|
|
| 345 |
+ }
|
|
| 346 |
+ }
|
|
| 347 |
+ return false;
|
|
| 348 |
+ }
|
|
| 349 |
+ |
|
| 350 |
+ private void computeCompanions(ImmutableSet.Builder<FloatingObjectPartsTreeNode> companionsBuilder) {
|
|
| 351 |
+ if (companionsBuilder != null) {
|
|
| 352 |
+ companionsBuilder.add(this);
|
|
| 353 |
+ }
|
|
| 354 |
+ |
|
| 355 |
+ ImmutableSet.Builder<FloatingObjectPartsTreeNode> childCompanionsBuilder = getUserObject().dto.isChildrenMultiSelectable() ? ImmutableSet.builder() : null;
|
|
| 356 |
+ for (FloatingObjectPartsTreeNode child : this) {
|
|
| 357 |
+ child.computeCompanions(childCompanionsBuilder);
|
|
| 358 |
+ }
|
|
| 359 |
+ setCompanions(childCompanionsBuilder);
|
|
| 360 |
+ }
|
|
| 361 |
+}
|
| 1 |
+package fr.ird.observe.client.ui.content.impl.seine.dcp;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import com.google.common.collect.ImmutableSet;
|
|
| 26 |
+import fr.ird.observe.client.ui.content.impl.seine.FloatingObjectUIModel;
|
|
| 27 |
+import fr.ird.observe.services.dto.seine.ObjectMaterialHierarchyDto;
|
|
| 28 |
+import java.util.Arrays;
|
|
| 29 |
+import java.util.Collections;
|
|
| 30 |
+import java.util.List;
|
|
| 31 |
+import java.util.Optional;
|
|
| 32 |
+import org.apache.commons.logging.Log;
|
|
| 33 |
+import org.apache.commons.logging.LogFactory;
|
|
| 34 |
+import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
|
|
| 35 |
+import org.jdesktop.swingx.treetable.TreeTableNode;
|
|
| 36 |
+import org.nuiton.i18n.I18n;
|
|
| 37 |
+ |
|
| 38 |
+/**
|
|
| 39 |
+ * Created by tchemit on 05/08/17.
|
|
| 40 |
+ *
|
|
| 41 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 42 |
+ * @since 7.0
|
|
| 43 |
+ */
|
|
| 44 |
+public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel {
|
|
| 45 |
+ |
|
| 46 |
+ /** Logger. */
|
|
| 47 |
+ private static final Log log = LogFactory.getLog(FloatingObjectPartsTreeTableModel.class);
|
|
| 48 |
+ |
|
| 49 |
+ private final FloatingObjectUIModel uiModel;
|
|
| 50 |
+ |
|
| 51 |
+ private ImmutableSet<FloatingObjectPartsTreeNode> allNodes;
|
|
| 52 |
+ private ImmutableSet<FloatingObjectPartsTreeNode> needOneSelectionNodes;
|
|
| 53 |
+ private ImmutableSet<FloatingObjectPartsTreeNode> mandatoryNodes;
|
|
| 54 |
+ |
|
| 55 |
+ public FloatingObjectPartsTreeTableModel(FloatingObjectUIModel uiModel) {
|
|
| 56 |
+ super(FloatingObjectPartsTreeNode.createRoot(uiModel, Collections.emptyList()), Arrays.asList(
|
|
| 57 |
+ I18n.t("observe.content.floatingObject.table.type"),
|
|
| 58 |
+ I18n.t("observe.common.whenArriving"),
|
|
| 59 |
+ I18n.t("observe.common.whenLeaving")));
|
|
| 60 |
+ this.uiModel = uiModel;
|
|
| 61 |
+ }
|
|
| 62 |
+ |
|
| 63 |
+ @Override
|
|
| 64 |
+ public FloatingObjectPartsTreeNode getRoot() {
|
|
| 65 |
+ return (FloatingObjectPartsTreeNode) super.getRoot();
|
|
| 66 |
+ }
|
|
| 67 |
+ |
|
| 68 |
+ public void rebuildRootNode(List<ObjectMaterialHierarchyDto> materials) {
|
|
| 69 |
+ FloatingObjectPartsTreeNode root = FloatingObjectPartsTreeNode.createRoot(uiModel, materials);
|
|
| 70 |
+ setRoot(root);
|
|
| 71 |
+ }
|
|
| 72 |
+ |
|
| 73 |
+ @Override
|
|
| 74 |
+ public void setRoot(TreeTableNode root) {
|
|
| 75 |
+ super.setRoot(root);
|
|
| 76 |
+ |
|
| 77 |
+ FloatingObjectPartsTreeNode myRoot = (FloatingObjectPartsTreeNode) root;
|
|
| 78 |
+ |
|
| 79 |
+ ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder = ImmutableSet.builder();
|
|
| 80 |
+ ImmutableSet.Builder<FloatingObjectPartsTreeNode> needOneSelectionNodesBuilder = ImmutableSet.builder();
|
|
| 81 |
+ ImmutableSet.Builder<FloatingObjectPartsTreeNode> mandatoryNodesBuilder = ImmutableSet.builder();
|
|
| 82 |
+ |
|
| 83 |
+ myRoot.fillNodeSets(allNodesBuilder, needOneSelectionNodesBuilder, mandatoryNodesBuilder);
|
|
| 84 |
+ |
|
| 85 |
+ allNodes = allNodesBuilder.build();
|
|
| 86 |
+ needOneSelectionNodes = needOneSelectionNodesBuilder.build();
|
|
| 87 |
+ mandatoryNodes = mandatoryNodesBuilder.build();
|
|
| 88 |
+ }
|
|
| 89 |
+ |
|
| 90 |
+ @Override
|
|
| 91 |
+ public int getColumnCount() {
|
|
| 92 |
+ return 3;
|
|
| 93 |
+ }
|
|
| 94 |
+ |
|
| 95 |
+ @Override
|
|
| 96 |
+ public Class<?> getColumnClass(int column) {
|
|
| 97 |
+ switch (column) {
|
|
| 98 |
+ case 0:
|
|
| 99 |
+ return String.class;
|
|
| 100 |
+ case 1:
|
|
| 101 |
+ case 2:
|
|
| 102 |
+ return Object.class;
|
|
| 103 |
+ }
|
|
| 104 |
+ throw new IllegalStateException();
|
|
| 105 |
+ }
|
|
| 106 |
+ |
|
| 107 |
+ @Override
|
|
| 108 |
+ public void setValueAt(Object value, Object node, int column) {
|
|
| 109 |
+ FloatingObjectPartsTreeNode treeNode = (FloatingObjectPartsTreeNode) node;
|
|
| 110 |
+ Optional<FloatingObjectPartsTreeNode> previousNode = treeNode.isExclusive() && value != null ? treeNode.getSelectedCompanion(column) : Optional.empty();
|
|
| 111 |
+ previousNode.ifPresent(p -> log.info("Previous selected node: " + p));
|
|
| 112 |
+ super.setValueAt(value, node, column);
|
|
| 113 |
+ previousNode.ifPresent(t -> super.setValueAt(null, t, column));
|
|
| 114 |
+ reset();
|
|
| 115 |
+ uiModel.setModified(true);
|
|
| 116 |
+ }
|
|
| 117 |
+ |
|
| 118 |
+ public void reset() {
|
|
| 119 |
+ allNodes.forEach(FloatingObjectPartsTreeNode::resetStates);
|
|
| 120 |
+ |
|
| 121 |
+ boolean whenArriving = uiModel.isArriving();
|
|
| 122 |
+ boolean whenLeaving = uiModel.isLeaving();
|
|
| 123 |
+ |
|
| 124 |
+ needOneSelectionNodes.forEach(n -> n.computeNeedAtLeastOnSelectValidState(whenArriving, whenLeaving));
|
|
| 125 |
+ mandatoryNodes.forEach(n -> n.computeMandatoryValidState(whenArriving, whenLeaving));
|
|
| 126 |
+ |
|
| 127 |
+ boolean notValid = allNodes.stream().anyMatch(FloatingObjectPartsTreeNode::isNotValid);
|
|
| 128 |
+ uiModel.getBean().setMaterialsValid(!notValid);
|
|
| 129 |
+ }
|
|
| 130 |
+ |
|
| 131 |
+}
|
| 1 |
+package fr.ird.observe.client.ui.util.treetable;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import java.awt.Component;
|
|
| 26 |
+import java.awt.event.ActionEvent;
|
|
| 27 |
+import java.awt.event.ActionListener;
|
|
| 28 |
+import java.awt.event.ItemEvent;
|
|
| 29 |
+import java.awt.event.ItemListener;
|
|
| 30 |
+import java.awt.event.MouseEvent;
|
|
| 31 |
+import java.io.Serializable;
|
|
| 32 |
+import java.util.EventObject;
|
|
| 33 |
+import javax.swing.AbstractCellEditor;
|
|
| 34 |
+import javax.swing.JComponent;
|
|
| 35 |
+import javax.swing.JRadioButton;
|
|
| 36 |
+import javax.swing.JTable;
|
|
| 37 |
+import javax.swing.SwingConstants;
|
|
| 38 |
+import javax.swing.table.TableCellEditor;
|
|
| 39 |
+import javax.swing.table.TableCellRenderer;
|
|
| 40 |
+ |
|
| 41 |
+/**
|
|
| 42 |
+ * Created by tchemit on 05/08/17.
|
|
| 43 |
+ *
|
|
| 44 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 45 |
+ * @since 7.0
|
|
| 46 |
+ */
|
|
| 47 |
+public class JRadioButtonCellEditor extends AbstractCellEditor implements TableCellEditor {
|
|
| 48 |
+ |
|
| 49 |
+ private JRadioButton editorComponent;
|
|
| 50 |
+ private EditorDelegate delegate;
|
|
| 51 |
+ |
|
| 52 |
+ public JRadioButtonCellEditor() {
|
|
| 53 |
+ editorComponent = new JRadioButton();
|
|
| 54 |
+ editorComponent.setHorizontalAlignment(SwingConstants.CENTER);
|
|
| 55 |
+ delegate = new EditorDelegate();
|
|
| 56 |
+ editorComponent.addActionListener(delegate);
|
|
| 57 |
+ editorComponent.setRequestFocusEnabled(false);
|
|
| 58 |
+ }
|
|
| 59 |
+ |
|
| 60 |
+ public Component getComponent() {
|
|
| 61 |
+ return editorComponent;
|
|
| 62 |
+ }
|
|
| 63 |
+ |
|
| 64 |
+ @Override
|
|
| 65 |
+ public Object getCellEditorValue() {
|
|
| 66 |
+ return delegate.getCellEditorValue();
|
|
| 67 |
+ }
|
|
| 68 |
+ |
|
| 69 |
+ @Override
|
|
| 70 |
+ public boolean isCellEditable(EventObject anEvent) {
|
|
| 71 |
+ return delegate.isCellEditable(anEvent);
|
|
| 72 |
+ }
|
|
| 73 |
+ |
|
| 74 |
+ @Override
|
|
| 75 |
+ public boolean shouldSelectCell(EventObject anEvent) {
|
|
| 76 |
+ return delegate.shouldSelectCell(anEvent);
|
|
| 77 |
+ }
|
|
| 78 |
+ |
|
| 79 |
+ @Override
|
|
| 80 |
+ public boolean stopCellEditing() {
|
|
| 81 |
+ return delegate.stopCellEditing();
|
|
| 82 |
+ }
|
|
| 83 |
+ |
|
| 84 |
+ @Override
|
|
| 85 |
+ public void cancelCellEditing() {
|
|
| 86 |
+ delegate.cancelCellEditing();
|
|
| 87 |
+ }
|
|
| 88 |
+ |
|
| 89 |
+ @Override
|
|
| 90 |
+ public Component getTableCellEditorComponent(JTable table, Object value,
|
|
| 91 |
+ boolean isSelected,
|
|
| 92 |
+ int row, int column) {
|
|
| 93 |
+ delegate.setValue(value);
|
|
| 94 |
+ //in order to avoid a "flashing" effect when clicking a checkbox
|
|
| 95 |
+ //in a table, it is important for the editor to have as a border
|
|
| 96 |
+ //the same border that the renderer has, and have as the background
|
|
| 97 |
+ //the same color as the renderer has. This is primarily only
|
|
| 98 |
+ //needed for JCheckBox since this editor doesn't fill all the
|
|
| 99 |
+ //visual space of the table cell, unlike a text field.
|
|
| 100 |
+ TableCellRenderer renderer = table.getCellRenderer(row, column);
|
|
| 101 |
+ Component c = renderer.getTableCellRendererComponent(table, value, isSelected, true, row, column);
|
|
| 102 |
+ if (c != null) {
|
|
| 103 |
+ editorComponent.setOpaque(true);
|
|
| 104 |
+ editorComponent.setBackground(c.getBackground());
|
|
| 105 |
+ if (c instanceof JComponent) {
|
|
| 106 |
+ editorComponent.setBorder(((JComponent) c).getBorder());
|
|
| 107 |
+ }
|
|
| 108 |
+ } else {
|
|
| 109 |
+ editorComponent.setOpaque(false);
|
|
| 110 |
+ }
|
|
| 111 |
+ return editorComponent;
|
|
| 112 |
+ }
|
|
| 113 |
+ |
|
| 114 |
+ protected class EditorDelegate implements ActionListener, ItemListener, Serializable {
|
|
| 115 |
+ |
|
| 116 |
+ boolean getCellEditorValue() {
|
|
| 117 |
+ return editorComponent.isSelected();
|
|
| 118 |
+ }
|
|
| 119 |
+ |
|
| 120 |
+ public void setValue(Object value) {
|
|
| 121 |
+ |
|
| 122 |
+ boolean selected = false;
|
|
| 123 |
+ if (value instanceof Boolean) {
|
|
| 124 |
+ selected = (Boolean) value;
|
|
| 125 |
+ } else if (value instanceof String) {
|
|
| 126 |
+ selected = value.equals("true");
|
|
| 127 |
+ }
|
|
| 128 |
+ editorComponent.setSelected(selected);
|
|
| 129 |
+ }
|
|
| 130 |
+ |
|
| 131 |
+ public boolean isCellEditable(EventObject anEvent) {
|
|
| 132 |
+ return !(anEvent instanceof MouseEvent) || ((MouseEvent) anEvent).getClickCount() > 0;
|
|
| 133 |
+ }
|
|
| 134 |
+ |
|
| 135 |
+ boolean shouldSelectCell(@SuppressWarnings("unused") EventObject ignored) {
|
|
| 136 |
+ return true;
|
|
| 137 |
+ }
|
|
| 138 |
+ |
|
| 139 |
+ boolean stopCellEditing() {
|
|
| 140 |
+ fireEditingStopped();
|
|
| 141 |
+ return true;
|
|
| 142 |
+ }
|
|
| 143 |
+ |
|
| 144 |
+ void cancelCellEditing() {
|
|
| 145 |
+ fireEditingCanceled();
|
|
| 146 |
+ }
|
|
| 147 |
+ |
|
| 148 |
+ @Override
|
|
| 149 |
+ public void actionPerformed(ActionEvent e) {
|
|
| 150 |
+ this.stopCellEditing();
|
|
| 151 |
+ }
|
|
| 152 |
+ |
|
| 153 |
+ @Override
|
|
| 154 |
+ public void itemStateChanged(ItemEvent e) {
|
|
| 155 |
+ this.stopCellEditing();
|
|
| 156 |
+ }
|
|
| 157 |
+ }
|
|
| 158 |
+ |
|
| 159 |
+}
|
| 1 |
+package fr.ird.observe.client.ui.util.treetable;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+import javax.swing.JLabel;
|
|
| 27 |
+import javax.swing.JRadioButton;
|
|
| 28 |
+import org.jdesktop.swingx.renderer.CellContext;
|
|
| 29 |
+import org.jdesktop.swingx.renderer.ComponentProvider;
|
|
| 30 |
+ |
|
| 31 |
+/**
|
|
| 32 |
+ * Created by tchemit on 05/08/17.
|
|
| 33 |
+ *
|
|
| 34 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 35 |
+ * @since 7.0
|
|
| 36 |
+ */
|
|
| 37 |
+public class JRadioButtonProvider extends ComponentProvider<JRadioButton> {
|
|
| 38 |
+ |
|
| 39 |
+ @Override
|
|
| 40 |
+ protected void format(CellContext context) {
|
|
| 41 |
+ rendererComponent.setSelected(Boolean.TRUE.equals(context.getValue()));
|
|
| 42 |
+ }
|
|
| 43 |
+ |
|
| 44 |
+ @Override
|
|
| 45 |
+ protected void configureState(CellContext context) {
|
|
| 46 |
+ rendererComponent.setHorizontalAlignment(JLabel.CENTER);
|
|
| 47 |
+ rendererComponent.setBorderPainted(true);
|
|
| 48 |
+ }
|
|
| 49 |
+ |
|
| 50 |
+ @Override
|
|
| 51 |
+ protected JRendererRadioButton createRendererComponent() {
|
|
| 52 |
+ return new JRendererRadioButton();
|
|
| 53 |
+ }
|
|
| 54 |
+ |
|
| 55 |
+}
|
| 1 |
+package fr.ird.observe.client.ui.util.treetable;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+import java.awt.Graphics;
|
|
| 27 |
+import java.awt.Graphics2D;
|
|
| 28 |
+import java.awt.Rectangle;
|
|
| 29 |
+import javax.swing.JRadioButton;
|
|
| 30 |
+import javax.swing.UIManager;
|
|
| 31 |
+import org.jdesktop.swingx.painter.Painter;
|
|
| 32 |
+import org.jdesktop.swingx.renderer.PainterAware;
|
|
| 33 |
+ |
|
| 34 |
+/**
|
|
| 35 |
+ * Created by tchemit on 05/08/17.
|
|
| 36 |
+ *
|
|
| 37 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 38 |
+ * @since 7.0
|
|
| 39 |
+ */
|
|
| 40 |
+public class JRendererRadioButton extends JRadioButton implements PainterAware {
|
|
| 41 |
+ /** the swingx painter */
|
|
| 42 |
+ private Painter painter;
|
|
| 43 |
+ /** a flag to prevent ui painting from filling the background. */
|
|
| 44 |
+ private boolean fakeTransparency;
|
|
| 45 |
+ |
|
| 46 |
+ JRendererRadioButton() {
|
|
| 47 |
+ super();
|
|
| 48 |
+ // fix # 1546-swingx: striping lost in synth-based lafs
|
|
| 49 |
+ // forcing opaque to enable painting the background
|
|
| 50 |
+ setOpaque(true);
|
|
| 51 |
+ }
|
|
| 52 |
+ |
|
| 53 |
+ @Override
|
|
| 54 |
+ public Painter getPainter() {
|
|
| 55 |
+ return painter;
|
|
| 56 |
+ }
|
|
| 57 |
+ |
|
| 58 |
+ @Override
|
|
| 59 |
+ public void setPainter(Painter painter) {
|
|
| 60 |
+ Painter old = getPainter();
|
|
| 61 |
+ this.painter = painter;
|
|
| 62 |
+ firePropertyChange("painter", old, getPainter());
|
|
| 63 |
+ }
|
|
| 64 |
+ |
|
| 65 |
+ /**
|
|
| 66 |
+ * Overridden to return false if painting flag is true.<p>
|
|
| 67 |
+ */
|
|
| 68 |
+ @Override
|
|
| 69 |
+ public boolean isOpaque() {
|
|
| 70 |
+ return !fakeTransparency && super.isOpaque();
|
|
| 71 |
+ }
|
|
| 72 |
+ |
|
| 73 |
+ /**
|
|
| 74 |
+ * Overridden to return false if painting flag is true.<p>
|
|
| 75 |
+ */
|
|
| 76 |
+ @Override
|
|
| 77 |
+ public boolean isContentAreaFilled() {
|
|
| 78 |
+ return !fakeTransparency && super.isContentAreaFilled();
|
|
| 79 |
+ }
|
|
| 80 |
+ |
|
| 81 |
+ /**
|
|
| 82 |
+ * Overridden to not automatically de/register itself from/to the ToolTipManager.
|
|
| 83 |
+ * As rendering component it is not considered to be active in any way, so the
|
|
| 84 |
+ * manager must not listen.
|
|
| 85 |
+ */
|
|
| 86 |
+ @Override
|
|
| 87 |
+ public void setToolTipText(String text) {
|
|
| 88 |
+ putClientProperty(TOOL_TIP_TEXT_KEY, text);
|
|
| 89 |
+ }
|
|
| 90 |
+ |
|
| 91 |
+ /**
|
|
| 92 |
+ * Overridden to snatch painting from super if a painter installed or Nimbus
|
|
| 93 |
+ * detected.<p>
|
|
| 94 |
+ * <p>
|
|
| 95 |
+ * The overall logic currently (since 1.6.5) is to simply call super without SwingX
|
|
| 96 |
+ * painter. Otherwise, that is with SwingX painter:
|
|
| 97 |
+ * <ol>
|
|
| 98 |
+ * <li> if opaque
|
|
| 99 |
+ * <ol>
|
|
| 100 |
+ * <li> set a flag which fakes transparency, that is both
|
|
| 101 |
+ * <code>contentAreaFilled</code> and
|
|
| 102 |
+ * <code>opaque</code> return false
|
|
| 103 |
+ * <li> fill background with the component's background color
|
|
| 104 |
+ * <li> apply swingx painter
|
|
| 105 |
+ * <li> hook into <code>ui.paint(...)</code>
|
|
| 106 |
+ * <li> reset the flag
|
|
| 107 |
+ * </ol>
|
|
| 108 |
+ * <li> else
|
|
| 109 |
+ * <ol> apply swingx painter
|
|
| 110 |
+ * <ol> call super
|
|
| 111 |
+ * <li>
|
|
| 112 |
+ * <ol>
|
|
| 113 |
+ * </ol>
|
|
| 114 |
+ * <p>
|
|
| 115 |
+ * Note that Nimbus is special cased (mainly due to its bug of
|
|
| 116 |
+ * even row striping instead of odd)
|
|
| 117 |
+ * and handled as if a SwingX painter were set.
|
|
| 118 |
+ */
|
|
| 119 |
+ @Override
|
|
| 120 |
+ protected void paintComponent(Graphics g) {
|
|
| 121 |
+ // JW: hack around for #1178-swingx (core issue)
|
|
| 122 |
+ // grab painting if Nimbus detected
|
|
| 123 |
+ if ((painter != null) || isNimbus()) {
|
|
| 124 |
+ // we have a custom (background) painter
|
|
| 125 |
+ // try to inject if possible
|
|
| 126 |
+ // there's no guarantee - some LFs have their own background
|
|
| 127 |
+ // handling elsewhere
|
|
| 128 |
+ if (isOpaque()) {
|
|
| 129 |
+ // replace the paintComponent completely
|
|
| 130 |
+ fakeTransparency = true;
|
|
| 131 |
+ paintComponentWithPainter((Graphics2D) g);
|
|
| 132 |
+ fakeTransparency = false;
|
|
| 133 |
+ } else {
|
|
| 134 |
+ // transparent apply the background painter before calling super
|
|
| 135 |
+ paintPainter(g);
|
|
| 136 |
+ super.paintComponent(g);
|
|
| 137 |
+ }
|
|
| 138 |
+ } else {
|
|
| 139 |
+ // nothing to worry about - delegate to super
|
|
| 140 |
+ super.paintComponent(g);
|
|
| 141 |
+ }
|
|
| 142 |
+ }
|
|
| 143 |
+ |
|
| 144 |
+ /**
|
|
| 145 |
+ * Hack around Nimbus not respecting background colors if UIResource.
|
|
| 146 |
+ * So by-pass ...
|
|
| 147 |
+ */
|
|
| 148 |
+ private boolean isNimbus() {
|
|
| 149 |
+ return UIManager.getLookAndFeel().getName().contains("Nimbus");
|
|
| 150 |
+ }
|
|
| 151 |
+ |
|
| 152 |
+ |
|
| 153 |
+ /**
|
|
| 154 |
+ * Hack around AbstractPainter.paint bug which disposes the Graphics.
|
|
| 155 |
+ * So here we give it a scratch to paint on. <p>
|
|
| 156 |
+ * TODO - remove again, the issue is fixed?
|
|
| 157 |
+ *
|
|
| 158 |
+ * @param g the graphics to paint on
|
|
| 159 |
+ */
|
|
| 160 |
+ private void paintPainter(Graphics g) {
|
|
| 161 |
+ if (painter == null) return;
|
|
| 162 |
+ // fail fast: we assume that g must not be null
|
|
| 163 |
+ // which throws an NPE here instead deeper down the bowels
|
|
| 164 |
+ // this differs from corresponding core implementation!
|
|
| 165 |
+ Graphics2D scratch = (Graphics2D) g.create();
|
|
| 166 |
+ try {
|
|
| 167 |
+ painter.paint(scratch, this, getWidth(), getHeight());
|
|
| 168 |
+ } finally {
|
|
| 169 |
+ scratch.dispose();
|
|
| 170 |
+ }
|
|
| 171 |
+ }
|
|
| 172 |
+ |
|
| 173 |
+ private void paintComponentWithPainter(Graphics2D g) {
|
|
| 174 |
+ // 1. be sure to fill the background
|
|
| 175 |
+ // 2. paint the painter
|
|
| 176 |
+ // by-pass ui.update and hook into ui.paint directly
|
|
| 177 |
+ if (ui != null) {
|
|
| 178 |
+ // fail fast: we assume that g must not be null
|
|
| 179 |
+ // which throws an NPE here instead deeper down the bowels
|
|
| 180 |
+ // this differs from corresponding core implementation!
|
|
| 181 |
+ Graphics scratchGraphics = g.create();
|
|
| 182 |
+ try {
|
|
| 183 |
+ scratchGraphics.setColor(getBackground());
|
|
| 184 |
+ scratchGraphics.fillRect(0, 0, getWidth(), getHeight());
|
|
| 185 |
+ paintPainter(g);
|
|
| 186 |
+ ui.paint(scratchGraphics, this);
|
|
| 187 |
+ } finally {
|
|
| 188 |
+ scratchGraphics.dispose();
|
|
| 189 |
+ }
|
|
| 190 |
+ }
|
|
| 191 |
+ |
|
| 192 |
+ }
|
|
| 193 |
+ |
|
| 194 |
+ /**
|
|
| 195 |
+ * Overridden for performance reasons.
|
|
| 196 |
+ * See the <a href="#override">Implementation Note</a>
|
|
| 197 |
+ * for more information.
|
|
| 198 |
+ *
|
|
| 199 |
+ * @since 1.5
|
|
| 200 |
+ */
|
|
| 201 |
+ @Override
|
|
| 202 |
+ public void invalidate() {
|
|
| 203 |
+ }
|
|
| 204 |
+ |
|
| 205 |
+ /**
|
|
| 206 |
+ * Overridden for performance reasons.
|
|
| 207 |
+ * See the <a href="#override">Implementation Note</a>
|
|
| 208 |
+ * for more information.
|
|
| 209 |
+ */
|
|
| 210 |
+ @Override
|
|
| 211 |
+ public void validate() {
|
|
| 212 |
+ }
|
|
| 213 |
+ |
|
| 214 |
+ /**
|
|
| 215 |
+ * Overridden for performance reasons.
|
|
| 216 |
+ * See the <a href="#override">Implementation Note</a>
|
|
| 217 |
+ * for more information.
|
|
| 218 |
+ */
|
|
| 219 |
+ @Override
|
|
| 220 |
+ public void revalidate() {
|
|
| 221 |
+ }
|
|
| 222 |
+ |
|
| 223 |
+ /**
|
|
| 224 |
+ * Overridden for performance reasons.
|
|
| 225 |
+ * See the <a href="#override">Implementation Note</a>
|
|
| 226 |
+ * for more information.
|
|
| 227 |
+ */
|
|
| 228 |
+ @Override
|
|
| 229 |
+ public void repaint(long tm, int x, int y, int width, int height) {
|
|
| 230 |
+ }
|
|
| 231 |
+ |
|
| 232 |
+ /**
|
|
| 233 |
+ * Overridden for performance reasons.
|
|
| 234 |
+ * See the <a href="#override">Implementation Note</a>
|
|
| 235 |
+ * for more information.
|
|
| 236 |
+ */
|
|
| 237 |
+ @Override
|
|
| 238 |
+ public void repaint(Rectangle r) {
|
|
| 239 |
+ }
|
|
| 240 |
+ |
|
| 241 |
+ /**
|
|
| 242 |
+ * Overridden for performance reasons.
|
|
| 243 |
+ * See the <a href="#override">Implementation Note</a>
|
|
| 244 |
+ * for more information.
|
|
| 245 |
+ *
|
|
| 246 |
+ * @since 1.5
|
|
| 247 |
+ */
|
|
| 248 |
+ @Override
|
|
| 249 |
+ public void repaint() {
|
|
| 250 |
+ }
|
|
| 251 |
+ |
|
| 252 |
+ /**
|
|
| 253 |
+ * Overridden for performance reasons.
|
|
| 254 |
+ * See the <a href="#override">Implementation Note</a>
|
|
| 255 |
+ * for more information.
|
|
| 256 |
+ */
|
|
| 257 |
+ @Override
|
|
| 258 |
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
|
|
| 259 |
+ // Strings get interned...
|
|
| 260 |
+ if ("text".equals(propertyName)) {
|
|
| 261 |
+ super.firePropertyChange(propertyName, oldValue, newValue);
|
|
| 262 |
+ }
|
|
| 263 |
+ }
|
|
| 264 |
+ |
|
| 265 |
+ /**
|
|
| 266 |
+ * Overridden for performance reasons.
|
|
| 267 |
+ * See the <a href="#override">Implementation Note</a>
|
|
| 268 |
+ * for more information.
|
|
| 269 |
+ */
|
|
| 270 |
+ @Override
|
|
| 271 |
+ public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
|
|
| 272 |
+ }
|
|
| 273 |
+ |
|
| 274 |
+ |
|
| 275 |
+}
|
| ... | ... | @@ -55,8 +55,8 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste |
| 55 | 55 |
|
| 56 | 56 |
LastUpdateDateTopiaDao dao = getDao(LastUpdateDate.class, LastUpdateDateTopiaDao.class);
|
| 57 | 57 |
LastUpdateDate lastUpdateDate = dao.findUniqueByType(entityType.getName());
|
| 58 |
- if (log.isInfoEnabled()) {
|
|
| 59 |
- log.info("getLastUpdateDate: " + lastUpdateDate.getLastUpdateDate() + " for entity type: " + entityType.getName());
|
|
| 58 |
+ if (log.isDebugEnabled()) {
|
|
| 59 |
+ log.debug("getLastUpdateDate: " + lastUpdateDate.getLastUpdateDate() + " for entity type: " + entityType.getName());
|
|
| 60 | 60 |
}
|
| 61 | 61 |
return lastUpdateDate.getLastUpdateDate();
|
| 62 | 62 |
|
| ... | ... | @@ -66,7 +66,7 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste |
| 66 | 66 |
|
| 67 | 67 |
entity.setLastUpdateDate(date);
|
| 68 | 68 |
|
| 69 |
- // on met à jour l'entité (cela permet de récupérer son topiaId si l'objet est créé)
|
|
| 69 |
+ // update (will then get new id if was not persisted)
|
|
| 70 | 70 |
getDao(entity).update(entity);
|
| 71 | 71 |
|
| 72 | 72 |
Class<E> type = getType(entity);
|
| ... | ... | @@ -86,14 +86,14 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste |
| 86 | 86 |
lastUpdateDate.setLastUpdateDate(date);
|
| 87 | 87 |
lastUpdateDate.setType(entityTypeName);
|
| 88 | 88 |
dao.create(lastUpdateDate);
|
| 89 |
- if (log.isInfoEnabled()) {
|
|
| 90 |
- log.info("Add LastUpdateDate: " + date + " for entity type: " + entityTypeName);
|
|
| 89 |
+ if (log.isDebugEnabled()) {
|
|
| 90 |
+ log.debug("Add LastUpdateDate: " + date + " for entity type: " + entityTypeName);
|
|
| 91 | 91 |
}
|
| 92 | 92 |
} else {
|
| 93 | 93 |
|
| 94 | 94 |
lastUpdateDate = optionalLastUpdateDate.get();
|
| 95 |
- if (log.isInfoEnabled()) {
|
|
| 96 |
- log.info("Change LastUpdateDate: " + date + " for entity type: " + entityTypeName);
|
|
| 95 |
+ if (log.isDebugEnabled()) {
|
|
| 96 |
+ log.debug("Change LastUpdateDate: " + date + " for entity type: " + entityTypeName);
|
|
| 97 | 97 |
}
|
| 98 | 98 |
lastUpdateDate.setLastUpdateDate(date);
|
| 99 | 99 |
}
|
| ... | ... | @@ -108,6 +108,7 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste |
| 108 | 108 |
|
| 109 | 109 |
ObserveEntityEnum entityEnum = ObserveEntityEnum.valueOf(entity);
|
| 110 | 110 |
Objects.requireNonNull(entityEnum, "Entity " + entity + " is not managed by ToPIA");
|
| 111 |
+ //noinspection unchecked
|
|
| 111 | 112 |
return (Class<E>) entityEnum.getContract();
|
| 112 | 113 |
|
| 113 | 114 |
}
|
| ... | ... | @@ -135,13 +136,13 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste |
| 135 | 136 |
|
| 136 | 137 |
private final String fullyTableName;
|
| 137 | 138 |
|
| 138 |
- public CountTableSqlWork(String fullyTableName) {
|
|
| 139 |
+ CountTableSqlWork(String fullyTableName) {
|
|
| 139 | 140 |
this.fullyTableName = fullyTableName;
|
| 140 | 141 |
}
|
| 141 | 142 |
|
| 142 | 143 |
@Override
|
| 143 | 144 |
public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
| 144 |
- String sql = "SELECT count(*) FROM " + fullyTableName;
|
|
| 145 |
+ String sql = String.format("SELECT count(*) FROM %s", fullyTableName);
|
|
| 145 | 146 |
if (showSql) {
|
| 146 | 147 |
log.debug(sql);
|
| 147 | 148 |
}
|
| ... | ... | @@ -329,5 +329,6 @@ public class ObserveI18nDecoratorHelper { |
| 329 | 329 |
n("observe.common.yearService");
|
| 330 | 330 |
n("observe.common.whenArriving");
|
| 331 | 331 |
n("observe.common.whenLeaving");
|
| 332 |
+ n("observe.common.materialsValid");
|
|
| 332 | 333 |
}
|
| 333 | 334 |
}
|
| 1 |
+package fr.ird.observe.services.dto.referential.seine;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Services
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+public class ObjectMaterialDto extends GeneratedObjectMaterialDto {
|
|
| 26 |
+ |
|
| 27 |
+ private static final long serialVersionUID = 1L;
|
|
| 28 |
+ |
|
| 29 |
+ public boolean isBoolean() {
|
|
| 30 |
+ return objectMaterialType != null && "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#0".equals(objectMaterialType.getId());
|
|
| 31 |
+ }
|
|
| 32 |
+ |
|
| 33 |
+ public boolean isText() {
|
|
| 34 |
+ return objectMaterialType != null && "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#3".equals(objectMaterialType.getId());
|
|
| 35 |
+ }
|
|
| 36 |
+ |
|
| 37 |
+ public boolean isInteger() {
|
|
| 38 |
+ return objectMaterialType != null && "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#2".equals(objectMaterialType.getId());
|
|
| 39 |
+ }
|
|
| 40 |
+ |
|
| 41 |
+ public boolean isFloat() {
|
|
| 42 |
+ return objectMaterialType != null && "fr.ird.observe.entities.referentiel.seine.ObjectMaterialType#0#1".equals(objectMaterialType.getId());
|
|
| 43 |
+ }
|
|
| 44 |
+}
|
| ... | ... | @@ -628,6 +628,7 @@ computedWhenArrivingSimplifiedObjectType + {*:1} String |
| 628 | 628 |
computedWhenLeavingBiodegradable + {*:1} !fr.ird.observe.common.constants.seine.DcpComputedValue
|
| 629 | 629 |
computedWhenLeavingNonEntangling + {*:1} !fr.ird.observe.common.constants.seine.DcpComputedValue
|
| 630 | 630 |
computedWhenLeavingSimplifiedObjectType + {*:1} String
|
| 631 |
+materialsValid + {*:1} boolean
|
|
| 631 | 632 |
|
| 632 | 633 |
seine.FloatingObjectObservedSpecies > Commentable
|
| 633 | 634 |
objectObservedSpecies {*} seine.ObjectObservedSpecies
|
| ... | ... | @@ -111,6 +111,7 @@ observe.common.lightsticksType=Lightsticks type |
| 111 | 111 |
observe.common.lineType=Line type
|
| 112 | 112 |
observe.common.locode=Locode
|
| 113 | 113 |
observe.common.longitude=Longitude
|
| 114 |
+observe.common.materialsValid=Materials
|
|
| 114 | 115 |
observe.common.maturityStatus=Maturity status
|
| 115 | 116 |
observe.common.maxDepthTargeted=Max depth targeted
|
| 116 | 117 |
observe.common.maxGearDepth=Max gear depth
|
| ... | ... | @@ -111,6 +111,7 @@ observe.common.lightsticksType=Tipo de barrita de luz |
| 111 | 111 |
observe.common.lineType=Tipo de línea
|
| 112 | 112 |
observe.common.locode=Locode
|
| 113 | 113 |
observe.common.longitude=Longitude
|
| 114 |
+observe.common.materialsValid=Materials \#TODO
|
|
| 114 | 115 |
observe.common.maturityStatus=Maturidad
|
| 115 | 116 |
observe.common.maxDepthTargeted=Profundidad máxima deseada
|
| 116 | 117 |
observe.common.maxGearDepth=Profundidad máxima (m)
|
| ... | ... | @@ -111,6 +111,7 @@ observe.common.lightsticksType=Type de cyalumes |
| 111 | 111 |
observe.common.lineType=Type de ligne
|
| 112 | 112 |
observe.common.locode=Locode
|
| 113 | 113 |
observe.common.longitude=Longitude
|
| 114 |
+observe.common.materialsValid=Matériels
|
|
| 114 | 115 |
observe.common.maturityStatus=Maturité sexuelle
|
| 115 | 116 |
observe.common.maxDepthTargeted=Profondeur maximum ciblée
|
| 116 | 117 |
observe.common.maxGearDepth=Profondeur maximum (m)
|