/*
 * Copyright 1999-2004 The Apache Software Foundation.
 * 
 * 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 org.apache.forrest.eclipse.popup.actions;

import org.apache.forrest.eclipse.job.ForrestManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class StopForrest 
implements IObjectActionDelegate, IJavaLaunchConfigurationConstants {   

	private IProject activeProject;
	
	/**
	 * Constructor for Action1.
	 */
	public StopForrest() {
		super();
	}

	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 */
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
	}

	/**
	 * @see IActionDelegate#run(IAction)
	 */
	public void run(IAction action) {
		IPath workingDirectory = activeProject.getLocation();
		Job forrest = ForrestManager.getInstance().getForrestJob(workingDirectory.toOSString(), ForrestManager.COMMAND_STOP);
		forrest.setUser(true);
		forrest.schedule();
	}

	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 */
	public void selectionChanged(IAction action, ISelection selection) {
	}

}
@@ -766,16 +766,61 @@
 roject;%0A
+import org.eclipse.core.resources.IResource;%0A
 import o
@@ -1042,24 +1042,79 @@
 ISelection;%0A
+import org.eclipse.jface.viewers.IStructuredSelection;%0A
 import org.e
@@ -2042,17 +2042,320 @@
 election) %7B%0A
+%09%09if (selection instanceof IStructuredSelection) %7B%0A%09%09%09Object first = ((IStructuredSelection)selection).getFirstElement();%0A            IResource resource = (IResource)first;%0A            if (resource instanceof IProject) %7B%0A                activeProject = (IProject)resource;%0A            %7D            %0A%09%09%7D%0A
 %09%7D%0A%0A%7D

monitor selection changed events so we keep track of the active project.