-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriveStatMainController_15022019.java
More file actions
1076 lines (790 loc) · 31.1 KB
/
DriveStatMainController_15022019.java
File metadata and controls
1076 lines (790 loc) · 31.1 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
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
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package de.gsi.csco.ap.app_drivestat.main;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import cern.lsa.domain.settings.BeamProductionChain;
import cern.lsa.domain.settings.Pattern;
import de.gsi.csco.ap.app_drivestat.model.domain.Drive;
import de.gsi.csco.ap.app_drivestat.utils.AboutButton;
import de.gsi.csco.ap.app_drivestat.utils.AutoSavingDialog;
import de.gsi.csco.ap.app_drivestat.utils.DeviceUpdateFESA;
import de.gsi.csco.ap.app_drivestat.utils.DeviceUserNameGenerator;
import de.gsi.csco.ap.app_drivestat.utils.DriveDataJoiner;
import de.gsi.csco.ap.app_drivestat.utils.DriveDataProcessorFESA;
import de.gsi.csco.ap.app_drivestat.utils.DriveDataProcessorLSA;
import de.gsi.csco.ap.app_drivestat.utils.ManualSavingDialog;
import de.gsi.csco.ap.app_drivestat.utils.PrinterDialog;
import de.gsi.csco.ap.app_drivestat.utils.PwdDialog;
import de.gsi.csco.ap.app_drivestat.utils.RetrieveOpticsName;
import de.gsi.csco.ap.app_drivestat.utils.RetrievePatternsAndChains;
import de.gsi.csco.ap.app_drivestat.utils.SaveData;
import de.gsi.sequencer.sequences.superfrs.SetAllFRSDrives;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
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.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.scene.text.TextAlignment;
import javafx.util.Callback;
// for library loggers
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
// for application loggers
// import de.gsi.cs.co.ap.common.gui.elements.logger.AppLogger;
/**
* @author fschirru
*/
public class DriveStatMainController {
// You can choose a logger (needed imports are given in the import section
// as comments):
// for libraries:
// private static final Logger LOGGER =
// LoggerFactory.getLogger(DriveStatMainController.class);
// for applications:
// private static final AppLogger LOGGER = AppLogger.getLogger();
@FXML
private BorderPane borderPane;
@FXML
private TableView<Drive> driveTable;
@FXML
private TableColumn<Drive, String> deviceName_col;
@FXML
private TableColumn<Drive, String> deviceNameDescr_col;
@FXML
private TableColumn<Drive, String> typeName_col;
@FXML
private TableColumn<Drive, Integer> abs_Posi_ds_col;
@FXML
private TableColumn<Drive, Integer> min_Pos_ds_col;
@FXML
private TableColumn<Drive, Integer> max_Pos_ds_col;
@FXML
private TableColumn<Drive, Integer> abs_Posi_pla_col;
@FXML
private TableColumn<Drive, Integer> extra_col1;
@FXML
private TableColumn<Drive, Integer> extra_col2;
@FXML
private Button save_bt;
@FXML
private Button exit_bt;
@FXML
private Button print_bt;
@FXML
private Button graph_bt;
@FXML
private Button settings_bt;
@FXML
private Button about_bt;
@FXML
private ComboBox<Pattern> patterns_cb;
@FXML
private ComboBox<BeamProductionChain> chains_cb;
@FXML
private CheckBox updateDrives_cb;
@FXML
private Label status_lb;
@FXML
private Circle dataSavingLed;
private Pattern selectedPattern;
private List<BeamProductionChain> chains;
private final RetrievePatternsAndChains retrievePatternsAndChains = RetrievePatternsAndChains.getInstance();
private final Map<Pattern, List<BeamProductionChain>> patternsAndChainsMap = retrievePatternsAndChains
.getPatternsAndChains();
private final AboutButton ab = AboutButton.getInstance();
private final AutoSavingDialog asd = AutoSavingDialog.getInstance();
private final DeviceUserNameGenerator dung = DeviceUserNameGenerator.getInstance();
private final DriveDataProcessorLSA ddpLSA = DriveDataProcessorLSA.getInstance();
private final DriveDataProcessorFESA ddpFESA = DriveDataProcessorFESA.getInstance();
private final ManualSavingDialog msd = ManualSavingDialog.getInstance();
private final RetrieveOpticsName ron = RetrieveOpticsName.getInstance();
private final DriveDataJoiner ddpj = DriveDataJoiner.getInstance();
private final PrinterDialog pd = PrinterDialog.getInstance();
private final PwdDialog pwdd = PwdDialog.getInstance();
private final SaveData sd = SaveData.getInstance();
private static int groupIndex = 0;
private Timer timer_dataRecording; // timer for data recorded on disk
private Timer timer_updateDrives;
private Boolean timer_dataRecording_started = false;
private final Boolean timer_updateDrives_started = false;
// private final Boolean aredevicesNamesPainted = false;
// private final Boolean destination_directory_isSelected = false;
// private String selected_directory;
private boolean accessForUpdateDrivesGranted = false;
// private Stage dialogSetDirectoryStage;
// private Stage pwdDialogStage;
private RadialGradient gradient1;
private RadialGradient gradient2;
// private final IntegerProperty isDestinationDirectorySelected = new
// SimpleIntegerProperty(0);
private final IntegerProperty isTableFilledWithData = new SimpleIntegerProperty(0);
private final IntegerProperty isAppRunning = new SimpleIntegerProperty(0);
final Map<String, String> userFriendlyDevicesNamesMap = new HashMap<>();
private final Color[] devicesNamesColor = new Color[200]; // temporary
// solution with
// 200 elements
@FXML
public void initialize() {
gradient1 = new RadialGradient(0, 0, dataSavingLed.getCenterX(), dataSavingLed.getCenterY(),
dataSavingLed.getRadius(), false, CycleMethod.NO_CYCLE, new Stop(0, Color.web("#ffebe6", 1.0)),
new Stop(1, Color.LIGHTGRAY));
gradient2 = new RadialGradient(0, 0, dataSavingLed.getCenterX(), dataSavingLed.getCenterY(),
dataSavingLed.getRadius(), false, CycleMethod.NO_CYCLE, new Stop(0, Color.RED),
new Stop(1, Color.LIGHTGRAY));
dataSavingLed.setFill(gradient1);
save_bt.disableProperty().bind(Bindings.when(asd.getDestinationDirectoryIsSelectedProperty().isNotEqualTo(1)
.or(isTableFilledWithData.isNotEqualTo(1))).then(true).otherwise(false));
settings_bt.disableProperty()
.bind(Bindings.when(isTableFilledWithData.isNotEqualTo(1).or(isAppRunning.isNotEqualTo(1))).then(true)
.otherwise(false));
print_bt.disableProperty().bind(isTableFilledWithData.isNotEqualTo(1));
about_bt.disableProperty().bind(isAppRunning.isNotEqualTo(1));
// updateDrives_cb.disableProperty()
// .bind(Bindings.when(isAppRunning.isNotEqualTo(1).or(isTableFilledWithData.isNotEqualTo(1))).then(true)
// .otherwise(false));
initializeUpdateDrivesAction();
status_lb.setText("");
driveTable.setSelectionModel(null); // it removes the row selection
driveTable.setStyle("-fx-focus-color: LightGray;" + "-fx-faint-focus-color: transparent;"); // it
// changes
// the
// //
// focus
// color
// to
// not
// visible
driveTable.setFocusTraversable(false); // focusing
setPatternsAndChains();
// Initialize column Titles and settings
final Label deviceName_colTitle_lb = new Label("Device ID");
deviceName_colTitle_lb.setPrefHeight(50);
deviceName_colTitle_lb.setWrapText(true);
deviceName_colTitle_lb.setTextAlignment(TextAlignment.CENTER);
deviceName_col.setGraphic(deviceName_colTitle_lb);
deviceName_col.setResizable(false);
deviceName_col.setPrefWidth(118);
deviceName_col.setStyle("-fx-alignment: CENTER-LEFT;");
deviceName_col.setSortable(false);
final Label deviceUFName_colTitle_lb = new Label("Description");
deviceUFName_colTitle_lb.setPrefHeight(50);
deviceUFName_colTitle_lb.setWrapText(true);
deviceUFName_colTitle_lb.setTextAlignment(TextAlignment.CENTER);
deviceNameDescr_col.setGraphic(deviceUFName_colTitle_lb);
deviceNameDescr_col.setResizable(false);
deviceNameDescr_col.setPrefWidth(236);
deviceNameDescr_col.setStyle("-fx-alignment: CENTER-LEFT;");
deviceNameDescr_col.setSortable(false);
final Label deviceType_colTitle_lb = new Label("Type");
deviceType_colTitle_lb.setPrefHeight(50);
deviceType_colTitle_lb.setWrapText(true);
deviceType_colTitle_lb.setTextAlignment(TextAlignment.CENTER);
typeName_col.setGraphic(deviceType_colTitle_lb);
typeName_col.setResizable(false);
typeName_col.setPrefWidth(118);
typeName_col.setStyle("-fx-alignment: CENTER;");
typeName_col.setSortable(false);
final Label minPos_ds_colTitle_lb = new Label("Min Pos." + "\n(mm)");
minPos_ds_colTitle_lb.setPrefHeight(50);
minPos_ds_colTitle_lb.setWrapText(true);
minPos_ds_colTitle_lb.setTextAlignment(TextAlignment.CENTER);
min_Pos_ds_col.setGraphic(minPos_ds_colTitle_lb);
min_Pos_ds_col.setResizable(false);
min_Pos_ds_col.setPrefWidth(118);
min_Pos_ds_col.setStyle("-fx-alignment: CENTER-RIGHT;");
min_Pos_ds_col.setSortable(false);
final Label absPosi_ds_colTitle_lb = new Label("Pos." + "\n(mm)");
absPosi_ds_colTitle_lb.setPrefHeight(50);
absPosi_ds_colTitle_lb.setWrapText(true);
absPosi_ds_colTitle_lb.setTextAlignment(TextAlignment.CENTER);
abs_Posi_ds_col.setGraphic(absPosi_ds_colTitle_lb);
abs_Posi_ds_col.setResizable(false);
abs_Posi_ds_col.setPrefWidth(118);
abs_Posi_ds_col.setStyle("-fx-alignment: CENTER-RIGHT;");
abs_Posi_ds_col.setSortable(false);
final Label maxPos_ds_colTitle_lb = new Label("Max Pos." + "\n(mm)");
maxPos_ds_colTitle_lb.setPrefHeight(50);
maxPos_ds_colTitle_lb.setWrapText(true);
maxPos_ds_colTitle_lb.setTextAlignment(TextAlignment.CENTER);
max_Pos_ds_col.setGraphic(maxPos_ds_colTitle_lb);
max_Pos_ds_col.setResizable(false);
max_Pos_ds_col.setPrefWidth(118);
max_Pos_ds_col.setStyle("-fx-alignment: CENTER-RIGHT;");
max_Pos_ds_col.setSortable(false);
final Label absPosi_pla_colTitle_lb = new Label("Pos." + "\n(IN/OUT[1/0])");
absPosi_pla_colTitle_lb.setPrefHeight(50);
absPosi_pla_colTitle_lb.setWrapText(true);
absPosi_pla_colTitle_lb.setTextAlignment(TextAlignment.CENTER);
abs_Posi_pla_col.setGraphic(absPosi_pla_colTitle_lb);
abs_Posi_pla_col.setResizable(false);
abs_Posi_pla_col.setPrefWidth(118);
abs_Posi_pla_col.setStyle("-fx-alignment: CENTER-RIGHT;");
abs_Posi_pla_col.setSortable(false);
// Columns temporarily not used
extra_col1.setResizable(false);
extra_col1.setPrefWidth(118);
extra_col1.setStyle("-fx-alignment: CENTER-RIGHT;");
extra_col1.setSortable(false);
extra_col2.setResizable(false);
extra_col2.setPrefWidth(107);
extra_col2.setStyle("-fx-alignment: CENTER-RIGHT;");
extra_col2.setSortable(false);
deviceName_col.setCellValueFactory(new PropertyValueFactory<Drive, String>("deviceName"));
typeName_col.setCellValueFactory(new PropertyValueFactory<Drive, String>("deviceType"));
min_Pos_ds_col.setCellValueFactory(new PropertyValueFactory<Drive, Integer>("minPos_ds"));
abs_Posi_ds_col.setCellValueFactory(new PropertyValueFactory<Drive, Integer>("absPosi_ds"));
max_Pos_ds_col.setCellValueFactory(new PropertyValueFactory<Drive, Integer>("maxPos_ds"));
abs_Posi_pla_col.setCellValueFactory(new PropertyValueFactory<Drive, Integer>("absPosi_pla"));
deviceNameDescr_col.setCellFactory(new Callback<TableColumn<Drive, String>, TableCell<Drive, String>>() {
@Override
public TableCell<Drive, String> call(final TableColumn<Drive, String> param) {
return new TableCell<Drive, String>() {
@Override
protected void updateItem(final String item, final boolean empty) {
super.updateItem(item, empty);
if (!empty) {
final int index = getTableRow().getIndex();
if (index < ddpj.getData().size() && index >= 0) {
// Get the device description corresponding to
// the given device name
final String device_description = dung
.retrieveUserFriendlyDevicesNames(ddpj.getData().get(index).getDeviceName());
// final String device_description =
// retrieveUserFriendlyDevicesNames(
// ddpj.getData().get(index).getDeviceName());
// System.out.println(index);
// System.out.println(ddpj.getData().size());
setText(device_description);
}
}
}
};
}
});
min_Pos_ds_col.setCellFactory(new Callback<TableColumn<Drive, Integer>, TableCell<Drive, Integer>>() {
@Override
public TableCell<Drive, Integer> call(final TableColumn<Drive, Integer> param) {
return new TableCell<Drive, Integer>() {
@Override
protected void updateItem(final Integer item, final boolean empty) {
super.updateItem(item, empty);
// if (!empty) {
driveTable.refresh(); // very important!!!!!
final int index = getTableRow().getIndex();
if (index < ddpj.getData().size() && index >= 0) {
// System.out.println(index);
// System.out.println(ddpj.getData().size());
if (ddpj.getData().get(index).getDeviceType().equals("DS")) {
setText(Double.toString((double) item / (double) 10));
} else {
setText(null);
}
}
}
};
}
});
max_Pos_ds_col.setCellFactory(new Callback<TableColumn<Drive, Integer>, TableCell<Drive, Integer>>() {
@Override
public TableCell<Drive, Integer> call(final TableColumn<Drive, Integer> param) {
return new TableCell<Drive, Integer>() {
@Override
protected void updateItem(final Integer item, final boolean empty) {
super.updateItem(item, empty);
// if (!empty) {
driveTable.refresh(); // very important!!!!!
final int index = getTableRow().getIndex();
if (getTableRow().getIndex() < ddpj.getData().size() && index >= 0) {
if (ddpj.getData().get(index).getDeviceType().equals("DS")) {
setText(Double.toString((double) item / (double) 10));
} else {
setText(null);
}
}
}
};
}
});
abs_Posi_ds_col.setCellFactory(new Callback<TableColumn<Drive, Integer>, TableCell<Drive, Integer>>() {
@Override
public TableCell<Drive, Integer> call(final TableColumn<Drive, Integer> param) {
return new TableCell<Drive, Integer>() {
@Override
protected void updateItem(final Integer item, final boolean empty) {
super.updateItem(item, empty);
// if (!empty) {
driveTable.refresh(); // very important!!!!!
final int index = getTableRow().getIndex();
if (getTableRow().getIndex() < ddpj.getData().size() && index >= 0) {
if (ddpj.getData().get(index).getDeviceType().equals("DS")) {
setText(Double.toString((double) item / (double) 10));
} else {
setText(null);
}
}
}
};
}
});
abs_Posi_pla_col.setCellFactory(new Callback<TableColumn<Drive, Integer>, TableCell<Drive, Integer>>() {
@Override
public TableCell<Drive, Integer> call(final TableColumn<Drive, Integer> param) {
return new TableCell<Drive, Integer>() {
@Override
protected void updateItem(final Integer item, final boolean empty) {
super.updateItem(item, empty);
// if (!empty) {
driveTable.refresh(); // very important!!!!!
final int index = getTableRow().getIndex();
if (getTableRow().getIndex() < ddpj.getData().size() && index >= 0) {
if (ddpj.getData().get(index).getDeviceType().equals("PLA")) {
setText(Integer.toString(item));
// Green OUT, RED in
if (item == 0) {
// Update Drives
// startDataRecording();
setTextFill(Color.GREEN);
}
if (item == 1) {
setTextFill(Color.RED);
}
if (item == 2) {
setTextFill(Color.GRAY);
}
} else {
setText(null);
}
}
}
};
}
});
// deviceName_col.setCellFactory(null);
driveTable.setMaxHeight(650);
driveTable.setFixedCellSize(25);
// Creating the mouse event handler
final EventHandler<ActionEvent> eventHandler_chains_cb = new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
/*
*
* if (timer_started) {
*
* // the following operation must be done otherwise will be
* created multiple timers timer.cancel(); // this is vital to
* restart the timer (for data saving and updating LSA) //
* whenever user switches a patter/chain }
*
* if (timer_dataRecording_started) {
*
* timer_dataRecording.cancel(); // this is vital to restart the
* timer (for data saving and // updating LSA) whenever user
* switches a patter/chain }
*
* //closeAllSubscriptions(); //mdpj.getData().clear();
*
* // createTable();
*/
// restore groudIndex for group color
// groupIndex = 0;
createTable();
}
};
// Adding event Filter
chains_cb.setOnAction(eventHandler_chains_cb);
patterns_cb.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Pattern>() {
@Override
public void changed(final ObservableValue<? extends Pattern> observable, final Pattern oldValue,
final Pattern newValue) {
selectedPattern = patterns_cb.getSelectionModel().getSelectedItem();
chains = patternsAndChainsMap.get(selectedPattern);
chains_cb.setOnAction(null);
chains_cb.getItems().clear();
chains_cb.getItems().addAll(chains);
chains_cb.setOnAction(eventHandler_chains_cb);
chains_cb.getSelectionModel().selectFirst();
}
});
// restore groudIndex for group color
// groupIndex = 0;
createTable();
}
private void createDeviceNamesTextColor() {
// Disable ComboBoxes patterns and chains
patterns_cb.setDisable(true);
chains_cb.setDisable(true);
groupIndex = 0;
driveTable.refresh();
// Reset colors
for (int c = 0; c < devicesNamesColor.length; c++) {
devicesNamesColor[c] = null;
}
if (ddpj.getData().size() != 0) {
for (int i = 0; i < ddpj.getData().size(); i++) {
String acceleratorZoneItem = "";
String acceleratorZonePreviousItem = "";
// acceleratorZoneItem =
// ddpj.getData().get(i).getDeviceAcceleratorZone().getName();
acceleratorZoneItem = dung.retrieveUserFriendlyDevicesNames(ddpj.getData().get(i).getDeviceName())
.substring(0, 3);
if (i == 0) {
devicesNamesColor[i] = Color.DARKBLUE;
} else {
acceleratorZoneItem = dung.retrieveUserFriendlyDevicesNames(ddpj.getData().get(i).getDeviceName())
.substring(0, 3);
// acceleratorZonePreviousItem = ddpj.getData().get(i -
// 1).getDeviceAcceleratorZone().getName();
acceleratorZonePreviousItem = dung
.retrieveUserFriendlyDevicesNames(ddpj.getData().get(i - 1).getDeviceName())
.substring(0, 3);
if (!acceleratorZoneItem.equals(acceleratorZonePreviousItem)) {
groupIndex++;
}
if (groupIndex % 2 == 0) {
devicesNamesColor[i] = Color.DARKBLUE;
// devicesNamesColor.add(Color.DARKBLUE);
} else {
devicesNamesColor[i] = Color.CORNFLOWERBLUE;
// devicesNamesColor.add(Color.CORNFLOWERBLUE);
}
}
}
deviceName_col.setCellFactory(new Callback<TableColumn<Drive, String>, TableCell<Drive, String>>() {
@Override
public TableCell<Drive, String> call(final TableColumn<Drive, String> param) {
return new TableCell<Drive, String>() {
@Override
protected void updateItem(final String item, final boolean empty) {
if (!empty) {
if (ddpj.getData().size() != 0) {
driveTable.refresh();
super.updateItem(item, empty);
final int index = getTableRow().getIndex();
// setTextFill(devicesNamesColor[index]);
setText(item);
setTextFill(devicesNamesColor[index]);
}
}
}
};
}
});
}
}
private void setPatternsAndChains() {
try {
final Iterator<Map.Entry<Pattern, List<BeamProductionChain>>> it = patternsAndChainsMap.entrySet()
.iterator();
while (it.hasNext()) {
final Map.Entry<Pattern, List<BeamProductionChain>> pair = it.next();
// System.out.println(pair//Update Drives
// startDataRecording();.getKey() + " = " + pair.getValue());
// it.remove(); // avoids a ConcurrentModificationException
patterns_cb.getItems().add(pair.getKey());
}
patterns_cb.getSelectionModel().selectFirst();
selectedPattern = patterns_cb.getSelectionModel().getSelectedItem();
chains = patternsAndChainsMap.get(selectedPattern);
// chains = selectedPattern.getChains();
chains_cb.getItems().clear();
chains_cb.getItems().addAll(chains);
chains_cb.getSelectionModel().selectFirst();
} catch (final Exception e) {
final Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Application Error");
// alert.setHeaderText("Look, an Error Dialog");
alert.setContentText("Error while loading the Patterns and Chains. Please try later.");
alert.showAndWait();
// timer.cancel();
Platform.exit();
System.exit(0);
// System.exit(0); // using Platform.exit() the main Stage pops up
// for a while!
}
}
private void createTable() {
accessForUpdateDrivesGranted = false;
updateDrives_cb.setDisable(true);
// Disable ComboBoxes while loading data
patterns_cb.setDisable(true);
chains_cb.setDisable(true);
closeAllSubscriptions();
// deviceName_col.setCellFactory(null);
// devicesNamesColor.clear();
isAppRunning.set(0);
isTableFilledWithData.set(0);// Update Drives
// aredevicesNamesPainted = false;
// startDataRecording();
// groupIndex = 0;
final BeamProductionChain chain = chains_cb.getValue();
final Task<Void> task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
/*
* Platform.runLater(() -> {
*
* loadingDevicesDialogStage.show(); //
* showLoadingDevicesDialogue(); });
*/
updateMessage("Please wait while loading data...");
driveTable.getItems().clear();
driveTable.refresh();
ddpLSA.setPattern(selectedPattern);
ddpLSA.setBeamChain(chain);
ddpLSA.setStaticDevices(); // Setting of devices belonging to
// the FRS static reference
ron.setBeamChain(chain);
if (ddpLSA.getDriveData().size() != 0) {
ddpFESA.setBeamChain(chain);
// ddpFESA.setFrsDevices();
ddpFESA.setDevices();
ddpj.joinData();
// driveTable.refresh();
// driveTable.setItems(ddpj.getData());
}
driveTable.refresh();
return null;
}
};
status_lb.textProperty().bind(task.messageProperty());
// java 8 construct, replace with java 7 code if using java 7.
task.setOnSucceeded(e -> {
status_lb.textProperty().unbind();
// this message will be seen.
if (ddpj.getData().size() != 0) {
status_lb.setText("Data successfully loaded. Elements [" + ddpj.getData().size() + "]");
isTableFilledWithData.set(1);
// aredevicesNamesPainted = true;
// driveTable.setItems(ddpj.getData());
driveTable.setItems(ddpj.getData());
driveTable.refresh();
createDeviceNamesTextColor();
// Enable ComboBoxes
// patterns_cb.setDisable(false);
// chains_cb.setDisable(false);
// Enable ComboBoxes patterns and chains
patterns_cb.setDisable(false);
chains_cb.setDisable(false);
updateDrives_cb.setSelected(false);
updateDrives_cb.setDisable(false);
// Start all device subscriptions
ddpFESA.generateDeviceSubscriptions();
} else {
status_lb.setText("Can not retrieve data from the selected Pattern/Chain.");
isTableFilledWithData.set(0);
// Enable ComboBoxes patterns and chains
patterns_cb.setDisable(false);
chains_cb.setDisable(false);
}
// Start timer for dataRecording
if (!timer_dataRecording_started) {
timer_dataRecording = new Timer();
timer_dataRecording.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
startDataRecording();
}
}, 0, 60000);
timer_dataRecording_started = true;
}
// Start timer for drives update
if (!timer_updateDrives_started) {
timer_updateDrives = new Timer();
timer_updateDrives.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (accessForUpdateDrivesGranted) {
final String patternName = selectedPattern.getName();
final List<String> deviceNames = new ArrayList<>();
System.out.println("ACCESS GRANTED");
System.out.println("List of devices injected to runSequence");
// System.exit(0);
// filling the list containing all device names
for (int n = 0; n < ddpj.getData().size(); n++) {
deviceNames.add(ddpj.getData().get(n).getDeviceName());
System.out.println(ddpj.getData().get(n).getDeviceName());
}
System.out.println(patternName);
// System.exit(0);
try {
SetAllFRSDrives.runSequence(deviceNames, patternName);
} catch (final RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// System.exit(0);
}
}
}
}, 0, 10000);
timer_dataRecording_started = true;
}
// Make the related buttons operative
isAppRunning.set(1);
});
task.setOnFailed(e -> {
status_lb.textProperty().unbind();
status_lb.setText("Can not retrieve data from the selected Pattern/Chain.");
isTableFilledWithData.set(0);
// Unlock patterns and chains combos
patterns_cb.setDisable(false);
chains_cb.setDisable(false);
});
final Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
@FXML
private void handleAbout() {
ab.showAboutStage();
}
@FXML
private void handleExit() {
// maybe not necessary since tasks are Daemon
if (timer_dataRecording_started) {
timer_dataRecording.cancel();
}
if (timer_updateDrives_started) {
timer_updateDrives.cancel();
}
closeAllSubscriptions();
/*
* System.out.println("*** DATA ***"); for (int i = 0; i <
* ddpj.getData().size(); i++) {
*
* System.out.println(ddpj.getData().get(i).getDeviceName() + " " +
* ddpj.getData().get(i).getDeviceAcceleratorZone().getParticleTransfers
* ());
*
* }
*/
Platform.exit();
System.exit(0);
}
@FXML
private void handleSettings() {
asd.setData();
// destination_directory_isSelected = false;
asd.getAutoSavingDialogStage().showAndWait();
// asd.requestFocusOnCloseButton(); // can not work because previously
// Showand"wait" is invoked!!
if (asd.getDestinationDirectoryIsSelectedProperty().getValue() == 1
&& asd.getIsAutoSavingOnProperty().getValue() == 1) {
dataSavingLed.setFill(gradient2);
startTimerForDataRecording(asd.getSavingFileFreq());
} else {
dataSavingLed.setFill(gradient1);
}
}
@FXML
private void handleManualSaving() {
if (ddpj.getData().size() != 0 && asd.getDestinationDirectoryIsSelectedProperty().getValue() == 1) {
msd.setData(patterns_cb.getSelectionModel().getSelectedItem().getName(),
chains_cb.getSelectionModel().getSelectedItem().getName(), ron.getOpticsName(),
asd.getSelectedDirectory());
msd.getManualSavingDialogStage().show();
}
}
@FXML
private void handlePrint() {
pd.setPatternAndChain(patterns_cb.getSelectionModel().getSelectedItem().getName(),
chains_cb.getSelectionModel().getSelectedItem().getName());
pd.ShowPrinterDialog();
}
private void initializeUpdateDrivesAction() {
updateDrives_cb.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(final ObservableValue<? extends Boolean> observable, final Boolean oldValue,
final Boolean newValue) {
if (newValue) {
if (updateDrives_cb.isSelected()) {
// accessForUpdateDrivesGranted = false;
// updateDrives_cb.setSelected(false);
// pwdDialogStage.show();
pwdd.showPwdDialogStage();
pwdd.closePwdDialog();
// Grant access
if (pwdd.getAccess().getValue().intValue() == 1) {
accessForUpdateDrivesGranted = true;
updateDrives_cb.setDisable(true);
} else {
accessForUpdateDrivesGranted = false;
updateDrives_cb.setSelected(false);