Ignore:
Timestamp:
06/15/14 08:59:05 (10 years ago)
Author:
hkaulbersch
Message:

Automatic PDF Generation from .fo files now works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/handler/GenerationHandler.java

    r71 r72  
    11package de.ugoe.cs.swe.bnftools.ui.handler; 
     2 
     3import java.util.Iterator; 
     4import java.util.Map; 
     5import java.util.Map.Entry; 
    26 
    37import org.eclipse.core.commands.AbstractHandler; 
     
    59import org.eclipse.core.commands.ExecutionException; 
    610import org.eclipse.core.commands.IHandler; 
     11import org.eclipse.core.commands.common.NotDefinedException; 
    712import org.eclipse.core.resources.IFile; 
    813import org.eclipse.core.resources.IFolder; 
     
    1116import org.eclipse.core.runtime.NullProgressMonitor; 
    1217import org.eclipse.emf.common.util.URI; 
     18import org.eclipse.emf.ecore.EcorePackage; 
    1319import org.eclipse.emf.ecore.resource.Resource; 
    1420import org.eclipse.emf.ecore.resource.ResourceSet; 
     21import org.eclipse.emf.ecore.xml.type.SimpleAnyType; 
     22import org.eclipse.emf.ecore.xml.type.XMLTypeFactory; 
    1523import org.eclipse.jface.viewers.ISelection; 
    1624import org.eclipse.jface.viewers.IStructuredSelection; 
    1725import org.eclipse.ui.handlers.HandlerUtil; 
    18 import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess; 
     26import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2; 
    1927import org.eclipse.xtext.generator.IGenerator; 
     28import org.eclipse.xtext.generator.OutputConfiguration; 
    2029import org.eclipse.xtext.resource.IResourceDescriptions; 
    2130import org.eclipse.xtext.ui.resource.IResourceSetProvider; 
     
    3039  
    3140    @Inject 
    32     private Provider<EclipseResourceFileSystemAccess> fileAccessProvider; 
     41    private Provider<EclipseResourceFileSystemAccess2> fileAccessProvider; 
    3342      
    3443    @Inject 
     
    4049    @Override 
    4150    public Object execute(ExecutionEvent event) throws ExecutionException { 
    42           
     51        String mode = ""; 
     52  
     53        try { 
     54                        mode = event.getCommand().getName(); 
     55                } catch (NotDefinedException e1) { 
     56                        // catch block 
     57                        e1.printStackTrace(); 
     58                } 
     59                  
     60 
     61          
    4362        ISelection selection = HandlerUtil.getCurrentSelection(event); 
    4463        if (selection instanceof IStructuredSelection) { 
     
    5877                } 
    5978  
    60                 final EclipseResourceFileSystemAccess fsa = fileAccessProvider.get(); 
     79                final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get(); 
    6180                fsa.setOutputPath(srcGenFolder.getFullPath().toString()); 
     81                 
     82                //complete the filesystemaccess  
     83                fsa.setMonitor(new NullProgressMonitor()); 
     84                Map<String, OutputConfiguration> teste = fsa.getOutputConfigurations(); 
     85                         
     86                Iterator<Entry<String, OutputConfiguration>> it = teste.entrySet().iterator(); 
     87                 
     88                while(it.hasNext()){ 
     89                          
     90                    Entry<String, OutputConfiguration> next = it.next(); 
     91                    OutputConfiguration out = next.getValue(); 
     92                    out.isOverrideExistingResources(); 
     93                    out.setCreateOutputDirectory(true); // <--- do not touch this 
    6294                  
     95                  } 
     96                  // -----> 
     97                 
    6398                URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); 
    6499                ResourceSet rs = resourceSetProvider.get(project); 
    65100                Resource r = rs.getResource(uri, true); 
     101                 
     102                // to pass a String inside a resource i have to wrap it in a EOBject 
     103                SimpleAnyType wrapper = XMLTypeFactory.eINSTANCE.createSimpleAnyType(); 
     104                wrapper.setInstanceType(EcorePackage.eINSTANCE.getEString()); 
     105                wrapper.setValue(mode); 
     106                // 
     107                
     108                // add string to resource 
     109                r.getContents().add(wrapper); 
     110             
    66111                generator.doGenerate(r, fsa); 
    67112                  
Note: See TracChangeset for help on using the changeset viewer.