-
-
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
Export pdf/linked files #3147
Export pdf/linked files #3147
Changes from 18 commits
9d38d12
00eccc7
50e9716
26a7e1f
ec7c44b
68e1562
d1b53eb
7021371
6b02e9c
edec73d
95474ea
bed0a54
e347bc9
090a4cd
93f72b2
353e9ad
f29066c
aa10731
9e6cffc
b61082c
713ecec
cfa74e5
4c01181
cc30b98
a67cd4e
5d96526
8011e6e
bb1a304
5e1117a
8dabe6d
fc7a2a1
ba35360
88faa7c
658d97e
8f14cc7
07ee6ea
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.jabref.gui.actions; | ||
|
||
import javafx.beans.property.ObjectProperty; | ||
import javafx.beans.property.SimpleObjectProperty; | ||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
|
||
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; | ||
|
||
public class CopyFilesResultViewModel { | ||
|
||
private final StringProperty file = new SimpleStringProperty(""); | ||
private final ObjectProperty<MaterialDesignIcon> icon = new SimpleObjectProperty<>(MaterialDesignIcon.ALERT); | ||
|
||
private final StringProperty message = new SimpleStringProperty(""); | ||
|
||
public CopyFilesResultViewModel(String file, boolean success, String message) { | ||
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. Please change the file from string to path |
||
this.file.setValue(file); | ||
this.message.setValue(message); | ||
if (success) { | ||
this.icon.setValue(MaterialDesignIcon.CHECK); | ||
} | ||
|
||
} | ||
|
||
public StringProperty getFile() { | ||
return file; | ||
} | ||
|
||
public void setFile(String file) { | ||
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. are these setters needed? I find an immutable solution better. |
||
this.file.setValue(file); | ||
} | ||
|
||
public StringProperty getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message.setValue(message); | ||
} | ||
|
||
public ObjectProperty<MaterialDesignIcon> getIcon() { | ||
return icon; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CopyFilesResultViewModel [file=" + file.get() + ", message=" + message.get() + "]"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package org.jabref.gui.actions; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javax.swing.AbstractAction; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.concurrent.Service; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.Dialog; | ||
import javafx.scene.control.ScrollPane; | ||
import javafx.scene.control.TableCell; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
import javafx.scene.paint.Color; | ||
import javafx.scene.text.Text; | ||
|
||
import org.jabref.Globals; | ||
import org.jabref.JabRefGUI; | ||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.FXDialogService; | ||
import org.jabref.gui.util.DefaultTaskExecutor; | ||
import org.jabref.gui.util.DirectoryDialogConfiguration; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; | ||
import de.jensd.fx.glyphs.materialdesignicons.utils.MaterialDesignIconFactory; | ||
|
||
public class ExportLinkedFilesAction extends AbstractAction { | ||
|
||
private final DialogService dialogService = new FXDialogService(); | ||
private BibDatabaseContext databaseContext; | ||
private List<BibEntry> entries; | ||
|
||
public ExportLinkedFilesAction() { | ||
super(Localization.lang("Copy attached files to folder...")); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
|
||
DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() | ||
.withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY))) | ||
.build(); | ||
entries = JabRefGUI.getMainFrame().getCurrentBasePanel().getSelectedEntries(); | ||
|
||
Optional<Path> exportPath = DefaultTaskExecutor | ||
.runInJavaFXThread(() -> dialogService.showDirectorySelectionDialog(dirDialogConfiguration)); | ||
|
||
exportPath.ifPresent(path -> { | ||
databaseContext = JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabaseContext(); | ||
|
||
Service<List<CopyFilesResultViewModel>> exportService = new ExportLinkedFilesService(databaseContext, entries, path); | ||
startServiceAndshowProgessDialog(exportService); | ||
}); | ||
} | ||
|
||
private void startServiceAndshowProgessDialog(Service<List<CopyFilesResultViewModel>> exportService) { | ||
DefaultTaskExecutor.runInJavaFXThread(() -> { | ||
exportService.setOnSucceeded(value -> { | ||
DefaultTaskExecutor.runInJavaFXThread(() -> showDialog(exportService.getValue())); | ||
}); | ||
exportService.start(); | ||
DialogService dlgService = new FXDialogService(); | ||
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. you already have a dialog service at class level -> reuse? |
||
dlgService.showCanceableProgressDialogAndWait(exportService); | ||
|
||
}); | ||
} | ||
|
||
private void showDialog(List<CopyFilesResultViewModel> data) { | ||
Dialog<ButtonType> dlg = new Dialog<>(); | ||
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. Can you please extract the result dialog to a seperate fxml file, as all the other dialogs. 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. Will do later. All other issues should be resolved now |
||
dlg.setTitle(Localization.lang("Result")); | ||
ObservableList<CopyFilesResultViewModel> tableData = FXCollections.observableArrayList(data); | ||
|
||
TableView<CopyFilesResultViewModel> tv = createTable(); | ||
ScrollPane sp = new ScrollPane(); | ||
sp.setContent(tv); | ||
|
||
dlg.getDialogPane().setContent(sp); | ||
tv.setItems(tableData); | ||
|
||
sp.setFitToHeight(true); | ||
sp.setFitToWidth(true); | ||
|
||
dlg.getDialogPane().getButtonTypes().add(ButtonType.CLOSE); | ||
dlg.setResizable(true); | ||
dlg.showAndWait(); | ||
} | ||
|
||
private static TableView<CopyFilesResultViewModel> createTable() { | ||
TableView<CopyFilesResultViewModel> tableResult = new TableView<>(); | ||
|
||
TableColumn<CopyFilesResultViewModel, String> colFile = new TableColumn<>(Localization.lang("File")); | ||
TableColumn<CopyFilesResultViewModel, MaterialDesignIcon> colIcon = new TableColumn<>(Localization.lang("Status")); | ||
TableColumn<CopyFilesResultViewModel, String> colMessage = new TableColumn<>(Localization.lang("Message")); | ||
|
||
colFile.setCellValueFactory(cellData -> cellData.getValue().getFile()); | ||
colMessage.setCellValueFactory(cellData -> cellData.getValue().getMessage()); | ||
colIcon.setCellValueFactory(cellData -> cellData.getValue().getIcon()); | ||
|
||
colIcon.setCellFactory(column -> { | ||
return new TableCell<CopyFilesResultViewModel, MaterialDesignIcon>() { | ||
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 think there is a table cell factory helper (similar to list view). If not, then I would be nice if you could create one. |
||
|
||
@Override | ||
protected void updateItem(MaterialDesignIcon item, boolean empty) { | ||
super.updateItem(item, empty); | ||
|
||
if ((item == null) || empty) { | ||
setText(null); | ||
setStyle(""); | ||
} else { | ||
Text icon = MaterialDesignIconFactory.get().createIcon(item); | ||
|
||
//Green checkmark | ||
if (item == MaterialDesignIcon.CHECK) { | ||
icon.setFill(Color.GREEN); | ||
} | ||
//Red Alert symbol | ||
if (item == MaterialDesignIcon.ALERT) { | ||
icon.setFill(Color.RED); | ||
} | ||
setGraphic(icon); | ||
|
||
} | ||
} | ||
}; | ||
}); | ||
tableResult.getColumns().add(colIcon); | ||
tableResult.getColumns().add(colMessage); | ||
tableResult.getColumns().add(colFile); | ||
|
||
return tableResult; | ||
} | ||
|
||
} |
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.
maybe change the name
Result
->ResultItem
to make it clearer that is one item in the result window.