OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | Rev 144 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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