AddEventSystem#1028
Conversation
|
Issue: #969 |
|
This commit should also demonstrate the structure of the new event system. Discussions are welcome. |
|
I just want to point out that there is an event system for BibDatabase. Which is not that much used. Maybe it can be used as inspiration/replaced. |
|
This does demonstrate how the API of Google Guava works, but not how it can really be used at JabRef. Should we use one bus for everything? Should we use one bus per "thing" such as BibDatabase etc. - This is also discussed at the documentation. Please double check the usage of Thus, please update this PR to
|
|
Yes, it actually only demonstrates the base function. I think we should have a separate package for that. So I created a new one and created a interface, which should normalize the usage of Google guava. Now we are going to replace the existing listeners and as @koppor already observed to prepare a global event bus. |
|
Mhh...I'm not sure that a global event bus is the right way to go. It adds another global object, makes debugging harder, everyone gets informed about everything (it is hard to listen only to changes to a certain database) etc. But of course it also has its advantages. What is the opinion of the other @JabRef/developers here? |
|
I think its OK to use one. Therefore we use different |
|
On the one hand, I don't like to pass around the EventBus object everywhere. It is a global thing and used everywhere. Maybe we should place it in On the other hand, I agree that a global object makes testing difficult. Let's hear about design ideas by the others. This, however, doesn't stop @obraliar replacing the old event system. The "location" of the EventBus object can be changed later on. |
| * to pass objects on event occurrence. | ||
| */ | ||
|
|
||
| public class Event { |
There was a problem hiding this comment.
Why not use https://docs.oracle.com/javase/7/docs/api/java/util/EventObject.html for this?
There was a problem hiding this comment.
Oh, I didn't know that there is a existing class for this purpose :)
There was a problem hiding this comment.
I see no reason for using java-util. We are implementing something contrary when using Guava. The only argument I see is that we can trace which events are existing. For that thing, I would agree to define an abstract class JabRefEvent.
There was a problem hiding this comment.
I agree with @koppor From the api doc the EventObject looks like that is's main purpose is to be used in GUI swing/awt events.
|
@obraliar Please do not take further action until @JabRef/developers decided which way to go. |
|
No opinions? If not, we would begin to discuss the details internally within the stupro group. |
|
Sorry, but (in contrast to other developers) I do not see why we need an event system. Everything we need should be doable with the plain old observer pattern and the benefit of an event bus is not clear to me. This will be discussed in a devcall, which may or may not take place soon. |
2e8afac to
7ad383a
Compare
8ce8ea5 to
8e34f7d
Compare
|
Now all entry events only base upon Google's Guava Bus System. Here are some new findings:
|
| this.setType(type.getName()); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Why is the code moved in this class? Could you keep the old position? I think, the move was on purpose. See #1309
There was a problem hiding this comment.
Done. Moved to old position.
| return fieldName; | ||
| } | ||
|
|
||
| public String getValue() { |
There was a problem hiding this comment.
getNewValue and rename private variable.
| if (entry.isPresent() && (entry.get() != newEntry)) { | ||
| entry.ifPresent(e -> e.unregisterListener(this.currentChangeFieldUpdateEvent)); | ||
| this.currentChangeFieldUpdateEvent = new ChangeFieldUpdateEvent(); | ||
| newEntry.registerListener(this.currentChangeFieldUpdateEvent); |
There was a problem hiding this comment.
I think, the registerListener should be moved after the if statement.
There was a problem hiding this comment.
With a check if newEntry is not null.
and use ChangeFieldEvent instead. Remove private listener classes. Small refactorings.
| import net.sf.jabref.model.entry.BibEntry; | ||
|
|
||
| /** | ||
| * <code>ChangedFieldEvent</code> is fired when a field of <code>BibEntry</code> has been modified. |
There was a problem hiding this comment.
Or removed. Or added. See eventBus.post(new ChangedFieldEvent(this, fieldName, null));. Please add this as comment.
|
|
||
| if (entry.isPresent() && (entry.get() != newEntry)) { | ||
| entry.ifPresent(e -> e.unregisterListener(this)); | ||
| } |
There was a problem hiding this comment.
could be written simpler: entry.filter(e -> e != newEntry).ifPresent(e -> e.unregisterListener(this));
|
@JabRef/stupro could you please add some short notes to the wiki on how to push and subscribe to events (using the eventbus). Thanks! |
DatabaseChangeEventabstract and add subclasses according toDatbaseChangeEventnet.sf.jabref.model.database.BibDatabase.addDatabaseChangeListener(DatabaseChangeListener)andnet.sf.jabref.model.database.BibDatabase.removeDatabaseChangeListener(DatabaseChangeListener)