Me n My Programming

If Only I Have TIme

Marama Code 116 ~ How to import project created to workspace package explorer

Recently, I have move out the generated code folder from the test model project. The reason why I did this is because I want to utilize the eclipse project java nature capabilities. With java nature, I can use the JUnit component attach to eclipse and run the JUnit GUI provided. FYI, the test model folder project nature is not on native java.

The problem when moving out the generated code is, once the all the new project created, it thus not load automatically to the current package explorer (or workspace). You need to manually import it using the import function provided. So start Google around and found the detail how to do here.

As a warning, this is a version specifically created for marama, but you can use the importExisitingProject method as you can supplied the project path and workspace used.

/** main method **/

MaramaDiagram diagram;

IProject devModelProject = diagram.getEditor().getFile().getProject(); // populate data regarding diagram
String devModelProjectPath = devModelProject.getLocation().toString(); // get project path

String testModelProjectPath = devModelProjectPath.concat(“Test”); // add test to the project name

Path projectPath = new Path(testModelProjectPath); // convert to Path type
importExisitingProject(projectPath, diagram.getEditor().getFile().getProject().getWorkspace()); // call the import function

* Imports the given path into the workspace as a project. Returns true if the
* operation succeeded, false if it failed to import due to an overlap.
* @param projectPath
* @return
* @throws CoreException if operation fails catastrophically
private boolean importExisitingProject(IPath projectPath, IWorkspace workspace) throws CoreException {

// Load the project description file
final IProjectDescription description = workspace.loadProjectDescription(projectPath.append(IPath.SEPARATOR + IProjectDescription.DESCRIPTION_FILE_NAME));

final IProject project = workspace.getRoot().getProject(description.getName());

// Only import the project if it doesn’t appear to already exist. If it looks like it
// exists, tell the user about it.
if (project.exists()) {
System.err.println(“Project already exists”);
return false;

IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
project.create(description, monitor);, monitor);
};, workspace.getRuleFactory().modifyRule(workspace.getRoot()), IResource.NONE, null);
return true;

And it will import the project. \(*0*)/


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


This entry was posted on November 16, 2010 by in Java, Life on Marama.
%d bloggers like this: