Search in sources :

Example 16 with NamedCompound

use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.

the class DroppedFileHandler method linkPdfToEntry.

public void linkPdfToEntry(String fileName, BibEntry entry) {
    Optional<ExternalFileType> optFileType = ExternalFileTypes.getInstance().getExternalFileTypeByExt("pdf");
    if (!optFileType.isPresent()) {
        LOGGER.warn("No file type with extension 'pdf' registered.");
        return;
    }
    ExternalFileType fileType = optFileType.get();
    // Show dialog
    if (!showLinkMoveCopyRenameDialog(fileName, fileType, entry, panel.getDatabase())) {
        return;
    }
    /*
         * Ok, we're ready to go. See first if we need to do a file copy before
         * linking:
         */
    boolean success = true;
    String destFilename;
    NamedCompound edits = new NamedCompound(Localization.lang("Drop %0", fileType.getExtension()));
    if (linkInPlace.isSelected()) {
        destFilename = FileUtil.shortenFileName(Paths.get(fileName), panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())).toString();
    } else {
        destFilename = renameCheckBox.isSelected() ? renameToTextBox.getText() : new File(fileName).getName();
        if (copyRadioButton.isSelected()) {
            success = doCopy(fileName, destFilename, edits);
        } else if (moveRadioButton.isSelected()) {
            success = doMove(fileName, destFilename, edits);
        }
    }
    if (success) {
        doLink(entry, fileType, destFilename, false, edits);
        panel.markBaseChanged();
    }
    edits.end();
    panel.getUndoManager().addEdit(edits);
}
Also used : ExternalFileType(org.jabref.gui.externalfiletype.ExternalFileType) NamedCompound(org.jabref.gui.undo.NamedCompound) File(java.io.File)

Example 17 with NamedCompound

use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.

the class AppendDatabaseAction method mergeFromBibtex.

private static void mergeFromBibtex(BasePanel panel, ParserResult parserResult, boolean importEntries, boolean importStrings, boolean importGroups, boolean importSelectorWords) throws KeyCollisionException {
    BibDatabase fromDatabase = parserResult.getDatabase();
    List<BibEntry> appendedEntries = new ArrayList<>();
    List<BibEntry> originalEntries = new ArrayList<>();
    BibDatabase database = panel.getDatabase();
    NamedCompound ce = new NamedCompound(Localization.lang("Append library"));
    MetaData meta = parserResult.getMetaData();
    if (importEntries) {
        // Add entries
        boolean overwriteOwner = Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_OWNER);
        boolean overwriteTimeStamp = Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_TIME_STAMP);
        for (BibEntry originalEntry : fromDatabase.getEntries()) {
            BibEntry entry = (BibEntry) originalEntry.clone();
            UpdateField.setAutomaticFields(entry, overwriteOwner, overwriteTimeStamp, Globals.prefs.getUpdateFieldPreferences());
            database.insertEntry(entry);
            appendedEntries.add(entry);
            originalEntries.add(originalEntry);
            ce.addEdit(new UndoableInsertEntry(database, entry, panel));
        }
    }
    if (importStrings) {
        for (BibtexString bs : fromDatabase.getStringValues()) {
            if (!database.hasStringLabel(bs.getName())) {
                database.addString(bs);
                ce.addEdit(new UndoableInsertString(panel, database, bs));
            }
        }
    }
    if (importGroups) {
        meta.getGroups().ifPresent(newGroups -> {
            if (newGroups.getGroup() instanceof AllEntriesGroup) {
                try {
                    ExplicitGroup group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT, Globals.prefs.getKeywordDelimiter());
                    newGroups.setGroup(group);
                    group.add(appendedEntries);
                } catch (IllegalArgumentException e) {
                    LOGGER.error(e);
                }
            }
            addGroups(newGroups, ce);
        });
    }
    if (importSelectorWords) {
        for (ContentSelector selector : meta.getContentSelectorList()) {
            panel.getBibDatabaseContext().getMetaData().addContentSelector(selector);
        }
    }
    ce.end();
    panel.getUndoManager().addEdit(ce);
    panel.markBaseChanged();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) BibtexString(org.jabref.model.entry.BibtexString) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) UndoableInsertString(org.jabref.gui.undo.UndoableInsertString) NamedCompound(org.jabref.gui.undo.NamedCompound) MetaData(org.jabref.model.metadata.MetaData) ContentSelector(org.jabref.model.metadata.ContentSelector) BibDatabase(org.jabref.model.database.BibDatabase)

Example 18 with NamedCompound

use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.

the class MergeEntriesDialog method init.

/**
     * Sets up the dialog
     *
     * @param selected Selected BibtexEntries
     */
