Skip to content
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

javafx replacement for file dialog #3005

Merged
merged 55 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
67ed3aa
javafx replacement for file dialog
Siedlerchr Jul 6, 2017
f4a58c3
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Jul 15, 2017
136a844
Add some core structure for selectFilesDialog
Siedlerchr Jul 15, 2017
b6d43dc
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Jul 31, 2017
b3d7641
Add Properties for binding
Siedlerchr Jul 31, 2017
24c35c5
add getters
Siedlerchr Jul 31, 2017
8dca324
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Aug 6, 2017
dfde523
Renaming, use properties in controller
Siedlerchr Aug 6, 2017
6633d61
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Sep 23, 2017
e099c2a
port some more code
Siedlerchr Sep 23, 2017
2296ea5
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Nov 1, 2017
982b475
Asssign combobox selected value property
Siedlerchr Nov 1, 2017
3b7e52d
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Nov 3, 2017
dbca24f
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Nov 19, 2017
9f5036d
fix some formatting
Siedlerchr Nov 19, 2017
5b797d4
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Dec 29, 2017
81c25ec
make getController public to get viewModel
Siedlerchr Dec 29, 2017
d4aed9b
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Jan 2, 2018
e71181a
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Jan 2, 2018
d3daaa6
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Jan 2, 2018
e326bcf
add enum with config values instead of booleans
Siedlerchr Jan 3, 2018
e64b406
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Jan 14, 2018
32c3db2
Fix depdendency injection
Siedlerchr Jan 14, 2018
3f85f65
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Siedlerchr Jan 24, 2018
34d4251
Merge remote-tracking branch 'origin/master' into selectFilesDlg
tobiasdiez Feb 6, 2018
514cd49
Rework
tobiasdiez Feb 6, 2018
5305d43
Merge remote-tracking branch 'upstream/maintable-beta' into selectFil…
Siedlerchr Mar 17, 2018
cb7096c
Merge remote-tracking branch 'upstream/master' into maintable-beta
Siedlerchr Mar 17, 2018
fbf8fdb
Create Wrapper to pass LinkedFile around
Siedlerchr Mar 17, 2018
cc6f3b9
fix some indentations
Siedlerchr Mar 17, 2018
ae7af40
remove open unknown external file type dialog
Siedlerchr Mar 17, 2018
16f0b11
Merge remote-tracking branch 'upstream/maintable-beta' into selectFil…
Siedlerchr Mar 18, 2018
3f7c282
fix indentation
Siedlerchr Mar 18, 2018
9d2df14
convert attachFileDialog to javafx
Siedlerchr Mar 18, 2018
38e087e
reformat
Siedlerchr Mar 18, 2018
298a28f
Mark old filelist as deprecated
Siedlerchr Mar 19, 2018
773d4cc
Merge remote-tracking branch 'upstream/maintable-beta' into selectFil…
Siedlerchr Mar 19, 2018
39a1092
fix checkstyle
Siedlerchr Mar 19, 2018
058aaf6
fix checkstyle again
Siedlerchr Mar 19, 2018
210d645
add changelog
Siedlerchr Mar 19, 2018
ce8b9c2
adjust indentation
Siedlerchr Mar 20, 2018
3450c8d
Merge remote-tracking branch 'upstream/maintable-beta' into selectFil…
Siedlerchr Mar 24, 2018
b5816bc
convert to new FXML dialog model funcionality
Siedlerchr Mar 24, 2018
e1f85fd
fix empty lines
Siedlerchr Mar 24, 2018
8cb812d
fix checkstyle
Siedlerchr Mar 24, 2018
0be175c
Fix viewModel NPE in copyFiles Action and linkedfilesEditDialog
Siedlerchr Mar 24, 2018
45697c4
Add close button in copy linked files
Siedlerchr Mar 24, 2018
7d627ff
fix checkstyle
Siedlerchr Mar 24, 2018
3189b33
Rename and reformat
Siedlerchr Mar 25, 2018
f579772
remove changelog
Siedlerchr Mar 25, 2018
95fdd2d
remove close method
Siedlerchr Mar 25, 2018
bb22a5e
change some odd looking assigments
Siedlerchr Mar 25, 2018
035d9e2
renaming
Siedlerchr Mar 25, 2018
ce3d5e6
forgotten rename
Siedlerchr Mar 25, 2018
c27c4d2
Merge remote-tracking branch 'upstream/maintable-beta' into selectFil…
Siedlerchr Mar 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ The new default removes the linked file from the entry instead of deleting the f
- Pressing <kbd>ESC</kbd> while searching will clear the search field and select the first entry, if available, in the table. [koppor#293](https://github.com/koppor/jabref/issues/293)
- We changed the metadata reading and writing. DublinCore is now the only metadata format, JabRef supports. (https://github.com/JabRef/jabref/pull/3710)
- We added another CLI functionality for reading and writing metadata to pdfs. (see https://github.com/JabRef/jabref/pull/3756 and see http://help.jabref.org/en/CommandLine)
- We improved the layout of the Edit file layout and made it resizable. We also tweaked the workflow for attaching files from the contextmenu, see https://github.com/JabRef/jabref/pull/3005
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the changes in maintable-beta is currently in the changelog. Thus, for consistency, I would say remove it for the moment and add it to the list in #3621.

- We no longer print errors in field values during autosave into the log [#3811](https://github.com/JabRef/jabref/issues/3811)


### Fixed
- We fixed several performance problems with the management of journal abbreviations [#3323](https://github.com/JabRef/jabref/issues/3323)
- We fixed an issue where changing the type of an entry did not update the label in the tool bar of the entry editor and the contents of the currently visible entry editor tab
Expand Down
213 changes: 90 additions & 123 deletions src/main/java/org/jabref/gui/BasePanel.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/actions/CopyFilesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void showDialog(List<CopyFilesResultItemViewModel> data) {
return;
}
CopyFilesDialogView dialog = new CopyFilesDialogView(databaseContext, new CopyFilesResultListDependency(data));
dialog.show();
dialog.showAndWait();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum StandardActions implements Action {
OPEN_EXTERNAL_FILE(Localization.lang("Open file"), IconTheme.JabRefIcons.FILE, KeyBinding.OPEN_FILE),
OPEN_URL(Localization.lang("Open URL or DOI"), IconTheme.JabRefIcons.WWW, KeyBinding.OPEN_URL_OR_DOI),
MERGE_WITH_FETCHED_ENTRY(Localization.lang("Get BibTeX data from %0", "DOI/ISBN/...")),
ADD_FILE_LINK(Localization.lang("Attach file"), IconTheme.JabRefIcons.ATTACH_FILE),
ATTACH_FILE(Localization.lang("Attach file"), IconTheme.JabRefIcons.ATTACH_FILE),
ADD_TO_GROUP(Localization.lang("Add to group")),
REMOVE_FROM_GROUP(Localization.lang("Remove from group")),
MOVE_TO_GROUP(Localization.lang("Move to group")),
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/jabref/gui/copyfiles/CopyFilesDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
</columnResizePolicy>
</TableView>
</center>
<bottom>
<ButtonBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<buttons>
<Button defaultButton="true" mnemonicParsing="false" onAction="#close" text="%OK" ButtonBar.buttonData="OK_DONE" />
</buttons>
</ButtonBar>
</bottom>
</BorderPane>
</content>
</DialogPane>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.paint.Color;
Expand All @@ -28,11 +29,14 @@ public CopyFilesDialogView(BibDatabaseContext bibDatabaseContext, CopyFilesResul
this.setTitle(Localization.lang("Result"));
this.setResizable(true);

this.getDialogPane().getButtonTypes().addAll(ButtonType.CLOSE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original button was labeled OK and I think this makes more sense than Close. Moreover, the close method in this class can now be removed, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that with an only OK button I was not able to close the dialog neither via the X in the corner nor via the OK button. It needs to have at least a button with Type CANCEL_CLOSE
Read the last paragraph: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Problem was that the OK button was not at the Dialog Pane, but inside the content and therefore did not work


viewModel = new CopyFilesDialogViewModel(results);

ViewLoader.view(this)
.load()
.setAsContent(this.getDialogPane());

viewModel = new CopyFilesDialogViewModel(results);
}

@FXML
Expand Down
111 changes: 14 additions & 97 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,26 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.regex.Pattern;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.jabref.Globals;
import org.jabref.JabRefGUI;
import org.jabref.gui.ClipBoardManager;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.desktop.os.DefaultDesktop;
import org.jabref.gui.desktop.os.Linux;
import org.jabref.gui.desktop.os.NativeDesktop;
import org.jabref.gui.desktop.os.OSX;
import org.jabref.gui.desktop.os.Windows;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypeEntryEditor;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.externalfiletype.UnknownExternalFileType;
import org.jabref.gui.filelist.FileListEntry;
import org.jabref.gui.filelist.FileListEntryEditor;
import org.jabref.gui.filelist.FileListTableModel;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.identifier.Eprint;
Expand Down Expand Up @@ -64,7 +52,8 @@ private JabRefDesktop() {
* Open a http/pdf/ps viewer for the given link string.
*/
public static void openExternalViewer(BibDatabaseContext databaseContext, String initialLink,
String initialFieldName) throws IOException {
String initialFieldName)
throws IOException {
String link = initialLink;
String fieldName = initialFieldName;
if (FieldName.PS.equals(fieldName) || FieldName.PDF.equals(fieldName)) {
Expand All @@ -85,7 +74,7 @@ public static void openExternalViewer(BibDatabaseContext databaseContext, String
if ("pdf".equalsIgnoreCase(split[split.length - 1])) {
fieldName = FieldName.PDF;
} else if ("ps".equalsIgnoreCase(split[split.length - 1])
|| ((split.length >= 3) && "ps".equalsIgnoreCase(split[split.length - 2]))) {
|| ((split.length >= 3) && "ps".equalsIgnoreCase(split[split.length - 2]))) {
fieldName = FieldName.PS;
}
}
Expand Down Expand Up @@ -132,7 +121,8 @@ private static void openDoi(String doi) throws IOException {
* @return false if the link couldn't be resolved, true otherwise.
*/
public static boolean openExternalFileAnyFormat(final BibDatabaseContext databaseContext, String link,
final Optional<ExternalFileType> type) throws IOException {
final Optional<ExternalFileType> type)
throws IOException {

if (REMOTE_LINK_PATTERN.matcher(link.toLowerCase(Locale.ROOT)).matches()) {
openExternalFilePlatformIndependent(type, link);
Expand All @@ -156,7 +146,7 @@ public static boolean openExternalFileAnyFormat(Path file, final BibDatabaseCont
}

private static void openExternalFilePlatformIndependent(Optional<ExternalFileType> fileType, String filePath)
throws IOException {
throws IOException {
if (fileType.isPresent()) {
String application = fileType.get().getOpenWithApplication();

Expand All @@ -168,82 +158,6 @@ private static void openExternalFilePlatformIndependent(Optional<ExternalFileTyp
}
}

public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry, BibDatabaseContext databaseContext,
String link, UnknownExternalFileType fileType) throws IOException {

String cancelMessage = Localization.lang("Unable to open file.");
String[] options = new String[] {Localization.lang("Define '%0'", fileType.getName()),
Localization.lang("Change file type"), Localization.lang("Cancel")};
String defOption = options[0];
int answer = JOptionPane.showOptionDialog(null,
Localization.lang("This external link is of the type '%0', which is undefined. What do you want to do?",
fileType.getName()),
Localization.lang("Undefined file type"), JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, defOption);
if (answer == JOptionPane.CANCEL_OPTION) {
frame.output(cancelMessage);
return false;
} else if (answer == JOptionPane.YES_OPTION) {
// User wants to define the new file type. Show the dialog:

ExternalFileType newType = new ExternalFileType(fileType.getName(), "", "", "", "new", IconTheme.JabRefIcons.FILE);
ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor((JFrame) null, newType);

editor.setVisible(true);
if (editor.okPressed()) {
// Get the old list of types, add this one, and update the list in prefs:
List<ExternalFileType> fileTypes = new ArrayList<>(
ExternalFileTypes.getInstance().getExternalFileTypeSelection());
fileTypes.add(newType);
Collections.sort(fileTypes);
ExternalFileTypes.getInstance().setExternalFileTypes(fileTypes);
// Finally, open the file:
return openExternalFileAnyFormat(databaseContext, link, Optional.of(newType));
} else {
// Canceled:
frame.output(cancelMessage);
return false;
}
} else {
// User wants to change the type of this link.
// First get a model of all file links for this entry:
FileListTableModel tModel = new FileListTableModel();
Optional<String> oldValue = entry.getField(FieldName.FILE);
oldValue.ifPresent(tModel::setContent);
FileListEntry flEntry = null;
// Then find which one we are looking at:
for (int i = 0; i < tModel.getRowCount(); i++) {
FileListEntry iEntry = tModel.getEntry(i);
if (iEntry.getLink().equals(link)) {
flEntry = iEntry;
break;
}
}
if (flEntry == null) {
// This shouldn't happen, so I'm not sure what to put in here:
throw new RuntimeException("Could not find the file list entry " + link + " in " + entry);
}

FileListEntryEditor editor = new FileListEntryEditor(flEntry.toParsedFileField(), false, true, databaseContext);
editor.setVisible(true, false);
if (editor.okPressed()) {
// Store the changes and add an undo edit:
String newValue = tModel.getStringRepresentation();
UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE, oldValue.orElse(null),
newValue);
entry.setField(FieldName.FILE, newValue);
frame.getCurrentBasePanel().getUndoManager().addEdit(ce);
frame.getCurrentBasePanel().markBaseChanged();
// Finally, open the link:
return openExternalFileAnyFormat(databaseContext, flEntry.getLink(), flEntry.getType());
} else {
// Canceled:
frame.output(cancelMessage);
return false;
}
}
}

/**
* Opens a file browser of the folder of the given file. If possible, the file is selected
* @param fileLink the location of the file
Expand Down Expand Up @@ -284,8 +198,11 @@ public static void openBrowserShowPopup(String url) {
String openManually = Localization.lang("Please open %0 manually.", url);
String copiedToClipboard = Localization.lang("The link has been copied to the clipboard.");
JabRefGUI.getMainFrame().output(couldNotOpenBrowser);
JOptionPane.showMessageDialog(null, couldNotOpenBrowser + "\n" + openManually + "\n" +
copiedToClipboard, couldNotOpenBrowser, JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
couldNotOpenBrowser + "\n" + openManually + "\n" +
copiedToClipboard,
couldNotOpenBrowser,
JOptionPane.ERROR_MESSAGE);
}
}

Expand Down Expand Up @@ -327,9 +244,9 @@ public static void openConsole(File file) throws IOException {
LOGGER.error("Open console", exception);

JOptionPane.showMessageDialog(null,
Localization.lang("Error occured while executing the command \"%0\".", commandLoggingText),
Localization.lang("Open console") + " - " + Localization.lang("Error"),
JOptionPane.ERROR_MESSAGE);
Localization.lang("Error occured while executing the command \"%0\".", commandLoggingText),
Localization.lang("Open console") + " - " + Localization.lang("Error"),
JOptionPane.ERROR_MESSAGE);
JabRefGUI.getMainFrame().output(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

import javax.swing.Icon;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import org.jabref.gui.JabRefFrame;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.util.FileHelper;

import org.slf4j.Logger;
Expand All @@ -25,30 +24,28 @@
* to process the request if the user clicks this menu item.
*/
public class ExternalFileMenuItem extends JMenuItem implements ActionListener {

private static final Logger LOGGER = LoggerFactory.getLogger(ExternalFileMenuItem.class);

private final BibEntry entry;
private final String link;
private final BibDatabaseContext databaseContext;
private Optional<ExternalFileType> fileType;
private final JabRefFrame frame;
private String fieldName;


public ExternalFileMenuItem(JabRefFrame frame, BibEntry entry, String name, String link, Icon icon,
BibDatabaseContext databaseContext, Optional<ExternalFileType> fileType) {
public ExternalFileMenuItem(JabRefFrame frame, String name, String link, Icon icon,
BibDatabaseContext databaseContext, Optional<ExternalFileType> fileType) {
super(name, icon);
this.frame = frame;
this.entry = entry;
this.link = link;
this.databaseContext = databaseContext;
this.fileType = fileType;
addActionListener(this);
}

public ExternalFileMenuItem(JabRefFrame frame, BibEntry entry, String name, String link, Icon icon,
BibDatabaseContext databaseContext, String fieldName) {
this(frame, entry, name, link, icon, databaseContext, Optional.empty());
public ExternalFileMenuItem(JabRefFrame frame, String name, String link, Icon icon,
BibDatabaseContext databaseContext, String fieldName) {
this(frame, name, link, icon, databaseContext, Optional.empty());
this.fieldName = fieldName;
}

Expand Down Expand Up @@ -77,25 +74,21 @@ private boolean openLink() {
}
}

if (type.isPresent() && (type.get() instanceof UnknownExternalFileType)) {
return JabRefDesktop.openExternalFileUnknown(frame, entry, databaseContext, link,
(UnknownExternalFileType) type.get());
} else {
return JabRefDesktop.openExternalFileAnyFormat(databaseContext, link, type);
}
return JabRefDesktop.openExternalFileAnyFormat(databaseContext, link, type);

} catch (IOException ex) {
// See if we should show an error message concerning the application to open the
// link with. We check if the file type is set, and if the file type has a non-empty
// application link. If that link is referred by the error message, we can assume
// that the problem is in the open-with-application setting:
if ((fileType.isPresent()) && (!fileType.get().getOpenWithApplication().isEmpty())
&& ex.getMessage().contains(fileType.get().getOpenWithApplication())) {
&& ex.getMessage().contains(fileType.get().getOpenWithApplication())) {

DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().showErrorDialogAndWait(Localization.lang("Could not open link"),
Localization.lang("Unable to open link. " + "The application '%0' associated with the file type '%1' could not be called.",
fileType.get().getOpenWithApplication(),
fileType.get().getName())));

JOptionPane.showMessageDialog(null, Localization.lang("Unable to open link. "
+ "The application '%0' associated with the file type '%1' could not be called.",
fileType.get().getOpenWithApplication(), fileType.get().getName()),
Localization.lang("Could not open link"), JOptionPane.ERROR_MESSAGE);
return false;
}

Expand Down
Loading