KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > importer > java > JavaImporter


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2005 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: JavaImporter.java,v 1.2 2005/06/08 06:17:32 nickb Exp $
16  */

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 /**
32  * @since 2.1.0
33  */

34 public class JavaImporter extends ModelImporter
35 {
36   public String JavaDoc 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 JavaDoc
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