Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Convert Exporter Customization Dialog to javafx #4394

Merged
merged 78 commits into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
f120b41
Exporter to JavaFX commit 1
abepolk Oct 19, 2018
12e3e7d
Work on Export Customization Dialog VM
abepolk Oct 21, 2018
ec364ad
Work on VM
abepolk Oct 21, 2018
f5c89fa
Combine methods in CustomExporterList and move to preferences
abepolk Oct 25, 2018
6773b22
work on VM
abepolk Oct 25, 2018
1f318f0
Add methods to VM
abepolk Oct 25, 2018
1a0b760
Fix typos
abepolk Oct 25, 2018
5c65b57
started work on exporter subdialog
abepolk Oct 26, 2018
2de4124
Continue work on exporter subdialog
abepolk Oct 26, 2018
a869aa2
Implement save exporter from add/modify exporter dialog
abepolk Oct 27, 2018
9ae84c0
Add two comments
abepolk Oct 27, 2018
e992c5d
More work on VMs and prefs
abepolk Oct 29, 2018
3a4baa3
Fix browse method in export customization subdialog
abepolk Oct 29, 2018
f63d43c
Remove int reference in VM
abepolk Oct 29, 2018
1f094d6
Create FXML for main exporter customization dialog
abepolk Oct 29, 2018
83b7dac
Work on View, not complete
abepolk Nov 2, 2018
99d7041
Work on using EasyBind
abepolk Nov 2, 2018
0479893
fix some binding issues add stubs
Siedlerchr Nov 2, 2018
547898c
More work on Export Customization Dialog
abepolk Nov 3, 2018
e2ae2c9
FXML changes among other things
abepolk Nov 3, 2018
3be5672
Work on View for subdialog
abepolk Nov 6, 2018
debd2bc
Changes to View and logic
abepolk Nov 6, 2018
7141a46
Deal with stubs, convert some EVMs to Optionals
abepolk Nov 8, 2018
889489b
Change Optional in subdialog
abepolk Nov 10, 2018
1fb234d
Add FXML and View
abepolk Nov 10, 2018
e17d0da
Remove typos and syntax error
abepolk Nov 11, 2018
73e683a
Move various code to logic
abepolk Nov 12, 2018
19720cc
Fix modify exporter
abepolk Nov 12, 2018
4e8c8df
Fix remove and close bugs
abepolk Nov 12, 2018
3618f83
Merge branch 'master' into exporter_to_javafx
abepolk Nov 12, 2018
51a726e
Fix customExports references
abepolk Nov 12, 2018
1821da3
Merge remote-tracking branch 'upstream/master' into exporter_to_javafx
abepolk Nov 12, 2018
d339f78
Fix get custom prefs
abepolk Nov 12, 2018
eea34ed
Remove prefs.customExports object from JabRef
abepolk Nov 12, 2018
d36eec2
Small FXML changes
abepolk Nov 12, 2018
294a367
Remove unused old Swing dialogs
abepolk Nov 12, 2018
4269ca0
Fix indentation
abepolk Nov 12, 2018
25db576
Make clear comments and Javadoc
abepolk Nov 12, 2018
3b54bc8
Remove CustomExportList
abepolk Nov 12, 2018
84f293e
Use new TemplateExporter constructor
abepolk Nov 12, 2018
00bac82
Fix spacing and a var name
abepolk Nov 12, 2018
b26d592
Add constant vars to prefs
abepolk Nov 12, 2018
b681ae8
Remove comments
abepolk Nov 12, 2018
be47855
Change log message
abepolk Nov 13, 2018
9aa0887
Fix tests
abepolk Nov 13, 2018
d7277e8
Add spacing between imports
abepolk Nov 13, 2018
7087cfb
Update localization
abepolk Nov 13, 2018
1daf7c4
Replace Optional parameter with null
abepolk Nov 24, 2018
83d490a
Replace Optional return with null
abepolk Nov 24, 2018
17d20cc
Remove AnchorPane
abepolk Nov 26, 2018
40eed27
Localize FXML labels
abepolk Nov 26, 2018
379f201
Add subdialog injections
abepolk Nov 26, 2018
4679150
Set browse action in FXML
abepolk Nov 26, 2018
0053abf
Add to l10n
abepolk Nov 26, 2018
9442025
Add cancel button to subdialog
abepolk Nov 26, 2018
de3bf63
Correction to VM try-catch
abepolk Nov 26, 2018
19d8c62
Inline setTextFields
abepolk Nov 26, 2018
df42676
Remove SortedList TODO
abepolk Nov 26, 2018
f31bc51
Inline closeDialog
abepolk Nov 26, 2018
d95a1aa
loadExporters to private
abepolk Nov 26, 2018
80ffa33
forEach to Stream and other fixes
abepolk Nov 26, 2018
5f56c25
inline init
abepolk Nov 26, 2018
f1d920e
Fixes to ExporterViewModel
abepolk Nov 26, 2018
f22e97a
Remove Optional
abepolk Nov 26, 2018
252ecbb
Add constants to TemplateExporter
abepolk Nov 27, 2018
ccdbf1f
Simplify getExtensions without dot
abepolk Nov 29, 2018
aba31a6
Merge branch 'master' into exporter_to_javafx
abepolk Nov 29, 2018
8cd7ff3
Change try-catch to empty list check
abepolk Nov 29, 2018
3e09a7b
Remove unnecessary method
abepolk Nov 29, 2018
3051022
Fix property getters
abepolk Nov 29, 2018
0ef3061
Fix property getters again
abepolk Nov 29, 2018
7bf6dd6
Fix typo
abepolk Nov 29, 2018
93838de
Update references to customFormats
abepolk Nov 29, 2018
a79d037
Add import
abepolk Nov 29, 2018
70479cb
Travis CI fixes
abepolk Nov 30, 2018
bf22adf
Further Travis CI fixes
abepolk Dec 5, 2018
c2b3489
Remove extra comments
abepolk Dec 8, 2018
a364e1d
Remove extra newlines
abepolk Dec 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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 {

//This could be separated into two dialogs, one for adding exporters and one for modifying them.
//See the two constructors for the view

//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;

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;
this.dialogService = dialogService;
this.preferences = preferences;
//Set text of each of the boxes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure checkstyle will complain about too many empty lines(not more than one)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fixing spacing and putting it in my next push. Thanks!

}

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

}
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;
//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 {
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To set the text, you would create a StringProperty here, e.g. selectedPath and then bind that property to a textfield in the View

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it. I think I had the property, but I hadn't realized this is what I needed here. Thanks for your recommendation!

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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.AbstractViewModel;
import org.jabref.gui.DialogService;
import org.jabref.logic.exporter.TemplateExporter;
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

