Package at.bestsolution.efxclipse.runtime.guice

Source Code of at.bestsolution.efxclipse.runtime.guice.InjectingFXMLLoader

/*******************************************************************************
* Copyright (c) 2012 BestSolution.at and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
*******************************************************************************/
package at.bestsolution.efxclipse.runtime.guice;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.util.Callback;

import com.google.inject.Injector;


public class InjectingFXMLLoader {
  public static <N> N loadFXML(final Injector injector, URL url) throws IOException {
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(url);
    loader.setBuilderFactory(new JavaFXBuilderFactory());
    loader.setControllerFactory(new Callback<Class<?>, Object>() {
     
      @Override
      public Object call(Class<?> param) {
        return injector.getInstance(param);
      }
    });
   
    InputStream in = url.openStream();
    @SuppressWarnings("unchecked")
    N value = (N) loader.load(in);
    in.close();
       
    return value;
  }
}
TOP

Related Classes of at.bestsolution.efxclipse.runtime.guice.InjectingFXMLLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.