Search in sources :

Example 1 with UndoableRemoveEntry

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

the class BasePanel method delete.

/**
     * Removes the selected entries from the database
     * @param cut If false the user will get asked if he really wants to delete the entries, and it will be localized
     *            as "deleted".
     *            If true the action will be localized as "cut"
     */
private void delete(boolean cut) {
    List<BibEntry> entries = mainTable.getSelectedEntries();
    if (entries.isEmpty()) {
        return;
    }
    if (!cut && !showDeleteConfirmationDialog(entries.size())) {
        return;
    }
    // select the next entry to stay at the same place as before (or the previous if we're already at the end)
    if (mainTable.getSelectedRow() != (mainTable.getRowCount() - 1)) {
        selectNextEntry();
    } else {
        selectPreviousEntry();
    }
    NamedCompound compound;
    if (cut) {
        compound = new NamedCompound((entries.size() > 1 ? Localization.lang("cut entries") : Localization.lang("cut entry")));
    } else {
        compound = new NamedCompound((entries.size() > 1 ? Localization.lang("delete entries") : Localization.lang("delete entry")));
    }
    for (BibEntry entry : entries) {
        compound.addEdit(new UndoableRemoveEntry(bibDatabaseContext.getDatabase(), entry, BasePanel.this));
        bibDatabaseContext.getDatabase().removeEntry(entry);
        ensureNotShowingBottomPanel(entry);
    }
    compound.end();
    getUndoManager().addEdit(compound);
    markBaseChanged();
    frame.output(formatOutputMessage(cut ? Localization.lang("Cut") : Localization.lang("Deleted"), entries.size()));
    // prevent the main table from loosing focus
    mainTable.requestFocus();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry)

Example 2 with UndoableRemoveEntry

use of org.jabref.gui.undo.UndoableRemoveEntry 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 3 with UndoableRemoveEntry

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

the class EntryDeleteChange method makeChange.

@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
    panel.getDatabase().removeEntry(memEntry);
    undoEdit.addEdit(new UndoableRemoveEntry(panel.getDatabase(), memEntry, panel));
    secondary.removeEntry(tmpEntry);
    return true;
}
Also used : UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry)

Example 4 with UndoableRemoveEntry

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

the class DuplicateSearch method run.

