Skip to content

Commit

Permalink
Refactorings, move functionality of CustomEntryTypesManager to Prefer…
Browse files Browse the repository at this point in the history
…ences

Use ObservableList instead of LIstProperty
  • Loading branch information
Siedlerchr committed Apr 24, 2019
1 parent c0327a6 commit 08b583d
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 109 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;

import javax.inject.Inject;

import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.control.ButtonType;
Expand All @@ -11,6 +13,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.EntryType;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
import org.controlsfx.control.CheckListView;
Expand All @@ -20,6 +23,7 @@ public class ImportCustomEntryTypesDialog extends BaseDialog<Void> {
@FXML private CheckListView<EntryType> unknownEntryTypesCheckList;
@FXML private VBox boxDifferentCustomization;
@FXML private CheckListView<EntryType> differentCustomizationCheckList;
@Inject private PreferencesService preferencesService;

private ImportCustomEntryTypesDialogViewModel viewModel;

Expand Down Expand Up @@ -47,11 +51,11 @@ public ImportCustomEntryTypesDialog(BibDatabaseMode mode, List<EntryType> custom

@FXML
public void initialize() {
viewModel = new ImportCustomEntryTypesDialogViewModel(mode, customEntryTypes);
viewModel = new ImportCustomEntryTypesDialogViewModel(mode, customEntryTypes, preferencesService);

boxDifferentCustomization.managedProperty().bind(Bindings.isNotEmpty(viewModel.differentCustomizationsProperty()));
unknownEntryTypesCheckList.itemsProperty().bind(viewModel.newTypesProperty());
differentCustomizationCheckList.itemsProperty().bind(viewModel.differentCustomizationsProperty());
boxDifferentCustomization.managedProperty().bind(Bindings.isNotEmpty(viewModel.differentCustomizations()));
unknownEntryTypesCheckList.setItems(viewModel.newTypes());
differentCustomizationCheckList.setItems(viewModel.differentCustomizations());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@

import java.util.List;

import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.jabref.Globals;
import org.jabref.gui.customentrytypes.CustomEntryTypesManager;
import org.jabref.model.EntryTypes;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.CustomEntryType;
import org.jabref.model.entry.EntryType;
import org.jabref.preferences.PreferencesService;

public class ImportCustomEntryTypesDialogViewModel {

private final ListProperty<EntryType> newTypesProperty;
private final ListProperty<EntryType> differentCustomizationsProperty;
private final BibDatabaseMode mode;
private final PreferencesService preferencesService;

public ImportCustomEntryTypesDialogViewModel(BibDatabaseMode mode, List<EntryType> customEntryTypes) {
this.mode = mode;
private final ObservableList<EntryType> newTypes = FXCollections.observableArrayList();
private final ObservableList<EntryType> differentCustomizationTypes = FXCollections.observableArrayList();

ObservableList<EntryType> newTypes = FXCollections.observableArrayList();
ObservableList<EntryType> differentCustomizationTypes = FXCollections.observableArrayList();
public ImportCustomEntryTypesDialogViewModel(BibDatabaseMode mode, List<EntryType> customEntryTypes, PreferencesService preferencesService) {
this.mode = mode;
this.preferencesService = preferencesService;

for (EntryType customType : customEntryTypes) {
if (!EntryTypes.getType(customType.getName(), mode).isPresent()) {
Expand All @@ -37,27 +34,24 @@ public ImportCustomEntryTypesDialogViewModel(BibDatabaseMode mode, List<EntryTyp
}
}

newTypesProperty = new SimpleListProperty<>(newTypes);
differentCustomizationsProperty = new SimpleListProperty<>(differentCustomizationTypes);

}

public ListProperty<EntryType> newTypesProperty() {
return this.newTypesProperty;
public ObservableList<EntryType> newTypes() {
return this.newTypes;
}

public ListProperty<EntryType> differentCustomizationsProperty() {
return this.differentCustomizationsProperty;
public ObservableList<EntryType> differentCustomizations() {
return this.differentCustomizationTypes;
}

public void importCustomEntryTypes(List<EntryType> checkedUnknownEntryTypes, List<EntryType> checkedDifferentEntryTypes) {
if (!checkedUnknownEntryTypes.isEmpty()) {
checkedUnknownEntryTypes.forEach(type -> EntryTypes.addOrModifyCustomEntryType((CustomEntryType) type, mode));
CustomEntryTypesManager.saveCustomEntryTypes(Globals.prefs);
preferencesService.saveCustomEntryTypes();
}
if (!checkedDifferentEntryTypes.isEmpty()) {
checkedUnknownEntryTypes.forEach(type -> EntryTypes.addOrModifyCustomEntryType((CustomEntryType) type, mode));
CustomEntryTypesManager.saveCustomEntryTypes(Globals.prefs);
preferencesService.saveCustomEntryTypes();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public boolean isActionNecessary(ParserResult parserResult) {
public void performAction(BasePanel panel, ParserResult parserResult) {
BibDatabaseMode mode = getBibDatabaseModeFromParserResult(parserResult);

ImportCustomEntryTypesDialog dlg = new ImportCustomEntryTypesDialog(mode, getListOfUnknownAndUnequalCustomizations(parserResult));
dlg.showAndWait();
ImportCustomEntryTypesDialog importCustomEntryTypesDialog = new ImportCustomEntryTypesDialog(mode, getListOfUnknownAndUnequalCustomizations(parserResult));
importCustomEntryTypesDialog.showAndWait();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public interface GUIPostOpenAction {
*
* @param panel The BasePanel where the database is shown.
* @param pr The result of the BIB parse operation.
* @param dialogService
*/
void performAction(BasePanel panel, ParserResult pr);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public OpenDatabaseAction(JabRefFrame frame) {
*
* @param panel The BasePanel where the database is shown.
* @param result The result of the BIB file parse operation.
* @param dialogService
*/
public static void performPostOpenActions(BasePanel panel, ParserResult result) {
for (GUIPostOpenAction action : OpenDatabaseAction.POST_OPEN_ACTIONS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Optional;

import org.jabref.Globals;
import org.jabref.gui.customentrytypes.CustomEntryTypesManager;
import org.jabref.model.EntryTypes;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.CustomEntryType;
Expand Down Expand Up @@ -36,7 +35,7 @@ static void upgradeStoredCustomEntryTypes(BibDatabaseMode defaultBibDatabaseMode
number++;
}

CustomEntryTypesManager.saveCustomEntryTypes(prefs);
prefs.saveCustomEntryTypes();
}

/**
Expand Down
105 changes: 60 additions & 45 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.jabref.logic.util.io.AutoLinkPreferences;
import org.jabref.logic.util.io.FileHistory;
import org.jabref.logic.xmp.XmpPreferences;
import org.jabref.model.EntryTypes;
import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern;
import org.jabref.model.cleanup.FieldFormatterCleanups;
import org.jabref.model.database.BibDatabaseMode;
Expand Down Expand Up @@ -872,11 +873,11 @@ private static Optional<String> getNextUnit(Reader data) throws IOException {

private static void insertDefaultCleanupPreset(Map<String, Object> storage) {
EnumSet<CleanupPreset.CleanupStep> deactivatedJobs = EnumSet.of(
CleanupPreset.CleanupStep.CLEAN_UP_UPGRADE_EXTERNAL_LINKS,
CleanupPreset.CleanupStep.MOVE_PDF,
CleanupPreset.CleanupStep.RENAME_PDF_ONLY_RELATIVE_PATHS,
CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX,
CleanupPreset.CleanupStep.CONVERT_TO_BIBTEX);
CleanupPreset.CleanupStep.CLEAN_UP_UPGRADE_EXTERNAL_LINKS,
CleanupPreset.CleanupStep.MOVE_PDF,
CleanupPreset.CleanupStep.RENAME_PDF_ONLY_RELATIVE_PATHS,
CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX,
CleanupPreset.CleanupStep.CONVERT_TO_BIBTEX);

for (CleanupPreset.CleanupStep action : EnumSet.allOf(CleanupPreset.CleanupStep.class)) {
storage.put(JabRefPreferences.CLEANUP + action.name(), !deactivatedJobs.contains(action));
Expand Down Expand Up @@ -1437,8 +1438,8 @@ public FilePreferences getFilePreferences() {
@Override
public UpdateFieldPreferences getUpdateFieldPreferences() {
return new UpdateFieldPreferences(getBoolean(USE_OWNER), getBoolean(OVERWRITE_OWNER), get(DEFAULT_OWNER),
getBoolean(USE_TIME_STAMP), getBoolean(OVERWRITE_TIME_STAMP), get(TIME_STAMP_FIELD),
get(TIME_STAMP_FORMAT));
getBoolean(USE_TIME_STAMP), getBoolean(OVERWRITE_TIME_STAMP), get(TIME_STAMP_FIELD),
get(TIME_STAMP_FORMAT));
}

public LatexFieldFormatterPreferences getLatexFieldFormatterPreferences() {
Expand All @@ -1453,14 +1454,14 @@ public FieldContentParserPreferences getFieldContentParserPreferences() {
@Override
public boolean isKeywordSyncEnabled() {
return getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)
&& getBoolean(JabRefPreferences.AUTOSYNCSPECIALFIELDSTOKEYWORDS);
&& getBoolean(JabRefPreferences.AUTOSYNCSPECIALFIELDSTOKEYWORDS);
}

@Override
public ImportFormatPreferences getImportFormatPreferences() {
return new ImportFormatPreferences(customImports, getDefaultEncoding(), getKeywordDelimiter(),
getBibtexKeyPatternPreferences(), getFieldContentParserPreferences(), getXMPPreferences(),
isKeywordSyncEnabled());
getBibtexKeyPatternPreferences(), getFieldContentParserPreferences(), getXMPPreferences(),
isKeywordSyncEnabled());
}

@Override
Expand All @@ -1475,32 +1476,32 @@ public SavePreferences loadForExportFromPreferences() {
}
}
return new SavePreferences(
saveInOriginalOrder,
saveOrder,
this.getDefaultEncoding(),
this.getBoolean(JabRefPreferences.BACKUP),
SavePreferences.DatabaseSaveType.ALL,
false,
this.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT),
this.getLatexFieldFormatterPreferences(),
this.getKeyPattern(),
getBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING),
getBibtexKeyPatternPreferences());
saveInOriginalOrder,
saveOrder,
this.getDefaultEncoding(),
this.getBoolean(JabRefPreferences.BACKUP),
SavePreferences.DatabaseSaveType.ALL,
false,
this.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT),
this.getLatexFieldFormatterPreferences(),
this.getKeyPattern(),
getBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING),
getBibtexKeyPatternPreferences());
}

public SavePreferences loadForSaveFromPreferences() {
return new SavePreferences(
false,
null,
this.getDefaultEncoding(),
this.getBoolean(JabRefPreferences.BACKUP),
SavePreferences.DatabaseSaveType.ALL,
true,
this.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT),
this.getLatexFieldFormatterPreferences(),
this.getKeyPattern(),
getBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING),
getBibtexKeyPatternPreferences());
false,
null,
this.getDefaultEncoding(),
this.getBoolean(JabRefPreferences.BACKUP),
SavePreferences.DatabaseSaveType.ALL,
true,
this.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT),
this.getLatexFieldFormatterPreferences(),
this.getKeyPattern(),
getBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING),
getBibtexKeyPatternPreferences());
}

public ExporterFactory getExporterFactory(JournalAbbreviationLoader abbreviationLoader) {
Expand Down Expand Up @@ -1541,14 +1542,14 @@ public XmpPreferences getXMPPreferences() {
@Override
public OpenOfficePreferences getOpenOfficePreferences() {
return new OpenOfficePreferences(
this.get(JabRefPreferences.OO_JARS_PATH),
this.get(JabRefPreferences.OO_EXECUTABLE_PATH),
this.get(JabRefPreferences.OO_PATH),
this.getBoolean(JabRefPreferences.OO_USE_ALL_OPEN_BASES),
this.getBoolean(JabRefPreferences.OO_SYNC_WHEN_CITING),
this.getBoolean(JabRefPreferences.OO_SHOW_PANEL),
this.getStringList(JabRefPreferences.OO_EXTERNAL_STYLE_FILES),
this.get(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE));
this.get(JabRefPreferences.OO_JARS_PATH),
this.get(JabRefPreferences.OO_EXECUTABLE_PATH),
this.get(JabRefPreferences.OO_PATH),
this.getBoolean(JabRefPreferences.OO_USE_ALL_OPEN_BASES),
this.getBoolean(JabRefPreferences.OO_SYNC_WHEN_CITING),
this.getBoolean(JabRefPreferences.OO_SHOW_PANEL),
this.getStringList(JabRefPreferences.OO_EXTERNAL_STYLE_FILES),
this.get(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE));
}

@Override
Expand Down Expand Up @@ -1728,10 +1729,9 @@ private SaveOrderConfig loadTableSaveOrder() {
@Override
public SaveOrderConfig loadExportSaveOrder() {
return new SaveOrderConfig(getBoolean(EXPORT_IN_ORIGINAL_ORDER), getBoolean(EXPORT_IN_SPECIFIED_ORDER),
new SaveOrderConfig.SortCriterion(get(EXPORT_PRIMARY_SORT_FIELD), getBoolean(EXPORT_PRIMARY_SORT_DESCENDING)),
new SaveOrderConfig.SortCriterion(get(EXPORT_SECONDARY_SORT_FIELD), getBoolean(EXPORT_SECONDARY_SORT_DESCENDING)),
new SaveOrderConfig.SortCriterion(get(EXPORT_TERTIARY_SORT_FIELD), getBoolean(EXPORT_TERTIARY_SORT_DESCENDING))
);
new SaveOrderConfig.SortCriterion(get(EXPORT_PRIMARY_SORT_FIELD), getBoolean(EXPORT_PRIMARY_SORT_DESCENDING)),
new SaveOrderConfig.SortCriterion(get(EXPORT_SECONDARY_SORT_FIELD), getBoolean(EXPORT_SECONDARY_SORT_DESCENDING)),
new SaveOrderConfig.SortCriterion(get(EXPORT_TERTIARY_SORT_FIELD), getBoolean(EXPORT_TERTIARY_SORT_DESCENDING)));
}

@Override
Expand Down Expand Up @@ -2008,7 +2008,7 @@ public List<TemplateExporter> getCustomExportFormats(JournalAbbreviationLoader l
filename = formatData.get(EXPORTER_FILENAME_INDEX);
extension = formatData.get(EXPORTER_EXTENSION_INDEX);
TemplateExporter format = new TemplateExporter(exporterName, filename, extension,
layoutPreferences, savePreferences);
layoutPreferences, savePreferences);
format.setCustomExport(true);
formats.add(format);
i++;
Expand Down Expand Up @@ -2060,4 +2060,19 @@ public boolean shouldWarnAboutDuplicatesForImport() {
public void setShouldWarnAboutDuplicatesForImport(boolean value) {
putBoolean(JabRefPreferences.WARN_ABOUT_DUPLICATES_IN_INSPECTION, value);
}

@Override
public void saveCustomEntryTypes() {
saveCustomEntryTypes(BibDatabaseMode.BIBTEX);
saveCustomEntryTypes(BibDatabaseMode.BIBLATEX);
}

private void saveCustomEntryTypes(BibDatabaseMode bibDatabaseMode) {
List<CustomEntryType> customBiblatexBibTexTypes = EntryTypes.getAllValues(bibDatabaseMode).stream()
.filter(type -> type instanceof CustomEntryType)
.map(entryType -> (CustomEntryType) entryType).collect(Collectors.toList());

storeCustomEntryTypes(customBiblatexBibTexTypes, bibDatabaseMode);

}
}
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/preferences/PreferencesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ public interface PreferencesService {
boolean shouldWarnAboutDuplicatesForImport();

void setShouldWarnAboutDuplicatesForImport(boolean value);

void saveCustomEntryTypes();
}

0 comments on commit 08b583d

Please sign in to comment.