-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExternalProjectsSyncController.java
More file actions
674 lines (583 loc) · 28.3 KB
/
ExternalProjectsSyncController.java
File metadata and controls
674 lines (583 loc) · 28.3 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
// Copyright 2025 doubleSlash Net Business GmbH
//
// This file is part of KeepTime.
// KeepTime is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package de.doubleslash.keeptime.view;
import de.doubleslash.keeptime.common.BrowserHelper;
import de.doubleslash.keeptime.common.DateFormatter;
import de.doubleslash.keeptime.common.Resources;
import de.doubleslash.keeptime.common.SvgNodeProvider;
import de.doubleslash.keeptime.controller.HeimatController;
import de.doubleslash.keeptime.model.Project;
import de.doubleslash.keeptime.model.Work;
import de.doubleslash.keeptime.rest.integration.heimat.model.HeimatTask;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.RotateTransition;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.SVGPath;
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.util.converter.LocalTimeStringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeParseException;
import java.time.format.FormatStyle;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Predicate;
import static de.doubleslash.keeptime.view.ReportController.copyToClipboard;
@Component
public class ExternalProjectsSyncController {
private static final Logger LOG = LoggerFactory.getLogger(ExternalProjectsSyncController.class);
@FXML
private TableView<TableRow> mappingTableView;
@FXML
private Button saveButton;
@FXML
private Button cancelButton;
@FXML
private Label dayOfSyncLabel;
@FXML
private Label sumTimeLabel;
@FXML
private Label keepTimeTimeLabel;
@FXML
private Label heimatTimeLabel;
@FXML
private Hyperlink externalSystemLink;
@FXML
private Hyperlink externalSystemLinkLoadingScreen;
@FXML
private VBox loadingScreen;
@FXML
private AnchorPane pane;
@FXML
private Label loadingMessage;
@FXML
private Label loadingClosingMessage;
@FXML
private Region syncingIconRegion;
@FXML
private ComboBox<HeimatTask> heimatTaskComboBox;
@FXML
private Button addHeimatTaskButton;
private final SVGPath loadingSpinner = SvgNodeProvider.getSvgNodeWithScale(Resources.RESOURCE.SVG_SPINNER_SOLID, 0.1,
0.1);
private final SVGPath loadingSuccess = SvgNodeProvider.getSvgNodeWithScale(Resources.RESOURCE.SVG_THUMBS_UP_SOLID,
0.1, 0.1);
private final SVGPath loadingFailure = SvgNodeProvider.getSvgNodeWithScale(Resources.RESOURCE.SVG_XMARK_SOLID, 0.1,
0.1);
private final Color colorLoadingSpinner = Color.valueOf("#00A5E1");
private final Color colorLoadingSuccess = Color.valueOf("#74a317");
private final Color colorLoadingFailure = Color.valueOf("#c63329");
private final LocalTimeStringConverter localTimeStringConverter = new LocalTimeStringConverter(FormatStyle.MEDIUM);
private ObservableList<TableRow> items;
private LocalDate currentReportDate;
private Stage thisStage;
private final HeimatController heimatController;
private final RotateTransition loadingSpinnerAnimation = new RotateTransition(Duration.seconds(1),
syncingIconRegion);
public ExternalProjectsSyncController(final HeimatController heimatController) {
this.heimatController = heimatController;
}
public void initForDate(LocalDate currentReportDate, List<Work> currentWorkItems) {
dayOfSyncLabel.setText(DateFormatter.toDayDateString(currentReportDate));
this.currentReportDate = currentReportDate;
// TODO add a spinner while loading?
final List<HeimatController.Mapping> tableRows = heimatController.getTableRows(currentReportDate,
currentWorkItems);
items = FXCollections.observableArrayList(tableRows.stream().map(mapping -> {
String userNotes = mapping.keeptimeNotes();
long userSeconds = mapping.keeptimeSeconds();
// use info from heimat when already present
if (mapping.heimatSeconds() != 0L) {
userNotes = mapping.heimatNotes();
userSeconds = mapping.heimatSeconds();
}
return new TableRow(mapping, userNotes, userSeconds);
}).toList());
mappingTableView.setItems(items);
ObservableList<TableRow> items2 = FXCollections.observableArrayList(
item -> new javafx.beans.Observable[] { item.userTimeSeconds, item.shouldSyncCheckBox, item.userNotes });
items2.addAll(items);
StringBinding totalSum = Bindings.createStringBinding(() -> localTimeStringConverter.toString(
LocalTime.ofSecondOfDay(
items.stream().filter(item -> item.mapping.heimatTaskId() != -1L) // if its bookable in heimat
.mapToLong(item -> {
if (item.shouldSyncCheckBox.get())
return item.userTimeSeconds.getValue();
else
return item.heimatTimeSeconds.get();
}).sum())), items2);
sumTimeLabel.textProperty().bind(totalSum);
keepTimeTimeLabel.setText(localTimeStringConverter.toString(
LocalTime.ofSecondOfDay(tableRows.stream().mapToLong(HeimatController.Mapping::keeptimeSeconds).sum())));
heimatTimeLabel.setText(localTimeStringConverter.toString(
LocalTime.ofSecondOfDay(tableRows.stream().mapToLong(HeimatController.Mapping::heimatSeconds).sum())));
BooleanBinding projectsValidProperty = Bindings.createBooleanBinding(() -> items.stream().anyMatch(item -> {
boolean shouldSync = item.shouldSyncCheckBox.get();
boolean hasNote = !item.userNotes.get().isBlank();
boolean hasTime = areSecondsOfDayValid(item.userTimeSeconds.get());
return shouldSync && !(hasNote && hasTime);
}), items2);
saveButton.disableProperty().bind(projectsValidProperty);
externalSystemLink.setOnAction(ae -> BrowserHelper.openURL(heimatController.getUrlForDay(currentReportDate)));
externalSystemLinkLoadingScreen.setOnAction(
ae -> BrowserHelper.openURL(heimatController.getUrlForDay(currentReportDate)));
final List<HeimatTask> tasksForDay = heimatController.getTasks(currentReportDate);
final FilteredList<HeimatTask> tasksNotInList = new FilteredList<>(FXCollections.observableArrayList(tasksForDay),
(task) -> items.stream().noneMatch(tr -> task.id() == tr.mapping.heimatTaskId()));
items.addListener((ListChangeListener<? super TableRow>) c -> {
final Predicate<? super HeimatTask> predicate = tasksNotInList.getPredicate();
tasksNotInList.setPredicate(null);
tasksNotInList.setPredicate(predicate);
});
heimatTaskComboBox.setItems(tasksNotInList);
addHeimatTaskButton.disableProperty()
.bind(heimatTaskComboBox.getSelectionModel().selectedItemProperty().isNull());
addHeimatTaskButton.setOnAction(ae -> {
final HeimatTask task = heimatTaskComboBox.getValue();
final TableRow addedRow = new TableRow(new HeimatController.Mapping(task.id(), true, true,
"Manually added\n\nSync to " + task.name() + "\n(" + task.taskHolderName() + ")", List.of(), List.of(),
"", "", 0, 0), "", 0);
items.add(addedRow);
items2.add(addedRow); // add new row also to items2 - as it is not added automatically :(
heimatTaskComboBox.getSelectionModel().clearSelection();
mappingTableView.scrollTo(items.size() - 1); // scroll to newly added row
});
}
@FXML
private void initialize() {
heimatTaskComboBox.setCellFactory(param -> new ListCell<>() {
@Override
protected void updateItem(HeimatTask item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
} else {
setText(item.taskHolderName() + " - " + item.name());
}
}
});
heimatTaskComboBox.setButtonCell(new ListCell<>() {
@Override
protected void updateItem(HeimatTask item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
} else {
setText(item.name() + " - " + item.taskHolderName());
}
}
});
initializeLoadingScreen();
TableColumn<TableRow, TableRow> shouldSyncColumn = new TableColumn<>("Sync");
shouldSyncColumn.setCellValueFactory(data -> new SimpleObjectProperty<>(data.getValue()));
// Custom Cell Factory to disable CheckBoxes
shouldSyncColumn.setCellFactory(col -> new TableCell<>() {
private final CheckBox checkBox = new CheckBox();
private ChangeListener<Boolean> boolChangeListener;
@Override
protected void updateItem(TableRow item, boolean empty) {
super.updateItem(item, empty);
if (boolChangeListener != null)
checkBox.selectedProperty().removeListener(boolChangeListener);
if (empty || item == null) {
setGraphic(null);
} else {
checkBox.setDisable(!item.mapping.canBeSynced());
checkBox.setSelected(item.shouldSyncCheckBox.get());
boolChangeListener = (obs, oldText, newBoolean) -> item.shouldSyncCheckBox.set(newBoolean);
checkBox.selectedProperty().addListener(boolChangeListener);
setAlignment(Pos.TOP_CENTER);
setGraphic(checkBox);
}
}
});
mappingTableView.setEditable(true);
shouldSyncColumn.setEditable(true);
TableColumn<TableRow, List<Project>> projectColumn = new TableColumn<>("Project");
projectColumn.setCellValueFactory(data -> new SimpleObjectProperty<>(data.getValue().mapping.projects()));
projectColumn.setCellFactory(column -> new TableCell<>() {
@Override
protected void updateItem(List<Project> item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setGraphic(null);
setText(null);
} else {
VBox vbox = new VBox(5);
item.forEach(project -> vbox.getChildren().add(createRow(project.getColor(), project.getName())));
setGraphic(vbox);
}
}
private HBox createRow(Color color, String text) {
Circle circle = new Circle(6, color);
Label label = new Label(text);
return new HBox(5, circle, label);
}
});
TableColumn<TableRow, TableRow> timeColumn = new TableColumn<>("Time");
timeColumn.setCellValueFactory(data -> new SimpleObjectProperty<>(data.getValue())); // Placeholder property
Consumer<Spinner<LocalTime>> spinnerValidConsumer = (Spinner<LocalTime> spinner) -> {
final boolean isValid = areSecondsOfDayValid(spinner.getValue().toSecondOfDay());
markNodeValidOrNot(spinner, isValid);
};
timeColumn.setCellFactory(column -> new TableCell<>() {
private final Spinner<LocalTime> timeSpinner = new Spinner<>();
private final Label keeptimeLabel = new Label();
private final Label heimatLabel = new Label();
private ChangeListener<LocalTime> localTimeChangeListener;
private final VBox container = new VBox(5); // Space between TextArea and Label
{
setUpTimeSpinner(timeSpinner);
container.getChildren().addAll(timeSpinner, keeptimeLabel, heimatLabel);
}
@Override
protected void updateItem(TableRow item, boolean empty) {
super.updateItem(item, empty);
if (localTimeChangeListener != null)
timeSpinner.valueProperty().removeListener(localTimeChangeListener);
if (empty || item == null) {
setGraphic(null);
} else {
keeptimeLabel.setText("KeepTime: " + localTimeStringConverter.toString(
LocalTime.ofSecondOfDay(item.keeptimeTimeSeconds.get())));
heimatLabel.setText("Heimat: " + localTimeStringConverter.toString(
LocalTime.ofSecondOfDay(item.heimatTimeSeconds.get())));
timeSpinner.setDisable(!item.mapping.canBeSynced());
timeSpinner.getValueFactory().setValue(LocalTime.ofSecondOfDay(0));
if (item.mapping.canBeSynced()) {
timeSpinner.getValueFactory().setValue(LocalTime.ofSecondOfDay(item.userTimeSeconds.get()));
localTimeChangeListener = (observable, oldValue, newValue) -> {
item.userTimeSeconds.set(newValue.toSecondOfDay());
spinnerValidConsumer.accept(timeSpinner);
};
spinnerValidConsumer.accept(timeSpinner);
timeSpinner.valueProperty().addListener(localTimeChangeListener);
}
setGraphic(container);
}
}
});
TableColumn<TableRow, TableRow> notesColumn = new TableColumn<>("Notes");
notesColumn.setCellValueFactory(data -> new SimpleObjectProperty<>(data.getValue())); // Placeholder property
Consumer<TextArea> textAreaValid = (TextArea textArea) -> {
final boolean isValid = !textArea.getText().isBlank();
markNodeValidOrNot(textArea, isValid);
};
notesColumn.setCellFactory(column -> new TableCell<>() {
private ChangeListener<String> stringChangeListener;
private final TextArea textArea = new TextArea();
private final Label heimatNotesLabel = new Label();
private final Label keepTimeNotesLabel = new Label();
private final HBox hbox = new HBox(5);
private final HBox hbox2 = new HBox(5);
private final VBox container = new VBox(5); // Space between TextArea and Label
{
textArea.setPrefHeight(50);
textArea.setPrefWidth(100);
textArea.setWrapText(true);
final Button copyKeepTimeNotes = new Button("",
SvgNodeProvider.getSvgNodeWithScale(Resources.RESOURCE.SVG_CLIPBOARD_ICON, 0.03, 0.03));
copyKeepTimeNotes.setMaxSize(20, 18);
copyKeepTimeNotes.setMinSize(20, 18);
copyKeepTimeNotes.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
copyKeepTimeNotes.setTooltip(new Tooltip("Copy notes"));
copyKeepTimeNotes.setOnAction(me -> copyToClipboard(keepTimeNotesLabel.getText()));
copyKeepTimeNotes.getStyleClass().add("tertiary-button");
final Button copyHeimatNotes = new Button("",
SvgNodeProvider.getSvgNodeWithScale(Resources.RESOURCE.SVG_CLIPBOARD_ICON, 0.03, 0.03));
copyHeimatNotes.setMaxSize(20, 18);
copyHeimatNotes.setMinSize(20, 18);
copyHeimatNotes.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
copyHeimatNotes.setTooltip(new Tooltip("Copy notes"));
copyHeimatNotes.setOnAction(me -> copyToClipboard(heimatNotesLabel.getText()));
copyHeimatNotes.getStyleClass().add("tertiary-button");
final Label keeptimeLabel = new Label("KeepTime:");
keeptimeLabel.setMinWidth(60);
hbox.getChildren().addAll(copyKeepTimeNotes, keeptimeLabel, keepTimeNotesLabel);
final Label heimatLabel = new Label("Heimat:");
heimatLabel.setMinWidth(60);
hbox2.getChildren().addAll(copyHeimatNotes, heimatLabel, heimatNotesLabel);
container.getChildren().addAll(textArea, hbox, hbox2);
}
@Override
protected void updateItem(TableRow item, boolean empty) {
super.updateItem(item, empty);
if (stringChangeListener != null)
textArea.textProperty().removeListener(stringChangeListener);
if (empty || item == null) {
setGraphic(null);
} else {
textArea.setDisable(!item.mapping.canBeSynced());
textArea.setText("");
if (item.mapping.canBeSynced()) {
textArea.setText(item.userNotes.get());
stringChangeListener = (obs, oldText, newText) -> {
item.userNotes.set(newText);
textAreaValid.accept(textArea);
};
textAreaValid.accept(textArea);
textArea.textProperty().addListener(stringChangeListener);
}
heimatNotesLabel.setText(item.heimatNotes.get());
keepTimeNotesLabel.setText(item.keeptimeNotes.get());
setGraphic(container);
}
}
});
TableColumn<TableRow, String> syncColumn = new TableColumn<>("Sync Status");
syncColumn.setCellValueFactory(data -> data.getValue().syncStatus);
shouldSyncColumn.setPrefWidth(50);
projectColumn.setPrefWidth(100);
timeColumn.setPrefWidth(125);
notesColumn.prefWidthProperty().bind(mappingTableView.widthProperty().subtract(525 + 17));
syncColumn.setPrefWidth(250);
mappingTableView.getColumns().addAll(shouldSyncColumn, projectColumn, timeColumn, notesColumn, syncColumn);
mappingTableView.setSelectionModel(null);
mappingTableView.getColumns().forEach(column -> column.setSortable(false));
saveButton.setOnAction(ae -> {
showLoadingScreen(true);
Task<List<HeimatController.HeimatErrors>> task = new Task<>() {
@Override
protected List<HeimatController.HeimatErrors> call() {
return heimatController.saveDay(items.stream()
.map(item -> new HeimatController.UserMapping(item.mapping,
item.shouldSyncCheckBox.get(), item.userNotes.get(),
(int) (item.userTimeSeconds.get() / 60)))
.toList(), currentReportDate);
}
};
task.setOnSucceeded(e -> {
final List<HeimatController.HeimatErrors> errors = task.getValue();
int closingSeconds = 5;
if (!errors.isEmpty()) {
closingSeconds = 10;
loadingScreenShowSyncing("Something did not work :(", loadingFailure);
List<String> a = errors.stream().map(error -> {
final List<Project> projects = error.mapping().mapping().projects();
// TODO would be nice to show heimat task name but we only have ID here
final String projectName = !projects.isEmpty()
? projects.get(0).getName()
: Long.toString(error.mapping().mapping().heimatTaskId());
return projectName + ": " + error.errorMessage() + ". Wanted to store '" + error.mapping()
.userMinutes()
+ "' minutes with notes '" + error.mapping().userNotes() + "'";
}).toList();
showErrorDialog(a);
} else {
loadingScreenShowSyncing(
"Successfully synced!\nPlease always validate that everything worked like expected.",
loadingSuccess);
}
final AtomicInteger remainingSeconds = new AtomicInteger(closingSeconds);
loadingClosingMessage.setText("Closing in " + remainingSeconds + " seconds...");
loadingClosingMessage.setVisible(true);
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(1), event -> {
remainingSeconds.getAndDecrement();
loadingClosingMessage.setText("Closing in " + remainingSeconds + " seconds...");
if (remainingSeconds.get() <= 0) {
showLoadingScreen(false);
thisStage.close();
loadingClosingMessage.setVisible(false);
}
}));
timeline.setCycleCount(remainingSeconds.get());
timeline.play();
});
task.setOnFailed(e -> {
final Throwable exception = task.getException();
LOG.error("Task failed unexpectedly.", exception);
loadingScreenShowSyncing("Something very unexpected has happened :(", loadingFailure);
showErrorDialog(Collections.singletonList(
"Please report this to a developer. The error was:" + exception.getMessage()));
showLoadingScreen(false);
thisStage.close();
});
loadingScreenShowSyncing("Syncing...", loadingSpinner);
Platform.runLater(() -> new Thread(task).start());
});
cancelButton.setOnAction(ae -> {
showLoadingScreen(false);
thisStage.close();
});
}
private static void markNodeValidOrNot(final Node textArea, final boolean isValid) {
String borderColor = "#74a317";
if (!isValid) {
borderColor = "#c63329";
}
textArea.setStyle("-fx-border-color: " + borderColor + ";");
}
private static boolean areSecondsOfDayValid(final long seconds) {
long minutes = (seconds / 60);
final boolean isInvalid = seconds % 60 != 0 || minutes % 15 != 0 || minutes <= 0;
return !isInvalid;
}
private void initializeLoadingScreen() {
showLoadingScreen(false);
loadingSuccess.setFill(colorLoadingSuccess);
loadingSuccess.prefHeight(50);
loadingSuccess.prefWidth(50);
loadingFailure.setFill(colorLoadingFailure);
loadingFailure.prefHeight(50);
loadingFailure.prefWidth(50);
loadingSpinner.setFill(colorLoadingSpinner);
loadingSpinner.prefHeight(50);
loadingSpinner.prefWidth(50);
loadingSpinnerAnimation.setNode(syncingIconRegion);
loadingSpinnerAnimation.setByAngle(360);
loadingSpinnerAnimation.setCycleCount(Animation.INDEFINITE);
}
private void loadingScreenShowSyncing(String statusMessage, SVGPath icon) {
if (icon == loadingSpinner) {
loadingSpinnerAnimation.play();
} else {
loadingSpinnerAnimation.stop();
syncingIconRegion.setRotate(0);
}
syncingIconRegion.setShape(icon);
syncingIconRegion.setBackground(new Background(new BackgroundFill(icon.getFill(), null, null)));
loadingMessage.setText(statusMessage);
}
private void showLoadingScreen(final boolean show) {
if (!show)
loadingSpinnerAnimation.stop();
loadingClosingMessage.setVisible(false);
pane.setDisable(show);
loadingScreen.setVisible(show);
pane.setEffect(show ? new GaussianBlur() : null);
}
private void showErrorDialog(List<String> errorMessages) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error Details");
alert.setHeaderText("The following errors occurred. Please copy and manually book the times.");
alert.initOwner(thisStage);
String errorText = String.join("\n\n", errorMessages);
// Create a TextArea to allow copying
TextArea textArea = new TextArea(errorText);
textArea.setEditable(false); // Prevent editing
textArea.setWrapText(true); // Wrap long lines
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
ScrollPane scrollPane = new ScrollPane(textArea);
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
scrollPane.setPrefHeight(150);
alert.getDialogPane().setContent(scrollPane);
alert.getButtonTypes().setAll(ButtonType.OK);
alert.showAndWait();
}
private void setUpTimeSpinner(final Spinner<LocalTime> spinner) {
spinner.focusedProperty().addListener(e -> {
final LocalTimeStringConverter stringConverter = new LocalTimeStringConverter(FormatStyle.MEDIUM);
final StringProperty text = spinner.getEditor().textProperty();
try {
stringConverter.fromString(text.get());
// needed to log in value from editor to spinner
spinner.increment(0); // TODO find better Solution
} catch (final DateTimeParseException ex) {
text.setValue(spinner.getValue().toString());
}
});
spinner.setValueFactory(new SpinnerValueFactory<>() {
@Override
public void decrement(final int steps) {
if (getValue() == null) {
setValue(LocalTime.now());
} else {
if (steps == 0)
return;
final LocalTime time = getValue();
setValue(decrementToLastFullQuarter(time));
}
}
@Override
public void increment(final int steps) {
if (getValue() == null) {
setValue(LocalTime.now());
} else {
if (steps == 0)
return;
final LocalTime time = getValue();
setValue(incrementToNextFullQuarter(time));
}
}
});
spinner.getValueFactory().setConverter(new LocalTimeStringConverter(FormatStyle.MEDIUM));
}
public static LocalTime decrementToLastFullQuarter(LocalTime time) {
int minutes = time.getMinute();
if (time.toSecondOfDay() == 0)
return time; // don't decrement below 0
int decrement = (minutes % 15 == 0 && time.getSecond() == 0) ? 15 : minutes % 15;
return time.minusMinutes(decrement).withSecond(0).withNano(0);
}
public static LocalTime incrementToNextFullQuarter(LocalTime time) {
int minutes = time.getMinute();
int increment = (minutes % 15 == 0 && time.getSecond() == 0) ? 15 : 15 - (minutes % 15);
return time.plusMinutes(increment).withSecond(0).withNano(0);
}
public void setStage(final Stage thisStage) {
this.thisStage = thisStage;
}
public static class TableRow {
private final HeimatController.Mapping mapping;
public final BooleanProperty shouldSyncCheckBox;
public final StringProperty keeptimeNotes;
public final StringProperty userNotes;
public final StringProperty heimatNotes;
public final LongProperty keeptimeTimeSeconds;
public final LongProperty userTimeSeconds;
public final LongProperty heimatTimeSeconds;
public final StringProperty syncStatus;
public TableRow(HeimatController.Mapping mapping, String userNotes, final long userSeconds) {
this.mapping = mapping;
this.shouldSyncCheckBox = new SimpleBooleanProperty(mapping.shouldBeSynced());
this.syncStatus = new SimpleStringProperty(mapping.syncMessage());
this.keeptimeNotes = new SimpleStringProperty(mapping.keeptimeNotes());
this.keeptimeTimeSeconds = new SimpleLongProperty(mapping.keeptimeSeconds());
this.heimatNotes = new SimpleStringProperty(mapping.heimatNotes());
this.heimatTimeSeconds = new SimpleLongProperty(mapping.heimatSeconds());
this.userNotes = new SimpleStringProperty(userNotes);
this.userTimeSeconds = new SimpleLongProperty(userSeconds);
}
}
}