-
-
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.
Convert "Manage external file types" dialog to JavaFX (#4711)
* Convert "Manage external file types" dialog to JavaFX * Fix language file
- Loading branch information
1 parent
f1de7bd
commit c16f733
Showing
8 changed files
with
191 additions
and
338 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
src/main/java/org/jabref/gui/actions/EditExternalFileTypesAction.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,12 +1,12 @@ | ||
package org.jabref.gui.actions; | ||
|
||
import org.jabref.gui.externalfiletype.ExternalFileTypeEditor; | ||
import org.jabref.gui.externalfiletype.CustomizeExternalFileTypesDialog; | ||
|
||
public class EditExternalFileTypesAction extends SimpleCommand { | ||
|
||
@Override | ||
public void execute() { | ||
ExternalFileTypeEditor editor = new ExternalFileTypeEditor(); | ||
editor.show(); | ||
CustomizeExternalFileTypesDialog editor = new CustomizeExternalFileTypesDialog(); | ||
editor.showAndWait(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.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,39 @@ | ||
<?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.TableColumn?> | ||
<?import javafx.scene.control.TableView?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.VBox?> | ||
<DialogPane xmlns:fx="http://javafx.com/fxml" | ||
xmlns="http://javafx.com/javafx" | ||
fx:controller="org.jabref.gui.externalfiletype.CustomizeExternalFileTypesDialog" | ||
prefHeight="500.0" prefWidth="750.0"> | ||
<content> | ||
<VBox spacing="10"> | ||
<TableView fx:id="fileTypesTable" VBox.vgrow="ALWAYS"> | ||
<columns> | ||
<TableColumn fx:id="fileTypesTableIconColumn" minWidth="40.0" maxWidth="40.0"/> | ||
<TableColumn fx:id="fileTypesTableNameColumn" text="%Name"/> | ||
<TableColumn fx:id="fileTypesTableExtensionColumn" text="%Extension" prefWidth="120"/> | ||
<TableColumn fx:id="fileTypesTableTypeColumn" text="%MIME type" prefWidth="150"/> | ||
<TableColumn fx:id="fileTypesTableApplicationColumn" text="%Application" prefWidth="100"/> | ||
<TableColumn fx:id="fileTypesTableEditColumn" minWidth="40.0" maxWidth="40.0"/> | ||
<TableColumn fx:id="fileTypesTableDeleteColumn" minWidth="40.0" maxWidth="40.0"/> | ||
</columns> | ||
<columnResizePolicy> | ||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/> | ||
</columnResizePolicy> | ||
</TableView> | ||
<HBox> | ||
<Button text="%Add new file type" onAction="#addNewType"/> | ||
<HBox HBox.hgrow="ALWAYS"/> | ||
<Button text="%Reset to default" onAction="#resetToDefault" styleClass="text-button"/> | ||
</HBox> | ||
</VBox> | ||
</content> | ||
<ButtonType fx:constant="OK"/> | ||
<ButtonType fx:constant="CANCEL"/> | ||
</DialogPane> |
86 changes: 86 additions & 0 deletions
86
src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.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,86 @@ | ||
package org.jabref.gui.externalfiletype; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
|
||
import org.jabref.gui.icon.IconTheme; | ||
import org.jabref.gui.icon.JabRefIcon; | ||
import org.jabref.gui.util.BaseDialog; | ||
import org.jabref.gui.util.BindingsHelper; | ||
import org.jabref.gui.util.ValueTableCellFactory; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
import com.airhacks.afterburner.views.ViewLoader; | ||
|
||
/** | ||
* Editor for external file types. | ||
*/ | ||
public class CustomizeExternalFileTypesDialog extends BaseDialog<Void> { | ||
|
||
@FXML private TableColumn<ExternalFileType, JabRefIcon> fileTypesTableIconColumn; | ||
@FXML private TableColumn<ExternalFileType, String> fileTypesTableNameColumn; | ||
@FXML private TableColumn<ExternalFileType, String> fileTypesTableExtensionColumn; | ||
@FXML private TableColumn<ExternalFileType, String> fileTypesTableTypeColumn; | ||
@FXML private TableColumn<ExternalFileType, String> fileTypesTableApplicationColumn; | ||
@FXML private TableColumn<ExternalFileType, Boolean> fileTypesTableEditColumn; | ||
@FXML private TableColumn<ExternalFileType, Boolean> fileTypesTableDeleteColumn; | ||
@FXML private TableView<ExternalFileType> fileTypesTable; | ||
|
||
private CustomizeExternalFileTypesViewModel viewModel; | ||
|
||
public CustomizeExternalFileTypesDialog() { | ||
this.setTitle(Localization.lang("Manage external file types")); | ||
|
||
ViewLoader.view(this) | ||
.load() | ||
.setAsDialogPane(this); | ||
|
||
this.setResultConverter(button -> { | ||
if (button == ButtonType.OK) { | ||
viewModel.storeSettings(); | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
@FXML | ||
public void initialize() { | ||
viewModel = new CustomizeExternalFileTypesViewModel(); | ||
|
||
fileTypesTable.setItems(viewModel.getFileTypes()); | ||
|
||
fileTypesTableIconColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getIcon())); | ||
fileTypesTableNameColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getName())); | ||
fileTypesTableExtensionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getExtension())); | ||
fileTypesTableTypeColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getMimeType())); | ||
fileTypesTableApplicationColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getOpenWithApplication())); | ||
fileTypesTableEditColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); | ||
fileTypesTableDeleteColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); | ||
|
||
new ValueTableCellFactory<ExternalFileType, JabRefIcon>() | ||
.withGraphic(JabRefIcon::getGraphicNode) | ||
.install(fileTypesTableIconColumn); | ||
new ValueTableCellFactory<ExternalFileType, Boolean>() | ||
.withGraphic(none -> IconTheme.JabRefIcons.EDIT.getGraphicNode()) | ||
.withOnMouseClickedEvent((type, none) -> event -> viewModel.edit(type)) | ||
.install(fileTypesTableEditColumn); | ||
new ValueTableCellFactory<ExternalFileType, Boolean>() | ||
.withGraphic(none -> IconTheme.JabRefIcons.REMOVE.getGraphicNode()) | ||
.withOnMouseClickedEvent((type, none) -> event -> viewModel.remove(type)) | ||
.install(fileTypesTableDeleteColumn); | ||
} | ||
|
||
@FXML | ||
private void addNewType() { | ||
viewModel.addNewType(); | ||
fileTypesTable.getSelectionModel().selectLast(); | ||
fileTypesTable.scrollTo(viewModel.getFileTypes().size() - 1); | ||
} | ||
|
||
@FXML | ||
private void resetToDefault() { | ||
viewModel.resetToDefaults(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.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,59 @@ | ||
package org.jabref.gui.externalfiletype; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
import org.jabref.gui.icon.IconTheme; | ||
|
||
public class CustomizeExternalFileTypesViewModel { | ||
private ObservableList<ExternalFileType> fileTypes; | ||
|
||
public CustomizeExternalFileTypesViewModel() { | ||
Set<ExternalFileType> types = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); | ||
fileTypes = FXCollections.observableArrayList(types); | ||
fileTypes.sort(Comparator.comparing(ExternalFileType::getName)); | ||
} | ||
|
||
/** | ||
* Stores the list of external entry types in the preferences. | ||
*/ | ||
public void storeSettings() { | ||
ExternalFileTypes.getInstance().setExternalFileTypes(fileTypes); | ||
} | ||
|
||
public void resetToDefaults() { | ||
List<ExternalFileType> list = ExternalFileTypes.getDefaultExternalFileTypes(); | ||
fileTypes.setAll(list); | ||
fileTypes.sort(Comparator.comparing(ExternalFileType::getName)); | ||
} | ||
|
||
public void addNewType() { | ||
CustomExternalFileType type = new CustomExternalFileType("", "", "", "", "new", IconTheme.JabRefIcons.FILE); | ||
fileTypes.add(type); | ||
edit(type); | ||
} | ||
|
||
public ObservableList<ExternalFileType> getFileTypes() { | ||
return fileTypes; | ||
} | ||
|
||
public void edit(ExternalFileType type) { | ||
CustomExternalFileType typeForEdit; | ||
if (type instanceof CustomExternalFileType) { | ||
typeForEdit = (CustomExternalFileType) type; | ||
} else { | ||
typeForEdit = new CustomExternalFileType(type); | ||
} | ||
|
||
ExternalFileTypeEntryEditor entryEditor = new ExternalFileTypeEntryEditor(typeForEdit); | ||
entryEditor.setVisible(true); | ||
} | ||
|
||
public void remove(ExternalFileType type) { | ||
fileTypes.remove(type); | ||
} | ||
} |
Oops, something went wrong.