/**
 *  Copyright (c) 2013-2014 Angelo ZERR.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *  Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
 */
package org.eclipse.angularjs.core;

import java.io.IOException;

import org.eclipse.angularjs.internal.core.Trace;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;

import tern.TernProject;
import tern.server.TernDef;
import tern.server.TernPlugin;

/**
 * AngularJS Nature.
 * 
 */
public class AngularNature implements IProjectNature {

	public static final String ID = AngularCorePlugin.PLUGIN_ID
			+ ".angularnature"; //$NON-NLS-1$

	private IProject project;

	public boolean isConfigured() throws CoreException{
		if (project == null) return false;

		// has "angular" plugin?
		TernProject<?> ternProject = AngularProject.getTernProject(project);
		if (!ternProject.hasPlugin(TernPlugin.angular)) {
			return false;
		}
		
		// Has "browser" + "ecma5" JSON Type Def?
		if (!ternProject.hasLib(TernDef.browser.name())) {
			return false;
		}
		if (!ternProject.hasLib(TernDef.ecma5.name())) {
			return false;
		}

		return true;
	}

	public void configure() throws CoreException {
		if (isConfigured()) return;

 		// Add "angular" plugin
 		TernProject<?> ternProject = AngularProject.getTernProject(project);
 		if (!ternProject.hasPlugin(TernPlugin.angular)) {
 			ternProject.addPlugin(TernPlugin.angular);
 		}
 		
 		// Add "browser" + "ecma5" JSON Type Def
 		if (!ternProject.hasLib(TernDef.browser.name())) {
 			ternProject.addLib(TernDef.browser.name());
 		}
 		if (!ternProject.hasLib(TernDef.ecma5.name())) {
 			ternProject.addLib(TernDef.ecma5.name());
 		}
 		
		try {
			ternProject.save();
		} catch (IOException e) {
			Trace.trace(Trace.SEVERE,
					"Error while configuring angular nature.", e);
 		}
	}
	
	public void deconfigure() throws CoreException {
		// Remove the nature-specific information here.
	}

	public IProject getProject() {
		return project;
	}

	public void setProject(IProject value) {
		project = value;
	}

}

@@ -1291,31 +1291,24 @@
 nDef.browser
-.name()
 )) %7B%0A%09%09%09retu
@@ -1356,31 +1356,24 @@
 ernDef.ecma5
-.name()
 )) %7B%0A%09%09%09retu
@@ -1779,23 +1779,16 @@
 .browser
-.name()
 )) %7B%0A %09%09
@@ -1822,23 +1822,16 @@
 .browser
-.name()
 );%0A %09%09%7D%0A
@@ -1870,23 +1870,16 @@
 ef.ecma5
-.name()
 )) %7B%0A %09%09
@@ -1915,15 +1915,8 @@
 cma5
-.name()
 );%0A 

Use TernProject#hasLib(ITernDef def)