@Override
public void run() {
    panel.output(Localization.lang("Searching for duplicates..."));
    bes = panel.getDatabase().getEntries();
    if (bes.size() < 2) {
        return;
    }
    SearcherRunnable st = new SearcherRunnable();
    JabRefExecutorService.INSTANCE.executeInterruptableTask(st, "DuplicateSearcher");
    int current = 0;
    final List<BibEntry> toRemove = new ArrayList<>();
    final List<BibEntry> toAdd = new ArrayList<>();
    int duplicateCounter = 0;
    boolean autoRemoveExactDuplicates = false;
    synchronized (duplicates) {
        while (!st.finished() || (current < duplicates.size())) {
            if (current >= duplicates.size()) {
                try {
                    duplicates.wait();
                } catch (InterruptedException ignored) {
                // Ignore
                }
            } else {
                // duplicates found
                List<BibEntry> be = duplicates.get(current);
                current++;
                if (!toRemove.contains(be.get(0)) && !toRemove.contains(be.get(1))) {
                    // Check if they are exact duplicates:
                    boolean askAboutExact = false;
                    if (DuplicateCheck.compareEntriesStrictly(be.get(0), be.get(1)) > 1) {
                        if (autoRemoveExactDuplicates) {
                            toRemove.add(be.get(1));
                            duplicateCounter++;
                            continue;
                        }
                        askAboutExact = true;
                    }
                    DuplicateCallBack cb = new DuplicateCallBack(JabRefGUI.getMainFrame(), be.get(0), be.get(1), askAboutExact ? DuplicateResolverType.DUPLICATE_SEARCH_WITH_EXACT : DuplicateResolverType.DUPLICATE_SEARCH);
                    ((CallBack) Spin.over(cb)).update();
                    duplicateCounter++;
                    DuplicateResolverResult answer = cb.getSelected();
                    if ((answer == DuplicateResolverResult.KEEP_LEFT) || (answer == DuplicateResolverResult.AUTOREMOVE_EXACT)) {
                        toRemove.add(be.get(1));
                        if (answer == DuplicateResolverResult.AUTOREMOVE_EXACT) {
                            // Remember choice
                            autoRemoveExactDuplicates = true;
                        }
                    } else if (answer == DuplicateResolverResult.KEEP_RIGHT) {
                        toRemove.add(be.get(0));
                    } else if (answer == DuplicateResolverResult.BREAK) {
                        // thread killing
                        st.setFinished();
                        current = Integer.MAX_VALUE;
                        // correct counter
                        duplicateCounter--;
                    } else if (answer == DuplicateResolverResult.KEEP_MERGE) {
                        toRemove.addAll(be);
                        toAdd.add(cb.getMergedEntry());
                    }
                }
            }
        }
    }
    final NamedCompound ce = new NamedCompound(Localization.lang("duplicate removal"));
    final int dupliC = duplicateCounter;
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            // Now, do the actual removal:
            if (!toRemove.isEmpty()) {
                for (BibEntry entry : toRemove) {
                    panel.getDatabase().removeEntry(entry);
                    ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), entry, panel));
                }
                panel.markBaseChanged();
            }
            // and adding merged entries:
            if (!toAdd.isEmpty()) {
                for (BibEntry entry : toAdd) {
                    panel.getDatabase().insertEntry(entry);
                    ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry, panel));
                }
                panel.markBaseChanged();
            }
            synchronized (duplicates) {
                panel.output(Localization.lang("Duplicates found") + ": " + duplicates.size() + ' ' + Localization.lang("pairs processed") + ": " + dupliC);
            }
            ce.end();
            panel.getUndoManager().addEdit(ce);
        }
    });
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) CallBack(org.jabref.gui.worker.CallBack) ArrayList(java.util.ArrayList) UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) DuplicateResolverResult(org.jabref.gui.DuplicateResolverDialog.DuplicateResolverResult)

Example 5 with UndoableRemoveEntry

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

the class SharedDatabaseUIManager method listen.

@Subscribe
public void listen(SharedEntryNotPresentEvent event) {
    BasePanel panel = jabRefFrame.getCurrentBasePanel();
    EntryEditor entryEditor = panel.getCurrentEditor();
    panel.getUndoManager().addEdit(new UndoableRemoveEntry(panel.getDatabase(), event.getBibEntry(), panel));
    if (Objects.nonNull(entryEditor) && (entryEditor.getEntry() == event.getBibEntry())) {
        JOptionPane.showMessageDialog(jabRefFrame, Localization.lang("The BibEntry you currently work on has been deleted on the shared side.") + "\n" + Localization.lang("You can restore the entry using the \"Undo\" operation."), Localization.lang("Shared entry is no longer present"), JOptionPane.INFORMATION_MESSAGE);
        SwingUtilities.invokeLater(() -> panel.hideBottomComponent());
    }
}
Also used : EntryEditor(org.jabref.gui.entryeditor.EntryEditor) BasePanel(org.jabref.gui.BasePanel) UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

UndoableRemoveEntry (org.jabref.gui.undo.UndoableRemoveEntry)5 NamedCompound (org.jabref.gui.undo.NamedCompound)3 BibEntry (org.jabref.model.entry.BibEntry)3 UndoableInsertEntry (org.jabref.gui.undo.UndoableInsertEntry)2 Subscribe (com.google.common.eventbus.Subscribe)1 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 ArrayList (java.util.ArrayList)1 JButton (javax.swing.JButton)1 JSeparator (javax.swing.JSeparator)1 BasePanel (org.jabref.gui.BasePanel)1 DuplicateResolverResult (org.jabref.gui.DuplicateResolverDialog.DuplicateResolverResult)1 EntryEditor (org.jabref.gui.entryeditor.EntryEditor)1 WindowLocation (org.jabref.gui.util.WindowLocation)1 CallBack (org.jabref.gui.worker.CallBack)1