package rhogenwizard.actions;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

import rhogenwizard.project.ProjectFactory;
import rhogenwizard.project.RhodesProject;
import rhogenwizard.sdk.facade.RhoTaskHolder;
import rhogenwizard.sdk.task.GenerateRhodesAppTask;
import rhogenwizard.sdk.task.GenerateRhodesSpecTask;

public class GenerateSpecAction implements IWorkbenchWindowActionDelegate 
{
	private IWorkbenchWindow window;
	/**
	 * The constructor.
	 */
	public GenerateSpecAction() 
	{
	}

	public void run(IAction action) 
	{
		IProject project = ProjectFactory.getInstance().getSelectedProject();
		
		if (project == null)
			return;
		
		if (!RhodesProject.checkNature(project))
			return;
	
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(GenerateRhodesAppTask.workDir, project.getLocation().toOSString());
		
		RhoTaskHolder.getInstance().runTask(GenerateRhodesSpecTask.class, params);
		
		try 
		{
			project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
		} 
		catch (CoreException e) 
		{
			e.printStackTrace();
		}
	}

	/**
	 * Selection in the workbench has been changed. We 
	 * can change the state of the 'real' action here
	 * if we want, but this can only happen after 
	 * the delegate has been created.
	 * @see IWorkbenchWindowActionDelegate#selectionChanged
	 */
	public void selectionChanged(IAction action, ISelection selection) 
	{
	}

	/**
	 * We can use this method to dispose of any system
	 * resources we previously allocated.
	 * @see IWorkbenchWindowActionDelegate#dispose
	 */
	public void dispose()
	{
	}

	/**
	 * We will cache window object in order to
	 * be able to provide parent shell for the message dialog.
	 * @see IWorkbenchWindowActionDelegate#init
	 */
	public void init(IWorkbenchWindow window) 
	{
		this.window = window;
	}
}
@@ -299,24 +299,72 @@
 on.IAction;%0A
+import org.eclipse.jface.dialogs.MessageDialog;%0A
 import org.e
@@ -392,24 +392,24 @@
 ISelection;%0A
-
 import org.e
@@ -829,25 +829,36 @@
 benchWindow 
-w
+m_workbenchW
 indow;%0A%09/**%0A
@@ -1055,16 +1055,147 @@
 = null)%0A
+%09%09%7B%0A%09%09%09MessageDialog.openError(m_workbenchWindow.getShell(), %22Error%22, %22You can generate spec files after select rhodes project.%22);%0A
 %09%09%09retur
@@ -1197,16 +1197,20 @@
 return;%0A
+%09%09%7D%0A
 %09%09%0A%09%09if 
@@ -1247,16 +1247,139 @@
 oject))%0A
+%09%09%7B%0A%09%09%09MessageDialog.openInformation(m_workbenchWindow.getShell(), %22Information%22, %22Selected item is not rhodes project.%22);%0A
 %09%09%09retur
@@ -1381,16 +1381,20 @@
 return;%0A
+%09%09%7D%0A
 %09%0A%09%09Map%3C
@@ -2492,17 +2492,28 @@
 %0A%09%09this.
-w
+m_workbenchW
 indow = 

add msg box