diff options
author | Tom Schindl | 2013-06-13 23:26:35 +0000 |
---|---|---|
committer | Tom Schindl | 2013-06-13 23:26:35 +0000 |
commit | bbf1558a8556131a640a3c43d1a25c503ef84af7 (patch) | |
tree | e94a8ca036457c3155a4396eeafdf3d43076f333 /org.eclipse.fx.ide.fxml.compiler | |
parent | b87558fbf23248c2cd57e68bc49807fe270ab07d (diff) | |
download | org.eclipse.efxclipse-bbf1558a8556131a640a3c43d1a25c503ef84af7.tar.gz org.eclipse.efxclipse-bbf1558a8556131a640a3c43d1a25c503ef84af7.tar.xz org.eclipse.efxclipse-bbf1558a8556131a640a3c43d1a25c503ef84af7.zip |
adding extra compiler tasks
Diffstat (limited to 'org.eclipse.fx.ide.fxml.compiler')
9 files changed, 171 insertions, 92 deletions
diff --git a/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/.gitignore b/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/.gitignore new file mode 100644 index 000000000..e401ec7cb --- /dev/null +++ b/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/.gitignore @@ -0,0 +1 @@ +/Sample.java diff --git a/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxgraph b/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxgraph index dbdbd23af..e9ebba287 100644 --- a/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxgraph +++ b/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxgraph @@ -27,6 +27,14 @@ component Sample { } }, VBox { + Label { + text : "Def 1" + }, + Label { + text : "Def 2" + } + }, + VBox { children : [ Label { text : "Label 1", diff --git a/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxml b/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxml index 8562155a0..14b4f3842 100644 --- a/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxml +++ b/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxml @@ -27,6 +27,10 @@ </HBox.margin>
</Label>
<VBox>
+ <Label text="Def 1"/>
+ <Label text="Def 2"/>
+ </VBox>
+ <VBox>
<children>
<Label text="Label 1" VBox.vgrow="SOMETIMES"/>
<GridPane>
diff --git a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphCompiler.java b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphCompiler.java index 9b607ee9b..4ddd32a92 100644 --- a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphCompiler.java +++ b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphCompiler.java @@ -79,7 +79,8 @@ public class FXGraphCompiler { fxgraph = "/tmp/"+UUID.randomUUID().toString()+".fxgraph"; File out = new File(fxgraph); - out.deleteOnExit(); + System.err.println(out); +// out.deleteOnExit(); try { FileOutputStream outStream = new FileOutputStream(out); outStream.write(new FXGraphConverter().generate(m).toString().getBytes()); diff --git a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphJavaGenerator.xtend b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphJavaGenerator.xtend index 0bca049b7..3d4a2904c 100644 --- a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphJavaGenerator.xtend +++ b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphJavaGenerator.xtend @@ -79,6 +79,14 @@ class FXGraphJavaGenerator { «ENDFOR»
«ENDIF»
«ENDFOR»
+ «FOR p : element.defaultChildren»
+ {
+ «val i = getVarIndex»
+ «val varName = 'e_'+i»
+ «generateElementDef(varName,p)»
+ «name».get«element.type.defaultAttribute.toFirstUpper»().add(«varName»);
+ }
+ «ENDFOR»
«ENDIF»
'''
diff --git a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ReflectionHelper.xtend b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ReflectionHelper.xtend index b49a1797a..a8d403f66 100644 --- a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ReflectionHelper.xtend +++ b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ReflectionHelper.xtend @@ -1,6 +1,7 @@ package org.eclipse.fx.ide.fxml.compiler import org.eclipse.xtext.common.types.JvmTypeReference +import javafx.beans.DefaultProperty class ReflectionHelper { def static getEnumType(JvmTypeReference type, String attributeName, boolean layoutConstraint) { @@ -15,4 +16,15 @@ class ReflectionHelper { val c = Class::forName(type.qualifiedName, false, typeof(ReflectionHelper).getClassLoader()) return c.constructors.findFirst[parameterCount==0] == null } + + def static defaultAttribute(JvmTypeReference type) { + var c = Class::forName(type.qualifiedName, false, typeof(ReflectionHelper).getClassLoader()) + var DefaultProperty p + do { + p = c.getAnnotation(typeof(DefaultProperty)) + c = c.superclass; + } while( p == null && c != typeof(Object) ) + + return p.value; + } }
\ No newline at end of file diff --git a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/CompilerTask.java b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/CompilerTask.java new file mode 100644 index 000000000..b4be8ac0e --- /dev/null +++ b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/CompilerTask.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2013 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 org.eclipse.fx.ide.fxml.compiler.ant; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.fx.ide.fxml.compiler.FXGraphCompiler; + +import com.google.inject.Injector; + +public abstract class CompilerTask extends Task { + private String srcDir; + private String destDir; + private final boolean fxgraph; + + public CompilerTask(boolean fxgraph) { + this.fxgraph = fxgraph; + } + + public void setSourceDir(String srcDir) { + this.srcDir = srcDir; + } + + public String getSrcDir() { + return srcDir; + } + + public void setDestDir(String destDir) { + this.destDir = destDir; + } + + public String getDestDir() { + return destDir; + } + + @Override + public void execute() throws BuildException { + File f = new File(getLocation().getFileName()); + File sourceDirectory = new File(f.getParentFile(), srcDir); + File outDirectory = new File(f.getParentFile(), destDir); + + final String sourcePrefix = sourceDirectory.getAbsolutePath(); + final String outPrefix = outDirectory.getAbsolutePath(); + Injector injector = new org.eclipse.fx.ide.fxgraph.FXGraphStandaloneSetupGenerated().createInjectorAndDoEMFRegistration(); + final FXGraphCompiler compiler = injector.getInstance(FXGraphCompiler.class); + + try { + Files.walkFileTree(Paths.get(sourceDirectory.getAbsolutePath()), new FileFinder(new Callable() { + + @Override + public void call(String file) { + System.out.println("Compiling " + file); + compiler.compile(file, sourcePrefix, outPrefix); + } + })); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + class FileFinder extends SimpleFileVisitor<Path> { + private final Callable runnable; + + public FileFinder(Callable runnable) { + this.runnable = runnable; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if ((file.toFile().getAbsolutePath().endsWith(".fxml") && !fxgraph) || (file.toFile().getAbsolutePath().endsWith(".fxgraph") && fxgraph)) { + runnable.call(file.toFile().getAbsolutePath()); + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + } + + public interface Callable { + public void call(String file); + } +}
\ No newline at end of file diff --git a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXGraphCompilerTask.java b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXGraphCompilerTask.java new file mode 100644 index 000000000..68c8bd1b4 --- /dev/null +++ b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXGraphCompilerTask.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2013 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 org.eclipse.fx.ide.fxml.compiler.ant; + + +public class FXGraphCompilerTask extends CompilerTask { + + public FXGraphCompilerTask() { + super(true); + } + +}
\ No newline at end of file diff --git a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXMLCompilerTask.java b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXMLCompilerTask.java index 481e428ac..ea1de0cd6 100644 --- a/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXMLCompilerTask.java +++ b/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXMLCompilerTask.java @@ -10,99 +10,11 @@ *******************************************************************************/ package org.eclipse.fx.ide.fxml.compiler.ant; -import java.io.File; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.eclipse.fx.ide.fxml.compiler.FXGraphCompiler; +public class FXMLCompilerTask extends CompilerTask { -import com.google.inject.Injector; - -public class FXMLCompilerTask extends Task { - private String srcDir; - private String destDir; - - public void setSourceDir(String srcDir) { - this.srcDir = srcDir; - } - - public String getSrcDir() { - return srcDir; - } - - public void setDestDir(String destDir) { - this.destDir = destDir; - } - - public String getDestDir() { - return destDir; - } - - @Override - public void execute() throws BuildException { - File f = new File(getLocation().getFileName()); - File sourceDirectory = new File(f.getParentFile(),srcDir); - File outDirectory = new File(f.getParentFile(),destDir); - - final String sourcePrefix = sourceDirectory.getAbsolutePath(); - final String outPrefix = outDirectory.getAbsolutePath(); - Injector injector = new org.eclipse.fx.ide.fxgraph.FXGraphStandaloneSetupGenerated().createInjectorAndDoEMFRegistration(); - final FXGraphCompiler compiler = injector.getInstance(FXGraphCompiler.class); - - try { - Files.walkFileTree(Paths.get(sourceDirectory.getAbsolutePath()), new FileFinder(new Callable() { - - @Override - public void call(String file) { - System.out.println("Compiling " + file); - compiler.compile(file, sourcePrefix, outPrefix); - } - })); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + public FXMLCompilerTask() { + super(false); } - static class FileFinder extends SimpleFileVisitor<Path> { - private final Callable runnable; - - public FileFinder(Callable runnable) { - this.runnable = runnable; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if( file.toFile().getAbsolutePath().endsWith(".fxml") ) { - runnable.call(file.toFile().getAbsolutePath()); - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { - return FileVisitResult.CONTINUE; - } - } - - public interface Callable { - public void call(String file); - } }
\ No newline at end of file |