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 3 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,71 @@
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;

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<Void> {
Copy link
Member

Choose a reason for hiding this comment

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

The View/Dialog class should derive from BaseDialog and not the view model.


//The class vars might need to be reordered

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 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"?
List<String> s;
while (!((s = preferences.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) {
//Shuold createFormat be in logic? Check how it works in CustomExportList
Optional<ExporterViewModel> 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
//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

}

//possibly not necessary, and if so getSortedList will have to return the correct type, not Eventlist<List<String>>
public List<ExporterViewModel> loadExporters() {
Copy link
Member

Choose a reason for hiding this comment

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

You might don't need the gui-wrapper ExporterViewModel around Exporter. In general such a wrapper is needed to adapt the properties of the model to display it to the user. But, here, the data of an exporter is relatively simple and the already in a suitable format for the gui.

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 put the data in the GUI wrapper ExporterViewModel for now. How would I create the TableView and TableColumns without a ViewModel for the data? All the examples I could find in JabRef and online had some sort of ViewModel.

Copy link
Member

Choose a reason for hiding this comment

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

You can also simply use Exporter as the datatype for the TableView. But if you have already created a ViewModel for it, keep it. It is probably the cleaner approach and more versatile for the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I've finished, but not tested, most of the ViewModel. I just have to add the dialog to add or modify the exporter, and then create the View and FXML. Unless there's something I forgot...

return preferences.customExports.getSortedList(); //As of now getSortedList refers to EventList<List<String>>
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/preferences/PreferencesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public interface PreferencesService {

public void updateEntryEditorTabList();

List<String> getStringList(String key);
Copy link
Member

Choose a reason for hiding this comment

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

Please no generic methods here, create specific ones for the cases you need, e.g. get CustomExporters or getExporterormat... Or you create CustomExporter preferences which has all the needed information inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Swing version has a class CustomExportList which holds a list of custom exporters and associated data. I was going to move some of the code here into the ExporterViewModel and other code into the ExporterCustomizationDialogViewModel. Do you recommend keeping the CustomExportList as it is?

Copy link
Member

Choose a reason for hiding this comment

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

The PreferencesService should only contain usecase-specific preference methods and the caller shouldn't care about how these information are stored in the preferences. So, here, the method would look like List<Exporter> getCustomExportFormats() and then in the implementation there would be calls like preferences.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).

Thus, most of the code in CustomExportList should go into JabrefPreferences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't the methods in preferencesService match those invoked in ExportCustomizationDialogViewModel as exporters.add(preferences.X) where X is the method, rather than using preferences.getStringList?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I don't really understand what you mean. The PreferencesService should provide an interface to the preferences that hide the exact semantics of how the object is serialized. So abstractly, X getX() and putX(X newValue), where X is the (model) object. The implementation in JabRefPreferences than has to worry about (de)serialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quick question: Do you recommend writing tests for the view model? The dialog is simple, but not as simple as the previous one I wrote.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of writing tests for the sake of it. My strategy is usually to program everything and when I discover a problem in the logic during testing, I'll write a test for it. Hence, if the dialog is simple enough that you don't make any errors, then you don't need to write tests ;-).
An exception is when there is really complex logic that is definitely worth testing.


String get(String key);

}