Search in sources :

Example 1 with FileUpdatePanel

use of org.jabref.collab.FileUpdatePanel in project jabref by JabRef.

the class BasePanel method fileUpdated.

@Override
public void fileUpdated() {
    if (saving) {
        // If not, we'll handle it on the next polling.
        return;
    }
    updatedExternally = true;
    final ChangeScanner scanner = new ChangeScanner(frame, BasePanel.this, getBibDatabaseContext().getDatabaseFile().orElse(null));
    // Test: running scan automatically in background
    if ((getBibDatabaseContext().getDatabaseFile().isPresent()) && !FileBasedLock.waitForFileLock(getBibDatabaseContext().getDatabaseFile().get().toPath())) {
        // The file is locked even after the maximum wait. Do nothing.
        LOGGER.error("File updated externally, but change scan failed because the file is locked.");
        // Perturb the stored timestamp so successive checks are made:
        Globals.getFileUpdateMonitor().perturbTimestamp(getFileMonitorHandle());
        return;
    }
    JabRefExecutorService.INSTANCE.executeInterruptableTaskAndWait(scanner);
    // Adding the sidepane component is Swing work, so we must do this in the Swing
    // thread:
    Runnable t = () -> {
        // Check if there is already a notification about external
        // changes:
        boolean hasAlready = sidePaneManager.hasComponent(FileUpdatePanel.class);
        if (hasAlready) {
            sidePaneManager.hideComponent(FileUpdatePanel.class);
            sidePaneManager.unregisterComponent(FileUpdatePanel.class);
        }
        FileUpdatePanel pan = new FileUpdatePanel(BasePanel.this, sidePaneManager, getBibDatabaseContext().getDatabaseFile().orElse(null), scanner);
        sidePaneManager.register(pan);
        sidePaneManager.show(FileUpdatePanel.class);
    };
    if (scanner.changesFound()) {
        SwingUtilities.invokeLater(t);
    } else {
        setUpdatedExternally(false);
    }
}
Also used : ChangeScanner(org.jabref.collab.ChangeScanner) FileUpdatePanel(org.jabref.collab.FileUpdatePanel)

Aggregations

ChangeScanner (org.jabref.collab.ChangeScanner)1 FileUpdatePanel (org.jabref.collab.FileUpdatePanel)1