OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 Rev 180
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 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.sqlobject;
14
 package org.openconcerto.sql.sqlobject;
15
 
15
 
16
import org.openconcerto.sql.model.SQLField;
16
import org.openconcerto.sql.model.SQLField;
17
import org.openconcerto.sql.model.SQLRow;
17
import org.openconcerto.sql.model.SQLRow;
18
import org.openconcerto.sql.model.SQLRowAccessor;
18
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
19
import org.openconcerto.sql.model.SQLRowValues;
-
 
20
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
19
import org.openconcerto.sql.model.SQLSelect;
21
import org.openconcerto.sql.model.SQLSelect;
20
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.sql.model.SQLTable;
21
import org.openconcerto.sql.model.Where;
23
import org.openconcerto.sql.model.Where;
22
import org.openconcerto.sql.request.MultipleSQLSelectExecutor;
24
import org.openconcerto.sql.request.MultipleSQLSelectExecutor;
23
import org.openconcerto.ui.component.text.TextComponent;
25
import org.openconcerto.ui.component.text.TextComponent;
24
import org.openconcerto.utils.CompareUtils;
26
import org.openconcerto.utils.CompareUtils;
25
import org.openconcerto.utils.OrderedSet;
27
import org.openconcerto.utils.OrderedSet;
26
import org.openconcerto.utils.cc.ITransformer;
28
import org.openconcerto.utils.cc.ITransformer;
27
import org.openconcerto.utils.checks.MutableValueObject;
29
import org.openconcerto.utils.checks.MutableValueObject;
28
import org.openconcerto.utils.model.DefaultIMutableListModel;
30
import org.openconcerto.utils.model.DefaultIMutableListModel;
29
import org.openconcerto.utils.text.DocumentFilterList;
31
import org.openconcerto.utils.text.DocumentFilterList;
30
import org.openconcerto.utils.text.DocumentFilterList.FilterType;
32
import org.openconcerto.utils.text.DocumentFilterList.FilterType;
31
import org.openconcerto.utils.text.LimitedSizeDocumentFilter;
33
import org.openconcerto.utils.text.LimitedSizeDocumentFilter;
32
 
34
 
33
import java.awt.Component;
35
import java.awt.Component;
34
import java.awt.GridLayout;
36
import java.awt.GridLayout;
35
import java.awt.event.ComponentEvent;
37
import java.awt.event.ComponentEvent;
36
import java.awt.event.ComponentListener;
38
import java.awt.event.ComponentListener;
37
import java.awt.event.FocusEvent;
39
import java.awt.event.FocusEvent;
38
import java.awt.event.FocusListener;
40
import java.awt.event.FocusListener;
39
import java.awt.event.KeyEvent;
41
import java.awt.event.KeyEvent;
40
import java.awt.event.KeyListener;
42
import java.awt.event.KeyListener;
41
import java.beans.PropertyChangeListener;
43
import java.beans.PropertyChangeListener;
42
import java.beans.PropertyChangeSupport;
44
import java.beans.PropertyChangeSupport;
43
import java.sql.SQLException;
45
import java.sql.SQLException;
44
import java.util.ArrayList;
46
import java.util.ArrayList;
45
import java.util.Iterator;
47
import java.util.Iterator;
46
import java.util.List;
48
import java.util.List;
47
import java.util.Stack;
49
import java.util.Stack;
48
import java.util.Vector;
50
import java.util.Vector;
49
 
51
 
50
import javax.swing.JComponent;
52
import javax.swing.JComponent;
51
import javax.swing.JPanel;
53
import javax.swing.JPanel;
52
import javax.swing.JTextField;
54
import javax.swing.JTextField;
53
import javax.swing.SwingUtilities;
55
import javax.swing.SwingUtilities;
54
import javax.swing.SwingWorker;
56
import javax.swing.SwingWorker;
55
import javax.swing.event.DocumentEvent;
57
import javax.swing.event.DocumentEvent;
56
import javax.swing.event.DocumentListener;
58
import javax.swing.event.DocumentListener;
57
import javax.swing.text.AbstractDocument;
59
import javax.swing.text.AbstractDocument;
58
import javax.swing.text.DocumentFilter;
60
import javax.swing.text.DocumentFilter;
59
import javax.swing.text.JTextComponent;
61
import javax.swing.text.JTextComponent;
60
 
62
 
