Search in sources :

Example 21 with BasePanel

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

the class EntryCustomizationDialog method updateEntriesForChangedTypes.

private void updateEntriesForChangedTypes(List<String> actuallyChangedTypes) {
    for (BasePanel bp : frame.getBasePanelList()) {
        // get all affected entries
        List<BibEntry> filtered = bp.getDatabase().getEntries().stream().filter(entry -> actuallyChangedTypes.contains(entry.getType().toLowerCase(Locale.ENGLISH))).collect(Collectors.toList());
        // update all affected entries with new type
        filtered.forEach(entry -> EntryTypes.getType(entry.getType(), bibDatabaseMode).ifPresent(entry::setType));
    }
}
Also used : ListSelectionModel(javax.swing.ListSelectionModel) Arrays(java.util.Arrays) ActionListener(java.awt.event.ActionListener) StringUtil(org.jabref.model.strings.StringUtil) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) HashMap(java.util.HashMap) BasePanel(org.jabref.gui.BasePanel) ArrayList(java.util.ArrayList) GridLayout(java.awt.GridLayout) HashSet(java.util.HashSet) JabRefFrame(org.jabref.gui.JabRefFrame) CustomEntryType(org.jabref.model.entry.CustomEntryType) Locale(java.util.Locale) Map(java.util.Map) InternalBibtexFields(org.jabref.model.entry.InternalBibtexFields) ListDataEvent(javax.swing.event.ListDataEvent) AbstractTableModel(javax.swing.table.AbstractTableModel) Localization(org.jabref.logic.l10n.Localization) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ActionMap(javax.swing.ActionMap) JComponent(javax.swing.JComponent) EntryTypes(org.jabref.model.EntryTypes) JButton(javax.swing.JButton) BibDatabaseMode(org.jabref.model.database.BibDatabaseMode) BibEntry(org.jabref.model.entry.BibEntry) JList(javax.swing.JList) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) Globals(org.jabref.Globals) List(java.util.List) ListDataListener(javax.swing.event.ListDataListener) JabRefDialog(org.jabref.gui.JabRefDialog) AbstractAction(javax.swing.AbstractAction) Optional(java.util.Optional) EntryType(org.jabref.model.entry.EntryType) GridBagLayout(java.awt.GridBagLayout) InputMap(javax.swing.InputMap) ListSelectionListener(javax.swing.event.ListSelectionListener) JPanel(javax.swing.JPanel) KeyBinding(org.jabref.gui.keyboard.KeyBinding) BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel)

Example 22 with BasePanel

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

the class NewSubDatabaseAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // Create a new, empty, database.
    FromAuxDialog dialog = new FromAuxDialog(jabRefFrame, "", true, jabRefFrame.getTabbedPane());
    dialog.setLocationRelativeTo(jabRefFrame);
    dialog.setVisible(true);
    if (dialog.generatePressed()) {
        Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode());
        BasePanel bp = new BasePanel(jabRefFrame, new BibDatabaseContext(dialog.getGenerateDB(), defaults));
        jabRefFrame.addTab(bp, true);
        jabRefFrame.output(Localization.lang("New library created."));
    }
}
Also used : FromAuxDialog(org.jabref.gui.auximport.FromAuxDialog) BasePanel(org.jabref.gui.BasePanel) Defaults(org.jabref.model.Defaults) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 23 with BasePanel

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

the class ExportToClipboardAction method run.

