Skip to content

Commit

Permalink
t pushMerge branch 'master' of https://github.com/JabRef/jabref
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Jul 20, 2017
2 parents 53589c2 + bee715d commit d848baa
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 15 deletions.
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
maven {
url 'http://maven.ej-technologies.com/repository'
url 'https://maven.ej-technologies.com/repository'
}
}
dependencies {
Expand Down Expand Up @@ -113,10 +113,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));
}

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

0 comments on commit d848baa

Please sign in to comment.