61
public class ITextArticleWithCompletion extends JPanel implements DocumentListener, TextComponent, MutableValueObject<String>, IComboSelectionItemListener {
63
public class ITextArticleWithCompletion extends JPanel implements DocumentListener, TextComponent, MutableValueObject<String>, IComboSelectionItemListener {
62
 
64
 
63
    public static int SQL_RESULT_LIMIT = 50;
65
    public static int SQL_RESULT_LIMIT = 50;
64
 
66
 
65
    public static final int MODE_STARTWITH = 1;
67
    public static final int MODE_STARTWITH = 1;
66
    public static final int MODE_CONTAINS = 2;
68
    public static final int MODE_CONTAINS = 2;
67
 
69
 
68
    private JTextComponent text;
70
    private JTextComponent text;
69
 
71
 
70
    private DefaultIMutableListModel<IComboSelectionItem> model = new DefaultIMutableListModel<IComboSelectionItem>();
72
    private DefaultIMutableListModel<IComboSelectionItem> model = new DefaultIMutableListModel<IComboSelectionItem>();
71
 
73
 
72
    private boolean completionEnabled = true;
74
    private boolean completionEnabled = true;
73
 
75
 
74
    private SQLRowAccessor selectedRow = null;
76
    private SQLRowAccessor selectedRow = null;
75
 
77
 
76
    private boolean selectAuto = true;
78
    private boolean selectAuto = true;
77
 
79
 
78
    protected ITextWithCompletionPopUp popup;
80
    protected ITextWithCompletionPopUp popup;
79
 
81
 
80
    OrderedSet<SelectionRowListener> listeners = new OrderedSet<SelectionRowListener>();
82
    OrderedSet<SelectionRowListener> listeners = new OrderedSet<SelectionRowListener>();
81
    Component popupInvoker;
83
    Component popupInvoker;
82
 
84
 
83
    private boolean isLoading = false;
85
    private boolean isLoading = false;
84
    private SQLRowAccessor rowToSelect = null;
86
    private SQLRowAccessor rowToSelect = null;
85
 
87
 
86
    private String fillWith = "CODE";
88
    private String fillWith = "CODE";
87
    private final PropertyChangeSupport supp;
89
    private final PropertyChangeSupport supp;
88
 
90
 
89
    private final SQLTable tableArticle, tableArticleFournisseur;
91
    private final SQLTable tableArticle, tableArticleFournisseur;
90
 
92
 
91
    // Asynchronous filling
93
    // Asynchronous filling
92
    private Thread searchThread;
94
    private Thread searchThread;
93
    private int autoCheckDelay = 1000;
95
    private int autoCheckDelay = 1000;
94
    private boolean disposed = false;
96
    private boolean disposed = false;
95
    private Stack<String> searchStack = new Stack<String>();
97
    private Stack<String> searchStack = new Stack<String>();
96
    private boolean autoselectIfMatch;
98
    private boolean autoselectIfMatch;
97
    private static final int PAUSE_MS = 150;
99
    private static final int PAUSE_MS = 150;
98
 
100
 
99
    public ITextArticleWithCompletion(SQLTable tableArticle, SQLTable tableARticleFournisseur) {
101
    public ITextArticleWithCompletion(SQLTable tableArticle, SQLTable tableARticleFournisseur) {
100
        this.tableArticle = tableArticle;
102
        this.tableArticle = tableArticle;
101
        this.tableArticleFournisseur = tableARticleFournisseur;
103
        this.tableArticleFournisseur = tableARticleFournisseur;
102
        this.supp = new PropertyChangeSupport(this);
104
        this.supp = new PropertyChangeSupport(this);
103
        this.popup = new ITextWithCompletionPopUp(this.model, this);
105
        this.popup = new ITextWithCompletionPopUp(this.model, this);
104
        this.text = new JTextField();
106
        this.text = new JTextField();
105
        this.setLayout(new GridLayout(1, 1));
107
        this.setLayout(new GridLayout(1, 1));
106
        this.add(this.text);
108
        this.add(this.text);
107
        setTextEditor(this.text);
109
        setTextEditor(this.text);
108
        setPopupInvoker(this);
110
        setPopupInvoker(this);
109
 
111
 
110
        //
112
        //
111
        disposed = false;
113
        disposed = false;
112
        searchThread = new Thread() {
114
        searchThread = new Thread() {
113
            public void run() {
115
            public void run() {
114
                while (!disposed) {
116
                while (!disposed) {
115
                    if (autoCheckDelay == 0) {
117
                    if (autoCheckDelay == 0) {
116
                        autoCheckDelay = -1;
118
                        autoCheckDelay = -1;
117
                        SwingUtilities.invokeLater(new Runnable() {
119
                        SwingUtilities.invokeLater(new Runnable() {
118
                            @Override
120
                            @Override
119
                            public void run() {
121
                            public void run() {
120
                                loadAutoCompletion();
122
                                loadAutoCompletion();
121
                            }
123
                            }
122
                        });
124
                        });
123
 
125
 
124
                    } else if (autoCheckDelay > 0) {
126
                    } else if (autoCheckDelay > 0) {
125
                        autoCheckDelay -= PAUSE_MS;
127
                        autoCheckDelay -= PAUSE_MS;
126
                    }
128
                    }
127
                    try {
129
                    try {
128
                        Thread.sleep(PAUSE_MS);
130
                        Thread.sleep(PAUSE_MS);
129
                    } catch (InterruptedException e) {
131
                    } catch (InterruptedException e) {
130
                        e.printStackTrace();
132
                        e.printStackTrace();
131
                    }
133
                    }
132
                }
134
                }
133
 
135
 
134
            };
136
            };
135
        };
137
        };
136
        searchThread.setName("ITextArticleWithCompletion thread");
138
        searchThread.setName("ITextArticleWithCompletion thread");
137
        searchThread.setPriority(Thread.MIN_PRIORITY);
139
        searchThread.setPriority(Thread.MIN_PRIORITY);
138
        searchThread.setDaemon(true);
140
        searchThread.setDaemon(true);
139
        searchThread.start();
141
        searchThread.start();
140
 
142
 
141
    }
143
    }
142
 
144
 
143
    public void setPopupListEnabled(boolean b) {
145
    public void setPopupListEnabled(boolean b) {
144
        this.popup.setListEnabled(b);
146
        this.popup.setListEnabled(b);
145
    }
147
    }
146
 
148
 
147
    private Where whereAdditionnal;
149
    private Where whereAdditionnal;
148
    private ITransformer<SQLSelect, SQLSelect> selTransformer;
150
    private ITransformer<SQLSelect, SQLSelect> selTransformer;
149
 
151
 
150
    public void setWhere(Where w) {
152
    public void setWhere(Where w) {
151
        this.whereAdditionnal = w;
153
        this.whereAdditionnal = w;
152
    }
154
    }
153
 
155
 
154
    public void setSelectTransformer(ITransformer<SQLSelect, SQLSelect> selTransformer) {
156
    public void setSelectTransformer(ITransformer<SQLSelect, SQLSelect> selTransformer) {
155
        this.selTransformer = selTransformer;
157
        this.selTransformer = selTransformer;
156
    }
158
    }
157
 
159
 
158
    public void setTextEditor(final JTextComponent atext) {
160
    public void setTextEditor(final JTextComponent atext) {
159
        if (atext == null) {
161
        if (atext == null) {
160
            throw new IllegalArgumentException("null textEditor");
162
            throw new IllegalArgumentException("null textEditor");
161
        }
163
        }
162
        this.text = atext;
164
        this.text = atext;
163
        atext.getDocument().addDocumentListener(this);
165
        atext.getDocument().addDocumentListener(this);
164
        atext.addKeyListener(new KeyListener() {
166
        atext.addKeyListener(new KeyListener() {
165
 
167
 
166
            private boolean consume;
168
            private boolean consume;
167
 
169
 
168
            public void keyPressed(KeyEvent e) {
170
            public void keyPressed(KeyEvent e) {
169
                if (e.getKeyCode() == KeyEvent.VK_TAB) {
171
                if (e.getKeyCode() == KeyEvent.VK_TAB) {
170
                    // Complete si exactement la valeur souhaitée
172
                    // Complete si exactement la valeur souhaitée
171
                    updateAutoCompletion(true);
173
                    updateAutoCompletion(true);
172
                    e.consume();
174
                    e.consume();
173
 
175
 
174
                } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
176
                } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
175
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
177
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
176
                        ITextArticleWithCompletion.this.popup.selectNext();
178
                        ITextArticleWithCompletion.this.popup.selectNext();
177
                        e.consume();
179
                        e.consume();
178
                    } else {
180
                    } else {
179
                        if (getSelectedRow() == null) {
181
                        if (getSelectedRow() == null) {
180
                            // updateAutoCompletion();
182
                            // updateAutoCompletion();
181
                            showPopup();
183
                            showPopup();
182
                        }
184
                        }
183
                    }
185
                    }
184
 
186
 
185
                } else if (e.getKeyCode() == KeyEvent.VK_UP) {
187
                } else if (e.getKeyCode() == KeyEvent.VK_UP) {
186
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
188
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
187
                        ITextArticleWithCompletion.this.popup.selectPrevious();
189
                        ITextArticleWithCompletion.this.popup.selectPrevious();
188
                        e.consume();
190
                        e.consume();
189
                    }
191
                    }
190
 
192
 
191
                } else if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB) {
193
                } else if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB) {
192
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
194
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
193
                        ITextArticleWithCompletion.this.popup.validateSelection();
195
                        ITextArticleWithCompletion.this.popup.validateSelection();
194
                        e.consume();
196
                        e.consume();
195
                    } else {
197
                    } else {
196
                        autoselectIfMatch = true;
198
                        autoselectIfMatch = true;
197
                        e.consume();
199
                        e.consume();
198
                    }
200
                    }
199
                } else if (e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
201
                } else if (e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
200
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
202
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
201
                        ITextArticleWithCompletion.this.popup.selectNextPage();
203
                        ITextArticleWithCompletion.this.popup.selectNextPage();
202
                        e.consume();
204
                        e.consume();
203
                    }
205
                    }
