Commit cfdf2368 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ added basic translation plug-in



Change-Id: I5da864173cb247ccbaad0b45d0bdc5ff0ef625a4
Signed-off-by: Philip Makedonski's avatarmakedonski <makedonski@informatik.uni-goettingen.de>
parent 3c536ae8
<?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>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.etsi.mts.tdl.rt.ui</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>
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
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ui
Bundle-SymbolicName: org.etsi.mts.tdl.rt.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.etsi.mts.tdl.tools.rt.ui.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui.editors;bundle-version="3.5.0",
org.eclipse.ui.ide;bundle-version="3.5.0",
org.eclipse.ui.workbench,
com.google.inject,
org.eclipse.xtext.ui,
org.eclipse.emf.ecore,
org.eclipse.xtext,
org.etsi.mts.tdl.model,
org.etsi.mts.tdl.TPLan2,
org.etsi.mts.tdl.TDLan2
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.emf.common.util
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<category
name="TDL"
id="org.etsi.mts.tdl.tools.rt.ui.commands.category">
</category>
<command
name="Translate TDL model"
categoryId="org.etsi.mts.tdl.tools.rt.ui.commands.category"
id="org.etsi.mts.tdl.tools.rt.ui.commands.translateCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="org.etsi.mts.tdl.tools.rt.ui.commands.translateCommand"
class="org.etsi.mts.tdl.tools.rt.ui.handlers.TranslationHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="org.etsi.mts.tdl.tools.rt.ui.commands.translateCommand"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+6"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="TDL"
mnemonic="T"
id="org.etsi.mts.tdl.tools.menus.TDLMenu">
<command
commandId="org.etsi.mts.tdl.tools.rt.ui.commands.translateCommand"
mnemonic="T"
id="org.etsi.mts.tdl.tools.rt.ui.menus.translateCommand">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="org.etsi.mts.tdl.tools.rt.ui.toolbars.translate">
<command
commandId="org.etsi.mts.tdl.tools.rt.ui.commands.translateCommand"
icon="icons/TranslateIcon.png"
tooltip="Translate TDL Model"
id="org.etsi.mts.tdl.tools.rt.ui.toolbars.translateCommand">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
package org.etsi.mts.tdl.tools.rt.ui;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.etsi.mts.tdl.tools.rt.ui"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
<?xml version="1.0" encoding="UTF-8"?><projectDescription><name>DUMMY</name><comment></comment><projects></projects><buildSpec></buildSpec><natures></natures></projectDescription>
\ No newline at end of file
package org.etsi.mts.tdl.tools.rt.ui.handlers;
import java.io.IOException;
import java.util.HashMap;
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.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.serializer.impl.Serializer;
import org.eclipse.xtext.util.Files;
import org.etsi.mts.tdl.Package;
import org.etsi.mts.tdl.util.tdlResourceFactoryImpl;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
* @see org.eclipse.core.commands.IHandler
* @see org.eclipse.core.commands.AbstractHandler
*/
public class TranslationHandler extends AbstractHandler {
@Inject Provider<ResourceSet> rsp;
@Inject Injector injector;
/**
* The constructor.
*/
public TranslationHandler() {
}
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
IEditorInput input = HandlerUtil.getActiveEditorInput(event);
IFile file = null;
IProject project = null;
if (input != null && input instanceof FileEditorInput) {
file = ((FileEditorInput) input).getFile();
project = file.getProject();
} else if (selection !=null && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IFile) {
file = (IFile) firstElement;
project = file.getProject();
}
}
if (file !=null) {
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = new ResourceSetImpl();
Resource r = rs.getResource(uri, true);
Package p = (Package) r.getContents().get(0);
if (file.getFullPath().toString().endsWith(".tdl")) {
String s = "";
URI targetURI = URI.createURI(uri.toString()+".tdlan2");
Injector injector = Guice.createInjector(new org.etsi.mts.tdl.TDLan2RuntimeModule());
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
Resource tr = resourceSet.createResource(targetURI);
boolean method1 = true;
//method 1
if (method1) {
tr.getContents().addAll(EcoreUtil.copyAll(r.getContents()));
try {
tr.save(null);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} else {
Serializer serializer = injector.getInstance(Serializer.class);
tr.getContents().add(p);
try {
s += serializer.serialize(p);
} catch (Exception ex) { // fall back:
System.out.println("Model could not be serialized");
ex.printStackTrace();
}
System.out.println(s);
Files.writeStringIntoFile(file.getRawLocation().toOSString()+".tdlan2", s);
}
} else if (file.getFullPath().toString().endsWith(".tdlan2")) {
String extension = "tdl";
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
tdlResourceFactoryImpl factory = new tdlResourceFactoryImpl();
m.put(extension, factory);
Resource outputResource = factory.createResource(URI.createURI(r.getURI().toString()+".tdl"));
outputResource.getContents().addAll(EcoreUtil.copyAll(r.getContents()));
Map options = new HashMap<>();
options.put(XMIResourceImpl.OPTION_ENCODING, "UTF-8");
try {
outputResource.save(options);
} catch (IOException e) {
e.printStackTrace();
}
} else if (file.getFullPath().toString().endsWith(".tplan2")) {
String extension = "tdl";
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
tdlResourceFactoryImpl factory = new tdlResourceFactoryImpl();
m.put(extension, factory);
Resource outputResource = factory.createResource(URI.createURI(r.getURI().toString()+".tdl"));
outputResource.getContents().add(p);
Map options = new HashMap<>();
options.put(XMIResourceImpl.OPTION_ENCODING, "UTF-8");
try {
outputResource.save(options);
} catch (IOException e) {
e.printStackTrace();
}
} else {
//TODO: handle unknown resource type
}
}
return null;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment