// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUIPlugin.java
// public class JSBuildFileUIPlugin extends AbstractUIPlugin {
// 
// 	// The plug-in ID
// 	public static final String PLUGIN_ID = "fr.opensagres.eclipse.jsbuild.ui"; //$NON-NLS-1$
// 
// 	// The shared instance
// 	private static JSBuildFileUIPlugin plugin;
// 
// 	/**
// 	 * The constructor
// 	 */
// 	public JSBuildFileUIPlugin() {
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// 	 * )
// 	 */
// 	public void start(BundleContext context) throws Exception {
// 		super.start(context);
// 		plugin = this;
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// 	 * )
// 	 */
// 	public void stop(BundleContext context) throws Exception {
// 		plugin = null;
// 		super.stop(context);
// 	}
// 
// 	/**
// 	 * Returns the shared instance
// 	 * 
// 	 * @return the shared instance
// 	 */
// 	public static JSBuildFileUIPlugin getDefault() {
// 		return plugin;
// 	}
// 
// 	/**
// 	 * Returns the standard display to be used. The method first checks, if the
// 	 * thread calling this method has an associated display. If so, this display
// 	 * is returned. Otherwise the method returns the default display.
// 	 */
// 	public static Display getStandardDisplay() {
// 		Display display = Display.getCurrent();
// 		if (display == null) {
// 			display = Display.getDefault();
// 		}
// 		return display;
// 	}
// 
// 	/**
// 	 * Returns the {@link IDialogSettings} section with the given name. Creates
// 	 * a new section if one does not exist.
// 	 * 
// 	 * @param name
// 	 * @return the {@link IDialogSettings} section with the given name
// 	 */
// 	public IDialogSettings getDialogSettingsSection(String name) {
// 		IDialogSettings dialogSettings = getDialogSettings();
// 		IDialogSettings section = dialogSettings.getSection(name);
// 		if (section == null) {
// 			section = dialogSettings.addNewSection(name);
// 		}
// 		return section;
// 	}
// 
// 	/**
// 	 * Returns the active workbench window or <code>null</code> if none
// 	 */
// 	public static IWorkbenchWindow getActiveWorkbenchWindow() {
// 		return getDefault().getWorkbench().getActiveWorkbenchWindow();
// 	}
// 
// 	public static IWorkbenchPage getActivePage() {
// 		return getActiveWorkbenchWindow().getActivePage();
// 	}
// 
// }


import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.custom.BusyIndicator;
import fr.opensagres.eclipse.jsbuild.internal.ui.JSBuildFileUIPlugin;
/**
 *  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.dialogs;




public class FileFilter extends ViewerFilter {

	/**
	 * Objects to filter
	 */
	private List<?> fFilter;

	/**
	 * Collection of files and containers to display
	 */
	private Set<IResource> fFiles;

	private String fExtension;

	private Pattern fExtnPattern;

	private boolean fConsiderExtension = true;

	/**
	 * Creates a new filter that filters the given objects. Note:
	 * considerExtension must be called to initialize the filter
	 */
	public FileFilter(List<?> objects, String extension) {
		fFilter = objects;
		fExtension = extension;
		if (extension.indexOf('|') > 0) { // Shouldn't be the first char!
			// This is a pattern; compile and cache it for better performance
			fExtnPattern = Pattern
					.compile(fExtension, Pattern.CASE_INSENSITIVE);
		} else {
			fExtnPattern = null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers
	 * .Viewer, java.lang.Object, java.lang.Object)
	 */
	@Override
	public boolean select(Viewer viewer, Object parentElement, Object element) {
		return fFiles.contains(element) && !fFilter.contains(element);
	}

	/**
	 * Search for all the matching files in the workspace.
	 */
	private void init() {
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUIPlugin.java
// public class JSBuildFileUIPlugin extends AbstractUIPlugin {
// 
// 	// The plug-in ID
// 	public static final String PLUGIN_ID = "fr.opensagres.eclipse.jsbuild.ui"; //$NON-NLS-1$
// 
// 	// The shared instance
// 	private static JSBuildFileUIPlugin plugin;
// 
// 	/**
// 	 * The constructor
// 	 */
// 	public JSBuildFileUIPlugin() {
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// 	 * )
// 	 */
// 	public void start(BundleContext context) throws Exception {
// 		super.start(context);
// 		plugin = this;
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see
// 	 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// 	 * )
// 	 */
// 	public void stop(BundleContext context) throws Exception {
// 		plugin = null;
// 		super.stop(context);
// 	}
// 
// 	/**
// 	 * Returns the shared instance
// 	 * 
// 	 * @return the shared instance
// 	 */
// 	public static JSBuildFileUIPlugin getDefault() {
// 		return plugin;
// 	}
// 
// 	/**
// 	 * Returns the standard display to be used. The method first checks, if the
// 	 * thread calling this method has an associated display. If so, this display
// 	 * is returned. Otherwise the method returns the default display.
// 	 */
// 	public static Display getStandardDisplay() {
// 		Display display = Display.getCurrent();
// 		if (display == null) {
// 			display = Display.getDefault();
// 		}
// 		return display;
// 	}
// 
// 	/**
// 	 * Returns the {@link IDialogSettings} section with the given name. Creates
// 	 * a new section if one does not exist.
// 	 * 
// 	 * @param name
// 	 * @return the {@link IDialogSettings} section with the given name
// 	 */
// 	public IDialogSettings getDialogSettingsSection(String name) {
// 		IDialogSettings dialogSettings = getDialogSettings();
// 		IDialogSettings section = dialogSettings.getSection(name);
// 		if (section == null) {
// 			section = dialogSettings.addNewSection(name);
// 		}
// 		return section;
// 	}
// 
// 	/**
// 	 * Returns the active workbench window or <code>null</code> if none
// 	 */
// 	public static IWorkbenchWindow getActiveWorkbenchWindow() {
// 		return getDefault().getWorkbench().getActiveWorkbenchWindow();
// 	}
// 
// 	public static IWorkbenchPage getActivePage() {
// 		return getActiveWorkbenchWindow().getActivePage();
// 	}
// 
// }


// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/dialogs/FileFilter.java
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.custom.BusyIndicator;
import fr.opensagres.eclipse.jsbuild.internal.ui.JSBuildFileUIPlugin;

/**
 *  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.dialogs;




public class FileFilter extends ViewerFilter {

	/**
	 * Objects to filter
	 */
	private List<?> fFilter;

	/**
	 * Collection of files and containers to display
	 */
	private Set<IResource> fFiles;

	private String fExtension;

	private Pattern fExtnPattern;

	private boolean fConsiderExtension = true;

	/**
	 * Creates a new filter that filters the given objects. Note:
	 * considerExtension must be called to initialize the filter
	 */
	public FileFilter(List<?> objects, String extension) {
		fFilter = objects;
		fExtension = extension;
		if (extension.indexOf('|') > 0) { // Shouldn't be the first char!
			// This is a pattern; compile and cache it for better performance
			fExtnPattern = Pattern
					.compile(fExtension, Pattern.CASE_INSENSITIVE);
		} else {
			fExtnPattern = null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers
	 * .Viewer, java.lang.Object, java.lang.Object)
	 */
	@Override
	public boolean select(Viewer viewer, Object parentElement, Object element) {
		return fFiles.contains(element) && !fFilter.contains(element);
	}

	/**
	 * Search for all the matching files in the workspace.
	 */
	private void init() {
		BusyIndicator.showWhile(JSBuildFileUIPlugin.getStandardDisplay(),