204
                } else if (e.getKeyCode() == KeyEvent.VK_PAGE_UP) {
206
                } else if (e.getKeyCode() == KeyEvent.VK_PAGE_UP) {
205
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
207
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
206
                        ITextArticleWithCompletion.this.popup.selectPreviousPage();
208
                        ITextArticleWithCompletion.this.popup.selectPreviousPage();
207
                        e.consume();
209
                        e.consume();
208
                    }
210
                    }
209
                } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
211
                } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
210
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
212
                    if (ITextArticleWithCompletion.this.popup.isShowing()) {
211
                        hidePopup();
213
                        hidePopup();
212
                    }
214
                    }
213
 
215
 
214
                }
216
                }
215
 
217
 
216
                // else {
218
                // else {
217
                // if (e.getKeyCode() != KeyEvent.VK_RIGHT && e.getKeyCode() !=
219
                // if (e.getKeyCode() != KeyEvent.VK_RIGHT && e.getKeyCode() !=
218
                // KeyEvent.VK_LEFT) {
220
                // KeyEvent.VK_LEFT) {
219
                // fireSelectionId(-1);
221
                // fireSelectionId(-1);
220
                // }
222
                // }
221
                // }
223
                // }
222
                // Evite les bips
224
                // Evite les bips
223
                if (ITextArticleWithCompletion.this.text.getDocument().getLength() == 0 && (e.getKeyCode() == KeyEvent.VK_DELETE || e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) {
225
                if (ITextArticleWithCompletion.this.text.getDocument().getLength() == 0 && (e.getKeyCode() == KeyEvent.VK_DELETE || e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) {
224
                    System.err.println("consume");
226
                    System.err.println("consume");
225
                    this.consume = true;
227
                    this.consume = true;
226
                    e.consume();
228
                    e.consume();
227
                }
229
                }
228
 
230
 
229
            }
231
            }
230
 
232
 
231
            public void keyReleased(KeyEvent e) {
233
            public void keyReleased(KeyEvent e) {
232
            }
234
            }
233
 
235
 
234
            public void keyTyped(KeyEvent e) {
236
            public void keyTyped(KeyEvent e) {
235
                // Evite les bips
237
                // Evite les bips
236
                if (this.consume) {
238
                if (this.consume) {
237
                    e.consume();
239
                    e.consume();
238
                    this.consume = false;
240
                    this.consume = false;
239
                }
241
                }
240
            }
242
            }
241
        });
243
        });
242
        this.addComponentListener(new ComponentListener() {
244
        this.addComponentListener(new ComponentListener() {
243
            public void componentHidden(ComponentEvent e) {
245
            public void componentHidden(ComponentEvent e) {
244
            }
246
            }
245
 
247
 
246
            public void componentMoved(ComponentEvent e) {
248
            public void componentMoved(ComponentEvent e) {
247
            }
249
            }
248
 
250
 
249
            public void componentResized(ComponentEvent e) {
251
            public void componentResized(ComponentEvent e) {
250
                // ajuste la taille min de la popup
252
                // ajuste la taille min de la popup
251
                ITextArticleWithCompletion.this.popup.setMinWith(atext.getBounds().width);
253
                ITextArticleWithCompletion.this.popup.setMinWith(atext.getBounds().width);
252
            }
254
            }
253
 
255
 
254
            public void componentShown(ComponentEvent e) {
256
            public void componentShown(ComponentEvent e) {
255
            }
257
            }
256
        });
258
        });
257
        atext.addFocusListener(new FocusListener() {
259
        atext.addFocusListener(new FocusListener() {
258
            @Override
260
            @Override
259
            public void focusGained(FocusEvent e) {
261
            public void focusGained(FocusEvent e) {
260
 
262
 
261
            }
263
            }
262
 
264
 
263
            @Override
265
            @Override
264
            public void focusLost(FocusEvent e) {
266
            public void focusLost(FocusEvent e) {
265
                hidePopup();
267
                hidePopup();
266
            }
268
            }
267
        });
269
        });
268
    }
270
    }
269
 
271
 
270
    /**
272
    /**
271
     * Retourne une liste de IComboSelectionItem, qui sont les selections possibles pour le text
273
     * Retourne une liste de IComboSelectionItem, qui sont les selections possibles pour le text
272
     * passé
274
     * passé
273
     * 
275
     * 
274
     * @throws SQLException
276
     * @throws SQLException
275
     */
277
     */
