[jbosstools-commits] JBoss Tools SVN: r22809 - branches/jbosstools-3.1.x/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Tue Jun 15 08:56:43 EDT 2010
Author: scabanovich
Date: 2010-06-15 08:56:42 -0400 (Tue, 15 Jun 2010)
New Revision: 22809
Modified:
branches/jbosstools-3.1.x/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizard.java
Log:
https://jira.jboss.org/browse/JBIDE-6374
Modified: branches/jbosstools-3.1.x/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizard.java
===================================================================
--- branches/jbosstools-3.1.x/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizard.java 2010-06-15 12:55:22 UTC (rev 22808)
+++ branches/jbosstools-3.1.x/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizard.java 2010-06-15 12:56:42 UTC (rev 22809)
@@ -22,17 +22,13 @@
package org.hibernate.eclipse.console.wizards;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
@@ -91,7 +87,20 @@
* Adding the page to the wizard.
*/
public void addPages() {
- cPage = new ExtendedWizardNewFileCreationPage( "Ccfgxml", (IStructuredSelection) selection ); //$NON-NLS-1$
+ cPage = new ExtendedWizardNewFileCreationPage( "Ccfgxml", (IStructuredSelection) selection ) {
+ protected InputStream getInitialContents() {
+ final Properties props = new Properties();
+ putIfNotNull(props, Environment.SESSION_FACTORY_NAME, connectionInfoPage.getSessionFactoryName() );
+ putIfNotNull(props, Environment.DIALECT, connectionInfoPage.getDialect() );
+ putIfNotNull(props, Environment.DRIVER, connectionInfoPage.getDriver() );
+ putIfNotNull(props, Environment.URL, connectionInfoPage.getConnectionURL() );
+ putIfNotNull(props, Environment.USER, connectionInfoPage.getUsername() );
+ putIfNotNull(props, Environment.PASS, connectionInfoPage.getPassword() );
+ putIfNotNull(props, Environment.DEFAULT_CATALOG, connectionInfoPage.getDefaultCatalog() );
+ putIfNotNull(props, Environment.DEFAULT_SCHEMA, connectionInfoPage.getDefaultSchema() );
+ return openContentStream(props);
+ }
+ }; //$NON-NLS-1$
cPage.setTitle( HibernateConsoleMessages.NewConfigurationWizard_create_hibernate_cfg_file );
cPage.setDescription( HibernateConsoleMessages.NewConfigurationWizard_create_new_hibernate_cfg_xml );
cPage.setFileName("hibernate.cfg.xml"); //$NON-NLS-1$
@@ -122,26 +131,7 @@
putIfNotNull(props, Environment.DEFAULT_SCHEMA, connectionInfoPage.getDefaultSchema() );
final IFile file = cPage.createNewFile();
- IRunnableWithProgress op = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException {
- try {
- createHibernateCfgXml(file, props, 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) {
- Throwable realException = e.getTargetException();
- HibernateConsolePlugin.getDefault().showError(getShell(), HibernateConsoleMessages.NewConfigurationWizard_error, realException);
- return false;
- }
+ openHibernateCfgXml(file);
if (connectionInfoPage.isCreateConsoleConfigurationEnabled()) {
try {
@@ -173,30 +163,7 @@
}
}
- /**
- * The worker method. It will find the container, create the
- * file if missing or just replace its contents, and open
- * the editor on the newly created file.
- * @param file
- * @param props
- */
- private void createHibernateCfgXml(
- final IFile file, Properties props, IProgressMonitor monitor)
- throws CoreException {
- // create a sample file
- monitor.beginTask(HibernateConsoleMessages.NewConfigurationWizard_creating + file.getName(), 2);
- try {
- InputStream stream = openContentStream(props);
- if (file.exists() ) {
- file.setContents(stream, true, true, monitor);
- } else {
- file.create(stream, true, monitor);
- }
- stream.close();
- } catch (IOException e) {
- }
- monitor.worked(1);
- monitor.setTaskName(HibernateConsoleMessages.NewConfigurationWizard_open_file_for_editing);
+ private void openHibernateCfgXml(final IFile file) {
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage page =
@@ -207,7 +174,6 @@
}
}
});
- monitor.worked(1);
}
/**
More information about the jbosstools-commits
mailing list