Search in sources :

Example 1 with SharedDatabaseUIManager

use of org.jabref.gui.shared.SharedDatabaseUIManager in project jabref by JabRef.

the class JabRefGUI method openWindow.

private void openWindow() {
    // This property is set to make the Mac OSX Java VM move the menu bar to the top of the screen
    if (OS.OS_X) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
    }
    // Set antialiasing on everywhere. This only works in JRE >= 1.5.
    // Or... it doesn't work, period.
    // TODO test and maybe remove this! I found this commented out with no additional info ( payload@lavabit.com )
    // Enabled since JabRef 2.11 beta 4
    System.setProperty("swing.aatext", "true");
    // Default is "on".
    // "lcd" instead of "on" because of http://wiki.netbeans.org/FaqFontRendering and http://docs.oracle.com/javase/6/docs/technotes/guides/2d/flags.html#aaFonts
    System.setProperty("awt.useSystemAAFontSettings", "lcd");
    // look and feel. This MUST be the first thing to do before loading any Swing-specific code!
    setLookAndFeel();
    // If the option is enabled, open the last edited libraries, if any.
    if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
        openLastEditedDatabases();
    }
    GUIGlobals.init();
    LOGGER.debug("Initializing frame");
    JabRefGUI.mainFrame = new JabRefFrame();
    // Add all bibDatabases databases to the frame:
    boolean first = false;
    if (!bibDatabases.isEmpty()) {
        for (Iterator<ParserResult> parserResultIterator = bibDatabases.iterator(); parserResultIterator.hasNext(); ) {
            ParserResult pr = parserResultIterator.next();
            // Define focused tab
            if (pr.getFile().get().getAbsolutePath().equals(focusedFile)) {
                first = true;
            }
            if (pr.isInvalid()) {
                failed.add(pr);
                parserResultIterator.remove();
            } else if (pr.getDatabase().isShared()) {
                try {
                    new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr);
                } catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException | NotASharedDatabaseException e) {
                    // do not open the original file
                    pr.getDatabaseContext().clearDatabaseFile();
                    pr.getDatabase().clearSharedDatabaseID();
                    LOGGER.error("Connection error", e);
                    JOptionPane.showMessageDialog(mainFrame, e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."), Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE);
                }
                toOpenTab.add(pr);
            } else if (pr.toOpenTab()) {
                // things to be appended to an opened tab should be done after opening all tabs
                // add them to the list
                toOpenTab.add(pr);
            } else {
                JabRefGUI.getMainFrame().addParserResult(pr, first);
                first = false;
            }
        }
    }
    // finally add things to the currently opened tab
    for (ParserResult pr : toOpenTab) {
        JabRefGUI.getMainFrame().addParserResult(pr, first);
        first = false;
    }
    // do it here:
    if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {
        JabRefGUI.getMainFrame().setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    JabRefGUI.getMainFrame().setVisible(true);
    for (ParserResult pr : failed) {
        String message = "<html>" + Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "<p>" + pr.getErrorMessage() + "</html>";
        JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), message, Localization.lang("Error opening file"), JOptionPane.ERROR_MESSAGE);
    }
    // Display warnings, if any
    int tabNumber = 0;
    for (ParserResult pr : bibDatabases) {
        ParserResultWarningDialog.showParserResultWarningDialog(pr, JabRefGUI.getMainFrame(), tabNumber++);
    }
    for (int i = 0; (i < bibDatabases.size()) && (i < JabRefGUI.getMainFrame().getBasePanelCount()); i++) {
        ParserResult pr = bibDatabases.get(i);
        BasePanel panel = JabRefGUI.getMainFrame().getBasePanelAt(i);
        OpenDatabaseAction.performPostOpenActions(panel, pr);
    }
    LOGGER.debug("Finished adding panels");
    if (!bibDatabases.isEmpty()) {
        JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus();
    }
}
Also used : JabRefFrame(org.jabref.gui.JabRefFrame) ParserResult(org.jabref.logic.importer.ParserResult) SharedDatabaseUIManager(org.jabref.gui.shared.SharedDatabaseUIManager) BasePanel(org.jabref.gui.BasePanel)

Example 2 with SharedDatabaseUIManager

use of org.jabref.gui.shared.SharedDatabaseUIManager 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)

Aggregations

BasePanel (org.jabref.gui.BasePanel)2 SharedDatabaseUIManager (org.jabref.gui.shared.SharedDatabaseUIManager)2 ParserResult (org.jabref.logic.importer.ParserResult)2 Path (java.nio.file.Path)1 FileTime (java.nio.file.attribute.FileTime)1 SQLException (java.sql.SQLException)1 JabRefFrame (org.jabref.gui.JabRefFrame)1 DatabaseNotSupportedException (org.jabref.shared.exception.DatabaseNotSupportedException)1 InvalidDBMSConnectionPropertiesException (org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException)1 NotASharedDatabaseException (org.jabref.shared.exception.NotASharedDatabaseException)1