276
    List<IComboSelectionItem> getPossibleValues(String aText) throws SQLException {
278
    List<IComboSelectionItem> getPossibleValues(String aText) throws SQLException {
277
        List<IComboSelectionItem> result = new Vector<IComboSelectionItem>();
279
        List<IComboSelectionItem> result = new Vector<IComboSelectionItem>();
278
        if (aText.isEmpty()) {
280
        if (aText.isEmpty()) {
279
            return result;
281
            return result;
280
        }
282
        }
281
        aText = aText.trim();
283
        aText = aText.trim();
282
 
284
 
283
        if (aText.length() > 0) {
285
        if (aText.length() > 0) {
284
 
286
 
285
            List<SQLSelect> listSel = new ArrayList<SQLSelect>();
287
            List<SQLSelect> listSel = new ArrayList<SQLSelect>();
286
            // CODE ARTICLE = aText
288
            // CODE ARTICLE = aText
287
            SQLSelect selMatchingCode = new SQLSelect();
289
            SQLSelect selMatchingCode = new SQLSelect();
288
            // selMatchingCode.addSelectStar(this.tableArticle);
290
            // selMatchingCode.addSelectStar(this.tableArticle);
289
            selMatchingCode.addSelect(this.tableArticle.getKey());
291
            selMatchingCode.addSelect(this.tableArticle.getKey());
290
            selMatchingCode.addSelect(this.tableArticle.getField("CODE"));
292
            selMatchingCode.addSelect(this.tableArticle.getField("CODE"));
291
            selMatchingCode.addSelect(this.tableArticle.getField("NOM"));
293
            selMatchingCode.addSelect(this.tableArticle.getField("NOM"));
292
            selMatchingCode.addSelect(this.tableArticle.getField("CODE_BARRE"));
294
            selMatchingCode.addSelect(this.tableArticle.getField("CODE_BARRE"));
293
            Where wMatchingCode = new Where(this.tableArticle.getField("CODE"), "=", aText);
295
            Where wMatchingCode = new Where(this.tableArticle.getField("CODE"), "=", aText);
294
            wMatchingCode = wMatchingCode.or(new Where(this.tableArticle.getField("NOM"), "=", aText));
296
            wMatchingCode = wMatchingCode.or(new Where(this.tableArticle.getField("NOM"), "=", aText));
295
            wMatchingCode = wMatchingCode.or(new Where(this.tableArticle.getField("CODE_BARRE"), "=", aText));
297
            wMatchingCode = wMatchingCode.or(new Where(this.tableArticle.getField("CODE_BARRE"), "=", aText));
296
            if (this.whereAdditionnal != null) {
298
            if (this.whereAdditionnal != null) {
297
                wMatchingCode = wMatchingCode.and(this.whereAdditionnal);
299
                wMatchingCode = wMatchingCode.and(this.whereAdditionnal);
298
            }
300
            }
299
            selMatchingCode.setWhere(wMatchingCode);
301
            selMatchingCode.setWhere(wMatchingCode);
300
            if (this.selTransformer != null) {
302
            if (this.selTransformer != null) {
301
                selMatchingCode = this.selTransformer.transformChecked(selMatchingCode);
303
                selMatchingCode = this.selTransformer.transformChecked(selMatchingCode);
302
            }
304
            }
303
            listSel.add(selMatchingCode);
305
            listSel.add(selMatchingCode);
304
 
306
 
305
            // CODE ARTICLE LIKE %aText% with limit
307
            // CODE ARTICLE LIKE %aText% with limit
306
            SQLSelect selContains = new SQLSelect();
308
            SQLSelect selContains = new SQLSelect();
307
            // selContains.addSelectStar(this.tableArticle);
309
            // selContains.addSelectStar(this.tableArticle);
308
            selContains.addSelect(this.tableArticle.getKey());
310
            selContains.addSelect(this.tableArticle.getKey());
309
            selContains.addSelect(this.tableArticle.getField("CODE"));
311
            selContains.addSelect(this.tableArticle.getField("CODE"));
310
            selContains.addSelect(this.tableArticle.getField("NOM"));
312
            selContains.addSelect(this.tableArticle.getField("NOM"));
311
            selContains.addSelect(this.tableArticle.getField("CODE_BARRE"));
313
            selContains.addSelect(this.tableArticle.getField("CODE_BARRE"));
312
            Where wContains = new Where(this.tableArticle.getField("CODE"), "LIKE", "%" + aText + "%");
314
            Where wContains = new Where(this.tableArticle.getField("CODE"), "LIKE", "%" + aText + "%");
313
            wContains = wContains.or(new Where(this.tableArticle.getField("NOM"), "LIKE", "%" + aText + "%"));
315
            wContains = wContains.or(new Where(this.tableArticle.getField("NOM"), "LIKE", "%" + aText + "%"));
314
            wContains = wContains.or(new Where(this.tableArticle.getField("CODE_BARRE"), "LIKE", "%" + aText + "%"));
316
            wContains = wContains.or(new Where(this.tableArticle.getField("CODE_BARRE"), "LIKE", "%" + aText + "%"));
315
            if (this.whereAdditionnal != null) {
317
            if (this.whereAdditionnal != null) {
316
                wContains = wContains.and(this.whereAdditionnal);
318
                wContains = wContains.and(this.whereAdditionnal);
317
            }
319
            }
318
 
320
 
319
            selContains.setWhere(wContains.and(wMatchingCode.not()));
321
            selContains.setWhere(wContains.and(wMatchingCode.not()));
320
            selContains.setExcludeUndefined(false, this.tableArticle.getForeignTable("ID_STOCK"));
322
            selContains.setExcludeUndefined(false, this.tableArticle.getForeignTable("ID_STOCK"));
321
            selContains.setLimit(SQL_RESULT_LIMIT);
323
            selContains.setLimit(SQL_RESULT_LIMIT);
322
            if (this.selTransformer != null) {
324
            if (this.selTransformer != null) {
323
                selContains = this.selTransformer.transformChecked(selContains);
325
                selContains = this.selTransformer.transformChecked(selContains);
324
            }
326
            }
325
            listSel.add(selContains);
327
            listSel.add(selContains);
326
 
328
 
327
            // CODE ARTICLE = aText
329
            // CODE ARTICLE = aText
328
            final Where wNotSync = new Where(this.tableArticleFournisseur.getField("ID_ARTICLE"), "IS", (Object) null)
330
            final Where wNotSync = new Where(this.tableArticleFournisseur.getField("ID_ARTICLE"), "IS", (Object) null)
329
                    .or(new Where(this.tableArticleFournisseur.getField("ID_ARTICLE"), "=", this.tableArticleFournisseur.getUndefinedID()));
331
                    .or(new Where(this.tableArticleFournisseur.getField("ID_ARTICLE"), "=", this.tableArticleFournisseur.getUndefinedID()));
330
 
332
 
331
            SQLSelect selMatchingCodeF = new SQLSelect();
333
            SQLSelect selMatchingCodeF = new SQLSelect();
332
            // selMatchingCodeF.addSelectStar(this.tableArticleFournisseur);
334
            // selMatchingCodeF.addSelectStar(this.tableArticleFournisseur);
333
            selMatchingCodeF.addSelect(this.tableArticleFournisseur.getKey());
335
            selMatchingCodeF.addSelect(this.tableArticleFournisseur.getKey());
334
            selMatchingCodeF.addSelect(this.tableArticleFournisseur.getField("CODE"));
336
            selMatchingCodeF.addSelect(this.tableArticleFournisseur.getField("CODE"));
335
            selMatchingCodeF.addSelect(this.tableArticleFournisseur.getField("NOM"));
337
            selMatchingCodeF.addSelect(this.tableArticleFournisseur.getField("NOM"));
336
            selMatchingCodeF.addSelect(this.tableArticleFournisseur.getField("CODE_BARRE"));
338
            selMatchingCodeF.addSelect(this.tableArticleFournisseur.getField("CODE_BARRE"));
337
            Where wMatchingCodeF = new Where(this.tableArticleFournisseur.getField("CODE"), "=", aText);
339
            Where wMatchingCodeF = new Where(this.tableArticleFournisseur.getField("CODE"), "=", aText);
338
            wMatchingCodeF = wMatchingCodeF.or(new Where(this.tableArticleFournisseur.getField("CODE_BARRE"), "=", aText));
340
            wMatchingCodeF = wMatchingCodeF.or(new Where(this.tableArticleFournisseur.getField("CODE_BARRE"), "=", aText));
339
            wMatchingCodeF = wMatchingCodeF.or(new Where(this.tableArticleFournisseur.getField("NOM"), "=", aText));
341
            wMatchingCodeF = wMatchingCodeF.or(new Where(this.tableArticleFournisseur.getField("NOM"), "=", aText));
340
            selMatchingCodeF.setWhere(wMatchingCodeF.and(wNotSync));
342
            selMatchingCodeF.setWhere(wMatchingCodeF.and(wNotSync));
341
            listSel.add(selMatchingCodeF);
343
            listSel.add(selMatchingCodeF);
342
 
344
 
343
            // CODE ARTICLE_FOURNISSEUR LIKE %aText% with limit
345
            // CODE ARTICLE_FOURNISSEUR LIKE %aText% with limit
344
            SQLSelect selContainsCodeF = new SQLSelect();
346
            SQLSelect selContainsCodeF = new SQLSelect();
345
            // selContainsCodeF.addSelectStar(this.tableArticleFournisseur);
347
            // selContainsCodeF.addSelectStar(this.tableArticleFournisseur);
346
            selContainsCodeF.addSelect(this.tableArticleFournisseur.getKey());
348
            selContainsCodeF.addSelect(this.tableArticleFournisseur.getKey());
347
            selContainsCodeF.addSelect(this.tableArticleFournisseur.getField("CODE"));
349
            selContainsCodeF.addSelect(this.tableArticleFournisseur.getField("CODE"));
348
            selContainsCodeF.addSelect(this.tableArticleFournisseur.getField("NOM"));
350
            selContainsCodeF.addSelect(this.tableArticleFournisseur.getField("NOM"));
349
            selContainsCodeF.addSelect(this.tableArticleFournisseur.getField("CODE_BARRE"));
351
            selContainsCodeF.addSelect(this.tableArticleFournisseur.getField("CODE_BARRE"));
350
            Where wContainsCodeF = new Where(this.tableArticleFournisseur.getField("CODE"), "LIKE", "%" + aText + "%");
352
            Where wContainsCodeF = new Where(this.tableArticleFournisseur.getField("CODE"), "LIKE", "%" + aText + "%");
351
            wContainsCodeF = wContainsCodeF.or(new Where(this.tableArticleFournisseur.getField("CODE_BARRE"), "LIKE", "%" + aText + "%"));
353
            wContainsCodeF = wContainsCodeF.or(new Where(this.tableArticleFournisseur.getField("CODE_BARRE"), "LIKE", "%" + aText + "%"));
352
            wContainsCodeF = wContainsCodeF.or(new Where(this.tableArticleFournisseur.getField("NOM"), "LIKE", "%" + aText + "%"));
354
            wContainsCodeF = wContainsCodeF.or(new Where(this.tableArticleFournisseur.getField("NOM"), "LIKE", "%" + aText + "%"));
353
            selContainsCodeF.setWhere(wContainsCodeF.and(wMatchingCodeF.not()).and(wNotSync));
355
            selContainsCodeF.setWhere(wContainsCodeF.and(wMatchingCodeF.not()).and(wNotSync));
354
            selContainsCodeF.setLimit(SQL_RESULT_LIMIT);
356
            selContainsCodeF.setLimit(SQL_RESULT_LIMIT);
355
 
357
 
356
            listSel.add(selContainsCodeF);
358
            listSel.add(selContainsCodeF);
357
 
359
 
358
            MultipleSQLSelectExecutor mult = new MultipleSQLSelectExecutor(this.tableArticle.getDBSystemRoot(), listSel);
360
            MultipleSQLSelectExecutor mult = new MultipleSQLSelectExecutor(this.tableArticle.getDBSystemRoot(), listSel);
359
 
361
 
360
            List<List<SQLRow>> resultList = mult.execute();
362
            List<List<? extends SQLRowAccessor>> resultList = new ArrayList<>();
-
 
363
            resultList.addAll(mult.execute());
361
 
364
 
-
 
365
            // Recherche dans les codes fournisseurs
-
 
366
            SQLTable tableCodeArt = this.tableArticle.getDBRoot().getTable("CODE_FOURNISSEUR");
-
 
367
            SQLRowValues rowValsCodeF = new SQLRowValues(tableCodeArt);
-
 
368
            rowValsCodeF.putNulls("CODE");
-
 
369
            rowValsCodeF.putRowValues("ID_ARTICLE").putNulls(this.tableArticle.getFieldsName());
-
 
370
 
-
 
371
            final String codeText = aText;
-
 
372
            SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsCodeF);
-
 
373
            fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
-
 
374
                @Override
-
 
375
                public SQLSelect transformChecked(SQLSelect input) {
-
 
376
 
-
 
377
                    Where wCodeFContains = new Where(tableCodeArt.getField("CODE"), "LIKE", "%" + codeText + "%");
-
 
378
                    input.setWhere(wCodeFContains);
-
 
379
                    input.setLimit(SQL_RESULT_LIMIT);
-
 
380
                    return input;
-
 
381
                }
-
 
382
            });
-
 
383
            List<SQLRowValues> resultCodeF = fetcher.fetch();
362
            for (List<SQLRow> list : resultList) {
384
            resultList.add(2, resultCodeF);
363
 
385
 
-
 
386
            for (List<? extends SQLRowAccessor> list : resultList) {
-
 
387
 
364
                for (SQLRow sqlRow : list) {
388
                for (SQLRowAccessor sqlRow : list) {
365
 
389
 
366
                    StringBuffer buf = new StringBuffer();
390
                    StringBuffer buf = new StringBuffer();
-
 
391
                    if (sqlRow.getTable().getName().equals("CODE_FOURNISSEUR")) {
-
 
392
                        SQLRowAccessor rArt = sqlRow.getForeign("ID_ARTICLE");
-
 
393
                        buf.append(sqlRow.getString("CODE") + " -- ");
-
 
394
                        buf.append(rArt.getString("CODE") + " -- ");
-
 
395
                        buf.append(rArt.getString("NOM"));
-
 
396
                        result.add(new IComboSelectionItem(rArt, buf.toString()));
-
 
397
                    } else {
367
                    if (sqlRow.getString("CODE_BARRE") != null && sqlRow.getString("CODE_BARRE").trim().length() > 0) {
398
                        if (sqlRow.getString("CODE_BARRE") != null && sqlRow.getString("CODE_BARRE").trim().length() > 0) {
368
                        buf.append(sqlRow.getString("CODE_BARRE") + " -- ");
399
                            buf.append(sqlRow.getString("CODE_BARRE") + " -- ");
369
                    }
400
                        }
370
                    buf.append(sqlRow.getString("CODE") + " -- ");
401
                        buf.append(sqlRow.getString("CODE") + " -- ");
371
                    buf.append(sqlRow.getString("NOM"));
402
                        buf.append(sqlRow.getString("NOM"));
372
                    result.add(new IComboSelectionItem(sqlRow, buf.toString()));
403
                        result.add(new IComboSelectionItem(sqlRow, buf.toString()));
373
                }
404
                    }
-
 
405
                }
374
            }
406
            }
375
 
407
 
376
        }
