Search in sources :

Example 6 with BasePanel

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

the class OpenOfficePanel method checkThatEntriesHaveKeys.

/**
     * Check that all entries in the list have BibTeX keys, if not ask if they should be generated
     *
     * @param entries A list of entries to be checked
     * @return true if all entries have BibTeX keys, if it so may be after generating them
     */
private boolean checkThatEntriesHaveKeys(List<BibEntry> entries) {
    // Check if there are empty keys
    boolean emptyKeys = false;
    for (BibEntry entry : entries) {
        if (!entry.getCiteKeyOptional().isPresent()) {
            // Found one, no need to look further for now
            emptyKeys = true;
            break;
        }
    }
    // If no empty keys, return true
    if (!emptyKeys) {
        return true;
    }
    // Ask if keys should be generated
    String[] options = { Localization.lang("Generate keys"), Localization.lang("Cancel") };
    int answer = JOptionPane.showOptionDialog(this.frame, Localization.lang("Cannot cite entries without BibTeX keys. Generate keys now?"), Localization.lang("Cite"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null);
    BasePanel panel = frame.getCurrentBasePanel();
    if ((answer == JOptionPane.OK_OPTION) && (panel != null)) {
        // Generate keys
        BibtexKeyPatternPreferences prefs = Globals.prefs.getBibtexKeyPatternPreferences();
        NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite"));
        for (BibEntry entry : entries) {
            if (!entry.getCiteKeyOptional().isPresent()) {
                // Generate key
                BibtexKeyPatternUtil.makeAndSetLabel(panel.getBibDatabaseContext().getMetaData().getCiteKeyPattern(prefs.getKeyPattern()), panel.getDatabase(), entry, prefs);
                // Add undo change
                undoCompound.addEdit(new UndoableKeyChange(entry, null, entry.getCiteKeyOptional().get()));
            }
        }
        undoCompound.end();
        // Add all undos
        panel.getUndoManager().addEdit(undoCompound);
        // Now every entry has a key
        return true;
    } else {
        // No, we canceled (or there is no panel to get the database from, highly unlikely)
        return false;
    }
}
Also used : UndoableKeyChange(org.jabref.gui.undo.UndoableKeyChange) BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) BibtexKeyPatternPreferences(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences) NamedCompound(org.jabref.gui.undo.NamedCompound)

Example 7 with BasePanel

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

the class OpenOfficePanel method pushEntries.

private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addPageInfo) {
    if (!ooBase.isConnectedToDocument()) {
        JOptionPane.showMessageDialog(frame, Localization.lang("Not connected to any Writer document. Please" + " make sure a document is open, and use the 'Select Writer document' button to connect to it."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    Boolean inParenthesis = inParenthesisIn;
    String pageInfo = null;
    if (addPageInfo) {
        AdvancedCiteDialog citeDialog = new AdvancedCiteDialog(frame);
        citeDialog.showDialog();
        if (citeDialog.canceled()) {
            return;
        }
        if (!citeDialog.getPageInfo().isEmpty()) {
            pageInfo = citeDialog.getPageInfo();
        }
        inParenthesis = citeDialog.isInParenthesisCite();
    }
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel != null) {
        final BibDatabase database = panel.getDatabase();
        List<BibEntry> entries = panel.getSelectedEntries();
        if (!entries.isEmpty() && checkThatEntriesHaveKeys(entries)) {
            try {
                if (style == null) {
                    style = loader.getUsedStyle();
                }
                ooBase.insertEntry(entries, database, getBaseList(), style, inParenthesis, withText, pageInfo, preferences.syncWhenCiting());
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE);
                LOGGER.warn("Problem with style file", ex);
            } catch (ConnectionLostException ex) {
                showConnectionLostErrorMessage();
            } catch (UndefinedCharacterFormatException ex) {
                reportUndefinedCharacterFormat(ex);
            } catch (UndefinedParagraphFormatException ex) {
                reportUndefinedParagraphFormat(ex);
            } catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | CreationException | NoSuchElementException | WrappedTargetException | IOException | BibEntryNotFoundException | IllegalTypeException | PropertyExistException | NotRemoveableException ex) {
                LOGGER.warn("Could not insert entry", ex);
            }
        }
    }
}
Also used : BasePanel(org.jabref.gui.BasePanel) WrappedTargetException(com.sun.star.lang.WrappedTargetException) IllegalTypeException(com.sun.star.beans.IllegalTypeException) NotRemoveableException(com.sun.star.beans.NotRemoveableException) FileNotFoundException(java.io.FileNotFoundException) PropertyExistException(com.sun.star.beans.PropertyExistException) BibEntry(org.jabref.model.entry.BibEntry) IOException(java.io.IOException) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) BibDatabase(org.jabref.model.database.BibDatabase) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) NoSuchElementException(com.sun.star.container.NoSuchElementException)

