Run Designer previews with application-owned DI adapters
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import de.neitzel.fx.view.ViewDependencies;
|
||||
import de.neitzel.fx.view.ViewObject;
|
||||
import de.neitzel.fxdesigner.preview.ExampleDescriptor;
|
||||
import de.neitzel.fxdesigner.preview.PreviewProvider;
|
||||
import de.neitzel.fxdesigner.preview.PreviewSession;
|
||||
import java.util.Optional;
|
||||
import de.neitzel.fxdesigner.target.PreviewFailure;
|
||||
import de.neitzel.fxdesigner.target.TargetPreview;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javafx.application.Platform;
|
||||
|
||||
/** Runs against FX 1.0.6 without linking the newer adapter types in the launcher. */
|
||||
public final class CapabilityCheck {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Platform.startup(() -> Platform.setImplicitExit(false));
|
||||
try {
|
||||
var descriptor = new ExampleDescriptor("book", "Missing adapter", "java.lang.String",
|
||||
"CapabilityCheck$Provider", "Book.fxml", "fixture");
|
||||
try (var target = TargetPreview.open(descriptor, CapabilityCheck.class.getClassLoader(), Duration.ofSeconds(20))) {
|
||||
try {
|
||||
target.ready().toCompletableFuture().get(20, TimeUnit.SECONDS);
|
||||
throw new AssertionError("Expected missing FX adapter API");
|
||||
} catch (ExecutionException failure) {
|
||||
var diagnostic = (PreviewFailure) failure.getCause();
|
||||
if (diagnostic.code() != PreviewFailure.Code.CONTEXT_TYPE
|
||||
|| !diagnostic.getMessage().contains("1.0.7")) throw new AssertionError(diagnostic);
|
||||
}
|
||||
target.cleanup().toCompletableFuture().get(5, TimeUnit.SECONDS);
|
||||
System.out.println("PASS missing-capability 1");
|
||||
}
|
||||
} finally {
|
||||
Platform.exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Linking this Provider itself needs the new interface, before opening any preview session.
|
||||
public static final class Provider implements PreviewProvider<String, ViewDependencies>, ViewDependencies {
|
||||
public Class<String> modelType() { return String.class; }
|
||||
|
||||
public PreviewSession<String, ViewDependencies> open(String id) {
|
||||
throw new AssertionError("Provider unexpectedly loaded with the old FX runtime");
|
||||
}
|
||||
|
||||
public boolean isComponent(Class<?> type) { return false; }
|
||||
|
||||
public <T> Optional<T> findService(Class<T> type) { return Optional.empty(); }
|
||||
|
||||
public <T> ViewObject<T> createViewObject(Class<T> type) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user