/*************************************************************************************
 * Copyright (c) 2004 Actuate Corporation and others.
 * 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:
 *     Actuate Corporation - Initial implementation.
 ************************************************************************************/

package org.eclipse.birt.integration.wtp.ui.project.facet;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jst.common.project.facet.core.ClasspathHelper;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;

/**
 * Delegate class for invoke "CHANGED" event
 * 
 */
public final class BirtFacetRuntimeChangedDelegate
		implements
			IDelegate,
			IBirtFacetConstants
{

	/**
	 * Invoke "CHANGED" event for project facet
	 * 
	 * @see org.eclipse.wst.common.project.facet.core.IDelegate#execute(org.eclipse.core.resources.IProject,
	 *      org.eclipse.wst.common.project.facet.core.IProjectFacetVersion,
	 *      java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
	 */
	public void execute( IProject project, IProjectFacetVersion fv,
			Object config, IProgressMonitor monitor ) throws CoreException
	{
		if ( monitor != null )
		{
			monitor.beginTask( "", 1 ); //$NON-NLS-1$
		}

		try
		{
			ClasspathHelper.removeClasspathEntries( project, fv );

			if ( !ClasspathHelper.addClasspathEntries( project, fv ) )
			{
				// TODO: Support the no runtime case.

			}

			if ( monitor != null )
			{
				monitor.worked( 1 );
			}
		}
		finally
		{
			if ( monitor != null )
			{
				monitor.done( );
			}
		}

	}

}
