-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
955 lines (856 loc) · 26.1 KB
/
Main.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import Controller.KanbanController;
import Controller.LaneController;
import Controller.UserController;
import Model.Kanban;
import Model.Lane;
import Model.Ticket;
import Model.User;
import View.UserView;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
public class Main extends Application{
Stage window;
static KanbanController kc;
static LaneController lc;
static Kanban kanban;
public BorderPane layout = new BorderPane();
public static GridPane mainGrid;
//Height and width of tickets
final int TICKET_HEIGHT = 150;
final static int TICKET_WIDTH = 150;
public boolean alreadyLoaded = false;
public static void main(String[] args) {
kc = new KanbanController(null);
//Creating the main Grid Pane
mainGrid = new GridPane();
mainGrid.setPadding(new Insets(0,TICKET_WIDTH,0,TICKET_WIDTH));
mainGrid.setId("ggg");
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
/*
Scene s = userView.splashPage();
*/
GridPane gp = createGridPane();
Text title = new Text("Please login to an exsiting Kanban or create a new one");
gp.add(title, 0, 1);
Button login = new Button("Login To Existing");
gp.add(login, 0, 3);
login.setOnAction(e->{
window.close();
loginAUser();
});
Button newBoard = new Button("Create New");
gp.add(newBoard, 1, 3);
newBoard.setOnAction(ex->{
window.close();
Kanban kanban1 = new Kanban("");
KanbanController kc = new KanbanController(kanban1);
kc.createDefaultKanban();
newKanban(kanban1);
});
window = primaryStage;
Scene s = new Scene(gp);
window.setTitle("Welcome");
window.setScene(s);
window.show();
}
private void newKanban(Kanban k){
BorderPane layout = new BorderPane();
GridPane gp = createGridPane();
Scene s = new Scene(layout, 400, 200);
Stage x = new Stage();
Text title = new Text("\n"
+ " Please enter your details so we can create an account for you");
layout.setTop(title);
Label nameLabel = new Label("Name");
gp.add(nameLabel, 0,0);
TextField nameInput = new TextField();
gp.add(nameInput, 1, 0);
Label passwordLabel = new Label("Password");
gp.add(passwordLabel, 0, 2);
TextField passwordInput = new TextField();
gp.add(passwordInput, 1, 2);
Button enterDetails = new Button("Create account");
gp.add(enterDetails, 1, 3);
layout.setCenter(gp);
enterDetails.setOnAction(e->{
User user = new User("","");
String name = nameInput.getText();
String password = passwordInput.getText();
if (name.length()> 0 && password.length()>0){
kc = new KanbanController(k);
UserController uc = new UserController(user);
uc.createProductOwner(name, password, kc.incrementID());
kanban = k;
kc = new KanbanController(kanban);
kc.loginUser(user);
ArrayList<User> ki =kanban.getUserArray();
ki.add(user);
kanban.setUserArray(ki);
//kc.addUserToArray(user);
x.close();
Alert alert = new Alert(AlertType.INFORMATION, "User name: "+user.getUserName()
+"\nPassword: "+user.getPassword());
showKanban();
alert.show();
}else{
Alert alert = new Alert(AlertType.ERROR,"One or more Fields has no content");
alert.show();
}
});
x.setScene(s);
x.show();
}
private void loginAUser(){
Stage s = new Stage();
BorderPane bp = new BorderPane();
Text title = new Text("Please enter your login details.");
bp.setPadding(new Insets(10,10,10,10));
bp.setTop(title);
GridPane gp = createGridPane();
//User name
Label userNamelLabel = new Label("User Name");
gp.add(userNamelLabel, 0, 0);
TextField userNameInput = new TextField();
gp.add(userNameInput, 1, 0);
//Password
Label passwordLabel = new Label("Password");
gp.add(passwordLabel, 0, 1);
TextField passwordInput = new TextField();
gp.add(passwordInput, 1, 1);
Button login = new Button("login");
gp.add(login, 1, 2);
bp.setCenter(gp);
login.setOnAction(e->{
String userName = userNameInput.getText();
String password = passwordInput.getText();
if (userName.length()>0 && password.length()>0){
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
/*
*Default path here is where the testing folder is
*/
//fileChooser.setInitialDirectory(new File("C:\\Users\\chris\\Documents\\College\\Eclipse\\ICS\\Saves"));
File file = fileChooser.showOpenDialog(window);
Kanban x = null;
try {
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream in = new ObjectInputStream(fileIn);
x = (Kanban) in.readObject();
in.close();
fileIn.close();
}catch(IOException i) {
i.printStackTrace();
return;
}catch(ClassNotFoundException c) {
c.printStackTrace();
return;
}
kc = new KanbanController(x);
User user = kc.findUserByID(userName);
if (user != null){
if (user.getPassword().equals(password)){
System.out.println("User Found");
kanban = x;
kc = new KanbanController(kanban);
// @ TODO
kc.loginUser(user);
if (alreadyLoaded == false){
showKanban();
}else{
updateBoard();
}
s.close();
}else{
Alert alert = new Alert(AlertType.ERROR,"Incorrect Password");
alert.show();
}
}else{
Alert alert = new Alert(AlertType.ERROR, "Either you have entered a bad username or there is no accounant\n"
+ "\nby the user: "+userName+" on this kanban");
alert.show();
}
}
});
Scene scene = new Scene(bp, 400,180);
s.setScene(scene);
s.show();
}
/**
* Uses an file chooser to get a kanban from the
* "Saves" directory
* @return a file
*/
public Kanban getAKanban(){
Stage primaryStage = new Stage();
Window window = primaryStage;
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
fileChooser.setInitialDirectory(new File("C:\\Users\\chris\\Documents\\College\\Eclipse\\ICS\\Saves"));
File file = fileChooser.showOpenDialog(window);
//Loading in a file
Kanban kanban = new Kanban("");
KanbanController kc = new KanbanController(kanban);
kc.loadIn(file);
return kanban;
}
private void showKanban(){
alreadyLoaded = true;
Stage stage = new Stage();
window.setTitle("Kanban Board");
ScrollPane scroller = new ScrollPane();
scroller.setContent(null);
mainGrid.getChildren().clear();
scroller.setContent(mainGrid);
layout.setCenter(scroller);
layout.setLeft(CreateTicketWindow());
//File Menu
Menu fileMenu = new Menu("File");
//User MEnu
Menu user = new Menu("User");
MenuItem addUser = new MenuItem("Add a User");
MenuItem loginUser = new MenuItem("Login A User");
user.getItems().add(loginUser);
user.getItems().add(addUser);
addUser.setOnAction(q ->{
createDev();
});
loginUser.setOnAction(ty ->{
loginAUser();
});
//Menu Items
MenuItem save = new MenuItem("Save Kanban Board...");
MenuItem load = new MenuItem("Load Kanban Board");
fileMenu.getItems().add(load);
load.setOnAction(loader ->{
loginAUser();
});
fileMenu.getItems().add(save);
save.setOnAction(saver -> {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save File");
fileChooser.setInitialDirectory(new File("C:\\Users\\chris\\Documents\\College\\Eclipse\\ICS\\Saves"));
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("SER", "*.ser")
);
File file = fileChooser.showSaveDialog(window);
kc.saveKanban(file);
});
//Edit Menu
Menu editMenu = new Menu("Edit");
//Adding sub items to this menu
MenuItem addTicket = new MenuItem("Add a ticket...");
MenuItem createNewLane = new MenuItem("Create New Lane");
MenuItem deleteALane = new MenuItem("Delete A Lane");
MenuItem splitLane = new MenuItem("Split A Lane");
MenuItem deleteSubLane = new MenuItem("Delete A Local Done Lane");
editMenu.getItems().add(addTicket);
editMenu.getItems().add(createNewLane);
editMenu.getItems().add(deleteALane);
editMenu.getItems().add(splitLane);
editMenu.getItems().add(deleteSubLane);
//Main Menu Bar
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(fileMenu);
menuBar.getMenus().add(editMenu);
menuBar.getMenus().add(user);
//Insering this into the layout
layout.setTop(menuBar);
//Create the scene
Scene scene = new Scene(layout,740,300);
scene.getStylesheets().add("CSS.css");
stage.setScene(scene);
stage.show();
//when "Add ticket is clicked"
addTicket.setOnAction(e->{
window = new Stage();
window.setTitle("Add Ticket");
//Create a label called task
Label task = new Label("Task: ");
//Create a textfield called input
TextField taskInput = new TextField();
//Create a button that when clicked creates the ticket
Button create = new Button("Add Ticket");
//Create the grid pane
GridPane gp = createGridPane();
gp.add(task, 0, 2);
gp.add(taskInput, 1, 2);
gp.add(create, 0, 4);
updateBoard();
Scene s = new Scene(gp,400,200);
window.setScene(s);
window.show();
//when the create ticket button is clicked
create.setOnAction(e2->{
Ticket newTicket;
String ticketTask = taskInput.getText();
newTicket = new Ticket(0,ticketTask);
kc = new KanbanController(kanban);
Lane lane = kc.getALane("Backlog");
newTicket.setTicketID(kc.incrementID());
lc = new LaneController(lane);
lc.addATicket(newTicket);
updateBoard();
window.close();
});
});
//when "insert lane" is clicked
createNewLane.setOnAction(e->{
createNewLane();
});
deleteALane.setOnAction(l4->{
deleteALane();
});
splitLane.setOnAction(er ->{
createSubLane();
});
deleteSubLane.setOnAction(op -> {
deleteSubLane();
});
updateBoard();
}
private void createDev() {
window = new Stage();
window.setTitle("New User");
Label owner = new Label("Devloper Name");
TextField ownerInput = new TextField();
Label passwordL = new Label("New Password");
TextField passwordIn = new TextField();
Button create = new Button("Create New User");
create.setOnAction(e_->{
String name = ownerInput.getText();
String password = passwordIn.getText();
if (name.length()<0 && password.length()<0){
Alert alert = new Alert(AlertType.ERROR, "One or more fields has not been filled");
alert.show();
}else{
kc = new KanbanController(kanban);
User user = new User("","");
UserController userC = new UserController(user);
userC.createSoftwareDev(name, password, kc.incrementID());
kanban.getUserArray().add(user);
Alert alert = new Alert(AlertType.INFORMATION, "Your user-name is "+user.getUserName()
+"\nYour password is "+user.getPassword());
alert.show();
window.close();
}
});
GridPane gp = createGridPane();
gp.setId("grid");
gp.add(owner, 0, 2);
gp.add(ownerInput, 1, 2);
gp.add(passwordL, 0, 3);
gp.add(passwordIn, 1, 3);
gp.add(create, 0, 6);
Scene s = new Scene(gp,400,200);
window.setScene(s);
window.show();
}
private static GridPane createGridPane(){
GridPane gp = new GridPane();
gp.setPadding(new Insets(10, 10, 10, 10));
gp.setVgap(15);
gp.setHgap(10);
return gp;
}
private StackPane createTicket(Ticket t){
//Creating the textObject for the task
Text task = new Text(t.getTicketName());
//Sets its max length
task.setWrappingWidth(TICKET_WIDTH);
///////////////////////////////////
////Backing for the rectangles////
/////////////////////////////////
Rectangle baseBox = new Rectangle();
baseBox.setHeight(TICKET_HEIGHT+10);
baseBox.setWidth(TICKET_WIDTH+10);
baseBox.setFill(Color.WHITE);
////////////////////////////
///Making the Sticky note//
//////////////////////////
Rectangle tickBox = new Rectangle();
tickBox.setHeight(TICKET_HEIGHT);
tickBox.setWidth(TICKET_WIDTH);
/*
*Setting the colour of the rectangle
*If it is in a blocked status it will be red
*
*/
if (t.isBlockedStatus()){
tickBox.setFill(Color.RED);
}else{
tickBox.setFill(Color.YELLOW);
}
//////////////////////////////////
//Placing these in a stack pane //
/////////////////////////////////
StackPane layout = new StackPane();
layout.getChildren().addAll(baseBox,tickBox, task);
layout.setAlignment(task, Pos.TOP_LEFT);
layout.setId("TickBox");
//Creating the context menu
ContextMenu ticketContext = new ContextMenu();
MenuItem moveTick = new MenuItem("Move A Ticket");
//Setting what happens when move a ticket is clicked
moveTick.setOnAction(e ->{
moveATicket(t);
});
MenuItem moveTicketSub = new MenuItem("Move To SubLane");
moveTicketSub.setOnAction(q ->{
moveToSubLane(t);
});
MenuItem editTicket = new MenuItem("Edit A Ticket");
editTicket.setOnAction(r -> {
editTicket(t);
});
MenuItem removeSub = new MenuItem("Remove From local done lane");
removeSub.setOnAction(pop ->{
removeFromSub(t);
});
//Adding the items to the context menu
ticketContext.getItems().addAll(moveTick,editTicket,moveTicketSub,removeSub);
//@ TODO Stop context menu showing the remoce from sublane if ticket is not in sublane
//Adding the event listener for the context menu to the layout
layout.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent me) -> {
if (me.getButton() == MouseButton.SECONDARY || me.isControlDown()) {
ticketContext.show(layout, me.getScreenX(), me.getScreenY());
} else {
ticketContext.hide();
}
});
return layout;
}
/**
* Used to create titles for the top of lanes
* @param title The text for the top of the lanes
* @param sub If it is going to be used as the heading for a sub-lane
* @return A StackPane with the text centred in the middle and the
*/
private StackPane createTitle(String title, boolean sub){
StackPane pane = new StackPane();
Text t = new Text(title);
if (sub == false){
t.setFont(Font.font("Aerial", FontWeight.BOLD, 12));
}else{
t.setFont(Font.font("Aerial", FontPosture.ITALIC, 12));
}
pane.getChildren().addAll(t);
pane.setMinWidth(TICKET_WIDTH);
pane.setId("titlePane");
return pane;
}
private void moveATicket(Ticket t){
boolean outcome = kc.moveATicket(t);
System.out.println("The move operation for ticket "+t.getTicketName()+" was a: ");
if (outcome == true){
System.out.print("success");
updateBoard();
}else{
Alert alert = new Alert(AlertType.ERROR, "Ticket is already in done lane");
alert.show();
System.out.print("failure");
}
}
private void moveToSubLane(Ticket t){
boolean outcome = kc.moveTicketToSub(t);
if (outcome == false){
window = new Stage();
GridPane gp = createGridPane();
window.setTitle("Error");
Text windowTitle = new Text("Lane does not have a local done"
+ "\nWould you like to create one");
gp.add(windowTitle, 1, 1);
Button yes = new Button("Yes");
gp.add(yes, 2, 3);
Button no = new Button("No");
gp.add(no, 4, 3);
Scene scene = new Scene(gp,300,130);
window.setScene(scene);
window.show();
yes.setOnAction(e->{
Lane lane = kc.laneHasTicket(t);
lc = new LaneController(lane);
boolean splitOutcome = lc.splitALane();
if (splitOutcome == true){
kc.replaceALane(lane);
window.close();
Alert alert = new Alert(AlertType.CONFIRMATION, "Success");
alert.show();
kc.moveTicketToSub(t);
updateBoard();
}
else{
window.close();
Alert alert = new Alert(AlertType.ERROR, "Operation has failed, lane cannot be split");
alert.show();
}
});
no.setOnAction(r -> {
window.close();
});
}
updateBoard();
}
/**
* Updates the grid pane which displays all the ticket and lane data
* should be called after any change to the actual GUI of the board
*/
private void updateBoard(){
ArrayList<Lane> listOfLanes = kanban.getLaneArray();
mainGrid.getChildren().clear();
int countColumn = 0;
for(int count =0; count<listOfLanes.size(); count++){
//Getting the current lane
Lane lane = listOfLanes.get(count);
//Setting the title
//adding it to the top of its column
StackPane pane = createTitle(lane.getName(), false);
mainGrid.add(pane,countColumn,0);
//Getting the array of tickets from the lane
ArrayList<Ticket> listOfTickets = lane.getLaneArr();
//Adding in all the tickets
for (int i =0; i<listOfTickets.size(); i++){
Ticket t = listOfTickets.get(i);
mainGrid.add(createTicket(t), countColumn, 1+i);
}
//Part where we add sub lanes
//Checking to see if it contains a sub lane
if (lane.getBooleanArr()[3] == true){
//Incrementing the column count
countColumn++;
//Creating a title
StackPane subPane = createTitle("sub - "+lane.getName(), true);
//Placing it a row below
mainGrid.add(subPane, countColumn, 0);
ArrayList<Ticket> subList = lane.getSubLaneArr();
//Inserting in all tickets
for (int y=0; y<subList.size(); y++){
Ticket ticket = subList.get(y);
mainGrid.add(createTicket(ticket), countColumn, 1+y);
}
}
countColumn++;
}
}
/**
* The right click menu for the ticket editing interface
* @param ticket
*/
private void editTicket(Ticket ticket){
// kc = new KanbanController(kanban);
window = new Stage();
GridPane gp = new GridPane();
window.setTitle("Edit Ticket");
Text windowTitle = new Text ("Edit a Ticket");
gp.add(windowTitle, 0, 0);
Label task = new Label("Task Name:");
gp.add(task, 0, 1);
TextField taskInput = new TextField(ticket.getTicketName());
gp.add(taskInput, 1, 1);
Label blocked = new Label("Blocked Status");
gp.add(blocked, 0, 2);
CheckBox blockedStatus = new CheckBox();
blockedStatus.setSelected(ticket.isBlockedStatus());
gp.add(blockedStatus, 1, 2);
Label priority = new Label("Set Priority");
gp.add(priority, 0, 3);
Slider slider = new Slider();
slider.setMin(0);
slider.setMax(100);
slider.setBlockIncrement(10);
slider.setValue(ticket.getPriority());
gp.add(slider,1,3);
//////////////////////////////////
//Event handlers for done button//
//////////////////////////////////
Button done = new Button("Done");
done.setOnAction(e-> {
boolean success = true;
String taskTitle = taskInput.getText();
if (taskTitle.length()>0){
ticket.setTicketName(taskTitle);
System.out.println("Name :"+taskInput.getText());
}else{
Alert alert= new Alert(Alert.AlertType.ERROR, "Please enter text in the task field");
alert.show();
success = false;
}
ticket.setBlockedStatus(blockedStatus.isSelected());
System.out.println("Status: " + blockedStatus.isSelected());
ticket.setPriority((int) slider.getValue());
System.out.println("Priority: "+slider.getValue());
if (success == true){
kc.findATicketAndReplace(ticket);
updateBoard();
window.close();
}
});
gp.add(done, 1, 4);
Button delete = new Button("Delete Ticket");
gp.add(delete, 2, 4);
delete.setOnAction(e->{
Lane lane = kc.laneHasTicket(ticket);
lc.removeATicket(ticket, kanban.getCurrentUser());
kc.replaceALane(lane);
updateBoard();
window.close();
});
if(kanban.getCurrentUser().isOwner() == false){
slider.setDisable(true);
delete.setDisable(true);
}
Scene scene = new Scene(gp,400,400);
window.setScene(scene);
window.show();
}
/**
* GUI for lane creation
*/
private void createNewLane(){
window = new Stage();
window.setTitle("Create New Lane");
Label laneName = new Label("Lane Name: ");
TextField nameInput = new TextField();
Label lanePos= new Label("Lane Position: ");
TextField posInput = new TextField();
Button create = new Button("Insert Lane");
GridPane gp = createGridPane();
gp.add(laneName, 0, 2);
gp.add(nameInput, 1, 2);
gp.add(lanePos, 0, 4);
gp.add(posInput, 1, 4);
gp.add(create, 0, 5);
Scene s = new Scene(gp,400,200);
window.setScene(s);
window.show();
create.setOnAction(e2->{
String name = nameInput.getText();
int position = Integer.parseInt(posInput.getText());
position++;
if (name.length()>0){
boolean validate = kc.createAUserLane(name, position);
if (validate == false){
Alert alert = new Alert(AlertType.ERROR, "You have entered an inavalid name or position");
alert.show();
}
else{
window.close();
updateBoard();
}
}else{
Alert alert = new Alert(AlertType.ERROR, "You have left the lane name section empty");
alert.show();
}
});
}
/**
* GUI for lane deletion
*/
private void deleteALane(){
window = new Stage();
window.setTitle("Delete");
Label laneName = new Label("Lane Name: ");
TextField nameInput = new TextField();
Button create = new Button("Delete");
GridPane gp = createGridPane();
gp.add(laneName, 0, 2);
gp.add(nameInput, 1, 2);
gp.add(create, 0, 4);
Scene s = new Scene(gp,400,200);
window.setScene(s);
window.show();
create.setOnAction(e2->{
boolean validate = kc.removeALane(nameInput.getText());
if (validate == false){
Alert alert = new Alert(AlertType.ERROR,
"You have either entered an invalid name "
+ "\nor the lane cannot be deleted"
+ "\nor it contains tickets");
alert.show();
}
else{
window.close();
updateBoard();
}
});
}
/**
* GUI for sub lane Creation
*/
private void createSubLane(){
window = new Stage();
window.setTitle("Create Sub-Lane");
Label laneName = new Label("Lane Name: ");
TextField nameInput = new TextField();
Button create = new Button("Create Sub");
GridPane gp = createGridPane();
gp.add(laneName, 0, 2);
gp.add(nameInput, 1, 2);
gp.add(create, 0, 4);
Scene s = new Scene(gp,400,200);
window.setScene(s);
window.show();
create.setOnAction(e2->{
String laneNameS = nameInput.getText();
if (laneNameS.length()>0){
Lane lane = kc.findALane(nameInput.getText());
if (lane!=null){
lc = new LaneController(lane);
boolean outcome = lc.splitALane();
if (outcome == true){
kc.replaceALane(lane);
System.out.println("Opeartion of splitting lane "+lane.getName()+ "was a success");
window.close();
updateBoard();
}
else {
Alert alert = new Alert(AlertType.ERROR, "You have entered an inavalid name or position");
alert.show();
}
}
}else{
Alert alert = new Alert(AlertType.ERROR, "You have entered an inavalid name or position");
alert.show();
}
});
}
private void removeFromSub(Ticket ticket){
boolean outcome = kc.removeFromSub(ticket);
if (outcome == false){
Alert alert = new Alert(AlertType.ERROR, "Not in a local done lane");
alert.show();
}
updateBoard();
}
/**
* GUI for local sub deletion
*/
private void deleteSubLane(){
window = new Stage();
window.setTitle("Delete Local Done Lane");
Label laneName = new Label("Lane Name: ");
TextField nameInput = new TextField();
Button delete = new Button("Delete Local-Done");
GridPane gp = createGridPane();
gp.add(laneName, 0, 2);
gp.add(nameInput, 1, 2);
gp.add(delete, 0, 4);
Scene s = new Scene(gp,400,200);
window.setScene(s);
window.show();
delete.setOnAction(e ->{
String nameOfLane = nameInput.getText();
if (nameOfLane.length()>0){
Lane lane = kc.getALane(nameOfLane);
if (lane != null){
lc = new LaneController(lane);
boolean splitWorked = lc.unSplitLane();
if (splitWorked == true){
kc.replaceALane(lane);
window.close();
updateBoard();
}
else{
//Lane has Tickets or not split
Alert alert = new Alert(AlertType.ERROR, "Lane has tickets or does not have a local done" );
alert.show();
}
}else{
//Lane does not Exist
Alert alert = new Alert(AlertType.ERROR, "Lane by name "+nameInput.getText()+" does not exist");
alert.show();
}
}else{
Alert alert = new Alert(AlertType.ERROR, "Please enter text in the field lane name");
alert.show();
}
});
}
/**
* GUI for the left create ticket window
* @return
*/
private GridPane CreateTicketWindow(){
GridPane gp =createGridPane();
Text windowTitle = new Text ("Edit a Ticket");
gp.add(windowTitle, 0, 0);
Label task = new Label("Task Name:");
gp.add(task, 0, 1);
TextField taskInput = new TextField();
gp.add(taskInput, 1, 1);
Label blocked = new Label("Blocked Status");
gp.add(blocked, 0, 2);
CheckBox blockedStatus = new CheckBox();
gp.add(blockedStatus, 1, 2);
Label priority = new Label("Set Priority");
gp.add(priority, 0, 3);
Slider slider = new Slider();
slider.setMin(0);
slider.setMax(100);
slider.setBlockIncrement(10);
slider.setShowTickMarks(true);
gp.add(slider,1,3);
Button done = new Button("Create");
done.setOnAction(e-> {
String task1 = taskInput.getText();
if (task1.length()>0){
kc = new KanbanController(kanban);
Lane lane = kc.getALane("Backlog");
Ticket ticket1 = new Ticket(kc.incrementID(),task1);
ticket1.setTicketID(kc.incrementID());
lc = new LaneController(lane);
lc.addATicket(ticket1);
updateBoard();
taskInput.clear();
blockedStatus.setSelected(false);
slider.setValue(0);
}else{
Alert alert = new Alert(AlertType.ERROR,"Please enter text for field \"Task Name\"");
alert.show();
}
});
gp.add(done, 1, 4);
if(kanban.getCurrentUser().isOwner() == false){
slider.setDisable(true);
}
return gp;
}
}