/**
 * Copyright (C) 2014 SINTEF <franck.fleurey@sintef.no>
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3, 29 June 2007;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.thingml.eclipse.ui.popup.deprecated_actions;

import org.eclipse.core.internal.resources.File;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.sintef.thingml.Configuration;
import org.sintef.thingml.ThingMLModel;
import org.thingml.javagenerator.extension.MQTTGenerator;
import org.thingml.javagenerator.kevoree.KevoreeGenerator;

public class ThingMLCompileJS implements IObjectActionDelegate {

	private Shell shell;
	
	/**
	 * Constructor for Action1.
	 */
	public ThingMLCompileJS() {
		super();
	}

	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 */
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();
	}

	/**
	 * @see IActionDelegate#run(IAction)
	 */
	public void run(IAction action) {
		if (PlatformUI.getWorkbench().getActiveWorkbenchWindow()
				.getSelectionService().getSelection().isEmpty())
			return;
		File f = (File) ((TreeSelection) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getSelectionService()
				.getSelection()).getFirstElement();
		java.io.File f1 = f.getLocation().toFile();
		ThingMLModel thingmlModel = LoadModelUtil.getInstance()
				.loadThingMLmodel(f1);
		java.io.File ftemp = null;
		String tempDir = System.getProperty("java.io.tmpdir") + "tmp"
				+ System.nanoTime();
		ftemp = new java.io.File(tempDir);
		if (!ftemp.exists())
			ftemp.mkdir();
		for (Configuration c : thingmlModel.getConfigs())
			org.thingml.jsgenerator.JavaScriptGenerator.compileAndRun(c, thingmlModel,false, null);
	}

	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection) {
	}

}

@@ -683,16 +683,88 @@
 tions;%0A%0A
+import org.thingml.compilers.*;%0Aimport org.thingml.compilers.actions.*;%0A
 import o
@@ -2404,150 +2404,327 @@
 ();%0A
-%09%09for (Configuration c : thingmlModel.getConfigs())%0A%09%09%09org.thingml.jsgenerator.JavaScriptGenerator.compileAndRun(c, thingmlModel,false, null);
+%0A%0A%0A        ThingMLCompiler compiler = new JavaScriptCompiler(new JSActionCompiler());%0A        for (Configuration c : thingmlModel.getConfigs()) %7B%0A            compiler.setOutputDirectory(new java.io.File(System.getProperty(%22java.io.tmpdir%22) + %22/ThingML_temp/%22 + c.getName()));%0A            compiler.compile(c);%0A        %7D%0A
 %0A%09%7D%0A

fix eclipse action related to updated JS compiler