83 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
83 |
ilm |
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.sql.sqlobject;
|
|
|
15 |
|
156 |
ilm |
16 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
17 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
18 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
19 |
import org.openconcerto.sql.model.Where;
|
|
|
20 |
import org.openconcerto.utils.cc.ITransformer;
|
|
|
21 |
|
83 |
ilm |
22 |
import java.awt.Component;
|
94 |
ilm |
23 |
import java.awt.event.KeyAdapter;
|
|
|
24 |
import java.awt.event.KeyEvent;
|
83 |
ilm |
25 |
|
|
|
26 |
import javax.swing.AbstractCellEditor;
|
94 |
ilm |
27 |
import javax.swing.BorderFactory;
|
83 |
ilm |
28 |
import javax.swing.JTable;
|
|
|
29 |
import javax.swing.SwingUtilities;
|
|
|
30 |
import javax.swing.table.TableCellEditor;
|
|
|
31 |
|
|
|
32 |
public class ITextArticleWithCompletionCellEditor extends AbstractCellEditor implements TableCellEditor {
|
|
|
33 |
|
|
|
34 |
private final ITextArticleWithCompletion text;
|
94 |
ilm |
35 |
private boolean listenersInited = false;
|
83 |
ilm |
36 |
|
182 |
ilm |
37 |
public ITextArticleWithCompletionCellEditor(SQLTable tableArticle, SQLTable tableARticleFournisseur, boolean withDeclinaison) {
|
|
|
38 |
this.text = new ITextArticleWithCompletion(tableArticle, tableARticleFournisseur,withDeclinaison);
|
94 |
ilm |
39 |
this.text.setBorder(BorderFactory.createEmptyBorder());
|
156 |
ilm |
40 |
this.text.getTextComp().setBorder(BorderFactory.createEmptyBorder());
|
83 |
ilm |
41 |
}
|
|
|
42 |
|
94 |
ilm |
43 |
private void initListener(final JTable t) {
|
|
|
44 |
if (!this.listenersInited) {
|
|
|
45 |
this.listenersInited = true;
|
|
|
46 |
this.text.getTextComp().addKeyListener(new KeyAdapter() {
|
|
|
47 |
@Override
|
|
|
48 |
public void keyPressed(KeyEvent e) {
|
|
|
49 |
if (e.getKeyCode() == KeyEvent.VK_TAB) {
|
|
|
50 |
final int column;
|
|
|
51 |
final int row = t.getEditingRow();
|
|
|
52 |
|
|
|
53 |
// gestion tab ou shift+tab
|
|
|
54 |
if (e.getModifiers() == KeyEvent.SHIFT_MASK) {
|
|
|
55 |
column = t.getEditingColumn() - 1;
|
|
|
56 |
} else {
|
|
|
57 |
column = t.getEditingColumn() + 1;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
61 |
|
|
|
62 |
public void run() {
|
|
|
63 |
if (t.getCellEditor() != null && t.getCellEditor().stopCellEditing()) {
|
|
|
64 |
if (column >= 0 && column < t.getColumnCount()) {
|
|
|
65 |
t.setColumnSelectionInterval(column, column);
|
|
|
66 |
t.setRowSelectionInterval(row, row);
|
|
|
67 |
// Need to postpone editCell because selection with
|
|
|
68 |
// cancel
|
|
|
69 |
// selection
|
|
|
70 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
71 |
|
|
|
72 |
public void run() {
|
|
|
73 |
if (t.editCellAt(row, column)) {
|
|
|
74 |
t.getEditorComponent().requestFocusInWindow();
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
});
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
});
|
|
|
82 |
|
|
|
83 |
} else {
|
|
|
84 |
if (e.getKeyCode() == KeyEvent.VK_SPACE && e.getModifiers() == KeyEvent.SHIFT_MASK) {
|
|
|
85 |
e.setModifiers(0);
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
});
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
83 |
ilm |
93 |
@Override
|
|
|
94 |
public Object getCellEditorValue() {
|
|
|
95 |
return this.text.getText();
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
@Override
|
|
|
99 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
|
|
|
100 |
|
94 |
ilm |
101 |
initListener(table);
|
83 |
ilm |
102 |
if (value != null) {
|
|
|
103 |
this.text.setText((String) value);
|
|
|
104 |
} else {
|
|
|
105 |
this.text.setText("");
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
Runnable r = new Runnable() {
|
|
|
109 |
|
|
|
110 |
public void run() {
|
|
|
111 |
text.getTextComp().grabFocus();
|
|
|
112 |
}
|
|
|
113 |
};
|
|
|
114 |
SwingUtilities.invokeLater(r);
|
|
|
115 |
|
|
|
116 |
return this.text;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
public void addSelectionListener(SelectionRowListener l) {
|
|
|
120 |
this.text.addSelectionListener(l);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
public SQLRowAccessor getComboSelectedRow() {
|
|
|
124 |
return this.text.getSelectedRow();
|
|
|
125 |
}
|
94 |
ilm |
126 |
|
132 |
ilm |
127 |
public void setSelectTransformer(ITransformer<SQLSelect, SQLSelect> selTrans) {
|
|
|
128 |
this.text.setSelectTransformer(selTrans);
|
|
|
129 |
}
|
|
|
130 |
|
94 |
ilm |
131 |
public void setWhere(Where w) {
|
|
|
132 |
this.text.setWhere(w);
|
|
|
133 |
}
|
83 |
ilm |
134 |
}
|