Search in sources :

Example 6 with FileDialogConfiguration

use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.

the class FileLinksUpgradeWarning method performAction.

/**
     * This method presents a dialog box explaining and offering to make the
     * changes. If the user confirms, the changes are performed.
     * @param panel
     * @param parserResult
     */
@Override
public void performAction(BasePanel panel, ParserResult parserResult) {
    if (!isThereSomethingToBeDone()) {
        // Nothing to do, just return.
        return;
    }
    JCheckBox changeSettings = new JCheckBox(Localization.lang("Change table column and General fields settings to use the new feature"), offerChangeSettings);
    JCheckBox changeDatabase = new JCheckBox(Localization.lang("Upgrade old external file links to use the new feature"), offerChangeDatabase);
    JCheckBox setFileDir = new JCheckBox(Localization.lang("Set main external file directory") + ":", offerSetFileDir);
    JTextField fileDir = new JTextField(30);
    JCheckBox doNotShowDialog = new JCheckBox(Localization.lang("Do not show these options in the future"), false);
    JPanel message = new JPanel();
    FormBuilder formBuilder = FormBuilder.create().layout(new FormLayout("left:pref", "p"));
    // Keep the formatting of these lines. Otherwise, strings have to be translated again.
    // See updated JabRef_en.properties modifications by python syncLang.py -s -u
    int row = 1;
    formBuilder.add(new JLabel("<html>" + Localization.lang("This library uses outdated file links.") + "<br><br>" + Localization.lang("JabRef no longer supports 'ps' or 'pdf' fields.<br>File links are now stored in the 'file' field and files are stored in an external file directory.<br>To make use of this feature, JabRef needs to upgrade file links.<br><br>") + "<p>" + Localization.lang("Do you want JabRef to do the following operations?") + "</html>")).xy(1, row);
    if (offerChangeSettings) {
        formBuilder.appendRows("2dlu, p");
        row += 2;
        formBuilder.add(changeSettings).xy(1, row);
    }
    if (offerChangeDatabase) {
        formBuilder.appendRows("2dlu, p");
        row += 2;
        formBuilder.add(changeDatabase).xy(1, row);
    }
    if (offerSetFileDir) {
        if (Globals.prefs.hasKey(FieldName.PDF + FileDirectoryPreferences.DIR_SUFFIX)) {
            fileDir.setText(Globals.prefs.get(FieldName.PDF + FileDirectoryPreferences.DIR_SUFFIX));
        } else {
            fileDir.setText(Globals.prefs.get(FieldName.PS + FileDirectoryPreferences.DIR_SUFFIX));
        }
        JPanel builderPanel = new JPanel();
        builderPanel.add(setFileDir);
        builderPanel.add(fileDir);
        JButton browse = new JButton(Localization.lang("Browse"));
        FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
        DialogService ds = new FXDialogService();
        browse.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration).ifPresent(f -> fileDir.setText(f.toAbsolutePath().toString()))));
        builderPanel.add(browse);
        formBuilder.appendRows("2dlu, p");
        row += 2;
        formBuilder.add(builderPanel).xy(1, row);
    }
    formBuilder.appendRows("6dlu, p");
    formBuilder.add(doNotShowDialog).xy(1, row + 2);
    message.add(formBuilder.build());
    int answer = JOptionPane.showConfirmDialog(panel.frame(), message, Localization.lang("Upgrade file"), JOptionPane.YES_NO_OPTION);
    if (doNotShowDialog.isSelected()) {
        Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false);
    }
    if (answer == JOptionPane.YES_OPTION) {
        makeChanges(panel, parserResult, changeSettings.isSelected(), changeDatabase.isSelected(), setFileDir.isSelected() ? fileDir.getText() : null);
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) FormLayout(com.jgoodies.forms.layout.FormLayout) FXDialogService(org.jabref.gui.FXDialogService) JPanel(javax.swing.JPanel) FormBuilder(com.jgoodies.forms.builder.FormBuilder) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField)

Example 7 with FileDialogConfiguration

