1 package fr.ifremer.tutti.ui.swing.util.caracteristics.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import com.google.common.base.Preconditions;
28 import fr.ifremer.tutti.persistence.entities.CaracteristicMap;
29 import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
30 import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport;
31 import fr.ifremer.tutti.ui.swing.util.caracteristics.CaracteristicMapEditorRowModel;
32 import fr.ifremer.tutti.ui.swing.util.caracteristics.CaracteristicMapEditorTableModel;
33 import fr.ifremer.tutti.ui.swing.util.caracteristics.CaracteristicMapEditorUI;
34 import fr.ifremer.tutti.ui.swing.util.caracteristics.CaracteristicMapEditorUIModel;
35 import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39
40
41
42
43
44
45 public class CaracteristicEditorRemoveRowAction extends SimpleActionSupport<CaracteristicMapEditorUI> {
46
47
48 private static final Log log = LogFactory.getLog(CaracteristicEditorRemoveRowAction.class);
49
50 private static final long serialVersionUID = 1L;
51
52 public CaracteristicEditorRemoveRowAction(CaracteristicMapEditorUI ui) {
53 super(ui);
54 }
55
56 @Override
57 protected void onActionPerformed(CaracteristicMapEditorUI ui) {
58
59 int rowIndex = ui.getCaracteristicMapEditorTable().getSelectedRow();
60
61 Preconditions.checkState(
62 rowIndex != -1,
63 "Cant remove caracteristic if no caracteristic selected");
64 CaracteristicMapEditorTableModel tableModel = ui.getHandler().getTableModel();
65 CaracteristicMapEditorRowModel row = tableModel.getEntry(rowIndex);
66
67 if (log.isInfoEnabled()) {
68 log.info("Remove caracteristic row: " + row);
69 }
70
71 CaracteristicMapEditorUIModel model = ui.getModel();
72 CaracteristicMap caracteristicMap = model.getCaracteristicMap();
73 if (caracteristicMap != null) {
74 caracteristicMap.remove(row.getKey());
75 }
76
77
78 BeanFilterableComboBox<Caracteristic> keyCombo = ui.getNewRowKey();
79 keyCombo.addItem(row.getKey());
80 keyCombo.reset();
81
82
83 model.getRows().remove(rowIndex);
84
85
86 tableModel.fireTableRowsDeleted(rowIndex, rowIndex);
87
88 model.removeRowInError(row);
89
90 }
91
92 }