package thahn.java.agui.ide.eclipse.wizard; import java.lang.reflect.InvocationTargetException; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jdt.ui.actions.OpenJavaPerspectiveAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ISelection; 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.IWorkbenchWizard; /** * This is a sample new wizard. Its role is to create a new file * resource in the provided container. If the container resource * (a folder or a project) is selected in the workspace * when the wizard is opened, it will accept it as the target * container. The wizard creates one file with the extension * "mpe". If a sample multi-page editor (also available * as a template) is registered for the same extension, it will * be able to open it. */ public class AguiProjectWizard extends Wizard implements INewWizard { private AguiProjectWizardPage page; private ISelection selection; private AguiProjectMaker mPreMaker; /** * Constructor for AguiProjectWizard. */ public AguiProjectWizard() { super(); setNeedsProgressMonitor(true); } /** * Adding the page to the wizard. */ public void addPages() { page = new AguiProjectWizardPage(selection); // TODO : You can add more pages here... addPage(page); } /** * 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() { final String applicationName = page.getApplicationName(); final String packageName = page.getPackageName(); final String activityName = page.getActivityName(); // final IProject project = page.getProjectHandle(); // IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { AguiProjectMaker maker = new AguiProjectMaker(applicationName, packageName, activityName); maker.createProject(project, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; try { getContainer().run(true, false, op); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { e.printStackTrace(); Throwable realException = e.getTargetException(); MessageDialog.openError(getShell(), "Error", realException.getMessage()); return false; } return true; } private void throwCoreException(String message) throws CoreException { IStatus status = new Status(IStatus.ERROR, "thahn.java.agui.ide.eclipse.wizard", IStatus.OK, message, null); throw new CoreException(status); } /** * We will accept the selection in the workbench to see if * we can initialize from it. * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection) */ public void init(IWorkbench workbench, IStructuredSelection selection) { this.selection = selection; } }