-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlanningPokerController.java
268 lines (232 loc) · 6.57 KB
/
PlanningPokerController.java
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
261
262
263
264
265
266
267
268
package application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;
import java.util.ArrayList;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.*;
//Controller for the Planning Poker page - MJ
public class PlanningPokerController
{
//Same fields being stored as in Main Menu controller - MJ
private Employee user;
private String accessType;
private ProjectDataBase projects;
private Project project;
public String projName;
private Task task;
private ArrayList<Task> taskList;
private ArrayList<String> taskNames;
private ArrayList<Integer> estimates;
//FXML fields for button and label - MJ
@FXML
private Button addStory;
@FXML
private Label accessLabel;
@FXML
private Button back;
@FXML
private ComboBox<String> tasks = new ComboBox<String>();
@FXML
private TextField newTask;
@FXML
private Button submit;
//Setter method to take in the reference to the project database - MJ
public void setProjects(ProjectDataBase projects)
{
this.projects = projects;
taskNames = new ArrayList<String>();
taskList = new ArrayList<Task>();
estimates = new ArrayList<Integer>();
}
public void setEstimates(ArrayList<Integer> estimates)
{
this.estimates = estimates;
}
public void setTask(Task task)
{
this.task = task;
}
public void setProject(Project project)
{
this.project = project;
}
public void setTasks(ArrayList<String> taskNames, ArrayList<Task> tasks)
{
this.taskNames = taskNames;
this.taskList = tasks;
}
@FXML
public void nextPage(ActionEvent event)
{
try {
FXMLLoader load = new FXMLLoader(getClass().getResource("AddUserStories.fxml"));
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
Scene scene = new Scene(load.load());
AddUserStoriesController ctrl = load.getController();
ctrl.setAccess(user);
ctrl.setProjects(projects);
Platform.runLater(() -> {
ctrl.setProject(project);
});
ctrl.setTask(task);
ctrl.setTasks(taskNames, taskList);
stage.setScene(scene);
stage.setTitle("Add User Stories!");
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public void check()
{
System.out.println(this.project == null);
}
//Setter method for the label displaying employee access type - MJ
@FXML
public void setLabel()
{
accessLabel.setText("Access Type: " + accessType);
}
//EventHandler for the back button to take user to main - MJ
@FXML
public void goBack(ActionEvent event)
{
try {
FXMLLoader load = new FXMLLoader(getClass().getResource("MainMenu.fxml"));
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
Scene scene = new Scene(load.load());
MainMenuController ctrl = load.getController();
ctrl.setAccess(user);
ctrl.setProjects(projects);
stage.setScene(scene);
stage.setTitle("Main Menu Effort Logger");
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
@FXML
public void addTask(ActionEvent event)
{
String taskChosen = newTask.getText();
if(!taskChosen.equals(""))
{
if(!taskNames.contains(taskChosen))
{
taskNames.add(taskChosen);
Task task = new Task();
task.setName(taskChosen);
taskList.add(task);
estimates.add(-1);
tasks.getItems().add(taskChosen + " - Estimate: -1");
}
else
{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error!");
alert.setHeaderText("Unable to add task name.");
alert.setContentText("Please choose a name you haven't picked yet!");
alert.showAndWait();
}
}
newTask.setText("");
}
public void updateTask(Task task, int estimate)
{
int idx = taskNames.indexOf(task.getName());
taskList.set(idx, task);
estimates.set(idx, estimate);
ArrayList<String> menuItems = new ArrayList<String>();
for(int i = 0; i < taskList.size(); i++)
{
menuItems.add(taskNames.get(i) + " - Estimate: " + estimates.get(i));
}
tasks.getItems().clear();
tasks.setItems(FXCollections.observableArrayList(menuItems));
tasks.getSelectionModel().select(0);
tasks.getSelectionModel().clearSelection();
//projects.getProject(project.getName()).getTask(task.getName()).setEstimate(estimate);
}
@FXML
public void chooseTask(ActionEvent event)
{
String name = tasks.getValue();
int end = name.indexOf('-');
name = name.substring(0, end-1);
Task task = taskList.get(taskNames.indexOf(name));
try {
FXMLLoader load = new FXMLLoader(getClass().getResource("AddUserStories.fxml"));
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
Scene scene = new Scene(load.load());
AddUserStoriesController ctrl = load.getController();
ctrl.setAccess(user);
ctrl.setProjects(projects);
ctrl.setProject(project);
ctrl.setTask(task);
ctrl.setTasks(taskNames, taskList);
ctrl.setEstimates(estimates);
ctrl.setTask(task);
stage.setScene(scene);
stage.setTitle("Add User Stories");
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public void endGame(ActionEvent event)
{
if(estimates.size() != 0 && !estimates.contains(-1))
{
try {
FXMLLoader load = new FXMLLoader(getClass().getResource("PokerEndScreen.fxml"));
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
Scene scene = new Scene(load.load());
PokerEndScreenController ctrl = load.getController();
ctrl.setAccess(user);
ctrl.setProjects(projects);
ctrl.setProject(project);
ctrl.setTasks(taskNames, taskList);
ctrl.setEstimates(estimates);
ctrl.setTask(task);
ctrl.setLabel();
stage.setScene(scene);
stage.setTitle("Add User Stories");
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error!");
alert.setHeaderText("Cannot end the game yet!");
alert.setContentText("Please make sure you have added and completed estimating all tasks.");
alert.showAndWait();
}
}
//Setter method for the accessType field used in the
//access label - MJ
public void setAccess(Employee empType)
{
user = empType;
if(user.getClass() == SoftwareEngineer.class)
{
accessType = "Software Engineer";
}
else if(user.getClass() == QAEngineer.class)
{
accessType = "Quality Assurance";
}
else
{
accessType =" Administration";
}
}
}