//exporters should probably be a JavaFX SortedList instead of SimpleListPreperty,
//but not yet sure how to make SortedList into a property
private final SimpleListProperty<ExporterViewModel> 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 final JournalAbbreviationLoader loader;

private static final Logger LOGGER = LoggerFactory.getLogger(CustomExportList.class);

//Other variable declarations here

//Also write tests for all of this if necessary

public ExportCustomizationDialogViewModel(DialogService dialogService, JournalAbbreviationLoader loader) {
this.dialogService = dialogService;
this.loader = loader;
init();

//ExporterViewModel is organized as a singular version of what now is CustomExportDialog, which
//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

}

public void loadExporters() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if this method can be made private.

List<TemplateExporter> exportersLogic = preferences.getCustomExportFormats(loader); //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
TemplateExporter exporter = new CreateModifyExporterDialogView().show(); //Not sure if this is right
exporters.add(new ExporterViewModel(exporter));//var might have to be renamed

}

public void modifyExporter(int row) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need an int here? It would be generally better if you just operate on the row object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I need it. I changed it to use a property selectedExporters.

// 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<TemplateExporter> exportersLogic;
exporters.forEach(exporter -> exportersLogic.add(exporter.getLogic()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find List<TemplateExporter> exportersLogic = exporters.stream().map(ExporterViewModel:getLogic).collect(toList()); more readable, but this is a matter of taste.

preferences.storeCustomExportFormats(exportersLogic);
}
public void init() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline?

loadExporters();
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/jabref/gui/exporter/ExporterViewModel.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
66 changes: 66 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2012,4 +2014,68 @@ public Map<String, SortType> getMainTableColumnSortTypes() {
}
return map;
}

@Override
public List<TemplateExporter> getCustomExportFormats(JournalAbbreviationLoader loader) {
int i = 0;
List<TemplateExporter> formats = null;
String exporterName;
String filename;
String extension;
String lfFileName;
LayoutFormatterPreferences layoutPreferences = getLayoutFormatterPreferences(loader);
SavePreferences savePreferences = loadForExportFromPreferences();
List<String> 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pleas use constants for the indicies, e.g. EXPORTER_NAME_INDEX = 0
And please use a better name for "s"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed these issues.

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 {
lfFileName = filename;
}
if (extension.contains(".")) {
extension = extension.substring(extension.indexOf('.') + 1, extension.length());
}
FileType fileType = StandardFileType.newFileType(extension);
Optional<TemplateExporter> 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;
}

@Override
public void storeCustomExportFormats(List<TemplateExporter> exporters) {
if (exporters.isEmpty()) {
purgeCustomExportFormats(0);
} else {
for (int i = 0; i < exporters.size(); i++) {
List<String> 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++;
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/preferences/PreferencesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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 {
Expand Down Expand Up @@ -35,4 +39,11 @@ public interface PreferencesService {

public void updateEntryEditorTabList();

List<TemplateExporter> getCustomExportFormats(JournalAbbreviationLoader loader);

void storeCustomExportFormats(List<TemplateExporter> exporters);

LayoutFormatterPreferences getLayoutFormatterPreferences();

SavePreferences LoadForExportFromPreferences();
}