// Path: si.gos.transpiler.core/src/si/gos/transpiler/core/TranspilerNature.java
// public class TranspilerNature implements IProjectNature {
// 
// 	/**
// 	 * ID of this project nature
// 	 */
// 	public static final String NATURE_ID = "si.gos.transpiler.nature";
// 
// 	private IProject project;
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.resources.IProjectNature#configure()
// 	 */
// 	public void configure() throws CoreException {
// 		IProjectDescription desc = project.getDescription();
// 		ICommand[] commands = desc.getBuildSpec();
// 
// 		for (int i = 0; i < commands.length; ++i) {
// 			if (commands[i].getBuilderName().equals(TranspilerBuilder.ID)) {
// 				return;
// 			}
// 		}
// 
// 		ICommand[] newCommands = new ICommand[commands.length + 1];
// 		System.arraycopy(commands, 0, newCommands, 0, commands.length);
// 		ICommand command = desc.newCommand();
// 		command.setBuilderName(TranspilerBuilder.ID);
// 		newCommands[newCommands.length - 1] = command;
// 		desc.setBuildSpec(newCommands);
// 		project.setDescription(desc, null);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.resources.IProjectNature#deconfigure()
// 	 */
// 	public void deconfigure() throws CoreException {
// 		IProjectDescription description = getProject().getDescription();
// 		ICommand[] commands = description.getBuildSpec();
// 		for (int i = 0; i < commands.length; ++i) {
// 			if (commands[i].getBuilderName().equals(TranspilerBuilder.ID)) {
// 				ICommand[] newCommands = new ICommand[commands.length - 1];
// 				System.arraycopy(commands, 0, newCommands, 0, i);
// 				System.arraycopy(commands, i + 1, newCommands, i,
// 						commands.length - i - 1);
// 				description.setBuildSpec(newCommands);
// 				project.setDescription(description, null);			
// 				return;
// 			}
// 		}
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.resources.IProjectNature#getProject()
// 	 */
// 	public IProject getProject() {
// 		return project;
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
// 	 */
// 	public void setProject(IProject project) {
// 		this.project = project;
// 	}
// 
// }


import java.util.Iterator;
import org.eclipse.core.commands.*;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import si.gos.transpiler.core.TranspilerNature;
package si.gos.transpiler.ui.handler;




public class AddTranspilerNatureHandler extends AbstractHandler {

	public Object execute(ExecutionEvent event) throws ExecutionException {
		ISelection selection = HandlerUtil.getCurrentSelection(event);

		if (selection instanceof IStructuredSelection) {
			for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it
					.hasNext();) {
				Object element = it.next();
				IProject project = null;
				if (element instanceof IProject) {
					project = (IProject) element;
				} else if (element instanceof IAdaptable) {
					project = (IProject) ((IAdaptable) element)
							.getAdapter(IProject.class);
				}
				if (project != null) {
					try {
						addTranspilerNature(project);
					} catch (CoreException e) {
						throw new ExecutionException("Failed to toggle nature", e);
					}
				}
			}
		}

		return null;
	}

	/**
	 * Adds transpiler nature on a project
	 *
	 * @param project
	 *            to have transpiler nature added
	 */
	private void addTranspilerNature(IProject project) throws CoreException {
		IProjectDescription description = project.getDescription();
		String[] natures = description.getNatureIds();

		// Add the nature
// Path: si.gos.transpiler.core/src/si/gos/transpiler/core/TranspilerNature.java
// public class TranspilerNature implements IProjectNature {
// 
// 	/**
// 	 * ID of this project nature
// 	 */
// 	public static final String NATURE_ID = "si.gos.transpiler.nature";
// 
// 	private IProject project;
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.resources.IProjectNature#configure()
// 	 */
// 	public void configure() throws CoreException {
// 		IProjectDescription desc = project.getDescription();
// 		ICommand[] commands = desc.getBuildSpec();
// 
// 		for (int i = 0; i < commands.length; ++i) {
// 			if (commands[i].getBuilderName().equals(TranspilerBuilder.ID)) {
// 				return;
// 			}
// 		}
// 
// 		ICommand[] newCommands = new ICommand[commands.length + 1];
// 		System.arraycopy(commands, 0, newCommands, 0, commands.length);
// 		ICommand command = desc.newCommand();
// 		command.setBuilderName(TranspilerBuilder.ID);
// 		newCommands[newCommands.length - 1] = command;
// 		desc.setBuildSpec(newCommands);
// 		project.setDescription(desc, null);
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.resources.IProjectNature#deconfigure()
// 	 */
// 	public void deconfigure() throws CoreException {
// 		IProjectDescription description = getProject().getDescription();
// 		ICommand[] commands = description.getBuildSpec();
// 		for (int i = 0; i < commands.length; ++i) {
// 			if (commands[i].getBuilderName().equals(TranspilerBuilder.ID)) {
// 				ICommand[] newCommands = new ICommand[commands.length - 1];
// 				System.arraycopy(commands, 0, newCommands, 0, i);
// 				System.arraycopy(commands, i + 1, newCommands, i,
// 						commands.length - i - 1);
// 				description.setBuildSpec(newCommands);
// 				project.setDescription(description, null);			
// 				return;
// 			}
// 		}
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.resources.IProjectNature#getProject()
// 	 */
// 	public IProject getProject() {
// 		return project;
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
// 	 */
// 	public void setProject(IProject project) {
// 		this.project = project;
// 	}
// 
// }


// Path: si.gos.transpiler.ui/src/si/gos/transpiler/ui/handler/AddTranspilerNatureHandler.java
import java.util.Iterator;
import org.eclipse.core.commands.*;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import si.gos.transpiler.core.TranspilerNature;

package si.gos.transpiler.ui.handler;




public class AddTranspilerNatureHandler extends AbstractHandler {

	public Object execute(ExecutionEvent event) throws ExecutionException {
		ISelection selection = HandlerUtil.getCurrentSelection(event);

		if (selection instanceof IStructuredSelection) {
			for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it
					.hasNext();) {
				Object element = it.next();
				IProject project = null;
				if (element instanceof IProject) {
					project = (IProject) element;
				} else if (element instanceof IAdaptable) {
					project = (IProject) ((IAdaptable) element)
							.getAdapter(IProject.class);
				}
				if (project != null) {
					try {
						addTranspilerNature(project);
					} catch (CoreException e) {
						throw new ExecutionException("Failed to toggle nature", e);
					}
				}
			}
		}

		return null;
	}

	/**
	 * Adds transpiler nature on a project
	 *
	 * @param project
	 *            to have transpiler nature added
	 */
	private void addTranspilerNature(IProject project) throws CoreException {
		IProjectDescription description = project.getDescription();
		String[] natures = description.getNatureIds();

		// Add the nature
		String[] newNatures = new String[natures.length + 1];