Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe
Commits:
-
7f1ce7d1
by Tony CHEMIT at 2018-07-11T15:17:05Z
6 changed files:
- 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
Changes:
| ... | ... | @@ -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,33 +193,9 @@ 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();
|
|
| 230 |
- }
|
|
| 231 |
- }
|
|
| 232 |
- |
|
| 233 | 199 |
@Override
|
| 234 | 200 |
public void startEditUI(String... binding) {
|
| 235 | 201 |
ContentUIModel<FloatingObjectDto> contentUIModel = getModel();
|
| ... | ... | @@ -334,7 +300,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 334 | 300 |
FloatingObjectUIModel model = getModel();
|
| 335 | 301 |
model.setReferentialMap(allMap);
|
| 336 | 302 |
|
| 337 |
- initTable(detailedForm, ui.getTable());
|
|
| 303 |
+ ui.getTable().initTable(model, () -> getUi().getPreferredSize().width - 200, detailedForm);
|
|
| 338 | 304 |
|
| 339 | 305 |
model.addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_REFERENCE, e -> {
|
| 340 | 306 |
if (!model.isUpdatingMode()) {
|
| ... | ... | @@ -386,60 +352,10 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, |
| 386 | 352 |
getModel().setArriving(operation.isWhenArriving());
|
| 387 | 353 |
getModel().setLeaving(operation.isWhenLeaving());
|
| 388 | 354 |
}
|
| 389 |
- FloatingObjectPartsTreeTableModel treeModel = (FloatingObjectPartsTreeTableModel) getUi().getTable().getTreeTableModel();
|
|
| 355 |
+ FloatingObjectPartsTreeTableModel treeModel = getUi().getTable().getTreeTableModel();
|
|
| 390 | 356 |
treeModel.reset();
|
| 391 | 357 |
}
|
| 392 | 358 |
|
| 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 | 359 |
protected void computeTabValidState(SwingValidatorMessageTableModel errorTableModel) {
|
| 444 | 360 |
|
| 445 | 361 |
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,11 @@ 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 | 29 |
import fr.ird.observe.dto.referential.FormulaHelper;
|
| 30 |
+import fr.ird.observe.dto.referential.ReferentialLocale;
|
|
| 29 | 31 |
import fr.ird.observe.dto.referential.seine.ObjectMaterialTypeReference;
|
| 30 | 32 |
import org.apache.commons.logging.Log;
|
| 31 | 33 |
import org.apache.commons.logging.LogFactory;
|
| ... | ... | @@ -203,14 +205,17 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 203 | 205 |
}
|
| 204 | 206 |
|
| 205 | 207 |
void computeMandatoryValidState(boolean whenArriving, boolean whenLeaving) {
|
| 208 |
+ FloatingObjectPartsTreeNodeContext userObject = getUserObject();
|
|
| 206 | 209 |
if (whenArriving) {
|
| 207 |
- getUserObject().validWhenArriving = getParent().getUserObject().validWhenArriving;
|
|
| 210 |
+ userObject.validWhenArriving = getParent().getUserObject().validWhenArriving;
|
|
| 208 | 211 |
}
|
| 209 | 212 |
if (whenLeaving) {
|
| 210 |
- getUserObject().validWhenLeaving = getParent().getUserObject().validWhenLeaving;
|
|
| 213 |
+ userObject.validWhenLeaving = getParent().getUserObject().validWhenLeaving;
|
|
| 211 | 214 |
}
|
| 212 | 215 |
|
| 213 |
- log.info("Validate node " + this);
|
|
| 216 |
+ if (userObject.getValueAt(1) != null || userObject.getValueAt(2) != null) {
|
|
| 217 |
+ log.info("Validate node " + this);
|
|
| 218 |
+ }
|
|
| 214 | 219 |
}
|
| 215 | 220 |
|
| 216 | 221 |
void computeFormulaValidState(boolean whenArriving, boolean whenLeaving) {
|
| ... | ... | @@ -304,6 +309,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 304 | 309 |
private final boolean mandatory;
|
| 305 | 310 |
// Is the node is exclusive (means only one value possible for him and his brothers) ?
|
| 306 | 311 |
private final boolean exclusive;
|
| 312 |
+ private final ReferentialLocale referentialLocale;
|
|
| 307 | 313 |
// Is the node valid for whenArriving column ?
|
| 308 | 314 |
private boolean validWhenArriving = true;
|
| 309 | 315 |
// Is the node valid for whenLeaving column ?
|
| ... | ... | @@ -322,6 +328,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 322 | 328 |
this.mandatory = false;
|
| 323 | 329 |
this.exclusive = false;
|
| 324 | 330 |
this.needOneSelection = false;
|
| 331 |
+ this.referentialLocale=ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale();
|
|
| 325 | 332 |
}
|
| 326 | 333 |
|
| 327 | 334 |
FloatingObjectPartsTreeNodeContext(ObjectMaterialHierarchyDto dto, FloatingObjectPartsTreeNodeContext parent) {
|
| ... | ... | @@ -340,7 +347,8 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 340 | 347 |
this.mandatory = parent.mandatory || parent.needOneSelection;
|
| 341 | 348 |
// exclusive if his parent requires it
|
| 342 | 349 |
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));
|
|
| 350 |
+ this.referentialLocale=ObserveSwingApplicationContext.get().getDecoratorService().getReferentialLocale();
|
|
| 351 |
+ log.info(String.format("New node: %s - mandatory %s - needOneSelection %s - exclusive %s", dto.getLabel(referentialLocale), mandatory, needOneSelection, exclusive));
|
|
| 344 | 352 |
}
|
| 345 | 353 |
|
| 346 | 354 |
Object getValueAt(int column) {
|
| ... | ... | @@ -356,6 +364,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 356 | 364 |
}
|
| 357 | 365 |
|
| 358 | 366 |
void setValueAt(Object aValue, int column) {
|
| 367 |
+ text = null;
|
|
| 359 | 368 |
switch (column) {
|
| 360 | 369 |
case 1: // when arriving
|
| 361 | 370 |
uiModel.setWhenArriving(dto.getId(), aValue == null ? null : String.valueOf(aValue));
|
| ... | ... | @@ -393,7 +402,7 @@ public class FloatingObjectPartsTreeNode extends AbstractMutableTreeTableNode im |
| 393 | 402 |
|
| 394 | 403 |
public String getText() {
|
| 395 | 404 |
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));
|
|
| 405 |
+ text = String.format("%s [value: %s-%s] [valid: %s-%s]", dto.getLabel(referentialLocale), getValueAt(1), getValueAt(2), isValid(1), isValid(2));
|
|
| 397 | 406 |
}
|
| 398 | 407 |
return text;
|
| 399 | 408 |
}
|
| 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.content.data.seine.FloatingObjectUIModel;
|
|
| 27 |
+import fr.ird.observe.dto.data.seine.FloatingObjectPartReference;
|
|
| 28 |
+import fr.ird.observe.dto.data.seine.ObjectMaterialHierarchyDto;
|
|
| 29 |
+import org.apache.log4j.lf5.viewer.categoryexplorer.TreeModelAdapter;
|
|
| 30 |
+import org.jdesktop.swingx.JXTable;
|
|
| 31 |
+import org.jdesktop.swingx.JXTreeTable;
|
|
| 32 |
+import org.jdesktop.swingx.decorator.ColorHighlighter;
|
|
| 33 |
+import org.jdesktop.swingx.table.ColumnFactory;
|
|
| 34 |
+import org.jdesktop.swingx.table.TableColumnExt;
|
|
| 35 |
+import org.jdesktop.swingx.treetable.MutableTreeTableNode;
|
|
| 36 |
+ |
|
| 37 |
+import javax.swing.ListSelectionModel;
|
|
| 38 |
+import javax.swing.SwingUtilities;
|
|
| 39 |
+import javax.swing.event.TreeModelEvent;
|
|
| 40 |
+import javax.swing.tree.TreePath;
|
|
| 41 |
+import java.awt.Color;
|
|
| 42 |
+import java.util.Enumeration;
|
|
| 43 |
+import java.util.Objects;
|
|
| 44 |
+import java.util.Set;
|
|
| 45 |
+import java.util.function.Supplier;
|
|
| 46 |
+ |
|
| 47 |
+/**
|
|
| 48 |
+ * Created by tchemit on 11/07/2018.
|
|
| 49 |
+ *
|
|
| 50 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 51 |
+ */
|
|
| 52 |
+public class FloatingObjectPartsTreeTable extends JXTreeTable {
|
|
| 53 |
+ |
|
| 54 |
+ public FloatingObjectPartsTreeTable(FloatingObjectPartsTreeTableModel treeModel) {
|
|
| 55 |
+ super(treeModel);
|
|
| 56 |
+ setTreeCellRenderer(new FloatingObjectPartLegendTreeCellRenderer());
|
|
| 57 |
+ setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
| 58 |
+ setRootVisible(false);
|
|
| 59 |
+ }
|
|
| 60 |
+ |
|
| 61 |
+ @Override
|
|
| 62 |
+ public FloatingObjectPartsTreeTableModel getTreeTableModel() {
|
|
| 63 |
+ return (FloatingObjectPartsTreeTableModel) super.getTreeTableModel();
|
|
| 64 |
+ }
|
|
| 65 |
+ |
|
| 66 |
+ public void openTable(FloatingObjectUIModel model, Set<FloatingObjectPartReference> partsSet, boolean persisted) {
|
|
| 67 |
+ |
|
| 68 |
+ for (FloatingObjectPartReference p : partsSet) {
|
|
| 69 |
+ String objectMaterialId = p.getObjectMaterialId();
|
|
| 70 |
+ String whenArriving = p.getWhenArriving();
|
|
| 71 |
+ String whenLeaving = p.getWhenLeaving();
|
|
| 72 |
+ if (whenArriving != null && !Objects.equals("false", whenArriving)) {
|
|
| 73 |
+ model.setWhenArriving(objectMaterialId, whenArriving);
|
|
| 74 |
+ }
|
|
| 75 |
+ if (whenLeaving != null && !Objects.equals("false", whenLeaving)) {
|
|
| 76 |
+ model.setWhenLeaving(objectMaterialId, whenLeaving);
|
|
| 77 |
+ }
|
|
| 78 |
+ }
|
|
| 79 |
+ |
|
| 80 |
+ FloatingObjectPartsTreeTableModel treeTableModel = getTreeTableModel();
|
|
| 81 |
+ treeTableModel.reset();
|
|
| 82 |
+ |
|
| 83 |
+ if (persisted) {
|
|
| 84 |
+ expandAll();
|
|
| 85 |
+ } else {
|
|
| 86 |
+ // expand first level nodes (except if they are disabled)
|
|
| 87 |
+ FloatingObjectPartsTreeNode root = treeTableModel.getRoot();
|
|
| 88 |
+ Enumeration<? extends MutableTreeTableNode> children = root.children();
|
|
| 89 |
+ while (children.hasMoreElements()) {
|
|
| 90 |
+ FloatingObjectPartsTreeNode mutableTreeTableNode = (FloatingObjectPartsTreeNode) children.nextElement();
|
|
| 91 |
+ if (mutableTreeTableNode.isEnabled()) {
|
|
| 92 |
+ SwingUtilities.invokeLater(() -> expandPath(new TreePath(new Object[]{root, mutableTreeTableNode})));
|
|
| 93 |
+ }
|
|
| 94 |
+ }
|
|
| 95 |
+ }
|
|
| 96 |
+ // auto expand nodes when selected
|
|
| 97 |
+ addTreeSelectionListener(e -> {
|
|
| 98 |
+ int selectedRow = getSelectedRow();
|
|
| 99 |
+ if (selectedRow != -1) {
|
|
| 100 |
+ if (!isExpanded(selectedRow)) {
|
|
| 101 |
+ SwingUtilities.invokeLater(() -> expandRow(selectedRow));
|
|
| 102 |
+ }
|
|
| 103 |
+ }
|
|
| 104 |
+ });
|
|
| 105 |
+ }
|
|
| 106 |
+ |
|
| 107 |
+ public void initTable(FloatingObjectUIModel model, Supplier<Integer> width, ObjectMaterialHierarchyDto materials) {
|
|
| 108 |
+ |
|
| 109 |
+ FloatingObjectPartsTreeTableModel treeModel = getTreeTableModel();
|
|
| 110 |
+ treeModel.rebuildRootNode(materials);
|
|
| 111 |
+ |
|
| 112 |
+ setColumnFactory(new ColumnFactory() {
|
|
| 113 |
+ |
|
| 114 |
+ @Override
|
|
| 115 |
+ public void configureColumnWidths(JXTable table, TableColumnExt columnExt) {
|
|
| 116 |
+ if (table.getColumn(0).equals(columnExt)) {
|
|
| 117 |
+ columnExt.setPreferredWidth(width.get());
|
|
| 118 |
+ columnExt.setMinWidth(columnExt.getPreferredWidth());
|
|
| 119 |
+ return;
|
|
| 120 |
+ }
|
|
| 121 |
+ super.configureColumnWidths(table, columnExt);
|
|
| 122 |
+ columnExt.setMinWidth(columnExt.getPreferredWidth());
|
|
| 123 |
+ }
|
|
| 124 |
+ });
|
|
| 125 |
+ treeModel.addTreeModelListener(new TreeModelAdapter() {
|
|
| 126 |
+ @Override
|
|
| 127 |
+ public void treeNodesChanged(TreeModelEvent e) {
|
|
| 128 |
+ if (treeModel.isAdjusting()) {
|
|
| 129 |
+ return;
|
|
| 130 |
+ }
|
|
| 131 |
+ model.setModified(true);
|
|
| 132 |
+ model.setPartsModified();
|
|
| 133 |
+ }
|
|
| 134 |
+ |
|
| 135 |
+ });
|
|
| 136 |
+ |
|
| 137 |
+ setDefaultRenderer(Object.class, new FloatingObjectPartsTableCellRenderer(this));
|
|
| 138 |
+ setDefaultEditor(Object.class, new FloatingObjectPartsTableCellEditor(this));
|
|
| 139 |
+ addHighlighter(new ColorHighlighter((renderer, adapter) -> {
|
|
| 140 |
+ JXTreeTable component = (JXTreeTable) adapter.getComponent();
|
|
| 141 |
+ int row = adapter.convertRowIndexToModel(adapter.row);
|
|
| 142 |
+ FloatingObjectPartsTreeNode node = (FloatingObjectPartsTreeNode) component.getPathForRow(row).getLastPathComponent();
|
|
| 143 |
+ boolean valid1 = node.isValid(1);
|
|
| 144 |
+ boolean valid2 = node.isValid(2);
|
|
| 145 |
+ switch (adapter.convertRowIndexToModel(adapter.column)) {
|
|
| 146 |
+ case 0:
|
|
| 147 |
+ return false;
|
|
| 148 |
+ case 1:
|
|
| 149 |
+ return !valid1;
|
|
| 150 |
+ case 2:
|
|
| 151 |
+ return !valid2;
|
|
| 152 |
+ }
|
|
| 153 |
+ return true;
|
|
| 154 |
+ }, ObserveSwingApplicationContext.get().getConfig().getFloatingObjectMaterialErrorColor(), Color.WHITE));
|
|
| 155 |
+ }
|
|
| 156 |
+}
|