	private void createFile(IProject project, IPath projectRelativePath, String content,
			boolean firstTimeOnly, IProgressMonitor monitor) {
		try {
			IContainer container = project;
			String[] folders = projectRelativePath.removeLastSegments(1).segments();
			for (int i = 0; i < folders.length; i++) {
				container = container.getFolder(new Path(folders[i]));
				if (!container.exists()) {
					((IFolder)container).create(true, true, monitor);
				}
			}
			IFile file = container.getFile(new Path(projectRelativePath.lastSegment()));
			if (!file.exists() && file.getParent().exists()) {
				IResource[] members = file.getParent().members(IResource.FILE);
				for (int i = 0; i < members.length; i++) {
					if (members[i] instanceof IFile
							&& file.getName().toLowerCase().equals(members[i].getName().toLowerCase())) {
						file = (IFile)members[i];
						break;
					}
				}
			}
			String text = content;
			if (!firstTimeOnly && file.exists() && "java".equals(file.getFileExtension())) { 
				String jmergeFile = URI.createPlatformPluginURI(
						"org.eclipse.emf.codegen.ecore/templates/emf-merge.xml", false).toString(); 
				JControlModel model = new JControlModel();
				ASTFacadeHelper astFacadeHelper = new ASTFacadeHelper();
				model.initialize(astFacadeHelper, jmergeFile);
				if (model.canMerge()) {
					JMerger jMerger = new JMerger(model);
					jMerger.setSourceCompilationUnit(jMerger.createCompilationUnitForContents(text));
					try {
						jMerger.setTargetCompilationUnit(jMerger
								.createCompilationUnitForInputStream(new FileInputStream(file.getLocation()
										.toFile()))); 
						jMerger.merge();
						text = jMerger.getTargetCompilationUnit().getContents();
					} catch (FileNotFoundException e) {
						AcceleoUIActivator.getDefault().getLog().log(
								new Status(IStatus.ERROR, AcceleoUIActivator.PLUGIN_ID, e.getMessage(), e));
					}
				} else {
					AcceleoUIActivator.getDefault().getLog().log(
							new Status(IStatus.WARNING, AcceleoUIActivator.PLUGIN_ID, AcceleoUIMessages
									.getString("CreateRunnableAcceleoOperation.MergerFailure"), null)); 
				}
			}
			if (!file.exists()
					|| (!firstTimeOnly && !text.equals(FileContent
							.getFileContent(file.getLocation().toFile()).toString()))) {
				ByteArrayInputStream javaStream = new ByteArrayInputStream(text.getBytes("UTF8")); 
				if (!file.exists()) {
					file.create(javaStream, true, monitor);
				} else if (!firstTimeOnly) {
					file.setContents(javaStream, true, false, monitor);
				}
			}
		} catch (CoreException e) {
			IStatus status = new Status(IStatus.ERROR, AcceleoUIActivator.PLUGIN_ID, IStatus.OK, e
					.getMessage(), e);
			AcceleoUIActivator.getDefault().getLog().log(status);
		} catch (UnsupportedEncodingException e) {
			IStatus status = new Status(IStatus.ERROR, AcceleoUIActivator.PLUGIN_ID, IStatus.OK, e
					.getMessage(), e);
			AcceleoUIActivator.getDefault().getLog().log(status);
		}
	}

	private void createFile(IProject project, IPath projectRelativePath, String content,
			boolean firstTimeOnly, IProgressMonitor monitor) {
		try {
			IContainer container = project;
			String[] folders = projectRelativePath.removeLastSegments(1).segments();
			for (int i = 0; i < folders.length; i++) {
				container = container.getFolder(new Path(folders[i]));
				if (!container.exists()) {
					((IFolder)container).create(true, true, monitor);
				}
			}
			IFile file = container.getFile(new Path(projectRelativePath.lastSegment()));
			if (!file.exists() && file.getParent().exists()) {
				IResource[] members = file.getParent().members(IResource.FILE);
				for (int i = 0; i < members.length; i++) {
					if (members[i] instanceof IFile
							&& file.getName().toLowerCase().equals(members[i].getName().toLowerCase())) {
						file = (IFile)members[i];
						break;
					}
				}
			}
			String text = content;
			if (!firstTimeOnly && file.exists() && "java".equals(file.getFileExtension())) { 
				String jmergeFile = URI.createPlatformPluginURI(
						"org.eclipse.emf.codegen.ecore/templates/emf-merge.xml", false).toString(); 
				JControlModel model = new JControlModel();
				ASTFacadeHelper astFacadeHelper = new ASTFacadeHelper();
				model.initialize(astFacadeHelper, jmergeFile);
				if (model.canMerge()) {
					JMerger jMerger = new JMerger(model);
					jMerger.setSourceCompilationUnit(jMerger.createCompilationUnitForContents(text));
					try {
						jMerger.setTargetCompilationUnit(jMerger
								.createCompilationUnitForInputStream(new FileInputStream(file.getLocation()
										.toFile()))); 
						jMerger.merge();
						text = jMerger.getTargetCompilationUnit().getContents();
					} catch (FileNotFoundException e) {
						AcceleoUIActivator.getDefault().getLog().log(
								new Status(IStatus.ERROR, AcceleoUIActivator.PLUGIN_ID, e.getMessage(), e));
					}
				} else {
					AcceleoUIActivator.getDefault().getLog().log(
							new Status(IStatus.WARNING, AcceleoUIActivator.PLUGIN_ID, AcceleoUIMessages
									.getString("CreateRunnableAcceleoOperation.MergerUnusable"), null)); 
				}
			}
			if (!file.exists()
					|| (!firstTimeOnly && !text.equals(FileContent
							.getFileContent(file.getLocation().toFile()).toString()))) {
				ByteArrayInputStream javaStream = new ByteArrayInputStream(text.getBytes("UTF8")); 
				if (!file.exists()) {
					file.create(javaStream, true, monitor);
				} else if (!firstTimeOnly) {
					file.setContents(javaStream, true, false, monitor);
				}
			}
		} catch (CoreException e) {
			IStatus status = new Status(IStatus.ERROR, AcceleoUIActivator.PLUGIN_ID, IStatus.OK, e
					.getMessage(), e);
			AcceleoUIActivator.getDefault().getLog().log(status);
		} catch (UnsupportedEncodingException e) {
			IStatus status = new Status(IStatus.ERROR, AcceleoUIActivator.PLUGIN_ID, IStatus.OK, e
					.getMessage(), e);
			AcceleoUIActivator.getDefault().getLog().log(status);
		}
	}
