|  | 
|  | 1 | +package org.jabref.gui.externalfiletype; | 
|  | 2 | + | 
|  | 3 | +import javafx.fxml.FXML; | 
|  | 4 | +import javafx.scene.control.ButtonType; | 
|  | 5 | +import javafx.scene.control.TableColumn; | 
|  | 6 | +import javafx.scene.control.TableView; | 
|  | 7 | + | 
|  | 8 | +import org.jabref.gui.icon.IconTheme; | 
|  | 9 | +import org.jabref.gui.icon.JabRefIcon; | 
|  | 10 | +import org.jabref.gui.util.BaseDialog; | 
|  | 11 | +import org.jabref.gui.util.BindingsHelper; | 
|  | 12 | +import org.jabref.gui.util.ValueTableCellFactory; | 
|  | 13 | +import org.jabref.logic.l10n.Localization; | 
|  | 14 | + | 
|  | 15 | +import com.airhacks.afterburner.views.ViewLoader; | 
|  | 16 | + | 
|  | 17 | +/** | 
|  | 18 | + * Editor for external file types. | 
|  | 19 | + */ | 
|  | 20 | +public class CustomizeExternalFileTypesDialog extends BaseDialog<Void> { | 
|  | 21 | + | 
|  | 22 | +    @FXML private TableColumn<ExternalFileType, JabRefIcon> fileTypesTableIconColumn; | 
|  | 23 | +    @FXML private TableColumn<ExternalFileType, String> fileTypesTableNameColumn; | 
|  | 24 | +    @FXML private TableColumn<ExternalFileType, String> fileTypesTableExtensionColumn; | 
|  | 25 | +    @FXML private TableColumn<ExternalFileType, String> fileTypesTableTypeColumn; | 
|  | 26 | +    @FXML private TableColumn<ExternalFileType, String> fileTypesTableApplicationColumn; | 
|  | 27 | +    @FXML private TableColumn<ExternalFileType, Boolean> fileTypesTableEditColumn; | 
|  | 28 | +    @FXML private TableColumn<ExternalFileType, Boolean> fileTypesTableDeleteColumn; | 
|  | 29 | +    @FXML private TableView<ExternalFileType> fileTypesTable; | 
|  | 30 | + | 
|  | 31 | +    private CustomizeExternalFileTypesViewModel viewModel; | 
|  | 32 | + | 
|  | 33 | +    public CustomizeExternalFileTypesDialog() { | 
|  | 34 | +        this.setTitle(Localization.lang("Manage external file types")); | 
|  | 35 | + | 
|  | 36 | +        ViewLoader.view(this) | 
|  | 37 | +                  .load() | 
|  | 38 | +                  .setAsDialogPane(this); | 
|  | 39 | + | 
|  | 40 | +        this.setResultConverter(button -> { | 
|  | 41 | +            if (button == ButtonType.OK) { | 
|  | 42 | +                viewModel.storeSettings(); | 
|  | 43 | +            } | 
|  | 44 | +            return null; | 
|  | 45 | +        }); | 
|  | 46 | +    } | 
|  | 47 | + | 
|  | 48 | +    @FXML | 
|  | 49 | +    public void initialize() { | 
|  | 50 | +        viewModel = new CustomizeExternalFileTypesViewModel(); | 
|  | 51 | + | 
|  | 52 | +        fileTypesTable.setItems(viewModel.getFileTypes()); | 
|  | 53 | + | 
|  | 54 | +        fileTypesTableIconColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getIcon())); | 
|  | 55 | +        fileTypesTableNameColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getName())); | 
|  | 56 | +        fileTypesTableExtensionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getExtension())); | 
|  | 57 | +        fileTypesTableTypeColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getMimeType())); | 
|  | 58 | +        fileTypesTableApplicationColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getOpenWithApplication())); | 
|  | 59 | +        fileTypesTableEditColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); | 
|  | 60 | +        fileTypesTableDeleteColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); | 
|  | 61 | + | 
|  | 62 | +        new ValueTableCellFactory<ExternalFileType, JabRefIcon>() | 
|  | 63 | +                .withGraphic(JabRefIcon::getGraphicNode) | 
|  | 64 | +                .install(fileTypesTableIconColumn); | 
|  | 65 | +        new ValueTableCellFactory<ExternalFileType, Boolean>() | 
|  | 66 | +                .withGraphic(none -> IconTheme.JabRefIcons.EDIT.getGraphicNode()) | 
|  | 67 | +                .withOnMouseClickedEvent((type, none) -> event -> viewModel.edit(type)) | 
|  | 68 | +                .install(fileTypesTableEditColumn); | 
|  | 69 | +        new ValueTableCellFactory<ExternalFileType, Boolean>() | 
|  | 70 | +                .withGraphic(none -> IconTheme.JabRefIcons.REMOVE.getGraphicNode()) | 
|  | 71 | +                .withOnMouseClickedEvent((type, none) -> event -> viewModel.remove(type)) | 
|  | 72 | +                .install(fileTypesTableDeleteColumn); | 
|  | 73 | +    } | 
|  | 74 | + | 
|  | 75 | +    @FXML | 
|  | 76 | +    private void addNewType() { | 
|  | 77 | +        viewModel.addNewType(); | 
|  | 78 | +        fileTypesTable.getSelectionModel().selectLast(); | 
|  | 79 | +        fileTypesTable.scrollTo(viewModel.getFileTypes().size() - 1); | 
|  | 80 | +    } | 
|  | 81 | + | 
|  | 82 | +    @FXML | 
|  | 83 | +    private void resetToDefault() { | 
|  | 84 | +        viewModel.resetToDefaults(); | 
|  | 85 | +    } | 
|  | 86 | +} | 
0 commit comments