use of bisq.desktop.common.ViewfxException in project bisq-desktop by bisq-network.
the class FxmlViewLoader method load.
@SuppressWarnings("unchecked")
public View load(Class<? extends View> viewClass) {
FxmlView fxmlView = AnnotationUtils.getAnnotation(viewClass, FxmlView.class);
final Class<? extends FxmlView.PathConvention> convention;
final Class<? extends FxmlView.PathConvention> defaultConvention = (Class<? extends FxmlView.PathConvention>) getDefaultValue(FxmlView.class, "convention");
final String specifiedLocation;
final String defaultLocation = (String) getDefaultValue(FxmlView.class, "location");
if (fxmlView == null) {
convention = defaultConvention;
specifiedLocation = defaultLocation;
} else {
convention = fxmlView.convention();
specifiedLocation = fxmlView.location();
}
if (convention == null || specifiedLocation == null)
throw new IllegalStateException("Convention and location should never be null.");
try {
final String resolvedLocation;
if (specifiedLocation.equals(defaultLocation))
resolvedLocation = convention.newInstance().apply(viewClass);
else
resolvedLocation = specifiedLocation;
URL fxmlUrl = viewClass.getClassLoader().getResource(resolvedLocation);
if (fxmlUrl == null)
throw new ViewfxException("Failed to load view class [%s] because FXML file at [%s] could not be loaded " + "as a classpath resource. Does it exist?", viewClass, specifiedLocation);
return loadFromFxml(fxmlUrl);
} catch (InstantiationException | IllegalAccessException ex) {
throw new ViewfxException(ex, "Failed to load view from class %s", viewClass);
}
}
use of bisq.desktop.common.ViewfxException in project bisq-desktop by bisq-network.
the class FxmlViewLoader method loadFromFxml.
private View loadFromFxml(URL fxmlUrl) {
checkNotNull(fxmlUrl, "FXML URL must not be null");
try {
FXMLLoader loader = new FXMLLoader(fxmlUrl, resourceBundle);
loader.setControllerFactory(viewFactory);
loader.load();
Object controller = loader.getController();
if (controller == null)
throw new ViewfxException("Failed to load view from FXML file at [%s]. " + "Does it declare an fx:controller attribute?", fxmlUrl);
if (!(controller instanceof View))
throw new ViewfxException("Controller of type [%s] loaded from FXML file at [%s] " + "does not implement [%s] as expected.", controller.getClass(), fxmlUrl, View.class);
return (View) controller;
} catch (IOException ex) {
throw new ViewfxException(ex, "Failed to load view from FXML file at [%s]", fxmlUrl);
}
}
Aggregations