fix controller display error
This commit is contained in:
parent
757444c6b4
commit
e3c75283f3
|
@ -10,6 +10,7 @@ import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||||
import com.tungsten.fclcore.fakefx.beans.property.ReadOnlyListProperty;
|
import com.tungsten.fclcore.fakefx.beans.property.ReadOnlyListProperty;
|
||||||
import com.tungsten.fclcore.fakefx.beans.property.ReadOnlyListWrapper;
|
import com.tungsten.fclcore.fakefx.beans.property.ReadOnlyListWrapper;
|
||||||
import com.tungsten.fclcore.fakefx.collections.ObservableList;
|
import com.tungsten.fclcore.fakefx.collections.ObservableList;
|
||||||
|
import com.tungsten.fclcore.task.Schedulers;
|
||||||
import com.tungsten.fclcore.util.Logging;
|
import com.tungsten.fclcore.util.Logging;
|
||||||
import com.tungsten.fclcore.util.gson.fakefx.factories.JavaFxPropertyTypeAdapterFactory;
|
import com.tungsten.fclcore.util.gson.fakefx.factories.JavaFxPropertyTypeAdapterFactory;
|
||||||
import com.tungsten.fclcore.util.io.FileUtils;
|
import com.tungsten.fclcore.util.io.FileUtils;
|
||||||
|
@ -19,6 +20,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -31,6 +33,8 @@ public class Controllers {
|
||||||
private static final ReadOnlyListWrapper<Controller> controllersWrapper = new ReadOnlyListWrapper<>(controllers);
|
private static final ReadOnlyListWrapper<Controller> controllersWrapper = new ReadOnlyListWrapper<>(controllers);
|
||||||
public static Controller DEFAULT_CONTROLLER;
|
public static Controller DEFAULT_CONTROLLER;
|
||||||
|
|
||||||
|
private static final List<Consumer<Void>> CALLBACKS = new ArrayList<>();
|
||||||
|
|
||||||
public static void checkControllers() {
|
public static void checkControllers() {
|
||||||
if (controllers.contains(null)) {
|
if (controllers.contains(null)) {
|
||||||
controllers.remove(null);
|
controllers.remove(null);
|
||||||
|
@ -98,6 +102,9 @@ public class Controllers {
|
||||||
checkControllers();
|
checkControllers();
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
CALLBACKS.forEach(callback -> {
|
||||||
|
Schedulers.androidUIThread().execute(()->callback.accept(null));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<Controller> getControllersFromDisk() {
|
private static ArrayList<Controller> getControllersFromDisk() {
|
||||||
|
@ -150,4 +157,12 @@ public class Controllers {
|
||||||
return controllers.stream().filter(it -> it.getName().equals(name)).findFirst().orElse(controllers.get(0));
|
return controllers.stream().filter(it -> it.getName().equals(name)).findFirst().orElse(controllers.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addCallback(Consumer<Void> consumer) {
|
||||||
|
if (initialized) {
|
||||||
|
consumer.accept(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CALLBACKS.add(consumer);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,33 +42,14 @@ import com.tungsten.fcllibrary.component.view.FCLUILayout;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ControllerUI extends FCLCommonUI implements View.OnClickListener {
|
public class ControllerUI extends FCLCommonUI implements View.OnClickListener {
|
||||||
|
|
||||||
private final BooleanProperty refreshProperty = new SimpleBooleanProperty(false);
|
private final BooleanProperty refreshProperty = new SimpleBooleanProperty(false);
|
||||||
|
|
||||||
private final ObjectProperty<Controller> selectedController = new SimpleObjectProperty<Controller>() {
|
private ObjectProperty<Controller> selectedController;
|
||||||
{
|
|
||||||
Controllers.getControllers().addListener(onInvalidating(this::invalidated));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void invalidated() {
|
|
||||||
if (!Controllers.isInitialized()) return;
|
|
||||||
|
|
||||||
Controller controller = get();
|
|
||||||
if (Controllers.getControllers().isEmpty()) {
|
|
||||||
if (controller != null) {
|
|
||||||
set(null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!Controllers.getControllers().contains(controller)) {
|
|
||||||
set(Controllers.getControllers().get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public Controller getSelectedController() {
|
public Controller getSelectedController() {
|
||||||
return selectedController.get();
|
return selectedController.get();
|
||||||
|
@ -94,8 +75,34 @@ public class ControllerUI extends FCLCommonUI implements View.OnClickListener {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
Controllers.addCallback(unused -> {
|
||||||
|
init();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (Controllers.controllersProperty().size() != 0) {
|
private void init() {
|
||||||
|
selectedController = new SimpleObjectProperty<Controller>() {
|
||||||
|
{
|
||||||
|
Controllers.getControllers().addListener(onInvalidating(this::invalidated));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void invalidated() {
|
||||||
|
if (!Controllers.isInitialized()) return;
|
||||||
|
|
||||||
|
Controller controller = get();
|
||||||
|
if (Controllers.getControllers().isEmpty()) {
|
||||||
|
if (controller != null) {
|
||||||
|
set(null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!Controllers.getControllers().contains(controller)) {
|
||||||
|
set(Controllers.getControllers().get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (!Controllers.controllersProperty().isEmpty()) {
|
||||||
selectedController.set(Controllers.controllersProperty().get(0));
|
selectedController.set(Controllers.controllersProperty().get(0));
|
||||||
} else {
|
} else {
|
||||||
selectedController.set(Controllers.DEFAULT_CONTROLLER);
|
selectedController.set(Controllers.DEFAULT_CONTROLLER);
|
||||||
|
|
Loading…
Reference in New Issue