Skip to content
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

Replace Reimplement MappedList.kt #3032

Merged
merged 3 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ dependencies {
compile 'de.codecentric.centerdevice:javafxsvg:1.2.1'
compile 'org.controlsfx:controlsfx:8.40.12'
compile 'org.fxmisc.easybind:easybind:1.0.3'
compile('net.corda:jfx:0.12.1') {
transitive = false
}
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.3' // required by net.corda:jfxc


compile 'org.fxmisc.flowless:flowless:0.5.2'
compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4'
compile 'org.fxmisc.richtext:richtextfx:0.7-M5'
Expand Down
5 changes: 0 additions & 5 deletions external-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ Project: EasyBind
URL: https://github.com/TomasMikula/EasyBind
License: BSD-2-Clause

Id: net.corda:jfx
Project: Corda
URL: https://github.com/corda/corda/tree/master/client/jfx
License: Apache-2.0

Id: org.fxmisc.flowless:flowless
Project: Flowless
URL: https://github.com/TomasMikula/Flowless
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/jabref/gui/util/BindingsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import javafx.css.PseudoClass;
import javafx.scene.Node;

import net.corda.client.jfx.utils.MappedList;


/**
* Helper methods for javafx binding.
Expand Down Expand Up @@ -67,8 +65,8 @@ public String getName() {
* the items are converted when the are inserted (and at the initialization) instead of when they are accessed.
* Thus the initial CPU overhead and memory consumption is higher but the access to list items is quicker.
*/
public static <A, B> ObservableList<B> mapBacked(ObservableList<A> source, Function<A, B> mapper) {
return new MappedList<>(source, mapper::apply);
public static <A, B> MappedList mapBacked(ObservableList<A> source, Function<A, B> mapper) {
return new MappedList<>(source, mapper);
}

/**
Expand Down Expand Up @@ -154,7 +152,7 @@ public ChangeListener<? super B> getChangeListenerB() {
public void changedA(ObservableValue<? extends A> observable, A oldValue, A newValue) {
updateLocked(updateB, oldValue, newValue);
}

public void changedB(ObservableValue<? extends B> observable, B oldValue, B newValue) {
updateLocked(updateA, oldValue, newValue);
}
Expand Down
113 changes: 113 additions & 0 deletions src/main/java/org/jabref/gui/util/MappedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.jabref.gui.util;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.transformation.TransformationList;

/**
* MappedList implementation based on https://gist.github.com/TomasMikula/8883719
*
* @author https://github.com/TomasMikula
*/
public final class MappedList<A, B> extends TransformationList<A, B> {

private final Function<B, A> mapper;

public MappedList(ObservableList<? extends B> sourceList, Function<B, A> mapper) {
super(sourceList);
this.mapper = mapper;
}

@Override
protected void sourceChanged(ListChangeListener.Change<? extends B> change) {
fireChange(new ListChangeListener.Change<A>(this) {

@Override
public boolean wasAdded() {
return change.wasAdded();
}

@Override
public boolean wasRemoved() {
return change.wasRemoved();
}

@Override
public boolean wasReplaced() {
return change.wasReplaced();
}

@Override
public boolean wasUpdated() {
return change.wasUpdated();
}

@Override
public boolean wasPermutated() {
return change.wasPermutated();
}

@Override
public int getPermutation(int index) {
return change.getPermutation(index);
}

@Override
protected int[] getPermutation() {
// This method is only called by the superclass methods
// wasPermutated() and getPermutation(int), which are
// both overridden by this class. There is no other way
// this method can be called.
throw new AssertionError("Unreachable code");
}

@Override
public List<A> getRemoved() {
List<A> result = new ArrayList<>(change.getRemovedSize());
for (B element : change.getRemoved()) {
result.add(mapper.apply(element));
}
return result;
}

@Override
public int getFrom() {
return change.getFrom();
}

@Override
public int getTo() {
return change.getTo();
}

@Override
public boolean next() {
return change.next();
}

@Override
public void reset() {
change.reset();
}
});
}

@Override
public int getSourceIndex(int index) {
return index;
}

@Override
public A get(int index) {
return mapper.apply(super.getSource().get(index));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation of the MappedList looks identical to the one in the EasyBind package but is different from MappedList.kt.
The mapped list from the corda package runs the mapper when the item is inserted/updated while this implementation here invokes the mapper on every get-call. Since the get method is called relatively often (e.g. if you scroll in the listview), the EasyBind implementation should only be used for quick mappers. Can you please revert the change and/or write a direct reimplementation of the corda mapped list since we otherwise run again in performance problems with huge groups trees.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will do!

}

@Override
public int size() {
return super.getSource().size();
}
}