Search in sources :

Example 6 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class JabRefFrame method addTab.

public void addTab(BasePanel basePanel, boolean raisePanel) {
    // add tab
    tabbedPane.add(basePanel.getTabTitle(), basePanel);
    // update all tab titles
    updateAllTabTitles();
    if (raisePanel) {
        tabbedPane.setSelectedComponent(basePanel);
    }
    // Register undo/redo listener
    basePanel.getUndoManager().registerListener(new UndoRedoEventManager());
    BibDatabaseContext context = basePanel.getBibDatabaseContext();
    if (readyForAutosave(context)) {
        AutosaveManager autosaver = AutosaveManager.start(context);
        autosaver.registerListener(new AutosaveUIManager(basePanel));
    }
    BackupManager.start(context);
    // Track opening
    trackOpenNewDatabase(basePanel);
}
Also used : BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) AutosaveManager(org.jabref.logic.autosaveandbackup.AutosaveManager) AutosaveUIManager(org.jabref.gui.autosaveandbackup.AutosaveUIManager)

Example 7 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class PreviewPanel method update.

public void update() {
    // Set entry number in case that is included in the preview layout.
    ExportFormats.entryNumber = 1;
    if (citationStyleWorker.isPresent()) {
        citationStyleWorker.get().cancel(true);
        citationStyleWorker = Optional.empty();
    }
    if (layout.isPresent()) {
        StringBuilder sb = new StringBuilder();
        bibEntry.ifPresent(entry -> sb.append(layout.get().doLayout(entry, databaseContext.map(BibDatabaseContext::getDatabase).orElse(null))));
        setPreviewLabel(sb.toString());
        markHighlights();
    } else if (basePanel.isPresent()) {
        citationStyleWorker = Optional.of(new CitationStyleWorker(this, previewPane));
        citationStyleWorker.get().execute();
    }
}
Also used : CitationStyleWorker(org.jabref.gui.worker.CitationStyleWorker) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 8 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class JabRefFrame method quit.

/**
     * General info dialog.  The MacAdapter calls this method when "Quit"
     * is selected from the application menu, Cmd-Q is pressed, or "Quit" is selected from the Dock.
     * The function returns a boolean indicating if quitting is ok or not.
     * <p>
     * Non-OSX JabRef calls this when choosing "Quit" from the menu
     * <p>
     * SIDE EFFECT: tears down JabRef
     *
     * @return true if the user chose to quit; false otherwise
     */
public boolean quit() {
    // Ask here if the user really wants to close, if the base
    // has not been saved since last save.
    boolean close = true;
    List<String> filenames = new ArrayList<>();
    if (tabbedPane.getTabCount() > 0) {
        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
            BibDatabaseContext context = getBasePanelAt(i).getBibDatabaseContext();
            if (getBasePanelAt(i).isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) {
                tabbedPane.setSelectedIndex(i);
                String filename = context.getDatabaseFile().map(File::getAbsolutePath).orElse(GUIGlobals.UNTITLED_TITLE);
                int answer = showSaveDialog(filename);
                if ((answer == JOptionPane.CANCEL_OPTION) || (answer == JOptionPane.CLOSED_OPTION)) {
                    return false;
                }
                if (answer == JOptionPane.YES_OPTION) {
                    // The user wants to save.
                    try {
                        //getCurrentBasePanel().runCommand("save");
                        SaveDatabaseAction saveAction = new SaveDatabaseAction(getCurrentBasePanel());
                        saveAction.runCommand();
                        if (saveAction.isCanceled() || !saveAction.isSuccess()) {
                            // The action was either canceled or unsuccessful.
                            // Break!
                            output(Localization.lang("Unable to save library"));
                            close = false;
                        }
                    } catch (Throwable ex) {
                        // Something prevented the file
                        // from being saved. Break!!!
                        close = false;
                        break;
                    }
                }
            } else if (context.getLocation() == DatabaseLocation.SHARED) {
                context.convertToLocalDatabase();
                context.getDBMSSynchronizer().closeSharedDatabase();
                context.clearDBMSSynchronizer();
            }
            AutosaveManager.shutdown(context);
            BackupManager.shutdown(context);
            context.getDatabaseFile().map(File::getAbsolutePath).ifPresent(filenames::add);
        }
    }
    if (close) {
        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
            if (getBasePanelAt(i).isSaving()) {
                // There is a database still being saved, so we need to wait.
                WaitForSaveOperation w = new WaitForSaveOperation(this);
                // This method won't return until canceled or the save operation is done.
                w.show();
                if (w.canceled()) {
                    // The user clicked cancel.
                    return false;
                }
            }
        }
        tearDownJabRef(filenames);
        return true;
    }
    return false;
}
Also used : SaveDatabaseAction(org.jabref.gui.exporter.SaveDatabaseAction) ArrayList(java.util.ArrayList) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 9 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class JabRefFrame method closeTab.

