OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 182
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.sql.view.list;
14
 package org.openconcerto.sql.view.list;
15
 
15
 
16
import org.openconcerto.sql.Configuration;
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.model.SQLField;
17
import org.openconcerto.sql.model.SQLField;
18
import org.openconcerto.sql.model.SQLRow;
18
import org.openconcerto.sql.model.SQLRow;
19
import org.openconcerto.sql.model.SQLRowAccessor;
19
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.model.SQLRowValues;
20
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.model.SQLSelect;
21
import org.openconcerto.sql.model.SQLSelect;
22
import org.openconcerto.sql.model.Where;
22
import org.openconcerto.sql.model.Where;
23
import org.openconcerto.sql.request.ComboSQLRequest;
23
import org.openconcerto.sql.request.ComboSQLRequest;
24
import org.openconcerto.sql.sqlobject.ITextArticleWithCompletionCellEditor;
24
import org.openconcerto.sql.sqlobject.ITextArticleWithCompletionCellEditor;
25
import org.openconcerto.sql.sqlobject.ITextWithCompletion;
25
import org.openconcerto.sql.sqlobject.ITextWithCompletion;
26
import org.openconcerto.sql.sqlobject.SelectionListener;
26
import org.openconcerto.sql.sqlobject.SelectionListener;
27
import org.openconcerto.sql.sqlobject.SelectionRowListener;
27
import org.openconcerto.sql.sqlobject.SelectionRowListener;
28
import org.openconcerto.ui.TextAreaRenderer;
28
import org.openconcerto.ui.TextAreaRenderer;
29
import org.openconcerto.utils.cc.ITransformer;
29
import org.openconcerto.utils.cc.ITransformer;
30
 
30
 
31
import java.beans.PropertyChangeEvent;
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyChangeListener;
32
import java.beans.PropertyChangeListener;
33
import java.sql.Types;
33
import java.sql.Types;
34
import java.util.HashMap;
34
import java.util.HashMap;
35
import java.util.Iterator;
35
import java.util.Iterator;
36
import java.util.LinkedHashMap;
36
import java.util.LinkedHashMap;
37
import java.util.List;
37
import java.util.List;
38
import java.util.Set;
38
import java.util.Set;
39
import java.util.Vector;
39
import java.util.Vector;
40
 
40
 
41
import javax.swing.SwingUtilities;
41
import javax.swing.SwingUtilities;
42
import javax.swing.event.CellEditorListener;
42
import javax.swing.event.CellEditorListener;
43
import javax.swing.event.ChangeEvent;
43
import javax.swing.event.ChangeEvent;
44
import javax.swing.table.TableCellEditor;
44
import javax.swing.table.TableCellEditor;
45
 
45
 
