From a87c64ede27eccd75f5f0e8466019c6ddfb180e7 Mon Sep 17 00:00:00 2001
From: Siedlerchr <siedlerkiller@gmail.com>
Date: Sun, 14 Apr 2019 14:18:16 +0200
Subject: [PATCH 1/4] [WIP] Convert ExternalFileTypeEntryEditor to javafx

---
 .../EditExternalFileTypeDialog.fxml           | 53 +++++++++++++
 .../EditExternalFileTypeDialog.java           | 76 +++++++++++++++++++
 .../EditExternalFileTypeViewModel.java        | 62 +++++++++++++++
 3 files changed, 191 insertions(+)
 create mode 100644 src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
 create mode 100644 src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
 create mode 100644 src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java

diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
new file mode 100644
index 00000000000..8b058afe5d0
--- /dev/null
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.scene.control.Button?>
+<?import javafx.scene.control.DialogPane?>
+<?import javafx.scene.control.Label?>
+<?import javafx.scene.control.RadioButton?>
+<?import javafx.scene.control.TextField?>
+<?import javafx.scene.control.ToggleGroup?>
+<?import javafx.scene.layout.ColumnConstraints?>
+<?import javafx.scene.layout.GridPane?>
+<?import javafx.scene.layout.RowConstraints?>
+
+
+<DialogPane prefHeight="302.0" prefWidth="462.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.externalfiletype.EditExternalFileTypeDialog">
+   <content>
+      <GridPane>
+        <columnConstraints>
+          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
+          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
+            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
+            <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>
+         <children>
+            <Label text="Icon" />
+            <Label text="Name" GridPane.rowIndex="1" />
+            <Label text="Extension" GridPane.rowIndex="2" />
+            <Label text="MIME type" GridPane.rowIndex="3" />
+            <Label text="Application" GridPane.rowIndex="4" />
+            <RadioButton fx:id="defaultApplication" mnemonicParsing="false" selected="true" text="Default" GridPane.columnIndex="1" GridPane.rowIndex="4">
+               <toggleGroup>
+                  <ToggleGroup fx:id="applicationToggleGroup" />
+               </toggleGroup>
+            </RadioButton>
+            <TextField fx:id="extension" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="2" />
+            <TextField fx:id="name" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="1" />
+            <TextField fx:id="mimeType" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="3" />
+            <RadioButton fx:id="customApplication" mnemonicParsing="false" toggleGroup="$applicationToggleGroup" GridPane.columnIndex="1" GridPane.rowIndex="5" />
+            <TextField fx:id="selectedApplication" prefWidth="152.0" GridPane.columnIndex="2" GridPane.rowIndex="5" />
+            <Button fx:id="btnBrowse" mnemonicParsing="false" onAction="#openFileChooser" text="Browse" GridPane.columnIndex="3" GridPane.rowIndex="5" />
+         </children>
+      </GridPane>
+   </content>
+   <ButtonType fx:constant="OK"/>
+   <ButtonType fx:constant="CANCEL"/>
+</DialogPane>
diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
new file mode 100644
index 00000000000..7647b97d166
--- /dev/null
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
@@ -0,0 +1,76 @@
+package org.jabref.gui.externalfiletype;
+
+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.RadioButton;
+import javafx.scene.control.TextField;
+import javafx.scene.control.ToggleGroup;
+
+import org.jabref.gui.DialogService;
+import org.jabref.gui.desktop.JabRefDesktop;
+import org.jabref.gui.desktop.os.NativeDesktop;
+import org.jabref.gui.util.BaseDialog;
+import org.jabref.gui.util.FileDialogConfiguration;
+import org.jabref.logic.l10n.Localization;
+
+import com.airhacks.afterburner.views.ViewLoader;
+
+public class EditExternalFileTypeDialog extends BaseDialog<Void> {
+
+    @FXML private RadioButton defaultApplication;
+    @FXML private ToggleGroup applicationToggleGroup;
+    @FXML private TextField extension;
+    @FXML private TextField name;
+    @FXML private TextField mimeType;
+    @FXML private RadioButton customApplication;
+    @FXML private TextField selectedApplication;
+    @FXML private Button btnBrowse;
+    private final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
+    private final FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
+
+    @Inject private DialogService dialogService;
+    private EditExternalFileTypeViewModel viewModel;
+    private CustomExternalFileType entry;
+
+    public EditExternalFileTypeDialog(CustomExternalFileType entry) {
+        this.entry = entry;
+        this.setTitle(Localization.lang("Edit external file type"));
+
+        ViewLoader.view(this)
+                  .load()
+                  .setAsDialogPane(this);
+
+        this.setResultConverter(button -> {
+            if (button == ButtonType.OK) {
+                viewModel.storeSettings();
+            }
+            return null;
+        });
+    }
+
+    @FXML
+    public void initialize() {
+        viewModel = new EditExternalFileTypeViewModel(entry);
+
+        viewModel.defaultApplicationSelectedProperty().bindBidirectional(defaultApplication.selectedProperty());
+        selectedApplication.disableProperty().bind(viewModel.defaultApplicationSelectedProperty());
+        btnBrowse.disableProperty().bind(viewModel.defaultApplicationSelectedProperty());
+
+        extension.textProperty().bindBidirectional(viewModel.extensionProperty());
+        name.textProperty().bindBidirectional(viewModel.nameProperty());
+        mimeType.textProperty().bindBidirectional(viewModel.mimeTypeProperty());
+        selectedApplication.textProperty().bindBidirectional(viewModel.selectedApplicationProperty());
+
+    }
+
+    @FXML
+    private void openFileChooser(ActionEvent event) {
+        dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> viewModel.selectedApplicationProperty().setValue(path.toAbsolutePath().toString()));
+
+    }
+
+}
diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java
new file mode 100644
index 00000000000..0e3329d222c
--- /dev/null
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java
@@ -0,0 +1,62 @@
+package org.jabref.gui.externalfiletype;
+
+import javafx.beans.property.BooleanProperty;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleBooleanProperty;
+import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.beans.property.StringProperty;
+import javafx.scene.Node;
+
+public class EditExternalFileTypeViewModel {
+
+    private final StringProperty extensionProperty = new SimpleStringProperty("");
+    private final StringProperty nameProperty = new SimpleStringProperty("");
+    private final StringProperty mimeTypeProperty = new SimpleStringProperty("");
+    private final StringProperty selectedApplicationProperty = new SimpleStringProperty("");
+    private final BooleanProperty defaultApplicationSelectedProperty = new SimpleBooleanProperty(false);
+    private final ObjectProperty<Node> iconProperty = new SimpleObjectProperty<>();
+
+    public EditExternalFileTypeViewModel(CustomExternalFileType entry) {
+        extensionProperty.setValue(entry.getExtension());
+        nameProperty.setValue(entry.getFieldName());
+        mimeTypeProperty.setValue(entry.getMimeType());
+        selectedApplicationProperty.setValue(entry.getOpenWithApplication());
+        iconProperty.setValue(entry.getIcon().getGraphicNode());
+
+        if (entry.getOpenWithApplication().isEmpty()) {
+            defaultApplicationSelectedProperty.setValue(true);
+        }
+
+    }
+
+    public StringProperty extensionProperty() {
+        return extensionProperty;
+    }
+
+    public StringProperty nameProperty() {
+        return nameProperty;
+    }
+
+    public StringProperty mimeTypeProperty() {
+        return mimeTypeProperty;
+    }
+
+    public StringProperty selectedApplicationProperty() {
+        return selectedApplicationProperty;
+    }
+
+    public BooleanProperty defaultApplicationSelectedProperty() {
+        return defaultApplicationSelectedProperty;
+    }
+
+    public ObjectProperty<Node> iconProperty() {
+        return iconProperty;
+    }
+
+    public void storeSettings() {
+        // TODO Auto-generated method stub
+
+    }
+
+}

