/*
 * Copyright 2014, Hridesh Rajan, Sambhav Srirama, Robert Dyer,
 *                 and Iowa State University of Science and Technology
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 edu.iastate.cs.boa.ui.wizard;

import java.util.Collections;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.xtext.ui.XtextProjectHelper;

/**
 * Customize the Boa project creator, so it doesn't make a bunch of
 * unnecessary folders or use unnecessary natures.
 * 
 * @author sambhav
 * @author rdyer
 */
public class BoaCustomProjectCreator extends BoaProjectCreator {
	@Override
	protected String[] getBuilders() {
		// we want the Xtext builder by default
		return new String[] { XtextProjectHelper.BUILDER_ID };
	}

	protected String[] getProjectNatures() {
		// we want the Xtext nature by default
		return new String[] { XtextProjectHelper.NATURE_ID };
	}

	@Override
	protected List<String> getAllFolders() {
		// no source folders for Boa projects
		return Collections.emptyList();
	}

	// since we generate files into the root, we have to provide
	// custom code for this method, which uses the root for iteration
	protected IFile getModelFile(IProject project) throws CoreException {
		final String expectedExtension = getPrimaryModelFileExtension();
		final IFile[] result = new IFile[1];
		project.accept(new IResourceVisitor() {
			public boolean visit(IResource resource) throws CoreException {
				if (IResource.FILE == resource.getType()) {
					if (expectedExtension.equals(resource.getFileExtension()))
						result[0] = (IFile) resource;
					return false;
				}
				return true;
			}
		});
		return result[0];
	}
}

@@ -1349,102 +1349,32 @@
 %7B%0A%09%09
-// we want the Xtext builder by default%0A%09%09return new String%5B%5D %7B XtextProjectHelper.BUILDER_ID 
+return new String%5B%5D %7B%0A%09%09
 %7D;%0A%09
@@ -1422,49 +1422,8 @@
 ) %7B%0A
-%09%09// we want the Xtext nature by default%0A
 %09%09re
@@ -1441,17 +1441,20 @@
 ring%5B%5D %7B
- 
+%0A%09%09%09
 XtextPro
@@ -1474,16 +1474,57 @@
 TURE_ID 
+// we want the Xtext nature by default%0A%09%09
 %7D;%0A%09%7D%0A%0A%09

remove xtext builder, as we arent using the generator yet