22
33import java .nio .file .Path ;
44import java .util .EnumSet ;
5+ import java .util .Objects ;
56import java .util .Optional ;
67
78import javafx .fxml .FXML ;
1920
2021public class CleanupFileRelatedPanel extends VBox implements CleanupPanel {
2122
22- @ FXML private Label cleanupRenamePDFLabel ;
23+ @ FXML private Label cleanupRenamePdfLabel ;
2324
24- @ FXML private CheckBox cleanUpMovePDF ;
25+ @ FXML private CheckBox cleanUpMovePdf ;
2526 @ FXML private CheckBox cleanUpMakePathsRelative ;
26- @ FXML private CheckBox cleanUpRenamePDF ;
27- @ FXML private CheckBox cleanUpRenamePDFonlyRelativePaths ;
27+ @ FXML private CheckBox cleanUpRenamePdf ;
28+ @ FXML private CheckBox cleanUpRenamePdfonlyRelativePaths ;
2829 @ FXML private CheckBox cleanUpDeletedFiles ;
2930 @ FXML private CheckBox cleanUpUpgradeExternalLinks ;
3031
3132 public CleanupFileRelatedPanel (BibDatabaseContext databaseContext , CleanupPreferences cleanupPreferences , FilePreferences filePreferences ) {
32- // Load FXML
33+ Objects .requireNonNull (cleanupPreferences , "cleanupPreferences must not be null" );
34+
3335 ViewLoader .view (this )
3436 .root (this )
3537 .load ();
@@ -40,45 +42,45 @@ public CleanupFileRelatedPanel(BibDatabaseContext databaseContext, CleanupPrefer
4042 private void init (BibDatabaseContext databaseContext , CleanupPreferences cleanupPreferences , FilePreferences filePreferences ) {
4143 Optional <Path > firstExistingDir = databaseContext .getFirstExistingFileDir (filePreferences );
4244 if (firstExistingDir .isPresent ()) {
43- cleanUpMovePDF .setText (Localization .lang ("Move linked files to default file directory %0" , firstExistingDir .get ().toString ()));
45+ cleanUpMovePdf .setText (Localization .lang ("Move linked files to default file directory %0" , firstExistingDir .get ().toString ()));
4446 } else {
45- cleanUpMovePDF .setText (Localization .lang ("Move linked files to default file directory %0" , "..." ));
47+ cleanUpMovePdf .setText (Localization .lang ("Move linked files to default file directory %0" , "..." ));
4648
4749 // Since the directory does not exist, we cannot move it to there. So, this option is not checked - regardless of the presets stored in the preferences.
48- cleanUpMovePDF .setDisable (true );
49- cleanUpMovePDF .setSelected (false );
50+ cleanUpMovePdf .setDisable (true );
51+ cleanUpMovePdf .setSelected (false );
5052 }
5153
52- cleanUpRenamePDFonlyRelativePaths .disableProperty ().bind (cleanUpRenamePDF .selectedProperty ().not ());
54+ cleanUpRenamePdfonlyRelativePaths .disableProperty ().bind (cleanUpRenamePdf .selectedProperty ().not ());
5355
5456 cleanUpUpgradeExternalLinks .setText (Localization .lang ("Upgrade external PDF/PS links to use the '%0' field." , StandardField .FILE .getDisplayName ()));
5557
5658 String currentPattern = Localization .lang ("Filename format pattern (from preferences)" )
5759 .concat (filePreferences .getFileNamePattern ());
58- cleanupRenamePDFLabel .setText (currentPattern );
60+ cleanupRenamePdfLabel .setText (currentPattern );
5961
6062 updateDisplay (cleanupPreferences );
6163 }
6264
6365 private void updateDisplay (CleanupPreferences preset ) {
64- if (!cleanUpMovePDF .isDisabled ()) {
65- cleanUpMovePDF .setSelected (preset .isActive (CleanupPreferences .CleanupStep .MOVE_PDF ));
66+ if (!cleanUpMovePdf .isDisabled ()) {
67+ cleanUpMovePdf .setSelected (preset .isActive (CleanupPreferences .CleanupStep .MOVE_PDF ));
6668 }
6769 cleanUpMakePathsRelative .setSelected (preset .isActive (CleanupPreferences .CleanupStep .MAKE_PATHS_RELATIVE ));
68- cleanUpRenamePDF .setSelected (preset .isActive (CleanupPreferences .CleanupStep .RENAME_PDF ));
69- cleanUpRenamePDFonlyRelativePaths .setSelected (preset .isActive (CleanupPreferences .CleanupStep .RENAME_PDF_ONLY_RELATIVE_PATHS ));
70+ cleanUpRenamePdf .setSelected (preset .isActive (CleanupPreferences .CleanupStep .RENAME_PDF ));
71+ cleanUpRenamePdfonlyRelativePaths .setSelected (preset .isActive (CleanupPreferences .CleanupStep .RENAME_PDF_ONLY_RELATIVE_PATHS ));
7072 cleanUpUpgradeExternalLinks .setSelected (preset .isActive (CleanupPreferences .CleanupStep .CLEAN_UP_UPGRADE_EXTERNAL_LINKS ));
7173 cleanUpDeletedFiles .setSelected (preset .isActive (CleanupPreferences .CleanupStep .CLEAN_UP_DELETED_LINKED_FILES ));
7274 }
7375
74- public CleanupPreferences getCleanupPreferences () {
76+ public Optional < CleanupPreferences > getCleanupPreferences () {
7577 EnumSet <CleanupPreferences .CleanupStep > activeJobs = EnumSet .noneOf (CleanupPreferences .CleanupStep .class );
7678
7779 if (cleanUpMakePathsRelative .isSelected ()) {
7880 activeJobs .add (CleanupPreferences .CleanupStep .MAKE_PATHS_RELATIVE );
7981 }
80- if (cleanUpRenamePDF .isSelected ()) {
81- if (cleanUpRenamePDFonlyRelativePaths .isSelected ()) {
82+ if (cleanUpRenamePdf .isSelected ()) {
83+ if (cleanUpRenamePdfonlyRelativePaths .isSelected ()) {
8284 activeJobs .add (CleanupPreferences .CleanupStep .RENAME_PDF_ONLY_RELATIVE_PATHS );
8385 } else {
8486 activeJobs .add (CleanupPreferences .CleanupStep .RENAME_PDF );
@@ -91,6 +93,6 @@ public CleanupPreferences getCleanupPreferences() {
9193 activeJobs .add (CleanupPreferences .CleanupStep .CLEAN_UP_DELETED_LINKED_FILES );
9294 }
9395
94- return new CleanupPreferences (activeJobs );
96+ return Optional . of ( new CleanupPreferences (activeJobs ) );
9597 }
9698}
0 commit comments