| 1 | |
package org.jtheque.primary.controller.impl; |
| 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.undo.IUndoRedoManager; |
| 21 | |
import org.jtheque.core.managers.view.able.controller.AbstractController; |
| 22 | |
import org.jtheque.primary.controller.able.ICountryController; |
| 23 | |
import org.jtheque.primary.controller.impl.undo.CreatedCountryEdit; |
| 24 | |
import org.jtheque.primary.od.able.Country; |
| 25 | |
import org.jtheque.primary.services.able.ICountriesService; |
| 26 | |
import org.jtheque.primary.view.able.ICountryView; |
| 27 | |
import org.jtheque.primary.view.able.ViewMode; |
| 28 | |
|
| 29 | |
import javax.annotation.Resource; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 0 | public final class CountryController extends AbstractController implements ICountryController { |
| 37 | 0 | private ViewMode state = ViewMode.NEW; |
| 38 | |
private Country currentCountry; |
| 39 | |
|
| 40 | |
@Resource |
| 41 | |
private ICountriesService countriesService; |
| 42 | |
|
| 43 | |
@Resource |
| 44 | |
private ICountryView countryView; |
| 45 | |
|
| 46 | |
@Override |
| 47 | |
public void newCountry() { |
| 48 | 0 | state = ViewMode.NEW; |
| 49 | |
|
| 50 | 0 | countryView.reload(); |
| 51 | 0 | currentCountry = countriesService.getEmptyCountry(); |
| 52 | 0 | } |
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public void editCountry(Country country) { |
| 56 | 0 | state = ViewMode.EDIT; |
| 57 | |
|
| 58 | 0 | countryView.reload(country); |
| 59 | 0 | currentCountry = country; |
| 60 | |
|
| 61 | 0 | displayView(); |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
@Override |
| 65 | |
public void save(String name) { |
| 66 | 0 | currentCountry.setName(name); |
| 67 | |
|
| 68 | 0 | if (state == ViewMode.NEW) { |
| 69 | 0 | countriesService.create(currentCountry); |
| 70 | |
|
| 71 | 0 | Managers.getManager(IUndoRedoManager.class).addEdit(new CreatedCountryEdit(currentCountry)); |
| 72 | |
} else { |
| 73 | 0 | countriesService.save(currentCountry); |
| 74 | |
} |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
@Override |
| 78 | |
public ICountryView getView() { |
| 79 | 0 | return countryView; |
| 80 | |
} |
| 81 | |
} |