/**
 *  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.internal.ui.handlers;

import java.io.IOException;

import org.eclipse.angularjs.internal.ui.AngularUIMessages;
import org.eclipse.angularjs.internal.ui.Trace;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.handlers.HandlerUtil;

import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.core.TernCorePlugin;
import tern.eclipse.ide.ui.handlers.AbstractConvertProjectCommandHandler;
import tern.server.ITernDef;
import tern.server.ITernPlugin;
import tern.server.TernDef;
import tern.server.TernPlugin;

/**
 * Convert selected project to Angular project.
 * 
 */
public class ConvertProjectToAngularCommandHandler extends
		AbstractConvertProjectCommandHandler {

	@Override
	protected String getConvertingProjectJobTitle(IProject project) {
		return NLS
				.bind(AngularUIMessages.ConvertProjectToAngular_converting_project_job_title,
						project.getName());
	}

	@Override
	protected ITernPlugin[] getPlugins(IScopeContext[] fLookupOrder) {
		return new ITernPlugin[] { TernPlugin.angular };
	}

	@Override
	protected ITernDef[] getDefs(IScopeContext[] fLookupOrder) {
		return new ITernDef[] { TernDef.browser, TernDef.ecma5 };
	}

}

@@ -455,329 +455,73 @@
 ava.
-io.IOException;%0A%0Aimport org.eclipse.angularjs.internal.ui.AngularUIMessages;%0Aimport org.eclipse.angularjs.internal.ui.Trace;%0Aimport org.eclipse.core.commands.AbstractHandler;%0Aimport org.eclipse.core.commands.ExecutionEvent;%0Aimport org.eclipse.core.commands.ExecutionException;%0Aimport org.eclipse.core.resources.IProjec
+util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Lis
 t;%0A
+%0A
 impo
@@ -539,636 +539,186 @@
 pse.
-core.resources.ResourcesPlugin;%0Aimport org.eclipse.core.resources.WorkspaceJob;%0Aimport org.eclipse.core.runtime.CoreException;%0Aimport org.eclipse.core.runtime.IProgressMonitor;%0Aimport org.eclipse.core.runtime.IStatus;%0Aimport org.eclipse.core.runtime.Platform;%0Aimport org.eclipse.core.runtime.Status;%0Aimport org.eclipse.core.runtime.preferences.IScopeContext;%0Aimport org.eclipse.jface.viewers.ISelection;%0Aimport org.eclipse.jface.viewers.IStructuredSelection;%0Aimport org.eclipse.osgi.util.NLS;%0Aimport org.eclipse.ui.handlers.HandlerUtil;%0A%0Aimport tern.eclipse.ide.core.IIDETernProject;%0Aimport tern.eclipse.ide.core.TernCorePlugin;
+angularjs.internal.ui.AngularUIMessages;%0Aimport org.eclipse.core.resources.IProject;%0Aimport org.eclipse.core.runtime.preferences.IScopeContext;%0Aimport org.eclipse.osgi.util.NLS;%0A
 %0Aimp
@@ -816,43 +816,14 @@
 Tern
-Def;%0Aimport tern.server.ITernPlugin
+Module
 ;%0Aim
@@ -1275,26 +1275,26 @@
 Tern
-Plugin%5B%5D getPlugin
+Module%5B%5D getModule
 s(IS
@@ -1329,196 +1329,414 @@
 %7B%0A%09%09
-return new ITernPlugin%5B%5D %7B TernPlugin.angular %7D;%0A%09%7D%0A%0A%09@Override%0A%09protected ITernDef%5B%5D getDefs(IScopeContext%5B%5D fLookupOrder) %7B%0A%09%09return new ITernDef%5B%5D %7B TernDef.browser, TernDef.ecma5 %7D
+List%3CITernModule%3E modules = new ArrayList%3CITernModule%3E(%0A%09%09%09%09Arrays.asList(super.getModules(fLookupOrder)));%0A%09%09if (!modules.contains(TernDef.ecma5)) %7B%0A%09%09%09modules.add(TernDef.ecma5);%0A%09%09%7D%0A%09%09if (!modules.contains(TernDef.browser)) %7B%0A%09%09%09modules.add(TernDef.browser);%0A%09%09%7D%0A%09%09if (!modules.contains(TernPlugin.angular)) %7B%0A%09%09%09modules.add(TernPlugin.angular);%0A%09%09%7D%0A%09%09return modules.toArray(ITernModule.EMPTY_MODULE)
 ;%0A%09%7D%0A
-%0A
 %7D%0A

Support default modules. Fix https://github.com/angelozerr/tern.java/issues/223