Search in sources :

Example 1 with FxmlView

use of io.bitsquare.gui.common.view.FxmlView in project bitsquare by bitsquare.

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);
    }
}
Also used : ViewfxException(io.bitsquare.gui.common.ViewfxException) FxmlView(io.bitsquare.gui.common.view.FxmlView) URL(java.net.URL)

Aggregations

ViewfxException (io.bitsquare.gui.common.ViewfxException)1 FxmlView (io.bitsquare.gui.common.view.FxmlView)1 URL (java.net.URL)1