1 package fr.ifremer.quadrige2.ui.swing.common.table.action;
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 fr.ifremer.quadrige2.ui.swing.common.table.AbstractTableUIHandler;
28
29 import java.awt.event.ActionEvent;
30
31
32
33
34
35
36 public class NextCellSelectionAction extends AbstractCellSelectionAction {
37
38
39
40
41
42
43
44 public NextCellSelectionAction(String name, AbstractTableUIHandler handler) {
45 super(name, handler);
46 }
47
48
49 @Override
50 public void actionPerformed(ActionEvent e) {
51
52 int currentRow = getSelectedRow();
53 int currentColumn = getSelectedColumn();
54
55 boolean canSelect = !isTableEditing();
56 do {
57
58 currentColumn = getNextColumn(currentColumn);
59
60 if (currentColumn >= getColumnCount()) {
61
62
63 currentColumn = getNextColumn(-1);
64 currentRow++;
65
66 if (currentRow == getRowCount()) {
67
68 if (isCreateNewRow()) {
69
70
71 addNewRow();
72 canSelect = true;
73 } else {
74 canSelect = false;
75 }
76 }
77 }
78
79
80 if (isTableEditing() && isCellEditable(currentRow, currentColumn)) {
81 canSelect = true;
82 }
83
84 } while (!canSelect && currentRow < getRowCount());
85
86 if (canSelect) {
87 if (isTableEditing()) {
88 editCell(currentRow, currentColumn);
89 } else {
90 selectCell(currentRow, currentColumn);
91 }
92 } else {
93 selectNextComponent();
94 }
95 }
96
97 }