private void init(List<BibEntry> selected) {
    // Check if there are two entries selected
    if (selected.size() != 2) {
        // None selected. Inform the user to select entries first.
        JOptionPane.showMessageDialog(panel.frame(), Localization.lang("You have to choose exactly two entries to merge."), MERGE_ENTRIES, JOptionPane.INFORMATION_MESSAGE);
        this.dispose();
        return;
    }
    // Store the two entries
    BibEntry one = selected.get(0);
    BibEntry two = selected.get(1);
    MergeEntries mergeEntries = new MergeEntries(one, two, panel.getBibDatabaseContext().getMode());
    // Create undo-compound
    NamedCompound ce = new NamedCompound(MERGE_ENTRIES);
    FormLayout layout = new FormLayout("fill:700px:grow", "fill:400px:grow, 4px, p, 5px, p");
    this.setLayout(layout);
    this.add(mergeEntries.getMergeEntryPanel(), cc.xy(1, 1));
    this.add(new JSeparator(), cc.xy(1, 3));
    // Create buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton cancel = new JButton(Localization.lang("Cancel"));
    cancel.setActionCommand("cancel");
    cancel.addActionListener(e -> {
        panel.output(Localization.lang("Canceled merging entries"));
        dispose();
    });
    JButton replaceentries = new JButton(MERGE_ENTRIES);
    replaceentries.setActionCommand("replace");
    replaceentries.addActionListener(e -> {
        BibEntry mergedEntry = mergeEntries.getMergeEntry();
        panel.insertEntry(mergedEntry);
        ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry, panel));
        ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), one, panel));
        panel.getDatabase().removeEntry(one);
        ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), two, panel));
        panel.getDatabase().removeEntry(two);
        ce.end();
        panel.getUndoManager().addEdit(ce);
        panel.output(Localization.lang("Merged entries"));
        dispose();
    });
    bb.addButton(new JButton[] { replaceentries, cancel });
    this.add(bb.getPanel(), cc.xy(1, 5));
    // Add some margin around the layout
    layout.appendRow(RowSpec.decode(MARGIN));
    layout.appendColumn(ColumnSpec.decode(MARGIN));
    layout.insertRow(1, RowSpec.decode(MARGIN));
    layout.insertColumn(1, ColumnSpec.decode(MARGIN));
    WindowLocation pw = new WindowLocation(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y);
    pw.displayWindowAtStoredLocation();
    // Show what we've got
    setVisible(true);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JButton(javax.swing.JButton) UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry) WindowLocation(org.jabref.gui.util.WindowLocation) JSeparator(javax.swing.JSeparator) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry)

Example 19 with NamedCompound

use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.

the class MergeFetchedEntryDialog method init.

/**
     * Sets up the dialog
     */
private void init() {
    mergeEntries = new MergeEntries(this.originalEntry, this.fetchedEntry, Localization.lang("Original entry"), Localization.lang("Entry from %0", type), panel.getBibDatabaseContext().getMode());
    // Create undo-compound
    ce = new NamedCompound(Localization.lang("Merge entry with %0 information", type));
    FormLayout layout = new FormLayout("fill:700px:grow", "fill:400px:grow, 4px, p, 5px, p");
    this.setLayout(layout);
    this.add(mergeEntries.getMergeEntryPanel(), cc.xy(1, 1));
    this.add(new JSeparator(), cc.xy(1, 3));
    // Create buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton cancel = new JButton(new CancelAction());
    JButton replaceEntry = new JButton(new ReplaceAction());
    bb.addButton(replaceEntry, cancel);
    this.add(bb.getPanel(), cc.xy(1, 5));
    // Add some margin around the layout
    layout.appendRow(RowSpec.decode(MARGIN));
    layout.appendColumn(ColumnSpec.decode(MARGIN));
    layout.insertRow(1, RowSpec.decode(MARGIN));
    layout.insertColumn(1, ColumnSpec.decode(MARGIN));
    WindowLocation pw = new WindowLocation(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y);
    pw.displayWindowAtStoredLocation();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) NamedCompound(org.jabref.gui.undo.NamedCompound) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JButton(javax.swing.JButton) WindowLocation(org.jabref.gui.util.WindowLocation) JSeparator(javax.swing.JSeparator)

Example 20 with NamedCompound

use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.

the class MarkEntriesAction method run.

@Override
public void run() {
    BasePanel panel = frame.getCurrentBasePanel();
    if (panel != null) {
        List<BibEntry> bes = panel.getSelectedEntries();
        // used at update() to determine output string
        besLength = bes.size();
        if (!bes.isEmpty()) {
            NamedCompound ce = new NamedCompound(Localization.lang("Mark entries"));
            for (BibEntry be : bes) {
                EntryMarker.markEntry(be, level + 1, false, ce);
            }
            ce.end();
            panel.getUndoManager().addEdit(ce);
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) NamedCompound(org.jabref.gui.undo.NamedCompound)

Aggregations

NamedCompound (org.jabref.gui.undo.NamedCompound)34 BibEntry (org.jabref.model.entry.BibEntry)27 UndoableFieldChange (org.jabref.gui.undo.UndoableFieldChange)11 FieldChange (org.jabref.model.FieldChange)7 ArrayList (java.util.ArrayList)5 BasePanel (org.jabref.gui.BasePanel)5 UndoableInsertEntry (org.jabref.gui.undo.UndoableInsertEntry)4 UndoableKeyChange (org.jabref.gui.undo.UndoableKeyChange)4 UndoableRemoveEntry (org.jabref.gui.undo.UndoableRemoveEntry)3 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)2 FormLayout (com.jgoodies.forms.layout.FormLayout)2 IOException (java.io.IOException)2 List (java.util.List)2 JButton (javax.swing.JButton)2 JSeparator (javax.swing.JSeparator)2 ExternalFileType (org.jabref.gui.externalfiletype.ExternalFileType)2 UndoableChangeType (org.jabref.gui.undo.UndoableChangeType)2 WindowLocation (org.jabref.gui.util.WindowLocation)2 CheckBoxMessage (org.jabref.gui.util.component.CheckBoxMessage)2 ParserResult (org.jabref.logic.importer.ParserResult)2