-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework PosteOpenActions to javafx (custom entry type import) (#4898)
* Rework PosteOpenActions to javafx (custom entry type import) Convert dialog for importing custom entry types to CheckListView Rework threading when opening a database * Rework PosteOpenActions to javafx (custom entry type import) Convert dialog for importing custom entry types to CheckListView Rework threading when opening a database * rework threading stuff simplify code * rework dialog, create fxml etc fix l10n Remove obsolete code * remove dialog service argument * remove dialogService parameter * Refactorings, move functionality of CustomEntryTypesManager to Preferences Use ObservableList instead of LIstProperty
- Loading branch information
Showing
14 changed files
with
300 additions
and
244 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypesManager.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
src/main/java/org/jabref/gui/importer/ImportCustomEntryTypesDialog.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.ButtonType?> | ||
<?import javafx.scene.control.DialogPane?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.layout.VBox?> | ||
<?import org.controlsfx.control.CheckListView?> | ||
|
||
<DialogPane prefHeight="550.0" prefWidth="566.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.importer.ImportCustomEntryTypesDialog"> | ||
<content> | ||
<VBox minHeight="-Infinity" prefHeight="113.0" prefWidth="571.0" spacing="1.0"> | ||
<children> | ||
<Label text="%Custom entry types found in file" /> | ||
<Label text="%Select all customized types to be stored in local preferences:" /> | ||
<Label text="%Currently unknown:" /> | ||
<CheckListView fx:id="unknownEntryTypesCheckList" /> | ||
<VBox fx:id="boxDifferentCustomization"> | ||
<children> | ||
<Label text="%Different customization, current settings will be overwritten" /> | ||
<CheckListView fx:id="differentCustomizationCheckList" /> | ||
</children> | ||
</VBox> | ||
</children> | ||
</VBox> | ||
</content> | ||
<buttonTypes> | ||
<ButtonType fx:constant="CANCEL" /> | ||
<ButtonType fx:constant="OK" /> | ||
</buttonTypes> | ||
</DialogPane> |
61 changes: 61 additions & 0 deletions
61
src/main/java/org/jabref/gui/importer/ImportCustomEntryTypesDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.jabref.gui.importer; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import javafx.beans.binding.Bindings; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.layout.VBox; | ||
|
||
import org.jabref.gui.util.BaseDialog; | ||
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; | ||
|
||
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; | ||
|
||
private final BibDatabaseMode mode; | ||
private final List<EntryType> customEntryTypes; | ||
|
||
public ImportCustomEntryTypesDialog(BibDatabaseMode mode, List<EntryType> customEntryTypes) { | ||
this.mode = mode; | ||
this.customEntryTypes = customEntryTypes; | ||
|
||
ViewLoader.view(this) | ||
.load() | ||
.setAsDialogPane(this); | ||
|
||
setResultConverter(btn -> { | ||
if (btn == ButtonType.OK) { | ||
viewModel.importCustomEntryTypes(unknownEntryTypesCheckList.getCheckModel().getCheckedItems(), differentCustomizationCheckList.getCheckModel().getCheckedItems()); | ||
} | ||
return null; | ||
}); | ||
|
||
setTitle(Localization.lang("Custom entry types")); | ||
|
||
} | ||
|
||
@FXML | ||
public void initialize() { | ||
viewModel = new ImportCustomEntryTypesDialogViewModel(mode, customEntryTypes, preferencesService); | ||
|
||
boxDifferentCustomization.managedProperty().bind(Bindings.isNotEmpty(viewModel.differentCustomizations())); | ||
unknownEntryTypesCheckList.setItems(viewModel.newTypes()); | ||
differentCustomizationCheckList.setItems(viewModel.differentCustomizations()); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/org/jabref/gui/importer/ImportCustomEntryTypesDialogViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.jabref.gui.importer; | ||
|
||
import java.util.List; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
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 BibDatabaseMode mode; | ||
private final PreferencesService preferencesService; | ||
|
||
private final ObservableList<EntryType> newTypes = FXCollections.observableArrayList(); | ||
private final 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()) { | ||
newTypes.add(customType); | ||
} else { | ||
EntryType currentlyStoredType = EntryTypes.getType(customType.getName(), mode).get(); | ||
if (!EntryTypes.isEqualNameAndFieldBased(customType, currentlyStoredType)) { | ||
differentCustomizationTypes.add(customType); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
public ObservableList<EntryType> newTypes() { | ||
return this.newTypes; | ||
} | ||
|
||
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)); | ||
preferencesService.saveCustomEntryTypes(); | ||
} | ||
if (!checkedDifferentEntryTypes.isEmpty()) { | ||
checkedUnknownEntryTypes.forEach(type -> EntryTypes.addOrModifyCustomEntryType((CustomEntryType) type, mode)); | ||
preferencesService.saveCustomEntryTypes(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.