use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.

the class SaveDatabaseAction method saveAs.

public void saveAs() throws Exception {
    // configure file dialog
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.BIBTEX_DB).withDefaultExtension(FileExtensions.BIBTEX_DB).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    Optional<Path> path = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration));
    if (path.isPresent()) {
        saveAs(path.get().toFile());
    } else {
        canceled = true;
        return;
    }
}
Also used : FXDialogService(org.jabref.gui.FXDialogService) Path(java.nio.file.Path) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration)

Example 8 with FileDialogConfiguration

use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.

the class LinkedFilesEditorViewModel method addNewFile.

public void addNewFile() {
    Path workingDirectory = databaseContext.getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences()).orElse(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)));
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(workingDirectory).build();
    List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
    dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
        LinkedFile newLinkedFile = fromFile(newFile, fileDirectories);
        files.add(new LinkedFileViewModel(newLinkedFile));
    });
}
Also used : Path(java.nio.file.Path) LinkedFile(org.jabref.model.entry.LinkedFile) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration)

Example 9 with FileDialogConfiguration

use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.

the class OpenDatabaseAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    List<Path> filesToOpen = new ArrayList<>();
    if (showDialog) {
        DialogService ds = new FXDialogService();
        FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.BIBTEX_DB).withDefaultExtension(FileExtensions.BIBTEX_DB).withInitialDirectory(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))).build();
        List<Path> chosenFiles = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration));
        filesToOpen.addAll(chosenFiles);
    } else {
        LOGGER.info(Action.NAME + " " + e.getActionCommand());
        filesToOpen.add(Paths.get(StringUtil.getCorrectFileName(e.getActionCommand(), "bib")));
    }
    openFiles(filesToOpen, true);
}
Also used : Path(java.nio.file.Path) FXDialogService(org.jabref.gui.FXDialogService) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) ArrayList(java.util.ArrayList) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration)

Example 10 with FileDialogConfiguration

use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.

the class AppendDatabaseAction method action.

@Override
public void action() {
    filesToOpen.clear();
    final MergeDialog dialog = new MergeDialog(frame, Localization.lang("Append library"), true);
    dialog.setLocationRelativeTo(panel);
    dialog.setVisible(true);
    if (dialog.isOkPressed()) {
        FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withDefaultExtension(FileExtensions.BIBTEX_DB).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
        DialogService dialogService = new FXDialogService();
        List<Path> chosen = DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showFileOpenDialogAndGetMultipleFiles(fileDialogConfiguration));
        if (chosen.isEmpty()) {
            return;
        }
        filesToOpen.addAll(chosen);
        // Run the actual open in a thread to prevent the program
        // locking until the file is loaded.
        JabRefExecutorService.INSTANCE.execute(() -> openIt(dialog.importEntries(), dialog.importStrings(), dialog.importGroups(), dialog.importSelectorWords()));
    }
}
Also used : FXDialogService(org.jabref.gui.FXDialogService) Path(java.nio.file.Path) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) MergeDialog(org.jabref.gui.MergeDialog)

Aggregations

FileDialogConfiguration (org.jabref.gui.util.FileDialogConfiguration)13 DialogService (org.jabref.gui.DialogService)10 FXDialogService (org.jabref.gui.FXDialogService)10 Path (java.nio.file.Path)9 FormBuilder (com.jgoodies.forms.builder.FormBuilder)5 FormLayout (com.jgoodies.forms.layout.FormLayout)5 JButton (javax.swing.JButton)5 JTextField (javax.swing.JTextField)4 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)3 ActionEvent (java.awt.event.ActionEvent)3 JPanel (javax.swing.JPanel)3 IOException (java.io.IOException)2 List (java.util.List)2 AbstractAction (javax.swing.AbstractAction)2 Action (javax.swing.Action)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 Globals (org.jabref.Globals)2 BasePanel (org.jabref.gui.BasePanel)2 DefaultTaskExecutor (org.jabref.gui.util.DefaultTaskExecutor)2