46
public class AutoCompletionManager implements SelectionRowListener, SelectionListener {
46
public class AutoCompletionManager implements SelectionRowListener, SelectionListener {
47
 
47
 
48
    private SQLTableElement fromTableElement;
48
    private SQLTableElement fromTableElement;
49
    private RowValuesTable table;
49
    private RowValuesTable table;
50
    private TextTableCellEditorWithCompletion editor;
50
    private TextTableCellEditorWithCompletion editor;
51
    private int lastSelectedComboId = 1;
51
    private int lastSelectedComboId = 1;
52
    protected boolean optOk, foreign;
52
    protected boolean optOk, foreign;
53
    protected boolean disableCompletion;
53
    protected boolean disableCompletion;
54
 
54
 
55
    private SQLField fillFrom;
55
    private SQLField fillFrom;
56
    private RowValuesTableModel tableModel;
56
    private RowValuesTableModel tableModel;
57
    ITextWithCompletion t;
57
    ITextWithCompletion t;
58
    SQLTextComboTableCellEditor textComboCellEdit;
58
    SQLTextComboTableCellEditor textComboCellEdit;
59
 
59
 
60
    public AutoCompletionManager(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel) {
60
    public AutoCompletionManager(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel) {
61
        this(fromTableElement, fillFrom, table, tableModel, ITextWithCompletion.MODE_CONTAINS, false);
61
        this(fromTableElement, fillFrom, table, tableModel, ITextWithCompletion.MODE_CONTAINS, false);
62
    }
62
    }
63
 
63
 
64
    // FIXME Le validstatechecker est à passer au SQLTableElement
64
    // FIXME Le validstatechecker est à passer au SQLTableElement
65
    public AutoCompletionManager(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, boolean expandWithShowAs,
65
    public AutoCompletionManager(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, boolean expandWithShowAs,
66
            boolean foreign, ValidStateChecker checker) {
66
            boolean foreign, ValidStateChecker checker) {
67
 
67
 
68
        this.foreign = foreign;
68
        this.foreign = foreign;
69
        List<String> l = new Vector<String>();
69
        List<String> l = new Vector<String>();
70
 
70
 
71
        if (expandWithShowAs) {
71
        if (expandWithShowAs) {
72
            List<SQLField> lSQLFields = Configuration.getInstance().getShowAs().getFieldExpand(fillFrom.getTable());
72
            List<SQLField> lSQLFields = Configuration.getInstance().getShowAs().getFieldExpand(fillFrom.getTable());
73
            for (int i = 0; i < lSQLFields.size(); i++) {
73
            for (int i = 0; i < lSQLFields.size(); i++) {
74
                l.add(lSQLFields.get(i).getName());
74
                l.add(lSQLFields.get(i).getName());
75
            }
75
            }
76
        } else {
76
        } else {
77
            l.add(fillFrom.getName());
77
            l.add(fillFrom.getName());
78
        }
78
        }
79
        ComboSQLRequest req = new ComboSQLRequest(fillFrom.getTable(), l);
79
        ComboSQLRequest req = new ComboSQLRequest(fillFrom.getTable(), l);
80
        init(fromTableElement, fillFrom, table, tableModel, modeCompletion, req, foreign, checker);
80
        init(fromTableElement, fillFrom, table, tableModel, modeCompletion, req, foreign, checker);
81
 
81
 
82
    }
82
    }
83
 
83
 
84
    public AutoCompletionManager(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, boolean expandWithShowAs) {
84
    public AutoCompletionManager(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, boolean expandWithShowAs) {
85
        this(fromTableElement, fillFrom, table, tableModel, modeCompletion, expandWithShowAs, false, new ValidStateChecker());
85
        this(fromTableElement, fillFrom, table, tableModel, modeCompletion, expandWithShowAs, false, new ValidStateChecker());
86
    }
86
    }
87
 
87
 
88
    public AutoCompletionManager(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, ComboSQLRequest req) {
88
    public AutoCompletionManager(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, ComboSQLRequest req) {
89
        init(fromTableElement, fillFrom, table, tableModel, modeCompletion, req, false);
89
        init(fromTableElement, fillFrom, table, tableModel, modeCompletion, req, false);
90
    }
90
    }
91
 
91
 
92
    public void init(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, ComboSQLRequest req, boolean foreign) {
92
    public void init(SQLTableElement fromTableElement, SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, ComboSQLRequest req, boolean foreign) {
93
        init(fromTableElement, fillFrom, table, tableModel, modeCompletion, req, foreign, new ValidStateChecker());
93
        init(fromTableElement, fillFrom, table, tableModel, modeCompletion, req, foreign, new ValidStateChecker());
94
    }
94
    }
95
 
95
 
96
    private ITextArticleWithCompletionCellEditor articleCombo;
96
    private ITextArticleWithCompletionCellEditor articleCombo;
97
 
97
 
98
    public void init(final SQLTableElement fromTableElement, final SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, ComboSQLRequest req, boolean foreign,
98
    public void init(final SQLTableElement fromTableElement, final SQLField fillFrom, RowValuesTable table, RowValuesTableModel tableModel, int modeCompletion, ComboSQLRequest req, boolean foreign,
99
            ValidStateChecker validStateChecker) {
99
            ValidStateChecker validStateChecker) {
100
 
100
 
101
        this.tableModel = tableModel;
101
        this.tableModel = tableModel;
102
        this.fromTableElement = fromTableElement;
102
        this.fromTableElement = fromTableElement;
103
 
103
 
104
        this.fillFrom = fillFrom;
104
        this.fillFrom = fillFrom;
105
 
105
 
106
        this.table = table;
106
        this.table = table;
107
 
107
 
108
        TableCellEditor cellEdit = this.fromTableElement.getTableCellEditor(table);
108
        TableCellEditor cellEdit = this.fromTableElement.getTableCellEditor(table);
109
        if (foreign) {
109
        if (foreign) {
110
            if (cellEdit instanceof SQLTextComboTableCellEditor) {
110
            if (cellEdit instanceof SQLTextComboTableCellEditor) {
111
                this.textComboCellEdit = (SQLTextComboTableCellEditor) cellEdit;
111
                this.textComboCellEdit = (SQLTextComboTableCellEditor) cellEdit;
112
                textComboCellEdit.addSelectionListener(new PropertyChangeListener() {
112
                textComboCellEdit.addSelectionListener(new PropertyChangeListener() {
113
 
113
 
114
                    @Override
114
                    @Override
115
                    public void propertyChange(PropertyChangeEvent evt) {
115
                    public void propertyChange(PropertyChangeEvent evt) {
116
 
116
 
117
                        int i = textComboCellEdit.getComboSelectedId();
117
                        int i = textComboCellEdit.getComboSelectedId();
118
                        if (AutoCompletionManager.this.lastSelectedComboId != i) {
118
                        if (AutoCompletionManager.this.lastSelectedComboId != i) {
119
                            if (fromTableElement.getField().getForeignTable().equals(fillFrom.getTable())) {
119
                            if (fromTableElement.getField().getForeignTable().equals(fillFrom.getTable())) {
120
                                idSelected(i, null);
120
                                idSelected(i, null);
121
                            } else {
121
                            } else {
122
                                int selectedID = SQLRow.NONEXISTANT_ID;
122
                                int selectedID = SQLRow.NONEXISTANT_ID;
123
                                final SQLRow selectedRow = textComboCellEdit.getCombo().getSelectedRow();
123
                                final SQLRow selectedRow = textComboCellEdit.getCombo().getSelectedRow();
124
                                if (selectedRow != null) {
124
                                if (selectedRow != null) {
125
                                    selectedID = selectedRow.getForeignRow("ID_" + fillFrom.getTable().getName()).getID();
125
                                    selectedID = selectedRow.getForeignRow("ID_" + fillFrom.getTable().getName()).getID();
126
                                }
126
                                }
127
                                idSelected(selectedID, null);
127
                                idSelected(selectedID, null);
128
                            }
128
                            }
129
                        }
129
                        }
130
                        AutoCompletionManager.this.lastSelectedComboId = i;
130
                        AutoCompletionManager.this.lastSelectedComboId = i;
131
                        System.err.println("editing stopped");
131
                        System.err.println("editing stopped");
132
                    }
132
                    }
133
                });
133
                });
134
 
134
 
135
                textComboCellEdit.addCellEditorListener(new CellEditorListener() {
135
                textComboCellEdit.addCellEditorListener(new CellEditorListener() {
136
                    @Override
136
                    @Override
137
                    public void editingCanceled(ChangeEvent e) {
137
                    public void editingCanceled(ChangeEvent e) {
138
                        AutoCompletionManager.this.lastSelectedComboId = textComboCellEdit.getComboSelectedId();
138
                        AutoCompletionManager.this.lastSelectedComboId = textComboCellEdit.getComboSelectedId();
139
                    }
139
                    }
140
 
140
 
141
                    @Override
141
                    @Override
142
                    public void editingStopped(ChangeEvent e) {
142
                    public void editingStopped(ChangeEvent e) {
143
                        AutoCompletionManager.this.lastSelectedComboId = textComboCellEdit.getComboSelectedId();
143
                        AutoCompletionManager.this.lastSelectedComboId = textComboCellEdit.getComboSelectedId();
144
                    }
144
                    }
145
                });
145
                });
146
 
146
 
147
            }
147
            }
148
        } else if (cellEdit instanceof ITextArticleWithCompletionCellEditor) {
148
        } else if (cellEdit instanceof ITextArticleWithCompletionCellEditor) {
149
            this.articleCombo = (ITextArticleWithCompletionCellEditor) cellEdit;
149
            this.articleCombo = (ITextArticleWithCompletionCellEditor) cellEdit;
150
            this.articleCombo.addSelectionListener(this);
150
            this.articleCombo.addSelectionListener(this);
151
        } else {
151
        } else {
152
 
152
 
153
            this.t = new ITextWithCompletion(req, true);
153
            this.t = new ITextWithCompletion(req, true);
154
            this.t.setModeCompletion(modeCompletion);
154
            this.t.setModeCompletion(modeCompletion);
155
            this.editor = new TextTableCellEditorWithCompletion(table, this.t, validStateChecker);
155
            this.editor = new TextTableCellEditorWithCompletion(table, this.t, validStateChecker);
156
 
156
 
157
            if (this.fillFrom.getType().getType() == Types.VARCHAR) {
157
            if (this.fillFrom.getType().getType() == Types.VARCHAR) {
158
                this.t.setLimitedSize(this.fillFrom.getType().getSize());
158
                this.t.setLimitedSize(this.fillFrom.getType().getSize());
159
                this.editor.setLimitedSize(this.fillFrom.getType().getSize());
159
                this.editor.setLimitedSize(this.fillFrom.getType().getSize());
160
            }
160
            }
161
 
161
 
162
            this.fromTableElement.setEditor(this.editor);
162
            this.fromTableElement.setEditor(this.editor);
163
            this.fromTableElement.setRenderer(new TextAreaRenderer());
163
            this.fromTableElement.setRenderer(new TextAreaRenderer());
164
 
164
 
165
            this.t.addSelectionListener(this);
165
            this.t.addSelectionListener(this);
166
        }
166
        }
167
    }
167
    }
168
 
168
 
169
    private HashMap<String, String> fillBy = new LinkedHashMap<String, String>();
169
    private HashMap<String, String> fillBy = new LinkedHashMap<String, String>();
170
    private int lastId = -1;
170
    private int lastId = -1;
171
    private int lastEditingRow = -1;
171
    private int lastEditingRow = -1;
172
 
172
 
173
    public void fill(String string, String string2) {
173
    public void fill(String string, String string2) {
174
        this.fillBy.put(string, string2);
174
        this.fillBy.put(string, string2);
175
 
175
 
176
    }
176
    }
177
 
177
 
178
    public void idSelected(int id, Object source) {
178
    public void idSelected(int id, Object source) {
179
 
179
 
180
        // Le Text correspond a un id
180
        // Le Text correspond a un id
181
        final int rowE = this.table.getEditingRow();
181
        final int rowE = this.table.getEditingRow();
182
        if (rowE < 0) {
182
        if (rowE < 0) {
183
            this.lastEditingRow = rowE;
183
            this.lastEditingRow = rowE;
184
            return;
184
            return;
185
        }
185
        }
186
 
186
 
187
        if (this.lastEditingRow == rowE && this.lastId == id) {
187
        if (this.lastEditingRow == rowE && this.lastId == id) {
188
            // Evite de reremplir si l'on reselectionne le meme id sur la meme ligne
188
            // Evite de reremplir si l'on reselectionne le meme id sur la meme ligne
189
            return;
189
            return;
190
        }
190
        }
191
        if (id > 1) {
191
        if (id > 1) {
192
            this.lastId = id;
192
            this.lastId = id;
193
            this.lastEditingRow = rowE;
193
            this.lastEditingRow = rowE;
194
 
194
 
195
            // On arrete l'edition nous meme pour eviter qu'un click externe fasse un cancelEditing
195
            // On arrete l'edition nous meme pour eviter qu'un click externe fasse un cancelEditing
196
            if (this.table.getCellEditor() != null && !this.foreign) {
196
            if (this.table.getCellEditor() != null && !this.foreign) {
197
                this.table.getCellEditor().stopCellEditing();
197
                this.table.getCellEditor().stopCellEditing();
198
            }
198
            }
199
 
199
 
200
            fillWithSelection(null, id, rowE);
200
            fillWithSelection(null, id, rowE);
201
        }
201
        }
202
    }
202
    }
203
 
203
 
204
    @Override
204
    @Override
205
    public void rowSelected(SQLRowAccessor row, Object source) {
205
    public void rowSelected(SQLRowAccessor row, Object source) {
206
        final int rowE = this.table.getEditingRow();
206
        final int rowE = this.table.getEditingRow();
207
        if (rowE < 0 || row == null) {
207
        if (rowE < 0 || row == null) {
208
            this.lastEditingRow = rowE;
208
            this.lastEditingRow = rowE;
209
            return;
209
            return;
210
        }
210
        }
211
 
211
 
212
        this.lastEditingRow = rowE;
212
        this.lastEditingRow = rowE;
213
 
213
 
214
        // On arrete l'edition nous meme pour eviter qu'un click externe fasse un cancelEditing
214
        // On arrete l'edition nous meme pour eviter qu'un click externe fasse un cancelEditing
215
        if (this.table.getCellEditor() != null && !this.foreign) {
215
        if (this.table.getCellEditor() != null && !this.foreign) {
216
            this.table.getCellEditor().stopCellEditing();
216
            this.table.getCellEditor().stopCellEditing();
217
        }
217
        }
218
        fillWithSelection(row, SQLRow.NONEXISTANT_ID, rowE);
218
        fillWithSelection(row, SQLRow.NONEXISTANT_ID, rowE);
219
    }
219
    }
220
 
220
 
221
    private void fillWithSelection(final SQLRowAccessor r, final int id, final int rowE) {
221
    private void fillWithSelection(final SQLRowAccessor r, final int id, final int rowE) {
222
 
222
 
223
        final SQLRowAccessor rowDest = (rowE >= 0 && rowE <= this.table.getRowCount()) ? this.table.getRowValuesTableModel().getRowValuesAt(rowE) : null;
223
        final SQLRowAccessor rowDest = (rowE >= 0 && rowE <= this.table.getRowCount()) ? this.table.getRowValuesTableModel().getRowValuesAt(rowE) : null;
224
 
224
 
225
        new Thread(new Runnable() {
225
        new Thread(new Runnable() {
226
            public void run() {
226
            public void run() {
227
                // final SQLRowValues rowV = new
227
                // final SQLRowValues rowV = new
228
                // SQLRowValues(AutoCompletionManager.this.fillFrom.getTable());
228
                // SQLRowValues(AutoCompletionManager.this.fillFrom.getTable());
229
                final SQLRow rowV;
229
                final SQLRow rowV;
230
                if (r != null) {
230
                if (r != null) {
231
                    rowV = r.asRow();
231
                    rowV = r.fetchNewRow(false);
232
                } else {
232
                } else {
233
                    rowV = AutoCompletionManager.this.fillFrom.getTable().getRow(id);
233
                    rowV = AutoCompletionManager.this.fillFrom.getTable().getRow(id);
234
                }
234
                }
235
                // Test pour éviter de perdre la sélection d'un article ayant la même désignation
235
                // Test pour éviter de perdre la sélection d'un article ayant la même désignation
236
                // mais un code différent (Problème remonté par Afhymat avec la tabulation)
236
                // mais un code différent (Problème remonté par Afhymat avec la tabulation)
237
                if (fillFrom != null && fillFrom.getTable().getName().equals("ARTICLE") && fillFrom.getName().equals("NOM") && rowDest != null && !rowDest.isUndefined()) {
237
                if (fillFrom != null && fillFrom.getTable().getName().equals("ARTICLE") && fillFrom.getName().equals("NOM") && rowDest != null && !rowDest.isUndefined()) {
238
                    SQLRowAccessor rowArt = rowDest.getForeign("ID_ARTICLE");
238
                    SQLRowAccessor rowArt = rowDest.getForeign("ID_ARTICLE");
239
                    if (rowArt != null && !rowArt.isUndefined() && rowArt.getString("NOM") != null && rowArt.getString("NOM").trim().equalsIgnoreCase(rowV.getString("NOM").trim())) {
239
                    if (rowArt != null && !rowArt.isUndefined() && rowArt.getString("NOM") != null && rowArt.getString("NOM").trim().equalsIgnoreCase(rowV.getString("NOM").trim())) {
240
                        return;
240
                        return;
241
                    }
241
                    }
242
                }
242
                }
243
 
243
 
244
                final Set<String> keys = AutoCompletionManager.this.fillBy.keySet();
244
                final Set<String> keys = AutoCompletionManager.this.fillBy.keySet();
245
                // Fill the table model rowvalue with the selected item using the fields defined
245
                // Fill the table model rowvalue with the selected item using the fields defined
246
                // with 'fill'
246
                // with 'fill'
247
 
247
 
248
                SwingUtilities.invokeLater(new Runnable() {
248
                SwingUtilities.invokeLater(new Runnable() {
249
                    public void run() {
249
                    public void run() {
250
                        for (Iterator<String> iter = keys.iterator(); iter.hasNext();) {
250
                        for (Iterator<String> iter = keys.iterator(); iter.hasNext();) {
251
                            String from = iter.next();
251
                            String from = iter.next();
252
                            String to = AutoCompletionManager.this.fillBy.get(from);
252
                            String to = AutoCompletionManager.this.fillBy.get(from);
253
                            Object fromV = getValueFrom(rowV, from, rowDest);
253
                            Object fromV = getValueFrom(rowV, from, rowDest);
254
                            int column = AutoCompletionManager.this.tableModel.getColumnForField(to);
254
                            int column = AutoCompletionManager.this.tableModel.getColumnForField(to);
255
                            if (column >= 0) {
255
                            if (column >= 0) {
256
 
256
 
257
                                // Request focus
257
                                // Request focus
258
                                if (AutoCompletionManager.this.table.getRowValuesTableModel().getValueAt(rowE, column) == null
258
                                if (AutoCompletionManager.this.table.getRowValuesTableModel().getValueAt(rowE, column) == null
259
                                        || !AutoCompletionManager.this.table.getRowValuesTableModel().getValueAt(rowE, column).equals(fromV)) {
259
                                        || !AutoCompletionManager.this.table.getRowValuesTableModel().getValueAt(rowE, column).equals(fromV)) {
260
                                    AutoCompletionManager.this.table.getRowValuesTableModel().setValueAt(fromV, rowE, column);
260
                                    AutoCompletionManager.this.table.getRowValuesTableModel().setValueAt(fromV, rowE, column);
261
                                    // Test Only if not foreign --> Bug avec le
261
                                    // Test Only if not foreign --> Bug avec le
262
                                    // sqltextcombocelleditor, si test edit cellAt -> fire
262
                                    // sqltextcombocelleditor, si test edit cellAt -> fire
263
                                    // idSelected
263
                                    // idSelected
264
                                    // -1 sur la combo ce qui entraine une déselection (Bug Remonté
264
                                    // -1 sur la combo ce qui entraine une déselection (Bug Remonté
265
                                    // par SA Poulignier)
265
                                    // par SA Poulignier)
266
                                    if (!AutoCompletionManager.this.foreign && AutoCompletionManager.this.table.getEditingColumn() == column
266
                                    if (!AutoCompletionManager.this.foreign && AutoCompletionManager.this.table.getEditingColumn() == column
267
                                            && AutoCompletionManager.this.table.getEditingRow() == rowE) {
267
                                            && AutoCompletionManager.this.table.getEditingRow() == rowE) {
268
                                        AutoCompletionManager.this.table.editingCanceled(null);
268
                                        AutoCompletionManager.this.table.editingCanceled(null);
269
                                        AutoCompletionManager.this.table.setColumnSelectionInterval(column, column);
269
                                        AutoCompletionManager.this.table.setColumnSelectionInterval(column, column);
270
                                        AutoCompletionManager.this.table.setRowSelectionInterval(rowE, rowE);
270
                                        AutoCompletionManager.this.table.setRowSelectionInterval(rowE, rowE);
271
                                        if (AutoCompletionManager.this.table.editCellAt(rowE, column)) {
271
                                        if (AutoCompletionManager.this.table.editCellAt(rowE, column)) {
272
                                            if (AutoCompletionManager.this.table.getEditorComponent() != null) {
272
                                            if (AutoCompletionManager.this.table.getEditorComponent() != null) {
273
                                                AutoCompletionManager.this.table.getEditorComponent().requestFocusInWindow();
273
                                                AutoCompletionManager.this.table.getEditorComponent().requestFocusInWindow();
274
                                            }
274
                                            }
275
                                        }
275
                                        }
276
                                    }
276
                                    }
277
                                }
277
                                }
278
                            } else {
278
                            } else {
279
                                // Not in the table
279
                                // Not in the table
280
                                AutoCompletionManager.this.table.getRowValuesTableModel().putValue(fromV, rowE, to);
280
                                AutoCompletionManager.this.table.getRowValuesTableModel().putValue(fromV, rowE, to);
281
                            }
281
                            }
282
                        }
282
                        }
283
 
283
 
284
                        AutoCompletionManager.this.table.resizeAndRepaint();
284
                        AutoCompletionManager.this.table.resizeAndRepaint();
285
                    }
285
                    }
286
                });
286
                });
287
            }
287
            }
288
        }).start();
288
        }).start();
289
    }
289
    }
290
 
290
 
291
    public Set<String> getFieldsFrom() {
291
    public Set<String> getFieldsFrom() {
292
        return this.fillBy.keySet();
292
        return this.fillBy.keySet();
293
    }
293
    }
-
 
294
 
-
 
295
    public String getToField(String fromField) {
-
 
296
        return this.fillBy.get(fromField);
-
 
297
    }
294
 
298
 
295
    public void fillRowValues(SQLRowAccessor from, Set<String> fields, SQLRowValues to) {
299
    public void fillRowValues(SQLRowAccessor from, Set<String> fields, SQLRowValues to) {
296
        for (String fromField : fields) {
300
        for (String fromField : fields) {
297
            String toField = AutoCompletionManager.this.fillBy.get(fromField);
301
            String toField = AutoCompletionManager.this.fillBy.get(fromField);
298
            to.put(toField, getValueFrom(from.asRow(), fromField, to));
302
            to.put(toField, getValueFrom(from.asRow(), fromField, to));
299
        }
303
        }
300
    }
304
    }
301
 
305
 
302
    protected Object getValueFrom(SQLRow row, String field, SQLRowAccessor rowDest) {
306
    protected Object getValueFrom(SQLRow row, String field, SQLRowAccessor rowDest) {
303
        return row.getObject(field);
307
        return row.getObject(field);
304
    }
308
    }
305
 
309
 
306
    public void setSelectTransformer(ITransformer<SQLSelect, SQLSelect> selTrans) {
310
    public void setSelectTransformer(ITransformer<SQLSelect, SQLSelect> selTrans) {
307
        if (this.t != null) {
311
        if (this.t != null) {
308
            this.t.setSelectTransformer(selTrans);
312
            this.t.setSelectTransformer(selTrans);
309
        } else if (this.textComboCellEdit != null) {
313
        } else if (this.textComboCellEdit != null) {
310
            this.textComboCellEdit.setSelectTransformer(selTrans);
314
            this.textComboCellEdit.setSelectTransformer(selTrans);
311
        } else if (this.articleCombo != null) {
315
        } else if (this.articleCombo != null) {
312
            this.articleCombo.setSelectTransformer(selTrans);
316
            this.articleCombo.setSelectTransformer(selTrans);
313
        }
317
        }
314
    }
318
    }
315
 
319
 
316
    public void setWhere(Where w) {
320
    public void setWhere(Where w) {
317
        if (this.t != null) {
321
        if (this.t != null) {
318
            this.t.setWhere(w);
322
            this.t.setWhere(w);
319
        } else if (this.textComboCellEdit != null) {
323
        } else if (this.textComboCellEdit != null) {
320
            this.textComboCellEdit.setWhere(w);
324
            this.textComboCellEdit.setWhere(w);
321
        } else if (this.articleCombo != null) {
325
        } else if (this.articleCombo != null) {
322
            this.articleCombo.setWhere(w);
326
            this.articleCombo.setWhere(w);
323
        }
327
        }
324
    }
328
    }
325
 
329
 
326
    public void setFillWithField(String s) {
330
    public void setFillWithField(String s) {
327
        this.t.setFillWithField(s);
331
        this.t.setFillWithField(s);
328
    }
332
    }
329
}
333
}