Search in sources :

Example 11 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class OpenDatabaseAction method openTheFile.

/**
     * @param file the file, may be null or not existing
     */
private void openTheFile(Path file, boolean raisePanel) {
    Objects.requireNonNull(file);
    if (Files.exists(file)) {
        Path fileToLoad = file.toAbsolutePath();
        frame.output(Localization.lang("Opening") + ": '" + file + "'");
        String fileName = file.getFileName().toString();
        Globals.prefs.put(JabRefPreferences.WORKING_DIRECTORY, fileToLoad.getParent().toString());
        if (FileBasedLock.hasLockFile(file)) {
            Optional<FileTime> modificationTime = FileBasedLock.getLockFileTimeStamp(file);
            if ((modificationTime.isPresent()) && ((System.currentTimeMillis() - modificationTime.get().toMillis()) > FileBasedLock.LOCKFILE_CRITICAL_AGE)) {
                // The lock file is fairly old, so we can offer to "steal" the file:
                int answer = JOptionPane.showConfirmDialog(null, "<html>" + Localization.lang("Error opening file") + " '" + fileName + "'. " + Localization.lang("File is locked by another JabRef instance.") + "<p>" + Localization.lang("Do you want to override the file lock?"), Localization.lang("File locked"), JOptionPane.YES_NO_OPTION);
                if (answer == JOptionPane.YES_OPTION) {
                    FileBasedLock.deleteLockFile(file);
                } else {
                    return;
                }
            } else if (!FileBasedLock.waitForFileLock(file)) {
                JOptionPane.showMessageDialog(null, Localization.lang("Error opening file") + " '" + fileName + "'. " + Localization.lang("File is locked by another JabRef instance."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
        if (BackupManager.checkForBackupFile(fileToLoad)) {
            BackupUIManager.showRestoreBackupDialog(frame, fileToLoad);
        }
        ParserResult result;
        result = OpenDatabase.loadDatabase(fileToLoad.toString(), Globals.prefs.getImportFormatPreferences());
        if (result.getDatabase().isShared()) {
            try {
                new SharedDatabaseUIManager(frame).openSharedDatabaseFromParserResult(result);
            } catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException | NotASharedDatabaseException e) {
                // do not open the original file
                result.getDatabaseContext().clearDatabaseFile();
                result.getDatabase().clearSharedDatabaseID();
                LOGGER.error("Connection error", e);
                JOptionPane.showMessageDialog(frame, e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."), Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE);
            }
        }
        BasePanel panel = addNewDatabase(result, file, raisePanel);
        // After adding the database, go through our list and see if
        // any post open actions need to be done. For instance, checking
        // if we found new entry types that can be imported, or checking
        // if the database contents should be modified due to new features
        // in this version of JabRef:
        final ParserResult finalReferenceToResult = result;
        SwingUtilities.invokeLater(() -> OpenDatabaseAction.performPostOpenActions(panel, finalReferenceToResult));
    }
}
Also used : Path(java.nio.file.Path) SharedDatabaseUIManager(org.jabref.gui.shared.SharedDatabaseUIManager) NotASharedDatabaseException(org.jabref.shared.exception.NotASharedDatabaseException) BasePanel(org.jabref.gui.BasePanel) SQLException(java.sql.SQLException) InvalidDBMSConnectionPropertiesException(org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException) FileTime(java.nio.file.attribute.FileTime) ParserResult(org.jabref.logic.importer.ParserResult) DatabaseNotSupportedException(org.jabref.shared.exception.DatabaseNotSupportedException)

Example 12 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class PreviewPrefsTab method storeSettings.

@Override
public void storeSettings() {
    List<String> styles = new ArrayList<>();
    Enumeration<Object> elements = chosenModel.elements();
    while (elements.hasMoreElements()) {
        Object obj = elements.nextElement();
        if (obj instanceof CitationStyle) {
            styles.add(((CitationStyle) obj).getFilepath());
        } else if (obj instanceof String) {
            styles.add("Preview");
        }
    }
    PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences().getBuilder().withPreviewCycle(styles).withPreviewStyle(layout.getText().replace("\n", "__NEWLINE__")).build();
    Globals.prefs.storePreviewPreferences(previewPreferences);
    // update preview
    for (BasePanel basePanel : JabRefGUI.getMainFrame().getBasePanelList()) {
        basePanel.getPreviewPanel().updateLayout();
    }
}
Also used : CitationStyle(org.jabref.logic.citationstyle.CitationStyle) BasePanel(org.jabref.gui.BasePanel) ArrayList(java.util.ArrayList) PreviewPreferences(org.jabref.preferences.PreviewPreferences)

Example 13 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class GlobalSearchBar method performGlobalSearch.

public void performGlobalSearch() {
    BasePanel currentBasePanel = frame.getCurrentBasePanel();
    if (currentBasePanel == null || validateSearchResultFrame(true)) {
        return;
    }
    if (globalSearchWorker != null) {
        globalSearchWorker.cancel(true);
    }
    if (searchField.getText().isEmpty()) {
        focus();
        return;
    }
    globalSearchWorker = new GlobalSearchWorker(currentBasePanel.frame(), getSearchQuery());
    globalSearchWorker.execute();
}
Also used : BasePanel(org.jabref.gui.BasePanel)

Example 14 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class GlobalSearchBar method openLocalFindingsInExternalPanel.

private void openLocalFindingsInExternalPanel() {
    BasePanel currentBasePanel = frame.getCurrentBasePanel();
    if (currentBasePanel == null || validateSearchResultFrame(false)) {
        return;
    }
    if (searchField.getText().isEmpty()) {
        focus();
        return;
    }
    SearchResultFrame searchDialog = new SearchResultFrame(currentBasePanel.frame(), Localization.lang("Search results in library %0 for %1", currentBasePanel.getBibDatabaseContext().getDatabaseFile().map(File::getName).orElse(GUIGlobals.UNTITLED_TITLE), this.getSearchQuery().localize()), getSearchQuery(), false);
    List<BibEntry> entries = currentBasePanel.getDatabase().getEntries().stream().filter(BibEntry::isSearchHit).collect(Collectors.toList());
    searchDialog.addEntries(entries, currentBasePanel);
    searchDialog.selectFirstEntry();
    searchDialog.setVisible(true);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel)

Example 15 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class MarkEntriesAction method run.

@Override
public void run() {
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel != null) {
        List<BibEntry> bes = panel.getSelectedEntries();
        // used at update() to determine output string
        besLength = bes.size();
        if (!bes.isEmpty()) {
            NamedCompound ce = new NamedCompound(Localization.lang("Mark entries"));
            for (BibEntry be : bes) {
                EntryMarker.markEntry(be, level + 1, false, ce);
            }
            ce.end();
            panel.getUndoManager().addEdit(ce);
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) NamedCompound(org.jabref.gui.undo.NamedCompound)

Aggregations

BasePanel (org.jabref.gui.BasePanel)31 BibEntry (org.jabref.model.entry.BibEntry)14 Path (java.nio.file.Path)4 NamedCompound (org.jabref.gui.undo.NamedCompound)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 JabRefFrame (org.jabref.gui.JabRefFrame)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 BorderFactory (javax.swing.BorderFactory)2 JFrame (javax.swing.JFrame)2 JList (javax.swing.JList)2 JOptionPane (javax.swing.JOptionPane)2 ListSelectionModel (javax.swing.ListSelectionModel)2 ComponentFinder (org.assertj.swing.core.ComponentFinder)2 FailOnThreadViolationRepaintManager (org.assertj.swing.edt.FailOnThreadViolationRepaintManager)2 WindowFinder (org.assertj.swing.finder.WindowFinder)2