@Override
public void run() {
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel == null) {
        return;
    }
    if (panel.getSelectedEntries().isEmpty()) {
        message = Localization.lang("This operation requires one or more entries to be selected.");
        getCallBack().update();
        return;
    }
    List<IExportFormat> exportFormats = new LinkedList<>(ExportFormats.getExportFormats().values());
    Collections.sort(exportFormats, (e1, e2) -> e1.getDisplayName().compareTo(e2.getDisplayName()));
    String[] exportFormatDisplayNames = new String[exportFormats.size()];
    for (int i = 0; i < exportFormats.size(); i++) {
        IExportFormat exportFormat = exportFormats.get(i);
        exportFormatDisplayNames[i] = exportFormat.getDisplayName();
    }
    JList<String> list = new JList<>(exportFormatDisplayNames);
    list.setBorder(BorderFactory.createEtchedBorder());
    list.setSelectionInterval(0, 0);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    int answer = JOptionPane.showOptionDialog(frame, list, Localization.lang("Select export format"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { Localization.lang("Export"), Localization.lang("Cancel") }, Localization.lang("Export"));
    if (answer == JOptionPane.NO_OPTION) {
        return;
    }
    IExportFormat format = exportFormats.get(list.getSelectedIndex());
    // Set the global variable for this database's file directory before exporting,
    // so formatters can resolve linked files correctly.
    // (This is an ugly hack!)
    Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectories(Globals.prefs.getFileDirectoryPreferences());
    File tmp = null;
    try {
        // To simplify the exporter API we simply do a normal export to a temporary
        // file, and read the contents afterwards:
        tmp = File.createTempFile("jabrefCb", ".tmp");
        tmp.deleteOnExit();
        List<BibEntry> entries = panel.getSelectedEntries();
        // Write to file:
        format.performExport(panel.getBibDatabaseContext(), tmp.getPath(), panel.getBibDatabaseContext().getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()), entries);
        // Read the file and put the contents on the clipboard:
        StringBuilder sb = new StringBuilder();
        try (Reader reader = new InputStreamReader(new FileInputStream(tmp), panel.getBibDatabaseContext().getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()))) {
            int s;
            while ((s = reader.read()) != -1) {
                sb.append((char) s);
            }
        }
        ClipboardOwner owner = (clipboard, content) -> {
        // Do nothing
        };
        RtfTransferable rs = new RtfTransferable(sb.toString());
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(rs, owner);
        message = Localization.lang("Entries exported to clipboard") + ": " + entries.size();
    } catch (Exception e) {
        //To change body of catch statement use File | Settings | File Templates.
        LOGGER.error("Error exporting to clipboard", e);
        message = Localization.lang("Error exporting to clipboard");
    } finally {
        // Clean up:
        if ((tmp != null) && !tmp.delete()) {
            LOGGER.info("Cannot delete temporary clipboard file");
        }
    }
}
Also used : ListSelectionModel(javax.swing.ListSelectionModel) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) IExportFormat(org.jabref.logic.exporter.IExportFormat) BibEntry(org.jabref.model.entry.BibEntry) JList(javax.swing.JList) AbstractWorker(org.jabref.gui.worker.AbstractWorker) ExportFormats(org.jabref.logic.exporter.ExportFormats) BorderFactory(javax.swing.BorderFactory) FileInputStream(java.io.FileInputStream) Reader(java.io.Reader) JOptionPane(javax.swing.JOptionPane) InputStreamReader(java.io.InputStreamReader) BasePanel(org.jabref.gui.BasePanel) File(java.io.File) Globals(org.jabref.Globals) Objects(java.util.Objects) List(java.util.List) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Toolkit(java.awt.Toolkit) BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) InputStreamReader(java.io.InputStreamReader) IExportFormat(org.jabref.logic.exporter.IExportFormat) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) File(java.io.File) JList(javax.swing.JList)

Example 24 with BasePanel

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

the class OpenDatabaseAction method addNewDatabase.

private BasePanel addNewDatabase(ParserResult result, final Path file, boolean raisePanel) {
    BibDatabase database = result.getDatabase();
    if (result.hasWarnings()) {
        JabRefExecutorService.INSTANCE.execute(() -> ParserResultWarningDialog.showParserResultWarningDialog(result, frame));
    }
    BasePanel basePanel = new BasePanel(frame, result.getDatabaseContext());
    // file is set to null inside the EventDispatcherThread
    SwingUtilities.invokeLater(() -> frame.addTab(basePanel, raisePanel));
    if (Objects.nonNull(file)) {
        frame.output(Localization.lang("Opened library") + " '" + file.toString() + "' " + Localization.lang("with") + " " + database.getEntryCount() + " " + Localization.lang("entries") + ".");
    }
    return basePanel;
}
Also used : BasePanel(org.jabref.gui.BasePanel) BibDatabase(org.jabref.model.database.BibDatabase)

Example 25 with BasePanel

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

the class ConnectToSharedDatabaseDialog method openSharedDatabase.

public void openSharedDatabase() {
    if (isSharedDatabaseAlreadyPresent()) {
        JOptionPane.showMessageDialog(ConnectToSharedDatabaseDialog.this, Localization.lang("You are already connected to a database using entered connection details."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    if (autosaveFile.isSelected()) {
        Path localFilePath = Paths.get(fileLocationField.getText());
        if (Files.exists(localFilePath) && !Files.isDirectory(localFilePath)) {
            int answer = JOptionPane.showConfirmDialog(this, Localization.lang("'%0' exists. Overwrite file?", localFilePath.getFileName().toString()), Localization.lang("Existing file"), JOptionPane.YES_NO_OPTION);
            if (answer == JOptionPane.NO_OPTION) {
                fileLocationField.requestFocus();
                return;
            }
        }
    }
    setLoadingConnectButtonText(true);
    try {
        BasePanel panel = new SharedDatabaseUIManager(frame).openNewSharedDatabaseTab(connectionProperties);
        setPreferences();
        dispose();
        if (!fileLocationField.getText().isEmpty()) {
            try {
                new SaveDatabaseAction(panel, Paths.get(fileLocationField.getText())).runCommand();
            } catch (Throwable e) {
                LOGGER.error("Error while saving the database", e);
            }
        }
        // setLoadingConnectButtonText(false) should not be reached regularly.
        return;
    } catch (SQLException | InvalidDBMSConnectionPropertiesException exception) {
        JOptionPane.showMessageDialog(ConnectToSharedDatabaseDialog.this, exception.getMessage(), Localization.lang("Connection error"), JOptionPane.ERROR_MESSAGE);
    } catch (DatabaseNotSupportedException exception) {
        new MigrationHelpDialog(this).setVisible(true);
    }
    setLoadingConnectButtonText(false);
}
Also used : Path(java.nio.file.Path) BasePanel(org.jabref.gui.BasePanel) SQLException(java.sql.SQLException) SaveDatabaseAction(org.jabref.gui.exporter.SaveDatabaseAction) InvalidDBMSConnectionPropertiesException(org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException) DatabaseNotSupportedException(org.jabref.shared.exception.DatabaseNotSupportedException)

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