| 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.IKindController; |
| 23 | |
import org.jtheque.primary.controller.impl.undo.CreatedKindEdit; |
| 24 | |
import org.jtheque.primary.od.able.Kind; |
| 25 | |
import org.jtheque.primary.services.able.IKindsService; |
| 26 | |
import org.jtheque.primary.view.able.IKindView; |
| 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 KindController extends AbstractController implements IKindController { |
| 37 | 0 | private ViewMode state = ViewMode.NEW; |
| 38 | |
private Kind currentKind; |
| 39 | |
|
| 40 | |
@Resource |
| 41 | |
private IKindsService kindsService; |
| 42 | |
|
| 43 | |
@Resource |
| 44 | |
private IKindView kindView; |
| 45 | |
|
| 46 | |
@Override |
| 47 | |
public IKindView getView() { |
| 48 | 0 | return kindView; |
| 49 | |
} |
| 50 | |
|
| 51 | |
@Override |
| 52 | |
public void newKind() { |
| 53 | 0 | state = ViewMode.NEW; |
| 54 | |
|
| 55 | 0 | kindView.reload(); |
| 56 | 0 | currentKind = kindsService.getEmptyKind(); |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
@Override |
| 60 | |
public void editKind(Kind kind) { |
| 61 | 0 | state = ViewMode.EDIT; |
| 62 | |
|
| 63 | 0 | kindView.reload(kind); |
| 64 | 0 | currentKind = kind; |
| 65 | |
|
| 66 | 0 | displayView(); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public void save(String name) { |
| 71 | 0 | currentKind.setName(name); |
| 72 | |
|
| 73 | 0 | if (state == ViewMode.NEW) { |
| 74 | 0 | kindsService.create(currentKind); |
| 75 | |
|
| 76 | 0 | Managers.getManager(IUndoRedoManager.class).addEdit(new CreatedKindEdit(currentKind)); |
| 77 | |
} else { |
| 78 | 0 | kindsService.save(currentKind); |
| 79 | |
} |
| 80 | 0 | } |
| 81 | |
} |