Skip to content

Commit

Permalink
feat: add CollectableHelper#updateUnderlayModel
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Feb 16, 2024
1 parent 200056b commit c3c6d37
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/viewtify/preference/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.function.Consumer;
import java.util.function.Function;

import javafx.collections.ObservableList;
import kiss.Extensible;
import kiss.I;
import kiss.Model;
Expand Down Expand Up @@ -240,7 +241,7 @@ public static <P extends Preferences> P of(Class<P> type, String name) {
* @param type
* @return
*/
public static <P extends Preferences> List<P> all(Class<P> type) {
public static <P extends Preferences> ObservableList<P> all(Class<P> type) {
return CACHE_LIST.computeIfAbsent(type, PreferencesList::new);
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/viewtify/ui/AbstractPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public abstract class AbstractPane<E, P extends Pane, Self extends AbstractPane>
/** The model modifier. */
private final ListChangeListener<E> modelModifier = c -> {
while (c.next()) {
System.out.println(c);
if (c.wasPermutated()) {
Map<Integer, Integer> mapping = new HashMap();
for (int i = c.getFrom(); i < c.getTo(); i++) {
Expand Down Expand Up @@ -136,7 +137,12 @@ private void addUI(Iterable<? extends E> models) {
views.put(added, view);
animator.observe(node);

ui.getChildren().add(this.models.get().indexOf(added), node);
int index = this.models.get().indexOf(added);
if (index == -1) {
ui.getChildren().add(node);
} else {
ui.getChildren().add(index, node);
}

ShowAnime.FadeIn(1).run(ui, node);
}
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/viewtify/ui/helper/CollectableHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;

import kiss.Disposable;
import kiss.I;
import kiss.Signal;
Expand Down Expand Up @@ -937,6 +936,18 @@ default Self reapply() {
return (Self) this;
}

/**
* Update the original {@link ObservableList}, which should not normally be touched.
*
* @param newList
*/
default Self updateUnderlayModel(ObservableList<E> newList) {
if (newList != null) {
refer().items.setValue(newList);
}
return (Self) this;
}

/**
* Retrieve the special reference holder.
*
Expand Down

0 comments on commit c3c6d37

Please sign in to comment.