-
-
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
Convert "Protected terms" dialog to JavaFX #4715
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
23 changes: 0 additions & 23 deletions
23
src/main/java/org/jabref/gui/actions/ManageProtectedTermsAction.java
This file was deleted.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsAction.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,16 @@ | ||
package org.jabref.gui.protectedterms; | ||
|
||
import org.jabref.gui.actions.SimpleCommand; | ||
|
||
public class ManageProtectedTermsAction extends SimpleCommand { | ||
|
||
public ManageProtectedTermsAction() { | ||
|
||
} | ||
|
||
@Override | ||
public void execute() { | ||
ManageProtectedTermsDialog protectTermsDialog = new ManageProtectedTermsDialog(); | ||
protectTermsDialog.showAndWait(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsDialog.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,36 @@ | ||
<?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.protectedterms.ManageProtectedTermsDialog" | ||
prefHeight="400.0" prefWidth="600.0"> | ||
<content> | ||
<VBox spacing="10"> | ||
<TableView fx:id="filesTable" editable="true" VBox.vgrow="ALWAYS"> | ||
<columns> | ||
<TableColumn fx:id="filesTableEnabledColumn" text="%Enabled" minWidth="80" maxWidth="80"/> | ||
<TableColumn fx:id="filesTableDescriptionColumn" text="%Description"/> | ||
<TableColumn fx:id="filesTableFileColumn" text="%File"/> | ||
<TableColumn fx:id="filesTableEditColumn" maxWidth="40" minWidth="40.0"/> | ||
<TableColumn fx:id="filesTableDeleteColumn" maxWidth="40" minWidth="40.0"/> | ||
</columns> | ||
<columnResizePolicy> | ||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/> | ||
</columnResizePolicy> | ||
</TableView> | ||
<HBox> | ||
<Button text="%Add protected terms file" onAction="#addFile"/> | ||
<Button text="%New protected terms file" onAction="#createNewFile"/> | ||
</HBox> | ||
</VBox> | ||
</content> | ||
<ButtonType fx:constant="CANCEL"/> | ||
<ButtonType fx:constant="APPLY"/> | ||
</DialogPane> |
126 changes: 126 additions & 0 deletions
126
src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsDialog.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,126 @@ | ||
package org.jabref.gui.protectedterms; | ||
|
||
import javax.inject.Inject; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.ContextMenu; | ||
import javafx.scene.control.MenuItem; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
import javafx.scene.control.cell.CheckBoxTableCell; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.icon.IconTheme; | ||
import org.jabref.gui.util.BaseDialog; | ||
import org.jabref.gui.util.BindingsHelper; | ||
import org.jabref.gui.util.ValueTableCellFactory; | ||
import org.jabref.gui.util.ViewModelTableRowFactory; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.protectedterms.ProtectedTermsList; | ||
import org.jabref.logic.protectedterms.ProtectedTermsLoader; | ||
|
||
import com.airhacks.afterburner.views.ViewLoader; | ||
|
||
/** | ||
* Dialog for managing term list files. | ||
*/ | ||
public class ManageProtectedTermsDialog extends BaseDialog<Void> { | ||
|
||
@FXML private TableView<ProtectedTermsList> filesTable; | ||
@FXML private TableColumn<ProtectedTermsList, Boolean> filesTableEnabledColumn; | ||
@FXML private TableColumn<ProtectedTermsList, String> filesTableDescriptionColumn; | ||
@FXML private TableColumn<ProtectedTermsList, String> filesTableFileColumn; | ||
@FXML private TableColumn<ProtectedTermsList, Boolean> filesTableEditColumn; | ||
@FXML private TableColumn<ProtectedTermsList, Boolean> filesTableDeleteColumn; | ||
|
||
@Inject private ProtectedTermsLoader termsLoader; | ||
@Inject private DialogService dialogService; | ||
private ManageProtectedTermsViewModel viewModel; | ||
|
||
public ManageProtectedTermsDialog() { | ||
this.setTitle(Localization.lang("Manage protected terms files")); | ||
|
||
ViewLoader.view(this) | ||
.load() | ||
.setAsDialogPane(this); | ||
|
||
setResultConverter(button -> { | ||
if (button == ButtonType.APPLY) { | ||
viewModel.save(); | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
@FXML | ||
public void initialize() { | ||
viewModel = new ManageProtectedTermsViewModel(termsLoader, dialogService); | ||
|
||
filesTable.setItems(viewModel.getTermsFiles()); | ||
new ViewModelTableRowFactory<ProtectedTermsList>() | ||
.withContextMenu(this::createContextMenu) | ||
.install(filesTable); | ||
filesTableEnabledColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().isEnabled())); | ||
filesTableEnabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(filesTableEnabledColumn)); | ||
filesTableDescriptionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getDescription())); | ||
filesTableFileColumn.setCellValueFactory(data -> { | ||
ProtectedTermsList list = data.getValue(); | ||
if (list.isInternalList()) { | ||
return BindingsHelper.constantOf(Localization.lang("Internal list")); | ||
} else { | ||
return BindingsHelper.constantOf(data.getValue().getLocation()); | ||
} | ||
}); | ||
filesTableEditColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); | ||
filesTableDeleteColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); | ||
|
||
new ValueTableCellFactory<ProtectedTermsList, Boolean>() | ||
.withGraphic(none -> IconTheme.JabRefIcons.EDIT.getGraphicNode()) | ||
.withOnMouseClickedEvent((file, none) -> event -> viewModel.edit(file)) | ||
.install(filesTableEditColumn); | ||
new ValueTableCellFactory<ProtectedTermsList, Boolean>() | ||
.withGraphic(none -> IconTheme.JabRefIcons.REMOVE.getGraphicNode()) | ||
.withTooltip(none -> Localization.lang("Remove protected terms file")) | ||
.withOnMouseClickedEvent((file, none) -> event -> viewModel.removeFile(file)) | ||
.install(filesTableDeleteColumn); | ||
} | ||
|
||
private ContextMenu createContextMenu(ProtectedTermsList file) { | ||
MenuItem edit = new MenuItem(Localization.lang("Edit")); | ||
edit.setOnAction(event -> viewModel.edit(file)); | ||
MenuItem show = new MenuItem(Localization.lang("View")); | ||
show.setOnAction(event -> viewModel.displayContent(file)); | ||
MenuItem remove = new MenuItem(Localization.lang("Remove")); | ||
remove.setOnAction(event -> viewModel.removeFile(file)); | ||
MenuItem reload = new MenuItem(Localization.lang("Reload")); | ||
reload.setOnAction(event -> viewModel.reloadFile(file)); | ||
|
||
// Enable/disable context menu items | ||
if (file.isInternalList()) { | ||
edit.setDisable(true); | ||
show.setDisable(false); | ||
remove.setDisable(true); | ||
reload.setDisable(true); | ||
} else { | ||
edit.setDisable(false); | ||
show.setDisable(false); | ||
remove.setDisable(false); | ||
reload.setDisable(false); | ||
} | ||
|
||
final ContextMenu contextMenu = new ContextMenu(); | ||
contextMenu.getItems().addAll(edit, show, remove, reload); | ||
return contextMenu; | ||
} | ||
|
||
@FXML | ||
private void addFile() { | ||
viewModel.addFile(); | ||
} | ||
|
||
@FXML | ||
private void createNewFile() { | ||
viewModel.createNewFile(); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsViewModel.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,97 @@ | ||
package org.jabref.gui.protectedterms; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
import org.jabref.Globals; | ||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.desktop.JabRefDesktop; | ||
import org.jabref.gui.externalfiletype.ExternalFileType; | ||
import org.jabref.gui.externalfiletype.ExternalFileTypes; | ||
import org.jabref.gui.util.FileDialogConfiguration; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.protectedterms.ProtectedTermsList; | ||
import org.jabref.logic.protectedterms.ProtectedTermsLoader; | ||
import org.jabref.logic.util.StandardFileType; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.util.OptionalUtil; | ||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ManageProtectedTermsViewModel { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ManageProtectedTermsViewModel.class); | ||
|
||
private final ProtectedTermsLoader termsLoader; | ||
private final ObservableList<ProtectedTermsList> termsFiles; | ||
private DialogService dialogService; | ||
|
||
public ManageProtectedTermsViewModel(ProtectedTermsLoader termsLoader, DialogService dialogService) { | ||
this.termsLoader = termsLoader; | ||
this.dialogService = dialogService; | ||
this.termsFiles = FXCollections.observableArrayList(termsLoader.getProtectedTermsLists()); | ||
} | ||
|
||
public ObservableList<ProtectedTermsList> getTermsFiles() { | ||
return termsFiles; | ||
} | ||
|
||
public void save() { | ||
Globals.prefs.setProtectedTermsPreferences(termsLoader); | ||
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. Use Injected PreferencesService and pass it as parameter to the ViewModel |
||
} | ||
|
||
public void addFile() { | ||
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() | ||
.addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS) | ||
.withDefaultExtension(Localization.lang("Protected terms file"), StandardFileType.TERMS) | ||
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); | ||
|
||
dialogService.showFileOpenDialog(fileDialogConfiguration) | ||
.ifPresent(file -> termsLoader.addProtectedTermsListFromFile(file.toAbsolutePath().toString(), true)); | ||
} | ||
|
||
public void removeFile(ProtectedTermsList list) { | ||
if (!list.isInternalList() && dialogService.showConfirmationDialogAndWait(Localization.lang("Remove protected terms file"), | ||
Localization.lang("Are you sure you want to remove the protected terms file?"), | ||
Localization.lang("Remove protected terms file"), | ||
Localization.lang("Cancel"))) { | ||
if (!termsLoader.removeProtectedTermsList(list)) { | ||
LOGGER.info("Problem removing protected terms file"); | ||
} | ||
} | ||
} | ||
|
||
public void createNewFile() { | ||
NewProtectedTermsFileDialog newDialog = new NewProtectedTermsFileDialog(termsLoader, dialogService); | ||
newDialog.showAndWait(); | ||
} | ||
|
||
public void edit(ProtectedTermsList file) { | ||
Optional<ExternalFileType> termsFileType = OptionalUtil.orElse( | ||
ExternalFileTypes.getInstance().getExternalFileTypeByExt("terms"), | ||
ExternalFileTypes.getInstance().getExternalFileTypeByExt("txt") | ||
); | ||
|
||
String fileName = file.getLocation(); | ||
try { | ||
JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), fileName, termsFileType); | ||
} catch (IOException e) { | ||
LOGGER.warn("Problem open protected terms file editor", e); | ||
} | ||
} | ||
|
||
public void displayContent(ProtectedTermsList list) { | ||
dialogService.showInformationDialogAndWait( | ||
list.getDescription() + " - " + list.getLocation(), | ||
list.getTermListing() | ||
); | ||
} | ||
|
||
public void reloadFile(ProtectedTermsList file) { | ||
termsLoader.reloadProtectedTermsList(file); | ||
} | ||
} |
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.
Remove the unnecessary constructor