Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
NotesComboBoxModel |
|
| 1.0;1 |
1 | package org.jtheque.primary.view.impl.models; | |
2 | ||
3 | /* | |
4 | * This file is part of JTheque. | |
5 | * | |
6 | * JTheque is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License. | |
9 | * | |
10 | * JTheque is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | import org.jtheque.core.managers.Managers; | |
20 | import org.jtheque.core.managers.beans.IBeansManager; | |
21 | import org.jtheque.core.utils.db.DaoNotes; | |
22 | import org.jtheque.core.utils.db.Note; | |
23 | ||
24 | import javax.swing.DefaultComboBoxModel; | |
25 | ||
26 | /** | |
27 | * A model for combo boxes. This model display all the notes. | |
28 | * | |
29 | * @author Baptiste Wicht | |
30 | */ | |
31 | public final class NotesComboBoxModel extends DefaultComboBoxModel { | |
32 | 0 | private final DaoNotes daoNotes = DaoNotes.getInstance(); |
33 | ||
34 | /** | |
35 | * Construct a new NotesComboBoxModel. | |
36 | */ | |
37 | public NotesComboBoxModel(){ | |
38 | 0 | super(); |
39 | ||
40 | 0 | Managers.getManager(IBeansManager.class).inject(this); |
41 | 0 | } |
42 | ||
43 | @Override | |
44 | public Object getElementAt(int index){ | |
45 | 0 | return daoNotes.getNotes()[index]; |
46 | } | |
47 | ||
48 | @Override | |
49 | public int getSize(){ | |
50 | 0 | return daoNotes.getNotes().length; |
51 | } | |
52 | ||
53 | /** | |
54 | * Return the selected data in the model. | |
55 | * | |
56 | * @return The data who's selected. | |
57 | */ | |
58 | public Note getSelectedNote(){ | |
59 | 0 | return (Note) getSelectedItem(); |
60 | } | |
61 | } |