Loading plugins/org.etsi.mts.tdl.helper/META-INF/MANIFEST.MF +2 −1 Original line number Diff line number Diff line Loading @@ -23,5 +23,6 @@ Require-Bundle: org.eclipse.xtext, org.eclipse.emf.common, org.eclipse.emf.mwe.utils, org.eclipse.ocl.xtext.completeocl, com.google.guava com.google.guava, org.etsi.mts.tdl.common Export-Package: org.etsi.mts.tdl.helper plugins/org.etsi.mts.tdl.helper/src/org/etsi/mts/tdl/helper/TDLHelper.java +17 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ package org.etsi.mts.tdl.helper; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Set; Loading Loading @@ -42,7 +43,9 @@ import org.etsi.mts.tdl.TDLtxStandaloneSetup; import org.etsi.mts.tdl.TDLtxiStandaloneSetup; import org.etsi.mts.tdl.TPLan2StandaloneSetup; import org.etsi.mts.tdl.impl.tdlPackageImpl; import org.etsi.mts.tdl.resources.ResourceHandler; import org.etsi.mts.tdl.structuredobjectives.impl.StructuredObjectivesPackageImpl; import org.osgi.framework.Bundle; import com.google.inject.Injector; Loading Loading @@ -260,11 +263,24 @@ public class TDLHelper { } }; prj.accept(finder); if (finder.file != null) { URI uri = URI.createPlatformResourceURI(finder.file.getFullPath().toString(), true); Resource tdlResource = resource.getResourceSet().getResource(uri, true); return (Package) tdlResource.getContents().get(0); } else { //TODO: somewhat hacky way to load resources from the library if not found locally if (Platform.isRunning()) { Bundle bundle = Platform.getBundle("org.etsi.mts.tdl.library"); ArrayList<Package> packages = new ArrayList<>(); bundle.findEntries("/","*.tdltx", true).asIterator().forEachRemaining(e-> { org.eclipse.emf.common.util.URI pURI = org.eclipse.emf.common.util.URI.createURI(e.toString()); if (names.contains(pURI.lastSegment().toLowerCase())) { Resource tdlResource = resource.getResourceSet().getResource(pURI, true); packages.add((Package) tdlResource.getContents().get(0)); } }); return packages.get(0); } } } } catch (CoreException e) { Loading plugins/org.etsi.mts.tdl.rt.ui/src/org/etsi/mts/tdl/tools/rt/ui/handlers/TranslationHandler.java +21 −4 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package org.etsi.mts.tdl.tools.rt.ui.handlers; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Optional; Loading @@ -28,9 +29,13 @@ import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.resource.IResourceServiceProvider; import org.eclipse.xtext.resource.SaveOptions; import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.resource.XtextResourceSet; import org.eclipse.xtext.ui.resource.IResourceSetProvider; import com.google.common.collect.Maps; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; Loading Loading @@ -108,8 +113,12 @@ public class TranslationHandler extends AbstractHandler { if (file !=null) { URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); ResourceSet rs = new ResourceSetImpl(); Injector injector = Guice.createInjector(); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); // ResourceSet rs = new ResourceSetImpl(); XtextResourceSet rs = resourceSet; Resource r = rs.getResource(uri, true); EcoreUtil.resolveAll(r); ElementListSelectionDialog dialog = new ElementListSelectionDialog(Display.getDefault().getActiveShell(), new LabelProvider()); dialog.setTitle("Translation Configuration"); Loading @@ -123,16 +132,19 @@ public class TranslationHandler extends AbstractHandler { if (dialog.open() != Window.OK) { return false; } else { Injector injector = Guice.createInjector(); // Injector injector = Guice.createInjector(); Object[] result = dialog.getResult(); String selected = (String)result[0]; TranslationHandler.translationTarget = selected; String extension = targetFormats.get(selected); URI targetURI = URI.createURI(uri.toString()+"."+extension); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); // XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); // resourceSet = rs; Resource tr = resourceSet.createResource(targetURI); tr.getContents().addAll(EcoreUtil.copyAll(r.getContents())); // tr.getContents().addAll(r.getContents()); // tr.getContents().add(EcoreUtil2.cloneWithProxies(r.getContents().get(0))); //post-process StructuredTestObjectives if (file.getName().endsWith("tplan2") && extension.startsWith("tdltx")) { Loading @@ -158,9 +170,14 @@ public class TranslationHandler extends AbstractHandler { } try { EcoreUtil.resolveAll(tr); // EcoreUtil2.resolveAll(r, null); // HashMap<Object,Object> options = Maps.newHashMap(); // options.put(XtextResource.OPTION_RESOLVE_ALL, true); tr.save(null); } catch (Exception e1) { System.err.println(" Translation: "+e1.getMessage()); e1.printStackTrace(); //TODO: provide an error dialog, fall back to XF, indicate approximate location based on error message / details } } Loading Loading
plugins/org.etsi.mts.tdl.helper/META-INF/MANIFEST.MF +2 −1 Original line number Diff line number Diff line Loading @@ -23,5 +23,6 @@ Require-Bundle: org.eclipse.xtext, org.eclipse.emf.common, org.eclipse.emf.mwe.utils, org.eclipse.ocl.xtext.completeocl, com.google.guava com.google.guava, org.etsi.mts.tdl.common Export-Package: org.etsi.mts.tdl.helper
plugins/org.etsi.mts.tdl.helper/src/org/etsi/mts/tdl/helper/TDLHelper.java +17 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ package org.etsi.mts.tdl.helper; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Set; Loading Loading @@ -42,7 +43,9 @@ import org.etsi.mts.tdl.TDLtxStandaloneSetup; import org.etsi.mts.tdl.TDLtxiStandaloneSetup; import org.etsi.mts.tdl.TPLan2StandaloneSetup; import org.etsi.mts.tdl.impl.tdlPackageImpl; import org.etsi.mts.tdl.resources.ResourceHandler; import org.etsi.mts.tdl.structuredobjectives.impl.StructuredObjectivesPackageImpl; import org.osgi.framework.Bundle; import com.google.inject.Injector; Loading Loading @@ -260,11 +263,24 @@ public class TDLHelper { } }; prj.accept(finder); if (finder.file != null) { URI uri = URI.createPlatformResourceURI(finder.file.getFullPath().toString(), true); Resource tdlResource = resource.getResourceSet().getResource(uri, true); return (Package) tdlResource.getContents().get(0); } else { //TODO: somewhat hacky way to load resources from the library if not found locally if (Platform.isRunning()) { Bundle bundle = Platform.getBundle("org.etsi.mts.tdl.library"); ArrayList<Package> packages = new ArrayList<>(); bundle.findEntries("/","*.tdltx", true).asIterator().forEachRemaining(e-> { org.eclipse.emf.common.util.URI pURI = org.eclipse.emf.common.util.URI.createURI(e.toString()); if (names.contains(pURI.lastSegment().toLowerCase())) { Resource tdlResource = resource.getResourceSet().getResource(pURI, true); packages.add((Package) tdlResource.getContents().get(0)); } }); return packages.get(0); } } } } catch (CoreException e) { Loading
plugins/org.etsi.mts.tdl.rt.ui/src/org/etsi/mts/tdl/tools/rt/ui/handlers/TranslationHandler.java +21 −4 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package org.etsi.mts.tdl.tools.rt.ui.handlers; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Optional; Loading @@ -28,9 +29,13 @@ import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.resource.IResourceServiceProvider; import org.eclipse.xtext.resource.SaveOptions; import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.resource.XtextResourceSet; import org.eclipse.xtext.ui.resource.IResourceSetProvider; import com.google.common.collect.Maps; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; Loading Loading @@ -108,8 +113,12 @@ public class TranslationHandler extends AbstractHandler { if (file !=null) { URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); ResourceSet rs = new ResourceSetImpl(); Injector injector = Guice.createInjector(); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); // ResourceSet rs = new ResourceSetImpl(); XtextResourceSet rs = resourceSet; Resource r = rs.getResource(uri, true); EcoreUtil.resolveAll(r); ElementListSelectionDialog dialog = new ElementListSelectionDialog(Display.getDefault().getActiveShell(), new LabelProvider()); dialog.setTitle("Translation Configuration"); Loading @@ -123,16 +132,19 @@ public class TranslationHandler extends AbstractHandler { if (dialog.open() != Window.OK) { return false; } else { Injector injector = Guice.createInjector(); // Injector injector = Guice.createInjector(); Object[] result = dialog.getResult(); String selected = (String)result[0]; TranslationHandler.translationTarget = selected; String extension = targetFormats.get(selected); URI targetURI = URI.createURI(uri.toString()+"."+extension); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); // XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); // resourceSet = rs; Resource tr = resourceSet.createResource(targetURI); tr.getContents().addAll(EcoreUtil.copyAll(r.getContents())); // tr.getContents().addAll(r.getContents()); // tr.getContents().add(EcoreUtil2.cloneWithProxies(r.getContents().get(0))); //post-process StructuredTestObjectives if (file.getName().endsWith("tplan2") && extension.startsWith("tdltx")) { Loading @@ -158,9 +170,14 @@ public class TranslationHandler extends AbstractHandler { } try { EcoreUtil.resolveAll(tr); // EcoreUtil2.resolveAll(r, null); // HashMap<Object,Object> options = Maps.newHashMap(); // options.put(XtextResource.OPTION_RESOLVE_ALL, true); tr.save(null); } catch (Exception e1) { System.err.println(" Translation: "+e1.getMessage()); e1.printStackTrace(); //TODO: provide an error dialog, fall back to XF, indicate approximate location based on error message / details } } Loading