-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from all commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
f120b41
Exporter to JavaFX commit 1
abepolk 12e3e7d
Work on Export Customization Dialog VM
abepolk ec364ad
Work on VM
abepolk f5c89fa
Combine methods in CustomExporterList and move to preferences
abepolk 6773b22
work on VM
abepolk 1f318f0
Add methods to VM
abepolk 1a0b760
Fix typos
abepolk 5c65b57
started work on exporter subdialog
abepolk 2de4124
Continue work on exporter subdialog
abepolk a869aa2
Implement save exporter from add/modify exporter dialog
abepolk 9ae84c0
Add two comments
abepolk e992c5d
More work on VMs and prefs
abepolk 3a4baa3
Fix browse method in export customization subdialog
abepolk f63d43c
Remove int reference in VM
abepolk 1f094d6
Create FXML for main exporter customization dialog
abepolk 83b7dac
Work on View, not complete
abepolk 99d7041
Work on using EasyBind
abepolk 0479893
fix some binding issues add stubs
Siedlerchr 547898c
More work on Export Customization Dialog
abepolk e2ae2c9
FXML changes among other things
abepolk 3be5672
Work on View for subdialog
abepolk debd2bc
Changes to View and logic
abepolk 7141a46
Deal with stubs, convert some EVMs to Optionals
abepolk 889489b
Change Optional in subdialog
abepolk 1fb234d
Add FXML and View
abepolk e17d0da
Remove typos and syntax error
abepolk 73e683a
Move various code to logic
abepolk 19720cc
Fix modify exporter
abepolk 4e8c8df
Fix remove and close bugs
abepolk 3618f83
Merge branch 'master' into exporter_to_javafx
abepolk 51a726e
Fix customExports references
abepolk 1821da3
Merge remote-tracking branch 'upstream/master' into exporter_to_javafx
abepolk d339f78
Fix get custom prefs
abepolk eea34ed
Remove prefs.customExports object from JabRef
abepolk d36eec2
Small FXML changes
abepolk 294a367
Remove unused old Swing dialogs
abepolk 4269ca0
Fix indentation
abepolk 25db576
Make clear comments and Javadoc
abepolk 3b54bc8
Remove CustomExportList
abepolk 84f293e
Use new TemplateExporter constructor
abepolk 00bac82
Fix spacing and a var name
abepolk b26d592
Add constant vars to prefs
abepolk b681ae8
Remove comments
abepolk be47855
Change log message
abepolk 9aa0887
Fix tests
abepolk d7277e8
Add spacing between imports
abepolk 7087cfb
Update localization
abepolk 1daf7c4
Replace Optional parameter with null
abepolk 83d490a
Replace Optional return with null
abepolk 17d20cc
Remove AnchorPane
abepolk 40eed27
Localize FXML labels
abepolk 379f201
Add subdialog injections
abepolk 4679150
Set browse action in FXML
abepolk 0053abf
Add to l10n
abepolk 9442025
Add cancel button to subdialog
abepolk de3bf63
Correction to VM try-catch
abepolk 19d8c62
Inline setTextFields
abepolk df42676
Remove SortedList TODO
abepolk f31bc51
Inline closeDialog
abepolk d95a1aa
loadExporters to private
abepolk 80ffa33
forEach to Stream and other fixes
abepolk 5f56c25
inline init
abepolk f1d920e
Fixes to ExporterViewModel
abepolk f22e97a
Remove Optional
abepolk 252ecbb
Add constants to TemplateExporter
abepolk ccdbf1f
Simplify getExtensions without dot
abepolk aba31a6
Merge branch 'master' into exporter_to_javafx
abepolk 8cd7ff3
Change try-catch to empty list check
abepolk 3e09a7b
Remove unnecessary method
abepolk 3051022
Fix property getters
abepolk 0ef3061
Fix property getters again
abepolk 7bf6dd6
Fix typo
abepolk 93838de
Update references to customFormats
abepolk a79d037
Add import
abepolk 70479cb
Travis CI fixes
abepolk bf22adf
Further Travis CI fixes
abepolk c2b3489
Remove extra comments
abepolk a364e1d
Remove extra newlines
abepolk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be a
Cancel
button as well (if the user decides to abort his editing).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hasn't worked despite my adding
<ButtonType fx:constant="CANCEL" />
to the FXML, and I'm not sure why. The button does not appear in the dialog.