TournamentCreateView.java
4.67 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
package fi.codecrew.moya.web.cdiview.tournaments;
import java.io.Serializable;
import java.util.List;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.enums.TournamentType;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import org.primefaces.event.FlowEvent;
@Named
@ConversationScoped
public class TournamentCreateView extends GenericCDIView {
private static final long serialVersionUID = 2547358764980373797L;
private List<TournamentGame> tournamentGames;
private List<TournamentRule> tournamentRules;
private TournamentRule rules = null;
private TournamentGame game = null;
private Tournament tournament = null;
private String tournamentGameName;
private String tournamentGameDescription;
private String rulesetName;
private String rulesetDescription;
private String rulesetRules;
private Integer backupPlayers;
@EJB TournamentBeanLocal tournamentBean;
@EJB EventBeanLocal eventBean;
public void initView() {
if(tournament == null) {
this.beginConversation();
tournament = new Tournament();
tournament.setPlayersPerMatch(0);
backupPlayers = 0;
tournamentGames = tournamentBean.getGames();
}
}
public void save(ActionEvent actionEvent) {
tournament.setPlayersPerTeam(tournament.getPlayersPerMatch() + backupPlayers);
tournament.setLanEvent(eventBean.getCurrentEvent());
tournament.setTournamentStatus(TournamentStatus.SETUP);
tournament.setTournamentGame(game);
tournament.setRules(rules);
tournamentBean.createTournament(tournament);
}
public List<TournamentGame> getTournamentGames() {
return tournamentGames;
}
public List<TournamentRule> getTournamentRules() {
return tournamentRules;
}
public void uploadListener(org.primefaces.event.FileUploadEvent event) {
System.out.println("ZZ");
}
public TournamentType[] getTournamentTypes() {
TournamentType[] items = TournamentType.values();
return items;
}
public String onFlowProcess(FlowEvent event) {
switch(event.getOldStep()) {
case "selectGame":
if(tournamentGameName.length() > 0) {
// oh lurd, we want to create a new gamy now
TournamentGame tg = new TournamentGame();
tg.setName(tournamentGameName);
tg.setDescription(tournamentGameDescription);
tg.setLanEvent(eventBean.getCurrentEvent());
tournamentBean.createGame(tg);
}
tournamentRules = tournamentBean.getRulesByGame(game);
System.out.println(tournamentRules);
break;
case "selectRuleset":
if(rulesetName != null && rulesetName.length() > 0) {
TournamentRule tr = new TournamentRule();
tr.setName(rulesetName);
tr.setDescription(rulesetDescription);
tr.setRules(rulesetRules);
tr.setTournamentGame(game);
rules = tournamentBean.createRule(tr);
tournamentRules = tournamentBean.getRulesByGame(game);
}
break;
}
return event.getNewStep();
}
public TournamentGame getGame() {
return game;
}
public void setGame(TournamentGame game) {
this.game = game;
}
public TournamentRule getRules() {
return rules;
}
public void setRules(TournamentRule rules) {
this.rules = rules;
}
public String getTournamentGameName() {
return tournamentGameName;
}
public void setTournamentGameName(String tournamentGameName) {
this.tournamentGameName = tournamentGameName;
}
public String getTournamentGameDescription() {
return tournamentGameDescription;
}
public void setTournamentGameDescription(String tournamentGameDescription) {
this.tournamentGameDescription = tournamentGameDescription;
}
public String getRulesetName() {
return rulesetName;
}
public void setRulesetName(String rulesetName) {
this.rulesetName = rulesetName;
}
public String getRulesetDescription() {
return rulesetDescription;
}
public void setRulesetDescription(String rulesetDescription) {
this.rulesetDescription = rulesetDescription;
}
public Tournament getTournament() {
return tournament;
}
public void setTournament(Tournament tournament) {
this.tournament = tournament;
}
public Integer getBackupPlayers() {
return backupPlayers;
}
public void setBackupPlayers(Integer backupPlayers) {
this.backupPlayers = backupPlayers;
}
public String getRulesetRules() {
return rulesetRules;
}
public void setRulesetRules(String rulesetRules) {
this.rulesetRules = rulesetRules;
}
}