private void closeTab(BasePanel panel) {
    // empty tab without database
    if (panel == null) {
        return;
    }
    BibDatabaseContext context = panel.getBibDatabaseContext();
    if (panel.isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) {
        if (confirmClose(panel)) {
            removeTab(panel);
        }
    } else if (context.getLocation() == DatabaseLocation.SHARED) {
        context.convertToLocalDatabase();
        context.getDBMSSynchronizer().closeSharedDatabase();
        context.clearDBMSSynchronizer();
        removeTab(panel);
    } else {
        removeTab(panel);
    }
    AutosaveManager.shutdown(context);
    BackupManager.shutdown(context);
}
Also used : BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 10 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class FieldFormatterCleanupsPanel method buildLayout.

private void buildLayout(List<FieldFormatterCleanup> actionsToDisplay) {
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 13dlu, left:pref:grow, 4dlu, pref, 4dlu, pref", "pref, 2dlu, pref, 2dlu, pref, 4dlu, pref, 2dlu, fill:pref:grow, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu"));
    builder.add(cleanupEnabled).xyw(1, 1, 7);
    actionsList = new JList<>(new CleanupActionsListModel(actionsToDisplay));
    actionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    actionsList.addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            super.mouseMoved(e);
            CleanupActionsListModel m = (CleanupActionsListModel) actionsList.getModel();
            int index = actionsList.locationToIndex(e.getPoint());
            if (index > -1) {
                actionsList.setToolTipText(m.getElementAt(index).getFormatter().getDescription());
            }
        }
    });
    actionsList.getModel().addListDataListener(new ListDataListener() {

        @Override
        public void intervalRemoved(ListDataEvent e) {
            //index0 is sufficient, because of SingleSelection
            if (e.getIndex0() == 0) {
                //when an item gets deleted, the next one becomes the new 0
                actionsList.setSelectedIndex(e.getIndex0());
            }
            if (e.getIndex0() > 0) {
                actionsList.setSelectedIndex(e.getIndex0() - 1);
            }
        }

        @Override
        public void intervalAdded(ListDataEvent e) {
        //empty, not needed
        }

        @Override
        public void contentsChanged(ListDataEvent e) {
        //empty, not needed
        }
    });
    builder.add(actionsList).xyw(3, 5, 5);
    resetButton = new JButton(Localization.lang("Reset"));
    resetButton.addActionListener(e -> ((CleanupActionsListModel) actionsList.getModel()).reset(defaultFormatters));
    BibDatabaseContext databaseContext = JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabaseContext();
    recommendButton = new JButton(Localization.lang("Recommended for %0", databaseContext.getMode().getFormattedName()));
    boolean isBiblatex = databaseContext.isBiblatexMode();
    recommendButton.addActionListener(e -> {
        if (isBiblatex) {
            ((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBLATEX_ACTIONS);
        } else {
            ((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBTEX_ACTIONS);
        }
    });
    removeButton = new JButton(Localization.lang("Remove selected"));
    removeButton.addActionListener(e -> ((CleanupActionsListModel) actionsList.getModel()).removeAtIndex(actionsList.getSelectedIndex()));
    builder.add(removeButton).xy(7, 11);
    builder.add(resetButton).xy(3, 11);
    builder.add(recommendButton).xy(5, 11);
    builder.add(getSelectorPanel()).xyw(3, 15, 5);
    makeDescriptionTextAreaLikeJLabel();
    builder.add(descriptionAreaText).xyw(3, 17, 5);
    this.setLayout(new BorderLayout());
    this.add(builder.getPanel(), BorderLayout.WEST);
    updateDescription();
    // make sure the layout is set according to the checkbox
    cleanupEnabled.addActionListener(new EnablementStatusListener(fieldFormatterCleanups.isEnabled()));
    cleanupEnabled.setSelected(fieldFormatterCleanups.isEnabled());
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) MouseEvent(java.awt.event.MouseEvent) JButton(javax.swing.JButton) ListDataListener(javax.swing.event.ListDataListener) ListDataEvent(javax.swing.event.ListDataEvent) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) BorderLayout(java.awt.BorderLayout) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Aggregations

BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)48 Defaults (org.jabref.model.Defaults)24 Before (org.junit.Before)16 BibDatabase (org.jabref.model.database.BibDatabase)15 Test (org.junit.Test)13 BibEntry (org.jabref.model.entry.BibEntry)11 ParserResult (org.jabref.logic.importer.ParserResult)9 MetaData (org.jabref.model.metadata.MetaData)8 Charset (java.nio.charset.Charset)6 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)6 Path (java.nio.file.Path)5 Scanner (java.util.Scanner)5 BibtexDatabaseWriter (org.jabref.logic.exporter.BibtexDatabaseWriter)5 SavePreferences (org.jabref.logic.exporter.SavePreferences)5 IOException (java.io.IOException)4 SaveException (org.jabref.logic.exporter.SaveException)4 BibtexImporter (org.jabref.logic.importer.fileformat.BibtexImporter)4 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)4 FileSaveSession (org.jabref.logic.exporter.FileSaveSession)3 SaveSession (org.jabref.logic.exporter.SaveSession)3