MapView.java
3.62 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.insomnia.bortal.view;
import fi.insomnia.bortal.beans.PlaceBeanLocal;
import fi.insomnia.bortal.beans.PlaceMapBeanLocal;
import fi.insomnia.bortal.handler.SessionHandler;
import fi.insomnia.bortal.model.EventMap;
import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author tuukka
*/
@ManagedBean(name = "mapView")
@SessionScoped
public class MapView {
private Logger logger = LoggerFactory.getLogger(MapView.class);
@EJB
private PlaceMapBeanLocal placeMapBean;
@EJB
private PlaceBeanLocal placeBean;
@ManagedProperty("#{sessionHandler}")
private SessionHandler sessionHandler;
private EventMap activeMap = null;
private List<Place> selectedPlaces = new ArrayList<Place>();
//private Place selectedPlace = null;
/** Creates a new instance of MapView */
public MapView() {
}
public void placeSelectActionListener(ActionEvent e) {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = e.getComponent().getClientId(context);
Map requestParams = context.getExternalContext().getRequestParameterMap();
int x = new Integer((String) requestParams.get(clientId + ".x")).intValue();
int y = new Integer((String) requestParams.get(clientId + ".y")).intValue();
Place place = getActiveMap().findPlace(x, y);
if (place != null) {
if (selectedPlaces.contains(place)) {
selectedPlaces.remove(place);
place.setReserved(false);
placeBean.mergeChanges(place);
} else {
selectedPlaces.add(place);
place.setReserved(true);
placeBean.mergeChanges(place);
}
}
logger.debug("Done calling PlaceSelectActionListener");
}
public String getSelectPlaceMapUrl() {
User user = sessionHandler.getUser();
logger.debug("Select map got user: {}", user );
EventMap map = getActiveMap();
logger.debug("Select map got active map: {}", map );
if (map == null) {
return "";
}
String ret = placeMapBean.getSelectPlaceMapUrl(getActiveMap(), selectedPlaces, user);
logger.debug("Returning placemapUrl: {}", ret);
return ret;
}
/**
* @return the activeMap, if it's not setted, return events first map. If this event does not have map, return null.
*/
public EventMap getActiveMap() {
if (activeMap == null) {
if (sessionHandler.getCurrentEvent().getEventMaps().size() >= 1) {
activeMap = sessionHandler.getCurrentEvent().getEventMaps().get(0);
}
}
return activeMap;
}
/**
* @param activeMap the activeMap to set
*/
public void setActiveMap(EventMap activeMap) {
this.activeMap = activeMap;
}
/**
* @return the sessionHandler
*/
public SessionHandler getSessionHandler() {
return sessionHandler;
}
/**
* @param sessionHandler the sessionHandler to set
*/
public void setSessionHandler(SessionHandler sessionHandler) {
this.sessionHandler = sessionHandler;
}
}