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 PreviousCellSelectionAction extends AbstractCellSelectionAction {
37
38
39
40
41
42
43
44 public PreviousCellSelectionAction(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 = getPreviousColumn(currentColumn);
59
60 if (currentColumn < 0) {
61
62
63 currentColumn = getPreviousColumn(getColumnCount());
64 currentRow--;
65 }
66
67 if (currentRow < 0) {
68 canSelect = false;
69 }
70
71
72 if (isTableEditing() && isCellEditable(currentRow, currentColumn)) {
73 canSelect = true;
74 }
75
76 } while (!canSelect && currentRow >= 0);
77
78 if (canSelect) {
79 if (isTableEditing()) {
80 editCell(currentRow, currentColumn);
81 } else {
82 selectCell(currentRow, currentColumn);
83 }
84 } else {
85 selectPreviousComponent();
86 }
87 }
88 }