- Timestamp:
- 05/28/14 09:25:14 (10 years ago)
- Location:
- v2/trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/handler/GenerationHandler.java
r69 r70 1 package de.ugoe.cs.swe.bnftools.ui.handler;2 3 import org.eclipse.core.commands.AbstractHandler;4 import org.eclipse.core.commands.ExecutionEvent;5 import org.eclipse.core.commands.ExecutionException;6 import org.eclipse.core.commands.IHandler;7 import org.eclipse.core.resources.IFile;8 import org.eclipse.core.resources.IFolder;9 import org.eclipse.core.resources.IProject;10 import org.eclipse.core.runtime.CoreException;11 import org.eclipse.core.runtime.NullProgressMonitor;12 import org.eclipse.emf.common.util.URI;13 import org.eclipse.emf.ecore.resource.Resource;14 import org.eclipse.emf.ecore.resource.ResourceSet;15 import org.eclipse.jface.viewers.ISelection;16 import org.eclipse.jface.viewers.IStructuredSelection;17 import org.eclipse.ui.handlers.HandlerUtil;18 import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess;19 import org.eclipse.xtext.generator.IGenerator;20 import org.eclipse.xtext.resource.IResourceDescriptions;21 import org.eclipse.xtext.ui.resource.IResourceSetProvider;22 23 import com.google.inject.Inject;24 import com.google.inject.Provider;25 26 public class GenerationHandler extends AbstractHandler implements IHandler {27 28 @Inject29 private IGenerator generator;30 31 @Inject32 private Provider<EclipseResourceFileSystemAccess> fileAccessProvider;33 34 @Inject35 IResourceDescriptions resourceDescriptions;36 37 @Inject38 IResourceSetProvider resourceSetProvider;39 40 @Override41 public Object execute(ExecutionEvent event) throws ExecutionException {42 43 ISelection selection = HandlerUtil.getCurrentSelection(event);44 if (selection instanceof IStructuredSelection) {45 IStructuredSelection structuredSelection = (IStructuredSelection) selection;46 Object firstElement = structuredSelection.getFirstElement();47 if (firstElement instanceof IFile) {48 IFile file = (IFile) firstElement;49 IProject project = file.getProject();50 IFolder srcGenFolder = project.getFolder("src-gen");51 if (!srcGenFolder.exists()) {52 try {53 srcGenFolder.create(true, true,54 new NullProgressMonitor());55 } catch (CoreException e) {56 return null;57 }58 }59 60 final EclipseResourceFileSystemAccess fsa = fileAccessProvider.get();61 fsa.setOutputPath(srcGenFolder.getFullPath().toString());62 63 URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);64 ResourceSet rs = resourceSetProvider.get(project);65 Resource r = rs.getResource(uri, true);66 generator.doGenerate(r, fsa);67 68 69 }70 }71 return null;72 }73 74 @Override75 public boolean isEnabled() {76 return true;77 }78 79 }1 //package de.ugoe.cs.swe.bnftools.ui.handler; 2 // 3 //import org.eclipse.core.commands.AbstractHandler; 4 //import org.eclipse.core.commands.ExecutionEvent; 5 //import org.eclipse.core.commands.ExecutionException; 6 //import org.eclipse.core.commands.IHandler; 7 //import org.eclipse.core.resources.IFile; 8 //import org.eclipse.core.resources.IFolder; 9 //import org.eclipse.core.resources.IProject; 10 //import org.eclipse.core.runtime.CoreException; 11 //import org.eclipse.core.runtime.NullProgressMonitor; 12 //import org.eclipse.emf.common.util.URI; 13 //import org.eclipse.emf.ecore.resource.Resource; 14 //import org.eclipse.emf.ecore.resource.ResourceSet; 15 //import org.eclipse.jface.viewers.ISelection; 16 //import org.eclipse.jface.viewers.IStructuredSelection; 17 //import org.eclipse.ui.handlers.HandlerUtil; 18 //import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess; 19 //import org.eclipse.xtext.generator.IGenerator; 20 //import org.eclipse.xtext.resource.IResourceDescriptions; 21 //import org.eclipse.xtext.ui.resource.IResourceSetProvider; 22 // 23 //import com.google.inject.Inject; 24 //import com.google.inject.Provider; 25 // 26 //public class GenerationHandler extends AbstractHandler implements IHandler { 27 // 28 // @Inject 29 // private IGenerator generator; 30 // 31 // @Inject 32 // private Provider<EclipseResourceFileSystemAccess> fileAccessProvider; 33 // 34 // @Inject 35 // IResourceDescriptions resourceDescriptions; 36 // 37 // @Inject 38 // IResourceSetProvider resourceSetProvider; 39 // 40 // @Override 41 // public Object execute(ExecutionEvent event) throws ExecutionException { 42 // 43 // ISelection selection = HandlerUtil.getCurrentSelection(event); 44 // if (selection instanceof IStructuredSelection) { 45 // IStructuredSelection structuredSelection = (IStructuredSelection) selection; 46 // Object firstElement = structuredSelection.getFirstElement(); 47 // if (firstElement instanceof IFile) { 48 // IFile file = (IFile) firstElement; 49 // IProject project = file.getProject(); 50 // IFolder srcGenFolder = project.getFolder("src-gen"); 51 // if (!srcGenFolder.exists()) { 52 // try { 53 // srcGenFolder.create(true, true, 54 // new NullProgressMonitor()); 55 // } catch (CoreException e) { 56 // return null; 57 // } 58 // } 59 // 60 // final EclipseResourceFileSystemAccess fsa = fileAccessProvider.get(); 61 // fsa.setOutputPath(srcGenFolder.getFullPath().toString()); 62 // 63 // URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); 64 // ResourceSet rs = resourceSetProvider.get(project); 65 // Resource r = rs.getResource(uri, true); 66 // generator.doGenerate(r, fsa); 67 // 68 // 69 // } 70 // } 71 // return null; 72 // } 73 // 74 // @Override 75 // public boolean isEnabled() { 76 // return true; 77 // } 78 // 79 //} -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/META-INF/MANIFEST.MF
r61 r70 19 19 org.eclipse.xtext.common.types 20 20 Import-Package: org.apache.log4j, 21 org.eclipse.core.resources, 22 org.eclipse.core.runtime;version="3.4.0", 21 23 org.eclipse.xtext.xbase.lib 22 24 Bundle-RequiredExecutionEnvironment: J2SE-1.5 -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/generator/EbnfGenerator.xtend
r69 r70 22 22 import org.eclipse.xtext.generator.IFileSystemAccessExtension2 23 23 import org.eclipse.emf.common.util.URI; 24 24 import org.eclipse.xtext.generator.IFileSystemAccessExtension 25 import java.io.PrintWriter 25 26 /** 26 27 * Generates code from your model files on save. … … 31 32 //generation of the xsl-file 32 33 override void doGenerate(Resource resource, IFileSystemAccess fsa) { 34 var String workspacePath =WorkspaceResolver.getWorkspace(); 33 35 for (e : resource.allContents.toIterable.filter(EtsiBnf)) { 34 36 if (e.bnfEntry.size!=0) { … … 36 38 37 39 //generate pdf 38 // var uri = (fsa as IFileSystemAccessExtension2).getURI(e.name+".fo"); 39 // (fsa as IFileSystemAccessExtension2). 40 // 41 // System.out.println(uri.hasAbsolutePath()); 42 // System.out.println(uri.path.substring(0,uri.path.length-3)); 43 // System.out.println(uri.file); 40 var uri = (fsa as IFileSystemAccessExtension2).getURI(e.name+".fo"); 41 var String fullUri = workspacePath+uri.path.substring(10,uri.path.length); 42 System.out.println(workspacePath+uri.path.substring(10,uri.path.length)); 43 var File file = new File(fullUri); 44 System.out.println(file.exists); 44 45 // System.out.println(uri.toString()); 45 // var File file = new File(uri.path).absoluteFile; 46 47 46 48 // System.out.println(file.exists); 47 // var String aPath = file.absolutePath; 48 // 49 49 50 // foToPdf.createPdfFromFo(file,aPath.substring(0,aPath.length-3)); 50 51 } -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/generator/foToPdf.java
r69 r70 22 22 public class foToPdf { 23 23 24 //public static void main(String args[]) throws IOException, FOPException,25 //TransformerException {26 // 27 //createfoFromPdf("test1","test1");28 //}24 public static void main(String args[]) throws IOException, FOPException, 25 TransformerException { 26 27 createfoFromPdf("test1","test1"); 28 } 29 29 30 30 public static void createPdfFromFo(String fileName) throws IOException, FOPException,
Note: See TracChangeset
for help on using the changeset viewer.