// Path: EclipsePlugin/plugin/src/io/leocad/dumbledroidplugin/core/DumbledroidClassCreator.java
// public class DumbledroidClassCreator {
// 
// 	public static void create(String urlAddress, boolean isPojo, long cacheDuration, IFile file, IProgressMonitor monitor) throws UnsupportedContentTypeException, InvalidUrlException, InvalidContentException {
// 
// 		monitor.beginTask("Validating URL…", 2);
// 		URL url = null;
// 		try {
// 			url = new URL(urlAddress);
// 		} catch (MalformedURLException e1) {
// 			e1.printStackTrace();
// 			// Will never happen. The URL was already validated on UrlInputPage
// 		}
// 		
// 		HttpURLConnection connection;
// 		try {
// 			connection = (HttpURLConnection) url.openConnection();
// 			connection.connect();
// 		} catch (IOException e2) {
// 			// e.printStackTrace();
// 			throw new InvalidUrlException();
// 		}
// 
// 		boolean isJson = isJson(connection);
// 		monitor.worked(1);
// 
// 		monitor.setTaskName("Writing files…");
// 		
// 		InputStream is;
// 		try {
// 			is = connection.getInputStream();
// 		} catch (IOException e) {
// 			throw new InvalidUrlException();
// 		}
// 
// 		if (isJson) {
// 			JsonReverseReflector.parseJsonToFiles(is, urlAddress, url.getQuery(), isPojo, cacheDuration, file);
// 		} else {
// 			XmlReverseReflector.parseXmlToFiles(is, urlAddress, url.getQuery(), isPojo, cacheDuration, file);
// 		}
// 		
// 		monitor.worked(1);
// 	}
// 
// 	private static boolean isJson(HttpURLConnection connection) throws UnsupportedContentTypeException {
// 
// 		String contentType = connection.getContentType();
// 
// 		if (contentType.contains("json") || contentType.contains("javascript")) {
// 			return true;
// 		} else if (contentType.contains("xml")) {
// 			return false;
// 		}
// 
// 		throw new UnsupportedContentTypeException(contentType);
// 	}
// }


import io.leocad.dumbledroidplugin.core.DumbledroidClassCreator;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
package io.leocad.dumbledroidplugin.wizards;




public class NewModelWizard extends Wizard implements INewWizard {

	private IStructuredSelection mSelection;

	public NewModelWizard() {
		setNeedsProgressMonitor(true);
	}
	
	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		mSelection = selection;
	}

	@Override
	public void addPages() {
		addPage(new DataInputPage(mSelection));
		addPage(new FileCreationPage(mSelection));
	}
	
	/**
	 * This method is called when 'Finish' button is pressed in the wizard. We
	 * will create an operation and run it using wizard as execution context.
	 */
	public boolean performFinish() {
		
		DataInputPage dataPage = (DataInputPage) getPage(DataInputPage.PAGE_NAME);
		final String url = dataPage.getUrl();
		final boolean isPojo = dataPage.getIsPojo();
		final long cacheDuration = dataPage.getCacheDuration();
		
		FileCreationPage filePage = (FileCreationPage) getPage(FileCreationPage.PAGE_NAME);
		final IFile newFile = filePage.createNewFile();
		
		IRunnableWithProgress op = new IRunnableWithProgress() {
			
			public void run(IProgressMonitor monitor) throws InvocationTargetException {
				
				try {
// Path: EclipsePlugin/plugin/src/io/leocad/dumbledroidplugin/core/DumbledroidClassCreator.java
// public class DumbledroidClassCreator {
// 
// 	public static void create(String urlAddress, boolean isPojo, long cacheDuration, IFile file, IProgressMonitor monitor) throws UnsupportedContentTypeException, InvalidUrlException, InvalidContentException {
// 
// 		monitor.beginTask("Validating URL…", 2);
// 		URL url = null;
// 		try {
// 			url = new URL(urlAddress);
// 		} catch (MalformedURLException e1) {
// 			e1.printStackTrace();
// 			// Will never happen. The URL was already validated on UrlInputPage
// 		}
// 		
// 		HttpURLConnection connection;
// 		try {
// 			connection = (HttpURLConnection) url.openConnection();
// 			connection.connect();
// 		} catch (IOException e2) {
// 			// e.printStackTrace();
// 			throw new InvalidUrlException();
// 		}
// 
// 		boolean isJson = isJson(connection);
// 		monitor.worked(1);
// 
// 		monitor.setTaskName("Writing files…");
// 		
// 		InputStream is;
// 		try {
// 			is = connection.getInputStream();
// 		} catch (IOException e) {
// 			throw new InvalidUrlException();
// 		}
// 
// 		if (isJson) {
// 			JsonReverseReflector.parseJsonToFiles(is, urlAddress, url.getQuery(), isPojo, cacheDuration, file);
// 		} else {
// 			XmlReverseReflector.parseXmlToFiles(is, urlAddress, url.getQuery(), isPojo, cacheDuration, file);
// 		}
// 		
// 		monitor.worked(1);
// 	}
// 
// 	private static boolean isJson(HttpURLConnection connection) throws UnsupportedContentTypeException {
// 
// 		String contentType = connection.getContentType();
// 
// 		if (contentType.contains("json") || contentType.contains("javascript")) {
// 			return true;
// 		} else if (contentType.contains("xml")) {
// 			return false;
// 		}
// 
// 		throw new UnsupportedContentTypeException(contentType);
// 	}
// }


// Path: EclipsePlugin/plugin/src/io/leocad/dumbledroidplugin/wizards/NewModelWizard.java
import io.leocad.dumbledroidplugin.core.DumbledroidClassCreator;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;

package io.leocad.dumbledroidplugin.wizards;




public class NewModelWizard extends Wizard implements INewWizard {

	private IStructuredSelection mSelection;

	public NewModelWizard() {
		setNeedsProgressMonitor(true);
	}
	
	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		mSelection = selection;
	}

	@Override
	public void addPages() {
		addPage(new DataInputPage(mSelection));
		addPage(new FileCreationPage(mSelection));
	}
	
	/**
	 * This method is called when 'Finish' button is pressed in the wizard. We
	 * will create an operation and run it using wizard as execution context.
	 */
	public boolean performFinish() {
		
		DataInputPage dataPage = (DataInputPage) getPage(DataInputPage.PAGE_NAME);
		final String url = dataPage.getUrl();
		final boolean isPojo = dataPage.getIsPojo();
		final long cacheDuration = dataPage.getCacheDuration();
		
		FileCreationPage filePage = (FileCreationPage) getPage(FileCreationPage.PAGE_NAME);
		final IFile newFile = filePage.createNewFile();
		
		IRunnableWithProgress op = new IRunnableWithProgress() {
			
			public void run(IProgressMonitor monitor) throws InvocationTargetException {
				
				try {
					DumbledroidClassCreator.create(url, isPojo, cacheDuration, newFile, monitor);