package android.malware.detection.actions;



import java.awt.Event;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

//import android.malware.detection.form.FormView;
//import android.malware.detection.form.OpenFormDialog;
import android.malware.detection.logic.Extractortwo;
import android.malware.detection.ui.AndroidSecurityExtractionWizardtwo;
import android.malware.detection.ui.AndroidSecurityExtractorWizardPagetwo;


import org.eclipse.jface.dialogs.MessageDialog;

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


	public void run(IAction action) {
		
		try {
			
			AndroidSecurityExtractionWizardtwo wizard = new AndroidSecurityExtractionWizardtwo();
			WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
			
			if (dialog.open() == Window.OK) {
				AndroidSecurityExtractorWizardPagetwo page = (AndroidSecurityExtractorWizardPagetwo)wizard.getPage("SelectProjectAndXMLDescriptors");
				IProject javaProject = page.getSelectedProject();
				String AndroidManifestDescriptor = page.getAndroidManifestDescriptor();
				String AndroidManifestDescriptor1 =  "file:/"+ ResourcesPlugin.getWorkspace().getRoot().getLocation().toString()+ "/" + javaProject.getName() + "/" + "AndroidManifest.xml";
				System.out.print("   AndroidManifestDescriptor : " + AndroidManifestDescriptor);			
				//for time:
				
				long startTime = System.currentTimeMillis();
				System.out.println("--------------start time----------------:"+startTime);
				Extractortwo ext = new Extractortwo(javaProject, AndroidManifestDescriptor1);
				
				ext.execute();
				//end
				long endTime   = System.currentTimeMillis();
				long totalTime = endTime - startTime;
				System.out.println("--------------totalTime----------------:"+totalTime);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		//FormView  displayMaliciousPermission=new FormView();
	}

	public void selectionChanged(IAction action, ISelection selection) {
	}

	public void dispose() {
		
	}

	public void init(IWorkbenchWindow window) {
		this.window = window;
	}
}
