-
-
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
AddEventSystem #1028
Merged
Merged
AddEventSystem #1028
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
51fcd67
Full replacement of the old event handling system
obraliar 6a924a6
Dissolve hierarchical structure and change type.
obraliar d2c2079
Make BibEntry final. Add comments. Add test method.
obraliar 5c3c8e0
Delete redundant empty lines.
obraliar a035ec8
Use IdGernerator and compare BibEntries directly.
obraliar 5a7daa0
Fix test. New abstract class EntryEvent. Fix abbreviations.
obraliar 62e697e
Replace event handling of VetoableChangeListener with event bus.
obraliar 793b914
Add change description to changelog
obraliar 64fcc94
Fix testRemoveEntryEventReceivement().
obraliar 70b2deb
Rename value to newValue
obraliar a3998a9
Add JavaDoc comments. Remove constructor (add definition). Improve va…
obraliar 1342a27
Rename event classes and variables.
obraliar f6605c7
Fix various comments. Remove SpecialFieldUpdateListener
obraliar 740a257
Fix comment.
obraliar 7a38d87
Extend ChangedEntryEvent. Fix comment.
obraliar 7f12e9f
Fix variable names
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.sf.jabref.event; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* <code>EntryAddedEvent</code> is fired when a new <code>BibEntry</code> was added | ||
* to the database. | ||
*/ | ||
|
||
public class EntryAddedEvent extends EntryEvent { | ||
|
||
/** | ||
* @param bibEntry <code>BibEntry</code> object which has been added. | ||
*/ | ||
public EntryAddedEvent(BibEntry bibEntry) { | ||
super(bibEntry); | ||
} | ||
|
||
} |
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,18 @@ | ||
package net.sf.jabref.event; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* <code>EntryChangedEvent</code> is fired when a <code>BibEntry</code> has been changed. | ||
*/ | ||
|
||
public class EntryChangedEvent extends EntryEvent { | ||
|
||
/** | ||
* @param bibEntry <code>BibEntry</code> object the changes were applied on. | ||
*/ | ||
public EntryChangedEvent(BibEntry bibEntry) { | ||
super(bibEntry); | ||
} | ||
|
||
} |
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,23 @@ | ||
package net.sf.jabref.event; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* This abstract class pretends a minimal set of attributes and methods | ||
* which an entry event should have. | ||
*/ | ||
public abstract class EntryEvent { | ||
|
||
private final BibEntry bibEntry; | ||
|
||
/** | ||
* @param bibEntry BibEntry object which is involved in this event | ||
*/ | ||
public EntryEvent(BibEntry bibEntry) { | ||
this.bibEntry = bibEntry; | ||
} | ||
|
||
public BibEntry getBibEntry() { | ||
return this.bibEntry; | ||
} | ||
} |
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,19 @@ | ||
package net.sf.jabref.event; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* <code>RemovedEntryEvent</code> is fired when a <code>BibEntry</code> was removed | ||
* from the database. | ||
*/ | ||
|
||
public class EntryRemovedEvent extends EntryEvent { | ||
|
||
/** | ||
* @param bibEntry <code>BibEntry</code> object which has been removed. | ||
*/ | ||
public EntryRemovedEvent(BibEntry bibEntry) { | ||
super(bibEntry); | ||
} | ||
|
||
} |
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,32 @@ | ||
package net.sf.jabref.event; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* <code>FieldChangedEvent</code> is fired when a field of <code>BibEntry</code> has been modified, removed or added. | ||
*/ | ||
public class FieldChangedEvent extends EntryChangedEvent { | ||
|
||
private final String fieldName; | ||
private final String newValue; | ||
|
||
/** | ||
* @param bibEntry Affected BibEntry object | ||
* @param fieldName Name of field which has been changed | ||
* @param newValue new field value | ||
*/ | ||
public FieldChangedEvent(BibEntry bibEntry, String fieldName, String newValue) { | ||
super(bibEntry); | ||
this.fieldName = fieldName; | ||
this.newValue = newValue; | ||
} | ||
|
||
public String getFieldName() { | ||
return fieldName; | ||
} | ||
|
||
public String getNewValue() { | ||
return newValue; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -21,9 +21,6 @@ | |
import java.awt.Insets; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.print.PrinterException; | ||
import java.beans.PropertyChangeEvent; | ||
import java.beans.PropertyVetoException; | ||
import java.beans.VetoableChangeListener; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.Objects; | ||
|
@@ -53,6 +50,7 @@ | |
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefExecutorService; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.event.FieldChangedEvent; | ||
import net.sf.jabref.exporter.ExportFormats; | ||
import net.sf.jabref.gui.desktop.JabRefDesktop; | ||
import net.sf.jabref.gui.fieldeditors.PreviewPanelTransferHandler; | ||
|
@@ -63,13 +61,15 @@ | |
import net.sf.jabref.logic.search.SearchQueryHighlightListener; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
/** | ||
* Displays an BibEntry using the given layout format. | ||
*/ | ||
public class PreviewPanel extends JPanel implements VetoableChangeListener, SearchQueryHighlightListener, EntryContainer { | ||
public class PreviewPanel extends JPanel | ||
implements SearchQueryHighlightListener, EntryContainer { | ||
|
||
private static final Log LOGGER = LogFactory.getLog(PreviewPanel.class); | ||
|
||
|
@@ -105,7 +105,6 @@ public class PreviewPanel extends JPanel implements VetoableChangeListener, Sear | |
|
||
private Optional<Pattern> highlightPattern = Optional.empty(); | ||
|
||
|
||
/** | ||
* @param databaseContext | ||
* (may be null) Optionally used to resolve strings and for resolving pdf directories for links. | ||
|
@@ -275,16 +274,28 @@ public void setLayout(Layout layout) { | |
} | ||
|
||
public void setEntry(BibEntry newEntry) { | ||
if(entry.isPresent() && (entry.get() != newEntry)) { | ||
entry.ifPresent(e -> e.removePropertyChangeListener(this)); | ||
newEntry.addPropertyChangeListener(this); | ||
|
||
if (entry.isPresent() && (entry.get() != newEntry)) { | ||
entry.ifPresent(e -> e.unregisterListener(this)); | ||
} | ||
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. could be written simpler: |
||
|
||
entry.ifPresent(e -> e.registerListener(this)); | ||
|
||
entry = Optional.ofNullable(newEntry); | ||
|
||
updateLayout(); | ||
update(); | ||
} | ||
|
||
|
||
/** | ||
* Listener for ChangedFieldEvent. | ||
*/ | ||
@Subscribe | ||
public void listen(FieldChangedEvent fieldChangedEvent) { | ||
update(); | ||
} | ||
|
||
@Override | ||
public BibEntry getEntry() { | ||
return this.entry.orElse(null); | ||
|
@@ -311,19 +322,6 @@ private void scrollToTop() { | |
SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar().setValue(0)); | ||
} | ||
|
||
/** | ||
* The PreviewPanel has registered itself as an event listener with the | ||
* currently displayed BibEntry. If the entry changes, an event is | ||
* received here, and we can update the preview immediately. | ||
*/ | ||
@Override | ||
public void vetoableChange(PropertyChangeEvent evt) | ||
throws PropertyVetoException { | ||
// TODO updating here is not really necessary isn't it? | ||
// Only if we are visible. | ||
update(); | ||
} | ||
|
||
@Override | ||
public void highlightPattern(Optional<Pattern> newPattern) { | ||
this.highlightPattern = newPattern; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
doc