-
-
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
Wrapper classes for UI Lists etc that ensure updates on JavaFX thread #5289
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ba94d2
added uithreadaware classes
r0light c902c1f
Merge branch 'master' into ensurejavafxthreadexecution
r0light 96b9aa5
UiThreadHelper package-private and usage of UiThreadListDecorator onl…
r0light 3001c84
added UiThreadStringProperty to be used in PersonsEditor
r0light 4592dca
added comments
r0light 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
28 changes: 28 additions & 0 deletions
28
src/main/java/org/jabref/gui/util/uithreadaware/UiThreadChangeListener.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,28 @@ | ||
package org.jabref.gui.util.uithreadaware; | ||
|
||
import javafx.beans.value.ChangeListener; | ||
import javafx.beans.value.ObservableValue; | ||
|
||
class UiThreadChangeListener<T> implements ChangeListener<T> { | ||
|
||
private ChangeListener<T> delegate; | ||
|
||
public UiThreadChangeListener(ChangeListener<T> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void changed(ObservableValue<? extends T> observable, T oldValue, T newValue) { | ||
UiThreadHelper.ensureUiThreadExecution(() -> delegate.changed(observable, oldValue, newValue)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return delegate.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return delegate.hashCode(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/jabref/gui/util/uithreadaware/UiThreadHelper.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,14 @@ | ||
package org.jabref.gui.util.uithreadaware; | ||
|
||
import javafx.application.Platform; | ||
|
||
class UiThreadHelper { | ||
|
||
static void ensureUiThreadExecution(Runnable task) { | ||
if (Platform.isFxApplicationThread()) { | ||
task.run(); | ||
} else { | ||
Platform.runLater(task); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/jabref/gui/util/uithreadaware/UiThreadInvalidationListener.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,28 @@ | ||
package org.jabref.gui.util.uithreadaware; | ||
|
||
import javafx.beans.InvalidationListener; | ||
import javafx.beans.Observable; | ||
|
||
class UiThreadInvalidationListener implements InvalidationListener { | ||
|
||
private final InvalidationListener delegate; | ||
|
||
public UiThreadInvalidationListener(InvalidationListener delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void invalidated(Observable observable) { | ||
UiThreadHelper.ensureUiThreadExecution(() -> delegate.invalidated(observable)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return delegate.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return delegate.hashCode(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/jabref/gui/util/uithreadaware/UiThreadListChangeListener.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,27 @@ | ||
package org.jabref.gui.util.uithreadaware; | ||
|
||
import javafx.collections.ListChangeListener; | ||
|
||
class UiThreadListChangeListener<E> implements ListChangeListener<E> { | ||
|
||
private final ListChangeListener<E> delegate; | ||
|
||
public UiThreadListChangeListener(ListChangeListener<E> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void onChanged(Change<? extends E> c) { | ||
UiThreadHelper.ensureUiThreadExecution(() -> delegate.onChanged(c)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return delegate.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return delegate.hashCode(); | ||
} | ||
} |
184 changes: 184 additions & 0 deletions
184
src/main/java/org/jabref/gui/util/uithreadaware/UiThreadObservableList.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,184 @@ | ||
package org.jabref.gui.util.uithreadaware; | ||
|
||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.ListIterator; | ||
|
||
import javafx.beans.InvalidationListener; | ||
import javafx.collections.ListChangeListener; | ||
import javafx.collections.ObservableList; | ||
|
||
public class UiThreadObservableList<E> implements ObservableList<E> { | ||
|
||
private final ObservableList<E> delegate; | ||
|
||
public UiThreadObservableList(ObservableList<E> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void addListener(ListChangeListener<? super E> listener) { | ||
delegate.addListener(new UiThreadListChangeListener(listener)); | ||
} | ||
|
||
@Override | ||
public void removeListener(ListChangeListener<? super E> listener) { | ||
delegate.removeListener(listener); | ||
} | ||
|
||
@Override | ||
public boolean addAll(E... elements) { | ||
return delegate.addAll(elements); | ||
} | ||
|
||
@Override | ||
public boolean setAll(E... elements) { | ||
return delegate.setAll(elements); | ||
} | ||
|
||
@Override | ||
public boolean setAll(Collection<? extends E> col) { | ||
return delegate.setAll(col); | ||
} | ||
|
||
@Override | ||
public boolean removeAll(E... elements) { | ||
return delegate.removeAll(elements); | ||
} | ||
|
||
@Override | ||
public boolean retainAll(E... elements) { | ||
return delegate.retainAll(elements); | ||
} | ||
|
||
@Override | ||
public void remove(int from, int to) { | ||
delegate.remove(from, to); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return delegate.size(); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return delegate.isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean contains(Object o) { | ||
return delegate.contains(o); | ||
} | ||
|
||
@Override | ||
public Iterator<E> iterator() { | ||
return delegate.iterator(); | ||
} | ||
|
||
@Override | ||
public Object[] toArray() { | ||
return delegate.toArray(); | ||
} | ||
|
||
@Override | ||
public <T> T[] toArray(T[] a) { | ||
return delegate.toArray(a); | ||
} | ||
|
||
@Override | ||
public boolean add(E e) { | ||
return delegate.add(e); | ||
} | ||
|
||
@Override | ||
public boolean remove(Object o) { | ||
return delegate.remove(o); | ||
} | ||
|
||
@Override | ||
public boolean containsAll(Collection<?> c) { | ||
return delegate.containsAll(c); | ||
} | ||
|
||
@Override | ||
public boolean addAll(Collection<? extends E> c) { | ||
return delegate.addAll(c); | ||
} | ||
|
||
@Override | ||
public boolean addAll(int index, Collection<? extends E> c) { | ||
return delegate.addAll(index, c); | ||
} | ||
|
||
@Override | ||
public boolean removeAll(Collection<?> c) { | ||
return delegate.removeAll(c); | ||
} | ||
|
||
@Override | ||
public boolean retainAll(Collection<?> c) { | ||
return delegate.retainAll(c); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
delegate.clear(); | ||
} | ||
|
||
@Override | ||
public E get(int index) { | ||
return delegate.get(index); | ||
} | ||
|
||
@Override | ||
public E set(int index, E element) { | ||
return delegate.set(index, element); | ||
} | ||
|
||
@Override | ||
public void add(int index, E element) { | ||
delegate.add(index, element); | ||
} | ||
|
||
@Override | ||
public E remove(int index) { | ||
return delegate.remove(index); | ||
} | ||
|
||
@Override | ||
public int indexOf(Object o) { | ||
return delegate.indexOf(o); | ||
} | ||
|
||
@Override | ||
public int lastIndexOf(Object o) { | ||
return delegate.lastIndexOf(o); | ||
} | ||
|
||
@Override | ||
public ListIterator<E> listIterator() { | ||
return delegate.listIterator(); | ||
} | ||
|
||
@Override | ||
public ListIterator<E> listIterator(int index) { | ||
return delegate.listIterator(index); | ||
} | ||
|
||
@Override | ||
public List<E> subList(int fromIndex, int toIndex) { | ||
return delegate.subList(fromIndex, toIndex); | ||
} | ||
|
||
@Override | ||
public void addListener(InvalidationListener listener) { | ||
delegate.addListener(new UiThreadInvalidationListener(listener)); | ||
} | ||
|
||
@Override | ||
public void removeListener(InvalidationListener listener) { | ||
delegate.removeListener(listener); | ||
} | ||
} |
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.
Is it necessary to keep a track of the reference? If not I would prefer if
decoratedStringProperty
is converted to a local variable (or be inlined completely).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.
In fact, i tried it with an inlined approach first, but the list of files did not update itself then.
I did not investigate it further, but i think it has to do with
WeakReference
s used insideBindings.bindContentBidirectional
.