/*
 * 作成日: 2008/08/05
 * 著作権: Copyright (c) 2005 ZIGEN
 * ライセンス：Eclipse Public License - v 1.0
 * 原文：http://www.eclipse.org/legal/epl-v10.html
 */
package zigen.plugin.db.ext.s2jdbc.wizards;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.ui.wizards.NewClassWizardPage;

import zigen.plugin.db.ext.s2jdbc.properties.S2jdbcPropertyPage;


public class NewEntityServiceWizard extends AbstractWizard {
	
	NewClassWizardPage fPage;
	
	public void addPages() {
		fPage = new NewEntityServiceWizardPage(selection);
		try {
			javaProject = getJavaProject(selection.getFirstElement());
			if (javaProject != null) {
				String defaultSuperClass = javaProject.getResource().getPersistentProperty(new QualifiedName(S2jdbcPropertyPage.QUALIFIER, S2jdbcPropertyPage.KEY_SERVICE_SUPERCLASS));
				
				if (defaultSuperClass != null)
					fPage.setSuperClass(defaultSuperClass, true);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		addPage(fPage);
	}
	
	@Override
	protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
		fPage.createType(monitor);
		

		if (javaProject != null && fPage != null) {
			javaProject.getResource().setPersistentProperty(new QualifiedName(S2jdbcPropertyPage.QUALIFIER, S2jdbcPropertyPage.KEY_SERVICE_SUPERCLASS), fPage.getSuperClass());
		}
		
	}
	
	@Override
	public IJavaElement getCreatedElement() {
		return fPage.getCreatedType();
	}
	
	@Override
	protected IResource getModifiedResource() {
		return fPage.getModifiedResource();
	}
	

}