From 67ed3aaff19533ffbe5f53897418e8403d56902b Mon Sep 17 00:00:00 2001 From: siedlerchr Date: Thu, 6 Jul 2017 17:17:22 +0200 Subject: [PATCH 01/36] javafx replacement for file dialog --- .../org/jabref/gui/SelectFilesDialog.fxml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/main/resources/org/jabref/gui/SelectFilesDialog.fxml diff --git a/src/main/resources/org/jabref/gui/SelectFilesDialog.fxml b/src/main/resources/org/jabref/gui/SelectFilesDialog.fxml new file mode 100644 index 00000000000..a2e27d20a9d --- /dev/null +++ b/src/main/resources/org/jabref/gui/SelectFilesDialog.fxml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + From ce8b9c2541c28b366145327dc1cc6da748e50f03 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 20 Mar 2018 15:40:23 +0100 Subject: [PATCH 24/36] adjust indentation --- src/main/java/org/jabref/gui/BasePanel.java | 214 +++++++++----------- 1 file changed, 92 insertions(+), 122 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 0ae79e1c3a4..9f017d2fa6b 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -291,9 +291,7 @@ public String getTabTitle() { } } } else if (databaseLocation == DatabaseLocation.SHARED) { - title.append( - this.bibDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") - + "]"); + title.append(this.bibDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]"); } return title.toString(); @@ -385,9 +383,8 @@ public void init() { numSelected = entries.size(); if (entries.isEmpty()) { // None selected. Inform the user to select entries first. - dialogService.showWarningDialogAndWait( - Localization.lang("Autogenerate BibTeX keys"), - Localization.lang("First select the entries you want keys to be generated for.")); + dialogService.showWarningDialogAndWait(Localization.lang("Autogenerate BibTeX keys"), + Localization.lang("First select the entries you want keys to be generated for.")); return; } output(formatOutputMessage(Localization.lang("Generating BibTeX key for"), numSelected)); @@ -404,12 +401,13 @@ public void run() { } else if (Globals.prefs.getBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY)) { if (entries.parallelStream().anyMatch(BibEntry::hasCiteKey)) { - boolean overwriteKeysPressed = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Overwrite keys"), - Localization.lang("One or more keys will be overwritten. Continue?"), - Localization.lang("Overwrite keys"), - Localization.lang("Cancel"), - Localization.lang("Disable this confirmation dialog"), - optOut -> Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, !optOut)); + boolean overwriteKeysPressed = dialogService.showConfirmationDialogWithOptOutAndWait( + Localization.lang("Overwrite keys"), + Localization.lang("One or more keys will be overwritten. Continue?"), + Localization.lang("Overwrite keys"), + Localization.lang("Cancel"), + Localization.lang("Disable this confirmation dialog"), + optOut -> Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, !optOut)); // The user doesn't want to overide cite keys if (!overwriteKeysPressed) { @@ -466,16 +464,11 @@ public void update() { // The action for copying the BibTeX key and the title for the first selected entry actions.put(Actions.COPY_KEY_AND_TITLE, (BaseAction) () -> copyKeyAndTitle()); - actions.put(Actions.COPY_CITATION_ASCII_DOC, - (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.ASCII_DOC)); - actions.put(Actions.COPY_CITATION_XSLFO, - (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.XSL_FO)); - actions.put(Actions.COPY_CITATION_HTML, - (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.HTML)); - actions.put(Actions.COPY_CITATION_RTF, - (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.RTF)); - actions.put(Actions.COPY_CITATION_TEXT, - (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.TEXT)); + actions.put(Actions.COPY_CITATION_ASCII_DOC, (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.ASCII_DOC)); + actions.put(Actions.COPY_CITATION_XSLFO, (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.XSL_FO)); + actions.put(Actions.COPY_CITATION_HTML, (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.HTML)); + actions.put(Actions.COPY_CITATION_RTF, (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.RTF)); + actions.put(Actions.COPY_CITATION_TEXT, (BaseAction) () -> copyCitationToClipboard(CitationStyleOutputFormat.TEXT)); // The action for copying the BibTeX keys as hyperlinks to the urls of the selected entries actions.put(Actions.COPY_KEY_AND_LINK, new CopyBibTeXKeyAndLinkAction(mainTable)); @@ -485,8 +478,7 @@ public void update() { actions.put(Actions.OPEN_EXTERNAL_FILE, (BaseAction) () -> openExternalFile()); actions.put(Actions.OPEN_FOLDER, (BaseAction) () -> JabRefExecutorService.INSTANCE.execute(() -> { - final List files = FileUtil.getListOfLinkedFiles(mainTable.getSelectedEntries(), - bibDatabaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())); + final List files = FileUtil.getListOfLinkedFiles(mainTable.getSelectedEntries(), bibDatabaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())); for (final Path f : files) { try { JabRefDesktop.openFolderAndSelectFile(f.toAbsolutePath()); @@ -497,12 +489,12 @@ public void update() { })); actions.put(Actions.OPEN_CONSOLE, (BaseAction) () -> JabRefDesktop - .openConsole(frame.getCurrentBasePanel().getBibDatabaseContext().getDatabaseFile().orElse(null))); + .openConsole(frame.getCurrentBasePanel().getBibDatabaseContext().getDatabaseFile().orElse(null))); actions.put(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, (BaseAction) () -> { DatabaseSynchronizer dbmsSynchronizer = frame.getCurrentBasePanel() - .getBibDatabaseContext() - .getDBMSSynchronizer(); + .getBibDatabaseContext() + .getDBMSSynchronizer(); dbmsSynchronizer.pullChanges(); }); @@ -529,7 +521,7 @@ public void update() { } output(Localization.lang("Replaced") + ' ' + counter + ' ' - + (counter == 1 ? Localization.lang("occurrence") : Localization.lang("occurrences")) + '.'); + + (counter == 1 ? Localization.lang("occurrence") : Localization.lang("occurrences")) + '.'); if (counter > 0) { ce.end(); getUndoManager().addEdit(ce); @@ -543,35 +535,33 @@ public void update() { // Note that we can't put the number of entries that have been reverted into the undoText as the concrete number cannot be injected actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(), - new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager).getSpecialFieldAction( - SpecialField.RELEVANCE.getValues().get(0), frame)); + new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager).getSpecialFieldAction(SpecialField.RELEVANCE.getValues().get(0), frame)); + actions.put(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getCommand(), - new SpecialFieldViewModel(SpecialField.QUALITY, undoManager) - .getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame)); + new SpecialFieldViewModel(SpecialField.QUALITY, undoManager).getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame)); + actions.put(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getCommand(), - new SpecialFieldViewModel(SpecialField.PRINTED, undoManager).getSpecialFieldAction( - SpecialField.PRINTED.getValues().get(0), frame)); + new SpecialFieldViewModel(SpecialField.PRINTED, undoManager).getSpecialFieldAction(SpecialField.PRINTED.getValues().get(0), frame)); for (SpecialFieldValue prio : SpecialField.PRIORITY.getValues()) { actions.put(new SpecialFieldValueViewModel(prio).getCommand(), - new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager).getSpecialFieldAction(prio, this.frame)); + new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager).getSpecialFieldAction(prio, this.frame)); } for (SpecialFieldValue rank : SpecialField.RANKING.getValues()) { actions.put(new SpecialFieldValueViewModel(rank).getCommand(), - new SpecialFieldViewModel(SpecialField.RANKING, undoManager).getSpecialFieldAction(rank, this.frame)); + new SpecialFieldViewModel(SpecialField.RANKING, undoManager).getSpecialFieldAction(rank, this.frame)); } for (SpecialFieldValue status : SpecialField.READ_STATUS.getValues()) { actions.put(new SpecialFieldValueViewModel(status).getCommand(), - new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame)); + new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame)); } actions.put(Actions.TOGGLE_PREVIEW, (BaseAction) () -> { PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences(); boolean enabled = !previewPreferences.isPreviewPanelEnabled(); - PreviewPreferences newPreviewPreferences = previewPreferences - .getBuilder() - .withPreviewPanelEnabled(enabled) - .build(); + PreviewPreferences newPreviewPreferences = previewPreferences.getBuilder() + .withPreviewPanelEnabled(enabled) + .build(); Globals.prefs.storePreviewPreferences(newPreviewPreferences); DefaultTaskExecutor.runInJavaFXThread(() -> setPreviewActiveBasePanels(enabled)); }); @@ -645,11 +635,9 @@ private void delete(boolean cut, List entries) { NamedCompound compound; if (cut) { - compound = new NamedCompound( - (entries.size() > 1 ? Localization.lang("cut entries") : Localization.lang("cut entry"))); + compound = new NamedCompound((entries.size() > 1 ? Localization.lang("cut entries") : Localization.lang("cut entry"))); } else { - compound = new NamedCompound( - (entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); + compound = new NamedCompound((entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry"))); } for (BibEntry entry : entries) { compound.addEdit(new UndoableRemoveEntry(bibDatabaseContext.getDatabase(), entry, BasePanel.this)); @@ -660,8 +648,7 @@ private void delete(boolean cut, List entries) { getUndoManager().addEdit(compound); markBaseChanged(); - frame.output( - formatOutputMessage(cut ? Localization.lang("Cut") : Localization.lang("Deleted"), entries.size())); + frame.output(formatOutputMessage(cut ? Localization.lang("Cut") : Localization.lang("Deleted"), entries.size())); // prevent the main table from loosing focus mainTable.requestFocus(); @@ -676,9 +663,9 @@ private void copyTitle() { if (!selectedBibEntries.isEmpty()) { // Collect all non-null titles. List titles = selectedBibEntries.stream() - .filter(bibEntry -> bibEntry.getTitle().isPresent()) - .map(bibEntry -> bibEntry.getTitle().get()) - .collect(Collectors.toList()); + .filter(bibEntry -> bibEntry.getTitle().isPresent()) + .map(bibEntry -> bibEntry.getTitle().get()) + .collect(Collectors.toList()); if (titles.isEmpty()) { output(Localization.lang("None of the selected entries have titles.")); @@ -689,12 +676,9 @@ private void copyTitle() { if (titles.size() == selectedBibEntries.size()) { // All entries had titles. - output((selectedBibEntries.size() > 1 ? Localization.lang("Copied titles") : Localization - .lang("Copied title")) + '.'); + output((selectedBibEntries.size() > 1 ? Localization.lang("Copied titles") : Localization.lang("Copied title")) + '.'); } else { - output(Localization.lang("Warning: %0 out of %1 entries have undefined title.", - Integer.toString(selectedBibEntries.size() - titles.size()), - Integer.toString(selectedBibEntries.size()))); + output(Localization.lang("Warning: %0 out of %1 entries have undefined title.", Integer.toString(selectedBibEntries.size() - titles.size()), Integer.toString(selectedBibEntries.size()))); } } } @@ -714,8 +698,8 @@ private void copyCiteKey() { String sb = String.join(",", keys); String citeCommand = Optional.ofNullable(Globals.prefs.get(JabRefPreferences.CITE_COMMAND)) - .filter(cite -> cite.contains("\\")) // must contain \ - .orElse("\\cite"); + .filter(cite -> cite.contains("\\")) // must contain \ + .orElse("\\cite"); StringSelection ss = new StringSelection(citeCommand + "{" + sb + '}'); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this); @@ -723,8 +707,7 @@ private void copyCiteKey() { // All entries had keys. output(bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key") + '.'); } else { - output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", - Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size()))); + output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size()))); } } } @@ -749,8 +732,7 @@ private void copyKey() { // All entries had keys. output((bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key")) + '.'); } else { - output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", - Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size()))); + output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size()))); } } } @@ -759,13 +741,11 @@ private void copyKeyAndTitle() { List bes = mainTable.getSelectedEntries(); if (!bes.isEmpty()) { // OK: in a future version, this string should be configurable to allow arbitrary exports - StringReader sr = new StringReader( - "\\bibtexkey - \\begin{title}\\format[RemoveBrackets]{\\title}\\end{title}\n"); + StringReader sr = new StringReader("\\bibtexkey - \\begin{title}\\format[RemoveBrackets]{\\title}\\end{title}\n"); Layout layout; try { - layout = new LayoutHelper(sr, - Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)) - .getLayoutFromText(); + layout = new LayoutHelper(sr, Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)) + .getLayoutFromText(); } catch (IOException e) { LOGGER.info("Could not get layout", e); return; @@ -794,8 +774,7 @@ private void copyKeyAndTitle() { // All entries had keys. output((bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key")) + '.'); } else { - output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", - Integer.toString(bes.size() - copied), Integer.toString(bes.size()))); + output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - copied), Integer.toString(bes.size()))); } } } @@ -822,8 +801,7 @@ private void openExternalFile() { return; } FileListEntry flEntry = fileListTableModel.getEntry(0); - ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), "", flEntry.getLink(), - flEntry.getType().get().getIcon().getSmallIcon(), bibDatabaseContext, flEntry.getType()); + ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), "", flEntry.getLink(), flEntry.getType().get().getIcon().getSmallIcon(), bibDatabaseContext, flEntry.getType()); item.doClick(); }); } @@ -852,16 +830,14 @@ public void runCommand(final Actions command) { } } - private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, - SavePreferences.DatabaseSaveType saveType) throws SaveException { + private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, SavePreferences.DatabaseSaveType saveType) throws SaveException { SaveSession session; final String SAVE_DATABASE = Localization.lang("Save library"); try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs) - .withEncoding(enc) - .withSaveType(saveType); - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>( - FileSaveSession::new); + .withEncoding(enc) + .withSaveType(saveType); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(bibDatabaseContext, mainTable.getSelectedEntries(), prefs); } else { @@ -872,10 +848,8 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, } // FIXME: not sure if this is really thrown anywhere catch (UnsupportedCharsetException ex) { - JOptionPane.showMessageDialog(null, - Localization.lang("Could not save file.") + ' ' - + Localization.lang("Character encoding '%0' is not supported.", enc.displayName()), - SAVE_DATABASE, JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, Localization.lang("Could not save file.") + ' ' + + Localization.lang("Character encoding '%0' is not supported.", enc.displayName()), SAVE_DATABASE, JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } catch (SaveException ex) { if (ex.specificEntry()) { @@ -886,33 +860,26 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, LOGGER.warn("Could not save", ex); } - dialogService.showErrorDialogAndWait( - SAVE_DATABASE, - Localization.lang("Could not save file."), - ex); + dialogService.showErrorDialogAndWait(SAVE_DATABASE, Localization.lang("Could not save file."), ex); throw new SaveException("rt"); } boolean commit = true; if (!session.getWriter().couldEncodeAll()) { FormBuilder builder = FormBuilder.create() - .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref")); + .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref")); JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters()); ta.setEditable(false); - builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", - session.getEncoding().displayName())).xy(1, 1); + builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1); builder.add(ta).xy(3, 1); builder.add(Localization.lang("What do you want to do?")).xy(1, 3); String tryDiff = Localization.lang("Try different encoding"); - int answer = JOptionPane.showOptionDialog(null, builder.getPanel(), SAVE_DATABASE, - JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, - new String[] {Localization.lang("Save"), tryDiff, Localization.lang("Cancel")}, tryDiff); + int answer = JOptionPane.showOptionDialog(null, builder.getPanel(), SAVE_DATABASE, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] {Localization.lang("Save"), tryDiff, Localization.lang("Cancel")}, tryDiff); if (answer == JOptionPane.NO_OPTION) { // The user wants to use another encoding. - Object choice = JOptionPane.showInputDialog(null, Localization.lang("Select encoding"), SAVE_DATABASE, - JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, enc); + Object choice = JOptionPane.showInputDialog(null, Localization.lang("Select encoding"), SAVE_DATABASE, JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, enc); if (choice == null) { commit = false; } else { @@ -1050,12 +1017,12 @@ private void createMainTable() { // Update entry editor and preview according to selected entries mainTable.addSelectionListener(event -> mainTable.getSelectedEntries() - .stream() - .findFirst() - .ifPresent(entry -> { - preview.setEntry(entry); - entryEditor.setEntry(entry); - })); + .stream() + .findFirst() + .ifPresent(entry -> { + preview.setEntry(entry); + entryEditor.setEntry(entry); + })); // TODO: Register these actions globally /* @@ -1183,8 +1150,8 @@ public void setupMainPanel() { // Saves the divider position as soon as it changes // We need to keep a reference to the subscription, otherwise the binding gets garbage collected dividerPositionSubscription = EasyBind.monadic(Bindings.valueAt(splitPane.getDividers(), 0)) - .flatMap(SplitPane.Divider::positionProperty) - .subscribe((observable, oldValue, newValue) -> saveDividerLocation(newValue)); + .flatMap(SplitPane.Divider::positionProperty) + .subscribe((observable, oldValue, newValue) -> saveDividerLocation(newValue)); } /** @@ -1317,9 +1284,9 @@ public void previousPreviewStyle() { private void cyclePreview(int newPosition) { PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences() - .getBuilder() - .withPreviewCyclePosition(newPosition) - .build(); + .getBuilder() + .withPreviewCyclePosition(newPosition) + .build(); Globals.prefs.storePreviewPreferences(previewPreferences); preview.updateLayout(previewPreferences); @@ -1393,7 +1360,7 @@ public void entryEditorClosing(EntryEditor editor) { */ public void ensureNotShowingBottomPanel(BibEntry entry) { if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry)) - || ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) { + || ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) { closeBottomPane(); } } @@ -1506,10 +1473,12 @@ public boolean showDeleteConfirmationDialog(int numberOfEntries) { cancelButton = Localization.lang("Keep entries"); } - return dialogService.showConfirmationDialogWithOptOutAndWait(title, message, - okButton, cancelButton, - Localization.lang("Disable this confirmation dialog"), - optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut)); + return dialogService.showConfirmationDialogWithOptOutAndWait(title, + message, + okButton, + cancelButton, + Localization.lang("Disable this confirmation dialog"), + optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut)); } else { return true; } @@ -1549,9 +1518,9 @@ private void saveDividerLocation(Number position) { if (mode == BasePanelMode.SHOWING_PREVIEW) { PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences() - .getBuilder() - .withPreviewPanelDividerPosition(position) - .build(); + .getBuilder() + .withPreviewPanelDividerPosition(position) + .build(); Globals.prefs.storePreviewPreferences(previewPreferences); } else if (mode == BasePanelMode.SHOWING_EDITOR) { preferences.setEntryEditorDividerPosition(position.doubleValue()); @@ -1626,8 +1595,7 @@ private BibEntry getShowing() { } public String formatOutputMessage(String start, int count) { - return String.format("%s %d %s.", start, count, - (count > 1 ? Localization.lang("entries") : Localization.lang("entry"))); + return String.format("%s %d %s.", start, count, (count > 1 ? Localization.lang("entries") : Localization.lang("entry"))); } /** @@ -1856,16 +1824,18 @@ public void action() { List files = bes.get(0).getFiles(); Optional linkedFile = files.stream() - .filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType()) - || FieldName.PS.equalsIgnoreCase(file.getFileType()) - || FieldName.PDF.equalsIgnoreCase(file.getFileType()))) - .findFirst(); + .filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType()) + || FieldName.PS.equalsIgnoreCase(file.getFileType()) + || FieldName.PDF.equalsIgnoreCase(file.getFileType()))) + .findFirst(); if (linkedFile.isPresent()) { try { - JabRefDesktop.openExternalFileAnyFormat(bibDatabaseContext, linkedFile.get().getLink(), ExternalFileTypes.getInstance().fromLinkedFile(linkedFile.get(), true)); + JabRefDesktop.openExternalFileAnyFormat(bibDatabaseContext, + linkedFile.get().getLink(), + ExternalFileTypes.getInstance().fromLinkedFile(linkedFile.get(), true)); output(Localization.lang("External viewer called") + '.'); } catch (IOException e) { @@ -1918,10 +1888,10 @@ public SaveSelectedAction(SavePreferences.DatabaseSaveType saveType) { @Override public void action() throws SaveException { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withDefaultExtension(FileType.BIBTEX_DB) - .addExtensionFilter(FileType.BIBTEX_DB) - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)) - .build(); + .withDefaultExtension(FileType.BIBTEX_DB) + .addExtensionFilter(FileType.BIBTEX_DB) + .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)) + .build(); Optional chosenFile = dialogService.showFileSaveDialog(fileDialogConfiguration); if (chosenFile.isPresent()) { From b5816bcb51faf8df559dc1d1d58ae0657c8994dc Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 24 Mar 2018 17:12:25 +0100 Subject: [PATCH 25/36] convert to new FXML dialog model funcionality still some NPEs --- .../jabref/gui/AbstractReturnDialogView.java | 19 ---- .../org/jabref/gui/desktop/JabRefDesktop.java | 14 +-- .../gui/fieldeditors/LinkedFileViewModel.java | 47 ++++----- .../jabref/gui/filelist/AttachFileAction.java | 17 ++-- .../LinkedFileEditDialogController.java | 43 -------- .../filelist/LinkedFileEditDialogView.java | 80 ++++++++++----- .../gui/importer/ImportInspectionDialog.java | 98 +++++++++---------- .../gui/openoffice/StyleSelectDialog.java | 46 ++++----- .../protectedterms/ProtectedTermsDialog.java | 15 +-- .../gui/filelist/LinkedFileEditDialog.fxml | 2 +- 10 files changed, 158 insertions(+), 223 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/AbstractReturnDialogView.java delete mode 100644 src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogController.java diff --git a/src/main/java/org/jabref/gui/AbstractReturnDialogView.java b/src/main/java/org/jabref/gui/AbstractReturnDialogView.java deleted file mode 100644 index 0386af11db7..00000000000 --- a/src/main/java/org/jabref/gui/AbstractReturnDialogView.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jabref.gui; - -import java.util.function.Function; - -/** - * Dialog which returns a result of type {@link T}. - */ -public abstract class AbstractReturnDialogView extends AbstractView { - - public AbstractReturnDialogView() { - super(); - } - - public AbstractReturnDialogView(Function injectionContext) { - super(injectionContext); - } - - public abstract T showAndWait(); -} diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 9725b77933a..21c6e4ec424 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -15,25 +15,16 @@ 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; @@ -83,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; } } @@ -167,7 +158,6 @@ private static void openExternalFilePlatformIndependent(Optional fileConflictCheck = pdfCleanup.findExistingFile(linkedFile, entry); @@ -237,9 +238,9 @@ private void performRenameWithConflictCheck(Optional file, RenamePdfCleanu } } else { confirm = dialogService.showConfirmationDialogAndWait(Localization.lang("File exists"), - Localization.lang("'%0' exists. Overwrite file?", targetFileName), - Localization.lang("Overwrite"), - Localization.lang("Cancel")); + Localization.lang("'%0' exists. Overwrite file?", targetFileName), + Localization.lang("Overwrite"), + Localization.lang("Cancel")); if (confirm) { try { @@ -247,7 +248,7 @@ private void performRenameWithConflictCheck(Optional file, RenamePdfCleanu pdfCleanup.cleanupWithException(entry); } catch (IOException e) { dialogService.showErrorDialogAndWait(Localization.lang("Rename failed"), - Localization.lang("JabRef cannot access the file because it is being used by another process.")); + Localization.lang("JabRef cannot access the file because it is being used by another process.")); } } } @@ -292,9 +293,9 @@ public boolean delete(FileDirectoryPreferences prefs) { ButtonType removeFromEntry = new ButtonType(Localization.lang("Remove from entry"), ButtonData.YES); ButtonType deleteFromEntry = new ButtonType(Localization.lang("Delete from disk")); Optional buttonType = dialogService.showCustomButtonDialogAndWait(AlertType.INFORMATION, - Localization.lang("Delete '%0'", file.get().toString()), - Localization.lang("Delete the selected file permanently from disk, or just remove the file from the entry? Pressing Delete will delete the file permanently from disk."), - removeFromEntry, deleteFromEntry, ButtonType.CANCEL); + Localization.lang("Delete '%0'", file.get().toString()), + Localization.lang("Delete the selected file permanently from disk, or just remove the file from the entry? Pressing Delete will delete the file permanently from disk."), + removeFromEntry, deleteFromEntry, ButtonType.CANCEL); if (buttonType.isPresent()) { if (buttonType.get().equals(removeFromEntry)) { @@ -315,17 +316,17 @@ public boolean delete(FileDirectoryPreferences prefs) { } public void edit() { + LinkedFilesWrapper wrapper = new LinkedFilesWrapper(); wrapper.setLinkedFile(this.linkedFile); LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(wrapper); - if (dialog.showAndWait()) { - LinkedFilesEditDialogViewModel model = (LinkedFilesEditDialogViewModel) dialog.getController().get().getViewModel(); - LinkedFile editedFile = model.getNewLinkedFile(); - this.linkedFile.setLink(editedFile.getLink()); - this.linkedFile.setDescription(editedFile.getDescription()); - this.linkedFile.setFileType(editedFile.getFileType()); - } + Optional editedFile = dialog.showAndWait(); + editedFile.ifPresent(file -> { + this.linkedFile.setLink(file.getLink()); + this.linkedFile.setDescription(file.getDescription()); + this.linkedFile.setFileType(file.getFileType()); + }); } public void writeXMPMetadata() { @@ -373,11 +374,11 @@ public void download() { Path destination = targetDirectory.get().resolve(suggestedName); BackgroundTask downloadTask = new FileDownloadTask(urlDownload.getSource(), destination) - .onSuccess(event -> { - LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(fileDirectoryPreferences)); - linkedFile.setLink(newLinkedFile.getLink()); - linkedFile.setFileType(newLinkedFile.getFileType()); - }).onFailure(ex -> dialogService.showErrorDialogAndWait("Download failed", ex)); + .onSuccess(event -> { + LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(fileDirectoryPreferences)); + linkedFile.setLink(newLinkedFile.getLink()); + linkedFile.setFileType(newLinkedFile.getFileType()); + }).onFailure(ex -> dialogService.showErrorDialogAndWait("Download failed", ex)); downloadProgress.bind(downloadTask.workDonePercentageProperty()); taskExecutor.execute(downloadTask); diff --git a/src/main/java/org/jabref/gui/filelist/AttachFileAction.java b/src/main/java/org/jabref/gui/filelist/AttachFileAction.java index 6bd9005c72a..d26d041b963 100644 --- a/src/main/java/org/jabref/gui/filelist/AttachFileAction.java +++ b/src/main/java/org/jabref/gui/filelist/AttachFileAction.java @@ -34,8 +34,8 @@ public void execute() { BibEntry entry = panel.getSelectedEntries().get(0); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)) - .build(); + .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)) + .build(); dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> { LinkedFile newLinkedFile = new LinkedFile("", newFile.toString(), ""); @@ -44,20 +44,19 @@ public void execute() { wrapper.setLinkedFile(newLinkedFile); LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(wrapper); - boolean applyPressed = dialog.showAndWait(); - if (applyPressed) { - LinkedFilesEditDialogViewModel model = (LinkedFilesEditDialogViewModel) dialog.getController().get().getViewModel(); - newLinkedFile = model.getNewLinkedFile(); + Optional editedLinkeDfile = dialog.showAndWait(); + editedLinkeDfile.ifPresent(file -> { - Optional fieldChange = entry.addFile(newLinkedFile); + Optional fieldChange = entry.addFile(file); if (fieldChange.isPresent()) { UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE, - entry.getField(FieldName.FILE).orElse(null), fieldChange.get().getNewValue()); + entry.getField(FieldName.FILE).orElse(null), + fieldChange.get().getNewValue()); panel.getUndoManager().addEdit(ce); panel.markBaseChanged(); } - } + }); }); } } diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogController.java b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogController.java deleted file mode 100644 index 86067326bf6..00000000000 --- a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogController.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.jabref.gui.filelist; - -import javax.inject.Inject; - -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.ComboBox; -import javafx.scene.control.TextField; - -import org.jabref.gui.AbstractController; -import org.jabref.gui.DialogService; -import org.jabref.gui.StateManager; -import org.jabref.gui.externalfiletype.ExternalFileType; -import org.jabref.preferences.PreferencesService; - -public class LinkedFileEditDialogController extends AbstractController { - - - @FXML private TextField link; - @FXML private TextField description; - @FXML private ComboBox fileType; - - @Inject private DialogService dialogService; - @Inject private StateManager stateManager; - @Inject private LinkedFilesWrapper linkedFilesWrapper; - - @Inject private PreferencesService preferences; - - @FXML - private void initialize() { - viewModel = new LinkedFilesEditDialogViewModel(linkedFilesWrapper.getLinkedFile(), stateManager.getActiveDatabase().get(), dialogService, preferences); - fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty()); - description.textProperty().bindBidirectional(viewModel.descriptionProperty()); - link.textProperty().bindBidirectional(viewModel.linkProperty()); - fileType.valueProperty().bindBidirectional(viewModel.getSelectedExternalFileType()); - } - - @FXML - private void openBrowseDialog(ActionEvent event) { - viewModel.openBrowseDialog(); - link.requestFocus(); - } -} diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java index d5479dffd1d..0d3fb5ccc35 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java @@ -1,40 +1,66 @@ package org.jabref.gui.filelist; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; +import javax.inject.Inject; -import javafx.scene.control.Alert.AlertType; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; import javafx.scene.control.ButtonType; -import javafx.scene.control.DialogPane; +import javafx.scene.control.ComboBox; +import javafx.scene.control.TextField; -import org.jabref.gui.AbstractReturnDialogView; -import org.jabref.gui.FXDialog; -import org.jabref.logic.l10n.Localization; +import org.jabref.gui.DialogService; +import org.jabref.gui.StateManager; +import org.jabref.gui.externalfiletype.ExternalFileType; +import org.jabref.gui.util.BaseDialog; +import org.jabref.model.entry.LinkedFile; +import org.jabref.preferences.PreferencesService; -public class LinkedFileEditDialogView extends AbstractReturnDialogView { +import com.airhacks.afterburner.views.ViewLoader; - public LinkedFileEditDialogView(LinkedFilesWrapper linkedFile) { - super(createContext(linkedFile)); +public class LinkedFileEditDialogView extends BaseDialog { + + + @FXML private TextField link; + @FXML private TextField description; + @FXML private ComboBox fileType; + + @Inject private DialogService dialogService; + @Inject private StateManager stateManager; + + @Inject private PreferencesService preferences; + private final LinkedFilesEditDialogViewModel viewModel; + + public LinkedFileEditDialogView(LinkedFilesWrapper wrapper) { + + ViewLoader.view(this) + .load() + .setAsContent(this.getDialogPane()); + + this.getDialogPane().getButtonTypes().addAll(ButtonType.APPLY, ButtonType.CANCEL); + + viewModel = new LinkedFilesEditDialogViewModel(wrapper.getLinkedFile(), stateManager.getActiveDatabase().get(), dialogService, preferences); + + this.setResultConverter(button -> { + if (button == ButtonType.APPLY) { + return viewModel.getNewLinkedFile(); + } else { + return null; + } + }); } - private static Function createContext(LinkedFilesWrapper linkedFilesWrapper) { - Map context = new HashMap<>(); - context.put("linkedFilesWrapper", linkedFilesWrapper); - return context::get; + + @FXML + private void initialize() { + fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty()); + description.textProperty().bindBidirectional(viewModel.descriptionProperty()); + link.textProperty().bindBidirectional(viewModel.linkProperty()); + fileType.valueProperty().bindBidirectional(viewModel.getSelectedExternalFileType()); } - /** - * @return true if the user accepts the change - */ - @Override - public Boolean showAndWait() { - FXDialog dialog = new FXDialog(AlertType.INFORMATION, Localization.lang("Edit linked file")); - dialog.setDialogPane((DialogPane) this.getView()); - dialog.getButtonTypes().addAll(ButtonType.APPLY, ButtonType.CANCEL); - dialog.setResizable(true); - Optional buttonPressed = dialog.showAndWait(); - return buttonPressed.equals(Optional.of(ButtonType.APPLY)); + @FXML + private void openBrowseDialog(ActionEvent event) { + viewModel.openBrowseDialog(); + link.requestFocus(); } } diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index d53bed00041..620cfa2edeb 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -69,7 +69,6 @@ import org.jabref.gui.filelist.FileListEntry; import org.jabref.gui.filelist.FileListTableModel; import org.jabref.gui.filelist.LinkedFileEditDialogView; -import org.jabref.gui.filelist.LinkedFilesEditDialogViewModel; import org.jabref.gui.filelist.LinkedFilesWrapper; import org.jabref.gui.groups.GroupTreeNodeViewModel; import org.jabref.gui.groups.UndoableChangeEntriesOfGroup; @@ -178,7 +177,7 @@ public class ImportInspectionDialog extends JabRefDialog implements ImportInspec private final PreviewPanel preview; private final Map> groupAdditions = new HashMap<>(); private final JCheckBox autoGenerate = new JCheckBox(Localization.lang("Generate keys"), - Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_AFTER_INSPECTION)); + Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_AFTER_INSPECTION)); private final JLabel duplLabel = new JLabel(IconTheme.JabRefIcons.DUPLICATE.getSmallIcon()); private final JLabel fileLabel = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); private final JLabel urlLabel = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); @@ -208,7 +207,7 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam sortedList = new SortedList<>(entries); DefaultEventTableModel tableModelGl = (DefaultEventTableModel) GlazedListsSwing - .eventTableModelWithThreadProxyList(sortedList, new EntryTableFormat()); + .eventTableModelWithThreadProxyList(sortedList, new EntryTableFormat()); glTable = new EntryTable(tableModelGl); GeneralRenderer renderer = new GeneralRenderer(Color.white); glTable.setDefaultRenderer(JLabel.class, renderer); @@ -218,11 +217,11 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam glTable.getActionMap().put("delete", deleteListener); selectionModel = (DefaultEventSelectionModel) GlazedListsSwing - .eventSelectionModelWithThreadProxyList(sortedList); + .eventSelectionModelWithThreadProxyList(sortedList); glTable.setSelectionModel(selectionModel); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); comparatorChooser = TableComparatorChooser.install(glTable, sortedList, - AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); + AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); setupComparatorChooser(); glTable.addMouseListener(new TableClickListener()); @@ -318,7 +317,7 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam // Remember and default to last size: setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH), - Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT))); + Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT))); addWindowListener(new WindowAdapter() { @Override @@ -382,8 +381,8 @@ public void addEntries(Collection entriesToAdd) { // database (if // applicable) and against entries already in the table. if ((panel != null) && (DuplicateCheck - .containsDuplicate(panel.getDatabase(), entry, panel.getBibDatabaseContext().getMode()).isPresent() - || (internalDuplicate(this.entries, entry).isPresent()))) { + .containsDuplicate(panel.getDatabase(), entry, panel.getBibDatabaseContext().getMode()).isPresent() + || (internalDuplicate(this.entries, entry).isPresent()))) { entry.setGroupHit(true); SwingUtilities.invokeLater(() -> deselectAllDuplicates.setEnabled(true)); } @@ -459,7 +458,7 @@ private void generateKeyForEntry(BibEntry entry) { // Generate a unique key: new BibtexKeyGenerator(localMetaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), - database, Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry); + database, Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry); // Remove the entry from the database again, since we only added it in // order to // make sure the key was unique: @@ -501,7 +500,7 @@ private void generateKeys() { database.insertEntry(entry); new BibtexKeyGenerator(localMetaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), - database, Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry); + database, Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry); // Add the generated key to our list: -- TODO: Why?? keys.add(entry.getCiteKeyOptional()); } @@ -651,9 +650,9 @@ public void showMessage(String message) { */ public void showErrorMessage(String fetcherTitle, String localizedException) { showMessage(Localization.lang("Error while fetching from %0", fetcherTitle) + "\n" + - Localization.lang("Please try again later and/or check your network connection.") + "\n" + - localizedException, - Localization.lang("Search %0", fetcherTitle), JOptionPane.ERROR_MESSAGE); + Localization.lang("Please try again later and/or check your network connection.") + "\n" + + localizedException, + Localization.lang("Search %0", fetcherTitle), JOptionPane.ERROR_MESSAGE); } public JabRefFrame getFrame() { @@ -733,11 +732,11 @@ public void actionPerformed(ActionEvent event) { if (entry.isGroupHit()) { boolean continuePressed = frame.getDialogService().showConfirmationDialogWithOptOutAndWait(Localization.lang("Duplicates found"), - Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"), - Localization.lang("Continue"), - Localization.lang("Cancel"), - Localization.lang("Disable this confirmation dialog"), - optOut -> Globals.prefs.putBoolean(JabRefPreferences.WARN_ABOUT_DUPLICATES_IN_INSPECTION, !optOut)); + Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"), + Localization.lang("Continue"), + Localization.lang("Cancel"), + Localization.lang("Disable this confirmation dialog"), + optOut -> Globals.prefs.putBoolean(JabRefPreferences.WARN_ABOUT_DUPLICATES_IN_INSPECTION, !optOut)); if (!continuePressed) { return; @@ -836,9 +835,9 @@ private boolean addToGroups(NamedCompound ce, BibEntry entry, Set // immediately. boolean generateKeysPressed = frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Add to group"), - Localization.lang("Cannot add entries to group without generating keys. Generate keys now?"), - Localization.lang("Generate keys"), - Localization.lang("Cancel")); + Localization.lang("Cannot add entries to group without generating keys. Generate keys now?"), + Localization.lang("Generate keys"), + Localization.lang("Cancel")); if (generateKeysPressed) { generateKeys(); @@ -856,7 +855,7 @@ private boolean addToGroups(NamedCompound ce, BibEntry entry, Set List undo = entryChanger.add(Collections.singletonList(entry)); if (!undo.isEmpty()) { ce.addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(new GroupTreeNodeViewModel(node), - undo)); + undo)); } } } @@ -973,7 +972,7 @@ public void mouseClicked(MouseEvent e) { } FileListEntry fl = tableModel.getEntry(0); (new ExternalFileMenuItem(frame, "", fl.getLink(), null, panel.getBibDatabaseContext(), - fl.getType())).actionPerformed(null); + fl.getType())).actionPerformed(null); } } else { // Must be URL_COL openExternalLink(FieldName.URL, e); @@ -1031,7 +1030,7 @@ private void showFileFieldMenu(MouseEvent e) { description = flEntry.getLink(); } menu.add(new ExternalFileMenuItem(panel.frame(), description, flEntry.getLink(), - flEntry.getType().get().getIcon().getSmallIcon(), panel.getBibDatabaseContext(), flEntry.getType())); + flEntry.getType().get().getIcon().getSmallIcon(), panel.getBibDatabaseContext(), flEntry.getType())); count++; } if (count == 0) { @@ -1085,12 +1084,12 @@ public void mousePressed(MouseEvent e) { if ((col == DUPL_COL) && (glTable.getValueAt(row, col) != null)) { BibEntry first = sortedList.get(row); Optional other = DuplicateCheck.containsDuplicate(panel.getDatabase(), first, - panel.getBibDatabaseContext().getMode()); + panel.getBibDatabaseContext().getMode()); if (other.isPresent()) { // This will be true if the duplicate is in the existing // database. DuplicateResolverDialog diag = new DuplicateResolverDialog(ImportInspectionDialog.this, other.get(), - first, DuplicateResolverDialog.DuplicateResolverType.INSPECTION); + first, DuplicateResolverDialog.DuplicateResolverType.INSPECTION); diag.setLocationRelativeTo(ImportInspectionDialog.this); diag.setVisible(true); ImportInspectionDialog.this.toFront(); @@ -1151,7 +1150,7 @@ public void mousePressed(MouseEvent e) { other = internalDuplicate(entries, first); if (other.isPresent()) { DuplicateResolverDialog diag = new DuplicateResolverDialog(ImportInspectionDialog.this, first, - other.get(), DuplicateResolverDialog.DuplicateResolverType.DUPLICATE_SEARCH); + other.get(), DuplicateResolverDialog.DuplicateResolverType.DUPLICATE_SEARCH); diag.setLocationRelativeTo(ImportInspectionDialog.this); diag.setVisible(true); ImportInspectionDialog.this.toFront(); @@ -1225,9 +1224,9 @@ public void actionPerformed(ActionEvent actionEvent) { if (!entry.getCiteKeyOptional().isPresent()) { boolean generateKeyPressed = frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Download file"), - Localization.lang("This entry has no BibTeX key. Generate key now?"), - Localization.lang("Generate key"), - Localization.lang("Cancel")); + Localization.lang("This entry has no BibTeX key. Generate key now?"), + Localization.lang("Generate key"), + Localization.lang("Cancel")); if (generateKeyPressed) { generateKeyForEntry(entry); @@ -1270,9 +1269,9 @@ public void actionPerformed(ActionEvent actionEvent) { if (!entry.hasCiteKey()) { boolean generateKeyPressed = frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Download file"), - Localization.lang("This entry has no BibTeX key. Generate key now?"), - Localization.lang("Generate key"), - Localization.lang("Cancel")); + Localization.lang("This entry has no BibTeX key. Generate key now?"), + Localization.lang("Generate key"), + Localization.lang("Cancel")); if (generateKeyPressed) { generateKeyForEntry(entry); @@ -1286,18 +1285,18 @@ public void actionPerformed(ActionEvent actionEvent) { // links: JDialog diag = new JDialog(ImportInspectionDialog.this, true); JabRefExecutorService.INSTANCE - .execute(AutoSetLinks.autoSetLinks(entry, bibDatabaseContext, e -> { - if (e.getID() > 0) { - - entries.getReadWriteLock().writeLock().lock(); - try { - entry.setField(FieldName.FILE, localModel.getStringRepresentation()); - } finally { - entries.getReadWriteLock().writeLock().unlock(); - } - glTable.repaint(); - } - }, diag)); + .execute(AutoSetLinks.autoSetLinks(entry, bibDatabaseContext, e -> { + if (e.getID() > 0) { + + entries.getReadWriteLock().writeLock().lock(); + try { + entry.setField(FieldName.FILE, localModel.getStringRepresentation()); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } + glTable.repaint(); + } + }, diag)); } } @@ -1323,13 +1322,8 @@ public void actionPerformed(ActionEvent actionEvent) { wrapper.setLinkedFile(linkedFile); LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(wrapper); - boolean applyPressed = DefaultTaskExecutor.runInJavaFXThread(() -> dialog.showAndWait()); - if (applyPressed) { - LinkedFilesEditDialogViewModel model = (LinkedFilesEditDialogViewModel) dialog.getController().get().getViewModel(); - linkedFile = model.getNewLinkedFile(); - entry.addFile(linkedFile); - } - + Optional editedLinkedFile = DefaultTaskExecutor.runInJavaFXThread(() -> dialog.showAndWait()); + editedLinkedFile.ifPresent(file -> entry.addFile(linkedFile)); } @Override diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java index 5723c35c3f0..b3dd612cd62 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java @@ -41,7 +41,6 @@ import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; -import org.jabref.gui.externalfiletype.UnknownExternalFileType; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.util.DefaultTaskExecutor; @@ -53,7 +52,6 @@ import org.jabref.logic.openoffice.StyleLoader; import org.jabref.logic.util.FileType; import org.jabref.logic.util.TestEntry; -import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; @@ -146,9 +144,10 @@ private void init() { FormBuilder builder = FormBuilder.create(); builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref", - "pref, 4dlu, 100dlu:grow, 4dlu, pref, 4dlu, fill:100dlu")); - builder.add(Localization.lang("Select one of the available styles or add a style file from disk.")).xyw(1, 1, - 5); + "pref, 4dlu, 100dlu:grow, 4dlu, pref, 4dlu, fill:100dlu")); + builder.add(Localization.lang("Select one of the available styles or add a style file from disk.")).xyw(1, + 1, + 5); builder.add(new JScrollPane(table)).xyw(1, 3, 5); builder.add(addButton).xy(3, 5); builder.add(removeButton).xy(5, 5); @@ -164,7 +163,7 @@ private void init() { public void actionPerformed(ActionEvent event) { if ((table.getRowCount() == 0) || (table.getSelectedRowCount() == 0)) { frame.getDialogService().showErrorDialogAndWait(Localization.lang("Style selection"), - Localization.lang("You must select a valid style file.")); + Localization.lang("You must select a valid style file.")); return; } okPressed = true; @@ -201,7 +200,7 @@ public void actionPerformed(ActionEvent event) { diag.pack(); WindowLocation pw = new WindowLocation(diag, JabRefPreferences.STYLES_POS_X, JabRefPreferences.STYLES_POS_Y, - JabRefPreferences.STYLES_SIZE_X, JabRefPreferences.STYLES_SIZE_Y); + JabRefPreferences.STYLES_SIZE_X, JabRefPreferences.STYLES_SIZE_Y); pw.displayWindowAtStoredLocation(); } @@ -210,7 +209,7 @@ private void setupTable() { EventList sortedStyles = new SortedList<>(styles); tableModel = (DefaultEventTableModel) GlazedListsSwing - .eventTableModelWithThreadProxyList(sortedStyles, new StyleTableFormat()); + .eventTableModelWithThreadProxyList(sortedStyles, new StyleTableFormat()); table = new JTable(tableModel); TableColumnModel cm = table.getColumnModel(); cm.getColumn(0).setPreferredWidth(100); @@ -218,7 +217,7 @@ private void setupTable() { cm.getColumn(2).setPreferredWidth(80); selectionModel = (DefaultEventSelectionModel) GlazedListsSwing - .eventSelectionModelWithThreadProxyList(sortedStyles); + .eventSelectionModelWithThreadProxyList(sortedStyles); table.setSelectionModel(selectionModel); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseAdapter() { @@ -252,12 +251,9 @@ private void setupPopupMenu() { Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("jstyle"); String link = style.getPath(); try { - if (type.isPresent()) { - JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), link, type); - } else { - JabRefDesktop.openExternalFileUnknown(frame, new BibEntry(), new BibDatabaseContext(), link, - new UnknownExternalFileType("jstyle")); - } + + JabRefDesktop.openExternalFileAnyFormat(frame.getCurrentBasePanel().getDatabaseContext(), link, type); + } catch (IOException e) { LOGGER.warn("Problem open style file editor", e); } @@ -270,9 +266,9 @@ private void setupPopupMenu() { removeAction = actionEvent -> getSelectedStyle().ifPresent(style -> { if (!style.isFromResource() && frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Remove style"), - Localization.lang("Are you sure you want to remove the style?"), - Localization.lang("Remove style"), - Localization.lang("Cancel"))) { + Localization.lang("Are you sure you want to remove the style?"), + Localization.lang("Remove style"), + Localization.lang("Cancel"))) { if (!loader.removeStyle(style)) { LOGGER.info("Problem removing style"); } @@ -470,14 +466,14 @@ public AddFileDialog() { JButton browse = new JButton(Localization.lang("Browse")); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .addExtensionFilter(FileType.JSTYLE) - .withDefaultExtension(FileType.JSTYLE) - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)) - .build(); + .addExtensionFilter(FileType.JSTYLE) + .withDefaultExtension(FileType.JSTYLE) + .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)) + .build(); browse.addActionListener(e -> { Optional file = DefaultTaskExecutor - .runInJavaFXThread(() -> frame.getDialogService().showFileOpenDialog(fileDialogConfiguration)); + .runInJavaFXThread(() -> frame.getDialogService().showFileOpenDialog(fileDialogConfiguration)); file.ifPresent(f -> newFile.setText(f.toAbsolutePath().toString())); }); @@ -517,8 +513,8 @@ public void actionPerformed(ActionEvent e) { // Key bindings: bb.getPanel() - .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) - .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); + .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) + .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); bb.getPanel().getActionMap().put("close", cancelAction); pack(); setLocationRelativeTo(diag); diff --git a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java index 8575b610e45..4e129975fb0 100644 --- a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java +++ b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java @@ -35,13 +35,11 @@ import javax.swing.table.TableColumnModel; import org.jabref.Globals; -import org.jabref.gui.DialogService; import org.jabref.gui.JabRefDialog; import org.jabref.gui.JabRefFrame; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; -import org.jabref.gui.externalfiletype.UnknownExternalFileType; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.util.DefaultTaskExecutor; @@ -52,7 +50,6 @@ import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.logic.util.FileType; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; @@ -235,12 +232,8 @@ private void setupPopupMenu() { // Fall back to ".txt" Optional txtType = ExternalFileTypes.getInstance() .getExternalFileTypeByExt("txt"); - if (txtType.isPresent()) { - JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), fileName, txtType); - } else { - JabRefDesktop.openExternalFileUnknown(frame, new BibEntry(), new BibDatabaseContext(), fileName, - new UnknownExternalFileType("terms")); - } + JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), fileName, type); + } } catch (IOException e) { LOGGER.warn("Problem open protected terms file editor", e); @@ -433,11 +426,9 @@ public AddFileDialog() { .addExtensionFilter(FileType.TERMS) .withDefaultExtension(FileType.TERMS) .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); - DialogService ds = frame.getDialogService(); browse.addActionListener(e -> { - Optional file = DefaultTaskExecutor - .runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration)); + Optional file = DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().showFileOpenDialog(fileDialogConfiguration)); file.ifPresent(f -> newFile.setText(f.toAbsolutePath().toString())); }); diff --git a/src/main/resources/org/jabref/gui/filelist/LinkedFileEditDialog.fxml b/src/main/resources/org/jabref/gui/filelist/LinkedFileEditDialog.fxml index 4f4f9d3f057..930f08a1030 100644 --- a/src/main/resources/org/jabref/gui/filelist/LinkedFileEditDialog.fxml +++ b/src/main/resources/org/jabref/gui/filelist/LinkedFileEditDialog.fxml @@ -10,7 +10,7 @@ - + From e1f85fd651ef8d16da0cdf7554a15bdda42cff27 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 24 Mar 2018 17:13:40 +0100 Subject: [PATCH 26/36] fix empty lines --- .../java/org/jabref/gui/filelist/LinkedFileEditDialogView.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java index 0d3fb5ccc35..8e2023bad7e 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java @@ -19,7 +19,6 @@ public class LinkedFileEditDialogView extends BaseDialog { - @FXML private TextField link; @FXML private TextField description; @FXML private ComboBox fileType; @@ -28,6 +27,7 @@ public class LinkedFileEditDialogView extends BaseDialog { @Inject private StateManager stateManager; @Inject private PreferencesService preferences; + private final LinkedFilesEditDialogViewModel viewModel; public LinkedFileEditDialogView(LinkedFilesWrapper wrapper) { @@ -49,7 +49,6 @@ public LinkedFileEditDialogView(LinkedFilesWrapper wrapper) { }); } - @FXML private void initialize() { fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty()); From 8cb812d4b8f21014d18792a381311636127189d7 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 24 Mar 2018 17:21:56 +0100 Subject: [PATCH 27/36] fix checkstyle --- src/main/java/org/jabref/gui/help/AboutDialogView.java | 3 ++- src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/help/AboutDialogView.java b/src/main/java/org/jabref/gui/help/AboutDialogView.java index 94f20f2adc9..ac8d286ece4 100644 --- a/src/main/java/org/jabref/gui/help/AboutDialogView.java +++ b/src/main/java/org/jabref/gui/help/AboutDialogView.java @@ -21,12 +21,13 @@ public class AboutDialogView extends BaseDialog { @FXML private ButtonType copyVersionButton; + @FXML private TextArea textAreaVersions; @FXML protected ImageView iconImage; + @Inject private DialogService dialogService; @Inject private ClipBoardManager clipBoardManager; @Inject private BuildInfo buildInfo; - @FXML private TextArea textAreaVersions; private AboutDialogViewModel viewModel; public AboutDialogView() { diff --git a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java index 93cc9196605..7e6a43ecc26 100644 --- a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java @@ -256,8 +256,6 @@ public void setValues() { } } - - class ExportAction extends AbstractAction { public ExportAction() { @@ -272,8 +270,7 @@ public void actionPerformed(ActionEvent e) { .withDefaultExtension(FileType.XML) .withInitialDirectory(prefs.get(JabRefPreferences.WORKING_DIRECTORY)) .build(); - Optional path = DefaultTaskExecutor - .runInJavaFXThread(() -> dialogService.showFileSaveDialog(fileDialogConfiguration)); + Optional path = DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showFileSaveDialog(fileDialogConfiguration)); path.ifPresent(exportFile -> { try { From 0be175c96b24020020a1c4961bbc3fc91a0d61c2 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 24 Mar 2018 19:31:53 +0100 Subject: [PATCH 28/36] Fix viewModel NPE in copyFiles Action and linkedfilesEditDialog --- .../java/org/jabref/gui/actions/CopyFilesAction.java | 2 +- .../org/jabref/gui/copyfiles/CopyFilesDialogView.java | 3 ++- .../jabref/gui/filelist/LinkedFileEditDialogView.java | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/actions/CopyFilesAction.java b/src/main/java/org/jabref/gui/actions/CopyFilesAction.java index 39ea9b34d4c..5efa6415506 100644 --- a/src/main/java/org/jabref/gui/actions/CopyFilesAction.java +++ b/src/main/java/org/jabref/gui/actions/CopyFilesAction.java @@ -48,7 +48,7 @@ private void showDialog(List data) { return; } CopyFilesDialogView dialog = new CopyFilesDialogView(databaseContext, new CopyFilesResultListDependency(data)); - dialog.show(); + dialog.showAndWait(); } @Override diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java b/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java index cd4b33832ea..672e4100e4e 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java @@ -28,11 +28,12 @@ public CopyFilesDialogView(BibDatabaseContext bibDatabaseContext, CopyFilesResul this.setTitle(Localization.lang("Result")); this.setResizable(true); + viewModel = new CopyFilesDialogViewModel(results); + ViewLoader.view(this) .load() .setAsContent(this.getDialogPane()); - viewModel = new CopyFilesDialogViewModel(results); } @FXML diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java index 8e2023bad7e..ff670ba6891 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java @@ -28,9 +28,12 @@ public class LinkedFileEditDialogView extends BaseDialog { @Inject private PreferencesService preferences; - private final LinkedFilesEditDialogViewModel viewModel; + private LinkedFilesEditDialogViewModel viewModel; + + private final LinkedFile linkedFile; public LinkedFileEditDialogView(LinkedFilesWrapper wrapper) { + this.linkedFile = wrapper.getLinkedFile(); ViewLoader.view(this) .load() @@ -38,8 +41,6 @@ public LinkedFileEditDialogView(LinkedFilesWrapper wrapper) { this.getDialogPane().getButtonTypes().addAll(ButtonType.APPLY, ButtonType.CANCEL); - viewModel = new LinkedFilesEditDialogViewModel(wrapper.getLinkedFile(), stateManager.getActiveDatabase().get(), dialogService, preferences); - this.setResultConverter(button -> { if (button == ButtonType.APPLY) { return viewModel.getNewLinkedFile(); @@ -51,6 +52,8 @@ public LinkedFileEditDialogView(LinkedFilesWrapper wrapper) { @FXML private void initialize() { + + viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences); fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty()); description.textProperty().bindBidirectional(viewModel.descriptionProperty()); link.textProperty().bindBidirectional(viewModel.linkProperty()); From 45697c4eaf073fb5c44122c0d0391778dac904a2 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 24 Mar 2018 19:37:20 +0100 Subject: [PATCH 29/36] Add close button in copy linked files --- .../java/org/jabref/gui/copyfiles/CopyFilesDialog.fxml | 7 ------- .../java/org/jabref/gui/copyfiles/CopyFilesDialogView.java | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialog.fxml b/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialog.fxml index 671b569acf3..6e7bb95f5f2 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialog.fxml +++ b/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialog.fxml @@ -23,13 +23,6 @@ - - - - - + diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java index 278d2cbf9ff..b592295e02a 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java @@ -11,6 +11,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.externalfiletype.ExternalFileType; +import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.util.BaseDialog; import org.jabref.model.entry.LinkedFile; import org.jabref.preferences.PreferencesService; @@ -31,10 +32,12 @@ public class LinkedFileEditDialogView extends BaseDialog { private LinkedFilesEditDialogViewModel viewModel; private final LinkedFile linkedFile; + private ExternalFileTypes externalFileTypes; - public LinkedFileEditDialogView(LinkedFilesWrapper wrapper) { - this.linkedFile = wrapper.getLinkedFile(); + public LinkedFileEditDialogView(LinkedFile linkedFile) { + this.linkedFile = linkedFile; + this.externalFileTypes = ExternalFileTypes.getInstance(); ViewLoader.view(this) .load() .setAsContent(this.getDialogPane()); @@ -53,7 +56,7 @@ public LinkedFileEditDialogView(LinkedFilesWrapper wrapper) { @FXML private void initialize() { - viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences); + viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences, externalFileTypes); fileType.itemsProperty().bindBidirectional(viewModel.externalFileType()); description.textProperty().bindBidirectional(viewModel.description()); link.textProperty().bindBidirectional(viewModel.link()); diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java index 47294315625..3114e7a4c63 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java @@ -24,39 +24,40 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.LinkedFile; import org.jabref.model.util.FileHelper; -import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreferencesService; public class LinkedFilesEditDialogViewModel extends AbstractViewModel { private static final Pattern REMOTE_LINK_PATTERN = Pattern.compile("[a-z]+://.*"); - private final StringProperty linkProperty = new SimpleStringProperty(""); - private final StringProperty descriptionProperty = new SimpleStringProperty(""); - private final ListProperty externalfilesTypes = new SimpleListProperty<>(FXCollections.emptyObservableList()); + private final StringProperty link = new SimpleStringProperty(""); + private final StringProperty description = new SimpleStringProperty(""); + private final ListProperty allExternalFileTypes = new SimpleListProperty<>(FXCollections.emptyObservableList()); private final ObjectProperty selectedExternalFileType = new SimpleObjectProperty<>(); private final BibDatabaseContext database; private final DialogService dialogService; private final PreferencesService preferences; + private final ExternalFileTypes externalFileTypes; - public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext database, DialogService dialogService, PreferencesService preferences2) { + public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext database, DialogService dialogService, PreferencesService preferences, ExternalFileTypes externalFileTypes) { this.database = database; this.dialogService = dialogService; - this.preferences = preferences2; - externalfilesTypes.set(FXCollections.observableArrayList(ExternalFileTypes.getInstance().getExternalFileTypeSelection())); + this.preferences = preferences; + this.externalFileTypes = externalFileTypes; + allExternalFileTypes.set(FXCollections.observableArrayList(externalFileTypes.getExternalFileTypeSelection())); setValues(linkedFile); } private void checkExtension() { - if (!linkProperty.getValueSafe().isEmpty()) { + if (!link.getValueSafe().isEmpty()) { // Check if this looks like a remote link: - if (REMOTE_LINK_PATTERN.matcher(linkProperty.get()).matches()) { - ExternalFileTypes.getInstance().getExternalFileTypeByExt("html").ifPresent(selectedExternalFileType::setValue); + if (REMOTE_LINK_PATTERN.matcher(link.get()).matches()) { + externalFileTypes.getExternalFileTypeByExt("html").ifPresent(selectedExternalFileType::setValue); } // Try to guess the file type: - String theLink = linkProperty.get().trim(); - ExternalFileTypes.getInstance().getExternalFileTypeForName(theLink).ifPresent(selectedExternalFileType::setValue); + String theLink = link.get().trim(); + externalFileTypes.getExternalFileTypeForName(theLink).ifPresent(selectedExternalFileType::setValue); } } @@ -65,7 +66,7 @@ public void openBrowseDialog() { Optional file = FileHelper.expandFilename(database, fileText, preferences.getFileDirectoryPreferences()); - Path workingDir = file.orElse(Paths.get(preferences.get(JabRefPreferences.WORKING_DIRECTORY))); + Path workingDir = file.orElse(preferences.getWorkingDir()); String fileName = Paths.get(fileText).getFileName().toString(); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() @@ -75,7 +76,7 @@ public void openBrowseDialog() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> { // Store the directory for next time: - preferences.put(JabRefPreferences.WORKING_DIRECTORY, path.toString()); + preferences.setWorkingDir(path); // If the file is below the file directory, make the path relative: List fileDirectories = database.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences()); @@ -86,32 +87,31 @@ public void openBrowseDialog() { }); } - // - public void setValues(LinkedFile entry) { - descriptionProperty.set(entry.getDescription()); - linkProperty.set(entry.getLink()); + public void setValues(LinkedFile linkedFile) { + description.set(linkedFile.getDescription()); + link.set(linkedFile.getLink()); selectedExternalFileType.setValue(null); // See what is a reasonable selection for the type combobox: - Optional fileType = ExternalFileTypes.getInstance().fromLinkedFile(entry, false); + Optional fileType = externalFileTypes.fromLinkedFile(linkedFile, false); if (fileType.isPresent() && !(fileType.get() instanceof UnknownExternalFileType)) { selectedExternalFileType.setValue(fileType.get()); - } else if ((entry.getLink() != null) && (!entry.getLink().isEmpty())) { + } else if ((linkedFile.getLink() != null) && (!linkedFile.getLink().isEmpty())) { checkExtension(); } } public StringProperty link() { - return linkProperty; + return link; } public StringProperty description() { - return descriptionProperty; + return description; } public ListProperty externalFileType() { - return externalfilesTypes; + return allExternalFileTypes; } public ObjectProperty selectedExternalFileType() { @@ -119,7 +119,7 @@ public ObjectProperty selectedExternalFileType() { } public LinkedFile getNewLinkedFile() { - return new LinkedFile(descriptionProperty.getValue(), linkProperty.getValue(), selectedExternalFileType.getValue().toString()); + return new LinkedFile(description.getValue(), link.getValue(), selectedExternalFileType.getValue().toString()); } diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesWrapper.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesWrapper.java deleted file mode 100644 index d71ce16d08d..00000000000 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesWrapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jabref.gui.filelist; - -import org.jabref.model.entry.LinkedFile; - -/** - * Workaround to inject {@link LinkedFile} into javafx controller - */ -public class LinkedFilesWrapper { - - private LinkedFile linkedFile; - - public LinkedFile getLinkedFile() { - return linkedFile; - } - - public void setLinkedFile(LinkedFile linkedFile) { - this.linkedFile = linkedFile; - } -} diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index 620cfa2edeb..c9730d463ff 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -69,7 +69,6 @@ import org.jabref.gui.filelist.FileListEntry; import org.jabref.gui.filelist.FileListTableModel; import org.jabref.gui.filelist.LinkedFileEditDialogView; -import org.jabref.gui.filelist.LinkedFilesWrapper; import org.jabref.gui.groups.GroupTreeNodeViewModel; import org.jabref.gui.groups.UndoableChangeEntriesOfGroup; import org.jabref.gui.help.HelpAction; @@ -1318,9 +1317,7 @@ public void actionPerformed(ActionEvent actionEvent) { entry = selectionModel.getSelected().get(0); LinkedFile linkedFile = new LinkedFile("", "", ""); - LinkedFilesWrapper wrapper = new LinkedFilesWrapper(); - wrapper.setLinkedFile(linkedFile); - LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(wrapper); + LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile); Optional editedLinkedFile = DefaultTaskExecutor.runInJavaFXThread(() -> dialog.showAndWait()); editedLinkedFile.ifPresent(file -> entry.addFile(linkedFile)); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index f4fda131aee..0a7246e7436 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -14,6 +14,8 @@ import java.net.UnknownHostException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -1373,6 +1375,7 @@ public void storeFileHistory(FileHistory history) { } } + @Override public FileDirectoryPreferences getFileDirectoryPreferences() { List fields = Arrays.asList(FieldName.FILE, FieldName.PDF, FieldName.PS); Map fieldDirectories = new HashMap<>(); @@ -1742,4 +1745,15 @@ public MainTablePreferences getMainTablePreferences() { getColumnPreferences(), getBoolean(AUTO_RESIZE_MODE)); } + + @Override + public Path getWorkingDir() { + return Paths.get(get(WORKING_DIRECTORY)); + } + + @Override + public void setWorkingDir(Path dir) { + put(WORKING_DIRECTORY, dir.toString()); + + } } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 2759b328528..1245e404ba7 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -1,5 +1,7 @@ package org.jabref.preferences; +import java.nio.file.Path; + import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.model.metadata.FileDirectoryPreferences; @@ -15,7 +17,8 @@ public interface PreferencesService { FileDirectoryPreferences getFileDirectoryPreferences(); - String get(String key); + Path getWorkingDir(); + + void setWorkingDir(Path dir); - void put(String key, String value); } From 95fdd2d398e846e247e5cb8b11a2c6253be9177a Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 25 Mar 2018 14:07:43 +0200 Subject: [PATCH 33/36] remove close method Add ok button to dialog pane --- .../org/jabref/gui/copyfiles/CopyFilesDialogView.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java b/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java index ff8fefd163b..bbf813c4c14 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java @@ -1,6 +1,5 @@ package org.jabref.gui.copyfiles; -import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.ButtonType; import javafx.scene.control.TableColumn; @@ -29,19 +28,13 @@ public CopyFilesDialogView(BibDatabaseContext bibDatabaseContext, CopyFilesResul this.setTitle(Localization.lang("Result")); this.setResizable(true); - this.getDialogPane().getButtonTypes().addAll(ButtonType.CLOSE); + this.getDialogPane().getButtonTypes().addAll(ButtonType.OK); viewModel = new CopyFilesDialogViewModel(results); ViewLoader.view(this) .load() .setAsContent(this.getDialogPane()); - - } - - @FXML - private void close(@SuppressWarnings("unused") ActionEvent event) { - close(); } @FXML From bb22a5eb828a437be7a7a75e71614e2568c967de Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 25 Mar 2018 14:12:01 +0200 Subject: [PATCH 34/36] change some odd looking assigments --- .../jabref/gui/filelist/LinkedFilesEditDialogViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java index 3114e7a4c63..006cb9567ca 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java @@ -62,7 +62,7 @@ private void checkExtension() { } public void openBrowseDialog() { - String fileText = link().get(); + String fileText = link.get(); Optional file = FileHelper.expandFilename(database, fileText, preferences.getFileDirectoryPreferences()); @@ -82,7 +82,7 @@ public void openBrowseDialog() { List fileDirectories = database.getFileDirectoriesAsPaths(preferences.getFileDirectoryPreferences()); path = FileUtil.shortenFileName(path, fileDirectories); - link().set(path.toString()); + link.set(path.toString()); checkExtension(); }); } From 035d9e2d6ac273ae474c17498cd0790098603cc2 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 25 Mar 2018 17:55:18 +0200 Subject: [PATCH 35/36] renaming --- .../gui/filelist/LinkedFileEditDialogView.java | 8 ++++---- .../LinkedFilesEditDialogViewModel.java | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java index b592295e02a..3833f493437 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFileEditDialogView.java @@ -57,10 +57,10 @@ public LinkedFileEditDialogView(LinkedFile linkedFile) { private void initialize() { viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences, externalFileTypes); - fileType.itemsProperty().bindBidirectional(viewModel.externalFileType()); - description.textProperty().bindBidirectional(viewModel.description()); - link.textProperty().bindBidirectional(viewModel.link()); - fileType.valueProperty().bindBidirectional(viewModel.selectedExternalFileType()); + fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty()); + description.textProperty().bindBidirectional(viewModel.descriptionProperty()); + link.textProperty().bindBidirectional(viewModel.linkProperty()); + fileType.valueProperty().bindBidirectional(viewModel.selectedExternalFileTypeProperty()); } @FXML diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java index 006cb9567ca..71dae7d7cf8 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java @@ -47,16 +47,16 @@ public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext setValues(linkedFile); } - private void checkExtension() { - if (!link.getValueSafe().isEmpty()) { + private void setExternalFileTypeByExtension(String link) { + if (!link.isEmpty()) { // Check if this looks like a remote link: - if (REMOTE_LINK_PATTERN.matcher(link.get()).matches()) { + if (REMOTE_LINK_PATTERN.matcher(link).matches()) { externalFileTypes.getExternalFileTypeByExt("html").ifPresent(selectedExternalFileType::setValue); } // Try to guess the file type: - String theLink = link.get().trim(); + String theLink = link.trim(); externalFileTypes.getExternalFileTypeForName(theLink).ifPresent(selectedExternalFileType::setValue); } } @@ -83,7 +83,7 @@ public void openBrowseDialog() { path = FileUtil.shortenFileName(path, fileDirectories); link.set(path.toString()); - checkExtension(); + setExternalFileTypeByExtension(link.getValueSafe()); }); } @@ -102,19 +102,19 @@ public void setValues(LinkedFile linkedFile) { } } - public StringProperty link() { + public StringProperty linkProperty() { return link; } - public StringProperty description() { + public StringProperty descriptionProperty() { return description; } - public ListProperty externalFileType() { + public ListProperty externalFileTypeProperty() { return allExternalFileTypes; } - public ObjectProperty selectedExternalFileType() { + public ObjectProperty selectedExternalFileTypeProperty() { return selectedExternalFileType; } From ce3d5e65df0de6b8fc49e06b120d912aa3a8bdf6 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 25 Mar 2018 17:56:25 +0200 Subject: [PATCH 36/36] forgotten rename --- .../org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java index 71dae7d7cf8..5a24ba38822 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java @@ -98,7 +98,7 @@ public void setValues(LinkedFile linkedFile) { if (fileType.isPresent() && !(fileType.get() instanceof UnknownExternalFileType)) { selectedExternalFileType.setValue(fileType.get()); } else if ((linkedFile.getLink() != null) && (!linkedFile.getLink().isEmpty())) { - checkExtension(); + setExternalFileTypeByExtension(linkedFile.getLink()); } }