| 1 | |
package org.jtheque.films.view.impl.models; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.Managers; |
| 20 | |
import org.jtheque.core.managers.beans.IBeansManager; |
| 21 | |
import org.jtheque.films.persistence.od.able.Film; |
| 22 | |
import org.jtheque.films.services.able.IFilmsService; |
| 23 | |
import org.jtheque.films.view.impl.models.able.IFilmsModel; |
| 24 | |
import org.jtheque.primary.view.impl.listeners.ObjectChangedEvent; |
| 25 | |
import org.jtheque.primary.view.impl.models.PrincipalDataModel; |
| 26 | |
|
| 27 | |
import java.util.Collection; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public final class FilmsModel extends PrincipalDataModel<Film> implements IFilmsModel { |
| 35 | |
private Film currentFilm; |
| 36 | |
|
| 37 | |
private Collection<Film> displayList; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
public FilmsModel() { |
| 43 | 0 | super(); |
| 44 | |
|
| 45 | 0 | getFilmsService().addDataListener(this); |
| 46 | 0 | } |
| 47 | |
|
| 48 | |
@Override |
| 49 | |
@SuppressWarnings("unchecked") |
| 50 | |
public void updateDisplayList(Collection<Film> films) { |
| 51 | 0 | getDisplayList().clear(); |
| 52 | |
|
| 53 | 0 | if (films == null) { |
| 54 | 0 | getDisplayList().addAll(getFilmsService().getFilms()); |
| 55 | |
} else { |
| 56 | 0 | getDisplayList().addAll(films); |
| 57 | |
} |
| 58 | |
|
| 59 | 0 | fireDisplayListChanged(); |
| 60 | 0 | } |
| 61 | |
|
| 62 | |
@Override |
| 63 | |
public void updateDisplayList() { |
| 64 | 0 | updateDisplayList(null); |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
@Override |
| 68 | |
public Collection<Film> getDisplayList() { |
| 69 | 0 | if (displayList == null) { |
| 70 | 0 | displayList = getFilmsService().getFilms(); |
| 71 | |
} |
| 72 | |
|
| 73 | 0 | return displayList; |
| 74 | |
} |
| 75 | |
|
| 76 | |
@Override |
| 77 | |
public Film getCurrentFilm() { |
| 78 | 0 | return currentFilm; |
| 79 | |
} |
| 80 | |
|
| 81 | |
@Override |
| 82 | |
public void setCurrentFilm(Film currentFilm) { |
| 83 | 0 | this.currentFilm = currentFilm; |
| 84 | |
|
| 85 | 0 | fireCurrentObjectChanged(new ObjectChangedEvent(this, currentFilm)); |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
private static IFilmsService getFilmsService() { |
| 94 | 0 | return Managers.getManager(IBeansManager.class).getBean("filmsService"); |
| 95 | |
} |
| 96 | |
} |