OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Rev 25 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 19
Line 147... Line 147...
147
        atext.addKeyListener(new KeyListener() {
147
        atext.addKeyListener(new KeyListener() {
148
 
148
 
149
            private boolean consume;
149
            private boolean consume;
150
 
150
 
151
            public void keyPressed(KeyEvent e) {
151
            public void keyPressed(KeyEvent e) {
152
                if (e.getKeyCode() == KeyEvent.VK_DOWN) {
152
                if (e.getKeyCode() == KeyEvent.VK_TAB) {
-
 
153
                    // Complete si exactement la valeur souhaitée
-
 
154
                    updateAutoCompletion(true);
-
 
155
                    e.consume();
-
 
156
                } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
153
                    if (ITextWithCompletion.this.popup.isShowing()) {
157
                    if (ITextWithCompletion.this.popup.isShowing()) {
154
                        ITextWithCompletion.this.popup.selectNext();
158
                        ITextWithCompletion.this.popup.selectNext();
155
                        e.consume();
159
                        e.consume();
156
                    } else {
160
                    } else {
157
                        if (getSelectedId() <= 1) {
161
                        if (getSelectedId() <= 1) {
Line 179... Line 183...
179
                } else if (e.getKeyCode() == KeyEvent.VK_PAGE_UP) {
183
                } else if (e.getKeyCode() == KeyEvent.VK_PAGE_UP) {
180
                    if (ITextWithCompletion.this.popup.isShowing()) {
184
                    if (ITextWithCompletion.this.popup.isShowing()) {
181
                        ITextWithCompletion.this.popup.selectPreviousPage();
185
                        ITextWithCompletion.this.popup.selectPreviousPage();
182
                        e.consume();
186
                        e.consume();
183
                    }
187
                    }
184
                } else {
-
 
185
                    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
188
                } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
186
                        if (ITextWithCompletion.this.popup.isShowing()) {
189
                    if (ITextWithCompletion.this.popup.isShowing()) {
187
                            hidePopup();
190
                        hidePopup();
188
                        }
191
                    }
189
                    }
-
 
-
 
192
 
190
                }
193
                }
191
 
194
 
192
                // else {
195
                // else {
193
                // if (e.getKeyCode() != KeyEvent.VK_RIGHT && e.getKeyCode() !=
196
                // if (e.getKeyCode() != KeyEvent.VK_RIGHT && e.getKeyCode() !=
194
                // KeyEvent.VK_LEFT) {
197
                // KeyEvent.VK_LEFT) {
Line 263... Line 266...
263
        synchronized (this) {
266
        synchronized (this) {
264
            this.isLoading = true;
267
            this.isLoading = true;
265
        }
268
        }
266
        final SwingWorker worker = new SwingWorker<Object, Object>() {
269
        final SwingWorker worker = new SwingWorker<Object, Object>() {
267
 
270
 
268
          
-
 
269
 
-
 
270
            // Runs on the event-dispatching thread.
271
            // Runs on the event-dispatching thread.
271
            @Override
272
            @Override
272
            public void done() {
273
            public void done() {
273
                ITextWithCompletion.this.popup.getAccessibleContext().setAccessibleParent(ITextWithCompletion.this.text);
274
                ITextWithCompletion.this.popup.getAccessibleContext().setAccessibleParent(ITextWithCompletion.this.text);
274
                // do not call updateAutoCompletion() otherwise the popup will be shown
275
                // do not call updateAutoCompletion() otherwise the popup will be shown
Line 294... Line 295...
294
     * Retourne une liste de IComboSelectionItem, qui sont les selections possibles pour le text
295
     * Retourne une liste de IComboSelectionItem, qui sont les selections possibles pour le text
295
     * passé
296
     * passé
296
     */
297
     */
297
    List<IComboSelectionItem> getPossibleValues(String aText) {
298
    List<IComboSelectionItem> getPossibleValues(String aText) {
298
        List<IComboSelectionItem> result = new Vector<IComboSelectionItem>();
299
        List<IComboSelectionItem> result = new Vector<IComboSelectionItem>();
-
 
300
        if (aText.isEmpty()) {
-
 
301
            return result;
299
 
302
        }
300
        Map<String, IComboSelectionItem> map = new HashMap<String, IComboSelectionItem>();
303
        Map<String, IComboSelectionItem> map = new HashMap<String, IComboSelectionItem>();
301
 
304
 
302
        aText = aText.trim().toLowerCase();
305
        aText = aText.trim().toLowerCase();
303
        List<String> values = cut(aText);
306
        List<String> values = cut(aText);
304
        int stop = values.size();
307
        int stop = values.size();
Line 351... Line 354...
351
 
354
 
352
        return result;
355
        return result;
353
    }
356
    }
354
 
357
 
355
    private List<String> cut(String value) {
358
    private List<String> cut(String value) {
356
        Vector<String> v = new Vector<String>();
359
        final Vector<String> v = new Vector<String>();
357
        StringTokenizer tokenizer = new StringTokenizer(value);
360
        final StringTokenizer tokenizer = new StringTokenizer(value);
358
        while (tokenizer.hasMoreElements()) {
361
        while (tokenizer.hasMoreElements()) {
359
            String element = (String) tokenizer.nextElement();
362
            final String element = (String) tokenizer.nextElement();
360
 
-
 
361
            v.add(element.toLowerCase());
363
            v.add(element.toLowerCase());
362
 
-
 
363
        }
364
        }
364
 
-
 
365
        return v;
365
        return v;
366
    }
366
    }
367
 
367
 
368
    private void updateAutoCompletion() {
368
    private void updateAutoCompletion(boolean autoselectIfMatch) {
369
        if (!this.isCompletionEnabled() || this.isLoading) {
369
        if (!this.isCompletionEnabled() || this.isLoading) {
370
            return;
370
            return;
371
        }
371
        }
372
        String t = this.text.getText().trim();
372
        String t = this.text.getText().trim();
373
 
373
 
Line 387... Line 387...
387
            showPopup();
387
            showPopup();
388
        } else {
388
        } else {
389
            hidePopup();
389
            hidePopup();
390
        }
390
        }
391
        // Le texte dans la case n'est pas celui d'un id
391
        // Le texte dans la case n'est pas celui d'un id
392
        // boolean isInCombo=false;
-
 
393
        // this.selectedId = -1;
-
 
-
 
392
 
394
        int newId = this.selectedId;
393
        int newId = this.selectedId;
395
        boolean found = false;
394
        boolean found = false;
396
        for (Iterator<IComboSelectionItem> iter = l.iterator(); iter.hasNext();) {
395
        for (Iterator<IComboSelectionItem> iter = l.iterator(); iter.hasNext();) {
397
            IComboSelectionItem element = iter.next();
396
            IComboSelectionItem element = iter.next();
398
            if (element.getLabel().equalsIgnoreCase(t) && l.size() == 1) {
397
            if (element.getLabel().equalsIgnoreCase(t) && autoselectIfMatch) {
399
 
-
 
400
                newId = element.getId();
398
                newId = element.getId();
401
                hidePopup();
399
                hidePopup();
402
                found = true;
400
                found = true;
403
                break;
401
                break;
404
            }
402
            }
Line 407... Line 405...
407
            this.selectedId = newId;
405
            this.selectedId = newId;
408
            SwingUtilities.invokeLater(new Runnable() {
406
            SwingUtilities.invokeLater(new Runnable() {
409
                public void run() {
407
                public void run() {
410
                    ITextWithCompletion.this.fireSelectionId(ITextWithCompletion.this.getSelectedId());
408
                    ITextWithCompletion.this.fireSelectionId(ITextWithCompletion.this.getSelectedId());
411
                }
409
                }
412
            }
-
 
413
 
-
 
414
            );
410
            });
415
        }
411
        }
416
        if (!found) {
412
        if (!found) {
417
            this.selectedId = -1;
413
            this.selectedId = -1;
418
            fireSelectionId(-1);
414
            fireSelectionId(-1);
419
        }
415
        }
Line 429... Line 425...
429
                this.popup.show(this.popupInvoker, 0, this.text.getBounds().height);
425
                this.popup.show(this.popupInvoker, 0, this.text.getBounds().height);
430
        }
426
        }
431
    }
427
    }
432
 
428
 
433
    public void changedUpdate(DocumentEvent e) {
429
    public void changedUpdate(DocumentEvent e) {
434
        updateAutoCompletion();
430
        updateAutoCompletion(false);
435
        this.supp.firePropertyChange("value", null, this.getText());
431
        this.supp.firePropertyChange("value", null, this.getText());
436
    }
432
    }
437
 
433
 
438
    public void insertUpdate(DocumentEvent e) {
434
    public void insertUpdate(DocumentEvent e) {
439
        updateAutoCompletion();
435
        updateAutoCompletion(false);
440
        this.supp.firePropertyChange("value", null, this.getText());
436
        this.supp.firePropertyChange("value", null, this.getText());
441
    }
437
    }
442
 
438
 
443
    public void removeUpdate(DocumentEvent e) {
439
    public void removeUpdate(DocumentEvent e) {
444
        updateAutoCompletion();
440
        updateAutoCompletion(false);
445
        this.supp.firePropertyChange("value", null, this.getText());
441
        this.supp.firePropertyChange("value", null, this.getText());
446
    }
442
    }
447
 
443
 
448
    public int getSelectedId() {
444
    public int getSelectedId() {
449
        return this.selectedId;
445
        return this.selectedId;