Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe
Commits:
-
ef780559
by Tony CHEMIT at 2018-07-12T16:20:27Z
9 changed files:
- client/src/main/java/fr/ird/observe/client/ui/ObserveKeyStrokes.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUI.jaxx
- client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUI.jcss
- client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeNode.java
- + client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeTable.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/seine/dcp/FloatingObjectPartsTreeTableModel.java
- dto/src/main/java/fr/ird/observe/dto/data/seine/ObjectMaterialHierarchyDto.java
Changes:
| ... | ... | @@ -111,6 +111,8 @@ public abstract class ObserveKeyStrokes { |
| 111 | 111 |
|
| 112 | 112 |
public static final KeyStroke KEY_STROKE_QUIT = KeyStroke.getKeyStroke("ctrl pressed Q");
|
| 113 | 113 |
public static final KeyStroke KEY_STROKE_DELETE = KeyStroke.getKeyStroke("ctrl pressed U");
|
| 114 |
+ public static final KeyStroke KEY_STROKE_EXPAND_TREE_TABLE_NODE = KeyStroke.getKeyStroke("ctrl released RIGHT");
|
|
| 115 |
+ public static final KeyStroke KEY_STROKE_COLLAPSE_TREE_TABLE_NODE = KeyStroke.getKeyStroke("ctrl released LEFT");
|
|
| 114 | 116 |
|
| 115 | 117 |
private static final ImmutableList<KeyStroke> KEY_STROKE_GO_TABS = ImmutableList.of(
|
| 116 | 118 |
KEY_STROKE_GO_TAB_1,
|
| ... | ... | @@ -39,6 +39,7 @@ |
| 39 | 39 |
fr.ird.observe.client.ui.actions.main.global.DeleteDataGlobalUIAction
|
| 40 | 40 |
fr.ird.observe.client.ui.actions.main.global.ResetDataGlobalUIAction
|
| 41 | 41 |
fr.ird.observe.client.ui.actions.main.global.SaveDataGlobalUIAction
|
| 42 |
+ fr.ird.observe.client.ui.content.data.seine.dcp.FloatingObjectPartsTreeTable
|
|
| 42 | 43 |
fr.ird.observe.client.ui.content.data.seine.dcp.FloatingObjectPartsTreeTableModel
|
| 43 | 44 |
fr.ird.observe.client.ui.content.data.seine.dcp.FloatingObjectPartLegendTreeCellRenderer
|
| 44 | 45 |
fr.ird.observe.client.ui.util.JComment
|
| ... | ... | @@ -175,7 +176,7 @@ |
| 175 | 176 |
<row>
|
| 176 | 177 |
<cell anchor="north" weightx="1" weighty="1">
|
| 177 | 178 |
<JScrollPane id='tableScroll'>
|
| 178 |
- <JXTreeTable id='table'/>
|
|
| 179 |
+ <FloatingObjectPartsTreeTable id='table' constructorParams="new FloatingObjectPartsTreeTableModel(getModel())"/>
|
|
| 179 | 180 |
</JScrollPane>
|
| 180 | 181 |
</cell>
|
| 181 | 182 |
</row>
|
| ... | ... | @@ -140,9 +140,3 @@ BeanComboBox { |
| 140 | 140 |
focusable:false;
|
| 141 | 141 |
}
|
| 142 | 142 |
|
| 143 |
-#table {
|
|
| 144 |
- treeTableModel:{new FloatingObjectPartsTreeTableModel(getModel())};
|
|
| 145 |
- treeCellRenderer:{new FloatingObjectPartLegendTreeCellRenderer()};
|
|
| 146 |
- selectionMode:{ListSelectionModel.SINGLE_SELECTION};
|
|
| 147 |
- rootVisible:false;
|
|
| 148 |
-}
|
| ... | ... | @@ -29,9 +29,6 @@ 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.data.seine.dcp.FloatingObjectPartsTableCellEditor;
|
|
| 33 |
-import fr.ird.observe.client.ui.content.data.seine.dcp.FloatingObjectPartsTableCellRenderer;
|
|
| 34 |
-import fr.ird.observe.client.ui.content.data.seine.dcp.FloatingObjectPartsTreeNode;
|
|
| 35 | 32 |
import fr.ird.observe.client.ui.content.data.seine.dcp.FloatingObjectPartsTreeTableModel;
|
| 36 | 33 |
import fr.ird.observe.client.ui.tree.navigation.NavigationTree;
|
| 37 | 34 |
import fr.ird.observe.client.ui.tree.navigation.nodes.NavigationTreeNodeSupport;
|
| ... | ... | @@ -53,12 +50,6 @@ import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloati |
| 53 | 50 |
import fr.ird.observe.spi.DtoModelHelper;
|
| 54 | 51 |
import org.apache.commons.logging.Log;
|
| 55 | 52 |
import org.apache.commons.logging.LogFactory;
|
| 56 |
-import org.apache.log4j.lf5.viewer.categoryexplorer.TreeModelAdapter;
|
|
| 57 |
-import org.jdesktop.swingx.JXTable;
|
|
| 58 |
-import org.jdesktop.swingx.JXTreeTable;
|
|
| 59 |
-import org.jdesktop.swingx.decorator.ColorHighlighter;
|
|
| 60 |
-import org.jdesktop.swingx.table.ColumnFactory;
|
|
| 61 |
-import org.jdesktop.swingx.table.TableColumnExt;
|
|
| 62 | 53 |
import org.nuiton.jaxx.runtime.spi.UIHandler;
|
| 63 | 54 |
import org.nuiton.jaxx.runtime.swing.SwingUtil;
|
| 64 | 55 |
import org.nuiton.jaxx.validator.swing.SwingValidatorMessage;
|
| ... | ... | @@ -68,8 +59,6 @@ import org.nuiton.validator.NuitonValidatorScope; |
| 68 | 59 |
import javax.swing.Icon;
|
| 69 | 60 |
import javax.swing.SwingUtilities;
|
| 70 | 61 |
import javax.swing.event.TableModelListener;
|
| 71 |
-import javax.swing.event.TreeModelEvent;
|
|
| 72 |
-import java.awt.Color;
|
|
| 73 | 62 |
import java.util.HashSet;
|
| 74 | 63 |
import java.util.Map;
|
| 75 | 64 |
import java.util.Objects;
|
| ... | ... | @@ -182,17 +171,18 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 182 | 171 |
}
|
| 183 | 172 |
loadReferentialReferenceSetsInModel(form);
|
| 184 | 173 |
|
| 185 |
- getModel().setForm(form);
|
|
| 174 |
+ FloatingObjectUIModel model = getModel();
|
|
| 175 |
+ model.setForm(form);
|
|
| 186 | 176 |
FloatingObjectHelper.copyFloatingObjectDto(form.getObject(), bean);
|
| 187 | 177 |
|
| 188 |
- getModel().reset();
|
|
| 178 |
+ model.reset();
|
|
| 189 | 179 |
|
| 190 |
- openTable(partsSet, getUi().getTable(), bean.isPersisted());
|
|
| 180 |
+ getUi().getTable().openTable(model, partsSet, bean.isPersisted());
|
|
| 191 | 181 |
|
| 192 | 182 |
setContentMode(mode);
|
| 193 | 183 |
|
| 194 | 184 |
// do this after setting mode (since only update mode use this...)
|
| 195 |
- getModel().setReference(floatingObjectReference.orElse(null));
|
|
| 185 |
+ model.setReference(floatingObjectReference.orElse(null));
|
|
| 196 | 186 |
|
| 197 | 187 |
if (mode != ContentMode.READ) {
|
| 198 | 188 |
getUi().startEdit(null);
|
| ... | ... | @@ -203,31 +193,15 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 203 | 193 |
|
| 204 | 194 |
@Override
|
| 205 | 195 |
protected void openedUI() {
|
| 206 |
- |
|
| 207 | 196 |
SwingUtilities.invokeLater(this::forceGrabFocusOnForm);
|
| 208 | 197 |
}
|
| 209 | 198 |
|
| 210 |
- private void openTable(Set<FloatingObjectPartReference> partsSet, JXTreeTable table, boolean persisted) {
|
|
| 211 |
- |
|
| 212 |
- FloatingObjectUIModel model = getModel();
|
|
| 213 |
- for (FloatingObjectPartReference p : partsSet) {
|
|
| 214 |
- String objectMaterialId = p.getObjectMaterialId();
|
|
| 215 |
- String whenArriving = p.getWhenArriving();
|
|
| 216 |
- String whenLeaving = p.getWhenLeaving();
|
|
| 217 |
- if (whenArriving != null && !Objects.equals("false", whenArriving)) {
|
|
| 218 |
- model.setWhenArriving(objectMaterialId, whenArriving);
|
|
| 219 |
- }
|
|
| 220 |
- if (whenLeaving != null && !Objects.equals("false", whenLeaving)) {
|
|
| 221 |
- model.setWhenLeaving(objectMaterialId, whenLeaving);
|
|
| 222 |
- }
|
|
| 223 |
- }
|
|
| 224 |
- |
|
| 225 |
- FloatingObjectPartsTreeTableModel treeTableModel = (FloatingObjectPartsTreeTableModel) table.getTreeTableModel();
|
|
| 226 |
- treeTableModel.reset();
|
|
| 227 |
- |
|
| 228 |
- if (persisted) {
|
|
| 229 |
- table.expandAll();
|
|
| 199 |
+ @Override
|
|
| 200 |
+ public void stopEditUI() {
|
|
| 201 |
+ if (ui.getMainTabbedPane().getSelectedIndex() == 1) {
|
|
| 202 |
+ ui.getTable().editingCanceled(null);
|
|
| 230 | 203 |
}
|
| 204 |
+ super.stopEditUI();
|
|
| 231 | 205 |
}
|
| 232 | 206 |
|
| 233 | 207 |
@Override
|
| ... | ... | @@ -334,7 +308,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 334 | 308 |
FloatingObjectUIModel model = getModel();
|
| 335 | 309 |
model.setReferentialMap(allMap);
|
| 336 | 310 |
|
| 337 |
- initTable(detailedForm, ui.getTable());
|
|
| 311 |
+ ui.getTable().initTable(model, () -> getUi().getPreferredSize().width - 200, detailedForm);
|
|
| 338 | 312 |
|
| 339 | 313 |
model.addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_REFERENCE, e -> {
|
| 340 | 314 |
if (!model.isUpdatingMode()) {
|
| ... | ... | @@ -386,60 +360,10 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 386 | 360 |
getModel().setArriving(operation.isWhenArriving());
|
| 387 | 361 |
getModel().setLeaving(operation.isWhenLeaving());
|
| 388 | 362 |
}
|
| 389 |
- FloatingObjectPartsTreeTableModel treeModel = (FloatingObjectPartsTreeTableModel) getUi().getTable().getTreeTableModel();
|
|
| 363 |
+ FloatingObjectPartsTreeTableModel treeModel = getUi().getTable().getTreeTableModel();
|
|
| 390 | 364 |
treeModel.reset();
|
| 391 | 365 |
}
|
| 392 | 366 |
|
| 393 |
- private void initTable(ObjectMaterialHierarchyDto materials, JXTreeTable table) {
|
|
| 394 |
- |
|
| 395 |
- FloatingObjectPartsTreeTableModel treeModel = (FloatingObjectPartsTreeTableModel) table.getTreeTableModel();
|
|
| 396 |
- treeModel.rebuildRootNode(materials);
|
|
| 397 |
- |
|
| 398 |
- table.setColumnFactory(new ColumnFactory() {
|
|
| 399 |
- |
|
| 400 |
- @Override
|
|
| 401 |
- public void configureColumnWidths(JXTable table, TableColumnExt columnExt) {
|
|
| 402 |
- if (table.getColumn(0).equals(columnExt)) {
|
|
| 403 |
- columnExt.setPreferredWidth(getUi().getPreferredSize().width - 200);
|
|
| 404 |
- columnExt.setMinWidth(columnExt.getPreferredWidth());
|
|
| 405 |
- return;
|
|
| 406 |
- }
|
|
| 407 |
- super.configureColumnWidths(table, columnExt);
|
|
| 408 |
- columnExt.setMinWidth(columnExt.getPreferredWidth());
|
|
| 409 |
- }
|
|
| 410 |
- });
|
|
| 411 |
- treeModel.addTreeModelListener(new TreeModelAdapter() {
|
|
| 412 |
- @Override
|
|
| 413 |
- public void treeNodesChanged(TreeModelEvent e) {
|
|
| 414 |
- if (treeModel.isAdjusting()) {
|
|
| 415 |
- return;
|
|
| 416 |
- }
|
|
| 417 |
- getModel().setModified(true);
|
|
| 418 |
- getModel().setPartsModified();
|
|
| 419 |
- }
|
|
| 420 |
- |
|
| 421 |
- });
|
|
| 422 |
- |
|
| 423 |
- table.setDefaultRenderer(Object.class, new FloatingObjectPartsTableCellRenderer(table));
|
|
| 424 |
- table.setDefaultEditor(Object.class, new FloatingObjectPartsTableCellEditor(table));
|
|
| 425 |
- table.addHighlighter(new ColorHighlighter((renderer, adapter) -> {
|
|
| 426 |
- JXTreeTable component = (JXTreeTable) adapter.getComponent();
|
|
| 427 |
- int row = adapter.convertRowIndexToModel(adapter.row);
|
|
| 428 |
- FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) component.getPathForRow(row).getLastPathComponent();
|
|
| 429 |
- boolean valid1 = node.isValid(1);
|
|
| 430 |
- boolean valid2 = node.isValid(2);
|
|
| 431 |
- switch (adapter.convertRowIndexToModel(adapter.column)) {
|
|
| 432 |
- case 0:
|
|
| 433 |
- return false;
|
|
| 434 |
- case 1:
|
|
| 435 |
- return !valid1;
|
|
| 436 |
- case 2:
|
|
| 437 |
- return !valid2;
|
|
| 438 |
- }
|
|
| 439 |
- return true;
|
|
| 440 |
- }, ObserveSwingApplicationContext.get().getConfig().getFloatingObjectMaterialErrorColor(), Color.WHITE));
|
|
| 441 |
- }
|
|
| 442 |
- |
|
| 443 | 367 |
protected void computeTabValidState(SwingValidatorMessageTableModel errorTableModel) {
|
| 444 | 368 |
|
| 445 | 369 |
Set<String> errorProperties = new HashSet<>();
|
| ... | ... | @@ -127,7 +127,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { |
| 127 | 127 |
return result.build();
|
| 128 | 128 |
}
|
| 129 | 129 |
|
| 130 |
- void setPartsModified() {
|
|
| 130 |
+ public void setPartsModified() {
|
|
| 131 | 131 |
firePropertyChange(PROPERTY_PARTS_MODIFIED, true);
|
| 132 | 132 |
}
|
| 133 | 133 |
|
| ... | ... | @@ -23,9 +23,10 @@ package fr.ird.observe.client.ui.content.data.seine.dcp; |
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 | 25 |
import com.google.common.collect.ImmutableSet;
|
| 26 |
+import fr.ird.observe.client.ObserveSwingApplicationContext;
|
|
| 26 | 27 |
import fr.ird.observe.client.ui.content.data.seine.FloatingObjectUIModel;
|
| 27 | 28 |
import fr.ird.observe.dto.data.seine.ObjectMaterialHierarchyDto;
|
| 28 |
-import fr.ird.observe.dto.referential.FormulaHelper;
|
|
| 29 |
+import fr.ird.observe.dto.referential.ReferentialLocale;
|
|
| 29 | 30 |
import fr.ird.observe.dto.referential.seine.ObjectMaterialTypeReference;
|
| 30 | 31 |
import org.apache.commons.logging.Log;
|
| 31 | 32 |
import org.apache.commons.logging.LogFactory;
|
| ... | ... | @@ -60,13 +61,13 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 60 | 61 |
static FloatingObjectPartsTreeNode createRoot(FloatingObjectUIModel model, ObjectMaterialHierarchyDto dto) {
|
| 61 | 62 |
FloatingObjectPartsTreeNode root;
|
| 62 | 63 |
FloatingObjectPartsTreeNodeContext rootModel = new FloatingObjectPartsTreeNodeContext(model);
|
| 63 |
- if (dto != null) {
|
|
| 64 |
+ if (dto == null) {
|
|
| 65 |
+ root = new FloatingObjectPartsTreeNode(rootModel);
|
|
| 66 |
+ } else {
|
|
| 64 | 67 |
FloatingObjectPartsTreeNodeContext childModel = new FloatingObjectPartsTreeNodeContext(dto, rootModel);
|
| 65 | 68 |
root = new FloatingObjectPartsTreeNode(childModel);
|
| 66 | 69 |
root.computeCompanions(null);
|
| 67 | 70 |
root.setCompanions(null);
|
| 68 |
- } else {
|
|
| 69 |
- root = new FloatingObjectPartsTreeNode(rootModel);
|
|
| 70 | 71 |
}
|
| 71 | 72 |
return root;
|
| 72 | 73 |
}
|
| ... | ... | @@ -164,6 +165,8 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 164 | 165 |
getUserObject().text = null;
|
| 165 | 166 |
getUserObject().validWhenArriving = true;
|
| 166 | 167 |
getUserObject().validWhenLeaving = true;
|
| 168 |
+ getUserObject().needOneSelectionOnArriving = false;
|
|
| 169 |
+ getUserObject().needOneSelectionOnLeaving = false;
|
|
| 167 | 170 |
}
|
| 168 | 171 |
|
| 169 | 172 |
@Override
|
| ... | ... | @@ -171,83 +174,88 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 171 | 174 |
return (FloatingObjectPartsTreeNode) super.getParent();
|
| 172 | 175 |
}
|
| 173 | 176 |
|
| 174 |
- void fillNodeSets(ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder,
|
|
| 175 |
- ImmutableSet.Builder<FloatingObjectPartsTreeNode> needOneSelectionNodesBuilder,
|
|
| 176 |
- ImmutableSet.Builder<FloatingObjectPartsTreeNode> mandatoryNodesBuilder) {
|
|
| 177 |
+ ImmutableSet<FloatingObjectPartsTreeNode> getShell() {
|
|
| 177 | 178 |
|
| 178 |
- allNodesBuilder.add(this);
|
|
| 179 |
- if (getUserObject().needOneSelection) {
|
|
| 180 |
- needOneSelectionNodesBuilder.add(this);
|
|
| 181 |
- }
|
|
| 182 |
- if (getUserObject().mandatory) {
|
|
| 183 |
- mandatoryNodesBuilder.add(this);
|
|
| 184 |
- }
|
|
| 179 |
+ ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder = ImmutableSet.builder();
|
|
| 180 |
+ getShell(allNodesBuilder);
|
|
| 181 |
+ return allNodesBuilder.build();
|
|
| 182 |
+ }
|
|
| 185 | 183 |
|
| 184 |
+ private void getShell(ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder) {
|
|
| 185 |
+ allNodesBuilder.add(this);
|
|
| 186 | 186 |
for (FloatingObjectPartsTreeNode child : this) {
|
| 187 |
- child.fillNodeSets(allNodesBuilder, needOneSelectionNodesBuilder, mandatoryNodesBuilder);
|
|
| 187 |
+ child.getShell(allNodesBuilder);
|
|
| 188 | 188 |
}
|
| 189 |
+ }
|
|
| 189 | 190 |
|
| 191 |
+ boolean withMandatoryConstraintsOnChildren() {
|
|
| 192 |
+ ObjectMaterialHierarchyDto userObject = getUserObject().dto;
|
|
| 193 |
+ return userObject == null || userObject.isChildSelectionMandatory();
|
|
| 190 | 194 |
}
|
| 191 | 195 |
|
| 192 | 196 |
void computeNeedAtLeastOnSelectValidState(boolean whenArriving, boolean whenLeaving) {
|
| 193 |
- |
|
| 197 |
+ boolean needSelect = isEditable();
|
|
| 198 |
+ FloatingObjectPartsTreeNodeContext userObject = getUserObject();
|
|
| 194 | 199 |
if (whenArriving) {
|
| 195 |
- getUserObject().validWhenArriving = isAtLeastOneSelected(1);
|
|
| 200 |
+ userObject.needOneSelectionOnArriving = (!needSelect || withValue(1)) && isAtLeastOneSelected(1);
|
|
| 196 | 201 |
}
|
| 197 | 202 |
if (whenLeaving) {
|
| 198 |
- getUserObject().validWhenLeaving = isAtLeastOneSelected(2);
|
|
| 203 |
+ userObject.needOneSelectionOnLeaving = (!needSelect || withValue(2)) && isAtLeastOneSelected(2);
|
|
| 204 |
+ }
|
|
| 205 |
+ if (userObject.needOneSelectionOnArriving || userObject.needOneSelectionOnLeaving) {
|
|
| 206 |
+ log.info("Validate node " + this);
|
|
| 199 | 207 |
}
|
| 200 |
- |
|
| 201 |
- log.info("Validate node " + this);
|
|
| 202 | 208 |
|
| 203 | 209 |
}
|
| 204 | 210 |
|
| 205 |
- void computeMandatoryValidState(boolean whenArriving, boolean whenLeaving) {
|
|
| 206 |
- if (whenArriving) {
|
|
| 207 |
- getUserObject().validWhenArriving = getParent().getUserObject().validWhenArriving;
|
|
| 208 |
- }
|
|
| 209 |
- if (whenLeaving) {
|
|
| 210 |
- getUserObject().validWhenLeaving = getParent().getUserObject().validWhenLeaving;
|
|
| 211 |
+ private FloatingObjectPartsTreeNode getFirstAncestorNeedOneSelection(int column) {
|
|
| 212 |
+ if (withMandatoryConstraintsOnChildren()) {
|
|
| 213 |
+ if (parent == null) {
|
|
| 214 |
+ return this;
|
|
| 215 |
+ }
|
|
| 216 |
+ if (withValue(column)) {
|
|
| 217 |
+ return this;
|
|
| 218 |
+ }
|
|
| 211 | 219 |
}
|
| 212 |
- |
|
| 213 |
- log.info("Validate node " + this);
|
|
| 220 |
+ return getParent().getFirstAncestorNeedOneSelection(column);
|
|
| 214 | 221 |
}
|
| 215 | 222 |
|
| 216 |
- void computeFormulaValidState(boolean whenArriving, boolean whenLeaving) {
|
|
| 217 |
- if (getUserObject().dto == null || getUserObject().dto.isBoolean()) {
|
|
| 218 |
- return;
|
|
| 219 |
- }
|
|
| 220 |
- String validation = getUserObject().dto.getValidation();
|
|
| 221 |
- if (whenArriving && getUserObject().validWhenArriving) {
|
|
| 222 |
- Object value = getUserObject().getValueAt(1);
|
|
| 223 |
- if (value != null) {
|
|
| 224 |
- if (getUserObject().dto.isText()) {
|
|
| 225 |
- getUserObject().validWhenArriving = FormulaHelper.validateObjectMaterialValidation(validation, value);
|
|
| 226 |
- } else if (getUserObject().dto.isInteger()) {
|
|
| 227 |
- getUserObject().validWhenArriving = FormulaHelper.validateObjectMaterialValidation(validation, Integer.valueOf(value.toString()));
|
|
| 228 |
- } else if (getUserObject().dto.isFloat()) {
|
|
| 229 |
- getUserObject().validWhenArriving = FormulaHelper.validateObjectMaterialValidation(validation, Float.valueOf(value.toString()));
|
|
| 230 |
- }
|
|
| 223 |
+ void computeMandatoryValidState(boolean whenArriving, boolean whenLeaving) {
|
|
| 224 |
+ FloatingObjectPartsTreeNodeContext userObject = getUserObject();
|
|
| 225 |
+ FloatingObjectPartsTreeNode parent = getParent();
|
|
| 226 |
+ if (whenArriving) {
|
|
| 227 |
+ if (parent != null && !parent.getUserObject().validWhenArriving) {
|
|
| 228 |
+ userObject.validWhenArriving = false;
|
|
| 229 |
+ } else {
|
|
| 230 |
+ userObject.validWhenArriving = getFirstAncestorNeedOneSelection(1).getUserObject().needOneSelectionOnArriving;
|
|
| 231 | 231 |
}
|
| 232 | 232 |
}
|
| 233 |
- if (whenLeaving && getUserObject().validWhenLeaving) {
|
|
| 234 |
- Object value = getUserObject().getValueAt(2);
|
|
| 235 |
- if (value != null) {
|
|
| 236 |
- if (getUserObject().dto.isText()) {
|
|
| 237 |
- getUserObject().validWhenLeaving = FormulaHelper.validateObjectMaterialValidation(validation, value);
|
|
| 238 |
- } else if (getUserObject().dto.isInteger()) {
|
|
| 239 |
- getUserObject().validWhenLeaving = FormulaHelper.validateObjectMaterialValidation(validation, Integer.valueOf(value.toString()));
|
|
| 240 |
- } else if (getUserObject().dto.isFloat()) {
|
|
| 241 |
- getUserObject().validWhenLeaving = FormulaHelper.validateObjectMaterialValidation(validation, Float.valueOf(value.toString()));
|
|
| 242 |
- }
|
|
| 233 |
+ if (whenLeaving) {
|
|
| 234 |
+ if (parent != null && !parent.getUserObject().validWhenLeaving) {
|
|
| 235 |
+ userObject.validWhenLeaving = false;
|
|
| 236 |
+ } else {
|
|
| 237 |
+ userObject.validWhenLeaving = getFirstAncestorNeedOneSelection(2).getUserObject().needOneSelectionOnLeaving;
|
|
| 243 | 238 |
}
|
| 244 | 239 |
}
|
| 245 | 240 |
|
| 241 |
+ if (userObject.getValueAt(1) != null || userObject.getValueAt(2) != null) {
|
|
| 242 |
+ log.info("Validate node " + this);
|
|
| 243 |
+ }
|
|
| 246 | 244 |
}
|
| 247 | 245 |
|
| 248 |
- boolean withValidation() {
|
|
| 249 |
- return getUserObject().dto != null && getUserObject().dto.withValidation();
|
|
| 250 |
- }
|
|
| 246 |
+// void computeFormulaValidState(boolean whenArriving, boolean whenLeaving) {
|
|
| 247 |
+// FloatingObjectPartsTreeNodeContext userObject = getUserObject();
|
|
| 248 |
+// ObjectMaterialHierarchyDto dto = Objects.requireNonNull(userObject.dto);
|
|
| 249 |
+// if (whenArriving && userObject.validWhenArriving) {
|
|
| 250 |
+// Object value = userObject.getValueAt(1);
|
|
| 251 |
+// userObject.validWhenArriving = dto.isValid(value);
|
|
| 252 |
+// }
|
|
| 253 |
+// if (whenLeaving && userObject.validWhenLeaving) {
|
|
| 254 |
+// Object value = userObject.getValueAt(2);
|
|
| 255 |
+// userObject.validWhenLeaving = dto.isValid(value);
|
|
| 256 |
+// }
|
|
| 257 |
+//
|
|
| 258 |
+// }
|
|
| 251 | 259 |
|
| 252 | 260 |
private void setCompanions(ImmutableSet.Builder<FloatingObjectPartsTreeNode> companionsBuilder) {
|
| 253 | 261 |
if (companionsBuilder != null) {
|
| ... | ... | @@ -258,12 +266,21 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 258 | 266 |
}
|
| 259 | 267 |
}
|
| 260 | 268 |
|
| 269 |
+ private boolean withValue(int column) {
|
|
| 270 |
+ return getValueAt(column) != null;
|
|
| 271 |
+ }
|
|
| 272 |
+ |
|
| 273 |
+ private boolean withValidValue(int column) {
|
|
| 274 |
+ return withValue(column) && (column == 1 ? getUserObject().valueValidOnArriving : getUserObject().valueValidOnLeaving);
|
|
| 275 |
+ }
|
|
| 276 |
+ |
|
| 261 | 277 |
private boolean isAtLeastOneSelected(int column) {
|
| 262 |
- if (getValueAt(column) != null) {
|
|
| 263 |
- return true;
|
|
| 264 |
- }
|
|
| 265 | 278 |
for (FloatingObjectPartsTreeNode child : this) {
|
| 266 |
- if (child.isAtLeastOneSelected(column)) {
|
|
| 279 |
+ if (child.withValidValue(column)) {
|
|
| 280 |
+ return true;
|
|
| 281 |
+ }
|
|
| 282 |
+ boolean result = child.isAtLeastOneSelected(column);
|
|
| 283 |
+ if (result) {
|
|
| 267 | 284 |
return true;
|
| 268 | 285 |
}
|
| 269 | 286 |
}
|
| ... | ... | @@ -288,6 +305,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 288 | 305 |
return dto != null && !dto.isChildrenMultiSelectable() && !isLeaf();
|
| 289 | 306 |
}
|
| 290 | 307 |
|
| 308 |
+ //TODO Improve the design, we should not store anything in uiModel and separate leaving and arriving data
|
|
| 291 | 309 |
private static class FloatingObjectPartsTreeNodeContext {
|
| 292 | 310 |
|
| 293 | 311 |
// main model to get and store values
|
| ... | ... | @@ -298,15 +316,22 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 298 | 316 |
private final boolean enabled;
|
| 299 | 317 |
// Is this node editable ?
|
| 300 | 318 |
private final boolean editable;
|
| 301 |
- // Is this node need at least one child selected ?
|
|
| 302 |
- private final boolean needOneSelection;
|
|
| 303 |
- // Is this node in the path of at least one mandatory child ancestor ?
|
|
| 304 |
- private final boolean mandatory;
|
|
| 305 | 319 |
// Is the node is exclusive (means only one value possible for him and his brothers) ?
|
| 306 | 320 |
private final boolean exclusive;
|
| 307 |
- // Is the node valid for whenArriving column ?
|
|
| 321 |
+ // Is the node use validation on his value ?
|
|
| 322 |
+ private final boolean useValidation;
|
|
| 323 |
+ private final ReferentialLocale referentialLocale;
|
|
| 324 |
+ // Is this node (on arriving) need at least one child selected ? (if editable then node must be selected)
|
|
| 325 |
+ private boolean needOneSelectionOnLeaving;
|
|
| 326 |
+ // Is this node (on leaving) need at least one child selected ? (if editable then node must be selected)
|
|
| 327 |
+ private boolean needOneSelectionOnArriving;
|
|
| 328 |
+ // for a validation node (on arriving), is value valid (if no value then it is valid)
|
|
| 329 |
+ private boolean valueValidOnLeaving = true;
|
|
| 330 |
+ // for a validation node (on leaving), is value valid (if no value then it is valid)
|
|
| 331 |
+ private boolean valueValidOnArriving = true;
|
|
| 332 |
+ // Is the node valid (on arriving) column ?
|
|
| 308 | 333 |
private boolean validWhenArriving = true;
|
| 309 |
- // Is the node valid for whenLeaving column ?
|
|
| 334 |
+ // Is the node valid (on leeaving) column ?
|
|
| 310 | 335 |
private boolean validWhenLeaving = true;
|
| 311 | 336 |
// Set of brothers of this node that is in a exclusive group of node (only one value among all of them)
|
| 312 | 337 |
private ImmutableSet<FloatingObjectPartsTreeNode> companions;
|
| ... | ... | @@ -314,33 +339,33 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 314 | 339 |
private String text;
|
| 315 | 340 |
|
| 316 | 341 |
FloatingObjectPartsTreeNodeContext(FloatingObjectUIModel uiModel) {
|
| 317 |
- Objects.requireNonNull(uiModel);
|
|
| 318 |
- this.uiModel = uiModel;
|
|
| 342 |
+ this.uiModel = Objects.requireNonNull(uiModel);
|
|
| 319 | 343 |
this.dto = null;
|
| 320 | 344 |
this.enabled = true;
|
| 321 | 345 |
this.editable = false;
|
| 322 |
- this.mandatory = false;
|
|
| 323 | 346 |
this.exclusive = false;
|
| 324 |
- this.needOneSelection = false;
|
|
| 347 |
+ this.useValidation = false;
|
|
| 348 |
+ this.valueValidOnArriving = true;
|
|
| 349 |
+ this.valueValidOnLeaving = true;
|
|
| 350 |
+ this.referentialLocale = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale();
|
|
| 325 | 351 |
}
|
| 326 | 352 |
|
| 327 | 353 |
FloatingObjectPartsTreeNodeContext(ObjectMaterialHierarchyDto dto, FloatingObjectPartsTreeNodeContext parent) {
|
| 328 |
- Objects.requireNonNull(dto);
|
|
| 329 |
- Objects.requireNonNull(parent);
|
|
| 330 |
- this.uiModel = parent.uiModel;
|
|
| 331 |
- this.dto = dto;
|
|
| 354 |
+ this.uiModel = Objects.requireNonNull(parent).uiModel;
|
|
| 355 |
+ this.dto = Objects.requireNonNull(dto);
|
|
| 332 | 356 |
// enabled if parent is enabled and dto is enabled
|
| 333 | 357 |
this.enabled = parent.enabled && dto.isEnabled();
|
| 334 |
- // need one selection if is enabled and dto requires it
|
|
| 335 |
- this.needOneSelection = enabled && dto.isChildSelectionMandatory();
|
|
| 336 | 358 |
// editable if dto is selectable (we also make sure that the object material type is here too)
|
| 337 | 359 |
this.editable = dto.isSelectable() && dto.getObjectMaterialType() != null;
|
| 338 |
- |
|
| 339 |
- // mandatory if enabled parent is so or parent makes this child to be
|
|
| 340 |
- this.mandatory = parent.mandatory || parent.needOneSelection;
|
|
| 360 |
+ this.useValidation = enabled && editable && dto.withValidation();
|
|
| 361 |
+ if (!useValidation) {
|
|
| 362 |
+ valueValidOnArriving = true;
|
|
| 363 |
+ valueValidOnLeaving = true;
|
|
| 364 |
+ }
|
|
| 341 | 365 |
// exclusive if his parent requires it
|
| 342 | 366 |
this.exclusive = parent.dto != null && !parent.dto.isChildrenMultiSelectable();
|
| 343 |
- log.info(String.format("New node: %s - mandatory %s - needOneSelection %s - exclusive %s", dto.getLabel2(), mandatory, needOneSelection, exclusive));
|
|
| 367 |
+ this.referentialLocale = ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale();
|
|
| 368 |
+ log.info(String.format("New node: %s %s - needOneSelection %b-%b - exclusive %s", dto.getCode(), dto.getLabel(referentialLocale), needOneSelectionOnArriving, needOneSelectionOnLeaving, exclusive));
|
|
| 344 | 369 |
}
|
| 345 | 370 |
|
| 346 | 371 |
Object getValueAt(int column) {
|
| ... | ... | @@ -356,12 +381,19 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 356 | 381 |
}
|
| 357 | 382 |
|
| 358 | 383 |
void setValueAt(Object aValue, int column) {
|
| 384 |
+ text = null;
|
|
| 359 | 385 |
switch (column) {
|
| 360 | 386 |
case 1: // when arriving
|
| 361 | 387 |
uiModel.setWhenArriving(dto.getId(), aValue == null ? null : String.valueOf(aValue));
|
| 388 |
+ if (useValidation) {
|
|
| 389 |
+ valueValidOnArriving = dto.isValid(aValue);
|
|
| 390 |
+ }
|
|
| 362 | 391 |
return;
|
| 363 | 392 |
case 2: // when leaving
|
| 364 | 393 |
uiModel.setWhenLeaving(dto.getId(), aValue == null ? null : String.valueOf(aValue));
|
| 394 |
+ if (useValidation) {
|
|
| 395 |
+ valueValidOnLeaving = dto.isValid(aValue);
|
|
| 396 |
+ }
|
|
| 365 | 397 |
return;
|
| 366 | 398 |
}
|
| 367 | 399 |
throw new IllegalStateException();
|
| ... | ... | @@ -393,7 +425,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 393 | 425 |
|
| 394 | 426 |
public String getText() {
|
| 395 | 427 |
if (text == null && dto != null) {
|
| 396 |
- text = String.format("%s [value: %s-%s] [valid: %s-%s]", dto.getLabel2(), getValueAt(1), getValueAt(2), isValid(1), isValid(2));
|
|
| 428 |
+ text = String.format("%s [value: %s-%s] [valid: %s-%s]", dto.getLabel(referentialLocale), getValueAt(1), getValueAt(2), isValid(1), isValid(2));
|
|
| 397 | 429 |
}
|
| 398 | 430 |
return text;
|
| 399 | 431 |
}
|
| 1 |
+package fr.ird.observe.client.ui.content.data.seine.dcp;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Client
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2018 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.client.ui.ObserveKeyStrokes;
|
|
| 27 |
+import fr.ird.observe.client.ui.content.data.seine.FloatingObjectUIModel;
|
|
| 28 |
+import fr.ird.observe.dto.data.seine.FloatingObjectPartReference;
|
|
| 29 |
+import fr.ird.observe.dto.data.seine.ObjectMaterialHierarchyDto;
|
|
| 30 |
+import org.apache.log4j.lf5.viewer.categoryexplorer.TreeModelAdapter;
|
|
| 31 |
+import org.jdesktop.swingx.JXTable;
|
|
| 32 |
+import org.jdesktop.swingx.JXTreeTable;
|
|
| 33 |
+import org.jdesktop.swingx.decorator.ColorHighlighter;
|
|
| 34 |
+import org.jdesktop.swingx.table.ColumnFactory;
|
|
| 35 |
+import org.jdesktop.swingx.table.TableColumnExt;
|
|
| 36 |
+import org.jdesktop.swingx.treetable.MutableTreeTableNode;
|
|
| 37 |
+ |
|
| 38 |
+import javax.swing.AbstractAction;
|
|
| 39 |
+import javax.swing.ActionMap;
|
|
| 40 |
+import javax.swing.InputMap;
|
|
| 41 |
+import javax.swing.ListSelectionModel;
|
|
| 42 |
+import javax.swing.SwingUtilities;
|
|
| 43 |
+import javax.swing.event.TreeModelEvent;
|
|
| 44 |
+import javax.swing.tree.TreePath;
|
|
| 45 |
+import java.awt.Color;
|
|
| 46 |
+import java.awt.event.ActionEvent;
|
|
| 47 |
+import java.util.Enumeration;
|
|
| 48 |
+import java.util.Objects;
|
|
| 49 |
+import java.util.Set;
|
|
| 50 |
+import java.util.function.Supplier;
|
|
| 51 |
+ |
|
| 52 |
+/**
|
|
| 53 |
+ * Created by tchemit on 11/07/2018.
|
|
| 54 |
+ *
|
|
| 55 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 56 |
+ */
|
|
| 57 |
+public class FloatingObjectPartsTreeTable extends JXTreeTable {
|
|
| 58 |
+ |
|
| 59 |
+ public FloatingObjectPartsTreeTable(FloatingObjectPartsTreeTableModel treeModel) {
|
|
| 60 |
+ super(treeModel);
|
|
| 61 |
+ setTreeCellRenderer(new FloatingObjectPartLegendTreeCellRenderer());
|
|
| 62 |
+ setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
| 63 |
+ setRootVisible(false);
|
|
| 64 |
+ }
|
|
| 65 |
+ |
|
| 66 |
+ @Override
|
|
| 67 |
+ public FloatingObjectPartsTreeTableModel getTreeTableModel() {
|
|
| 68 |
+ return (FloatingObjectPartsTreeTableModel) super.getTreeTableModel();
|
|
| 69 |
+ }
|
|
| 70 |
+ |
|
| 71 |
+ public void openTable(FloatingObjectUIModel model, Set<FloatingObjectPartReference> partsSet, boolean persisted) {
|
|
| 72 |
+ |
|
| 73 |
+ for (FloatingObjectPartReference p : partsSet) {
|
|
| 74 |
+ String objectMaterialId = p.getObjectMaterialId();
|
|
| 75 |
+ String whenArriving = p.getWhenArriving();
|
|
| 76 |
+ String whenLeaving = p.getWhenLeaving();
|
|
| 77 |
+ if (whenArriving != null && !Objects.equals("false", whenArriving)) {
|
|
| 78 |
+ model.setWhenArriving(objectMaterialId, whenArriving);
|
|
| 79 |
+ }
|
|
| 80 |
+ if (whenLeaving != null && !Objects.equals("false", whenLeaving)) {
|
|
| 81 |
+ model.setWhenLeaving(objectMaterialId, whenLeaving);
|
|
| 82 |
+ }
|
|
| 83 |
+ }
|
|
| 84 |
+ |
|
| 85 |
+ FloatingObjectPartsTreeTableModel treeTableModel = getTreeTableModel();
|
|
| 86 |
+ treeTableModel.reset();
|
|
| 87 |
+ |
|
| 88 |
+ if (persisted) {
|
|
| 89 |
+ expandAll();
|
|
| 90 |
+ } else {
|
|
| 91 |
+ // expand first level nodes (except if they are disabled)
|
|
| 92 |
+ FloatingObjectPartsTreeNode root = treeTableModel.getRoot();
|
|
| 93 |
+ Enumeration<? extends MutableTreeTableNode> children = root.children();
|
|
| 94 |
+ while (children.hasMoreElements()) {
|
|
| 95 |
+ FloatingObjectPartsTreeNode mutableTreeTableNode = (FloatingObjectPartsTreeNode) children.nextElement();
|
|
| 96 |
+ if (mutableTreeTableNode.isEnabled()) {
|
|
| 97 |
+ SwingUtilities.invokeLater(() -> expandPath(new TreePath(new Object[]{root, mutableTreeTableNode})));
|
|
| 98 |
+ }
|
|
| 99 |
+ }
|
|
| 100 |
+ }
|
|
| 101 |
+ // auto expand nodes when selected
|
|
| 102 |
+ addTreeSelectionListener(e -> {
|
|
| 103 |
+ int selectedRow = getSelectedRow();
|
|
| 104 |
+ if (selectedRow != -1) {
|
|
| 105 |
+ if (!isExpanded(selectedRow)) {
|
|
| 106 |
+ SwingUtilities.invokeLater(() -> expandRow(selectedRow));
|
|
| 107 |
+ }
|
|
| 108 |
+ }
|
|
| 109 |
+ });
|
|
| 110 |
+ }
|
|
| 111 |
+ |
|
| 112 |
+ public void initTable(FloatingObjectUIModel model, Supplier<Integer> width, ObjectMaterialHierarchyDto materials) {
|
|
| 113 |
+ |
|
| 114 |
+ FloatingObjectPartsTreeTableModel treeModel = getTreeTableModel();
|
|
| 115 |
+ treeModel.rebuildRootNode(materials);
|
|
| 116 |
+ |
|
| 117 |
+ setColumnFactory(new ColumnFactory() {
|
|
| 118 |
+ |
|
| 119 |
+ @Override
|
|
| 120 |
+ public void configureColumnWidths(JXTable table, TableColumnExt columnExt) {
|
|
| 121 |
+ if (table.getColumn(0).equals(columnExt)) {
|
|
| 122 |
+ columnExt.setPreferredWidth(width.get());
|
|
| 123 |
+ columnExt.setMinWidth(columnExt.getPreferredWidth());
|
|
| 124 |
+ return;
|
|
| 125 |
+ }
|
|
| 126 |
+ super.configureColumnWidths(table, columnExt);
|
|
| 127 |
+ columnExt.setMinWidth(columnExt.getPreferredWidth());
|
|
| 128 |
+ }
|
|
| 129 |
+ });
|
|
| 130 |
+ treeModel.addTreeModelListener(new TreeModelAdapter() {
|
|
| 131 |
+ @Override
|
|
| 132 |
+ public void treeNodesChanged(TreeModelEvent e) {
|
|
| 133 |
+ if (treeModel.isAdjusting()) {
|
|
| 134 |
+ return;
|
|
| 135 |
+ }
|
|
| 136 |
+ model.setModified(true);
|
|
| 137 |
+ model.setPartsModified();
|
|
| 138 |
+ }
|
|
| 139 |
+ |
|
| 140 |
+ });
|
|
| 141 |
+ |
|
| 142 |
+ setDefaultRenderer(Object.class, new FloatingObjectPartsTableCellRenderer(this));
|
|
| 143 |
+ setDefaultEditor(Object.class, new FloatingObjectPartsTableCellEditor(this));
|
|
| 144 |
+ addHighlighter(new ColorHighlighter((renderer, adapter) -> {
|
|
| 145 |
+ JXTreeTable component = (JXTreeTable) adapter.getComponent();
|
|
| 146 |
+ int row = adapter.convertRowIndexToModel(adapter.row);
|
|
| 147 |
+ FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) component.getPathForRow(row).getLastPathComponent();
|
|
| 148 |
+ boolean valid1 = node.isValid(1);
|
|
| 149 |
+ boolean valid2 = node.isValid(2);
|
|
| 150 |
+ switch (adapter.convertRowIndexToModel(adapter.column)) {
|
|
| 151 |
+ case 0:
|
|
| 152 |
+ return false;
|
|
| 153 |
+ case 1:
|
|
| 154 |
+ return !valid1;
|
|
| 155 |
+ case 2:
|
|
| 156 |
+ return !valid2;
|
|
| 157 |
+ }
|
|
| 158 |
+ return true;
|
|
| 159 |
+ }, ObserveSwingApplicationContext.get().getConfig().getFloatingObjectMaterialErrorColor(), Color.WHITE));
|
|
| 160 |
+ |
|
| 161 |
+ InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW);
|
|
| 162 |
+ ActionMap actionMap = getActionMap();
|
|
| 163 |
+ inputMap.put(ObserveKeyStrokes.KEY_STROKE_EXPAND_TREE_TABLE_NODE,"expandNode");
|
|
| 164 |
+ actionMap.put("expandNode", new AbstractAction() {
|
|
| 165 |
+ @Override
|
|
| 166 |
+ public void actionPerformed(ActionEvent e) {
|
|
| 167 |
+ int selectedRow = getSelectedRow();
|
|
| 168 |
+ if (selectedRow != -1) {
|
|
| 169 |
+ if (!isExpanded(selectedRow)) {
|
|
| 170 |
+ SwingUtilities.invokeLater(() -> expandRow(selectedRow));
|
|
| 171 |
+ }
|
|
| 172 |
+ }
|
|
| 173 |
+ }
|
|
| 174 |
+ });
|
|
| 175 |
+ inputMap.put(ObserveKeyStrokes.KEY_STROKE_COLLAPSE_TREE_TABLE_NODE,"collapseNode");
|
|
| 176 |
+ actionMap.put("collapseNode", new AbstractAction() {
|
|
| 177 |
+ @Override
|
|
| 178 |
+ public void actionPerformed(ActionEvent e) {
|
|
| 179 |
+ int selectedRow = getSelectedRow();
|
|
| 180 |
+ if (selectedRow != -1) {
|
|
| 181 |
+ if (!isCollapsed(selectedRow)) {
|
|
| 182 |
+ SwingUtilities.invokeLater(() -> collapseRow(selectedRow));
|
|
| 183 |
+ }
|
|
| 184 |
+ }
|
|
| 185 |
+ }
|
|
| 186 |
+ });
|
|
| 187 |
+ }
|
|
| 188 |
+}
|
| ... | ... | @@ -33,7 +33,6 @@ import org.nuiton.i18n.I18n; |
| 33 | 33 |
|
| 34 | 34 |
import java.util.Arrays;
|
| 35 | 35 |
import java.util.Optional;
|
| 36 |
-import java.util.stream.Collectors;
|
|
| 37 | 36 |
|
| 38 | 37 |
/**
|
| 39 | 38 |
* Created by tchemit on 05/08/17.
|
| ... | ... | @@ -51,7 +50,6 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { |
| 51 | 50 |
private ImmutableSet<FloatingObjectPartsTreeNode> allNodes;
|
| 52 | 51 |
private ImmutableSet<FloatingObjectPartsTreeNode> needOneSelectionNodes;
|
| 53 | 52 |
private ImmutableSet<FloatingObjectPartsTreeNode> mandatoryNodes;
|
| 54 |
- private ImmutableSet<FloatingObjectPartsTreeNode> withValidationNodes;
|
|
| 55 | 53 |
private boolean adjusting;
|
| 56 | 54 |
|
| 57 | 55 |
public FloatingObjectPartsTreeTableModel(FloatingObjectUIModel uiModel) {
|
| ... | ... | @@ -71,18 +69,22 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { |
| 71 | 69 |
public void setRoot(TreeTableNode root) {
|
| 72 | 70 |
super.setRoot(root);
|
| 73 | 71 |
|
| 74 |
- FloatingObjectPartsTreeNode myRoot = (FloatingObjectPartsTreeNode) root;
|
|
| 72 |
+ allNodes = ((FloatingObjectPartsTreeNode) root).getShell();
|
|
| 75 | 73 |
|
| 76 |
- ImmutableSet.Builder<FloatingObjectPartsTreeNode> allNodesBuilder = ImmutableSet.builder();
|
|
| 77 | 74 |
ImmutableSet.Builder<FloatingObjectPartsTreeNode> needOneSelectionNodesBuilder = ImmutableSet.builder();
|
| 78 | 75 |
ImmutableSet.Builder<FloatingObjectPartsTreeNode> mandatoryNodesBuilder = ImmutableSet.builder();
|
| 79 | 76 |
|
| 80 |
- myRoot.fillNodeSets(allNodesBuilder, needOneSelectionNodesBuilder, mandatoryNodesBuilder);
|
|
| 81 |
- |
|
| 82 |
- allNodes = allNodesBuilder.build();
|
|
| 77 |
+ for (FloatingObjectPartsTreeNode node : allNodes) {
|
|
| 78 |
+ if (!node.isEnabled()) {
|
|
| 79 |
+ continue;
|
|
| 80 |
+ }
|
|
| 81 |
+ mandatoryNodesBuilder.add(node);
|
|
| 82 |
+ if (node.withMandatoryConstraintsOnChildren()) {
|
|
| 83 |
+ needOneSelectionNodesBuilder.add(node);
|
|
| 84 |
+ }
|
|
| 85 |
+ }
|
|
| 83 | 86 |
needOneSelectionNodes = needOneSelectionNodesBuilder.build();
|
| 84 | 87 |
mandatoryNodes = mandatoryNodesBuilder.build();
|
| 85 |
- withValidationNodes = ImmutableSet.copyOf(allNodes.stream().filter(FloatingObjectPartsTreeNode::withValidation).collect(Collectors.toSet()));
|
|
| 86 | 88 |
}
|
| 87 | 89 |
|
| 88 | 90 |
public void rebuildRootNode(ObjectMaterialHierarchyDto materials) {
|
| ... | ... | @@ -129,7 +131,6 @@ public class FloatingObjectPartsTreeTableModel extends DefaultTreeTableModel { |
| 129 | 131 |
|
| 130 | 132 |
needOneSelectionNodes.forEach(n -> n.computeNeedAtLeastOnSelectValidState(whenArriving, whenLeaving));
|
| 131 | 133 |
mandatoryNodes.forEach(n -> n.computeMandatoryValidState(whenArriving, whenLeaving));
|
| 132 |
- withValidationNodes.forEach(n -> n.computeFormulaValidState(whenArriving, whenLeaving));
|
|
| 133 | 134 |
|
| 134 | 135 |
boolean notValid = allNodes.stream().anyMatch(FloatingObjectPartsTreeNode::isNotValid);
|
| 135 | 136 |
uiModel.getBean().setMaterialsValid(!notValid);
|
| ... | ... | @@ -22,6 +22,7 @@ package fr.ird.observe.dto.data.seine; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
+import fr.ird.observe.dto.referential.FormulaHelper;
|
|
| 25 | 26 |
import fr.ird.observe.dto.referential.seine.ObjectMaterialDto;
|
| 26 | 27 |
import org.nuiton.util.beans.Binder;
|
| 27 | 28 |
import org.nuiton.util.beans.BinderFactory;
|
| ... | ... | @@ -60,6 +61,20 @@ public class ObjectMaterialHierarchyDto extends ObjectMaterialDto { |
| 60 | 61 |
return result;
|
| 61 | 62 |
}
|
| 62 | 63 |
|
| 64 |
+ public boolean isValid(Object value) {
|
|
| 65 |
+ if (value==null) {
|
|
| 66 |
+ return true;
|
|
| 67 |
+ }
|
|
| 68 |
+ if (isText()) {
|
|
| 69 |
+ return FormulaHelper.validateObjectMaterialValidation(validation, value);
|
|
| 70 |
+ } else if (isInteger()) {
|
|
| 71 |
+ return FormulaHelper.validateObjectMaterialValidation(validation, Integer.valueOf(value.toString()));
|
|
| 72 |
+ } else if (isFloat()) {
|
|
| 73 |
+ return FormulaHelper.validateObjectMaterialValidation(validation, Float.valueOf(value.toString()));
|
|
| 74 |
+ }
|
|
| 75 |
+ throw new IllegalStateException("Can't validate this dto... "+this);
|
|
| 76 |
+ }
|
|
| 77 |
+ |
|
| 63 | 78 |
private void getAllDtos(ObjectMaterialHierarchyDto hierarchyDto, Set<ObjectMaterialHierarchyDto> result) {
|
| 64 | 79 |
result.add(hierarchyDto);
|
| 65 | 80 |
hierarchyDto.getChildren().forEach(c -> getAllDtos(c, result));
|