Example 8 with BasePanel

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

the class SearchResultFrame method selectEntryInBasePanel.

private void selectEntryInBasePanel(BibEntry entry) {
    BasePanel basePanel = entryHome.get(entry);
    frame.showBasePanel(basePanel);
    basePanel.requestFocus();
    basePanel.highlightEntry(entry);
}
Also used : BasePanel(org.jabref.gui.BasePanel)

Example 9 with BasePanel

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

the class LookupIdentifiersWorker method run.

@Override
public void run() {
    BasePanel basePanel = Objects.requireNonNull(frame.getCurrentBasePanel());
    List<BibEntry> bibEntries = basePanel.getSelectedEntries();
    if (!bibEntries.isEmpty()) {
        String totalCount = Integer.toString(bibEntries.size());
        NamedCompound namedCompound = new NamedCompound(Localization.lang("Look up %0", fetcher.getIdentifierName()));
        int count = 0;
        int foundCount = 0;
        for (BibEntry bibEntry : bibEntries) {
            count++;
            frame.output(Localization.lang("Looking up %0... - entry %1 out of %2 - found %3", fetcher.getIdentifierName(), Integer.toString(count), totalCount, Integer.toString(foundCount)));
            Optional<T> identifier = Optional.empty();
            try {
                identifier = fetcher.findIdentifier(bibEntry);
            } catch (FetcherException e) {
                LOGGER.error("Could not fetch " + fetcher.getIdentifierName(), e);
            }
            if (identifier.isPresent() && !bibEntry.hasField(identifier.get().getDefaultField())) {
                Optional<FieldChange> fieldChange = bibEntry.setField(identifier.get().getDefaultField(), identifier.get().getNormalized());
                if (fieldChange.isPresent()) {
                    namedCompound.addEdit(new UndoableFieldChange(fieldChange.get()));
                    foundCount++;
                    frame.output(Localization.lang("Looking up %0... - entry %1 out of %2 - found %3", Integer.toString(count), totalCount, Integer.toString(foundCount)));
                }
            }
        }
        namedCompound.end();
        if (foundCount > 0) {
            basePanel.getUndoManager().addEdit(namedCompound);
            basePanel.markBaseChanged();
        }
        message = Localization.lang("Determined %0 for %1 entries", fetcher.getIdentifierName(), Integer.toString(foundCount));
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) FetcherException(org.jabref.logic.importer.FetcherException) NamedCompound(org.jabref.gui.undo.NamedCompound) FieldChange(org.jabref.model.FieldChange) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange)

Example 10 with BasePanel

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

the class OpenDatabaseAction method openFiles.

/**
     * Opens the given files. If one of it is null or 404, nothing happens
     *
     * @param filesToOpen the filesToOpen, may be null or not existing
     */
public void openFiles(List<Path> filesToOpen, boolean raisePanel) {
    BasePanel toRaise = null;
    int initialCount = filesToOpen.size();
    int removed = 0;
    // Check if any of the files are already open:
    for (Iterator<Path> iterator = filesToOpen.iterator(); iterator.hasNext(); ) {
        Path file = iterator.next();
        for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
            BasePanel basePanel = frame.getBasePanelAt(i);
            if ((basePanel.getBibDatabaseContext().getDatabaseFile().isPresent()) && basePanel.getBibDatabaseContext().getDatabaseFile().get().equals(file)) {
                iterator.remove();
                removed++;
                // raise the BasePanel in question:
                if (removed == initialCount) {
                    toRaise = basePanel;
                }
                // no more bps to check, we found a matching one
                break;
            }
        }
    }
    // locking until the file is loaded.
    if (!filesToOpen.isEmpty()) {
        final List<Path> theFiles = Collections.unmodifiableList(filesToOpen);
        JabRefExecutorService.INSTANCE.execute(() -> {
            for (Path theFile : theFiles) {
                openTheFile(theFile, raisePanel);
            }
        });
        for (Path theFile : theFiles) {
            frame.getFileHistory().newFile(theFile.toString());
        }
    } else // already open. If so, we may have to raise the correct tab:
    if (toRaise != null) {
        frame.output(Localization.lang("File '%0' is already open.", toRaise.getBibDatabaseContext().getDatabaseFile().get().getPath()));
        frame.getTabbedPane().setSelectedComponent(toRaise);
    }
    frame.output(Localization.lang("Files opened") + ": " + (filesToOpen.size()));
}
Also used : Path(java.nio.file.Path) BasePanel(org.jabref.gui.BasePanel)

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