| 1 | |
package org.jtheque.films.controllers.impl; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.view.able.controller.AbstractController; |
| 20 | |
import org.jtheque.films.controllers.able.IAutoAddController; |
| 21 | |
import org.jtheque.films.controllers.able.IFilmController; |
| 22 | |
import org.jtheque.films.persistence.od.able.Film; |
| 23 | |
import org.jtheque.films.services.able.IFilmAutoService; |
| 24 | |
import org.jtheque.films.services.able.IFilmsService; |
| 25 | |
import org.jtheque.films.services.impl.utils.EditArguments; |
| 26 | |
import org.jtheque.films.services.impl.utils.web.FilmResult; |
| 27 | |
import org.jtheque.films.view.able.IAutoAddView; |
| 28 | |
|
| 29 | |
import javax.annotation.Resource; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 0 | public final class AutoAddController extends AbstractController implements IAutoAddController { |
| 37 | |
private boolean edit; |
| 38 | |
private EditArguments args; |
| 39 | |
|
| 40 | |
@Resource |
| 41 | |
private IFilmAutoService filmAutoService; |
| 42 | |
|
| 43 | |
@Resource |
| 44 | |
private IFilmsService filmsService; |
| 45 | |
|
| 46 | |
@Resource |
| 47 | |
private IAutoAddView autoAddView; |
| 48 | |
|
| 49 | |
@Resource |
| 50 | |
private IFilmController filmController; |
| 51 | |
|
| 52 | |
@Override |
| 53 | |
public IAutoAddView getView() { |
| 54 | 0 | return autoAddView; |
| 55 | |
} |
| 56 | |
|
| 57 | |
@Override |
| 58 | |
public void add() { |
| 59 | 0 | autoAddView.display(); |
| 60 | 0 | } |
| 61 | |
|
| 62 | |
@Override |
| 63 | |
public void edit() { |
| 64 | 0 | displayView(); |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
@Override |
| 68 | |
public void setFields(EditArguments args) { |
| 69 | 0 | edit = true; |
| 70 | 0 | this.args = args; |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
@Override |
| 74 | |
public void auto(FilmResult selectedFilm) { |
| 75 | 0 | if (edit) { |
| 76 | 0 | Film film = filmController.getViewModel().getCurrentFilm(); |
| 77 | |
|
| 78 | 0 | filmAutoService.modifyFilm(selectedFilm, film, args); |
| 79 | |
|
| 80 | 0 | filmController.view(film); |
| 81 | 0 | filmController.manualEdit(); |
| 82 | 0 | } else { |
| 83 | 0 | Film film = filmAutoService.getFilm(selectedFilm); |
| 84 | |
|
| 85 | 0 | filmsService.create(film); |
| 86 | |
|
| 87 | 0 | filmController.view(film); |
| 88 | |
} |
| 89 | 0 | } |
| 90 | |
|
| 91 | |
@Override |
| 92 | |
public void displayView() { |
| 93 | 0 | super.displayView(); |
| 94 | |
|
| 95 | 0 | if (edit) { |
| 96 | 0 | autoAddView.sendMessage("title", filmController.getViewModel().getCurrentFilm().getTitle()); |
| 97 | |
} |
| 98 | 0 | } |
| 99 | |
} |