408
        }
377
 
409
 
378
        return result;
410
        return result;
379
    }
411
    }
380
 
412
 
381
    private void updateAutoCompletion(boolean autoselectIfMatch) {
413
    private void updateAutoCompletion(boolean autoselectIfMatch) {
382
        this.autoselectIfMatch = autoselectIfMatch;
414
        this.autoselectIfMatch = autoselectIfMatch;
383
        this.autoCheckDelay = PAUSE_MS * 2;
415
        this.autoCheckDelay = PAUSE_MS * 2;
384
        synchronized (searchStack) {
416
        synchronized (searchStack) {
385
            this.searchStack.push(this.text.getText().trim());
417
            this.searchStack.push(this.text.getText().trim());
386
        }
418
        }
387
    }
419
    }
388
 
420
 
389
    private void loadAutoCompletion() {
421
    private void loadAutoCompletion() {
390
        if (!this.isCompletionEnabled() || this.isLoading) {
422
        if (!this.isCompletionEnabled() || this.isLoading) {
391
            return;
423
            return;
392
        }
424
        }
393
        final String t;
425
        final String t;
394
        synchronized (searchStack) {
426
        synchronized (searchStack) {
395
            if (this.searchStack.isEmpty()) {
427
            if (this.searchStack.isEmpty()) {
396
                return;
428
                return;
397
            }
429
            }
398
            t = this.searchStack.pop();
430
            t = this.searchStack.pop();
399
            this.searchStack.clear();
431
            this.searchStack.clear();
400
        }
432
        }
401
 
433
 
402
        final SwingWorker<List<IComboSelectionItem>, Object> worker = new SwingWorker<List<IComboSelectionItem>, Object>() {
434
        final SwingWorker<List<IComboSelectionItem>, Object> worker = new SwingWorker<List<IComboSelectionItem>, Object>() {
403
 
435
 
404
            @Override
436
            @Override
405
            protected List<IComboSelectionItem> doInBackground() throws Exception {
437
            protected List<IComboSelectionItem> doInBackground() throws Exception {
406
                List<IComboSelectionItem> l = getPossibleValues(t); // Liste de IComboSelection
438
                List<IComboSelectionItem> l = getPossibleValues(t); // Liste de IComboSelection
407
                return l;
439
                return l;
408
            }
440
            }
409
 
441
 
410
            @Override
442
            @Override
411
            protected void done() {
443
            protected void done() {
412
                List<IComboSelectionItem> l;
444
                List<IComboSelectionItem> l;
413
                try {
445
                try {
414
                    l = get();
446
                    l = get();
415
                } catch (Exception e) {
447
                } catch (Exception e) {
416
                    l = new ArrayList<IComboSelectionItem>(0);
448
                    l = new ArrayList<IComboSelectionItem>(0);
417
                    e.printStackTrace();
449
                    e.printStackTrace();
418
                }
450
                }
419
 
451
 
420
                // On cache la popup si le nombre de ligne change afin que sa taille soit correcte
452
                // On cache la popup si le nombre de ligne change afin que sa taille soit correcte
421
                if (l.size() != model.getSize() && l.size() <= ITextWithCompletionPopUp.MAXROW) {
453
                if (l.size() != model.getSize() && l.size() <= ITextWithCompletionPopUp.MAXROW) {
422
                    hidePopup();
454
                    hidePopup();
423
                }
455
                }
424
                // on vide le model
456
                // on vide le model
425
                model.removeAllElements();
457
                model.removeAllElements();
426
                model.addAll(l);
458
                model.addAll(l);
427
 
459
 
428
                if (l.size() > 0) {
460
                if (l.size() > 0) {
429
                    showPopup();
461
                    showPopup();
430
                } else {
462
                } else {
431
                    hidePopup();
463
                    hidePopup();
432
                }
464
                }
433
                SQLRowAccessor newRow = selectedRow;
465
                SQLRowAccessor newRow = selectedRow;
434
                IComboSelectionItem newSelectedItem = null;
466
                IComboSelectionItem newSelectedItem = null;
435
                boolean found = false;
467
                boolean found = false;
436
                for (Iterator<IComboSelectionItem> iter = l.iterator(); iter.hasNext();) {
468
                for (Iterator<IComboSelectionItem> iter = l.iterator(); iter.hasNext();) {
437
                    IComboSelectionItem element = iter.next();
469
                    IComboSelectionItem element = iter.next();
438
 
470
 
439
                    if ((element.getRow().getString("CODE_BARRE").toLowerCase().equals(t.toLowerCase()) || element.getRow().getString("CODE").toLowerCase().equals(t.toLowerCase()))
471
                    if ((element.getRow().getString("CODE_BARRE").toLowerCase().equals(t.toLowerCase()) || element.getRow().getString("CODE").toLowerCase().equals(t.toLowerCase()))
440
                            && autoselectIfMatch) {
472
                            && autoselectIfMatch) {
441
                        newRow = element.getRow();
473
                        newRow = element.getRow();
442
                        newSelectedItem = element;
474
                        newSelectedItem = element;
443
                        hidePopup();
475
                        hidePopup();
444
                        found = true;
476
                        found = true;
445
                        break;
477
                        break;
446
                    }
478
                    }
447
                }
479
                }
448
                if (selectAuto && found && !CompareUtils.equals(newRow, selectedRow)) {
480
                if (selectAuto && found && !CompareUtils.equals(newRow, selectedRow)) {
449
                    final IComboSelectionItem selectedItem = newSelectedItem;
481
                    final IComboSelectionItem selectedItem = newSelectedItem;
450
                    SwingUtilities.invokeLater(new Runnable() {
482
                    SwingUtilities.invokeLater(new Runnable() {
451
                        public void run() {
483
                        public void run() {
452
                            itemSelected(selectedItem);
484
                            itemSelected(selectedItem);
453
                        }
485
                        }
454
                    });
486
                    });
455
                }
487
                }
456
                if (!found) {
488
                if (!found) {
457
                    selectedRow = null;
489
                    selectedRow = null;
458
                    itemSelected(null);
490
                    itemSelected(null);
459
                }
491
                }
460
 
492
 
461
            }
493
            }
462
        };
494
        };
463
        worker.execute();
495
        worker.execute();
464
 
496
 
465
    }
497
    }
