MapManageView.java
5.9 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
package fi.insomnia.bortal.view;
import java.math.BigInteger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.ListDataModel;
import org.jboss.weld.bean.builtin.EventBean;
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.PlaceBeanLocal;
import fi.insomnia.bortal.beans.UserBeanLocal;
import fi.insomnia.bortal.enums.Permission;
import fi.insomnia.bortal.enums.RolePermission;
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 {
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 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() {
userBean.fatalPermission(Permission.TICKET_SALES, RolePermission.WRITE, "No right to view all maps in management context");
eventmaps = new ListDataModel<EventMap>(eventBean.getCurrentEvent().getEventMaps());
return eventmaps;
}
public String editMap() {
userBean.fatalPermission(Permission.TICKET_SALES, RolePermission.WRITE, "No right to view all maps in management context");
setMap(eventmaps.getRowData());
return "edit";
}
public String saveMap() {
userBean.fatalPermission(Permission.TICKET_SALES, RolePermission.WRITE, "No right to view all maps in management context");
eventmapBean.saveMap(getMap());
return "edit";
}
public String createMap() {
EventMap map = eventmapBean.create(getMapname());
setMap(map);
return "edit";
}
public void generatePlaces() {
String[] tablenames = getNamebase().split(";");
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 : height * rowI);
int rowYStart = tableYStart + (tablesHorizontal ? width * 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);
map.getPlaces().add(place);
}
}
}
eventmapBean.saveMap(map);
}
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;
}
}