-
-
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.
[WIP] Convert Exporter Customization Dialog to javafx (#4394)
* Exporter to JavaFX commit 1 * Work on Export Customization Dialog VM * Work on VM * Combine methods in CustomExporterList and move to preferences * work on VM * Add methods to VM * Fix typos * started work on exporter subdialog * Continue work on exporter subdialog * Implement save exporter from add/modify exporter dialog * Add two comments * More work on VMs and prefs * Fix browse method in export customization subdialog * Remove int reference in VM * Create FXML for main exporter customization dialog * Work on View, not complete * Work on using EasyBind * fix some binding issues add stubs * More work on Export Customization Dialog * FXML changes among other things * Work on View for subdialog * Changes to View and logic * Deal with stubs, convert some EVMs to Optionals * Change Optional in subdialog * Add FXML and View * Remove typos and syntax error * Move various code to logic * Fix modify exporter * Fix remove and close bugs * Fix customExports references * Fix get custom prefs * Remove prefs.customExports object from JabRef * Small FXML changes * Remove unused old Swing dialogs * Fix indentation * Make clear comments and Javadoc * Remove CustomExportList * Use new TemplateExporter constructor * Fix spacing and a var name * Add constant vars to prefs * Remove comments * Change log message * Fix tests * Add spacing between imports * Update localization * Replace Optional parameter with null * Replace Optional return with null * Remove AnchorPane * Localize FXML labels * Add subdialog injections * Set browse action in FXML * Add to l10n * Add cancel button to subdialog * Correction to VM try-catch * Inline setTextFields * Remove SortedList TODO * Inline closeDialog * loadExporters to private * forEach to Stream and other fixes * inline init * Fixes to ExporterViewModel * Remove Optional * Add constants to TemplateExporter * Simplify getExtensions without dot * Change try-catch to empty list check * Remove unnecessary method * Fix property getters * Fix property getters again * Fix typo * Update references to customFormats * Add import * Travis CI fixes * Further Travis CI fixes * Remove extra comments * Remove extra newlines
- Loading branch information
1 parent
55c41c7
commit 41f2d61
Showing
26 changed files
with
610 additions
and
582 deletions.
There are no files selected for viewing
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
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
12 changes: 2 additions & 10 deletions
12
src/main/java/org/jabref/gui/actions/ManageCustomExportsAction.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 |
---|---|---|
@@ -1,20 +1,12 @@ | ||
package org.jabref.gui.actions; | ||
|
||
import org.jabref.gui.JabRefFrame; | ||
import org.jabref.gui.exporter.ExportCustomizationDialog; | ||
import org.jabref.gui.exporter.ExportCustomizationDialogView; | ||
|
||
public class ManageCustomExportsAction extends SimpleCommand { | ||
|
||
private final JabRefFrame jabRefFrame; | ||
|
||
public ManageCustomExportsAction(JabRefFrame jabRefFrame) { | ||
this.jabRefFrame = jabRefFrame; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
ExportCustomizationDialog ecd = new ExportCustomizationDialog(jabRefFrame); | ||
ecd.setVisible(true); | ||
new ExportCustomizationDialogView().show(); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialog.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,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.ButtonType?> | ||
<?import javafx.scene.control.DialogPane?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.TextField?> | ||
<?import javafx.scene.layout.AnchorPane?> | ||
<?import javafx.scene.layout.ColumnConstraints?> | ||
<?import javafx.scene.layout.GridPane?> | ||
<?import javafx.scene.layout.RowConstraints?> | ||
|
||
<DialogPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="480.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.exporter.CreateModifyExporterDialogView"> | ||
<content> | ||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="320.0"> | ||
<children> | ||
<GridPane prefWidth="480.0" scaleShape="false"> | ||
<columnConstraints> | ||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> | ||
</columnConstraints> | ||
<rowConstraints> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
</rowConstraints> | ||
<children> | ||
<TextField fx:id="name" GridPane.rowIndex="1" /> | ||
<Label text="%Main layout file:" GridPane.rowIndex="2" /> | ||
<TextField fx:id="fileName" GridPane.rowIndex="3" /> | ||
<TextField fx:id="extension" GridPane.rowIndex="6" /> | ||
<Label alignment="TOP_LEFT" text="%Export format name:"> | ||
<GridPane.margin> | ||
<Insets /> | ||
</GridPane.margin> | ||
</Label> | ||
<Label text="%File extension:" GridPane.rowIndex="5" /> | ||
<Button fx:id="browseButton" text="%Browse" onAction="#browse" GridPane.rowIndex="4" /> | ||
</children> | ||
<padding> | ||
<Insets bottom="30.0" left="30.0" right="30.0" top="30.0" /> | ||
</padding> | ||
</GridPane> | ||
</children></AnchorPane> | ||
</content> | ||
<ButtonType fx:id="saveExporter" text="%Save exporter" /> | ||
<ButtonType fx:constant="CANCEL" /> | ||
</DialogPane> |
67 changes: 67 additions & 0 deletions
67
src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogView.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,67 @@ | ||
package org.jabref.gui.exporter; | ||
|
||
import javax.inject.Inject; | ||
|
||
import javafx.event.ActionEvent; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.TextField; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.util.BaseDialog; | ||
import org.jabref.logic.journals.JournalAbbreviationLoader; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
import com.airhacks.afterburner.views.ViewLoader; | ||
|
||
public class CreateModifyExporterDialogView extends BaseDialog<ExporterViewModel> { | ||
|
||
@FXML private Button browseButton; | ||
@FXML private TextField name; | ||
@FXML private TextField fileName; | ||
@FXML private TextField extension; | ||
@FXML private ButtonType saveExporter; | ||
|
||
@Inject private DialogService dialogService; | ||
@Inject private PreferencesService preferences; | ||
@Inject private final JournalAbbreviationLoader loader; | ||
private CreateModifyExporterDialogViewModel viewModel; | ||
|
||
private final ExporterViewModel exporter; | ||
|
||
public CreateModifyExporterDialogView(ExporterViewModel exporter, DialogService dialogService, | ||
PreferencesService preferences, JournalAbbreviationLoader loader) { | ||
this.setTitle(Localization.lang("Customize Export Formats")); | ||
this.exporter = exporter; | ||
this.loader = loader; | ||
this.dialogService = dialogService; | ||
this.preferences = preferences; | ||
|
||
ViewLoader.view(this) | ||
.load() | ||
.setAsDialogPane(this); | ||
|
||
this.setResultConverter(button -> { | ||
if (button == saveExporter) { | ||
return viewModel.saveExporter(); | ||
} else { | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
@FXML | ||
private void initialize() { | ||
viewModel = new CreateModifyExporterDialogViewModel(exporter, dialogService, preferences, loader); | ||
name.textProperty().bindBidirectional(viewModel.getName()); | ||
fileName.textProperty().bindBidirectional(viewModel.getLayoutFileName()); | ||
extension.textProperty().bindBidirectional(viewModel.getExtension()); | ||
} | ||
|
||
@FXML | ||
private void browse(ActionEvent event) { | ||
viewModel.browse(); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.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,107 @@ | ||
package org.jabref.gui.exporter; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
|
||
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.journals.JournalAbbreviationLoader; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.layout.LayoutFormatterPreferences; | ||
import org.jabref.logic.util.StandardFileType; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* | ||
* This view model can be used both for "add exporter" and "modify exporter" functionalities. | ||
* It takes an optional exporter which is empty for "add exporter," and takes the selected exporter | ||
* for "modify exporter." It returns an optional exporter which empty if an invalid or no exporter is | ||
* created, and otherwise contains the exporter to be added or that is modified. | ||
* | ||
*/ | ||
|
||
public class CreateModifyExporterDialogViewModel extends AbstractViewModel { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(CreateModifyExporterDialogViewModel.class); | ||
|
||
private final DialogService dialogService; | ||
private final PreferencesService preferences; | ||
|
||
private final StringProperty name = new SimpleStringProperty(""); | ||
private final StringProperty layoutFile = new SimpleStringProperty(""); | ||
private final StringProperty extension = new SimpleStringProperty(""); | ||
|
||
private final JournalAbbreviationLoader loader; | ||
|
||
public CreateModifyExporterDialogViewModel(ExporterViewModel exporter, DialogService dialogService, PreferencesService preferences, | ||
JournalAbbreviationLoader loader) { | ||
this.dialogService = dialogService; | ||
this.preferences = preferences; | ||
this.loader = loader; | ||
|
||
//Set text of each of the boxes | ||
if (exporter != null) { | ||
name.setValue(exporter.name().get()); | ||
layoutFile.setValue(exporter.layoutFileName().get()); | ||
extension.setValue(exporter.extension().get()); | ||
} | ||
} | ||
|
||
public ExporterViewModel saveExporter() { | ||
Path layoutFileDir = Paths.get(layoutFile.get()).getParent(); | ||
if (layoutFileDir != null) { | ||
String layoutFileDirString = layoutFileDir.toString(); | ||
preferences.setExportWorkingDirectory(layoutFileDirString); | ||
} | ||
|
||
// Check that there are no empty strings. | ||
if (layoutFile.get().isEmpty() || name.get().isEmpty() || extension.get().isEmpty() | ||
|| !layoutFile.get().endsWith(".layout")) { | ||
|
||
LOGGER.info("One of the fields is empty or invalid!"); | ||
return null; | ||
} | ||
|
||
// Create a new exporter to be returned to ExportCustomizationDialogViewModel, which requested it | ||
LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(loader); | ||
SavePreferences savePreferences = preferences.loadForExportFromPreferences(); | ||
TemplateExporter format = new TemplateExporter(name.get(), layoutFile.get(), extension.get(), | ||
layoutPreferences, savePreferences); | ||
format.setCustomExport(true); | ||
return new ExporterViewModel(format); | ||
} | ||
|
||
public String getExportWorkingDirectory() { | ||
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 -> layoutFile.set(f.toAbsolutePath().toString())); | ||
} | ||
|
||
public StringProperty getName() { | ||
return name; | ||
} | ||
|
||
public StringProperty getLayoutFileName() { | ||
return layoutFile; | ||
} | ||
|
||
public StringProperty getExtension() { | ||
return extension; | ||
} | ||
|
||
} |
Oops, something went wrong.