466
 
498
 
467
    public synchronized void hidePopup() {
499
    public synchronized void hidePopup() {
468
        this.popup.setVisible(false);
500
        this.popup.setVisible(false);
469
    }
501
    }
470
 
502
 
471
    private synchronized void showPopup() {
503
    private synchronized void showPopup() {
472
        if (this.model.getSize() > 0) {
504
        if (this.model.getSize() > 0) {
473
            if (this.popupInvoker.isShowing())
505
            if (this.popupInvoker.isShowing())
474
                this.popup.show(this.popupInvoker, 0, this.text.getBounds().height);
506
                this.popup.show(this.popupInvoker, 0, this.text.getBounds().height);
475
        }
507
        }
476
    }
508
    }
477
 
509
 
478
    public void changedUpdate(DocumentEvent e) {
510
    public void changedUpdate(DocumentEvent e) {
479
        updateAutoCompletion(false);
511
        updateAutoCompletion(false);
480
        this.supp.firePropertyChange("value", null, this.getText());
512
        this.supp.firePropertyChange("value", null, this.getText());
481
    }
513
    }
482
 
514
 
483
    public void insertUpdate(DocumentEvent e) {
515
    public void insertUpdate(DocumentEvent e) {
484
        updateAutoCompletion(false);
516
        updateAutoCompletion(false);
485
        this.supp.firePropertyChange("value", null, this.getText());
517
        this.supp.firePropertyChange("value", null, this.getText());
486
    }
518
    }
