From f120b4160addddd6f4eec272c4038ca7e11814eb Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Fri, 19 Oct 2018 09:57:06 -0400 Subject: [PATCH 01/75] Exporter to JavaFX commit 1 --- .../ExportCustomizationDialogViewModel.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java new file mode 100644 index 00000000000..c1a51eeafaf --- /dev/null +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -0,0 +1,17 @@ +package org.jabref.gui.exporter; + +import org.jabref.gui.DialogService; +import org.jabref.gui.util.BaseDialog; + +public class ExportCustomizationDialogViewModel extends BaseDialog { + + private final DialogService dialogService; + + + //stuff here + + public ExportCustomizationDialogViewModel(DialogService dialogService) { + this.dialogService = dialogService; + + } +} \ No newline at end of file From 12e3e7d409ae72224beb874a13d13c43111c68c8 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sat, 20 Oct 2018 20:19:23 -0400 Subject: [PATCH 02/75] Work on Export Customization Dialog VM --- .../ExportCustomizationDialogViewModel.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index c1a51eeafaf..de8281162de 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -1,17 +1,52 @@ package org.jabref.gui.exporter; +import java.util.Optional; + +import javax.inject.Inject; + +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; + import org.jabref.gui.DialogService; import org.jabref.gui.util.BaseDialog; +import org.jabref.logic.exporter.TemplateExporter; +import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; public class ExportCustomizationDialogViewModel extends BaseDialog { - private final DialogService dialogService; + private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final int size; //final? Or you don't need this and just use a a while loop + private final PreferencesService preferences; + private final DialogService dialogService; - //stuff here + //Other variable declarations here public ExportCustomizationDialogViewModel(DialogService dialogService) { this.dialogService = dialogService; + int i = 0; + //raname var "s"? + while (!((s = preferences.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)))) { + Optional format = createFormat(s.get(EXPORTER_NAME_INDEX), s.get(EXPORTER_FILENAME_INDEX), s.get(EXPORTER_EXTENSION_INDEX), layoutPreferences, savePreferences); + if (format.isPresent()) { + exporters.add(format.get()); //put was changed to add becuase we are not dealing with Map as in CustomExpoertList + } else { + String customExportFormat = preferences.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); + LOGGER.error("Error initializing custom export format from string " + customExportFormat); + } + i++; + } + //exporters.addAll(//add here); //How will ExporterViewModel be organized? + //It should be analogous to AbbreviationViewModel, except possibly more complicated + //Rather than use addAll(), you might want to take from CustomExportList. + //You may have to write a method that gets all the relevant information about the exporters + + } + + //possibly not necessary, and if so getSortedList will have to return the correct type, not Eventlist> + public List loadExporters() { + return preferences.customExports.getSortedList(); //As of now getSortedList refers to EventList> } } \ No newline at end of file From ec364ade398a477470a461b16cbce7376ace7143 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sat, 20 Oct 2018 20:44:27 -0400 Subject: [PATCH 03/75] Work on VM --- .../ExportCustomizationDialogViewModel.java | 33 +++++++++++++++---- .../preferences/PreferencesService.java | 4 +++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index de8281162de..f64391a3f6a 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.exporter; +import java.util.List; import java.util.Optional; import javax.inject.Inject; @@ -10,26 +11,43 @@ import org.jabref.gui.DialogService; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.exporter.TemplateExporter; +import org.jabref.preferences.CustomExportList; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreferencesService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class ExportCustomizationDialogViewModel extends BaseDialog { + //The class vars might need to be reordered + private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); private final int size; //final? Or you don't need this and just use a a while loop + //Indices within which export format information is stored within JabRefPreferences + private static final int EXPORTER_NAME_INDEX = 0; + private static final int EXPORTER_FILENAME_INDEX = 1; + private static final int EXPORTER_EXTENSION_INDEX = 2; + private final PreferencesService preferences; private final DialogService dialogService; + private static final Logger LOGGER = LoggerFactory.getLogger(CustomExportList.class); + //Other variable declarations here + //Also write tests for all of this + public ExportCustomizationDialogViewModel(DialogService dialogService) { this.dialogService = dialogService; int i = 0; //raname var "s"? - while (!((s = preferences.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)))) { - Optional format = createFormat(s.get(EXPORTER_NAME_INDEX), s.get(EXPORTER_FILENAME_INDEX), s.get(EXPORTER_EXTENSION_INDEX), layoutPreferences, savePreferences); + List s; + while (!((s = preferences.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) { + //Shuold createFormat be in logic? Check how it works in CustomExportList + Optional format = createFormat(s.get(EXPORTER_NAME_INDEX), s.get(EXPORTER_FILENAME_INDEX), s.get(EXPORTER_EXTENSION_INDEX), layoutPreferences, savePreferences); if (format.isPresent()) { exporters.add(format.get()); //put was changed to add becuase we are not dealing with Map as in CustomExpoertList } else { @@ -38,10 +56,11 @@ public ExportCustomizationDialogViewModel(DialogService dialogService) { } i++; } - //exporters.addAll(//add here); //How will ExporterViewModel be organized? - //It should be analogous to AbbreviationViewModel, except possibly more complicated - //Rather than use addAll(), you might want to take from CustomExportList. - //You may have to write a method that gets all the relevant information about the exporters + //ExporterViewModel will be organized as a singular version of what now is CustomExportDialog, which + //currently stores all the exporters in a class var. Each ViewModel will have one exporter and associated data, and + //the class var exporters will be a list of them + //You will have to write properites into ExpoerterViewModel that get all the relevant information about the exporter + //in addition to a property for the exporter itself } @@ -49,4 +68,4 @@ public ExportCustomizationDialogViewModel(DialogService dialogService) { public List loadExporters() { return preferences.customExports.getSortedList(); //As of now getSortedList refers to EventList> } -} \ No newline at end of file +} diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 0458c688759..4dfc3b03649 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -35,4 +35,8 @@ public interface PreferencesService { public void updateEntryEditorTabList(); + List getStringList(String key); + + String get(String key); + } From f5c89fa3af97a1f3f221966f5b6f964b2200720e Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Thu, 25 Oct 2018 07:19:47 -0400 Subject: [PATCH 04/75] Combine methods in CustomExporterList and move to preferences --- .../ExportCustomizationDialogViewModel.java | 32 +++++---------- .../jabref/preferences/JabRefPreferences.java | 40 +++++++++++++++++++ .../preferences/PreferencesService.java | 5 +-- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index f64391a3f6a..4a31493d352 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -1,10 +1,5 @@ package org.jabref.gui.exporter; -import java.util.List; -import java.util.Optional; - -import javax.inject.Inject; - import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; @@ -12,7 +7,6 @@ import org.jabref.gui.util.BaseDialog; import org.jabref.logic.exporter.TemplateExporter; import org.jabref.preferences.CustomExportList; -import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -22,7 +16,7 @@ public class ExportCustomizationDialogViewModel extends BaseDialog { //The class vars might need to be reordered - private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); private final int size; //final? Or you don't need this and just use a a while loop //Indices within which export format information is stored within JabRefPreferences @@ -41,21 +35,8 @@ public class ExportCustomizationDialogViewModel extends BaseDialog { public ExportCustomizationDialogViewModel(DialogService dialogService) { this.dialogService = dialogService; + init(); - int i = 0; - //raname var "s"? - List s; - while (!((s = preferences.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) { - //Shuold createFormat be in logic? Check how it works in CustomExportList - Optional format = createFormat(s.get(EXPORTER_NAME_INDEX), s.get(EXPORTER_FILENAME_INDEX), s.get(EXPORTER_EXTENSION_INDEX), layoutPreferences, savePreferences); - if (format.isPresent()) { - exporters.add(format.get()); //put was changed to add becuase we are not dealing with Map as in CustomExpoertList - } else { - String customExportFormat = preferences.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); - LOGGER.error("Error initializing custom export format from string " + customExportFormat); - } - i++; - } //ExporterViewModel will be organized as a singular version of what now is CustomExportDialog, which //currently stores all the exporters in a class var. Each ViewModel will have one exporter and associated data, and //the class var exporters will be a list of them @@ -65,7 +46,12 @@ public ExportCustomizationDialogViewModel(DialogService dialogService) { } //possibly not necessary, and if so getSortedList will have to return the correct type, not Eventlist> - public List loadExporters() { - return preferences.customExports.getSortedList(); //As of now getSortedList refers to EventList> + public void loadExporters() { + exporters.addAll(preferences.getCustomExportFormats()); //Implement in JabRefPreferences + //preferences.customExports.getSortedList(); //As of now getSortedList refers to EventList> + } + + public void init() { + loadExporters(); } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 45f724fc252..40c90893106 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -79,7 +79,9 @@ import org.jabref.logic.protectedterms.ProtectedTermsPreferences; import org.jabref.logic.remote.RemotePreferences; import org.jabref.logic.shared.prefs.SharedDatabasePreferences; +import org.jabref.logic.util.FileType; import org.jabref.logic.util.OS; +import org.jabref.logic.util.StandardFileType; import org.jabref.logic.util.UpdateFieldPreferences; import org.jabref.logic.util.Version; import org.jabref.logic.util.io.AutoLinkPreferences; @@ -2012,4 +2014,42 @@ public Map getMainTableColumnSortTypes() { } return map; } + + @Override + public List getCustomExportFormats(JournalAbbreviationLoader loader) { + int i = 0; + List formats; + String exporterName; + String filename; + String extension; + String lfFileName; + LayoutFormatterPreferences layoutPreferences = getLayoutFormatterPreferences(loader); + SavePreferences savePreferences = loadForExportFromPreferences(); + List s; + while (!((s = getStringList(CUSTOM_EXPORT_FORMAT + i)).isEmpty())) { + exporterName = s.get(0); + filename = s.get(1); // 0, 1, 2 were originally static vars + extension = s.get(2); + if (filename.endsWith(".layout")) { + lfFileName = filename.substring(0, filename.length() - ".layout".length()); + } else { + lfFileName = filename; + if (extension.contains(".")) { + extension = extension.substring(extension.indexOf('.') + 1, extension.length()); + } + FileType fileType = StandardFileType.newFileType(extension); + Optional format = Optional.of(new TemplateExporter(exporterName, exporterName, lfFileName, + null, fileType, layoutPreferences, + savePreferences)); + format.get().setCustomExport(true); //Taken out of orig CustomExporerList + if (format.isPresent()) { + formats.add(format.get()); + } else { + String customExportFormat = get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); + LOGGER.error("Error initializing custom export format from string " + customExportFormat); + } + i++; + } + return formats; + } } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 4dfc3b03649..7bb5af39414 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -5,6 +5,7 @@ import java.util.Map; import org.jabref.gui.keyboard.KeyBindingRepository; +import org.jabref.logic.exporter.TemplateExporter; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.metadata.FilePreferences; @@ -35,8 +36,6 @@ public interface PreferencesService { public void updateEntryEditorTabList(); - List getStringList(String key); - - String get(String key); + List getCustomExportFormats(); } From 6773b22379d235382ce836e2e73558dad0d991f9 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Thu, 25 Oct 2018 09:14:25 -0400 Subject: [PATCH 05/75] work on VM --- .../ExportCustomizationDialogViewModel.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index 4a31493d352..55bf44d964e 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -1,8 +1,9 @@ package org.jabref.gui.exporter; +import java.util.List; + import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; - import org.jabref.gui.DialogService; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.exporter.TemplateExporter; @@ -16,7 +17,8 @@ public class ExportCustomizationDialogViewModel extends BaseDialog { //The class vars might need to be reordered - private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final int size; //final? Or you don't need this and just use a a while loop //Indices within which export format information is stored within JabRefPreferences @@ -45,12 +47,25 @@ public ExportCustomizationDialogViewModel(DialogService dialogService) { } - //possibly not necessary, and if so getSortedList will have to return the correct type, not Eventlist> public void loadExporters() { - exporters.addAll(preferences.getCustomExportFormats()); //Implement in JabRefPreferences - //preferences.customExports.getSortedList(); //As of now getSortedList refers to EventList> + List exportersLogic = preferences.getCustomExportFormats(); //Var may need more descriptive name + for (TemplateExporter exporter : exportersLogic) { + exporters.add(new ExporterViewModel(exporter)); + } } + //The following method will have to be implemented to get information from the JavaFX analogue of Swing CustomExportDialog + public void addExporter() { + // open add Exporter dialog, set vars as dialogResult or analogous + exporters.add(new ExporterViewModel(dialogResult)) //var might have to be renamed + + } + + public void saveToPrefs() { + List exportersLogic; + exporters.forEach(exporter -> exportersLogic.add(exporter.getLogic())); + preferences.storeNewExporters(exportersLogic); + } public void init() { loadExporters(); } From 1f318f0006805d883b89af975cafb28d0da270c5 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Thu, 25 Oct 2018 18:38:33 -0400 Subject: [PATCH 06/75] Add methods to VM --- .../ExportCustomizationDialogViewModel.java | 35 ++++++++++++++----- .../jabref/preferences/JabRefPreferences.java | 24 +++++++++++++ .../preferences/PreferencesService.java | 4 ++- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index 55bf44d964e..dd76baabdfc 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -1,13 +1,15 @@ package org.jabref.gui.exporter; +import java.util.ArrayList; import java.util.List; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; + import org.jabref.gui.DialogService; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.exporter.TemplateExporter; -import org.jabref.preferences.CustomExportList; +import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -17,6 +19,7 @@ public class ExportCustomizationDialogViewModel extends BaseDialog { //The class vars might need to be reordered + //exporters should probably be a JavaFX SortedList, but not yet sure how to make that into a property private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); private final int size; //final? Or you don't need this and just use a a while loop @@ -28,6 +31,7 @@ public class ExportCustomizationDialogViewModel extends BaseDialog { private final PreferencesService preferences; private final DialogService dialogService; + private final JournalAbbreviationLoader loader; private static final Logger LOGGER = LoggerFactory.getLogger(CustomExportList.class); @@ -35,20 +39,19 @@ public class ExportCustomizationDialogViewModel extends BaseDialog { //Also write tests for all of this - public ExportCustomizationDialogViewModel(DialogService dialogService) { + public ExportCustomizationDialogViewModel(DialogService dialogService, JournalAbbreviationLoader loader) { this.dialogService = dialogService; + this.loader = loader; init(); - //ExporterViewModel will be organized as a singular version of what now is CustomExportDialog, which - //currently stores all the exporters in a class var. Each ViewModel will have one exporter and associated data, and - //the class var exporters will be a list of them - //You will have to write properites into ExpoerterViewModel that get all the relevant information about the exporter - //in addition to a property for the exporter itself + //ExporterViewModel is organized as a singular version of what now is CustomExportDialog, which + //currently stores all the exporters in a class var. Each ViewModel wraps and exporter, and + //the class var exporters is a list of them } public void loadExporters() { - List exportersLogic = preferences.getCustomExportFormats(); //Var may need more descriptive name + List exportersLogic = preferences.getCustomExportFormats(loader); //Var may need more descriptive name for (TemplateExporter exporter : exportersLogic) { exporters.add(new ExporterViewModel(exporter)); } @@ -61,10 +64,24 @@ public void addExporter() { } + public void modfiyExporter(int row) { + // open modify Exporter dialog, which may be the same as add Exporter dialog, and set that into exporters. + exporters.set(row, new ExporterViewModel(dialogResult)); //result must come from dialog + } + + public void removeExporters(int[] rows) { + if (rows.length == 0) { // Is this check necessary? Probably not + return; + } + for (int i = 0; i < rows.length; i++) { + exporters.remove(rows[i]); + } + } + public void saveToPrefs() { List exportersLogic; exporters.forEach(exporter -> exportersLogic.add(exporter.getLogic())); - preferences.storeNewExporters(exportersLogic); + preferences.storeCustomExportFormats(exportersLogic); } public void init() { loadExporters(); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 40c90893106..712b240743e 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2034,6 +2034,7 @@ public List getCustomExportFormats(JournalAbbreviationLoader l lfFileName = filename.substring(0, filename.length() - ".layout".length()); } else { lfFileName = filename; + } if (extension.contains(".")) { extension = extension.substring(extension.indexOf('.') + 1, extension.length()); } @@ -2052,4 +2053,27 @@ public List getCustomExportFormats(JournalAbbreviationLoader l } return formats; } + + @Override + public void storeCustomExportFormats(List exporters) { + if (exporters.isEmpty()) { + purgeCustomExportFormats(0); + } else { + for (int i = 0; i < exporters.size(); i++) { + List exporterData = new ArrayList<>(); + exporterData.add(exporters.get(i).getName()); + exporterData.add(exporters.get(i).getId()); + putStringList(CUSTOM_EXPORT_FORMAT + i, exporterData); + } + purgeCustomExportFormats(exporters.size()); + } + } + + private void purgeCustomExportFormats(int from) { + int i = from; + while (!getStringList(CUSTOM_EXPORT_FORMAT + i).isEmpty()) { + remove(CUSTOM_EXPORT_FORMAT + i); + i++; + } + } } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 7bb5af39414..a62ef811890 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -6,6 +6,7 @@ import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.logic.exporter.TemplateExporter; +import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.metadata.FilePreferences; @@ -36,6 +37,7 @@ public interface PreferencesService { public void updateEntryEditorTabList(); - List getCustomExportFormats(); + List getCustomExportFormats(JournalAbbreviationLoader loader); + void storeCustomExportFormats(List exporters); } From 1a0b76030695589c4bcaae69ea974a387d0620a1 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Thu, 25 Oct 2018 18:45:10 -0400 Subject: [PATCH 07/75] Fix typos --- .../gui/exporter/ExportCustomizationDialogViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index dd76baabdfc..75634f55e35 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -45,7 +45,7 @@ public ExportCustomizationDialogViewModel(DialogService dialogService, JournalAb init(); //ExporterViewModel is organized as a singular version of what now is CustomExportDialog, which - //currently stores all the exporters in a class var. Each ViewModel wraps and exporter, and + //currently stores all the exporters in a class var. Each ViewModel wraps an exporter, and //the class var exporters is a list of them } @@ -64,7 +64,7 @@ public void addExporter() { } - public void modfiyExporter(int row) { + public void modifyExporter(int row) { // open modify Exporter dialog, which may be the same as add Exporter dialog, and set that into exporters. exporters.set(row, new ExporterViewModel(dialogResult)); //result must come from dialog } From 5c65b57ea1653ceb24bec90568030d4345550c42 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Fri, 26 Oct 2018 15:03:49 -0400 Subject: [PATCH 08/75] started work on exporter subdialog --- .../CreateModifyExporterDialogViewModel.java | 12 ++++++++++++ .../ExportCustomizationDialogViewModel.java | 7 ++++--- .../jabref/gui/exporter/ExporterViewModel.java | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java create mode 100644 src/main/java/org/jabref/gui/exporter/ExporterViewModel.java diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java new file mode 100644 index 00000000000..3aaae20f0c7 --- /dev/null +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -0,0 +1,12 @@ +package org.jabref.gui.exporter + +import org.jabref.gui.util.BaseDialog; +import org.jabref.logic.exporter.TemplateExporter; + +public class CreateModifyExporterDialogViewModel extends AbstractViewModel { + + //This could be separated into two classes, one for adding exporters and one for modifying them. + //See the two constructors + + public CreateModifyExporterDialogViewModel //Is this actually how a dialog opens another one in JavaFX? +} \ No newline at end of file diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index 75634f55e35..1bdc9e6068e 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -6,8 +6,8 @@ import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; +import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; -import org.jabref.gui.util.BaseDialog; import org.jabref.logic.exporter.TemplateExporter; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.preferences.PreferencesService; @@ -15,7 +15,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ExportCustomizationDialogViewModel extends BaseDialog { +public class ExportCustomizationDialogViewModel extends AbstractViewModel { //The class vars might need to be reordered @@ -60,7 +60,8 @@ public void loadExporters() { //The following method will have to be implemented to get information from the JavaFX analogue of Swing CustomExportDialog public void addExporter() { // open add Exporter dialog, set vars as dialogResult or analogous - exporters.add(new ExporterViewModel(dialogResult)) //var might have to be renamed + TemplateExporter exporter = new CreateModifyExporterDialogView().show(); //Not sure if this is right + exporters.add(new ExporterViewModel(exporter));//var might have to be renamed } diff --git a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java new file mode 100644 index 00000000000..c71428849e1 --- /dev/null +++ b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java @@ -0,0 +1,17 @@ +package org.jabref.gui.exporter; + +import org.jabref.logic.exporter.TemplateExporter; + +public class ExporterViewModel { + + TemplateExporter exporter; + + public ExporterViewModel(TemplateExporter exporter) { + this.exporter = exporter; + } + + public TemplateExporter getLogic() { + return this.exporter; + } + +} From 2de4124050398a561090ce354911073d683215e8 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Fri, 26 Oct 2018 18:40:23 -0400 Subject: [PATCH 09/75] Continue work on exporter subdialog --- .../CreateModifyExporterDialogViewModel.java | 51 ++++++++++++++++--- .../jabref/preferences/JabRefPreferences.java | 3 +- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 3aaae20f0c7..fedf369af47 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -1,12 +1,51 @@ -package org.jabref.gui.exporter +package org.jabref.gui.exporter; -import org.jabref.gui.util.BaseDialog; +import org.jabref.gui.AbstractViewModel; +import org.jabref.gui.DialogService; +import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.exporter.TemplateExporter; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.StandardFileType; +import org.jabref.preferences.PreferencesService; public class CreateModifyExporterDialogViewModel extends AbstractViewModel { - //This could be separated into two classes, one for adding exporters and one for modifying them. - //See the two constructors + //This could be separated into two dialogs, one for adding exporters and one for modifying them. + //See the two constructors for the view - public CreateModifyExporterDialogViewModel //Is this actually how a dialog opens another one in JavaFX? -} \ No newline at end of file + //The view will return a TemplateExporter + //You will have to look at Swing class CustomExportDialog when you write the View + + //Cancel to be implemented in View, not here + + private final TemplateExporter exporter; + private final DialogService dialogService; + private final PreferencesService preferences; + + + public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogService dialogService, PreferencesService preferences) { + this.exporter = exporter; + this.dialogService = dialogService; + this.preferences = preferences; + //Set text of each of the boxes + + } + + public TemplateExporter saveExporter() {//void? + preferences.saveExportWorkingDirectory(layoutFileDir); //See Swing class CustomExportDialog for more on how implement this + // Maybe create a new exporter? - see Swing version for how to do this + } + + public String getExportWorkingDirectory() {//i.e. layout dir + return preferences.getExportWorkingDirectory(); + } + + public void browse() { + FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() + .addExtensionFilter(Localization.lang("Custom layout file"), StandardFileType.LAYOUT) + .withDefaultExtension(Localization.lang("Custom layout file"), StandardFileType.LAYOUT) + .withInitialDirectory(getExportWorkingDirectory()).build(); + dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(f -> setText(f.toAbsolutePath().toString())); //implement setting the text + } + +} diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 712b240743e..cd7a41f8ad3 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2018,7 +2018,7 @@ public Map getMainTableColumnSortTypes() { @Override public List getCustomExportFormats(JournalAbbreviationLoader loader) { int i = 0; - List formats; + List formats = null; String exporterName; String filename; String extension; @@ -2026,6 +2026,7 @@ public List getCustomExportFormats(JournalAbbreviationLoader l LayoutFormatterPreferences layoutPreferences = getLayoutFormatterPreferences(loader); SavePreferences savePreferences = loadForExportFromPreferences(); List s; + // possibly check if CUSTOM_EXPORT_FORMAT + 0 is empty too and throw error while (!((s = getStringList(CUSTOM_EXPORT_FORMAT + i)).isEmpty())) { exporterName = s.get(0); filename = s.get(1); // 0, 1, 2 were originally static vars From a869aa2363f6a17e8bb0873066784901880735c6 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sat, 27 Oct 2018 19:43:17 -0400 Subject: [PATCH 10/75] Implement save exporter from add/modify exporter dialog --- .../CreateModifyExporterDialogViewModel.java | 41 ++++++++++++++++++- .../ExportCustomizationDialogViewModel.java | 9 ++-- .../preferences/PreferencesService.java | 6 +++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index fedf369af47..be57b7aaa62 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -1,11 +1,21 @@ package org.jabref.gui.exporter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Optional; + +import javafx.beans.property.SimpleStringProperty; + import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; import org.jabref.gui.util.FileDialogConfiguration; +import org.jabref.logic.exporter.SavePreferences; import org.jabref.logic.exporter.TemplateExporter; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.layout.LayoutFormatterPreferences; +import org.jabref.logic.util.FileType; import org.jabref.logic.util.StandardFileType; +import org.jabref.preferences.JabRefPreferences; //will be removed with writing of new method import org.jabref.preferences.PreferencesService; public class CreateModifyExporterDialogViewModel extends AbstractViewModel { @@ -22,6 +32,10 @@ public class CreateModifyExporterDialogViewModel extends AbstractViewModel { private final DialogService dialogService; private final PreferencesService preferences; + private final SimpleStringProperty name; //prevent saveExporter from saving this if it's null + private final SimpleStringProperty layoutFile; + private final SimpleStringProperty extension; + public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogService dialogService, PreferencesService preferences) { this.exporter = exporter; @@ -32,8 +46,31 @@ public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogServ } public TemplateExporter saveExporter() {//void? - preferences.saveExportWorkingDirectory(layoutFileDir); //See Swing class CustomExportDialog for more on how implement this - // Maybe create a new exporter? - see Swing version for how to do this + Path layoutFileDir = Paths.get(layoutFile.get()).getParent(); + if (layoutFileDir != null) { + preferences.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, layoutFileDir.toString()); //fix to work with PreferencesService + + } + preferences.saveExportWorkingDirectory(layoutFileDir.toString()); //See Swing class CustomExportDialog for more on how implement this + // Create a new exporter to be returned to ExportCustomizationDialog, which requested it + LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(); + SavePreferences savePreferences = preferences.LoadForExportFromPreferences(); + String filename = layoutFile.get(); //change var name? + String extensionString = extension.get(); //change var name? + String lfFileName; + if (filename.endsWith(".layout")) { + lfFileName = filename.substring(0, filename.length() - ".layout".length()); + } else { + lfFileName = filename; + } + if (extensionString.contains(".")) { + extension.set(extensionString.substring(extensionString.indexOf('.') + 1, extensionString.length())); + } + FileType fileType = StandardFileType.newFileType(extensionString); + TemplateExporter format = new TemplateExporter(name.get(), name.get(), lfFileName, null, fileType, layoutPreferences, + savePreferences); + format.setCustomExport(true); + return format; } public String getExportWorkingDirectory() {//i.e. layout dir diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index 1bdc9e6068e..ee0f4449525 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -19,7 +19,8 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { //The class vars might need to be reordered - //exporters should probably be a JavaFX SortedList, but not yet sure how to make that into a property + //exporters should probably be a JavaFX SortedList instead of SimpleListPreperty, + //but not yet sure how to make SortedList into a property private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); private final int size; //final? Or you don't need this and just use a a while loop @@ -37,7 +38,7 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { //Other variable declarations here - //Also write tests for all of this + //Also write tests for all of this if necessary public ExportCustomizationDialogViewModel(DialogService dialogService, JournalAbbreviationLoader loader) { this.dialogService = dialogService; @@ -45,8 +46,8 @@ public ExportCustomizationDialogViewModel(DialogService dialogService, JournalAb init(); //ExporterViewModel is organized as a singular version of what now is CustomExportDialog, which - //currently stores all the exporters in a class var. Each ViewModel wraps an exporter, and - //the class var exporters is a list of them + //currently stores all the exporters in a class var. Each ExporterViewModel wraps an exporter, and + //the class var exporters is a list of the ExporterViewModels } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index a62ef811890..e6eaae83c8a 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -5,9 +5,11 @@ import java.util.Map; import org.jabref.gui.keyboard.KeyBindingRepository; +import org.jabref.logic.exporter.SavePreferences; import org.jabref.logic.exporter.TemplateExporter; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; +import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.model.metadata.FilePreferences; public interface PreferencesService { @@ -40,4 +42,8 @@ public interface PreferencesService { List getCustomExportFormats(JournalAbbreviationLoader loader); void storeCustomExportFormats(List exporters); + + LayoutFormatterPreferences getLayoutFormatterPreferences(); + + SavePreferences LoadForExportFromPreferences(); } From 9ae84c0933f110d91c2d3c8b319548085670dc3c Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sat, 27 Oct 2018 19:58:15 -0400 Subject: [PATCH 11/75] Add two comments --- .../jabref/gui/exporter/CreateModifyExporterDialogViewModel.java | 1 + src/main/java/org/jabref/preferences/JabRefPreferences.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index be57b7aaa62..6b704a541fb 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -58,6 +58,7 @@ public TemplateExporter saveExporter() {//void? String filename = layoutFile.get(); //change var name? String extensionString = extension.get(); //change var name? String lfFileName; + //You might want to move the next few lines into logic because it also appears in JabRefPreferences if (filename.endsWith(".layout")) { lfFileName = filename.substring(0, filename.length() - ".layout".length()); } else { diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index cd7a41f8ad3..e40a6b93686 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2031,6 +2031,7 @@ public List getCustomExportFormats(JournalAbbreviationLoader l exporterName = s.get(0); filename = s.get(1); // 0, 1, 2 were originally static vars extension = s.get(2); + //You might want to put the following few lines in logic because it also appears in CreateModifyExporterDialogViewModel if (filename.endsWith(".layout")) { lfFileName = filename.substring(0, filename.length() - ".layout".length()); } else { From e992c5d77eaaad4656ffa0efd7787175b37b3647 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sun, 28 Oct 2018 20:01:26 -0400 Subject: [PATCH 12/75] More work on VMs and prefs --- .../CreateModifyExporterDialogViewModel.java | 33 +++++++++++++++---- .../ExportCustomizationDialogViewModel.java | 4 +-- .../jabref/preferences/JabRefPreferences.java | 6 ++++ .../preferences/PreferencesService.java | 2 ++ 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 6b704a541fb..03192ca3fa7 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -18,41 +18,60 @@ import org.jabref.preferences.JabRefPreferences; //will be removed with writing of new method import org.jabref.preferences.PreferencesService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class CreateModifyExporterDialogViewModel extends AbstractViewModel { //This could be separated into two dialogs, one for adding exporters and one for modifying them. - //See the two constructors for the view + //See the two constructors for the view, as was done in CustomExportDialog //The view will return a TemplateExporter //You will have to look at Swing class CustomExportDialog when you write the View //Cancel to be implemented in View, not here + private static final Logger LOGGER = LoggerFactory.getLogger(CreateModifyExporterDialogViewModel.class); + private final TemplateExporter exporter; private final DialogService dialogService; private final PreferencesService preferences; - private final SimpleStringProperty name; //prevent saveExporter from saving this if it's null + private final SimpleStringProperty name; private final SimpleStringProperty layoutFile; private final SimpleStringProperty extension; - public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogService dialogService, PreferencesService preferences) { + public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogService dialogService, PreferencesService preferences, + String name, String layoutFile, String extension) { this.exporter = exporter; this.dialogService = dialogService; this.preferences = preferences; - //Set text of each of the boxes + //Set text of each of the boxes + this.name = name; + this.layoutFile = layoutFile; + this.extension = extension; } public TemplateExporter saveExporter() {//void? Path layoutFileDir = Paths.get(layoutFile.get()).getParent(); if (layoutFileDir != null) { - preferences.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, layoutFileDir.toString()); //fix to work with PreferencesService + String layoutFileDirString = layoutFileDir.toString(); + preferences.setExportWorkingDirectory(layoutFileDirString); } - preferences.saveExportWorkingDirectory(layoutFileDir.toString()); //See Swing class CustomExportDialog for more on how implement this - // Create a new exporter to be returned to ExportCustomizationDialog, which requested it + + // Check that there are no empty strings. + if (layoutFile.get().isEmpty() || name.get().isEmpty() || extension.get().isEmpty() + || !layoutFile.get().endsWith(".layout")) { + + LOGGER.info("One of the fields is empty!"); //TODO: Better error message + return null; //return implemented similarly to CleanupDialog, although JavaFX documentation says you need something + //like a result converter, which must be in the view, see class EntryTypeView + } + + // Create a new exporter to be returned to ExportCustomizationDialogViewModel, which requested it LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(); SavePreferences savePreferences = preferences.LoadForExportFromPreferences(); String filename = layoutFile.get(); //change var name? diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index ee0f4449525..3dc9e777449 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -23,8 +23,6 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { //but not yet sure how to make SortedList into a property private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final int size; //final? Or you don't need this and just use a a while loop - //Indices within which export format information is stored within JabRefPreferences private static final int EXPORTER_NAME_INDEX = 0; private static final int EXPORTER_FILENAME_INDEX = 1; @@ -58,7 +56,7 @@ public void loadExporters() { } } - //The following method will have to be implemented to get information from the JavaFX analogue of Swing CustomExportDialog + //The following dialog will have to be implemented as the JavaFX MVVM analogue of Swing CustomExportDialog public void addExporter() { // open add Exporter dialog, set vars as dialogResult or analogous TemplateExporter exporter = new CreateModifyExporterDialogView().show(); //Not sure if this is right diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index e40a6b93686..7a01d7c613c 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2078,4 +2078,10 @@ private void purgeCustomExportFormats(int from) { i++; } } + + @Override + public void setExportWorkingDirectory(String layoutFileDirString) { + put(EXPORT_WORKING_DIRECTORY, layoutFileDirString); + } + } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index e6eaae83c8a..2258dbbd715 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -46,4 +46,6 @@ public interface PreferencesService { LayoutFormatterPreferences getLayoutFormatterPreferences(); SavePreferences LoadForExportFromPreferences(); + + void setExportWorkingDirectory(String layoutFileDirString); } From 3a4baa3993c2a24be00f39d7bb5335bcf13ef297 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Mon, 29 Oct 2018 11:28:57 -0400 Subject: [PATCH 13/75] Fix browse method in export customization subdialog --- .../gui/exporter/CreateModifyExporterDialogViewModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 03192ca3fa7..1d6a0549923 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -102,7 +102,7 @@ public void browse() { .addExtensionFilter(Localization.lang("Custom layout file"), StandardFileType.LAYOUT) .withDefaultExtension(Localization.lang("Custom layout file"), StandardFileType.LAYOUT) .withInitialDirectory(getExportWorkingDirectory()).build(); - dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(f -> setText(f.toAbsolutePath().toString())); //implement setting the text + dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(f -> layoutFile.set(f.toAbsolutePath().toString())); //implement setting the text } } From f63d43c0a9ccd46e041eac6f3dedb4584e6b27e3 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Mon, 29 Oct 2018 12:18:59 -0400 Subject: [PATCH 14/75] Remove int reference in VM --- .../ExportCustomizationDialogViewModel.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index 3dc9e777449..f7144794977 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -22,6 +22,7 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { //exporters should probably be a JavaFX SortedList instead of SimpleListPreperty, //but not yet sure how to make SortedList into a property private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final SimpleListProperty selectedExporters = new SimpleListProperty<>(FXCollections.observableArrayList()); //Indices within which export format information is stored within JabRefPreferences private static final int EXPORTER_NAME_INDEX = 0; @@ -64,17 +65,17 @@ public void addExporter() { } - public void modifyExporter(int row) { + public void modifyExporter() { // open modify Exporter dialog, which may be the same as add Exporter dialog, and set that into exporters. - exporters.set(row, new ExporterViewModel(dialogResult)); //result must come from dialog + exporters.add(new ExporterViewModel(dialogResult)); //result must come from dialog, and this will append the exporter unless you make a sorted list property } - public void removeExporters(int[] rows) { - if (rows.length == 0) { // Is this check necessary? Probably not + public void removeExporters() { + if (selectedExporters.getSize() == 0) { // Is this check necessary? return; } - for (int i = 0; i < rows.length; i++) { - exporters.remove(rows[i]); + for (ExporterViewModel exporter : selectedExporters) { + exporters.remove(exporter); } } From 1f094d6fd9df1bb1e71df3eafd370a0839ec98ff Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Mon, 29 Oct 2018 12:26:46 -0400 Subject: [PATCH 15/75] Create FXML for main exporter customization dialog --- .../exporter/ExportCustomizationDialog.fxml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml new file mode 100644 index 00000000000..4c794207850 --- /dev/null +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 83b7dacd05023e54c75d88a2ee5ed9bbb3bdd500 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Thu, 1 Nov 2018 20:36:26 -0400 Subject: [PATCH 16/75] Work on View, not complete --- .../exporter/ExportCustomizationDialog.fxml | 6 +- .../ExportCustomizationDialogView.java | 67 +++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml index 4c794207850..d0b84479848 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml @@ -15,9 +15,9 @@ - - - + + + diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java new file mode 100644 index 00000000000..d26da1c2e6c --- /dev/null +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java @@ -0,0 +1,67 @@ +package org.jabref.gui.exporter; + +import javax.inject.Inject; + +import javafx.fxml.FXML; +import javafx.scene.control.ButtonType; +import javafx.scene.control.MultipleSelectionModel; +import javafx.scene.control.SelectionModel; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; + +import org.jabref.gui.DialogService; +import org.jabref.gui.util.BaseDialog; +import org.jabref.gui.util.ControlHelper; +import org.jabref.logic.journals.JournalAbbreviationLoader; +import org.jabref.logic.l10n.Localization; +import org.jabref.preferences.PreferencesService; + +import com.airhacks.afterburner.views.ViewLoader; +import org.fxmisc.easybind.EasyBind; + +public class ExportCustomizationDialogView extends BaseDialog { + + @FXML private ButtonType addButton; + @FXML private ButtonType modifyButton; + @FXML private ButtonType removeButton; + @FXML private ButtonType closeButton; + @FXML private TableView exporterTable; + @FXML private TableColumn nameColumn; + @FXML private TableColumn layoutColumn; + @FXML private TableColumn extensionColumn; + + @Inject private DialogService dialogService; + @Inject private PreferencesService preferences; + @Inject private JournalAbbreviationLoader loader; //not sure this should be injected this way + private ExportCustomizationDialogViewModel viewModel; + + public ExportCustomizationDialogView() { + this.setTitle(Localization.lang("Customize Export Formats")); + + ViewLoader.view(this) + .load() + .setAsDialogPane(this); + + ControlHelper.setAction(addButton, getDialogPane(), event -> addExporter()); + ControlHelper.setAction(modifyButton, getDialogPane(), event -> modifyExporter()); + ControlHelper.setAction(removeButton, getDialogPane(), event -> removeExporter()); + } + + @FXML + private void initialize() { + viewModel = new ExportCustomizationDialogViewModel(dialogService, loader); + //enable multiple selection somewhere around here + EasyBind.listBind(viewModel.selectedExportersProperty(), + EasyBind.monadic(exporterTable.selectionModelProperty(). + + ) + //trying something new above + viewModel.selectedExportersProperty().bind( + EasyBind.monadic(exporterTable.selectionModelProperty()). + flatMap(SelectionModel::selectedItemsProperty). //This will have to be done differently from key bindings because it's multiple selection + selectProperty(Item::valueProperty) + ); + + } + +} \ No newline at end of file From 99d7041d38798d91fa90fc2cfea5add26be97c1b Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Fri, 2 Nov 2018 16:56:40 -0400 Subject: [PATCH 17/75] Work on using EasyBind --- .../gui/exporter/ExportCustomizationDialogView.java | 10 +++++----- .../exporter/ExportCustomizationDialogViewModel.java | 9 ++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java index d26da1c2e6c..97653fbff92 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java @@ -8,6 +8,7 @@ import javafx.scene.control.SelectionModel; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; +import javafx.scene.control.TableView.TableViewSelectionModel; import org.jabref.gui.DialogService; import org.jabref.gui.util.BaseDialog; @@ -51,14 +52,13 @@ public ExportCustomizationDialogView() { private void initialize() { viewModel = new ExportCustomizationDialogViewModel(dialogService, loader); //enable multiple selection somewhere around here - EasyBind.listBind(viewModel.selectedExportersProperty(), - EasyBind.monadic(exporterTable.selectionModelProperty(). - - ) + EasyBind.listBind(viewModel.selectedExportersProperty(), //the order may be mixed up here + EasyBind.monadic(exporterTable.selectionModelProperty()) + .selectProperty(MultipleSelectionModel::getSelectedItems)); //trying something new above viewModel.selectedExportersProperty().bind( EasyBind.monadic(exporterTable.selectionModelProperty()). - flatMap(SelectionModel::selectedItemsProperty). //This will have to be done differently from key bindings because it's multiple selection + flatMap(SelectionModel::selectedItemProperty). //This will have to be done differently from key bindings because it's multiple selection selectProperty(Item::valueProperty) ); diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index f7144794977..472ba19668d 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; @@ -33,7 +34,7 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { private final DialogService dialogService; private final JournalAbbreviationLoader loader; - private static final Logger LOGGER = LoggerFactory.getLogger(CustomExportList.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ExportCustomizationDialogViewModel.class); //Other variable declarations here @@ -83,7 +84,13 @@ public void saveToPrefs() { List exportersLogic; exporters.forEach(exporter -> exportersLogic.add(exporter.getLogic())); preferences.storeCustomExportFormats(exportersLogic); + + } + + public ListProperty selectedExportersProperty() { + return selectedExporters; } + public void init() { loadExporters(); } From 04798932b9ba7d0619e80d3924888e037442106b Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 2 Nov 2018 22:26:51 +0100 Subject: [PATCH 18/75] fix some binding issues add stubs --- .../CreateModifyExporterDialogViewModel.java | 13 ++++---- .../ExportCustomizationDialogView.java | 30 +++++++++++-------- .../ExportCustomizationDialogViewModel.java | 3 +- .../jabref/preferences/JabRefPreferences.java | 18 +++++++++++ .../preferences/PreferencesService.java | 2 ++ 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 1d6a0549923..680f9655468 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -5,6 +5,7 @@ import java.util.Optional; import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; @@ -37,9 +38,9 @@ public class CreateModifyExporterDialogViewModel extends AbstractViewModel { private final DialogService dialogService; private final PreferencesService preferences; - private final SimpleStringProperty name; - private final SimpleStringProperty layoutFile; - private final SimpleStringProperty extension; + private final StringProperty name = new SimpleStringProperty(""); + private final StringProperty layoutFile = new SimpleStringProperty(""); + private final StringProperty extension = new SimpleStringProperty(""); public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogService dialogService, PreferencesService preferences, @@ -49,9 +50,9 @@ public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogServ this.preferences = preferences; //Set text of each of the boxes - this.name = name; - this.layoutFile = layoutFile; - this.extension = extension; + this.name.setValue( name); + this.layoutFile.setValue(layoutFile); + this.extension.setValue(extension); } public TemplateExporter saveExporter() {//void? diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java index 97653fbff92..967b1f6684f 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java @@ -4,11 +4,9 @@ import javafx.fxml.FXML; import javafx.scene.control.ButtonType; -import javafx.scene.control.MultipleSelectionModel; -import javafx.scene.control.SelectionModel; +import javafx.scene.control.SelectionMode; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; -import javafx.scene.control.TableView.TableViewSelectionModel; import org.jabref.gui.DialogService; import org.jabref.gui.util.BaseDialog; @@ -18,7 +16,6 @@ import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; -import org.fxmisc.easybind.EasyBind; public class ExportCustomizationDialogView extends BaseDialog { @@ -48,19 +45,26 @@ public ExportCustomizationDialogView() { ControlHelper.setAction(removeButton, getDialogPane(), event -> removeExporter()); } + private void removeExporter() { + // TODO Auto-generated method stub + } + + private void modifyExporter() { + // TODO Auto-generated method stub + } + + private void addExporter() { + // TODO Auto-generated method stub + + } + @FXML private void initialize() { viewModel = new ExportCustomizationDialogViewModel(dialogService, loader); //enable multiple selection somewhere around here - EasyBind.listBind(viewModel.selectedExportersProperty(), //the order may be mixed up here - EasyBind.monadic(exporterTable.selectionModelProperty()) - .selectProperty(MultipleSelectionModel::getSelectedItems)); - //trying something new above - viewModel.selectedExportersProperty().bind( - EasyBind.monadic(exporterTable.selectionModelProperty()). - flatMap(SelectionModel::selectedItemProperty). //This will have to be done differently from key bindings because it's multiple selection - selectProperty(Item::valueProperty) - ); + + exporterTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + exporterTable.setItems(viewModel.selectedExportersProperty()); } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index 472ba19668d..c1836ab3544 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -40,7 +40,8 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { //Also write tests for all of this if necessary - public ExportCustomizationDialogViewModel(DialogService dialogService, JournalAbbreviationLoader loader) { + public ExportCustomizationDialogViewModel(PreferencesService prefernces, DialogService dialogService, JournalAbbreviationLoader loader) { + this.preferences = prefernces; this.dialogService = dialogService; this.loader = loader; init(); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 7a01d7c613c..d090ae295f2 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2084,4 +2084,22 @@ public void setExportWorkingDirectory(String layoutFileDirString) { put(EXPORT_WORKING_DIRECTORY, layoutFileDirString); } + @Override + public LayoutFormatterPreferences getLayoutFormatterPreferences() { + // TODO Auto-generated method stub + return null; + } + + @Override + public SavePreferences LoadForExportFromPreferences() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getExportWorkingDirectory() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 2258dbbd715..f306ded914d 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -48,4 +48,6 @@ public interface PreferencesService { SavePreferences LoadForExportFromPreferences(); void setExportWorkingDirectory(String layoutFileDirString); + + String getExportWorkingDirectory(); } From 547898ce45d53dc2825fa0f73f4673e6bf1f83db Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sat, 3 Nov 2018 14:31:31 -0400 Subject: [PATCH 19/75] More work on Export Customization Dialog --- src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- .../actions/ManageCustomExportsAction.java | 12 ++------- .../ExportCustomizationDialogView.java | 23 +++++++++-------- .../ExportCustomizationDialogViewModel.java | 20 +++++++++------ .../gui/exporter/ExporterViewModel.java | 25 ++++++++++++++++++- .../logic/exporter/TemplateExporter.java | 4 +++ 6 files changed, 56 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 2531456c6f0..df6d700293e 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -928,7 +928,7 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.SETUP_GENERAL_FIELDS, new SetupGeneralFieldsAction()), factory.createMenuItem(StandardActions.MANAGE_CUSTOM_IMPORTS, new ManageCustomImportsAction(this)), - factory.createMenuItem(StandardActions.MANAGE_CUSTOM_EXPORTS, new ManageCustomExportsAction(this)), + factory.createMenuItem(StandardActions.MANAGE_CUSTOM_EXPORTS, new ManageCustomExportsAction()), factory.createMenuItem(StandardActions.MANAGE_EXTERNAL_FILETYPES, new EditExternalFileTypesAction()), factory.createMenuItem(StandardActions.MANAGE_JOURNALS, new ManageJournalsAction()), factory.createMenuItem(StandardActions.CUSTOMIZE_KEYBINDING, new CustomizeKeyBindingAction()), diff --git a/src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.java b/src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.java index 90567f5f820..60298e05555 100644 --- a/src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.java +++ b/src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.java @@ -1,20 +1,12 @@ package org.jabref.gui.actions; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.exporter.ExportCustomizationDialog; +import org.jabref.gui.exporter.ExportCustomizationDialogView; public class ManageCustomExportsAction extends SimpleCommand { - private final JabRefFrame jabRefFrame; - - public ManageCustomExportsAction(JabRefFrame jabRefFrame) { - this.jabRefFrame = jabRefFrame; - } - @Override public void execute() { - ExportCustomizationDialog ecd = new ExportCustomizationDialog(jabRefFrame); - ecd.setVisible(true); + new ExportCustomizationDialogView().show(); } } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java index 967b1f6684f..b681b021d17 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java @@ -16,6 +16,7 @@ import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; +import org.fxmisc.easybind.EasyBind; public class ExportCustomizationDialogView extends BaseDialog { @@ -45,27 +46,27 @@ public ExportCustomizationDialogView() { ControlHelper.setAction(removeButton, getDialogPane(), event -> removeExporter()); } - private void removeExporter() { - // TODO Auto-generated method stub + private void addExporter() { + viewModel.addExporter(); } private void modifyExporter() { - // TODO Auto-generated method stub + viewModel.modifyExporter(); } - private void addExporter() { - // TODO Auto-generated method stub - + private void removeExporter() { + viewModel.removeExporters(); } @FXML private void initialize() { - viewModel = new ExportCustomizationDialogViewModel(dialogService, loader); - //enable multiple selection somewhere around here - + viewModel = new ExportCustomizationDialogViewModel(preferences, dialogService, loader); exporterTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - exporterTable.setItems(viewModel.selectedExportersProperty()); - + // Unidirectional list binding - this is okay because item selection only fires from the View + EasyBind.listBind(viewModel.selectedExportersProperty(), exporterTable.getSelectionModel().getSelectedItems()); + nameColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); + layoutColumn.setCellValueFactory(cellData -> cellData.getValue().getLayoutFileName()); + extensionColumn.setCellValueFactory(cellData -> cellData.getValue().getExtension()); } } \ No newline at end of file diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index c1836ab3544..f8ff5778da2 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -6,6 +6,7 @@ import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; +import javafx.scene.control.Dialog; import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; @@ -22,8 +23,8 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { //exporters should probably be a JavaFX SortedList instead of SimpleListPreperty, //but not yet sure how to make SortedList into a property - private final SimpleListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final SimpleListProperty selectedExporters = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ListProperty selectedExporters = new SimpleListProperty<>(FXCollections.observableArrayList()); //Indices within which export format information is stored within JabRefPreferences private static final int EXPORTER_NAME_INDEX = 0; @@ -40,8 +41,8 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { //Also write tests for all of this if necessary - public ExportCustomizationDialogViewModel(PreferencesService prefernces, DialogService dialogService, JournalAbbreviationLoader loader) { - this.preferences = prefernces; + public ExportCustomizationDialogViewModel(PreferencesService preferences, DialogService dialogService, JournalAbbreviationLoader loader) { + this.preferences = preferences; this.dialogService = dialogService; this.loader = loader; init(); @@ -61,15 +62,16 @@ public void loadExporters() { //The following dialog will have to be implemented as the JavaFX MVVM analogue of Swing CustomExportDialog public void addExporter() { - // open add Exporter dialog, set vars as dialogResult or analogous - TemplateExporter exporter = new CreateModifyExporterDialogView().show(); //Not sure if this is right + TemplateExporter exporter = dialogService.showCustomDialogAndWait(new CreateModifyExporterDialogView()); exporters.add(new ExporterViewModel(exporter));//var might have to be renamed } public void modifyExporter() { // open modify Exporter dialog, which may be the same as add Exporter dialog, and set that into exporters. - exporters.add(new ExporterViewModel(dialogResult)); //result must come from dialog, and this will append the exporter unless you make a sorted list property + Dialog dialog = new CreateModifyExporterDialogView(selectedExporters.get(0)); + TemplateExporter exporter = dialogService.showCustomDialogAndWait(dialog); + exporters.add(new ExporterViewModel(exporter)); //result must come from dialog, and this will append the exporter unless you make a sorted list property } public void removeExporters() { @@ -92,6 +94,10 @@ public ListProperty selectedExportersProperty() { return selectedExporters; } + public ListProperty exportersProperty() { + return exporters; + } + public void init() { loadExporters(); } diff --git a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java index c71428849e1..d5d9463124c 100644 --- a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java @@ -1,17 +1,40 @@ package org.jabref.gui.exporter; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import org.jabref.logic.exporter.TemplateExporter; public class ExporterViewModel { - TemplateExporter exporter; + private final TemplateExporter exporter; //Should this be final? Eclipse says so + private final StringProperty name = new SimpleStringProperty(); + private final StringProperty lfFileName = new SimpleStringProperty(); + //If the TemplateExporter + private final StringProperty extension = new SimpleStringProperty(); public ExporterViewModel(TemplateExporter exporter) { this.exporter = exporter; + this.name.set(exporter.getName()); + this.lfFileName.set(exporter.getLayoutFileName()); + //This should return at least one of the extensions, but may need to be changed to return the most common extension + this.extension.set(exporter.getFileType().getExtensionsWithDot().get(0)); } public TemplateExporter getLogic() { return this.exporter; } + public StringProperty getName() { + return this.name; + + } + + public StringProperty getLayoutFileName() { + return this.lfFileName; + } + + public StringProperty getExtension() { + return this.extension; + } } diff --git a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java index de3a7ab022c..de26cfa34fa 100644 --- a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java +++ b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java @@ -331,4 +331,8 @@ private void readFormatterFile() { } } } + + public String getLayoutFileName() { + return lfFileName; + } } From e2ae2c9f103466e74f12a95aee9e46aea6a24e20 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sat, 3 Nov 2018 16:20:26 -0400 Subject: [PATCH 20/75] FXML changes among other things --- .../CreateModifyExporterDialogViewModel.java | 7 ++----- .../gui/exporter/ExportCustomizationDialog.fxml | 12 +++++------- .../gui/exporter/ExportCustomizationDialogView.java | 1 + .../org/jabref/gui/exporter/ExporterViewModel.java | 6 +++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 680f9655468..6fabdd44326 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -2,8 +2,6 @@ import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Optional; - import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -16,7 +14,6 @@ import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.util.FileType; import org.jabref.logic.util.StandardFileType; -import org.jabref.preferences.JabRefPreferences; //will be removed with writing of new method import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -50,7 +47,7 @@ public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogServ this.preferences = preferences; //Set text of each of the boxes - this.name.setValue( name); + this.name.setValue(name); this.layoutFile.setValue(layoutFile); this.extension.setValue(extension); } @@ -67,7 +64,7 @@ public TemplateExporter saveExporter() {//void? if (layoutFile.get().isEmpty() || name.get().isEmpty() || extension.get().isEmpty() || !layoutFile.get().endsWith(".layout")) { - LOGGER.info("One of the fields is empty!"); //TODO: Better error message + LOGGER.info("One of the fields is empty!"); return null; //return implemented similarly to CleanupDialog, although JavaFX documentation says you need something //like a result converter, which must be in the view, see class EntryTypeView } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml index d0b84479848..0ff4d41a034 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialog.fxml @@ -1,23 +1,21 @@ - - + - - + - - - + + + diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java index b681b021d17..99c396370ee 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java @@ -62,6 +62,7 @@ private void removeExporter() { private void initialize() { viewModel = new ExportCustomizationDialogViewModel(preferences, dialogService, loader); exporterTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + exporterTable.itemsProperty().bind(viewModel.exportersProperty()); // Unidirectional list binding - this is okay because item selection only fires from the View EasyBind.listBind(viewModel.selectedExportersProperty(), exporterTable.getSelectionModel().getSelectedItems()); nameColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); diff --git a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java index d5d9463124c..e523bc84235 100644 --- a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java @@ -15,10 +15,10 @@ public class ExporterViewModel { public ExporterViewModel(TemplateExporter exporter) { this.exporter = exporter; - this.name.set(exporter.getName()); - this.lfFileName.set(exporter.getLayoutFileName()); + this.name.setValue(exporter.getName()); + this.lfFileName.setValue(exporter.getLayoutFileName()); //This should return at least one of the extensions, but may need to be changed to return the most common extension - this.extension.set(exporter.getFileType().getExtensionsWithDot().get(0)); + this.extension.setValue(exporter.getFileType().getExtensionsWithDot().get(0)); } public TemplateExporter getLogic() { From 3be56720d5eb48c7b70f627575e7d75e260820d1 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Tue, 6 Nov 2018 08:55:32 -0500 Subject: [PATCH 21/75] Work on View for subdialog --- .../CreateModifyExporterDialogViewModel.java | 29 ++++++++++++++----- .../ExportCustomizationDialogViewModel.java | 20 +++++++------ .../jabref/preferences/JabRefPreferences.java | 2 +- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 6fabdd44326..87ca7d1b4ea 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -2,6 +2,8 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Optional; + import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -31,7 +33,7 @@ public class CreateModifyExporterDialogViewModel extends AbstractViewModel { private static final Logger LOGGER = LoggerFactory.getLogger(CreateModifyExporterDialogViewModel.class); - private final TemplateExporter exporter; + private final ExporterViewModel exporter; //Maybe you should get rid of this - maybe the exporter can be held by am ExporterVM that directly observes the View private final DialogService dialogService; private final PreferencesService preferences; @@ -40,16 +42,15 @@ public class CreateModifyExporterDialogViewModel extends AbstractViewModel { private final StringProperty extension = new SimpleStringProperty(""); - public CreateModifyExporterDialogViewModel(TemplateExporter exporter, DialogService dialogService, PreferencesService preferences, - String name, String layoutFile, String extension) { - this.exporter = exporter; + public CreateModifyExporterDialogViewModel(Optional exporter, DialogService dialogService, PreferencesService preferences, + String name, String layoutFile, String extension) { //get ride of name, layout file, extension, take them from exporter + this.exporter = exporter.orElse(null); //Is using null the right way of doing this? this.dialogService = dialogService; this.preferences = preferences; - //Set text of each of the boxes - this.name.setValue(name); - this.layoutFile.setValue(layoutFile); - this.extension.setValue(extension); + setTextFields() + + } public TemplateExporter saveExporter() {//void? @@ -103,4 +104,16 @@ public void browse() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(f -> layoutFile.set(f.toAbsolutePath().toString())); //implement setting the text } + private void setTextFields() { + + //Set text of each of the boxes + name.setValue(exporter.getName().get()); //Should this even be done in this VM, or should the View direclty bind to the ExporterVM? + layoutFile.setValue(exporter.getLayoutFileName().get()); + extension.setValue(exporter.getExtension().get())); + } + + public StringProperty getName() { + return name; + } + } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index f8ff5778da2..ba43c50b12a 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -2,12 +2,11 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; -import javafx.scene.control.Dialog; - import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; import org.jabref.logic.exporter.TemplateExporter; @@ -62,16 +61,19 @@ public void loadExporters() { //The following dialog will have to be implemented as the JavaFX MVVM analogue of Swing CustomExportDialog public void addExporter() { - TemplateExporter exporter = dialogService.showCustomDialogAndWait(new CreateModifyExporterDialogView()); - exporters.add(new ExporterViewModel(exporter));//var might have to be renamed - + Optional exporter = dialogService.showCustomDialogAndWait(new CreateModifyExporterDialogView()); + if (exporter.isPresent()) { + exporters.add(exporter.get()); + } } public void modifyExporter() { // open modify Exporter dialog, which may be the same as add Exporter dialog, and set that into exporters. - Dialog dialog = new CreateModifyExporterDialogView(selectedExporters.get(0)); - TemplateExporter exporter = dialogService.showCustomDialogAndWait(dialog); - exporters.add(new ExporterViewModel(exporter)); //result must come from dialog, and this will append the exporter unless you make a sorted list property + //Make the following line shorter + Optional exporter = dialogService.showCustomDialogAndWait(new CreateModifyExporterDialogView(selectedExporters.get(0))); + if (exporter.isPresent()) { + exporters.add(exporter.get()); //result must come from dialog, and this will append the exporter unless you make a sorted list property + } } public void removeExporters() { @@ -84,7 +86,7 @@ public void removeExporters() { } public void saveToPrefs() { - List exportersLogic; + List exportersLogic = new ArrayList<>(); exporters.forEach(exporter -> exportersLogic.add(exporter.getLogic())); preferences.storeCustomExportFormats(exportersLogic); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index d090ae295f2..8191b522abc 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2018,7 +2018,7 @@ public Map getMainTableColumnSortTypes() { @Override public List getCustomExportFormats(JournalAbbreviationLoader loader) { int i = 0; - List formats = null; + List formats = new ArrayList<>(); String exporterName; String filename; String extension; From debd2bc0437aece7258241a6ceb74879e63e2677 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Tue, 6 Nov 2018 17:57:23 -0500 Subject: [PATCH 22/75] Changes to View and logic --- .../CreateModifyExporterDialogViewModel.java | 9 ++++++++ .../ExportCustomizationDialogView.java | 2 +- .../ExportCustomizationDialogViewModel.java | 22 +++++++++---------- .../gui/exporter/ExporterViewModel.java | 4 ++++ .../logic/exporter/TemplateExporter.java | 5 +++++ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 87ca7d1b4ea..88b42fb06e7 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -4,6 +4,7 @@ import java.nio.file.Paths; import java.util.Optional; +import javafx.beans.property.Property; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -116,4 +117,12 @@ public StringProperty getName() { return name; } + public StringProperty getLayoutFileName() {ß + return layoutFile; + } + + public StringProperty getExtension() { + return extension; + } + } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java index 99c396370ee..6b001e5b55e 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java @@ -63,7 +63,7 @@ private void initialize() { viewModel = new ExportCustomizationDialogViewModel(preferences, dialogService, loader); exporterTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); exporterTable.itemsProperty().bind(viewModel.exportersProperty()); - // Unidirectional list binding - this is okay because item selection only fires from the View + // Unidirectional list binding - this is okay because item selection only fires from the View, not the other way around EasyBind.listBind(viewModel.selectedExportersProperty(), exporterTable.getSelectionModel().getSelectedItems()); nameColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); layoutColumn.setCellValueFactory(cellData -> cellData.getValue().getLayoutFileName()); diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index ba43c50b12a..c52d0e7201c 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -25,7 +25,7 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { private final ListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); private final ListProperty selectedExporters = new SimpleListProperty<>(FXCollections.observableArrayList()); - //Indices within which export format information is stored within JabRefPreferences + //Indices within which export format information is stored within JabRefPreferences, currently unused private static final int EXPORTER_NAME_INDEX = 0; private static final int EXPORTER_FILENAME_INDEX = 1; private static final int EXPORTER_EXTENSION_INDEX = 2; @@ -34,11 +34,7 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { private final DialogService dialogService; private final JournalAbbreviationLoader loader; - private static final Logger LOGGER = LoggerFactory.getLogger(ExportCustomizationDialogViewModel.class); - - //Other variable declarations here - - //Also write tests for all of this if necessary + private static final Logger LOGGER = LoggerFactory.getLogger(ExportCustomizationDialogViewModel.class); //currently unused public ExportCustomizationDialogViewModel(PreferencesService preferences, DialogService dialogService, JournalAbbreviationLoader loader) { this.preferences = preferences; @@ -53,24 +49,26 @@ public ExportCustomizationDialogViewModel(PreferencesService preferences, Dialog } public void loadExporters() { - List exportersLogic = preferences.getCustomExportFormats(loader); //Var may need more descriptive name + List exportersLogic = preferences.getCustomExportFormats(loader); //Var exportersLogic may need more descriptive name for (TemplateExporter exporter : exportersLogic) { exporters.add(new ExporterViewModel(exporter)); } } - //The following dialog will have to be implemented as the JavaFX MVVM analogue of Swing CustomExportDialog public void addExporter() { - Optional exporter = dialogService.showCustomDialogAndWait(new CreateModifyExporterDialogView()); + ExporterViewModel blankExporter = new ExporterViewModel(); + CreateModifyExporterDialogView dialog = new CreateModifyExporterDialogView(blankExporter); + Optional exporter = dialogService.showCustomDialogAndWait(dialog); if (exporter.isPresent()) { exporters.add(exporter.get()); } } public void modifyExporter() { - // open modify Exporter dialog, which may be the same as add Exporter dialog, and set that into exporters. - //Make the following line shorter - Optional exporter = dialogService.showCustomDialogAndWait(new CreateModifyExporterDialogView(selectedExporters.get(0))); + // open modify Exporter dialog, which is the same as add Exporter dialog but beginning with a non-blank ExporterViewModel, + // and set that into exporters. + CreateModifyExporterDialogView dialog = new CreateModifyExporterDialogView(selectedExporters.get(0)); + Optional exporter = dialogService.showCustomDialogAndWait(dialog); if (exporter.isPresent()) { exporters.add(exporter.get()); //result must come from dialog, and this will append the exporter unless you make a sorted list property } diff --git a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java index e523bc84235..353b1547d81 100644 --- a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java @@ -13,6 +13,10 @@ public class ExporterViewModel { //If the TemplateExporter private final StringProperty extension = new SimpleStringProperty(); + public ExporterViewModel() { + this(new TemplateExporter()); //You will need a new constructor in logic for this, that is probably also called by JAbREf preferences, for creating a new TE in the Export Customization subdialog + } + public ExporterViewModel(TemplateExporter exporter) { this.exporter = exporter; this.name.setValue(exporter.getName()); diff --git a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java index de26cfa34fa..f0a444055f0 100644 --- a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java +++ b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java @@ -66,6 +66,11 @@ public TemplateExporter(String displayName, String consoleName, String lfFileNam this(displayName, consoleName, lfFileName, directory, extension, null, null); } + //Following to be used by Export Customization dialogs, may want to change, especially directory being null + public TemplateExporter(String name, String lfFileName, String extension) { + this(name, name, lfFileName, null, StandardFileType.newFileType(extension), null, null); + } + /** * Initialize another export format based on templates stored in dir with * layoutFile lfFilename. From 7141a463e08cee4d7d62dee1f461a4487cb37e1e Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Thu, 8 Nov 2018 10:21:02 -0500 Subject: [PATCH 23/75] Deal with stubs, convert some EVMs to Optionals --- .../CreateModifyExporterDialogViewModel.java | 12 ++++--- .../ExportCustomizationDialogViewModel.java | 36 +++++++++---------- .../gui/exporter/ExporterViewModel.java | 4 --- .../logic/exporter/TemplateExporter.java | 7 ++-- .../jabref/preferences/JabRefPreferences.java | 17 ++------- .../preferences/PreferencesService.java | 2 +- 6 files changed, 34 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 88b42fb06e7..f60d19c8ee8 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -13,6 +13,7 @@ import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.exporter.SavePreferences; import org.jabref.logic.exporter.TemplateExporter; +import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.util.FileType; @@ -42,14 +43,17 @@ public class CreateModifyExporterDialogViewModel extends AbstractViewModel { private final StringProperty layoutFile = new SimpleStringProperty(""); private final StringProperty extension = new SimpleStringProperty(""); + private final JournalAbbreviationLoader loader; + public CreateModifyExporterDialogViewModel(Optional exporter, DialogService dialogService, PreferencesService preferences, - String name, String layoutFile, String extension) { //get ride of name, layout file, extension, take them from exporter + JournalAbbreviationLoader loader) { //get ride of name, layout file, extension, take them from exporter this.exporter = exporter.orElse(null); //Is using null the right way of doing this? this.dialogService = dialogService; this.preferences = preferences; + this.loader = loader; - setTextFields() + setTextFields(); } @@ -72,7 +76,7 @@ public TemplateExporter saveExporter() {//void? } // Create a new exporter to be returned to ExportCustomizationDialogViewModel, which requested it - LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(); + LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(loader); SavePreferences savePreferences = preferences.LoadForExportFromPreferences(); String filename = layoutFile.get(); //change var name? String extensionString = extension.get(); //change var name? @@ -110,7 +114,7 @@ private void setTextFields() { //Set text of each of the boxes name.setValue(exporter.getName().get()); //Should this even be done in this VM, or should the View direclty bind to the ExporterVM? layoutFile.setValue(exporter.getLayoutFileName().get()); - extension.setValue(exporter.getExtension().get())); + extension.setValue(exporter.getExtension().get()); } public StringProperty getName() { diff --git a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java index c52d0e7201c..74ed50edf04 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogViewModel.java @@ -13,9 +13,6 @@ import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.preferences.PreferencesService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class ExportCustomizationDialogViewModel extends AbstractViewModel { //The class vars might need to be reordered @@ -25,17 +22,11 @@ public class ExportCustomizationDialogViewModel extends AbstractViewModel { private final ListProperty exporters = new SimpleListProperty<>(FXCollections.observableArrayList()); private final ListProperty selectedExporters = new SimpleListProperty<>(FXCollections.observableArrayList()); - //Indices within which export format information is stored within JabRefPreferences, currently unused - private static final int EXPORTER_NAME_INDEX = 0; - private static final int EXPORTER_FILENAME_INDEX = 1; - private static final int EXPORTER_EXTENSION_INDEX = 2; private final PreferencesService preferences; private final DialogService dialogService; private final JournalAbbreviationLoader loader; - private static final Logger LOGGER = LoggerFactory.getLogger(ExportCustomizationDialogViewModel.class); //currently unused - public ExportCustomizationDialogViewModel(PreferencesService preferences, DialogService dialogService, JournalAbbreviationLoader loader) { this.preferences = preferences; this.dialogService = dialogService; @@ -56,21 +47,30 @@ public void loadExporters() { } public void addExporter() { - ExporterViewModel blankExporter = new ExporterViewModel(); - CreateModifyExporterDialogView dialog = new CreateModifyExporterDialogView(blankExporter); - Optional exporter = dialogService.showCustomDialogAndWait(dialog); - if (exporter.isPresent()) { - exporters.add(exporter.get()); + Optional blankExporter = Optional.empty(); + CreateModifyExporterDialogView dialog = new CreateModifyExporterDialogView(blankExporter, dialogService, preferences, + loader); + Optional> exporter = dialogService.showCustomDialogAndWait(dialog); + if (exporter.isPresent() && exporter.get().isPresent()) { + exporters.add(exporter.get().get()); } } public void modifyExporter() { // open modify Exporter dialog, which is the same as add Exporter dialog but beginning with a non-blank ExporterViewModel, // and set that into exporters. - CreateModifyExporterDialogView dialog = new CreateModifyExporterDialogView(selectedExporters.get(0)); - Optional exporter = dialogService.showCustomDialogAndWait(dialog); - if (exporter.isPresent()) { - exporters.add(exporter.get()); //result must come from dialog, and this will append the exporter unless you make a sorted list property + CreateModifyExporterDialogView dialog; + try { + dialog = new CreateModifyExporterDialogView(Optional.of(selectedExporters.get(0)), + dialogService, preferences, loader); + } catch (IndexOutOfBoundsException ex) { + Optional emptyExporter = Optional.empty(); + dialog = new CreateModifyExporterDialogView(emptyExporter, dialogService, + preferences, loader); + } + Optional> exporter = dialogService.showCustomDialogAndWait(dialog); + if (exporter.isPresent() && exporter.get().isPresent()) { //First optional because you may not have entered a exporter to begin with, and second because you may not have outputted one at the end + exporters.add(exporter.get().get()); // this will append the exporter unless you make a sorted list property } } diff --git a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java index 353b1547d81..e523bc84235 100644 --- a/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/ExporterViewModel.java @@ -13,10 +13,6 @@ public class ExporterViewModel { //If the TemplateExporter private final StringProperty extension = new SimpleStringProperty(); - public ExporterViewModel() { - this(new TemplateExporter()); //You will need a new constructor in logic for this, that is probably also called by JAbREf preferences, for creating a new TE in the Export Customization subdialog - } - public ExporterViewModel(TemplateExporter exporter) { this.exporter = exporter; this.name.setValue(exporter.getName()); diff --git a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java index f0a444055f0..0fe6bc4950c 100644 --- a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java +++ b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java @@ -66,9 +66,10 @@ public TemplateExporter(String displayName, String consoleName, String lfFileNam this(displayName, consoleName, lfFileName, directory, extension, null, null); } - //Following to be used by Export Customization dialogs, may want to change, especially directory being null - public TemplateExporter(String name, String lfFileName, String extension) { - this(name, name, lfFileName, null, StandardFileType.newFileType(extension), null, null); + //Following to be used by Export Customization dialogs, as of now directory can be null for custom exports + public TemplateExporter(String name, String lfFileName, String extension, LayoutFormatterPreferences layoutPreferences, + SavePreferences savePreferences) { + this(name, name, lfFileName, null, StandardFileType.newFileType(extension), layoutPreferences, savePreferences); } /** diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 8191b522abc..1dca1ab4049 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -1468,6 +1468,7 @@ public ImportFormatPreferences getImportFormatPreferences() { isKeywordSyncEnabled()); } + @Override public SavePreferences loadForExportFromPreferences() { Boolean saveInOriginalOrder = this.getBoolean(JabRefPreferences.EXPORT_IN_ORIGINAL_ORDER); SaveOrderConfig saveOrder = null; @@ -1530,6 +1531,7 @@ public TimestampPreferences getTimestampPreferences() { return new TimestampPreferences(getBoolean(USE_TIME_STAMP), getBoolean(UPDATE_TIMESTAMP), get(TIME_STAMP_FIELD), get(TIME_STAMP_FORMAT), getBoolean(OVERWRITE_TIME_STAMP)); } + @Override public LayoutFormatterPreferences getLayoutFormatterPreferences( JournalAbbreviationLoader journalAbbreviationLoader) { Objects.requireNonNull(journalAbbreviationLoader); @@ -2084,22 +2086,9 @@ public void setExportWorkingDirectory(String layoutFileDirString) { put(EXPORT_WORKING_DIRECTORY, layoutFileDirString); } - @Override - public LayoutFormatterPreferences getLayoutFormatterPreferences() { - // TODO Auto-generated method stub - return null; - } - - @Override - public SavePreferences LoadForExportFromPreferences() { - // TODO Auto-generated method stub - return null; - } - @Override public String getExportWorkingDirectory() { - // TODO Auto-generated method stub - return null; + return get(EXPORT_WORKING_DIRECTORY); } } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index f306ded914d..81fafe055d5 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -43,7 +43,7 @@ public interface PreferencesService { void storeCustomExportFormats(List exporters); - LayoutFormatterPreferences getLayoutFormatterPreferences(); + LayoutFormatterPreferences getLayoutFormatterPreferences(JournalAbbreviationLoader loader); SavePreferences LoadForExportFromPreferences(); From 889489b5de95e53796e1dc09e40aa671f765cd53 Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sat, 10 Nov 2018 17:18:40 -0500 Subject: [PATCH 24/75] Change Optional in subdialog --- .../CreateModifyExporterDialogViewModel.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index f60d19c8ee8..6075a394a1f 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -4,7 +4,6 @@ import java.nio.file.Paths; import java.util.Optional; -import javafx.beans.property.Property; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -35,7 +34,6 @@ public class CreateModifyExporterDialogViewModel extends AbstractViewModel { private static final Logger LOGGER = LoggerFactory.getLogger(CreateModifyExporterDialogViewModel.class); - private final ExporterViewModel exporter; //Maybe you should get rid of this - maybe the exporter can be held by am ExporterVM that directly observes the View private final DialogService dialogService; private final PreferencesService preferences; @@ -48,17 +46,17 @@ public class CreateModifyExporterDialogViewModel extends AbstractViewModel { public CreateModifyExporterDialogViewModel(Optional exporter, DialogService dialogService, PreferencesService preferences, JournalAbbreviationLoader loader) { //get ride of name, layout file, extension, take them from exporter - this.exporter = exporter.orElse(null); //Is using null the right way of doing this? + //this.exporter = exporter.orElse(null); //Is using null the right way of doing this? this.dialogService = dialogService; this.preferences = preferences; this.loader = loader; - setTextFields(); + setTextFields(exporter); } - public TemplateExporter saveExporter() {//void? + public Optional saveExporter() { Path layoutFileDir = Paths.get(layoutFile.get()).getParent(); if (layoutFileDir != null) { String layoutFileDirString = layoutFileDir.toString(); @@ -71,7 +69,7 @@ public TemplateExporter saveExporter() {//void? || !layoutFile.get().endsWith(".layout")) { LOGGER.info("One of the fields is empty!"); - return null; //return implemented similarly to CleanupDialog, although JavaFX documentation says you need something + return Optional.empty(); //return implemented similarly to CleanupDialog, although JavaFX documentation says you need something //like a result converter, which must be in the view, see class EntryTypeView } @@ -94,7 +92,7 @@ public TemplateExporter saveExporter() {//void? TemplateExporter format = new TemplateExporter(name.get(), name.get(), lfFileName, null, fileType, layoutPreferences, savePreferences); format.setCustomExport(true); - return format; + return Optional.of(new ExporterViewModel(format)); } public String getExportWorkingDirectory() {//i.e. layout dir @@ -109,19 +107,21 @@ public void browse() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(f -> layoutFile.set(f.toAbsolutePath().toString())); //implement setting the text } - private void setTextFields() { + private void setTextFields(Optional exporter) { //Set text of each of the boxes - name.setValue(exporter.getName().get()); //Should this even be done in this VM, or should the View direclty bind to the ExporterVM? - layoutFile.setValue(exporter.getLayoutFileName().get()); - extension.setValue(exporter.getExtension().get()); + if (exporter.isPresent()) { + name.setValue(exporter.get().getName().get()); + layoutFile.setValue(exporter.get().getLayoutFileName().get()); + extension.setValue(exporter.get().getExtension().get()); + } } public StringProperty getName() { return name; } - public StringProperty getLayoutFileName() {ß + public StringProperty getLayoutFileName() { return layoutFile; } From 1fb234d8b386042830032d7cf367a683cfc6e64e Mon Sep 17 00:00:00 2001 From: Abraham Polk Date: Sat, 10 Nov 2018 17:26:44 -0500 Subject: [PATCH 25/75] Add FXML and View --- .../exporter/CreateModifyExporterDialog.fxml | 54 +++++++++++++ .../CreateModifyExporterDialogView.java | 77 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialog.fxml create mode 100644 src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogView.java diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialog.fxml b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialog.fxml new file mode 100644 index 00000000000..412fcab3624 --- /dev/null +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialog.fxml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + +