1 17 package org.eclipse.emf.importer.java; 18 19 import org.eclipse.core.resources.IFile; 20 import org.eclipse.core.resources.IProject; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IPath; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.core.runtime.IStatus; 25 import org.eclipse.jdt.core.JavaCore; 26 27 import org.eclipse.emf.importer.ModelImporter; 28 import org.eclipse.emf.importer.java.builder.JavaEcoreBuilder; 29 30 31 34 public class JavaImporter extends ModelImporter 35 { 36 public String getID() 37 { 38 return "org.eclipse.emf.importer.java"; 39 } 40 41 public boolean canImport() 42 { 43 IFile genModelFile = getGenModelFile(); 44 if (genModelFile != null) 45 { 46 IProject project = genModelFile.getProject(); 47 try 48 { 49 return project.hasNature(JavaCore.NATURE_ID); 50 } 51 catch (CoreException e) 52 { 53 JavaImporterPlugin.INSTANCE.log(e); 54 } 55 } 56 return false; 57 } 58 59 protected IFile getGenModelFile() 60 { 61 IPath path = getGenModelPath(); 62 if (path != null) 63 { 64 return getWorkspaceRoot().getFile(path); 65 } 66 return null; 67 } 68 69 protected IStatus doComputeEPackages(IProgressMonitor progressMonitor) throws Exception 70 { 71 progressMonitor.beginTask("", 2); 72 progressMonitor.subTask(JavaImporterPlugin.INSTANCE.getString("_UI_CreatingPackages_message")); 73 74 JavaEcoreBuilder javaEcoreBuilder = new JavaEcoreBuilder(getGenModelFile(), getOriginalGenModel()); 75 javaEcoreBuilder.computeEPackages(progressMonitor, this); 76 return javaEcoreBuilder.getStatus(); 77 } 78 79 protected void adjustGenModel(IProgressMonitor progressMonitor) 80 { 81 super.adjustGenModel(progressMonitor); 82 getGenModel().getForeignModel().add("@model"); 83 } 84 } | Popular Tags |