diff options
21 files changed, 439 insertions, 0 deletions
diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/.classpath b/bundles/tooling/org.eclipse.fx.ide.converter/.classpath new file mode 100755 index 000000000..b1dabee38 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/.gitignore b/bundles/tooling/org.eclipse.fx.ide.converter/.gitignore new file mode 100755 index 000000000..4dc009173 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/.gitignore @@ -0,0 +1,2 @@ +/target +/bin diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/.project b/bundles/tooling/org.eclipse.fx.ide.converter/.project new file mode 100755 index 000000000..c971478be --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.fx.ide.converter</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.core.resources.prefs b/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.core.resources.prefs new file mode 100755 index 000000000..99f26c020 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/<project>=UTF-8 diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.core.runtime.prefs b/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.core.runtime.prefs new file mode 100755 index 000000000..deae05a97 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\r\n diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.jdt.core.prefs b/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 000000000..f42de363a --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/META-INF/MANIFEST.MF b/bundles/tooling/org.eclipse.fx.ide.converter/META-INF/MANIFEST.MF new file mode 100755 index 000000000..6fd8d59f6 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Converter +Bundle-SymbolicName: org.eclipse.fx.ide.converter;singleton:=true +Bundle-Version: 0.8.1.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Require-Bundle: org.eclipse.ui, + org.eclipse.core.resources;bundle-version="3.7.0", + org.eclipse.core.runtime;bundle-version="3.7.0", + org.eclipse.core.expressions;bundle-version="3.4.300", + org.eclipse.fx.formats.svg;bundle-version="0.8.1", + org.eclipse.fx.ide.fxgraph;bundle-version="0.8.1", + org.eclipse.jdt.core;bundle-version="3.7.0", + org.eclipse.text;bundle-version="3.5.0" diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/build.properties b/bundles/tooling/org.eclipse.fx.ide.converter/build.properties new file mode 100755 index 000000000..e9863e281 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/plugin.xml b/bundles/tooling/org.eclipse.fx.ide.converter/plugin.xml new file mode 100755 index 000000000..07c5b2352 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/plugin.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + allPopups="false" + locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?after=additions"> + <command + commandId="org.eclipse.fx.ide.converter.svg" + label="Convert SVG To FXML" + style="push"> + <visibleWhen + checkEnabled="true"> + <with + variable="activeMenuSelection"> + <iterate + ifEmpty="false" + operator="and"> + <adapt + type="org.eclipse.core.resources.IFile"> + <test + property="org.eclipse.core.resources.name" + value="*.svg"> + </test> + </adapt> + </iterate> + <count + value="1"> + </count> + </with> + </visibleWhen> + </command> + <command + commandId="org.eclipse.fx.ide.converter.fxml" + label="Convert FXML to FXGraph" + style="push"> + <visibleWhen + checkEnabled="true"> + <with + variable="activeMenuSelection"> + <iterate + ifEmpty="false" + operator="and"> + <adapt + type="org.eclipse.core.resources.IFile"> + <test + property="org.eclipse.core.resources.name" + value="*.fxml"> + </test> + </adapt> + </iterate> + <count + value="1"> + </count> + </with> + </visibleWhen> + </command> + </menuContribution> + </extension> + <extension + point="org.eclipse.ui.commands"> + <command + defaultHandler="org.eclipse.fx.ide.converter.ConvertFXMLHandler" + id="org.eclipse.fx.ide.converter.fxml" + name="Convert FXML"> + </command> + <command + defaultHandler="org.eclipse.fx.ide.converter.ConvertSVGHandler" + id="org.eclipse.fx.ide.converter.svg" + name="Convert SVG"> + </command> + </extension> + +</plugin> diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/pom.xml b/bundles/tooling/org.eclipse.fx.ide.converter/pom.xml new file mode 100755 index 000000000..3307423a6 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/pom.xml @@ -0,0 +1,34 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <name>e(fx)clipse - IDE - Converter</name> + <groupId>org.eclipse.fx.ide</groupId> + <artifactId>org.eclipse.fx.ide.converter</artifactId> + <packaging>eclipse-plugin</packaging> + + <parent> + <groupId>org.eclipse.fx.ide</groupId> + <artifactId>releng</artifactId> + <relativePath>../../../releng/org.eclipse.fx.ide.releng/pom.xml</relativePath> + <version>0.8.1-SNAPSHOT</version> + </parent> + + <build> + <resources> + <!-- to ensure that the feature lookup of the ui test works --> + <resource> + <directory>.</directory> + <includes> + <include>META-INF/</include> + </includes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> + +</project>
\ No newline at end of file diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/AbstractConverterHandler.java b/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/AbstractConverterHandler.java new file mode 100755 index 000000000..99efc1445 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/AbstractConverterHandler.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * 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 org.eclipse.fx.ide.converter; + +import java.io.ByteArrayInputStream; +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.formatter.CodeFormatter; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.ISources; + +public abstract class AbstractConverterHandler extends AbstractHandler { + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IEvaluationContext context = (IEvaluationContext) event + .getApplicationContext(); + ISelection s = (ISelection) context + .getVariable(ISources.ACTIVE_MENU_SELECTION_NAME); + if (s instanceof IStructuredSelection) { + Object o = ((IStructuredSelection) s).getFirstElement(); + if (o instanceof IFile) { + IFile f = (IFile) o; + IContainer folder = f.getParent(); + IFile outFile = folder.getFile(new Path(f.getName().substring( + 0, + f.getName().length() - f.getFileExtension().length() + - 1) + + getTargetFileExtension())); + String content = convert(outFile, f); + IProject project = outFile.getProject(); + Object codeFormatter = createCodeFormatter(project); + if (codeFormatter != null) { + content = format(content, (CodeFormatter) codeFormatter); + } + + if (!outFile.exists()) { + try { + outFile.create( + new ByteArrayInputStream(content.getBytes()), + true, new NullProgressMonitor()); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + try { + outFile.setContents( + new ByteArrayInputStream(content.getBytes()), + IResource.KEEP_HISTORY | IResource.FORCE, + new NullProgressMonitor()); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + return null; + } + + protected abstract String convert(IFile outFile, IFile file) + throws ExecutionException; + + protected abstract String getTargetFileExtension(); + + protected String format(String content, CodeFormatter codeFormatter) { + return content; + } + + public static Object createCodeFormatter(IProject project) { + IJavaProject javaProject = JavaCore.create(project); + Map options = javaProject.getOptions(true); + return ToolFactory.createCodeFormatter(options); + } +}
\ No newline at end of file diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/ConvertFXMLHandler.java b/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/ConvertFXMLHandler.java new file mode 100755 index 000000000..dce61031e --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/ConvertFXMLHandler.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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: + * Martin Bluehweis <martin.bluehweis@bestsolution.at> - initial API and implementation + *******************************************************************************/ +package org.eclipse.fx.ide.converter; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.fx.ide.fxgraph.converter.FXGraphConverter; +import org.eclipse.fx.ide.fxgraph.converter.FXMLLoader; +import org.eclipse.fx.ide.fxgraph.fXGraph.Model; +import org.eclipse.jdt.core.formatter.CodeFormatter; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.text.edits.TextEdit; + +public class ConvertFXMLHandler extends AbstractConverterHandler { + + @Override + protected String convert(IFile outFile, IFile file) + throws ExecutionException { + FXMLLoader loader = new FXMLLoader(); + Model m = loader.loadModel(file); + return new FXGraphConverter().generate(m).toString(); + } + + @Override + protected String getTargetFileExtension() { + return ".fxgraph"; + } + + @Override + protected String format(String contents, CodeFormatter codeFormatter) { + if (codeFormatter instanceof CodeFormatter) { + IDocument doc = new Document(contents); + // FIXME always returns null + TextEdit edit = ((CodeFormatter) codeFormatter).format( + CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0, doc.get() + .length(), 0, null); + + if (edit != null) { + try { + edit.apply(doc); + contents = doc.get(); + } catch (Exception e) { + // TODO + e.printStackTrace(); + } + } + } + return contents; + } +} diff --git a/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/ConvertSVGHandler.java b/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/ConvertSVGHandler.java new file mode 100755 index 000000000..fbe900415 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.converter/src/org/eclipse/fx/ide/converter/ConvertSVGHandler.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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 org.eclipse.fx.ide.converter; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.fx.formats.svg.converter.FXMLConverter; +import org.eclipse.fx.formats.svg.handler.XMLLoader; +import org.eclipse.fx.formats.svg.svg.SvgSvgElement; + +public class ConvertSVGHandler extends AbstractConverterHandler { + + @Override + protected String convert(IFile outFile, IFile file) throws ExecutionException { + try { + XMLLoader loader = new XMLLoader(); + SvgSvgElement root = loader.loadDocument(outFile.getFullPath().toOSString(), file.getContents()); + return new FXMLConverter(root).generate().toString(); + } catch (Exception e) { + throw new ExecutionException("Conversion failed", e); + } + } + + @Override + protected String getTargetFileExtension() { + return ".fxml"; + } +} diff --git a/releng/org.eclipse.fx.ide.releng/pom.xml b/releng/org.eclipse.fx.ide.releng/pom.xml index be0c8873b..3b0c2bc7e 100755 --- a/releng/org.eclipse.fx.ide.releng/pom.xml +++ b/releng/org.eclipse.fx.ide.releng/pom.xml @@ -53,12 +53,14 @@ <module>../../bundles/tooling/org.eclipse.fx.ide.fxgraph</module> <module>../../bundles/tooling/org.eclipse.fx.ide.fxgraph.ui</module> <module>../../bundles/tooling/org.eclipse.fx.ide.fxml</module> + <module>../../bundles/tooling/org.eclipse.fx.ide.converter</module> <module>../tooling/org.eclipse.fx.ide.basic.feature</module> <module>../tooling/org.eclipse.fx.ide.rrobot.feature</module> <module>../tooling/org.eclipse.fx.ide.css.feature</module> <module>../tooling/org.eclipse.fx.ide.fxgraph.feature</module> <module>../tooling/org.eclipse.fx.ide.fxml.feature</module> + <module>../tooling/org.eclipse.fx.ide.converter.feature</module> <module>../tooling/org.eclipse.fx.ide.pde.feature</module> <module>../tooling/org.eclipse.fx.ide.pde.prekepler.feature</module> diff --git a/releng/org.eclipse.fx.ide.updatesite/site.xml b/releng/org.eclipse.fx.ide.updatesite/site.xml index 0340a69aa..6aa658e02 100644 --- a/releng/org.eclipse.fx.ide.updatesite/site.xml +++ b/releng/org.eclipse.fx.ide.updatesite/site.xml @@ -27,6 +27,9 @@ <feature url="features/org.eclipse.fx.ide.fxgraph.feature_0.8.1.qualifier.jar" id="org.eclipse.fx.ide.fxgraph.feature" version="0.8.1.qualifier"> <category name="e(fx)clipse - single components"/> </feature> + <feature url="features/org.eclipse.fx.ide.converter.feature_0.8.1.qualifier.jar" id="org.eclipse.fx.ide.converter.feature" version="0.8.1.qualifier"> + <category name="e(fx)clipse - single components"/> + </feature> <category-def name="e(fx)clipse - install" label="e(fx)clipse - install"/> <category-def name="e(fx)clipse - single components" label="e(fx)clipse - single components"/> </site> diff --git a/releng/tooling/org.eclipse.fx.ide.all.kepler.feature/feature.xml b/releng/tooling/org.eclipse.fx.ide.all.kepler.feature/feature.xml index fe2e2641f..c9c281e31 100644 --- a/releng/tooling/org.eclipse.fx.ide.all.kepler.feature/feature.xml +++ b/releng/tooling/org.eclipse.fx.ide.all.kepler.feature/feature.xml @@ -41,4 +41,8 @@ id="org.eclipse.fx.ide.fxgraph.feature" version="0.0.0"/> + <includes + id="org.eclipse.fx.ide.converter.feature" + version="0.0.0"/> + </feature> diff --git a/releng/tooling/org.eclipse.fx.ide.converter.feature/.gitignore b/releng/tooling/org.eclipse.fx.ide.converter.feature/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/releng/tooling/org.eclipse.fx.ide.converter.feature/.gitignore @@ -0,0 +1 @@ +/target diff --git a/releng/tooling/org.eclipse.fx.ide.converter.feature/.project b/releng/tooling/org.eclipse.fx.ide.converter.feature/.project new file mode 100644 index 000000000..957c572a5 --- /dev/null +++ b/releng/tooling/org.eclipse.fx.ide.converter.feature/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.fx.ide.converter.feature</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.pde.FeatureBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.FeatureNature</nature> + </natures> +</projectDescription> diff --git a/releng/tooling/org.eclipse.fx.ide.converter.feature/build.properties b/releng/tooling/org.eclipse.fx.ide.converter.feature/build.properties new file mode 100644 index 000000000..64f93a9f0 --- /dev/null +++ b/releng/tooling/org.eclipse.fx.ide.converter.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/releng/tooling/org.eclipse.fx.ide.converter.feature/feature.xml b/releng/tooling/org.eclipse.fx.ide.converter.feature/feature.xml new file mode 100644 index 000000000..3dc4ef1e2 --- /dev/null +++ b/releng/tooling/org.eclipse.fx.ide.converter.feature/feature.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<feature + id="org.eclipse.fx.ide.converter.feature" + label="e(fx)clipse - IDE - Converter" + version="0.8.1.qualifier" + provider-name="BestSolution.at"> + + <description url="http://www.example.com/description"> + [Enter Feature Description here.] + </description> + + <copyright url="http://www.example.com/copyright"> + [Enter Copyright Description here.] + </copyright> + + <license url="http://www.example.com/license"> + [Enter License Description here.] + </license> + + <plugin + id="org.eclipse.fx.ide.converter" + download-size="0" + install-size="0" + version="0.0.0"/> + +</feature> diff --git a/releng/tooling/org.eclipse.fx.ide.converter.feature/pom.xml b/releng/tooling/org.eclipse.fx.ide.converter.feature/pom.xml new file mode 100644 index 000000000..d4e9bc77d --- /dev/null +++ b/releng/tooling/org.eclipse.fx.ide.converter.feature/pom.xml @@ -0,0 +1,16 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <name>e(fx)clipse - IDE - Features - Converter</name>
+ <groupId>org.eclipse.fx.ide</groupId>
+ <artifactId>org.eclipse.fx.ide.converter.feature</artifactId>
+ <packaging>eclipse-feature</packaging>
+
+ <parent>
+ <groupId>org.eclipse.fx.ide</groupId>
+ <artifactId>releng</artifactId>
+ <relativePath>../../org.eclipse.fx.ide.releng/pom.xml</relativePath>
+ <version>0.8.1-SNAPSHOT</version>
+ </parent>
+
+</project>
\ No newline at end of file |