-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changes from 76 commits
f120b41
12e3e7d
ec364ad
f5c89fa
6773b22
1f318f0
1a0b760
5c65b57
2de4124
a869aa2
9ae84c0
e992c5d
3a4baa3
f63d43c
1f094d6
83b7dac
99d7041
0479893
547898c
e2ae2c9
3be5672
debd2bc
7141a46
889489b
1fb234d
e17d0da
73e683a
19720cc
4e8c8df
3618f83
51a726e
1821da3
d339f78
eea34ed
d36eec2
294a367
4269ca0
25db576
3b54bc8
84f293e
00bac82
b26d592
b681ae8
be47855
9aa0887
d7277e8
7087cfb
1daf7c4
83d490a
17d20cc
40eed27
379f201
4679150
0053abf
9442025
de3bf63
19d8c62
df42676
f31bc51
d95a1aa
80ffa33
5f56c25
f1d920e
f22e97a
252ecbb
ccdbf1f
aba31a6
8cd7ff3
3e09a7b
3051022
0ef3061
7bf6dd6
93838de
a79d037
70479cb
bf22adf
c2b3489
a364e1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
} | ||
|
||
} |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
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> { | ||
|
||
//Browse must be a Button because ButtonTypes must be on the buttom, not next to the filename field | ||
@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) { //should the latter three have been injected as in the main dialog rather than passed as a param? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it is slightly better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I have also injected |
||
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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
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 empty exporter to the main exporter customization dialog | ||
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() { //i.e. layout dir | ||
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())); //implement setting the text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put it in both, since saving the exporter might also indicate where the working directory should be. However, now it won't set the directory as before. Since this fix isn't working I am pushing this into a separate branch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now it's called in as part of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
} | ||
|
||
public StringProperty getName() { | ||
return name; | ||
} | ||
|
||
public StringProperty getLayoutFileName() { | ||
return layoutFile; | ||
} | ||
|
||
public StringProperty getExtension() { | ||
return extension; | ||
} | ||
|
||
} |
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.