487
 
519
 
488
    public void removeUpdate(DocumentEvent e) {
520
    public void removeUpdate(DocumentEvent e) {
489
        updateAutoCompletion(false);
521
        updateAutoCompletion(false);
490
        this.supp.firePropertyChange("value", null, this.getText());
522
        this.supp.firePropertyChange("value", null, this.getText());
491
    }
523
    }
492
 
524
 
493
    public SQLRowAccessor getSelectedRow() {
525
    public SQLRowAccessor getSelectedRow() {
494
        return this.selectedRow;
526
        return this.selectedRow;
495
    }
527
    }
496
 
528
 
497
    public void setSelectedRow(SQLRowAccessor row) {
529
    public void setSelectedRow(SQLRowAccessor row) {
498
        this.selectedRow = row;
530
        this.selectedRow = row;
499
    }
531
    }
500
 
532
 
501
    private void clearText() {
533
    private void clearText() {
502
        setText("");
534
        setText("");
503
    }
535
    }
504
 
536
 
505
    public void setEditable(boolean b) {
537
    public void setEditable(boolean b) {
506
        this.text.setEditable(b);
538
        this.text.setEditable(b);
507
    }
539
    }
508
 
540
 
509
    public void setFillWithField(String s) {
541
    public void setFillWithField(String s) {
510
        this.fillWith = s;
542
        this.fillWith = s;
511
    }
543
    }
512
 
544
 
513
    public SQLField getFillWithField() {
545
    public SQLField getFillWithField() {
514
        return this.tableArticle.getField(fillWith);
546
        return this.tableArticle.getField(fillWith);
515
    }
547
    }
516
 
548
 
517
    public void selectItem(IComboSelectionItem item) {
549
    public void selectItem(IComboSelectionItem item) {
518
        if (!SwingUtilities.isEventDispatchThread()) {
550
        if (!SwingUtilities.isEventDispatchThread()) {
519
            throw new IllegalStateException("Not in Swing!");
551
            throw new IllegalStateException("Not in Swing!");
520
        }
552
        }
521
        if (item != null) {
553
        if (item != null) {
522
            if (this.fillWith != null) {
554
            if (this.fillWith != null) {
523
                // FIXME SQL request in Swing
555
                // FIXME SQL request in Swing
524
                SQLRowAccessor row = item.getRow();
556
                SQLRowAccessor row = item.getRow();
525
                this.setText(row.getObject(this.fillWith).toString());
557
                this.setText(row.getObject(this.fillWith).toString());
526
            } else {
558
            } else {
527
                this.setText(item.getLabel());
559
                this.setText(item.getLabel());
528
            }
560
            }
529
        } else {
561
        } else {
530
            this.clearText();
562
            this.clearText();
531
        }
563
        }
532
        hidePopup();
564
        hidePopup();
533
    }
565
    }
534
 
566
 
535
    public void setText(final String label) {
567
    public void setText(final String label) {
536
        if (!SwingUtilities.isEventDispatchThread()) {
568
        if (!SwingUtilities.isEventDispatchThread()) {
537
            throw new IllegalStateException("Not in Swing!");
569
            throw new IllegalStateException("Not in Swing!");
538
        }
570
        }
539
        setCompletionEnabled(false);
571
        setCompletionEnabled(false);
540
        this.text.setText(label);
572
        this.text.setText(label);
541
        if (label != null) {
573
        if (label != null) {
542
            this.text.setCaretPosition(label.length());
574
            this.text.setCaretPosition(label.length());
543
        }
575
        }
544
        this.text.repaint();
576
        this.text.repaint();
545
        setCompletionEnabled(true);
577
        setCompletionEnabled(true);
546
    }
578
    }
547
 
579
 
548
    // Gestion des listeners de selection d'id
580
    // Gestion des listeners de selection d'id
549
    public void addSelectionListener(SelectionRowListener l) {
581
    public void addSelectionListener(SelectionRowListener l) {
550
        this.listeners.add(l);
582
        this.listeners.add(l);
551
    }
583
    }
552
 
584
 
553
    public void removeSelectionListener(SelectionRowListener l) {
585
    public void removeSelectionListener(SelectionRowListener l) {
554
        this.listeners.remove(l);
586
        this.listeners.remove(l);
555
    }
587
    }
556
 
588
 
557
    private boolean isDispatching = false;
