Index: D:/work/abator/eclipse/org.apache.ibatis.abator.ui/META-INF/MANIFEST.MF =================================================================== --- D:/work/abator/eclipse/org.apache.ibatis.abator.ui/META-INF/MANIFEST.MF (revision 511515) +++ D:/work/abator/eclipse/org.apache.ibatis.abator.ui/META-INF/MANIFEST.MF (working copy) @@ -1,23 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Abator UI Plug-in -Bundle-SymbolicName: org.apache.ibatis.abator.ui; singleton:=true -Bundle-Version: 1.0.0 -Bundle-ClassPath: abatorui.jar -Bundle-Activator: org.apache.ibatis.abator.ui.plugin.AbatorUIPlugin -Bundle-Localization: plugin -Require-Bundle: org.apache.ibatis.abator.core, - org.eclipse.ui, - org.eclipse.core.runtime, - org.eclipse.core.resources, - org.eclipse.jdt.core, - org.eclipse.text, - org.eclipse.jdt.launching, - org.eclipse.ui.editors, - org.eclipse.jface.text, - org.eclipse.ui.ide, - org.eclipse.ui.workbench.texteditor, - org.apache.ant, - org.eclipse.ant.core -Eclipse-AutoStart: true -Bundle-Vendor: ibatis.apache.org Index: D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/NewConfigFileWizard.java =================================================================== --- D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/NewConfigFileWizard.java (revision 511515) +++ D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/NewConfigFileWizard.java (working copy) @@ -13,12 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.ibatis.abator.ui.wizards; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; +import java.sql.Connection; +import java.util.Properties; import org.apache.ibatis.abator.ui.plugin.AbatorUIPlugin; import org.eclipse.core.resources.IContainer; @@ -35,7 +38,11 @@ import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardContainer; +import org.eclipse.jface.wizard.IWizardContainer2; +import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; @@ -43,6 +50,11 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; +import org.eclipse.wst.rdb.connection.internal.ui.wizards.ConnectionWizardProperties; +import org.eclipse.wst.rdb.connection.internal.ui.wizards.shared.DatabaseAuthenticationWizardPage; +import org.eclipse.wst.rdb.internal.core.RDBCorePlugin; +import org.eclipse.wst.rdb.internal.core.connection.ConnectionInfo; +import org.eclipse.wst.rdb.internal.core.util.DatabaseProviderHelper; /** * This is a sample new wizard. Its role is to create a new file @@ -54,182 +66,485 @@ * as a template) is registered for the same extension, it will * be able to open it. */ +public class NewConfigFileWizard extends Wizard implements INewWizard +{ + private static final String P_PLUGINID_ROOT = "org.apache.ibatis.abator.ui.wizards."; + private static final String P_SELECT_CONFIG_PAGE = P_PLUGINID_ROOT + "SelectConfigPage"; + private static final String P_SELECT_CONNECTION_PAGE = P_PLUGINID_ROOT + "SelectConnectionWizardPage"; + private static final String P_AUTHENTICATION_PAGE = P_PLUGINID_ROOT + "DatabaseAuthenticationWizardPage"; + private static final String P_JDBC_CONFIGURATION_PAGE = P_PLUGINID_ROOT + "JDBCConfigurationWizardPage"; + private static final String P_SELECT_SCHEMA_PAGE = P_PLUGINID_ROOT + "SelectSchemaWizardPage"; -public class NewConfigFileWizard extends Wizard implements INewWizard { - private NewConfigFileWizardPage1 page; - private ISelection selection; + private NewConfigFileWizardPage1 _selectConfigPage; + private SelectConnectionWizardPage _selectConnectionPage; + private DatabaseAuthenticationWizardPage _authenticationPage; + private JDBCConfigurationWizardPage _jdbcConfigurationPage; + private SelectSchemaWizardPage _selectSchemaPage; - /** - * Constructor for NewConfigFileWizard. - */ - public NewConfigFileWizard() { - super(); - setNeedsProgressMonitor(true); - } - - /** - * Adding the page to the wizard. - */ + private boolean _controlsCreated = false; + private String _defaultConnection; + private boolean _noDefault = true; + private ConnectionWizardProperties _connectionProperties; - public void addPages() { - page = new NewConfigFileWizardPage1(selection); - addPage(page); - } + private ISelection _selection; - /** - * 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 containerName = page.getLocation(); - final String fileName = page.getFileName(); - IRunnableWithProgress op = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException { - try { - doFinish(containerName, fileName, 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(); - MessageDialog.openError(getShell(), "Error", realException.getMessage()); - return false; - } - return true; - } - - /** - * 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. - */ + /** + * Constructor for NewConfigFileWizard. + * + * @param defaultConnection the default connection. + */ + public NewConfigFileWizard() + { + super(); + setNeedsProgressMonitor( true ); + setWindowTitle( "Abator Config Wizard Page" ); + } - private void doFinish( - String containerName, - String fileName, - IProgressMonitor monitor) - throws CoreException { - // create a sample file - monitor.beginTask("Creating " + fileName, 2); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IResource resource = root.findMember(new Path(containerName)); - if (!resource.exists() || !(resource instanceof IContainer)) { - throwCoreException("Container \"" + containerName + "\" does not exist."); - } - IContainer container = (IContainer) resource; - final IFile file = container.getFile(new Path(fileName)); - try { - InputStream stream = openContentStream(); - 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("Opening file for editing..."); - getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - IWorkbenchPage page = - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - try { - IDE.openEditor(page, file, true); - } catch (PartInitException e) { - } - } - }); - monitor.worked(1); - } - - /** - * We will initialize file contents with a sample text. - */ + /** + * We will accept the selection in the workbench to see if + * we can initialize from it. + * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection) + */ + public void init( final IWorkbench workbench, final IStructuredSelection selection ) + { + _selection = selection; + } - private InputStream openContentStream() { - String lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$ - if (lineSeparator == null) { - lineSeparator = "\n"; //$NON-NLS-1$ - } - - StringBuffer sb = new StringBuffer(); - sb.append(""); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(""); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(lineSeparator); - sb.append(""); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ + public void init( final IWorkbench workbench, final ISelection selection ) + { + _selection = selection; + // ISelection defaultConnection + if( selection != null ) + { + //TODO: type cast of defaultConnection ... + _defaultConnection = "sample"; + } + } - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); + /** + * @see Wizard#createPageControls(org.eclipse.swt.widgets.Composite) + */ + public void createPageControls( final Composite pageContainer ) + { + super.createPageControls( pageContainer ); + final IWizardContainer container = getContainer(); + if( container instanceof IWizardContainer2 ) + { + ( (IWizardContainer2) container ).updateSize(); + } + _controlsCreated = true; + } - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); + /** + * Adding the page to the wizard. + * @see Wizard#addPages() + */ + public void addPages() + { + super.addPages(); - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append(" "); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append("
"); //$NON-NLS-1$ - sb.append(lineSeparator); - - sb.append(lineSeparator); - sb.append("
"); //$NON-NLS-1$ - sb.append(lineSeparator); - sb.append("
"); //$NON-NLS-1$ - sb.append(lineSeparator); - - return new ByteArrayInputStream(sb.toString().getBytes()); - } + _selectConfigPage = new NewConfigFileWizardPage1( P_SELECT_CONFIG_PAGE, _selection ); + addPage( _selectConfigPage ); - private void throwCoreException(String message) throws CoreException { - IStatus status = - new Status(IStatus.ERROR, AbatorUIPlugin.getPluginId(), IStatus.OK, message, null); - throw new CoreException(status); - } + _selectConnectionPage = new SelectConnectionWizardPage( P_SELECT_CONNECTION_PAGE, _defaultConnection ); + addPage( _selectConnectionPage ); - /** - * 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; - } + _authenticationPage = new DatabaseAuthenticationWizardPage( P_AUTHENTICATION_PAGE ); + addPage( _authenticationPage ); - public void init(IWorkbench workbench, ISelection selection) { - this.selection = selection; - } + _jdbcConfigurationPage = new JDBCConfigurationWizardPage( P_JDBC_CONFIGURATION_PAGE ); + addPage( _jdbcConfigurationPage ); + + _selectSchemaPage = new SelectSchemaWizardPage( P_SELECT_SCHEMA_PAGE ); + addPage( _selectSchemaPage ); + } + + /* + * (non-Javadoc) + * @see Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage) + */ + public IWizardPage getNextPage( final IWizardPage wizardPage ) + { + _authenticationPage.setConnectionInfo( _selectConnectionPage.getSelectedConnection() ); + + // Sets the default connection properties, if one was defined. + if( _noDefault && _controlsCreated && _connectionProperties != null ) + { + _noDefault = false; + _jdbcConfigurationPage.setConnectionProperties( _connectionProperties ); + } + + final IWizardPage nextPage; + final String currentPage = wizardPage.getName(); + if( P_SELECT_CONFIG_PAGE.equals( currentPage ) ) + { + nextPage = _selectConnectionPage; + } + else if( P_SELECT_CONNECTION_PAGE.equals( currentPage ) ) + { + if( _selectConnectionPage.isNewConnectionSelected() ) + { + nextPage = _jdbcConfigurationPage; + } + else + { + // determine if prompt is needed + if( _selectConnectionPage.isSelectedConnectionClosed() ) + { + nextPage = _authenticationPage; + } + else + { + nextPage = _selectSchemaPage; + } + } + } + else if( P_AUTHENTICATION_PAGE.equals( currentPage ) ) + { + nextPage = _selectSchemaPage; + } + else if( P_JDBC_CONFIGURATION_PAGE.equals( currentPage ) ) + { + nextPage = _selectSchemaPage; + _selectConnectionPage._selectedConnection = _jdbcConfigurationPage.getConnectionName(); + } + else if( P_SELECT_SCHEMA_PAGE.equals( currentPage ) ) + { + nextPage = null; + } + else + { + nextPage = super.getNextPage( wizardPage ); + } + return nextPage; + } + + /* + * (non-Javadoc) + * @see Wizard#canFinish() + */ + public boolean canFinish() + { + final boolean canFinish; + if( _selectSchemaPage.isPageComplete() && _selectConnectionPage.isExistingConnectionSelected() ) + { + canFinish = true; + } + else + { + canFinish = super.canFinish(); + } + return canFinish; + } + + /** + * 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 containerName = _selectConfigPage.getLocation(); + final String fileName = _selectConfigPage.getFileName(); + final ConnectionInfo connection = _selectConnectionPage.getSelectedConnection(); + if( connection != null ) + { + final IRunnableWithProgress op = new IRunnableWithProgress() + { + public void run( final IProgressMonitor monitor ) throws InvocationTargetException + { + try + { + doFinish( containerName, fileName, connection, monitor ); + } + catch( CoreException e ) + { + throw new InvocationTargetException( e ); + } + finally + { + monitor.done(); + } + } + }; + try + { + getContainer().run( true, false, op ); + } + catch( final InterruptedException e ) + { + return false; + } + catch( final InvocationTargetException e ) + { + final Throwable realException = e.getTargetException(); + MessageDialog.openError( getShell(), "Error", realException.getMessage() ); + return false; + } + } + return true; + } + + /** + * 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. + */ + private void doFinish( final String containerName, final String fileName, final ConnectionInfo connection, final IProgressMonitor monitor ) throws CoreException + { + // create a sample file + monitor.beginTask( "Creating " + fileName, 2 ); + final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + final IResource resource = root.findMember( new Path( containerName ) ); + if( !resource.exists() || !( resource instanceof IContainer ) ) + { + throwCoreException( "Container \"" + containerName + "\" does not exist." ); + } + final IContainer container = (IContainer) resource; + final IFile file = container.getFile( new Path( fileName ) ); + try + { + // the user and password are stored here. + final Properties p = connection.getProperties(); + + // JDBC_DRIVER and something else. + p.putAll( connection.getCustomProperties() ); + + // others ... + p.put( _PAR_classLocation, connection.getLoadingPath() ); + p.put( _PAR_connectionURL, connection.getURL() ); + p.put( _PAR_databaseName, connection.getDatabaseName() ); + p.put( _PAR_jdbcDriverClass, connection.getDriverClassName() ); + + final InputStream stream = openContentStream( p ); + 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( "Opening file for editing..." ); + getShell().getDisplay().asyncExec( new Runnable() + { + public void run() + { + final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try + { + IDE.openEditor( page, file, true ); + } + catch( PartInitException e ) + { + } + } + } ); + monitor.worked( 1 ); + } + + /** + * We will initialize file contents with a sample text. + * + * TODO: move it out of this class ... + */ + private InputStream openContentStream( final Properties p ) + { + String lineSeparator = System.getProperty( "line.separator" ); //$NON-NLS-1$ + if( lineSeparator == null ) + { + lineSeparator = "\n"; //$NON-NLS-1$ + } + + final StringBuffer sb = new StringBuffer(); + + //TODO: combobox to get a different encoding ... + sb.append( "" ) //$NON-NLS-1$ + .append( lineSeparator ) + .append( "" ) //$NON-NLS-1$ + .append( lineSeparator ); + + sb.append( "" ) //$NON-NLS-1$ + .append( lineSeparator ) + .append( " " ) //$NON-NLS-1$ + .append( lineSeparator ); + + sb.append( lineSeparator ) + .append( " " ) //$NON-NLS-1$ + .append( lineSeparator ) + .append( " " ) //$NON-NLS-1$ + .append( lineSeparator ) + .append( " " ) //$NON-NLS-1$ + .append( lineSeparator ); + + //TODO: a new wizard page to configure the code below (coding stuff). + sb.append( lineSeparator ); + sb.append( " " ); //$NON-NLS-1$ + sb.append( lineSeparator ); + sb.append( " " ); //$NON-NLS-1$ + sb.append( lineSeparator ); + sb.append( " " ); //$NON-NLS-1$ + sb.append( lineSeparator ); + + //TODO: a new wizard page to configure the code below (schema, table, and columns). + sb.append( lineSeparator ); + sb.append( " " ); //$NON-NLS-1$ + sb.append( lineSeparator ); + sb.append( " " ); //$NON-NLS-1$ + sb.append( lineSeparator ); + sb.append( "
" ); //$NON-NLS-1$ + sb.append( lineSeparator ); + + sb.append( lineSeparator ) + .append( "
" ) //$NON-NLS-1$ + .append( lineSeparator ) + .append( "
" ) //$NON-NLS-1$ + .append( lineSeparator ); + + return new ByteArrayInputStream( sb.toString().getBytes() ); + } + + private void throwCoreException( final String message ) throws CoreException + { + IStatus status = new Status( IStatus.ERROR, AbatorUIPlugin.getPluginId(), IStatus.OK, message, null ); + throw new CoreException( status ); + } + + /** + * Sets the default connection properties. + * + * @param connectionProperties the default connection properties. + */ + public void setConnectionProperties( final ConnectionWizardProperties connectionProperties ) + { + _connectionProperties = connectionProperties; + } + + /** + * Returns the configured connection. + * + * @return the configured connection. + */ + public ConnectionInfo getConnection() + { + try + { + final ConnectionInfo connectionInfo; + if( _selectConnectionPage.isNewConnectionSelected() ) + { + _jdbcConfigurationPage.internalSaveWidgetValues(); + _jdbcConfigurationPage.performTestConnection( false ); + if( _jdbcConfigurationPage.isFinalConnection() ) + { + connectionInfo = _jdbcConfigurationPage.getConnection(); + saveConnection( connectionInfo ); + } + else + { + connectionInfo = null; + } + } + else + { + connectionInfo = _selectConnectionPage.getSelectedConnection(); + } + return connectionInfo; + } + catch( final Exception e ) + { + // If the connection is not valid, then this method should return null. + return null; + } + } + + /** + * Save the given connection at the default store. + * + * @param connectionInfo the connection to be saved. + * @return + */ + public ConnectionInfo saveConnection( final ConnectionInfo connectionInfo ) + { + Connection connection = null; + try + { + connection = connectionInfo.connect(); + connectionInfo.setSharedConnection( connection ); + connectionInfo.saveConnectionInfo(); + new DatabaseProviderHelper().setDatabase( connection, connectionInfo, connectionInfo.getDatabaseName() ); + } + catch( final Exception e ) + { + RDBCorePlugin.getDefault().getConnectionManager().removeConnectionInfo( connectionInfo.getName() ); + connection = null; + } + return connectionInfo; + } + + /** + * Simple class to display messages on eclipse. + */ + public class DisplayMessage implements Runnable + { + private String _title; + private String _message; + + /** + * Constructor. + * + * @param title the title message. + * @param message the message. + */ + public DisplayMessage( final String title, final String message ) + { + _title = title; + _message = message; + } + + /* + * (non-Javadoc) + * @see java.lang.Runnable#run() + */ + public void run() + { + MessageDialog.openInformation( getShell(), _title, _message ); + } + } + + /*/ internal constants /*/ + private static final String _PAR_databaseName = "Database"; + private static final String _PAR_jdbcDriverClass = "JDBC Driver Class"; + private static final String _PAR_classLocation = "Class Location"; + private static final String _PAR_connectionURL = "Connection URL"; + + private static final String _PAR_userId = "user"; + private static final String _PAR_userPassword = "password"; } \ No newline at end of file Index: D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/JDBCConfigurationWizardPage.java =================================================================== --- D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/JDBCConfigurationWizardPage.java (revision 0) +++ D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/JDBCConfigurationWizardPage.java (revision 0) @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.apache.ibatis.abator.ui.wizards; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.wst.rdb.connection.internal.ui.wizards.shared.NewCWJDBCPage; + +/** + * The jdbc configuration page. + * + * @author Anaximandro de Godinho. + * @version $Revision: 1.0 $ + */ +public class JDBCConfigurationWizardPage extends NewCWJDBCPage +{ + /** + * Constructor. + * + * @param pageName the page name. + */ + public JDBCConfigurationWizardPage( final String pageName ) + { + super( pageName ); + } + + /* + * (non-Javadoc) + * @see org.eclipse.wst.rdb.connection.internal.ui.wizards.RDBWizardPage#getNextPage() + */ + public IWizardPage getNextPage() + { + performTestConnection( false ); + final IWizardPage nextPage; + if( isFinalConnection() ) + { + nextPage = super.getNextPage(); + } + else + { + nextPage = null; + } + return nextPage; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage() + */ + public boolean canFlipToNextPage() + { + /* without this override the superclass will try to connect + * to the db on each key press event, so, don't remove it! + */ + return isPageComplete(); + } +} \ No newline at end of file Index: D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/SelectConnectionWizardPage.java =================================================================== --- D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/SelectConnectionWizardPage.java (revision 0) +++ D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/SelectConnectionWizardPage.java (revision 0) @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.apache.ibatis.abator.ui.wizards; + +import java.sql.SQLException; +import java.util.List; +import java.util.Vector; + +import org.eclipse.wst.rdb.connection.internal.ui.wizards.shared.ExistingConnectionsWizardPage; +import org.eclipse.wst.rdb.internal.core.RDBCorePlugin; +import org.eclipse.wst.rdb.internal.core.connection.ConnectionInfo; + +/** + * The select existing connection wizard page. + * + * @author Anaximandro de Godinho. + * @version $Revision: 1.0 $ + */ +public class SelectConnectionWizardPage extends ExistingConnectionsWizardPage +{ + // the filter list. + protected final List _filter; + + // the default connection. + protected String _selectedConnection; + + /** + * Constructor. + * + * @param pageName the page name. + */ + public SelectConnectionWizardPage( final String pageName, final String defaultConnection ) + { + super( pageName ); + _filter = new Vector(); + _selectedConnection = defaultConnection; + } + + /* + * (non-Javadoc) + * @see org.eclipse.wst.rdb.connection.internal.ui.wizards.shared.ExistingConnectionsWizardPage#setVisible(boolean) + */ + public void setVisible( boolean visible ) + { + super.setVisible( visible ); + if( visible && _selectedConnection != null ) + { + setDefaultConnection( _selectedConnection ); + _selectedConnection = null; + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage() + */ + public boolean canFlipToNextPage() + { + final boolean can = super.canFlipToNextPage(); + if( can ) + { + final boolean isNewConnection = isNewConnectionSelected(); + if( isNewConnection ) + { + setDefaultConnection( "" ); + _selectedConnection = null; + } + else + { + final ConnectionInfo info = getSelectedConnection(); + if( info != null ) + { + _selectedConnection = info.getName(); + } + } + } + return can; + } + + /** + * This method overrides the base class implementation and returns + * all connections for the specified filter, if one was specified. + * + * @see org.eclipse.wst.rdb.connection.internal.ui.wizards.shared.ExistingConnectionsWizardPage#getConnectionsToDisplay() + */ + protected ConnectionInfo[] getConnectionsToDisplay() + { + final ConnectionInfo[] infos; + final ConnectionInfo[] allInfos = RDBCorePlugin.getDefault().getConnectionManager().getAllNamedConnectionInfo(); + if( _filter.isEmpty() ) + { + infos = allInfos; + } + else + { + final int infoLength = allInfos.length; + infos = new ConnectionInfo[infoLength]; + if( infoLength > 0 ) + { + final List filteredInfosCollection = new Vector(); + for( int i = 0; i < infoLength; i++ ) + { + final String entry = getFilterEntry( allInfos[i].getDatabaseDefinition().getProduct(), allInfos[i] + .getDatabaseDefinition().getVersion() ); + if( _filter.contains( entry ) ) + { + filteredInfosCollection.add( allInfos[i] ); + } + } + filteredInfosCollection.toArray( infos ); + } + } + return infos; + } + + /** + * Returns the status of the selected connection. + * + * @return true if the selected connection is still open otherwise false. + */ + public boolean isSelectedConnectionClosed() + { + boolean isClosed = true; + final ConnectionInfo connectionInfo = getSelectedConnection(); + if( ( connectionInfo != null ) && ( connectionInfo.getSharedConnection() != null ) ) + { + try + { + if( !connectionInfo.getSharedConnection().isClosed() ) + { + isClosed = false; + } + } + catch( final SQLException e ) + { + // just ignore. + } + } + return isClosed; + } + + /** + * Adds one filter to the filter list, this filter will be used on the connection wizard page. + * + * @param vendor the vendor string to filter all connections at the connection wizard page. + * @param version the version string to filter all connections at the connection wizard page. + */ + protected void addFilter( final String vendor, final String version ) + { + _filter.add( getFilterEntry( vendor, version ) ); + } + + /** + * Builds the vendor + version filter string. + * + * @param vendor the vendor string. + * @param version the version string. + */ + protected String getFilterEntry( final String vendor, final String version ) + { + final String vendor2 = vendor == null? _empty: vendor.trim().toUpperCase(); + final String version2 = version == null? _empty: version.trim().toUpperCase(); + return vendor2 + ";" + version2; + } + + /*/ private constants /*/ + private static final String _empty = ""; +} \ No newline at end of file Index: D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/NewConfigFileWizardPage1.java =================================================================== --- D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/NewConfigFileWizardPage1.java (revision 511515) +++ D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/NewConfigFileWizardPage1.java (working copy) @@ -54,10 +54,11 @@ /** * Constructor for SampleNewWizardPage. + * @param pageName the page name. * @param selection - the current selection */ - public NewConfigFileWizardPage1(ISelection selection) { - super("wizardPage"); + public NewConfigFileWizardPage1(String pageName, ISelection selection) { + super(pageName); setTitle("Abator Configuration File"); setDescription("This wizard creates a new Abator for iBATIS configuration file."); this.selection = selection; Index: D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/SelectSchemaWizardPage.java =================================================================== --- D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/SelectSchemaWizardPage.java (revision 0) +++ D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/wizards/SelectSchemaWizardPage.java (revision 0) @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.apache.ibatis.abator.ui.wizards; + +import org.eclipse.wst.rdb.connection.internal.ui.filter.SchemaFilterWizardPage; + +/** + * The select schema wizard page. + * + * @author Anaximandro de Godinho. + * @version $Revision: 1.0 $ + */ +public class SelectSchemaWizardPage extends SchemaFilterWizardPage +{ + /** + * Constructor. + * + * @param pageName the page name. + */ + public SelectSchemaWizardPage( final String pageName ) + { + super( pageName ); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean) + */ + public void setVisible( final boolean visible ) + { + super.setVisible( visible ); + if( visible ) + { + setConnectionInfo( ( (NewConfigFileWizard) getWizard() ).getConnection() ); + setPageComplete( true ); + } + } +} \ No newline at end of file Index: D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/content/AbatorConfigVerifyer.java =================================================================== --- D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/content/AbatorConfigVerifyer.java (revision 511515) +++ D:/work/abator/eclipse/org.apache.ibatis.abator.ui/src/org/apache/ibatis/abator/ui/content/AbatorConfigVerifyer.java (working copy) @@ -16,7 +16,6 @@ package org.apache.ibatis.abator.ui.content; -import java.io.IOException; import java.io.InputStream; import java.io.StringReader; @@ -82,7 +81,7 @@ } } - public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException { + public InputSource resolveEntity(String publicId, String systemId) throws SAXException { if (!XmlConstants.ABATOR_CONFIG_PUBLIC_ID.equals(publicId)) { throw new SAXException("Not an Abator configuration file"); } Property changes on: D:\work\abator\eclipse\org.apache.ibatis.abator.ui\icons ___________________________________________________________________ Name: svn:ignore + Thumbs.db Index: D:/work/abator/eclipse/org.apache.ibatis.abator.ui/plugin.xml =================================================================== --- D:/work/abator/eclipse/org.apache.ibatis.abator.ui/plugin.xml (revision 511515) +++ D:/work/abator/eclipse/org.apache.ibatis.abator.ui/plugin.xml (working copy) @@ -1,7 +1,41 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +