-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor EntryEvents - removal part #5410
Changes from 31 commits
80e8377
48cb7fd
923b40e
a0ffcb5
b08ae88
3a830a8
4e57a46
b990e0d
3122e67
aac840c
90c27f1
a0cafc4
868deed
2afb868
460f44a
f11389e
f535a0b
77ff450
b0805cc
7ac7a1c
8255ad2
3b8dfea
5f1b811
c41dc17
bb88484
4c97c64
30d8d51
5cf5965
1df2869
0f5d76f
13abf0c
17f04b0
214e958
a90c44e
648c5da
b0f585a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
import org.jabref.gui.duplicationFinder.DuplicateResolverDialog.DuplicateResolverType; | ||
import org.jabref.gui.undo.NamedCompound; | ||
import org.jabref.gui.undo.UndoableInsertEntry; | ||
import org.jabref.gui.undo.UndoableRemoveEntry; | ||
import org.jabref.gui.undo.UndoableRemoveEntries; | ||
import org.jabref.gui.util.BackgroundTask; | ||
import org.jabref.gui.util.DefaultTaskExecutor; | ||
import org.jabref.logic.bibtex.DuplicateCheck; | ||
|
@@ -162,10 +162,8 @@ private void handleDuplicates(DuplicateSearchResult result) { | |
final NamedCompound compoundEdit = new NamedCompound(Localization.lang("duplicate removal")); | ||
// Now, do the actual removal: | ||
if (!result.getToRemove().isEmpty()) { | ||
for (BibEntry entry : result.getToRemove()) { | ||
panel.getDatabase().removeEntry(entry); | ||
compoundEdit.addEdit(new UndoableRemoveEntry(panel.getDatabase(), entry)); | ||
} | ||
compoundEdit.addEdit(new UndoableRemoveEntries(panel.getDatabase(), new ArrayList<>(result.getToRemove()))); | ||
panel.getDatabase().removeEntries(new ArrayList<>(result.getToRemove())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just made the change, as I think it's better if |
||
panel.markBaseChanged(); | ||
} | ||
// and adding merged entries: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.jabref.gui.mergeentries; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
|
@@ -10,7 +11,7 @@ | |
import org.jabref.gui.actions.SimpleCommand; | ||
import org.jabref.gui.undo.NamedCompound; | ||
import org.jabref.gui.undo.UndoableInsertEntry; | ||
import org.jabref.gui.undo.UndoableRemoveEntry; | ||
import org.jabref.gui.undo.UndoableRemoveEntries; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
|
@@ -57,10 +58,9 @@ public void execute() { | |
// Remove the other two entries and add them to the undo stack (which is not working...) | ||
NamedCompound ce = new NamedCompound(Localization.lang("Merge entries")); | ||
ce.addEdit(new UndoableInsertEntry(basePanel.getDatabase(), mergedEntry.get())); | ||
ce.addEdit(new UndoableRemoveEntry(basePanel.getDatabase(), one)); | ||
basePanel.getDatabase().removeEntry(one); | ||
ce.addEdit(new UndoableRemoveEntry(basePanel.getDatabase(), two)); | ||
basePanel.getDatabase().removeEntry(two); | ||
List<BibEntry> entriesToRemove = Arrays.asList(one, two); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. I just want to create a |
||
ce.addEdit(new UndoableRemoveEntries(basePanel.getDatabase(), entriesToRemove)); | ||
basePanel.getDatabase().removeEntries(entriesToRemove); | ||
ce.end(); | ||
basePanel.getUndoManager().addEdit(ce); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.jabref.gui.undo; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.event.EntriesEventSource; | ||
import org.jabref.model.strings.StringUtil; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This class represents the removal of entries. The constructor needs | ||
* references to the database, the entries, and the map of open entry editors. | ||
* TODO is this map still being used? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this TODO be resoled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would appear the map is not being used, as there is no reference to entry editors in the class. Am I mistaken? |
||
* The latter to be able to close the entry's editor if it is opened after | ||
* an undo, and the removal is then undone. | ||
*/ | ||
public class UndoableRemoveEntries extends AbstractUndoableJabRefEdit { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(UndoableRemoveEntries.class); | ||
private final BibDatabase base; | ||
private final List<BibEntry> entries; | ||
private final boolean cut; | ||
|
||
public UndoableRemoveEntries(BibDatabase base, BibEntry entry) { | ||
this(base, Collections.singletonList(entry)); | ||
} | ||
|
||
public UndoableRemoveEntries(BibDatabase base, List<BibEntry> entries) { | ||
this(base, entries, false); | ||
} | ||
|
||
public UndoableRemoveEntries(BibDatabase base, List<BibEntry> entries, boolean cut) { | ||
this.base = base; | ||
this.entries = entries; | ||
this.cut = cut; | ||
} | ||
|
||
@Override | ||
public String getPresentationName() { | ||
if (cut) { | ||
if (entries.size() > 1) { | ||
return Localization.lang("cut entries"); | ||
} | ||
else if (entries.size() == 1) { | ||
return Localization.lang("cut entry %0", | ||
StringUtil.boldHTML(entries.get(0).getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
} else { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there something be logged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't thought of that. What do you think? |
||
} | ||
} else { | ||
if (entries.size() > 1) { | ||
return Localization.lang("remove entries"); | ||
} | ||
else if (entries.size() == 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please format the code using JabRef's code style --> The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Let me know if I've fixed it right. Is there a way to get IntelliJ to do this automatically? |
||
return Localization.lang("remove entry %0", | ||
StringUtil.boldHTML(entries.get(0).getCiteKeyOptional().orElse(Localization.lang("undefined")))); | ||
} | ||
else { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there something be logged? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't thought of that. What do you think? |
||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void undo() { | ||
super.undo(); | ||
base.insertEntries(entries, EntriesEventSource.UNDO); | ||
} | ||
|
||
@Override | ||
public void redo() { | ||
super.redo(); | ||
|
||
// Redo the change. | ||
try { | ||
base.removeEntries(entries); | ||
} catch (Throwable ex) { | ||
LOGGER.warn("Problem to redo `remove entries`", ex); | ||
} | ||
} | ||
|
||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the constructor of
UndoableRemoveEntries
accepting a single BibEntry, and similarly the methodBibDatabase#removeEntry
.(Btw, there is
Colections.singletonList(element)
which is preferred overnew ArrayList<>(element)
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that
DuplicateSearch.getToRemove
returns a Collection, not a single one. The only way I found that I could coerce aCollection
to aList
was via theArrayList<>
constructor. I could make a constructor for aCollection
, but that feels to specific.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for the second constructor. Even if very specific, the code with
new ArrayList<>
reads strange.