private void saveRefreshContent(final ContentData contentData) {
folder.setVisible(true);
ClassLoader cl = null;
FXMLLoader loader;
if (contentData.extraJarPath != null && !contentData.extraJarPath.isEmpty() && swtFXContainer != null) {
final URLClassLoader previewClassLoader = new PreviewURLClassloader(contentData.extraJarPath.toArray(new URL[0]), swtFXContainer.getClass().getClassLoader());
cl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(previewClassLoader);
loader = new FXMLLoader();
loader.setBuilderFactory(new BuilderFactory() {
private BuilderFactory f = new JavaFXBuilderFactory(previewClassLoader);
@Override
public Builder<?> getBuilder(Class<?> type) {
return f.getBuilder(type);
}
});
loader.setClassLoader(previewClassLoader);
} else {
loader = new FXMLLoader();
}
String exception = null;
try {
currentFile = contentData.file;
loader.setStaticLoad(!preference.getBoolean(PREF_LOAD_CONTROLLER, false));
try {
// TODO Should we set this to the bin-Folder??
loader.setLocation(contentData.file.getParent().getLocation().toFile().getAbsoluteFile().toURI().toURL());
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (contentData.resourceBundle != null) {
FileInputStream in = null;
try {
in = new FileInputStream(new File(contentData.resourceBundle));
Properties p = new Properties();
p.load(in);
final Object[][] entries = new Object[p.entrySet().size()][];
int i = 0;
for (Entry<Object, Object> e : p.entrySet()) {
entries[i++] = new Object[] { e.getKey(), e.getValue() };
}
ListResourceBundle b = new ListResourceBundle() {
@Override
protected Object[][] getContents() {
return entries;
}
};
loader.setResources(b);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
try {
document.set(contentData.contents);
ByteArrayInputStream out = new ByteArrayInputStream(contentData.contents.getBytes());
Object root = loader.load(out);
out.close();
Scene scene = null;
if (root instanceof Scene) {
scene = (Scene) root;
rootPane_new = scene.getRoot();
} else {
if( contentData.previewSceneSetup != null ) {
ByteArrayInputStream sceneOut = new ByteArrayInputStream(contentData.previewSceneSetup.getBytes());
Object sceneRoot = loader.load(sceneOut);
if( sceneRoot instanceof Scene ) {
scene = (Scene) sceneRoot;
}
}