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

Improve entrytype customization #2331

Merged
merged 27 commits into from
Dec 16, 2016
Merged

Conversation

matthiasgeiger
Copy link
Member

@matthiasgeiger matthiasgeiger commented Dec 2, 2016

Goals:

  • Entry customization based on BibDatabaseMode

    • working for custom entry types defined in bib DB
    • storage is working for new customized entries (instead of creating three/four prefs Strings for each customized entry type in the form ("custom_type_1_name", "custom_type_1_REQ", ...) two distinct pref nodes (one for BibTeX one for BibLaTeX) for customized entry types are used which simply use the custom type name as key and the string serialization as value (--> parsing can be reused))
    • loading is working for newly created customized entries
    • write prefs migration (is performed on first startup of new version, existing prefs will be put as new custom types for defaultBibDatabaseMode, old prefs are not deleted)
  • enable testing with cleanup after test execution

    • bibtex
    • biblatex
  • various bug fixes and improvements, e.g., Customizing the entry types freezes Jabref #2318 custom entry types bug #772 Refactor entry type/custom entry type logic #366 Save custom entry types in bib file #365

  • CHANGELOG

@matthiasgeiger matthiasgeiger added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Dec 11, 2016
@matthiasgeiger
Copy link
Member Author

Okay... I think the current state is now a good improvement of the old status-quo.
At the moment the prefs migration and a dialog showing a warning if customized entries would be overridden is still missing.

Apart from that I would appreciate some feedback ;-)

Copy link
Member

@lenhard lenhard left a comment

Choose a reason for hiding this comment

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

I just looked through the code, but did not test this in a running JabRef. There are a number of things that can be improved quality/architecture-wise, but none of these is a blocker. So please fix what you agree with.

sb.append(type).append(", ");
public void performAction(BasePanel panel, ParserResult parserResult) {

BibDatabaseMode mode = parserResult.getMetaData().getMode().orElse(Globals.prefs.getDefaultBibDatabaseMode());
Copy link
Member

Choose a reason for hiding this comment

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

To avoid writing that method chain multiple times in this class, maybe extract a helper method?

List<EntryType> newTypes = new ArrayList<>();
List<EntryType> differentCustomizations = new ArrayList<>();

for(EntryType customType : allCustomizedEntryTypes) {
Copy link
Member

Choose a reason for hiding this comment

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

please adhere to the formatting guidelines: for ( and below if (

JPanel checkboxPanel = new JPanel();
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.PAGE_AXIS));

JLabel customFoundLabel = new JLabel(Localization.lang("Custom entry types found in file")+".");
Copy link
Member

Choose a reason for hiding this comment

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

Also formatting problems here. I should be sufficient to auto-format the file.

@@ -57,19 +57,31 @@ private void populateChangeEntryTypeMenu(JMenu menu, BasePanel panel) {
for (EntryType type : EntryTypes.getAllValues(BibDatabaseMode.BIBLATEX)) {
menu.add(new ChangeTypeAction(type, panel));
}

List<EntryType> customTypes = EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBLATEX);
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to extract the following code in a private method? It is duplicated below and the only difference is the mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would prefer to leave it as it, as the helper method would require three params (BibDatabaseMode, Menu and BasePanel) for just a simple get, if, create...

if (frame.getCurrentBasePanel().getBibDatabaseContext().isBiblatexMode()) {
panel.add(createEntryGroupPanel("BibLateX", BibLatexEntryTypes.ALL));

List<EntryType> customTypes = EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBLATEX);
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to extract the following code in a private method? It is duplicated below and the only difference is the mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above - helper method would be overkill, imho

import net.sf.jabref.preferences.JabRefPreferences;

public class CustomEntryTypesManager {

public static final List<EntryType> ALL = new ArrayList<>();
/**
* Load all custom entry types from preferences. This method is
* called from JabRef when the program starts.
*/
public static void loadCustomEntryTypes(JabRefPreferences prefs) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you change this class to be independent of JabRefPreferences? This would get us one step closer to our desired architecture. For the load method, this is easy (just put in CustomEntryType instead of the preferences). For the saving it is a little more tricky and you will need to push code into the calling UI-class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Mhmmm... This is basically just a UI-Helper class. loadCustomEntryTypes is called from the JabRefMain and the CLI Argument processer.

Storage is also used in the UI only...

So would it be possible and sensible to move it as is into the gui package?

Copy link
Member

Choose a reason for hiding this comment

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

Not entirely, unfortunately. See: https://github.com/JabRef/jabref/wiki/High-Level-Documentation
The CLI is not supposed to call the gui, so anything accessed from GUI and CLI should be in logic, but it should be independent of the preferences. You could move the save and leave the load for instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

No we just need a new package net.sf.ui which could be called by gui and cli!

... just kidding 😉 I'll think about it...

public static List<EntryType> getAllCustomTypes(BibDatabaseMode mode) {
Collection<EntryType> allTypes = getAllValues(mode);
if(mode == BibDatabaseMode.BIBTEX) {
return allTypes.stream().filter(entryType -> !BibtexEntryTypes.getType(entryType.getName()).isPresent())
Copy link
Member

Choose a reason for hiding this comment

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

Can you extract the almost duplicated lambda into a private helper method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, but I cannot come up with an intelligent solution for such a helper method which is not basically the same as I already wrote here 😉

Copy link
Member

Choose a reason for hiding this comment

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

Sure, no problem. This is just a suggestion.


public static List<EntryType> getAllModifiedStandardTypes(BibDatabaseMode mode) {
if (mode == BibDatabaseMode.BIBTEX) {
return BIBTEX.getAllValues().stream().filter(type -> type instanceof CustomEntryType)
Copy link
Member

Choose a reason for hiding this comment

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

Again, can the lambda be extracted into a helper method?

*/
private static boolean checkEqualityOfLists(List<String> fieldList1, List<String> fieldList2) {

if(fieldList1.size()!=fieldList2.size()) {
Copy link
Member

Choose a reason for hiding this comment

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

Please format this properly.

@matthiasgeiger matthiasgeiger changed the title [WIP] Improve entrytype customization Improve entrytype customization Dec 13, 2016
@matthiasgeiger
Copy link
Member Author

Apart from a CHANGELOG and some more tests this is good to go from my side.

@matthiasgeiger
Copy link
Member Author

@mlep @frithnanth It is not yet decided whether we will include this improvement in 3.8 or not. However, there are three more translations which are added in this pull request. Could you provide me translations for these three strings? Then I'll add them manually.
Thanks!

Select_all_customized_types_to_be_stored_in_local_preferences=
Currently_unknown=
Different_Customization,_current_settings_will_be_overwritten=

@frithnanth
Copy link
Contributor

frithnanth commented Dec 15, 2016 via email

@koppor koppor merged commit 5e256f5 into master Dec 16, 2016
@koppor koppor deleted the improve-entrytype-customization branch December 16, 2016 15:52
@lenhard lenhard mentioned this pull request Dec 16, 2016
@matthiasgeiger
Copy link
Member Author

Thank you @frithnanth !

@frithnanth
Copy link
Contributor

frithnanth commented Dec 16, 2016 via email

@koppor
Copy link
Member

koppor commented Aug 18, 2017

How did we proceed regarding standard types? Is it a v4.0 issue? See koppor#248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reset preferences & Import preferences not working for custom entry types.
4 participants