-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of EntryEventlistener.
Functional substitution for fireDatabaseChanged() in BibDatabase.java. Extracting event code to new EntryEventListener. Event passing for GroupTreeUpdater, GlazedEntrySorter, SearchAutoCompleterUpdater and AutoCompletersUpdater. Handle nullpointer errors while testing.
- Loading branch information
Showing
22 changed files
with
393 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.sf.jabref.gui.event; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
public class EntryAddEvent extends Event { | ||
|
||
public EntryAddEvent(BibEntry entry) { | ||
super(entry); | ||
} | ||
|
||
public BibEntry getEntry() { | ||
return (BibEntry) this.getObject(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/sf/jabref/gui/event/EntryChangeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.sf.jabref.gui.event; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
public class EntryChangeEvent extends Event { | ||
|
||
public EntryChangeEvent(BibEntry entry) { | ||
super(entry); | ||
} | ||
|
||
public BibEntry getEntry() { | ||
return (BibEntry) this.getObject(); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/sf/jabref/gui/event/EntryRemoveEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.sf.jabref.gui.event; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
public class EntryRemoveEvent extends Event { | ||
|
||
public EntryRemoveEvent(BibEntry entry) { | ||
super(entry); | ||
} | ||
|
||
public BibEntry getEntry() { | ||
return (BibEntry) this.getObject(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.sf.jabref.gui.event; | ||
|
||
/** | ||
* Represents a medium which can be used | ||
* to pass objects on event occurrence. | ||
*/ | ||
|
||
public class Event { | ||
|
||
private final Object object; | ||
|
||
public Event(Object object) { | ||
this.object = object; | ||
} | ||
|
||
public Object getObject() { | ||
return this.object; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.sf.jabref.gui.event; | ||
|
||
|
||
public class TestEvent extends Event { | ||
|
||
public TestEvent(String eventMesage) { | ||
super(eventMesage); | ||
} | ||
|
||
public String getMessage() { | ||
return (String) this.getObject(); | ||
} | ||
|
||
} |
114 changes: 114 additions & 0 deletions
114
src/main/java/net/sf/jabref/gui/event/listener/EntryEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package net.sf.jabref.gui.event.listener; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import javax.swing.JToggleButton; | ||
import javax.swing.SwingUtilities; | ||
import javax.swing.tree.TreePath; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.groups.GroupSelector; | ||
import net.sf.jabref.groups.GroupTreeNode; | ||
import net.sf.jabref.gui.GlazedEntrySorter; | ||
import net.sf.jabref.gui.event.*; | ||
import net.sf.jabref.logic.autocompleter.AutoCompleter; | ||
import net.sf.jabref.logic.autocompleter.ContentAutoCompleters; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
public class EntryEventListener extends EventListener<Event> { | ||
|
||
private GlazedEntrySorter glazedEntrySorter; | ||
private GroupSelector groupSelector; | ||
private JToggleButton groupToggleBtn; | ||
private AutoCompleter<String> searchAutoCompleter; | ||
private ContentAutoCompleters autoCompleters; | ||
|
||
@Override | ||
@Subscribe | ||
public void listen(Event event) { | ||
return; | ||
} | ||
|
||
@Subscribe | ||
public void listen(EntryAddEvent eae) { | ||
lock(true); | ||
glazedEntrySorter.getTheList().add(eae.getEntry()); | ||
lock(false); | ||
|
||
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP) | ||
&& groupToggleBtn.isSelected()) { | ||
final List<BibEntry> entries = Collections.singletonList(eae.getEntry()); | ||
final TreePath[] selection = groupSelector.getGroupsTree().getSelectionPaths(); | ||
if (selection != null) { | ||
// it is possible that the user selected nothing. Therefore, checked for "!= null" | ||
for (final TreePath tree : selection) { | ||
((GroupTreeNode) tree.getLastPathComponent()).addToGroup(entries); | ||
} | ||
} | ||
//BasePanel.this.updateEntryEditorIfShowing(); // doesn't seem to be necessary | ||
SwingUtilities.invokeLater(() -> groupSelector.valueChanged(null)); | ||
} | ||
|
||
searchAutoCompleter.addBibtexEntry(eae.getEntry()); | ||
|
||
autoCompleters.addEntry(eae.getEntry()); | ||
|
||
} | ||
|
||
|
||
@Subscribe | ||
public void listen(EntryChangeEvent ece) { | ||
lock(true); | ||
int index = glazedEntrySorter.getTheList().indexOf(ece.getEntry()); | ||
if (index != -1) { | ||
// SpecialFieldUtils.syncSpecialFieldsFromKeywords update an entry during | ||
// DatabaseChangeEvent.ADDED_ENTRY | ||
// thus, | ||
glazedEntrySorter.getTheList().set(index, ece.getEntry()); | ||
} | ||
lock(false); | ||
|
||
searchAutoCompleter.addBibtexEntry(ece.getEntry()); | ||
|
||
autoCompleters.addEntry(ece.getEntry()); | ||
} | ||
|
||
@Subscribe | ||
public void listen(EntryRemoveEvent ere) { | ||
lock(true); | ||
glazedEntrySorter.getTheList().remove(ere.getEntry()); | ||
lock(false); | ||
} | ||
|
||
public void setGlazedEntrySorter(GlazedEntrySorter glazedEntrySorter) { | ||
this.glazedEntrySorter = glazedEntrySorter; | ||
} | ||
|
||
public void setGroupSelector(GroupSelector groupSelector) { | ||
this.groupSelector = groupSelector; | ||
} | ||
|
||
public void setGroupToggleBtn(JToggleButton groupToggleBtn) { | ||
this.groupToggleBtn = groupToggleBtn; | ||
} | ||
|
||
public void setSearchAutoCompleter(AutoCompleter<String> searchAutoCompleter) { | ||
this.searchAutoCompleter = searchAutoCompleter; | ||
} | ||
|
||
public void setAutoCompleters(ContentAutoCompleters autoCompleters) { | ||
this.autoCompleters = autoCompleters; | ||
} | ||
|
||
private void lock(boolean lock) { | ||
if (lock) { | ||
glazedEntrySorter.getTheList().getReadWriteLock().writeLock().lock(); | ||
} else { | ||
glazedEntrySorter.getTheList().getReadWriteLock().writeLock().unlock(); | ||
} | ||
} | ||
} |
Oops, something went wrong.