1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.ui.api.location;
35
36 import info.magnolia.event.EventBus;
37 import info.magnolia.ui.api.event.AdmincentralEventBus;
38 import info.magnolia.ui.api.ioc.AdmincentralScoped;
39 import info.magnolia.ui.api.shell.ConfirmationHandler;
40 import info.magnolia.ui.api.shell.Shell;
41
42 import javax.inject.Inject;
43 import javax.inject.Named;
44
45
46
47
48 @AdmincentralScoped
49 public class LocationController {
50
51 private final EventBus eventBus;
52
53 private Shell shell;
54
55 private Location where = Location.NOWHERE;
56
57 @Inject
58 public LocationController(@Named(AdmincentralEventBus.NAME) final EventBus eventBus, Shell shell) {
59 this.eventBus = eventBus;
60 this.shell = shell;
61 }
62
63
64
65
66 public Location getWhere() {
67 return where;
68 }
69
70
71
72
73 public void goTo(final Location newLocation) {
74
75 if (newLocation == null || getWhere().equals(newLocation)) {
76 return;
77 }
78
79 LocationChangeRequestedEventedEvent.html#LocationChangeRequestedEvent">LocationChangeRequestedEvent willChange = new LocationChangeRequestedEvent(newLocation);
80 eventBus.fireEvent(willChange);
81
82
83
84 if (willChange.getWarning() != null) {
85 shell.askForConfirmation(willChange.getWarning(), new ConfirmationHandler() {
86
87 @Override
88 public void onConfirm() {
89 goToWithoutChecks(newLocation);
90 }
91
92 @Override
93 public void onCancel() {
94 }
95 });
96 } else {
97 goToWithoutChecks(newLocation);
98 }
99 }
100
101 protected void goToWithoutChecks(Location newLocation) {
102 this.where = newLocation;
103 eventBus.fireEvent(new LocationChangedEvent(newLocation));
104 }
105 }