From 8aa09b9bd00e5b42b83da7e8e4c2c48e56ca9aa8 Mon Sep 17 00:00:00 2001
From: Siedlerchr <siedlerkiller@gmail.com>
Date: Sun, 14 Apr 2019 16:47:19 +0200
Subject: [PATCH 2/4] convert rest of the dialog

---
 .../CustomizeExternalFileTypesDialog.java     |   2 +-
 .../CustomizeExternalFileTypesViewModel.java  |  12 +-
 .../EditExternalFileTypeDialog.fxml           |  27 ++-
 .../EditExternalFileTypeDialog.java           |  25 +-
 .../EditExternalFileTypeViewModel.java        |  52 +++-
 .../ExternalFileTypeEntryEditor.java          | 229 ------------------
 6 files changed, 80 insertions(+), 267 deletions(-)
 delete mode 100644 src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java

diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java
index e7a2d1492ef..ab1435cb4ff 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java
@@ -64,7 +64,7 @@ public void initialize() {
                 .install(fileTypesTableIconColumn);
         new ValueTableCellFactory<ExternalFileType, Boolean>()
                 .withGraphic(none -> IconTheme.JabRefIcons.EDIT.getGraphicNode())
-                .withOnMouseClickedEvent((type, none) -> event -> viewModel.edit(type))
+                                                              .withOnMouseClickedEvent((type, none) -> event -> viewModel.edit(type, false))
                 .install(fileTypesTableEditColumn);
         new ValueTableCellFactory<ExternalFileType, Boolean>()
                 .withGraphic(none -> IconTheme.JabRefIcons.REMOVE.getGraphicNode())
diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
index 5d8c68e9fa4..560c9ea1eea 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
@@ -10,7 +10,8 @@
 import org.jabref.gui.icon.IconTheme;
 
 public class CustomizeExternalFileTypesViewModel {
-    private ObservableList<ExternalFileType> fileTypes;
+
+    private final ObservableList<ExternalFileType> fileTypes;
 
     public CustomizeExternalFileTypesViewModel() {
         Set<ExternalFileType> types = ExternalFileTypes.getInstance().getExternalFileTypeSelection();
@@ -34,14 +35,14 @@ public void resetToDefaults() {
     public void addNewType() {
         CustomExternalFileType type = new CustomExternalFileType("", "", "", "", "new", IconTheme.JabRefIcons.FILE);
         fileTypes.add(type);
-        edit(type);
+        edit(type, true);
     }
 
     public ObservableList<ExternalFileType> getFileTypes() {
         return fileTypes;
     }
 
-    public void edit(ExternalFileType type) {
+    public void edit(ExternalFileType type, boolean add) {
         CustomExternalFileType typeForEdit;
         if (type instanceof CustomExternalFileType) {
             typeForEdit = (CustomExternalFileType) type;
@@ -49,8 +50,9 @@ public void edit(ExternalFileType type) {
             typeForEdit = new CustomExternalFileType(type);
         }
 
-        ExternalFileTypeEntryEditor entryEditor = new ExternalFileTypeEntryEditor(typeForEdit);
-        entryEditor.setVisible(true);
+        EditExternalFileTypeDialog dlg = new EditExternalFileTypeDialog(typeForEdit, add);
+        dlg.showAndWait();
+
     }
 
     public void remove(ExternalFileType type) {
diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
index 8b058afe5d0..d8a5d86257c 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <?import javafx.scene.control.Button?>
+<?import javafx.scene.control.ButtonType?>
 <?import javafx.scene.control.DialogPane?>
 <?import javafx.scene.control.Label?>
 <?import javafx.scene.control.RadioButton?>
@@ -10,8 +11,7 @@
 <?import javafx.scene.layout.GridPane?>
 <?import javafx.scene.layout.RowConstraints?>
 
-
-<DialogPane prefHeight="302.0" prefWidth="462.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.externalfiletype.EditExternalFileTypeDialog">
+<DialogPane minHeight="-Infinity" prefHeight="302.0" prefWidth="508.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.externalfiletype.EditExternalFileTypeDialog">
    <content>
       <GridPane>
         <columnConstraints>
@@ -29,25 +29,26 @@
             <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
         </rowConstraints>
          <children>
-            <Label text="Icon" />
-            <Label text="Name" GridPane.rowIndex="1" />
-            <Label text="Extension" GridPane.rowIndex="2" />
-            <Label text="MIME type" GridPane.rowIndex="3" />
-            <Label text="Application" GridPane.rowIndex="4" />
-            <RadioButton fx:id="defaultApplication" mnemonicParsing="false" selected="true" text="Default" GridPane.columnIndex="1" GridPane.rowIndex="4">
+            <Label text="%Icon" />
+            <Label text="%Name" GridPane.rowIndex="1" />
+            <Label text="%Extension" GridPane.rowIndex="2" />
+            <Label text="%MIME type" GridPane.rowIndex="3" />
+            <Label text="%Application" GridPane.rowIndex="4" />
+            <RadioButton fx:id="defaultApplication" mnemonicParsing="false" selected="true" text="%Default" GridPane.columnIndex="1" GridPane.rowIndex="4">
                <toggleGroup>
                   <ToggleGroup fx:id="applicationToggleGroup" />
                </toggleGroup>
             </RadioButton>
-            <TextField fx:id="extension" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="2" />
             <TextField fx:id="name" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="1" />
+            <TextField fx:id="extension" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="2" />
             <TextField fx:id="mimeType" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="3" />
-            <RadioButton fx:id="customApplication" mnemonicParsing="false" toggleGroup="$applicationToggleGroup" GridPane.columnIndex="1" GridPane.rowIndex="5" />
+            <RadioButton fx:id="customApplication" mnemonicParsing="false" text="Custom" toggleGroup="$applicationToggleGroup" GridPane.columnIndex="1" GridPane.rowIndex="5" />
             <TextField fx:id="selectedApplication" prefWidth="152.0" GridPane.columnIndex="2" GridPane.rowIndex="5" />
-            <Button fx:id="btnBrowse" mnemonicParsing="false" onAction="#openFileChooser" text="Browse" GridPane.columnIndex="3" GridPane.rowIndex="5" />
+            <Button fx:id="btnBrowse" mnemonicParsing="false" onAction="#openFileChooser" text="%Browse" GridPane.columnIndex="3" GridPane.rowIndex="5" />
+            <Label fx:id="icon" GridPane.columnIndex="1" />
          </children>
       </GridPane>
    </content>
-   <ButtonType fx:constant="OK"/>
-   <ButtonType fx:constant="CANCEL"/>
+   <ButtonType fx:constant="OK" />
+   <ButtonType fx:constant="CANCEL" />
 </DialogPane>
diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
index 7647b97d166..b78045c3780 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
@@ -6,6 +6,7 @@
 import javafx.fxml.FXML;
 import javafx.scene.control.Button;
 import javafx.scene.control.ButtonType;
+import javafx.scene.control.Label;
 import javafx.scene.control.RadioButton;
 import javafx.scene.control.TextField;
 import javafx.scene.control.ToggleGroup;
@@ -29,16 +30,21 @@ public class EditExternalFileTypeDialog extends BaseDialog<Void> {
     @FXML private RadioButton customApplication;
     @FXML private TextField selectedApplication;
     @FXML private Button btnBrowse;
+    @FXML private Label icon;
+    @Inject private DialogService dialogService;
+
     private final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
     private final FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
+    private final String editFileTitle = Localization.lang("Edit file type");
+    private final String newFileTitle = Localization.lang("Add new file type");
 
-    @Inject private DialogService dialogService;
     private EditExternalFileTypeViewModel viewModel;
     private CustomExternalFileType entry;
 
-    public EditExternalFileTypeDialog(CustomExternalFileType entry) {
+    public EditExternalFileTypeDialog(CustomExternalFileType entry, boolean add) {
         this.entry = entry;
-        this.setTitle(Localization.lang("Edit external file type"));
+
+        setTitleToAddOrEdit(add);
 
         ViewLoader.view(this)
                   .load()
@@ -56,7 +62,9 @@ public EditExternalFileTypeDialog(CustomExternalFileType entry) {
     public void initialize() {
         viewModel = new EditExternalFileTypeViewModel(entry);
 
-        viewModel.defaultApplicationSelectedProperty().bindBidirectional(defaultApplication.selectedProperty());
+        icon.setGraphic(viewModel.getIcon());
+
+        defaultApplication.selectedProperty().bindBidirectional(viewModel.defaultApplicationSelectedProperty());
         selectedApplication.disableProperty().bind(viewModel.defaultApplicationSelectedProperty());
         btnBrowse.disableProperty().bind(viewModel.defaultApplicationSelectedProperty());
 
@@ -64,13 +72,18 @@ public void initialize() {
         name.textProperty().bindBidirectional(viewModel.nameProperty());
         mimeType.textProperty().bindBidirectional(viewModel.mimeTypeProperty());
         selectedApplication.textProperty().bindBidirectional(viewModel.selectedApplicationProperty());
-
     }
 
     @FXML
     private void openFileChooser(ActionEvent event) {
         dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> viewModel.selectedApplicationProperty().setValue(path.toAbsolutePath().toString()));
-
     }
 
+    private void setTitleToAddOrEdit(boolean add) {
+        if (add) {
+            this.setTitle(newFileTitle);
+        } else {
+            this.setTitle(editFileTitle);
+        }
+    }
 }
diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java
index 0e3329d222c..9697f6fded1 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java
@@ -1,13 +1,13 @@
 package org.jabref.gui.externalfiletype;
 
 import javafx.beans.property.BooleanProperty;
-import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleBooleanProperty;
-import javafx.beans.property.SimpleObjectProperty;
 import javafx.beans.property.SimpleStringProperty;
 import javafx.beans.property.StringProperty;
 import javafx.scene.Node;
 
+import org.jabref.logic.util.OS;
+
 public class EditExternalFileTypeViewModel {
 
     private final StringProperty extensionProperty = new SimpleStringProperty("");
@@ -15,16 +15,18 @@ public class EditExternalFileTypeViewModel {
     private final StringProperty mimeTypeProperty = new SimpleStringProperty("");
     private final StringProperty selectedApplicationProperty = new SimpleStringProperty("");
     private final BooleanProperty defaultApplicationSelectedProperty = new SimpleBooleanProperty(false);
-    private final ObjectProperty<Node> iconProperty = new SimpleObjectProperty<>();
+    private final Node icon;
+    private final CustomExternalFileType fileType;
 
-    public EditExternalFileTypeViewModel(CustomExternalFileType entry) {
-        extensionProperty.setValue(entry.getExtension());
-        nameProperty.setValue(entry.getFieldName());
-        mimeTypeProperty.setValue(entry.getMimeType());
-        selectedApplicationProperty.setValue(entry.getOpenWithApplication());
-        iconProperty.setValue(entry.getIcon().getGraphicNode());
+    public EditExternalFileTypeViewModel(CustomExternalFileType fileType) {
+        this.fileType = fileType;
+        extensionProperty.setValue(fileType.getExtension());
+        nameProperty.setValue(fileType.getFieldName());
+        mimeTypeProperty.setValue(fileType.getMimeType());
+        selectedApplicationProperty.setValue(fileType.getOpenWithApplication());
+        icon = fileType.getIcon().getGraphicNode();
 
-        if (entry.getOpenWithApplication().isEmpty()) {
+        if (fileType.getOpenWithApplication().isEmpty()) {
             defaultApplicationSelectedProperty.setValue(true);
         }
 
@@ -50,12 +52,36 @@ public BooleanProperty defaultApplicationSelectedProperty() {
         return defaultApplicationSelectedProperty;
     }
 
-    public ObjectProperty<Node> iconProperty() {
-        return iconProperty;
+    public Node getIcon() {
+        return icon;
     }
 
     public void storeSettings() {
-        // TODO Auto-generated method stub
+
+        fileType.setName(nameProperty.getValue().trim());
+        fileType.setMimeType(mimeTypeProperty.getValue().trim());
+
+        String ext = extensionProperty.getValue().trim();
+        if (!ext.isEmpty() && (ext.charAt(0) == '.')) {
+            fileType.setExtension(ext.substring(1));
+        } else {
+            fileType.setExtension(ext);
+        }
+
+        String application = selectedApplicationProperty.getValue().trim();
+        if (OS.WINDOWS) {
+            // On Windows, store application as empty if the "Default" option is selected,
+            // or if the application name is empty:
+            if (defaultApplicationSelectedProperty.getValue() || application.isEmpty()) {
+                fileType.setOpenWith("");
+                selectedApplicationProperty.setValue("");
+
+            } else {
+                fileType.setOpenWith(application);
+            }
+        } else {
+            fileType.setOpenWith(application);
+        }
 
     }
 
diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java
deleted file mode 100644
index 676868ac898..00000000000
--- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java
+++ /dev/null
@@ -1,229 +0,0 @@
-package org.jabref.gui.externalfiletype;
-
-import java.awt.BorderLayout;
-import java.awt.Dialog;
-import java.awt.Dimension;
-import java.awt.event.ActionListener;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Optional;
-
-import javax.swing.BorderFactory;
-import javax.swing.ButtonGroup;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-import javax.swing.JTextField;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-
-import org.jabref.Globals;
-import org.jabref.JabRefGUI;
-import org.jabref.gui.DialogService;
-import org.jabref.gui.icon.IconTheme;
-import org.jabref.gui.util.DefaultTaskExecutor;
-import org.jabref.gui.util.FileDialogConfiguration;
-import org.jabref.logic.l10n.Localization;
-import org.jabref.logic.util.OS;
-import org.jabref.preferences.JabRefPreferences;
-
-import com.jgoodies.forms.builder.ButtonBarBuilder;
-import com.jgoodies.forms.builder.FormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-
-/**
- * This class produces a dialog box for editing an external file type.
- */
-public class ExternalFileTypeEntryEditor {
-
-    private JDialog diag;
-    private final JTextField extension = new JTextField();
-    private final JTextField name = new JTextField();
-    private final JTextField mimeType = new JTextField();
-    private final JTextField application = new JTextField();
-    private final JLabel icon = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon());
-    private final JButton ok = new JButton(Localization.lang("OK"));
-    private final JButton cancel = new JButton(Localization.lang("Cancel"));
-    private final JRadioButton useDefault = new JRadioButton(Localization.lang("Default"));
-    private final JRadioButton other = new JRadioButton("");
-    private final String editFileTitle = Localization.lang("Edit file type");
-    private final String newFileTitle = Localization.lang("Add new file type");
-
-    private CustomExternalFileType entry;
-    private boolean okPressed;
-
-    private final ActionListener browsePressed = e -> {
-        String appDir = application.getText().trim();
-        if (appDir.isEmpty()) {
-            appDir = Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY);
-        }
-
-        FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
-                .withInitialDirectory(Paths.get(appDir)).build();
-        DialogService ds = JabRefGUI.getMainFrame().getDialogService();
-
-        Optional<Path> path = DefaultTaskExecutor
-                .runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));
-
-        path.ifPresent(applicationDir -> {
-            if (applicationDir.getParent() != null) {
-                Globals.prefs.put(JabRefPreferences.WORKING_DIRECTORY, applicationDir.getParent().toString());
-            }
-            application.setText(applicationDir.toString());
-        });
-    };
-
-    public ExternalFileTypeEntryEditor(CustomExternalFileType entry) {
-        init(entry);
-    }
-
-    private void init(CustomExternalFileType inEntry) {
-        entry = inEntry;
-        icon.setText(null);
-
-        ButtonGroup bg = new ButtonGroup();
-        bg.add(useDefault);
-        bg.add(other);
-
-        FormBuilder builder = FormBuilder.create();
-        builder.layout(new FormLayout("left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref",
-                "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"));
-        builder.add(Localization.lang("Icon")).xy(1, 1);
-        builder.add(icon).xy(3, 1);
-        builder.add(Localization.lang("Name")).xy(1, 3);
-        builder.add(name).xy(3, 3);
-        builder.add(Localization.lang("Extension")).xy(1, 5);
-        builder.add(extension).xy(3, 5);
-        builder.add(Localization.lang("MIME type")).xy(1, 7);
-        builder.add(mimeType).xy(3, 7);
-        builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
-        builder.add(Localization.lang("Application")).xy(1, 9);
-        JButton browseBut = new JButton(Localization.lang("Browse"));
-        if (OS.WINDOWS) {
-            builder.add(useDefault).xy(3, 9);
-            builder.appendRows("2dlu, p");
-            JPanel p1 = new JPanel();
-            builder.add(p1).xy(1, 11);
-            JPanel p2 = new JPanel();
-            application.setPreferredSize(new Dimension(300, application.getPreferredSize().height));
-            BorderLayout bl = new BorderLayout();
-            bl.setHgap(4);
-            p2.setLayout(bl);
-            p2.add(other, BorderLayout.WEST);
-            p2.add(application, BorderLayout.CENTER);
-            builder.add(p2).xy(3, 11);
-            builder.add(browseBut).xy(5, 11);
-        } else {
-            builder.add(application).xy(3, 9);
-            builder.add(browseBut).xy(5, 9);
-        }
-        ButtonBarBuilder bb = new ButtonBarBuilder();
-        bb.addGlue();
-        bb.addButton(ok);
-        bb.addButton(cancel);
-        bb.addGlue();
-
-        ok.addActionListener(e -> {
-            okPressed = true;
-
-            storeSettings(ExternalFileTypeEntryEditor.this.entry);
-            diag.dispose();
-
-        });
-        cancel.addActionListener(e -> diag.dispose());
-
-        if (OS.WINDOWS) {
-            application.getDocument().addDocumentListener(new DocumentListener() {
-
-                private void handle() {
-                    if (application.getText().isEmpty()) {
-                        useDefault.setSelected(true);
-                    } else {
-                        other.setSelected(true);
-                    }
-                }
-
-                @Override
-                public void insertUpdate(DocumentEvent documentEvent) {
-                    handle();
-                }
-
-                @Override
-                public void removeUpdate(DocumentEvent documentEvent) {
-                    handle();
-                }
-
-                @Override
-                public void changedUpdate(DocumentEvent documentEvent) {
-                    handle();
-                }
-            });
-        }
-
-        String title = editFileTitle;
-
-        if (entry.getName().isEmpty()) {
-            title = newFileTitle;
-        }
-
-        diag = new JDialog((Dialog) null, title, true);
-        diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
-        diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
-        diag.pack();
-
-        browseBut.addActionListener(browsePressed);
-
-        setValues(entry);
-    }
-
-    public void setVisible(boolean visible) {
-        if (visible) {
-            okPressed = false;
-        }
-        diag.setVisible(visible);
-    }
-
-    private void setValues(ExternalFileType entry) {
-        name.setText(entry.getName());
-        extension.setText(entry.getExtension());
-        mimeType.setText(entry.getMimeType());
-        application.setText(entry.getOpenWithApplication());
-        icon.setIcon(entry.getIcon().getSmallIcon());
-        if (application.getText().isEmpty()) {
-            useDefault.setSelected(true);
-        } else {
-            other.setSelected(true);
-        }
-    }
-
-    private void storeSettings(CustomExternalFileType fileTypeEntry) {
-        fileTypeEntry.setName(name.getText().trim());
-        fileTypeEntry.setMimeType(mimeType.getText().trim());
-        // Set extension, but remove initial dot if user has added that:
-        String ext = extension.getText().trim();
-        if (!ext.isEmpty() && (ext.charAt(0) == '.')) {
-            fileTypeEntry.setExtension(ext.substring(1));
-        } else {
-            fileTypeEntry.setExtension(ext);
-        }
-
-        if (OS.WINDOWS) {
-            // On Windows, store application as empty if the "Default" option is selected,
-            // or if the application name is empty:
-            if (useDefault.isSelected() || application.getText().trim().isEmpty()) {
-                fileTypeEntry.setOpenWith("");
-            } else {
-                fileTypeEntry.setOpenWith(application.getText().trim());
-            }
-        } else {
-            fileTypeEntry.setOpenWith(application.getText().trim());
-        }
-    }
-
-    public boolean okPressed() {
-        return okPressed;
-    }
-
-}

From 1263b5d5c11ed9db16a81a125af59299b5321988 Mon Sep 17 00:00:00 2001
From: Siedlerchr <siedlerkiller@gmail.com>
Date: Sun, 14 Apr 2019 20:56:51 +0200
Subject: [PATCH 3/4] Pass l10n dialog title as parameter

---
 .../CustomizeExternalFileTypesDialog.java          |  2 +-
 .../CustomizeExternalFileTypesViewModel.java       | 10 +++++++---
 .../EditExternalFileTypeDialog.java                | 14 ++------------
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java
index ab1435cb4ff..e7a2d1492ef 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java
@@ -64,7 +64,7 @@ public void initialize() {
                 .install(fileTypesTableIconColumn);
         new ValueTableCellFactory<ExternalFileType, Boolean>()
                 .withGraphic(none -> IconTheme.JabRefIcons.EDIT.getGraphicNode())
-                                                              .withOnMouseClickedEvent((type, none) -> event -> viewModel.edit(type, false))
+                .withOnMouseClickedEvent((type, none) -> event -> viewModel.edit(type))
                 .install(fileTypesTableEditColumn);
         new ValueTableCellFactory<ExternalFileType, Boolean>()
                 .withGraphic(none -> IconTheme.JabRefIcons.REMOVE.getGraphicNode())
diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
index 560c9ea1eea..1bcc8f6fcdc 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
@@ -8,6 +8,7 @@
 import javafx.collections.ObservableList;
 
 import org.jabref.gui.icon.IconTheme;
+import org.jabref.logic.l10n.Localization;
 
 public class CustomizeExternalFileTypesViewModel {
 
@@ -35,14 +36,14 @@ public void resetToDefaults() {
     public void addNewType() {
         CustomExternalFileType type = new CustomExternalFileType("", "", "", "", "new", IconTheme.JabRefIcons.FILE);
         fileTypes.add(type);
-        edit(type, true);
+        showEditDialog(type, Localization.lang("Add new file type"));
     }
 
     public ObservableList<ExternalFileType> getFileTypes() {
         return fileTypes;
     }
 
-    public void edit(ExternalFileType type, boolean add) {
+    private void showEditDialog(ExternalFileType type, String dialogTitle) {
         CustomExternalFileType typeForEdit;
         if (type instanceof CustomExternalFileType) {
             typeForEdit = (CustomExternalFileType) type;
@@ -50,9 +51,12 @@ public void edit(ExternalFileType type, boolean add) {
             typeForEdit = new CustomExternalFileType(type);
         }
 
-        EditExternalFileTypeDialog dlg = new EditExternalFileTypeDialog(typeForEdit, add);
+        EditExternalFileTypeDialog dlg = new EditExternalFileTypeDialog(typeForEdit, dialogTitle);
         dlg.showAndWait();
+    }
 
+    public void edit(ExternalFileType type) {
+        showEditDialog(type, Localization.lang("Edit file type"));
     }
 
     public void remove(ExternalFileType type) {
diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
index b78045c3780..5617766bc7e 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
@@ -16,7 +16,6 @@
 import org.jabref.gui.desktop.os.NativeDesktop;
 import org.jabref.gui.util.BaseDialog;
 import org.jabref.gui.util.FileDialogConfiguration;
-import org.jabref.logic.l10n.Localization;
 
 import com.airhacks.afterburner.views.ViewLoader;
 
@@ -35,16 +34,14 @@ public class EditExternalFileTypeDialog extends BaseDialog<Void> {
 
     private final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
     private final FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
-    private final String editFileTitle = Localization.lang("Edit file type");
-    private final String newFileTitle = Localization.lang("Add new file type");
 
     private EditExternalFileTypeViewModel viewModel;
     private CustomExternalFileType entry;
 
-    public EditExternalFileTypeDialog(CustomExternalFileType entry, boolean add) {
+    public EditExternalFileTypeDialog(CustomExternalFileType entry, String dialogTitle) {
         this.entry = entry;
 
-        setTitleToAddOrEdit(add);
+        this.setTitle(dialogTitle);
 
         ViewLoader.view(this)
                   .load()
@@ -79,11 +76,4 @@ private void openFileChooser(ActionEvent event) {
         dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> viewModel.selectedApplicationProperty().setValue(path.toAbsolutePath().toString()));
     }
 
-    private void setTitleToAddOrEdit(boolean add) {
-        if (add) {
-            this.setTitle(newFileTitle);
-        } else {
-            this.setTitle(editFileTitle);
-        }
-    }
 }

From 56db85c841a2c1335d6a0da51ef520d35ccdfced Mon Sep 17 00:00:00 2001
From: Siedlerchr <siedlerkiller@gmail.com>
Date: Sun, 14 Apr 2019 21:00:06 +0200
Subject: [PATCH 4/4] rename to EditExternalFileTypeEntryDialog

---
 .../externalfiletype/CustomizeExternalFileTypesViewModel.java | 2 +-
 .../gui/externalfiletype/EditExternalFileTypeDialog.fxml      | 2 +-
 ...leTypeDialog.java => EditExternalFileTypeEntryDialog.java} | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
 rename src/main/java/org/jabref/gui/externalfiletype/{EditExternalFileTypeDialog.java => EditExternalFileTypeEntryDialog.java} (94%)

diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
index 1bcc8f6fcdc..4a250f6f549 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java
@@ -51,7 +51,7 @@ private void showEditDialog(ExternalFileType type, String dialogTitle) {
             typeForEdit = new CustomExternalFileType(type);
         }
 
-        EditExternalFileTypeDialog dlg = new EditExternalFileTypeDialog(typeForEdit, dialogTitle);
+        EditExternalFileTypeEntryDialog dlg = new EditExternalFileTypeEntryDialog(typeForEdit, dialogTitle);
         dlg.showAndWait();
     }
 
diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
index d8a5d86257c..11da6fc3712 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.fxml
@@ -11,7 +11,7 @@
 <?import javafx.scene.layout.GridPane?>
 <?import javafx.scene.layout.RowConstraints?>
 
-<DialogPane minHeight="-Infinity" prefHeight="302.0" prefWidth="508.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.externalfiletype.EditExternalFileTypeDialog">
+<DialogPane minHeight="-Infinity" prefHeight="302.0" prefWidth="508.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.externalfiletype.EditExternalFileTypeEntryDialog">
    <content>
       <GridPane>
         <columnConstraints>
diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeEntryDialog.java
similarity index 94%
rename from src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
rename to src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeEntryDialog.java
index 5617766bc7e..88566e07772 100644
--- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeDialog.java
+++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeEntryDialog.java
@@ -19,7 +19,7 @@
 
 import com.airhacks.afterburner.views.ViewLoader;
 
-public class EditExternalFileTypeDialog extends BaseDialog<Void> {
+public class EditExternalFileTypeEntryDialog extends BaseDialog<Void> {
 
     @FXML private RadioButton defaultApplication;
     @FXML private ToggleGroup applicationToggleGroup;
@@ -38,7 +38,7 @@ public class EditExternalFileTypeDialog extends BaseDialog<Void> {
     private EditExternalFileTypeViewModel viewModel;
     private CustomExternalFileType entry;
 
-    public EditExternalFileTypeDialog(CustomExternalFileType entry, String dialogTitle) {
+    public EditExternalFileTypeEntryDialog(CustomExternalFileType entry, String dialogTitle) {
         this.entry = entry;
 
         this.setTitle(dialogTitle);