MapManageView.java
5.68 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
package fi.insomnia.bortal.view;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.ListDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.beans.EventMapBeanLocal;
import fi.insomnia.bortal.beans.PermissionDeniedException;
import fi.insomnia.bortal.beans.PlaceBeanLocal;
import fi.insomnia.bortal.beans.UserBeanLocal;
import fi.insomnia.bortal.model.EventMap;
import fi.insomnia.bortal.model.Place;
import fi.insomnia.bortal.model.Product;
@ManagedBean(name = "mapManageView")
@SessionScoped
public class MapManageView extends GenericView {
private static final Logger logger = LoggerFactory.getLogger(MapManageView.class);
@EJB
private UserBeanLocal userBean;
@EJB
private EventBeanLocal eventBean;
@EJB
private EventMapBeanLocal eventmapBean;
@EJB
private PlaceBeanLocal placebean;
private ListDataModel<EventMap> eventmaps;
private EventMap map;
private String mapname;
private String buyableLike;
private boolean tablesHorizontal = false;
private boolean oneRowTable = false;
private int placesInRow = 1;
private int width;
private int height;
private int startX;
private int startY;
private int tableCount = 1;
private int tableXdiff;
private int tableYdiff;
private Product mapproduct;
private String namebase;
public ListDataModel<EventMap> getMaps() {
eventmaps = new ListDataModel<EventMap>(eventBean.getCurrentEvent().getEventMaps());
return eventmaps;
}
public String lockBuyable() {
int count = placebean.setBuyable(map, buyableLike, false);
this.addFaceMessage("mapManage.lockedPlaces", count);
return null;
}
public String releaseBuyable() {
int count = placebean.setBuyable(map, buyableLike, true);
this.addFaceMessage("mapManage.releasedPlaces", count);
return null;
}
public String editMap() {
setMap(eventmaps.getRowData());
return "edit";
}
public String saveMap() {
eventmapBean.saveMap(getMap());
return "edit";
}
public String createMap() {
EventMap map;
try {
map = eventmapBean.create(getMapname());
setMap(map);
} catch (PermissionDeniedException e) {
logger.info("Permission denied", e);
}
return "edit";
}
public void generatePlaces() {
String[] tablenames = getNamebase().split(";");
List<Place> mapplaces = map.getPlaces();
logger.debug("places in map before {}", mapplaces.size());
if (mapplaces == null || mapplaces.isEmpty()) {
mapplaces = new ArrayList<Place>();
map.setPlaces(mapplaces);
}
for (int tableI = 0; tableI < tableCount; ++tableI) {
int tableXStart = tableI * tableXdiff;
int tableYStart = tableI * tableYdiff;
int rows = isOneRowTable() ? 1 : 2;
for (int rowI = 0; rowI < rows; ++rowI) {
int rowXStart = tableXStart + (tablesHorizontal ? 0 : width * rowI);
int rowYStart = tableYStart + (tablesHorizontal ? height * rowI : 0);
logger.debug("row start {} {}", rowXStart, rowYStart);
for (int placeI = 1; placeI <= placesInRow; ++placeI) {
Place place = new Place(map);
place.setHeight(Math.abs(height));
place.setWidth(Math.abs(width));
int xpos = startX + rowXStart + (tablesHorizontal ? placeI * width : 0);
int ypos = startY + rowYStart + (tablesHorizontal ? 0 : placeI * height);
logger.debug("Creating map in {} {}", xpos, ypos);
place.setMapX(xpos);
place.setMapY(ypos);
place.setProduct(mapproduct);
place.setName(tablenames[tableI] + (placeI + placesInRow * rowI));
mapplaces.add(place);
}
}
}
logger.debug("places in map after {}", mapplaces.size());
map = eventmapBean.saveMap(map);
logger.debug("places in map merge {}", map.getPlaces().size());
}
public void setMapname(String mapname) {
this.mapname = mapname;
}
public String getMapname() {
return mapname;
}
public void setMap(EventMap map) {
this.map = map;
}
public EventMap getMap() {
return map;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getStartX() {
return startX;
}
public void setStartX(int startX) {
this.startX = startX;
}
public int getStartY() {
return startY;
}
public void setStartY(int startY) {
this.startY = startY;
}
public Product getMapproduct() {
return mapproduct;
}
public void setMapproduct(Product mapproduct) {
this.mapproduct = mapproduct;
}
public String getNamebase() {
return namebase;
}
public int getTableCount() {
return tableCount;
}
public void setTableCount(int tableCount) {
this.tableCount = tableCount;
}
public int getTableXdiff() {
return tableXdiff;
}
public void setTableXdiff(int tableXdiff) {
this.tableXdiff = tableXdiff;
}
public int getTableYdiff() {
return tableYdiff;
}
public void setTableYdiff(int tableYdiff) {
this.tableYdiff = tableYdiff;
}
public void setTablesHorizontal(boolean tablesHorizontal) {
this.tablesHorizontal = tablesHorizontal;
}
public boolean isTablesHorizontal() {
return tablesHorizontal;
}
public void setPlacesInRow(int placesInRow) {
this.placesInRow = placesInRow;
}
public int getPlacesInRow() {
return placesInRow;
}
public void setOneRowTable(boolean oneRowTable) {
this.oneRowTable = oneRowTable;
}
public boolean isOneRowTable() {
return oneRowTable;
}
public void setNamebase(String namebase) {
this.namebase = namebase;
}
public void setBuyableLike(String buyableLike) {
this.buyableLike = buyableLike;
}
public String getBuyableLike() {
return buyableLike;
}
}