1 4 package org.hibernate.eclipse.console.wizards; 5 6 import java.lang.reflect.InvocationTargetException ; 7 8 import org.eclipse.core.runtime.CoreException; 9 import org.eclipse.core.runtime.IPath; 10 import org.eclipse.core.runtime.IProgressMonitor; 11 import org.eclipse.core.runtime.IStatus; 12 import org.eclipse.core.runtime.Status; 13 import org.eclipse.jface.dialogs.ErrorDialog; 14 import org.eclipse.jface.operation.IRunnableWithProgress; 15 import org.eclipse.jface.viewers.ISelection; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.jface.wizard.Wizard; 18 import org.eclipse.ui.INewWizard; 19 import org.eclipse.ui.IWorkbench; 20 import org.eclipse.ui.IWorkbenchWizard; 21 import org.hibernate.console.ConsoleConfiguration; 22 import org.hibernate.console.ConsoleConfigurationPreferences; 23 import org.hibernate.console.ImageConstants; 24 import org.hibernate.console.KnownConfigurations; 25 import org.hibernate.eclipse.console.EclipseConsoleConfiguration; 26 import org.hibernate.eclipse.console.HibernateConsolePlugin; 27 import org.hibernate.eclipse.console.utils.EclipseImages; 28 29 32 public class ConsoleConfigurationCreationWizard extends Wizard implements 33 INewWizard { 34 35 private ConsoleConfigurationWizardPage page; 36 private ISelection selection; 37 38 41 public ConsoleConfigurationCreationWizard() { 42 super(); 43 setDefaultPageImageDescriptor(EclipseImages.getImageDescriptor(ImageConstants.NEW_WIZARD)); 44 setNeedsProgressMonitor(true); 45 } 46 47 50 51 public void addPages() { 52 page = new ConsoleConfigurationWizardPage(selection); 53 addPage(page); 54 } 55 56 61 public boolean performFinish() { 62 final String configName = page.getConfigurationName(); 63 final IPath propertyFile = page.getPropertyFilePath(); 64 final IPath fileName = page.getConfigurationFilePath(); 65 final IPath[] mappings = page.getMappingFiles(); 66 final IPath[] classpaths = page.getClassPath(); 67 IRunnableWithProgress op = new IRunnableWithProgress() { 68 public void run(IProgressMonitor monitor) throws InvocationTargetException { 69 try { 70 doFinish(page.getOldConfiguration(), configName, propertyFile, fileName, mappings, classpaths, monitor); 71 } catch (CoreException e) { 72 throw new InvocationTargetException (e); 73 } finally { 74 monitor.done(); 75 } 76 } 77 }; 78 try { 79 getContainer().run(true, false, op); 80 } catch (InterruptedException e) { 81 return false; 82 } catch (InvocationTargetException e) { 83 Throwable realException = e.getTargetException(); 84 realException.printStackTrace(); 85 IStatus s = null; 86 if(realException instanceof CoreException) { 87 s = ((CoreException)realException).getStatus(); 88 } else { 89 s = new Status(Status.ERROR,HibernateConsolePlugin.ID, Status.OK, "Probably missing classes or errors with classloading", e); 90 91 } 92 ErrorDialog.openError(getShell(), "Create Conscole Configuration Wizard", "Error while finishing Wizard", s); 93 return false; 94 } 95 return true; 96 } 97 98 106 107 private void doFinish( 108 EclipseConsoleConfiguration oldConfig, 109 String configName, 110 IPath propertyFilename, 111 IPath cfgFile, IPath[] mappings, IPath[] classpaths, IProgressMonitor monitor) 112 throws CoreException { 113 114 monitor.beginTask("Configuring Hibernate Console" + propertyFilename, IProgressMonitor.UNKNOWN); 115 116 ConsoleConfigurationPreferences ccp = new EclipseConsoleConfigurationPreferences(configName, cfgFile, propertyFilename, mappings, classpaths); 117 118 final ConsoleConfiguration cfg = new EclipseConsoleConfiguration(ccp); 119 120 if(oldConfig!=null) { 121 oldConfig.reset(); KnownConfigurations.getInstance().removeConfiguration(oldConfig); 123 } 124 KnownConfigurations.getInstance().addConfiguration(cfg, true); 125 126 monitor.worked(1); 127 } 128 129 130 135 public void init(IWorkbench workbench, IStructuredSelection selection) { 136 this.selection = selection; 137 } 138 } 139 | Popular Tags |