// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
// public class JSBuildFileFactoryManager {
// 
// 	/**
// 	 * Returns the factory id for the given file and null otherwise.
// 	 * 
// 	 * @param file
// 	 *            (Gruntfile.js, gulpfile.js, etc)
// 	 * @return the factory id for the given file and null otherwise.
// 	 */
// 	public static String findFactoryId(IFile file) {
// 		return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
// 				file);
// 	}
// 
// 	/**
// 	 * Create an instance of {@link IJSBuildFile} from the given file.
// 	 * 
// 	 * @param file
// 	 *            (Gruntfile.js, gulpfile.js).
// 	 * @param factoryId
// 	 *            the factory id.
// 	 * @return an instance of {@link IJSBuildFile} from the given file.
// 	 */
// 	public static IJSBuildFile create(IFile file, String factoryId) {
// 		return JSBuildFileFactoriesRegistryReader.getInstance().create(file,
// 				factoryId);
// 	}
// 
// 	public static IJSBuildFileNode tryToCreate(IResource resource) {
// 		if (resource == null || resource.getType() != IResource.FILE) {
// 			return null;
// 		}
// 		IFile file = (IFile) resource;
// 		String factoryId = findFactoryId(file);
// 		if (factoryId == null) {
// 			return null;
// 		}
// 		return create(file, factoryId);
// 	}
// }


import fr.opensagres.eclipse.jsbuild.core.JSBuildFileFactoryManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
/**
 *  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 fr.opensagres.eclipse.jsbuild.internal.ui;



/**
 * Property Tester for a IResource receiver object
 * 
 * Property to be tested: "isJSBuildFile"
 * 
 */
public class JSBuildFileTester extends
		org.eclipse.core.expressions.PropertyTester {
	private static final String IS_JS_BUILD_FILE_PROPERTY = "isJSBuildFile";

	public JSBuildFileTester() {
		// Default constructor is required for property tester
	}

	/**
	 * Returns true if the receiver object is a JavaScript build file and false
	 * otherwise.
	 * 
	 * @return true if the receiver object is a JavaScript build file and false
	 *         otherwise.
	 */
	@Override
	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {

		if (IS_JS_BUILD_FILE_PROPERTY.equals(property))
			return testIsJSBuildFile(receiver,
					expectedValue != null ? expectedValue.toString() : "");

		return false;
	}

	private boolean testIsJSBuildFile(Object receiver, String expectedFactoryId) {
		if (receiver instanceof IAdaptable) {
			IResource resource = (IResource) ((IAdaptable) receiver)
					.getAdapter(IResource.class);
			if (resource != null && resource.getType() == IResource.FILE) {
				IFile file = (IFile) resource;
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
// public class JSBuildFileFactoryManager {
// 
// 	/**
// 	 * Returns the factory id for the given file and null otherwise.
// 	 * 
// 	 * @param file
// 	 *            (Gruntfile.js, gulpfile.js, etc)
// 	 * @return the factory id for the given file and null otherwise.
// 	 */
// 	public static String findFactoryId(IFile file) {
// 		return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
// 				file);
// 	}
// 
// 	/**
// 	 * Create an instance of {@link IJSBuildFile} from the given file.
// 	 * 
// 	 * @param file
// 	 *            (Gruntfile.js, gulpfile.js).
// 	 * @param factoryId
// 	 *            the factory id.
// 	 * @return an instance of {@link IJSBuildFile} from the given file.
// 	 */
// 	public static IJSBuildFile create(IFile file, String factoryId) {
// 		return JSBuildFileFactoriesRegistryReader.getInstance().create(file,
// 				factoryId);
// 	}
// 
// 	public static IJSBuildFileNode tryToCreate(IResource resource) {
// 		if (resource == null || resource.getType() != IResource.FILE) {
// 			return null;
// 		}
// 		IFile file = (IFile) resource;
// 		String factoryId = findFactoryId(file);
// 		if (factoryId == null) {
// 			return null;
// 		}
// 		return create(file, factoryId);
// 	}
// }


// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileTester.java
import fr.opensagres.eclipse.jsbuild.core.JSBuildFileFactoryManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;

/**
 *  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 fr.opensagres.eclipse.jsbuild.internal.ui;



/**
 * Property Tester for a IResource receiver object
 * 
 * Property to be tested: "isJSBuildFile"
 * 
 */
public class JSBuildFileTester extends
		org.eclipse.core.expressions.PropertyTester {
	private static final String IS_JS_BUILD_FILE_PROPERTY = "isJSBuildFile";

	public JSBuildFileTester() {
		// Default constructor is required for property tester
	}

	/**
	 * Returns true if the receiver object is a JavaScript build file and false
	 * otherwise.
	 * 
	 * @return true if the receiver object is a JavaScript build file and false
	 *         otherwise.
	 */
	@Override
	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {

		if (IS_JS_BUILD_FILE_PROPERTY.equals(property))
			return testIsJSBuildFile(receiver,
					expectedValue != null ? expectedValue.toString() : "");

		return false;
	}

	private boolean testIsJSBuildFile(Object receiver, String expectedFactoryId) {
		if (receiver instanceof IAdaptable) {
			IResource resource = (IResource) ((IAdaptable) receiver)
					.getAdapter(IResource.class);
			if (resource != null && resource.getType() == IResource.FILE) {
				IFile file = (IFile) resource;
				String actualFactoryId = JSBuildFileFactoryManager