589
    private boolean isDispatching = false;
558
 
590
 
559
    private void fireSelectionRow(SQLRowAccessor row) {
591
    private void fireSelectionRow(SQLRowAccessor row) {
560
        if (!this.isDispatching) {
592
        if (!this.isDispatching) {
561
 
593
 
562
            this.isDispatching = true;
594
            this.isDispatching = true;
563
            for (Iterator<SelectionRowListener> iter = this.listeners.iterator(); iter.hasNext();) {
595
            for (Iterator<SelectionRowListener> iter = this.listeners.iterator(); iter.hasNext();) {
564
                SelectionRowListener element = iter.next();
596
                SelectionRowListener element = iter.next();
565
                element.rowSelected(row, this);
597
                element.rowSelected(row, this);
566
            }
598
            }
567
            this.isDispatching = false;
599
            this.isDispatching = false;
568
        }
600
        }
569
    }
601
    }
570
 
602
 
571
    /**
603
    /**
572
     * @return Returns the completionEnabled.
604
     * @return Returns the completionEnabled.
573
     */
605
     */
574
    boolean isCompletionEnabled() {
606
    boolean isCompletionEnabled() {
575
        return this.completionEnabled;
607
        return this.completionEnabled;
576
    }
608
    }
577
 
609
 
578
    /**
610
    /**
579
     * @param completionEnabled The completionEnabled to set.
611
     * @param completionEnabled The completionEnabled to set.
580
     */
612
     */
581
    void setCompletionEnabled(boolean completionEnabled) {
613
    void setCompletionEnabled(boolean completionEnabled) {
582
        this.completionEnabled = completionEnabled;
614
        this.completionEnabled = completionEnabled;
583
    }
615
    }
584
 
616
 
585
    public Object getText() {
617
    public Object getText() {
586
        return this.text.getText();
618
        return this.text.getText();
587
    }
619
    }
588
 
620
 
589
    /**
621
    /**
590
     * @param popupInvoker The popupInvoker to set.
622
     * @param popupInvoker The popupInvoker to set.
591
     */
623
     */
592
    public void setPopupInvoker(Component popupInvoker) {
624
    public void setPopupInvoker(Component popupInvoker) {
593
        this.popupInvoker = popupInvoker;
625
        this.popupInvoker = popupInvoker;
594
    }
626
    }
595
 
627
 
596
    public JTextComponent getTextComp() {
628
    public JTextComponent getTextComp() {
597
        return this.text;
629
        return this.text;
598
    }
630
    }
599
 
631
 
600
    public JComponent getComp() {
632
    public JComponent getComp() {
601
        return this;
633
        return this;
602
    }
634
    }
603
 
635
 
604
    public void setSelectionAutoEnabled(boolean b) {
636
    public void setSelectionAutoEnabled(boolean b) {
605
        this.selectAuto = b;
637
        this.selectAuto = b;
606
    }
638
    }
607
 
639
 
608
    public void setLimitedSize(int nbChar) {
640
    public void setLimitedSize(int nbChar) {
609
        // rm previous ones
641
        // rm previous ones
610
        final DocumentFilterList dfl = DocumentFilterList.get((AbstractDocument) this.text.getDocument());
642
        final DocumentFilterList dfl = DocumentFilterList.get((AbstractDocument) this.text.getDocument());
611
        final Iterator<DocumentFilter> iter = dfl.getFilters().iterator();
643
        final Iterator<DocumentFilter> iter = dfl.getFilters().iterator();
612
        while (iter.hasNext()) {
644
        while (iter.hasNext()) {
613
            final DocumentFilter df = iter.next();
645
            final DocumentFilter df = iter.next();
614
            if (df instanceof LimitedSizeDocumentFilter)
646
            if (df instanceof LimitedSizeDocumentFilter)
615
                iter.remove();
647
                iter.remove();
616
        }
648
        }
617
        // add the new one
649
        // add the new one
618
        DocumentFilterList.add((AbstractDocument) this.text.getDocument(), new LimitedSizeDocumentFilter(nbChar), FilterType.SIMPLE_FILTER);
650
        DocumentFilterList.add((AbstractDocument) this.text.getDocument(), new LimitedSizeDocumentFilter(nbChar), FilterType.SIMPLE_FILTER);
619
    }
651
    }
620
 
652
 
621
    @Override
653
    @Override
622
    public void resetValue() {
654
    public void resetValue() {
623
        this.setText("");
655
        this.setText("");
624
    }
656
    }
625
 
657
 
626
    @Override
658
    @Override
627
    public void setValue(String val) {
659
    public void setValue(String val) {
628
        this.setText(val);
660
        this.setText(val);
629
    }
661
    }
630
 
662
 
631
    @Override
663
    @Override
632
    public void addValueListener(PropertyChangeListener l) {
664
    public void addValueListener(PropertyChangeListener l) {
633
        this.supp.addPropertyChangeListener(l);
665
        this.supp.addPropertyChangeListener(l);
634
    }
666
    }
635
 
667
 
636
    @Override
668
    @Override
637
    public String getValue() {
669
    public String getValue() {
638
        return (String) this.getText();
670
        return (String) this.getText();
639
    }
671
    }
640
 
672
 
641
    @Override
673
    @Override
642
    public void rmValueListener(PropertyChangeListener l) {
674
    public void rmValueListener(PropertyChangeListener l) {
643
        this.supp.removePropertyChangeListener(l);
675
        this.supp.removePropertyChangeListener(l);
644
    }
676
    }
645
 
677
 
646
    @Override
678
    @Override
647
    public void itemSelected(IComboSelectionItem item) {
679
    public void itemSelected(IComboSelectionItem item) {
648
        if (item == null) {
680
        if (item == null) {
649
            fireSelectionRow(null);
681
            fireSelectionRow(null);
650
        } else {
682
        } else {
651
            final SQLRowAccessor row = item.getRow();
683
            final SQLRowAccessor row = item.getRow();
652
            if (this.isLoading) {
684
            if (this.isLoading) {
653
                this.rowToSelect = row;
685
                this.rowToSelect = row;
654
 
686
 
655
            } else {
687
            } else {
656
                if (!CompareUtils.equals(this.selectedRow, row)) {
688
                if (!CompareUtils.equals(this.selectedRow, row)) {
657
                    this.setSelectedRow(row);
689
                    this.setSelectedRow(row);
658
                    this.selectItem(item);
690
                    this.selectItem(item);
659
                    this.fireSelectionRow(row);
691
                    this.fireSelectionRow(row);
660
                }
692
                }
661
            }
693
            }
662
        }
694
        }
663
    }
695
    }
664
 
696
 
665
}
697
}