From: khartlage Date: Sat, 24 Jul 2004 19:25:19 +0000 (+0000) Subject: Quantum version 2.4.1 X-Git-Url: http://git.phpeclipse.com Quantum version 2.4.1 --- diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/bookmark_name.html b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/bookmark_name.html new file mode 100644 index 0000000..a6260d1 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/bookmark_name.html @@ -0,0 +1,16 @@ + + + + + Choosing a Bookmark Name + + + +

Choosing a Bookmark Name

+

Provide a unique name for your bookmark:

+ + + + + diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/getting_started_connections.html b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/getting_started_connections.html index c14d6aa..df0d83a 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/getting_started_connections.html +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/getting_started_connections.html @@ -19,59 +19,16 @@ when right-clicking on the blank space in the Once this menu item is selected, you will see the "New Bookmark" wizard:

- + + +

Creating Bookmarks involve four things: + +

    +
  1. specify a JDBC Driver; +
  2. provide the connection details (userid, password and JDBC URL); +
  3. choose a name for your bookmark; and +
  4. optionally, specify which schemas you want to view. +
-

The data that the form asks of you is: -

-

Other examples (only as orientation, your particular data may be -different)
-

-For MySql (in Windows):

-
Connect: jdbc:mysql://localhost/test
Driver: com.mysql.jdbc.Driver
Driver Filename: C:\mysql\jdbc\mysql-connector-java-2.0.4-bin.jar
-
-

For PostgreSql (in Linux):

-
- 
Connect: jdbc:postgresql://localhost/emsdevel
Driver: org.postgresql.Driver
driver filename: /opt/postgresql/share/java/postgresql.jar
diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/add_driver.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/add_driver.gif new file mode 100644 index 0000000..177f0a6 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/add_driver.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page1.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page1.gif new file mode 100644 index 0000000..831bba6 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page1.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2.gif new file mode 100644 index 0000000..20dba7e Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2_informix.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2_informix.gif new file mode 100644 index 0000000..3619e74 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2_informix.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2_postgresql.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2_postgresql.gif new file mode 100644 index 0000000..9c72ec3 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page2_postgresql.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page3.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page3.gif new file mode 100644 index 0000000..42b13ae Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page3.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page4.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page4.gif new file mode 100644 index 0000000..f4c8eee Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/images/new_bookmark/page4.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/jdbc_connection_details.html b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/jdbc_connection_details.html new file mode 100644 index 0000000..a456a47 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/jdbc_connection_details.html @@ -0,0 +1,34 @@ + + + + + Specifying JDBC Connection Details + + + +

Specifying JDBC Connection Details

+

Once a JDBC Driver has been selected, provide the JDBC connection details such as +userid, password and JDBC connection URL.

+ + + +

Please note that passwords are stored relatively unsecurely in a QuantumDB +configuration file. A more secure option might be to select the "Prompt for +Password" option. When this option is selected, QuantumDB will prompt the user +for a password whenever it tries to connect to the database. + +

QuantumDB provides extra JDBC URL assistance for some well-known drivers. For example, +if you're using the standard PostgreSQL driver, org.postgresql.Driver, you'll +see the following screen:

+ + + +

Similarly, the standard IBM Informix driver provides the following screen:

+ + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/jdbc_driver.html b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/jdbc_driver.html new file mode 100644 index 0000000..98cbf67 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/jdbc_driver.html @@ -0,0 +1,41 @@ + + + + + Creating a QuantumDB Bookmark + + + +

Specifying a JDBC Driver

+

QuantumDB uses standard JDBC Drivers to access databases. The first step in +setting up a database bookmark is, therefore, selecting a JDBC Driver.

+ + + +

The first time you try to configure a bookmark, QuantumDB will already recognize +one driver: the standard JDBC-ODBC driver provided with the Java Runtime Environment. +For some people, this will be sufficient to access databases, but most people will +probably choose to set up additional drivers. + +

Select the "Add Driver..." button to choose an alternate driver.

+ + + +

Provide the details for the new driver. Most drivers require at least one .jar file. +Specify the location of the .jar file(s), and the driver class name. Note that once you +specify the .jar locations, you can use the "Browse..." button beside the class name +field to select valid driver class names. + +

Finally, the Add Driver Wizard asks for a database type. If you're setting up a fairly +standard driver (such as, for example, the standard Oracle or DB2 driver), QuantumDB will +probably recognize the driver class name and select the appropriate driver from the list. +Otherwise, choose the corresponding database type or, if your database type isn't listed, +select "Generic JDBC". + +

The database type helps QuantumDB provide defaults for later parts of the bookmark set-up +process, and also tells the plugin how to support some of the non-standard database features +(such as sequences). + + + diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/schema_rules.html b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/schema_rules.html new file mode 100644 index 0000000..50a681a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/schema_rules.html @@ -0,0 +1,22 @@ + + + + + Choosing Which Schemas You Want to View + + + +

Choosing Which Schemas You Want to View

+

Optionally, the fourth page of the Bookmark Wizard lets you choose which +schemas you want to work with.

+ + + +

By default, bookmarks are set up to view all schemas. + +

If your database doesn't support schemas (like, for example, MySQL), then the +schema selection rule has no effect. + + + diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/toc.xml b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/toc.xml index 5af310f..d676b89 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/doc/toc.xml +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/doc/toc.xml @@ -4,6 +4,11 @@ - + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/bigtable.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/bigtable.gif index b90c043..2ea69c8 100644 Binary files a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/bigtable.gif and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/bigtable.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close.gif index 3fb8662..97335a3 100644 Binary files a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close.gif and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all.gif new file mode 100644 index 0000000..4cae8e4 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all_2x.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all_2x.gif new file mode 100644 index 0000000..65a3841 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all_2x.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all_disabled.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all_disabled.gif new file mode 100644 index 0000000..e6d96df Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_all_disabled.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_disabled.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_disabled.gif new file mode 100644 index 0000000..3323f17 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/close_disabled.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/entitygroup.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/entitygroup.gif index 8bfe593..f124fcb 100644 Binary files a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/entitygroup.gif and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/entitygroup.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/external_jar.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/external_jar.gif new file mode 100644 index 0000000..6cb185c Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/external_jar.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/external_jar_2x.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/external_jar_2x.gif new file mode 100644 index 0000000..11e04e2 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/external_jar_2x.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/next.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/next.gif index d25a3f9..90bcce6 100644 Binary files a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/next.gif and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/next.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/previous.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/previous.gif index f48362d..3751627 100644 Binary files a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/previous.gif and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/previous.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/icons/table_details.gif b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/table_details.gif new file mode 100644 index 0000000..4c96271 Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.quantum.sql/icons/table_details.gif differ diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml index bc0c025..710df0b 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml @@ -3,8 +3,8 @@ @@ -122,7 +122,7 @@ + class="com.quantum.php.preferences.PHPSQLConnectionPreferencePage" + id="com.quantum.php.preferences.PHPSQLConnectionPreferencePage"> + class="com.quantum.php.preferences.PHPSQLTemplatesPreferencePage" + id="com.quantum.php.preferences.PHPSQLTemplatesPreferencePage"> diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ImageStore.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ImageStore.java index 4d643d7..1a7495f 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ImageStore.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ImageStore.java @@ -35,6 +35,9 @@ public class ImageStore { public static final String CLASS = "class"; public static final String CLEAR = "clear"; public static final String CLOSE = "close"; + public static final String CLOSE_DISABLED = "close_disabled"; + public static final String CLOSE_ALL = "close_all"; + public static final String CLOSE_ALL_DISABLED = "close_all_disabled"; public static final String COLUMN = "column"; public static final String CONNECT = "connect"; public static final String CONNECTED = "connected"; @@ -46,6 +49,7 @@ public class ImageStore { public static final String EDIT = "edit"; public static final String ENTITYGROUP = "entitygroup"; public static final String EXPORT = "export"; + public static final String EXTERNAL_JAR = "external_jar"; public static final String FILTER = "filter"; public static final String FOREIGNKEY = "foreignkey"; public static final String FULLDATA = "fulldata"; @@ -75,6 +79,7 @@ public class ImageStore { public static final String SUBSET = "subset"; public static final String SUCCESS = "success"; public static final String TABLE = "bigtable"; + public static final String TABLE_DETAILS = "table_details"; public static final String TEMPLATE = "template"; public static final String TORQUE = "torque"; public static final String TRIGGER = "trigger"; @@ -96,7 +101,7 @@ public class ImageStore { * @param default1 * @return */ - private static Image getImage(String imageName, AbstractUIPlugin plugin) { + public static Image getImage(String imageName, AbstractUIPlugin plugin) { ImageRegistry registry = plugin.getImageRegistry(); String key = stripSuffix(imageName); Image image = registry.get(getVersionAppropriateImage(key)); @@ -153,6 +158,9 @@ public class ImageStore { addImage(registry, url, CLASS); addImage(registry, url, CLEAR); addImage(registry, url, CLOSE); + addImage(registry, url, CLOSE_DISABLED); + addImage(registry, url, CLOSE_ALL); + addImage(registry, url, CLOSE_ALL_DISABLED); addImage(registry, url, COLUMN); addImage(registry, url, CONNECT); addImage(registry, url, CONNECTED); @@ -164,6 +172,7 @@ public class ImageStore { addImage(registry, url, EDIT); addImage(registry, url, ENTITYGROUP); addImage(registry, url, EXPORT); + addImage(registry, url, EXTERNAL_JAR); addImage(registry, url, FILTER); addImage(registry, url, FOREIGNKEY); addImage(registry, url, FULLDATA); @@ -192,6 +201,7 @@ public class ImageStore { addImage(registry, url, SUBSET); addImage(registry, url, SUCCESS); addImage(registry, url, TABLE); + addImage(registry, url, TABLE_DETAILS); addImage(registry, url, TEMPLATE); addImage(registry, url, TORQUE); addImage(registry, url, TRIGGER); @@ -202,9 +212,11 @@ public class ImageStore { if (!VersioningHelper.isEclipse30()) { addImage(registry, url, CLOSE + VERSION_2); + addImage(registry, url, CLOSE_ALL + VERSION_2); addImage(registry, url, COPY + VERSION_2); addImage(registry, url, DELETE + VERSION_2); addImage(registry, url, EXPORT + VERSION_2); + addImage(registry, url, EXTERNAL_JAR + VERSION_2); addImage(registry, url, IMPORT + VERSION_2); addImage(registry, url, PASTE + VERSION_2); addImage(registry, url, REFRESH + VERSION_2); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumPlugin.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumPlugin.java index 12d4f2f..5a8b0e9 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumPlugin.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumPlugin.java @@ -20,11 +20,9 @@ import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.Path; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbench; @@ -130,16 +128,7 @@ public class QuantumPlugin extends AbstractUIPlugin { sysClip = new Clipboard(null); } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.Plugin#shutdown() - */ - public void shutdown() throws CoreException { -// if (!sysClip.isDisposed()) { -// sysClip.dispose(); -// } - super.shutdown(); - } - + /** * Write the bookmarks and subsets to a file, saving them for next use of the quantum plugin * @param target @@ -198,8 +187,9 @@ public class QuantumPlugin extends AbstractUIPlugin { getPreferenceStore().setDefault("quantum.string.bold", false); //$NON-NLS-1$ getPreferenceStore().setDefault("quantum.comment.bold", false); //$NON-NLS-1$ getPreferenceStore().setDefault("quantum.numeric.bold", false); //$NON-NLS-1$ - PreferenceConverter.setDefault(getPreferenceStore(), "quantum.font", (FontData) null); //$NON-NLS-1$ - getPreferenceStore().setDefault("com.quantum.model.Bookmark.queryHistorySize", 20); //$NON-NLS-1$ + PreferenceConverter.setDefault(getPreferenceStore(), "quantum.font", //$NON-NLS-1$ + JFaceResources.getTextFont().getFontData()); + getPreferenceStore().setDefault("com.quantum.model.Bookmark.queryHistorySize", 20); //$NON-NLS-1$ getPreferenceStore().setDefault( diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumResources.properties b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumResources.properties index 326db6a..7cb2931 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumResources.properties +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/QuantumResources.properties @@ -16,7 +16,6 @@ bookmarkview.deleteAllRows = Delete all rows from bookmarkview.deleteRowsAction = Delete all rows bookmarkview.customCopyAction = Custom Copy bookmarkview.confirmDeleteAllRows = Are you sure you want to delete all the rows from this table? -sqlqueryview.executeQuery = Execute Query (Ctrl+Shift+Q) sqlqueryview.importQuery = Import Query sqlqueryview.exportQuery = Export Query sqlqueryview.clear = Clear @@ -30,7 +29,6 @@ tableview.close = Close Table tableview.update = Update... tableview.insert = Insert... tableview.delete = Delete... -tableview.filterSort = Sort or Filter Table... tableview.showAll = Toggle Show All Table Rows tableview.defaultEncoding = Set Default Encoding tableview.UTF8Encoding = Set UTF-8 @@ -174,10 +172,13 @@ SubsetView.CreatesANewEmptySubset=Creates a new empty subset SubsetView.DeletesTheSelectedColumns=Deletes the selected column SubsetView.DeletesTheSelectedObject=Deletes the selected object SubsetView.DeletesTheSelectedSubset=Deletes the selected subset -TableView.FilterAndSort=Filter and Sort TableView.UpdateRow=Update Row TableView.InsertRow=Insert Row TableView.DeleteRow=Delete Row +TableView.PHPSelectRow=PHP Select Row +TableView.PHPUpdateRow=PHP Update Row +TableView.PHPInsertRow=PHP Insert Row +TableView.PHPDeleteRow=PHP Delete Row TableAdapter.to=\ to TableAdapter.of=\ of TableAdapter.full=\ (FULL) @@ -192,7 +193,7 @@ BookmarkWizard.PasswordAst=Password BookmarkWizard.Schema=Schema (optional) BookmarkWizard.ConnectAst=*JDBC URL BookmarkWizard.DriverAst=*Driver -BookmarkWizard.TypeAst=*Type +BookmarkWizard.TypeAst=Type BookmarkWizard.Prompt=Prompt for password BookmarkWizard.DriverFilenameAst=*Driver Filename BookmarkWizard.Browse=Browse... @@ -303,9 +304,11 @@ com.quantum.view.JDBCDriverTableViewer.driverColumn4=File Path com.quantum.wizards.AddDriverWizard.windowTitle=New JDBC Driver com.quantum.wizards.AddDriverWizard$PageImpl.title=JDBC Driver com.quantum.wizards.AddDriverWizard$PageImpl.description=Provide the following information about the driver. -com.quantum.wizards.AddDriverWizard$PageImpl.browse=Browse -com.quantum.wizards.AddDriverWizard$PageImpl.fileName=File name: -com.quantum.wizards.AddDriverWizard$PageImpl.driverClassName=Class name: +com.quantum.wizards.AddDriverWizard.addExternalJar=Add External Jar... +com.quantum.wizards.AddDriverWizard.removeJar=Remove Jar... +com.quantum.wizards.AddDriverWizard.browse=Browse... +com.quantum.wizards.AddDriverWizard.jars=Driver Jars: +com.quantum.wizards.AddDriverWizard.driverClassName=Class name: com.quantum.adapters.DatabaseAdapter.GENERIC = Generic JDBC com.quantum.adapters.DatabaseAdapter.HSQLDB = HSQL (Hypersonic) @@ -319,6 +322,8 @@ com.quantum.adapters.DatabaseAdapter.INFORMIX = Informix Dynamic Server com.quantum.adapters.DatabaseAdapter.REDBRICK = Red Brick com.quantum.adapters.DatabaseAdapter.SYBASE = Sybase com.quantum.adapters.DatabaseAdapter.POINTBASE = Pointbase +com.quantum.adapters.DatabaseAdapter.JDBC_ODBC_BRIDGE = JDBC-ODBC Bridge +com.quantum.adapters.DatabaseAdapter.MS_SQL_SERVER = Microsoft SQL Server com.quantum.view.SchemaSelectionControl.addSchemaDialog = Select a Schema com.quantum.view.SchemaSelectionControl.connectTitle = Connect Required @@ -369,6 +374,41 @@ com.quantum.actions.BaseExecuteAction.execute2=Executing Query.. com.quantum.actions.BaseExecuteAction.done=Done ({0} queries executed, {1} rows updated, {2} result sets displayed, {3} errors, {4} seconds) com.quantum.actions.BaseExecuteAction.selectBookmark=Select a bookmark +com.quantum.actions.ExecuteAction.textNoBookmark=Execute... +com.quantum.actions.ExecuteAction.text=Execute Against "{0}" com.quantum.actions.ExecuteAction.parsing=Parsing sql script... com.quantum.actions.ExecuteAction.autocommitTitle=Autocommit changed -com.quantum.actions.ExecuteAction.autocommitMessage=The autocommit setting of the bookmark, {0} has been changed. \ No newline at end of file +com.quantum.actions.ExecuteAction.autocommitMessage=The autocommit setting of the bookmark, {0} has been changed. +com.quantum.view.driver.DeleteDriverAction.text=Delete +com.quantum.view.driver.DeleteDriverAction.confirm=Confirm Delete +com.quantum.view.driver.DeleteDriverAction.confirmText=Are you sure you want to delete "{0}"? +com.quantum.view.driver.DeleteDriverAction.failed=Delete Failed +com.quantum.view.driver.DeleteDriverAction.inUse=The selected driver is still in use. +com.quantum.view.driver.DeleteDriverAction.cant=The selected driver cannot be deleted. + +com.quantum.view.tableview.NextPageAction.text=Next +com.quantum.view.tableview.PreviousPageAction.text=Previous +com.quantum.view.tableview.RefreshTableAction.text=Refresh +com.quantum.view.tableview.ChangeEncodingAction.default=Default encoding +com.quantum.view.tableview.ChangeEncodingAction.utf8=UTF-8 encoding +com.quantum.view.tableview.ChangeEncodingAction.utf16=UTF-16 encoding +com.quantum.view.tableview.CloseResultSetAction.text=Close Result Set +com.quantum.view.tableview.CloseAllResultSetsAction.text=Close All Result Sets +com.quantum.view.tableview.CopyAction.text=Copy +com.quantum.view.tableview.SelectAllAction.text=Select All +com.quantum.view.tableview.FullModeAction.text = Toggle Show All Table Rows +com.quantum.view.tableview.TableViewActionGroup.filterSortTitle = Sort or Filter Table... +com.quantum.view.tableview.TableViewActionGroup.filterSort=Filter and Sort + +com.quantum.view.tableview.ResultSetViewer.position = {0} to {1} of {2} rows. +com.quantum.view.tableview.ResultSetViewer.unknown = + +com.quantum.wizards.URLSetupControl.text=JDBC Connection URL +com.quantum.wizards.URLSetupControl.hostname=Host name: +com.quantum.wizards.URLSetupControl.port=Port: +com.quantum.wizards.URLSetupControl.dbname=Database name: +com.quantum.wizards.URLSetupControl.datasource=Data Source: +com.quantum.wizards.InformixURLSetupControl.informixserver=Informix Server: +com.quantum.wizards.URLSetupControl.url=URL: + +com.quantum.model.ConnectionException.couldNotInstaniateDriver = The driver, {0}, could not be instantiated.\nPlease ensure that the bookmark, {1}, is properly defined. diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/BaseExecuteAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/BaseExecuteAction.java index 5e8c9d6..c5ab79e 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/BaseExecuteAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/BaseExecuteAction.java @@ -10,12 +10,14 @@ import com.quantum.Messages; import com.quantum.model.Bookmark; import com.quantum.model.BookmarkCollection; import com.quantum.sql.MultiSQLServer; +import com.quantum.sql.SQLResultSetCollection; +import com.quantum.sql.SQLResultSetResults; import com.quantum.sql.SQLResults; +import com.quantum.sql.SQLUpdateResults; import com.quantum.ui.dialog.ExceptionDisplayDialog; import com.quantum.ui.dialog.SimpleSelectionDialog; import com.quantum.util.connection.ConnectionUtil; import com.quantum.view.LogProxy; -import com.quantum.view.tableview.DefaultSizes; import com.quantum.view.tableview.TableView; import org.eclipse.core.runtime.CoreException; @@ -43,12 +45,12 @@ public abstract class BaseExecuteAction extends Action { if (results == null) { errorCount++; } else { - queryDuration += results.getTime()/1000.0; // calculate the execution time (in seconds) + queryDuration += results.getTime()/1000.0; resultCount++; if (results.isResultSet()) { resultsDisplayed++; } else { - resultUpdateCount += results.getUpdateCount(); + resultUpdateCount += ((SQLUpdateResults) results).getUpdateCount(); } } } @@ -129,12 +131,14 @@ public abstract class BaseExecuteAction extends Action { String query = (String) queries.get(i); System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$ if (query != null && query.trim().length() > 0) { - SQLResults results = getSQLResults(connection, server, query); + SQLResults results = getSQLResults(bookmark, connection, server, query); metrics.measure(results); if (results != null) { bookmark.addQuery(query); if (results.isResultSet()) { - TableView.getInstance().loadQuery(bookmark, results); + SQLResultSetCollection.getInstance().addSQLResultSet( + (SQLResultSetResults) results); + activateTableView(); } } } @@ -145,6 +149,13 @@ public abstract class BaseExecuteAction extends Action { } /** + * + */ + private void activateTableView() { + TableView.getInstance(); + } + + /** * @return * @throws CoreException * @throws IOException @@ -162,14 +173,13 @@ public abstract class BaseExecuteAction extends Action { private void displayFinalStatusMessage(Metrics metrics) { String message = Messages.getString( BaseExecuteAction.class, - "done", //$NON-NLS-1$ //$NON-NLS-2$ + "done", //$NON-NLS-1$ metrics.getResults()); if (metrics.hasErrors()) { getStatusLineManager().setErrorMessage( ImageStore.getImage(ImageStore.STOP), message); } else { - getStatusLineManager().setMessage( - ImageStore.getImage(ImageStore.SUCCESS), message); + getStatusLineManager().setMessage(message); } } @@ -179,11 +189,10 @@ public abstract class BaseExecuteAction extends Action { * @param query * @return */ - private SQLResults getSQLResults(Connection connection, MultiSQLServer server, String query) { + private SQLResults getSQLResults(Bookmark bookmark, Connection connection, MultiSQLServer server, String query) { SQLResults results = null; try { - results = server.execute(connection, query, 1, - DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE); + results = server.execute(bookmark, connection, query); } catch (SQLException e) { LogProxy log = LogProxy.getInstance(); log.addText(LogProxy.ERROR, diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/BaseSequenceAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/BaseSequenceAction.java index 0e967c4..d0f4217 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/BaseSequenceAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/BaseSequenceAction.java @@ -3,8 +3,13 @@ package com.quantum.actions; import java.sql.Connection; import java.util.List; +import com.quantum.adapters.DatabaseAdapter; import com.quantum.model.Bookmark; +import com.quantum.sql.SQLResultSetCollection; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.sql.SQLResults; import com.quantum.util.connection.ConnectionUtil; +import com.quantum.view.ViewHelper; import com.quantum.view.bookmark.EntityNode; import com.quantum.view.bookmark.TreeNode; @@ -23,7 +28,7 @@ public abstract class BaseSequenceAction extends SelectionListenerAction { protected BaseSequenceAction(String text, IViewPart view) { super(text); - + this.view = view; } protected Bookmark getBookmark() { @@ -50,4 +55,28 @@ public abstract class BaseSequenceAction extends SelectionListenerAction { && (selection.getFirstElement() instanceof EntityNode) && ((EntityNode) selection.getFirstElement()).isSequence(); } + + public void run() { + EntityNode sequence = getEntityNode(); + String name = null; + if (sequence.isSequence()) { + Bookmark bookmark = sequence.getBookmark(); + DatabaseAdapter adapter = bookmark.getAdapter(); + if (adapter == null) return; + name = sequence.getName(); + String query = getQuery(sequence, name, adapter); + + SQLResults results = ViewHelper.tryGetResults(view, bookmark, getConnection(), query); + if (results != null && results.isResultSet()) + SQLResultSetCollection.getInstance().addSQLResultSet((SQLResultSetResults) results); + } + } + + /** + * @param sequence + * @param name + * @param adapter + * @return + */ + protected abstract String getQuery(EntityNode sequence, String name, DatabaseAdapter adapter); } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/CloseTableAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/CloseTableAction.java deleted file mode 100644 index dc99395..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/CloseTableAction.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.quantum.actions; - -import com.quantum.view.tableview.TableView; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; - -/** - * @author root - * - */ -public class CloseTableAction extends Action implements IViewActionDelegate { - TableView view; - /** - * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart) - */ - public void init(IViewPart view) { - this.view = (TableView) view; - } - - /** - * @see org.eclipse.ui.IActionDelegate#run(IAction) - */ - public void run(IAction action) { - run(); - } - public void run() { - view.closeCurrent(); - } - - /** - * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - } - -} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ExecuteAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ExecuteAction.java index d0044f5..26f869c 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ExecuteAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ExecuteAction.java @@ -3,14 +3,17 @@ package com.quantum.actions; import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; +import java.util.Arrays; import java.util.List; import java.util.Vector; import com.quantum.ImageStore; import com.quantum.Messages; +import com.quantum.QuantumPlugin; import com.quantum.model.Bookmark; import com.quantum.model.BookmarkCollection; -import com.quantum.sql.SQLParser; +import com.quantum.model.DisplayableComparator; +import com.quantum.sql.parser.SQLParser; import com.quantum.view.SQLQueryView; import org.eclipse.core.runtime.CoreException; @@ -18,6 +21,7 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IMenuCreator; import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.events.MenuAdapter; import org.eclipse.swt.events.MenuEvent; @@ -32,36 +36,60 @@ import org.eclipse.swt.widgets.Shell; * @author panic */ public class ExecuteAction extends BaseExecuteAction implements IMenuCreator { + +private static final String LAST_USED_BOOKMARK_PREFERENCE = ExecuteAction.class.getName() + ".bookmark"; private SQLQueryView view; public ExecuteAction(SQLQueryView view) { this.view = view; setActionDefinitionId("com.quantum.actions.ExecuteAction"); setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.PLAY)); - setText(Messages.getString("sqlqueryview.executeQuery")); - setToolTipText(Messages.getString("sqlqueryview.executeQuery")); + initTextAndToolTip(); setMenuCreator(this); } - - + /** + * + */ + private void initTextAndToolTip() { + Bookmark lastUsedBookmark = getLastUsedBookmark(); + if (lastUsedBookmark == null) { + setText(Messages.getString(ExecuteAction.class, "textNoBookmark")); + setToolTipText(Messages.getString(ExecuteAction.class, "textNoBookmark")); + } else { + Object[] parameters = new Object[] { lastUsedBookmark.getName() }; + setText(Messages.getString(ExecuteAction.class, "text", parameters)); + setToolTipText(Messages.getString(ExecuteAction.class, "text", parameters)); + } + } + + protected Bookmark getBookmark() { + Bookmark lastUsedBookmark = getLastUsedBookmark(); + return lastUsedBookmark == null ? super.getBookmark() : lastUsedBookmark; + } protected void execute(Bookmark bookmark, Connection connection) throws IOException, CoreException, SQLException { - boolean autoCommitPreference = this.view.isAutoCommitPreference(); - boolean changed = false; - if (connection.getAutoCommit() != autoCommitPreference) { - connection.setAutoCommit(autoCommitPreference); - changed = true; - } - - super.execute(bookmark, connection); - - if (changed) { - MessageDialog.openInformation(getShell(), - Messages.getString(ExecuteAction.class, "autocommitTitle"), - Messages.getString(ExecuteAction.class, "autocommitMessage", - new Object[] { bookmark.getName() })); + try { + boolean autoCommitPreference = this.view.isAutoCommitPreference(); + boolean changed = false; + if (connection.getAutoCommit() != autoCommitPreference) { + connection.setAutoCommit(autoCommitPreference); + changed = true; + } + + super.execute(bookmark, connection); + + if (changed) { + MessageDialog.openInformation(getShell(), + Messages.getString(ExecuteAction.class, "autocommitTitle"), + Messages.getString(ExecuteAction.class, "autocommitMessage", + new Object[] { bookmark.getName() })); + } + } finally { + QuantumPlugin.getDefault().getPreferenceStore().setValue( + LAST_USED_BOOKMARK_PREFERENCE, bookmark.getName()); + initTextAndToolTip(); } } /** @@ -113,18 +141,58 @@ public class ExecuteAction extends BaseExecuteAction implements IMenuCreator { } protected void fillMenu(Menu menu) { + Bookmark lastUsedBookmark = getLastUsedBookmark(); + + if (lastUsedBookmark != null) { + createSubAction(menu, lastUsedBookmark); + Separator separator = new Separator(); + separator.fill(menu, -1); + } + Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks(); + Arrays.sort(bookmarks, new DisplayableComparator()); for (int i = 0, length = bookmarks == null ? 0 : bookmarks.length; i < length; i++) { final Bookmark bookmark = bookmarks[i]; - Action action = new Action() { - public void run() { - ExecuteAction.this.execute(bookmark); - } - }; - action.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.BOOKMARK)); + createSubAction(menu, bookmark); + } + } + + + + /** + * @return + */ + private Bookmark getLastUsedBookmark() { + String lastUsedName = QuantumPlugin.getDefault().getPreferenceStore().getString( + LAST_USED_BOOKMARK_PREFERENCE); + Bookmark lastUsedBookmark = lastUsedName == null + ? null + : BookmarkCollection.getInstance().find(lastUsedName); + return lastUsedBookmark; + } + + + + /** + * @param menu + * @param bookmark + */ + private void createSubAction(Menu menu, final Bookmark bookmark) { + Action action = new Action() { + public void run() { + ExecuteAction.this.execute(bookmark); + } + }; + action.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.BOOKMARK)); + + // The last '@' sign is treated specially, so if the + // bookmark name contains an '@', then add an extra one to the end + if (bookmark.getName().indexOf('@') >= 0) { + action.setText(bookmark.getName() + '@'); + } else { action.setText(bookmark.getName()); - ActionContributionItem item = new ActionContributionItem(action); - item.fill(menu, -1); } + ActionContributionItem item = new ActionContributionItem(action); + item.fill(menu, -1); } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ExecuteAgainstAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ExecuteAgainstAction.java index ffdac6c..0051eaf 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ExecuteAgainstAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ExecuteAgainstAction.java @@ -5,12 +5,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import com.quantum.ImageStore; -import com.quantum.Messages; -import com.quantum.model.Bookmark; -import com.quantum.model.BookmarkCollection; -import com.quantum.sql.SQLParser; -import com.quantum.ui.dialog.SimpleSelectionDialog; +import com.quantum.sql.parser.SQLParser; import com.quantum.util.io.InputStreamHelper; import org.eclipse.core.resources.IFile; @@ -20,7 +15,6 @@ import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPart; diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/NextSequenceAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/NextSequenceAction.java index 83a7a26..f4b032c 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/NextSequenceAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/NextSequenceAction.java @@ -3,11 +3,7 @@ package com.quantum.actions; import com.quantum.ImageStore; import com.quantum.Messages; import com.quantum.adapters.DatabaseAdapter; -import com.quantum.model.Bookmark; -import com.quantum.sql.SQLResults; -import com.quantum.view.ViewHelper; import com.quantum.view.bookmark.EntityNode; -import com.quantum.view.tableview.TableView; import org.eclipse.ui.IViewPart; @@ -22,19 +18,13 @@ public class NextSequenceAction extends BaseSequenceAction { setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.APPEND)); } - public void run() { - EntityNode sequence = getEntityNode(); - String name = null; - if (sequence.isSequence()) { - Bookmark bookmark = sequence.getBookmark(); - DatabaseAdapter adapter = bookmark.getAdapter(); - if (adapter == null) return; - name = sequence.getName(); - String query = adapter.getNextValue(name, sequence.getEntity().getSchema()); - - SQLResults results = ViewHelper.tryGetResults(view, getConnection(), query); - if (results != null && ! results.isError()) - TableView.getInstance().loadQuery(bookmark, results); - } + /** + * @param sequence + * @param name + * @param adapter + * @return + */ + protected String getQuery(EntityNode sequence, String name, DatabaseAdapter adapter) { + return adapter.getNextValue(name, sequence.getEntity().getSchema()); } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/PrevSequenceAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/PrevSequenceAction.java index ab63311..ba086d0 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/PrevSequenceAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/PrevSequenceAction.java @@ -7,11 +7,7 @@ package com.quantum.actions; import com.quantum.ImageStore; import com.quantum.Messages; import com.quantum.adapters.DatabaseAdapter; -import com.quantum.model.Bookmark; -import com.quantum.sql.SQLResults; -import com.quantum.view.ViewHelper; import com.quantum.view.bookmark.EntityNode; -import com.quantum.view.tableview.TableView; import org.eclipse.ui.IViewPart; @@ -25,17 +21,13 @@ public class PrevSequenceAction extends BaseSequenceAction { setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.GRID)); } - public void run() { - EntityNode sequence = getEntityNode(); - if (sequence.isSequence()) { - Bookmark bookmark = sequence.getBookmark(); - DatabaseAdapter adapter = bookmark.getAdapter(); - if (adapter == null) return; - String name = sequence.getName(); - String query = adapter.getPrevValue(name, sequence.getEntity().getSchema()); - SQLResults results = ViewHelper.tryGetResults(view, getConnection(), query); - if (results != null && ! results.isError()) - TableView.getInstance().loadQuery(bookmark, results); - } + /** + * @param sequence + * @param name + * @param adapter + * @return + */ + protected String getQuery(EntityNode sequence, String name, DatabaseAdapter adapter) { + return adapter.getPrevValue(name, sequence.getEntity().getSchema()); } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/RefreshTableAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/RefreshTableAction.java deleted file mode 100644 index d987d8a..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/RefreshTableAction.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.quantum.actions; - -import com.quantum.view.tableview.TableView; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; - -/** - * @author root - * Implements the "Refresh Table" action for the TableView view - */ -public class RefreshTableAction extends Action implements IViewActionDelegate { - TableView view; - /** - * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart) - */ - public void init(IViewPart view) { - this.view = (TableView) view; - } - - /** - * @see org.eclipse.ui.IActionDelegate#run(IAction) - */ - public void run(IAction action) { - run(); - } - public void run() { - view.refreshCurrent(); - } - - /** - * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - } - -} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableAction.java index 91b9916..7975f0b 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableAction.java @@ -1,12 +1,22 @@ package com.quantum.actions; +import java.sql.SQLException; + import com.quantum.ImageStore; import com.quantum.Messages; +import com.quantum.adapters.DatabaseAdapter; +import com.quantum.model.Bookmark; import com.quantum.model.Entity; +import com.quantum.sql.MultiSQLServer; +import com.quantum.sql.SQLResultSetCollection; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.sql.SQLResults; +import com.quantum.ui.dialog.ExceptionDisplayDialog; +import com.quantum.util.connection.ConnectionUtil; import com.quantum.view.bookmark.EntityNode; -import com.quantum.view.tableview.TableView; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IViewPart; import org.eclipse.ui.actions.SelectionListenerAction; @@ -16,28 +26,42 @@ import org.eclipse.ui.actions.SelectionListenerAction; */ public class ViewTableAction extends SelectionListenerAction { private Entity entity; + private ConnectionUtil connectionUtil = new ConnectionUtil(); + private final IViewPart view; public ViewTableAction(IViewPart view) { super(Messages.getString(ViewTableAction.class, "text")); + this.view = view; setImageDescriptor( ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE)); } public void run() { - TableView.getInstance().loadTable(this.entity); - // TODO: reinstate this -// } else if (view instanceof SubsetView){ -// SubsetView subsetView = (SubsetView) view; -// node = (TreeNode) subsetView.getCurrent(); -// if (!(node instanceof ObjectNode)) return; -// ObjectNode objectNode = (ObjectNode) node; -// -// String query = objectNode.getQuery(); -// -// SQLResults results = ViewHelper.tryGetResults(view, objectNode.getConnection(), query); -// if (results != null && ! results.isError()) -// TableView.getInstance().loadQuery(bookmark.getBookmark(), results); -// + + Bookmark bookmark = this.entity.getBookmark(); + DatabaseAdapter adapter = bookmark.getAdapter(); + String query = adapter.getTableQuery((entity).getQualifiedName()); + + try { + SQLResults results = MultiSQLServer.getInstance().execute( + bookmark, + this.connectionUtil.connect(bookmark, getShell()), + this.entity, + query); + + if (results != null && results.isResultSet()) { + SQLResultSetCollection.getInstance().addSQLResultSet((SQLResultSetResults) results); + } + } catch (SQLException e) { + ExceptionDisplayDialog.openError(getShell(), null, null, e); + } + } + + /** + * @return + */ + private Shell getShell() { + return this.view.getSite().getShell(); } public boolean updateSelection(IStructuredSelection selection) { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableDetailsAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableDetailsAction.java index 9d16eef..19d803c 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableDetailsAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableDetailsAction.java @@ -1,17 +1,19 @@ package com.quantum.actions; import java.sql.Connection; +import java.sql.SQLException; import java.util.List; import com.quantum.ImageStore; import com.quantum.Messages; import com.quantum.model.Bookmark; import com.quantum.model.Entity; -import com.quantum.sql.SQLResults; +import com.quantum.sql.MultiSQLServer; +import com.quantum.sql.SQLResultSetCollection; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.ui.dialog.ExceptionDisplayDialog; import com.quantum.util.connection.ConnectionUtil; -import com.quantum.view.ViewHelper; import com.quantum.view.bookmark.EntityNode; -import com.quantum.view.tableview.TableView; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; @@ -26,20 +28,23 @@ public class ViewTableDetailsAction extends SelectionListenerAction { public ViewTableDetailsAction(IViewPart view) { super(Messages.getString(ViewTableDetailsAction.class, "text")); - setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE)); + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.TABLE_DETAILS)); this.view = view; } public void run() { Entity entity = getEntity(); - StringBuffer query = new StringBuffer(); - query.append(Messages.getString("MetaDataKey")+Messages.getString("MetaDataKeySeparator")); //$NON-NLS-1$ //$NON-NLS-2$ - query.append(entity.getQuotedTableName()); Connection connection = connectionUtil.getConnection(getBookmark(), getShell()); if (connection != null) { - SQLResults results = ViewHelper.tryGetResults(view, connection, query.toString()); - if (results != null && ! results.isError()) - TableView.getInstance().loadQuery(entity.getBookmark(), results); + try { + SQLResultSetResults results = + MultiSQLServer.getInstance().getMetaData(entity, connection); + if (results != null) { + SQLResultSetCollection.getInstance().addSQLResultSet(results); + } + } catch (SQLException e) { + ExceptionDisplayDialog.openError(getShell(), null, null, e); + } } } public void selectionChanged(IAction action, ISelection selection) { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/AdapterFactory.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/AdapterFactory.java index 37f05c4..8ff6821 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/AdapterFactory.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/AdapterFactory.java @@ -31,6 +31,26 @@ public class AdapterFactory { } } + static class DriverInfo { + private final String type; + private final String urlPattern; + + DriverInfo(String type) { + this(type, null); + } + DriverInfo(String type, String urlPattern) { + this.type = type; + this.urlPattern = urlPattern; + + } + public String getType() { + return this.type; + } + public String getURLPattern() { + return this.urlPattern; + } + } + public static final String GENERIC = "GENERIC"; //$NON-NLS-1$ public static final String HSQLDB = "HSQLDB"; //$NON-NLS-1$ public static final String ORACLE = "ORACLE"; //$NON-NLS-1$ @@ -43,33 +63,39 @@ public class AdapterFactory { public static final String REDBRICK = "REDBRICK"; //$NON-NLS-1$ public static final String POINTBASE = "POINTBASE"; //$NON-NLS-1$ public static final String SYBASE = "SYBASE"; //$NON-NLS-1$ + public static final String JDBC_ODBC_BRIDGE = "JDBC_ODBC_BRIDGE"; //$NON-NLS-1$ + public static final String MS_SQL_SERVER = "MS_SQL_SERVER"; //$NON-NLS-1$ private static final Map DRIVER_MAP = Collections.synchronizedMap(new HashMap()); static { - DRIVER_MAP.put("com.ddtek.jdbc.informix.InformixDriver", AdapterFactory.INFORMIX); - DRIVER_MAP.put("com.ddtek.jdbc.db2.DB2Driver", AdapterFactory.DB2); - DRIVER_MAP.put("com.ddtek.jdbc.oracle.OracleDriver", AdapterFactory.ORACLE); - DRIVER_MAP.put("com.ddtek.jdbc.sqlserver.SQLServerDriver", AdapterFactory.GENERIC); - DRIVER_MAP.put("com.ddtek.jdbc.sybase.SybaseDriver", AdapterFactory.SYBASE); - DRIVER_MAP.put("com.ibm.as400.access.AS400JDBCDriver", AdapterFactory.DB2AS400); - DRIVER_MAP.put("COM.ibm.db2.jdbc.app.DB2Driver", AdapterFactory.DB2); - DRIVER_MAP.put("COM.ibm.db2.jdbc.net.DB2Driver", AdapterFactory.DB2); - DRIVER_MAP.put("com.inet.ora.OraDriver", AdapterFactory.ORACLE); - DRIVER_MAP.put("com.inet.drda.DRDADriver", AdapterFactory.DB2); - DRIVER_MAP.put("com.inet.syb.SybDriver", AdapterFactory.SYBASE); - DRIVER_MAP.put("com.inet.tds.TdsDriver", AdapterFactory.GENERIC); - DRIVER_MAP.put("com.informix.jdbc.IfxDriver", AdapterFactory.INFORMIX); - DRIVER_MAP.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", AdapterFactory.GENERIC); - DRIVER_MAP.put("com.mysql.jdbc.Driver", AdapterFactory.MYSQL); - DRIVER_MAP.put("com.pointbase.jdbc.jdbcUniversalDriver", AdapterFactory.POINTBASE); - DRIVER_MAP.put("com.sybase.jdbcx.SybDriver", AdapterFactory.SYBASE); - DRIVER_MAP.put("oracle.jdbc.driver.OracleDriver", AdapterFactory.ORACLE); - DRIVER_MAP.put("org.gjt.mm.mysql.Driver", AdapterFactory.MYSQL); - DRIVER_MAP.put("org.hsqldb.jdbcDriver", AdapterFactory.HSQLDB); - DRIVER_MAP.put("org.postgresql.Driver", AdapterFactory.POSTGRES); - DRIVER_MAP.put("weblogic.jdbc.informix.InformixDriver", AdapterFactory.INFORMIX); - DRIVER_MAP.put("weblogic.jdbc.sqlserver.SybaseDriver", AdapterFactory.SYBASE); + DRIVER_MAP.put("com.ddtek.jdbc.informix.InformixDriver", new DriverInfo(INFORMIX)); + DRIVER_MAP.put("com.ddtek.jdbc.db2.DB2Driver", new DriverInfo(DB2, "jdbc:datadirect:db2://${hostname}:${port};DatabaseName=${dbname}")); + DRIVER_MAP.put("com.ddtek.jdbc.oracle.OracleDriver", new DriverInfo(ORACLE)); + DRIVER_MAP.put("com.ddtek.jdbc.sqlserver.SQLServerDriver", new DriverInfo(GENERIC)); + DRIVER_MAP.put("com.ddtek.jdbc.sybase.SybaseDriver", new DriverInfo(SYBASE)); + DRIVER_MAP.put("com.ibm.as400.access.AS400JDBCDriver", new DriverInfo(DB2AS400)); + DRIVER_MAP.put("COM.ibm.db2.jdbc.app.DB2Driver", new DriverInfo(DB2, "jdbc:db2:{dbname}")); + DRIVER_MAP.put("COM.ibm.db2.jdbc.net.DB2Driver", new DriverInfo(DB2, "jdbc:db2://{hostname}:{port}/{dbname}")); + DRIVER_MAP.put("com.inet.ora.OraDriver", new DriverInfo(ORACLE)); + DRIVER_MAP.put("com.inet.drda.DRDADriver", new DriverInfo(DB2, "jdbc:inetdb2:{hostname}:{port}?database={dbname}")); + DRIVER_MAP.put("com.inet.syb.SybDriver", new DriverInfo(SYBASE)); + DRIVER_MAP.put("com.inet.tds.TdsDriver", new DriverInfo(MS_SQL_SERVER)); + DRIVER_MAP.put("com.informix.jdbc.IfxDriver", new DriverInfo(INFORMIX, "jdbc:informix-sqli://{hostname}:{port}/{dbname}:INFORMIXSERVER={informixserver}")); + DRIVER_MAP.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", new DriverInfo(MS_SQL_SERVER)); + DRIVER_MAP.put("com.mysql.jdbc.Driver", new DriverInfo(MYSQL, "jdbc:mysql://{hostname}:{port}/{dbname}")); + DRIVER_MAP.put("com.pointbase.jdbc.jdbcUniversalDriver", new DriverInfo(POINTBASE, "jdbc:pointbase:server://{hostname}:{port}/{dbname}")); + DRIVER_MAP.put("com.sybase.jdbc.SybDriver", new DriverInfo(SYBASE, "jdbc:sybase:Tds:{hostname}:{port}/{dbname}")); + DRIVER_MAP.put("com.sybase.jdbc2.jdbc.SybDriver", new DriverInfo(SYBASE, "jdbc:sybase:Tds:{hostname}:{port}/{dbname}")); + DRIVER_MAP.put("com.sybase.jdbcx.SybDriver", new DriverInfo(SYBASE, "jdbc:sybase:Tds:{hostname}:{port}/{dbname}")); + DRIVER_MAP.put("net.sourceforge.jtds.jdbc.Driver", new DriverInfo(MS_SQL_SERVER)); + DRIVER_MAP.put("oracle.jdbc.driver.OracleDriver", new DriverInfo(ORACLE)); + DRIVER_MAP.put("org.gjt.mm.mysql.Driver", new DriverInfo(MYSQL, "jdbc:mysql://{hostname}:{port}/{dbname}")); + DRIVER_MAP.put("org.hsqldb.jdbcDriver", new DriverInfo(HSQLDB)); + DRIVER_MAP.put("org.postgresql.Driver", new DriverInfo(POSTGRES, "jdbc:postgresql://{hostname}:{port}/{dbname}")); + DRIVER_MAP.put("sun.jdbc.odbc.JdbcOdbcDriver", new DriverInfo(JDBC_ODBC_BRIDGE, "jdbc:odbc:{datasource}")); + DRIVER_MAP.put("weblogic.jdbc.informix.InformixDriver", new DriverInfo(INFORMIX)); + DRIVER_MAP.put("weblogic.jdbc.sqlserver.SybaseDriver", new DriverInfo(SYBASE)); } private static AdapterFactory instance; @@ -83,12 +109,14 @@ public class AdapterFactory { addAdapter(new DB2Adapter()); addAdapter(new DB2AS400Adapter()); addAdapter(new PostgresAdapter()); - addAdapter(new GenericAdapter(MYSQL)); + addAdapter(new MySQLAdapter()); addAdapter(new AdabasDAdapter()); - addAdapter(new GenericAdapter(INFORMIX)); + addAdapter(new InformixAdapter()); addAdapter(new RedBrickAdapter()); addAdapter(new GenericAdapter(SYBASE)); addAdapter(new GenericAdapter(POINTBASE)); + addAdapter(new GenericAdapter(JDBC_ODBC_BRIDGE)); + addAdapter(new MSSQLServerAdapter()); } private void addAdapter(DatabaseAdapter adapter) { this.adapters.put(adapter.getType(), adapter); @@ -121,6 +149,15 @@ public class AdapterFactory { * @return the adapter type, or null if the adapter type is not known */ public String getAdapterType(String driverClassName) { - return (String) DRIVER_MAP.get(driverClassName); + DriverInfo driverInfo = (DriverInfo) DRIVER_MAP.get(driverClassName); + return driverInfo == null ? null : driverInfo.getType(); } + /** + * @param type + * @return + */ + public String getURLPattern(String driverClassName) { + DriverInfo driverInfo = (DriverInfo) DRIVER_MAP.get(driverClassName); + return driverInfo == null ? null : driverInfo.getURLPattern(); + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DB2AS400Adapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DB2AS400Adapter.java index 437dbf4..755b768 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DB2AS400Adapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DB2AS400Adapter.java @@ -6,13 +6,15 @@ public class DB2AS400Adapter extends DatabaseAdapter { super(AdapterFactory.DB2AS400); } public String getShowTableQuery(String qualifier) { - return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" + + return "SELECT table_schema, TABLE_NAME FROM QSYS2.SYSTABLES " + + "WHERE table_schema = '" + qualifier.toUpperCase() + - "' AND TABLE_TYPE IN ('T', 'P')"; //$NON-NLS-1$ //$NON-NLS-2$ + "' AND TABLE_TYPE IN ('T', 'P')"; } public String getShowViewQuery(String qualifier) { - return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" + + return "SELECT table_schema, TABLE_NAME FROM QSYS2.SYSTABLES " + + "WHERE table_schema = '" + qualifier.toUpperCase() + - "' AND TABLE_TYPE IN ('V', 'L')"; //$NON-NLS-1$ //$NON-NLS-2$ + "' AND TABLE_TYPE IN ('V', 'L')"; } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DB2Adapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DB2Adapter.java index 3f0141d..29ef4b7 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DB2Adapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DB2Adapter.java @@ -1,6 +1,8 @@ package com.quantum.adapters; -import com.quantum.sql.SQLHelper; +import java.util.HashMap; +import java.util.Map; + public class DB2Adapter extends DatabaseAdapter { /** @@ -10,18 +12,25 @@ public class DB2Adapter extends DatabaseAdapter { super(AdapterFactory.DB2); } public String getShowTableQuery(String qualifier) { - return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + qualifier.toUpperCase() + "' AND TYPE='T'"; //$NON-NLS-1$ //$NON-NLS-2$ + return "SELECT tabschema, TABNAME FROM syscat.tables WHERE tabschema = '" + qualifier.toUpperCase() + "' AND TYPE='T'"; //$NON-NLS-1$ //$NON-NLS-2$ } public String getShowViewQuery(String qualifier) { - return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + qualifier.toUpperCase() + "' AND TYPE='V'"; //$NON-NLS-1$ //$NON-NLS-2$ + return "SELECT tabschema, TABNAME FROM syscat.tables WHERE tabschema = '" + qualifier.toUpperCase() + "' AND TYPE='V'"; //$NON-NLS-1$ //$NON-NLS-2$ } public String getShowSequenceQuery(String qualifier) { - return "SELECT SEQNAME FROM sysibm.syssequences WHERE seqschema = '" + qualifier.toUpperCase() + "'"; //$NON-NLS-1$ //$NON-NLS-2$ + return "SELECT seqschema, SEQNAME FROM sysibm.syssequences WHERE seqschema = '" + qualifier.toUpperCase() + "'"; //$NON-NLS-1$ //$NON-NLS-2$ } public String getNextValue(String sequence, String owner) { - return "VALUES NEXTVAL FOR " + SQLHelper.getQualifiedName(owner, sequence); //$NON-NLS-1$ + return "VALUES NEXTVAL FOR " + getQualifiedName(owner, sequence); //$NON-NLS-1$ } public String getPrevValue(String sequence, String owner) { - return "VALUES PREVVAL FOR " + SQLHelper.getQualifiedName(owner, sequence); //$NON-NLS-1$ + return "VALUES PREVVAL FOR " + getQualifiedName(owner, sequence); //$NON-NLS-1$ + } + public Map getDefaultConnectionParameters() { + Map map = new HashMap(); + // the standard driver doesn't use these values, but other drivers might... + map.put("port", "50000"); + map.put("hostname", "localhost"); + return map; } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DatabaseAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DatabaseAdapter.java index 12bde71..1917e9f 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DatabaseAdapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/DatabaseAdapter.java @@ -1,8 +1,11 @@ package com.quantum.adapters; +import java.util.HashMap; +import java.util.Map; + import com.quantum.Messages; -import com.quantum.sql.SQLHelper; import com.quantum.util.StringUtil; +import com.quantum.util.sql.TypesHelper; /** * Abstract base class for all the adapter classes. Most functions can be redefined in @@ -127,7 +130,7 @@ public abstract class DatabaseAdapter { * @return */ protected boolean isTextType(int type, String typeString) { - return SQLHelper.isText(type); + return TypesHelper.isText(type); } @@ -212,4 +215,12 @@ public abstract class DatabaseAdapter { public String getType() { return this.type; } + + protected String getQualifiedName(String schema, String name) { + return (schema != null && schema.length() > 0) ? schema + "." + name : name; + } + + public Map getDefaultConnectionParameters() { + return new HashMap(); + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/InformixAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/InformixAdapter.java new file mode 100644 index 0000000..46862e0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/InformixAdapter.java @@ -0,0 +1,43 @@ +package com.quantum.adapters; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; + +/** + * @author BC Holmes + */ +public class InformixAdapter extends GenericAdapter { + + /** + * @param type + */ + protected InformixAdapter() { + super(AdapterFactory.INFORMIX); + } + + /** + * Get the default connection properties for Informix. These defaults assume that + * the database is located on the user's local machine. Informix doesn't allow + * for "localhost". + */ + public Map getDefaultConnectionParameters() { + Map map = new HashMap(); + map.put("hostname", getHostName()); + map.put("informixserver", "ol_" + getHostName()); + map.put("port", "1526"); + return map; + } + + /** + * @return + */ + private String getHostName() { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + return "localhost"; + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/MSSQLServerAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/MSSQLServerAdapter.java new file mode 100644 index 0000000..c38bf2c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/MSSQLServerAdapter.java @@ -0,0 +1,25 @@ +package com.quantum.adapters; + +import java.util.HashMap; +import java.util.Map; + + +/** + * @author BC + */ +public class MSSQLServerAdapter extends GenericAdapter { + + /** + * @param type + */ + protected MSSQLServerAdapter() { + super(AdapterFactory.MS_SQL_SERVER); + } + + public Map getDefaultConnectionParameters() { + Map map = new HashMap(); + map.put("port", "1433"); + map.put("hostname", "localhost"); + return map; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/MySQLAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/MySQLAdapter.java index 3478b3c..e4e1ad3 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/MySQLAdapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/MySQLAdapter.java @@ -1,8 +1,11 @@ package com.quantum.adapters; +import java.util.HashMap; +import java.util.Map; -public class MySQLAdapter extends DatabaseAdapter { + +public class MySQLAdapter extends GenericAdapter { /** * @param type @@ -10,7 +13,10 @@ public class MySQLAdapter extends DatabaseAdapter { protected MySQLAdapter() { super(AdapterFactory.MYSQL); } -// public String getShowTableQuery(String qualifier, boolean isDefault) { -// return "SHOW TABLES"; //$NON-NLS-1$ -// } + public Map getDefaultConnectionParameters() { + Map map = new HashMap(); + map.put("port", "3306"); + map.put("hostname", "localhost"); + return map; + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java index a01fbbf..78d2cce 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java @@ -1,7 +1,6 @@ package com.quantum.adapters; import com.quantum.Messages; -import com.quantum.sql.SQLHelper; import com.quantum.util.QuantumUtil; @@ -15,9 +14,9 @@ public class OracleAdapter extends DatabaseAdapter { } public String getPrevValue(String sequence, String owner) { return "SELECT LAST_NUMBER FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + owner + "' AND SEQUENCE_NAME = '" + sequence + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - } + } public String getNextValue(String sequence, String owner) { - return "SELECT " + SQLHelper.getQualifiedName(owner, sequence) + ".NEXTVAL FROM DUAL"; + return "SELECT " + getQualifiedName(owner, sequence) + ".NEXTVAL FROM DUAL"; } public String getCommentsQuery(String tableName, String column) { String query = "SELECT COMMENTS FROM ALL_COL_COMMENTS WHERE TABLE_NAME = '"; diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PointbaseAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PointbaseAdapter.java new file mode 100644 index 0000000..7f7a5c0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PointbaseAdapter.java @@ -0,0 +1,25 @@ +package com.quantum.adapters; + +import java.util.HashMap; +import java.util.Map; + + +/** + * @author BC + */ +public class PointbaseAdapter extends GenericAdapter { + + /** + * @param type + */ + protected PointbaseAdapter() { + super(AdapterFactory.POINTBASE); + } + + public Map getDefaultConnectionParameters() { + Map map = new HashMap(); + map.put("port", "9093"); + map.put("hostname", "localhost"); + return map; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PostgresAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PostgresAdapter.java index 3283163..90bf17f 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PostgresAdapter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/PostgresAdapter.java @@ -1,6 +1,8 @@ package com.quantum.adapters; -import com.quantum.sql.SQLHelper; +import java.util.HashMap; +import java.util.Map; + import com.quantum.util.QuantumUtil; import com.quantum.util.sql.TypesHelper; @@ -24,10 +26,10 @@ public class PostgresAdapter extends DatabaseAdapter { "and pg_namespace.nspname = '" + qualifier + "'"; } public String getNextValue(String sequence, String owner) { - return "SELECT NEXTVAL('" + SQLHelper.getQualifiedName(owner, sequence) + "')"; + return "SELECT NEXTVAL('" + getQualifiedName(owner, sequence) + "')"; } public String getPrevValue(String sequence, String owner) { - return "SELECT * FROM " + SQLHelper.getQualifiedName(owner, sequence); + return "SELECT * FROM " + getQualifiedName(owner, sequence); } /** @@ -51,6 +53,9 @@ public class PostgresAdapter extends DatabaseAdapter { return super.quote(string, type, typeString); } + public String getTableQuery(String table) { + return "SELECT OID, * FROM " + filterTableName(table); //$NON-NLS-1$ + } /** * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String) */ @@ -72,4 +77,10 @@ public class PostgresAdapter extends DatabaseAdapter { return "public"; } + public Map getDefaultConnectionParameters() { + Map map = new HashMap(); + map.put("port", "5432"); + map.put("hostname", "localhost"); + return map; + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLContentAssistProcessor.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLContentAssistProcessor.java index bf225cf..e90ed5c 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLContentAssistProcessor.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLContentAssistProcessor.java @@ -28,7 +28,7 @@ public class SQLContentAssistProcessor implements IContentAssistProcessor { ICompletionProposal proposal = new CompletionProposal("select", offset, 0, 6, ImageStore.getImage(ImageStore.TEMPLATE), "select - select columns from a table or view", null, null); -System.out.println(this.text); +//System.out.println(this.text); // complete a key word // complete a function diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLContentOutlinePage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLContentOutlinePage.java new file mode 100644 index 0000000..c32788e --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLContentOutlinePage.java @@ -0,0 +1,155 @@ +package com.quantum.editors; + +import java.util.List; +import java.util.StringTokenizer; + +import com.quantum.ImageStore; +import com.quantum.sql.parser.SQLParser; + +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.views.contentoutline.ContentOutlinePage; + + +/** + * @author BC + */ +public class SQLContentOutlinePage extends ContentOutlinePage { + + class LabelProviderImpl implements ILabelProvider { + public Image getImage(Object element) { + return ImageStore.getImage(ImageStore.SCRIPT); + } + + public String getText(Object element) { + if (element != null && element instanceof String) { + StringTokenizer tokenizer = new StringTokenizer((String) element); + + String token = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : ""; + + if ("select".equalsIgnoreCase(token) + || "update".equalsIgnoreCase(token) + || "insert".equalsIgnoreCase(token) + || "delete".equalsIgnoreCase(token) + || "grant".equalsIgnoreCase(token)) { + return token; + } else if (tokenizer.hasMoreTokens()) { + return token + " " + tokenizer.nextToken(); + } else { + return token; + } + } else { + return element == null ? "" : element.toString(); + } + } + + public void addListener(ILabelProviderListener listener) { + } + + public void dispose() { + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) { + } + } + + class ContentProviderImpl implements ITreeContentProvider { + + public Object[] getElements(Object inputElement) { + if (inputElement != null && inputElement instanceof IDocument) { + String text = ((IDocument) inputElement).get(); + List sql = SQLParser.parse(text); + return sql.toArray(); + } else { + return null; + } + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public Object[] getChildren(Object parentElement) { + return null; + } + + public Object getParent(Object element) { + return null; + } + + public boolean hasChildren(Object element) { + return false; + } + } + + private IDocumentListener listener; + + private final SQLDocumentProvider documentProvider; + private IEditorInput editorInput; + /** + * @param documentProvider + * @param editor + */ + public SQLContentOutlinePage(SQLDocumentProvider documentProvider, SQLEditor editor) { + this.documentProvider = documentProvider; + } + + + + public void createControl(Composite parent) { + super.createControl(parent); + + final TreeViewer treeViewer = getTreeViewer(); + + IDocument document = this.documentProvider.getDocument(this.editorInput); + if (document != null) { + treeViewer.setLabelProvider(new LabelProviderImpl()); + treeViewer.setContentProvider(new ContentProviderImpl()); + treeViewer.setInput(document); + + this.listener = new IDocumentListener() { + + public void documentAboutToBeChanged(DocumentEvent event) { + } + + public void documentChanged(DocumentEvent event) { + treeViewer.refresh(); + } + }; + document.addDocumentListener(this.listener); + } + } + /** + * @param editorInput + */ + public void setInput(IEditorInput editorInput) { + this.editorInput = editorInput; + } + + + public void dispose() { + if (this.listener != null) { + IDocument document = this.documentProvider.getDocument(this.editorInput); + if (document != null) { + document.removeDocumentListener(this.listener); + this.listener = null; + } + } + super.dispose(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLDocumentProvider.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLDocumentProvider.java index 1fab1c3..51c7d28 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLDocumentProvider.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLDocumentProvider.java @@ -13,6 +13,7 @@ public class SQLDocumentProvider extends FileDocumentProvider { } protected IDocument createDocument(Object element) throws CoreException { +//System.out.println("element: " + element.getClass().getName()); IDocument document = super.createDocument(element); if (document != null) { IDocumentPartitioner partitioner = diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLEditor.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLEditor.java index 1ceab17..a27f6ec 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLEditor.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLEditor.java @@ -12,17 +12,20 @@ import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; public class SQLEditor extends TextEditor { - SQLConfiguration config; + private SQLSourceViewerConfiguration config; private ColorManager colorManager; + private SQLContentOutlinePage outlinePage; /** * An editor capable of editing SQL scripts */ public SQLEditor() { super(); +//System.out.println("SQL Editor"); colorManager = new ColorManager(); - config = new SQLConfiguration(colorManager); + config = new SQLSourceViewerConfiguration(colorManager); config.loadPrefs(); setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore()); @@ -56,4 +59,18 @@ public class SQLEditor extends TextEditor { Color background = colorManager.getColor(SQLColorConstants.BACKGROUND); widget.setBackground(background); } + + public Object getAdapter(Class required) { + if (IContentOutlinePage.class.equals(required)) { + if (this.outlinePage == null) { + this.outlinePage= new SQLContentOutlinePage( + (SQLDocumentProvider) getDocumentProvider(), this); + if (getEditorInput() != null) + this.outlinePage.setInput(getEditorInput()); + } + return this.outlinePage; + } + return super.getAdapter(required); + } + } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLSourceViewerConfiguration.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLSourceViewerConfiguration.java new file mode 100644 index 0000000..8582103 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/editors/SQLSourceViewerConfiguration.java @@ -0,0 +1,110 @@ +package com.quantum.editors; + +import java.util.HashMap; + +import com.quantum.QuantumPlugin; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistant; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; + +public class SQLSourceViewerConfiguration extends SourceViewerConfiguration { + private PresentationReconciler reconciler = new PresentationReconciler(); + private ColorManager colorManager; + private HashMap cache = new HashMap(); + private boolean textBold = false; + private boolean keywordBold = true; + private boolean stringBold = false; + private boolean commentBold = false; + private boolean numericBold = false; + public SQLSourceViewerConfiguration(ColorManager colorManager) { + this.colorManager = colorManager; + } + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return new String[] { + IDocument.DEFAULT_CONTENT_TYPE, + SQLPartitionScanner.SQL_COMMENT, + SQLPartitionScanner.SQL_KEYWORD, + SQLPartitionScanner.SQL_IDENTIFIER}; + } + + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + initializeColors(); + return reconciler; + } + public void loadPrefs() { + IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore(); + textBold = store.getBoolean("quantum.text.bold"); //$NON-NLS-1$ + keywordBold = store.getBoolean("quantum.keyword.bold"); //$NON-NLS-1$ + stringBold = store.getBoolean("quantum.string.bold"); //$NON-NLS-1$ + commentBold = store.getBoolean("quantum.comment.bold"); //$NON-NLS-1$ + numericBold = store.getBoolean("quantum.numeric.bold"); //$NON-NLS-1$ + SQLColorConstants.BACKGROUND = PreferenceConverter.getColor(store, "quantum.background.color"); //$NON-NLS-1$ + SQLColorConstants.DEFAULT = PreferenceConverter.getColor(store, "quantum.text.color"); //$NON-NLS-1$ + SQLColorConstants.IDENTIFIER = PreferenceConverter.getColor(store, "quantum.text.color"); //$NON-NLS-1$ + SQLColorConstants.KEYWORD = PreferenceConverter.getColor(store, "quantum.keyword.color"); //$NON-NLS-1$ + SQLColorConstants.STRING = PreferenceConverter.getColor(store, "quantum.string.color"); //$NON-NLS-1$ + SQLColorConstants.COMMENT = PreferenceConverter.getColor(store, "quantum.comment.color"); //$NON-NLS-1$ + SQLColorConstants.NUMERIC = PreferenceConverter.getColor(store, "quantum.numeric.color"); //$NON-NLS-1$ + } + public void initializeColors() { + setDamageRepairer(getAttr(SQLColorConstants.KEYWORD, keywordBold), SQLPartitionScanner.SQL_KEYWORD); + setDamageRepairer(getAttr(SQLColorConstants.COMMENT, commentBold), SQLPartitionScanner.SQL_COMMENT); + setDamageRepairer(getAttr(SQLColorConstants.STRING, stringBold), SQLPartitionScanner.SQL_STRING); + setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), IDocument.DEFAULT_CONTENT_TYPE); + setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_SYMBOL); + setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_IDENTIFIER); + setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_SEPARATOR); + setDamageRepairer(getAttr(SQLColorConstants.NUMERIC, numericBold), SQLPartitionScanner.SQL_NUMERIC); + } + public TextAttribute getAttr(RGB color, boolean bold) { + colorManager.getColor(SQLColorConstants.BACKGROUND); + Color foreground = colorManager.getColor(color); + TextAttribute attr = new TextAttribute(foreground); + if (bold) { + return new TextAttribute(foreground, attr.getBackground(), SWT.BOLD); + } + return attr; + } + public void setDamageRepairer(TextAttribute attr, String token) { + NonRuleBasedDamagerRepairer ndr = (NonRuleBasedDamagerRepairer) cache.get(token); + if (ndr == null) { + ndr = + new NonRuleBasedDamagerRepairer(attr); + reconciler.setDamager(ndr, token); + reconciler.setRepairer(ndr, token); + cache.put(token, ndr); + } else { + ndr.setTextAttribute(attr); + } + } +// public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { +// ContentAssistant assistant = new ContentAssistant(); +// assistant.setContentAssistProcessor(new SQLContentAssistProcessor("default"), +// IDocument.DEFAULT_CONTENT_TYPE); +//// assistant.setContentAssistProcessor(new SQLContentAssistProcessor("comment"), +//// SQLPartitionScanner.SQL_COMMENT); +//// assistant.setContentAssistProcessor(new SQLContentAssistProcessor("keyword"), +//// SQLPartitionScanner.SQL_KEYWORD); +//// assistant.setContentAssistProcessor(new SQLContentAssistProcessor("identifier"), +//// SQLPartitionScanner.SQL_IDENTIFIER); +// +// // everybody else is doin' it... +// assistant.enableAutoActivation(true); +// assistant.setAutoActivationDelay(500); +// +// assistant.setProposalPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW); +// assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW); +// return assistant; +// } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Bookmark.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Bookmark.java index a4a50e8..4b42669 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Bookmark.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Bookmark.java @@ -76,6 +76,7 @@ public class Bookmark implements Displayable { setPromptForPassword(data.getPromptForPassword()); setAutoCommit(data.isAutoCommit()); setAutoCommitPreference(data.getAutoCommitPreference()); + setSchemaRule(data.getSchemaRule()); this.schemas.addAll(data.schemas); this.quickList = new Hashtable(data.quickList); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/BookmarkCollection.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/BookmarkCollection.java index 882f111..2f66b2e 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/BookmarkCollection.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/BookmarkCollection.java @@ -20,8 +20,10 @@ import org.w3c.dom.NodeList; import com.quantum.IQuantumConstants; import com.quantum.Messages; +import com.quantum.adapters.AdapterFactory; import com.quantum.model.xml.ModelToXMLConverter; import com.quantum.sql.metadata.MetaDataXMLInterface; +import com.quantum.util.JarUtil; /** * The collection of database bookmarks that the Quantum plug-in knows about. @@ -32,7 +34,9 @@ import com.quantum.sql.metadata.MetaDataXMLInterface; */ public class BookmarkCollection { - private static BookmarkCollection instance = new BookmarkCollection(); + +private static final String SUN_JDBC_ODBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver"; + private static BookmarkCollection instance = new BookmarkCollection(); private List bookmarks = new Vector(); private boolean changed = false; private PropertyChangeSupport support = new PropertyChangeSupport(this); @@ -86,7 +90,7 @@ public class BookmarkCollection { String driver = props.getProperty(i + ".driver"); //$NON-NLS-1$ String driverFile = props.getProperty(i + ".driverLocation"); //$NON-NLS-1$ String type = props.getProperty(i + ".type"); //$NON-NLS-1$ - this.drivers.add(new JDBCDriver(driver, driverFile, type)); + this.drivers.add(new JDBCDriver(driver, new String[] { driverFile }, type)); } if (overwrite) { this.bookmarks = newBookmarks; @@ -154,15 +158,49 @@ public class BookmarkCollection { for (int i = 0; i < nodes.getLength(); i++) { Element driver = (Element) nodes.item(i); - if (!"".equals(driver.getAttribute("type"))) { + List jarFileNames = new ArrayList(); + String jarFileName = driver.getAttribute("jarFileName"); + if (jarFileName != null && jarFileName.trim().length() > 0) { + jarFileNames.add(jarFileName); + } + NodeList jars = driver.getElementsByTagName("jar"); + for (int j = 0; j < jars.getLength(); j++) { + String fileName = ((Element) jars.item(j)).getAttribute("fileName"); + if (fileName != null && fileName.trim().length() > 0) { + jarFileNames.add(fileName); + } + } + + if (!isQuantum232Notation(driver)) { addDriver(new JDBCDriver( driver.getAttribute("className"), - driver.getAttribute("jarFileName"), + (String[]) jarFileNames.toArray(new String[jarFileNames.size()]), driver.getAttribute("type"), driver.getAttribute("name"), driver.getAttribute("version"))); } - + } + addStandardDrivers(); + } + + /** + * An earlier version of the Quantum XML format omitted the + * type. + * + * @param driver + * @return + */ + private boolean isQuantum232Notation(Element driver) { + return "".equals(driver.getAttribute("type")); + } + + /** + * + */ + private void addStandardDrivers() { + if (JarUtil.loadDriver(null, SUN_JDBC_ODBC_DRIVER) != null) { + addDriver(new JDBCDriver(SUN_JDBC_ODBC_DRIVER, new String[0], + AdapterFactory.JDBC_ODBC_BRIDGE)); } } @@ -204,10 +242,21 @@ public class BookmarkCollection { backwardCompatibility(bookmark, column); String driverClassName = MetaDataXMLInterface.getElementText(column,"driver"); //$NON-NLS-1$ - String driverFile = MetaDataXMLInterface.getElementText(column,"driverLocation"); //$NON-NLS-1$ + + List jarFiles = new ArrayList(); + NodeList driverLocations = column.getElementsByTagName("driverLocation"); + for (int j = 0, length = driverLocations == null + ? 0 : driverLocations.getLength(); j < length; j++) { + String jarFileName = MetaDataXMLInterface.extractText((Element) driverLocations.item(j), ""); + if (jarFileName != null && jarFileName.trim().length() > 0) { + jarFiles.add(jarFileName); + } + } String type = MetaDataXMLInterface.getElementText(column,"type"); //$NON-NLS-1$ - bookmark.setJDBCDriver(new JDBCDriver(driverClassName, driverFile, type)); + bookmark.setJDBCDriver(new JDBCDriver(driverClassName, + (String[]) jarFiles.toArray(new String[jarFiles.size()]), + type)); NodeList children = column.getElementsByTagName("Other_Schemas"); if (children.getLength() > 0) { @@ -336,7 +385,13 @@ public class BookmarkCollection { } public JDBCDriver[] getJDBCDrivers() { - return (JDBCDriver[]) this.drivers.toArray(new JDBCDriver[this.drivers.size()]); + if (this.drivers.isEmpty()) { + addStandardDrivers(); + } + + List list = new ArrayList(this.drivers); + Collections.sort(list); + return (JDBCDriver[]) list.toArray(new JDBCDriver[list.size()]); } /** * @return @@ -396,8 +451,8 @@ public class BookmarkCollection { * @param driver * @param driverFile */ - public JDBCDriver findDriver(String driverClassName, String driverFile, String type) { - JDBCDriver temp = new JDBCDriver(driverClassName, driverFile, type); + public JDBCDriver findDriver(String driverClassName, String[] driverFiles, String type) { + JDBCDriver temp = new JDBCDriver(driverClassName, driverFiles, type); return findDriver(temp); } @@ -420,5 +475,25 @@ public class BookmarkCollection { return result; } - + /** + * @param driver + */ + public boolean removeDriver(JDBCDriver driver) { + boolean found = false; + for (Iterator i = this.bookmarks.iterator(); + !found && driver != null && i.hasNext();) { + Bookmark bookmark = (Bookmark) i.next(); + found |= driver.equals(bookmark.getJDBCDriver()); + } + + if (!found && driver != null && !SUN_JDBC_ODBC_DRIVER.equals(driver.getClassName())) { + boolean deleted = this.drivers.remove(driver); + if (deleted) { + this.support.firePropertyChange("drivers", null, null); + } + return deleted; + } else { + return false; + } + } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ColumnImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ColumnImpl.java index 0775427..7944c2b 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ColumnImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ColumnImpl.java @@ -1,6 +1,6 @@ package com.quantum.model; -import com.quantum.sql.SQLHelper; +import com.quantum.util.sql.TypesHelper; /** * @author BC @@ -79,7 +79,7 @@ class ColumnImpl implements Column, Comparable { * @see com.quantum.model.Column#isNumeric() */ public boolean isNumeric() { - return SQLHelper.isNumeric(this.type); + return TypesHelper.isNumeric(this.type); } /** diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Database.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Database.java index 5637b55..cdc3501 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Database.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/Database.java @@ -12,14 +12,32 @@ import java.util.Set; import com.quantum.adapters.DatabaseAdapter; import com.quantum.sql.MultiSQLServer; -import com.quantum.sql.SQLResults; +import com.quantum.sql.SQLResultSetResults; /** * @author BC */ public class Database { - private DatabaseAdapter databaseAdapter; + private static final int TABLE_METADATA_TABLE_SCHEM = 2; + private static final int TABLE_METADATA_TABLE_NAME = 3; + + private static final int TABLE_TYPE_METADATA_TABLE_TYPE = 1; + + private static final int FOREIGN_KEY_METADATA_PKTABLE_SCHEM = 2; + private static final int FOREIGN_KEY_METADATA_PKTABLE_NAME = 3; + private static final int FOREIGN_KEY_METADATA_PKCOLUMN_NAME = 4; + private static final int FOREIGN_KEY_METADATA_FKTABLE_SCHEM = 6; + private static final int FOREIGN_KEY_METADATA_FKTABLE_NAME = 7; + private static final int FOREIGN_KEY_METADATA_FKCOLUMN_NAME = 8; + private static final int FOREIGN_KEY_METADATA_KEY_SEQ = 9; + private static final int FOREIGN_KEY_METADATA_DELETE_RULE = 11; + private static final int FOREIGN_KEY_METADATA_FK_NAME = 12; + + private static final int TYPE_INFO_METADATA_TYPE_NAME = 1; + private static final int TYPE_INFO_METADATA_DATA_TYPE = 2; + + private DatabaseAdapter databaseAdapter; private Bookmark bookmark; public Database(Bookmark bookmark) { @@ -80,7 +98,7 @@ public class Database { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTableTypes(); while (resultSet.next()) { - String type = resultSet.getString("TABLE_TYPE"); + String type = resultSet.getString(TABLE_TYPE_METADATA_TABLE_TYPE); if (type != null) { // Informix, in particular, pads this with extra spaces type = type.trim(); @@ -149,9 +167,10 @@ public class Database { String sql = getSQL(bookmark, type, schema); List list = new ArrayList(); - SQLResults results = null; + SQLResultSetResults results = null; if (sql != null) { - results = MultiSQLServer.getInstance().execute(connection, sql); + results = (SQLResultSetResults) MultiSQLServer.getInstance().execute( + bookmark, connection, sql, Integer.MAX_VALUE); for (int i = 1, size = (results == null) ? 0 : results.getRowCount(); i <= size; i++) { String schemaName = results.getColumnCount() == 1 ? schema.getName() : results.getElement(1, i).toString(); @@ -173,15 +192,16 @@ public class Database { DatabaseMetaData metaData = connection.getMetaData(); // getTables needs a null schema to get all the schemas. So we don't pass a "" schema, but a null one ResultSet set = null; - if (metaData.supportsSchemasInTableDefinitions()) + if (metaData.supportsSchemasInTableDefinitions()) { set = metaData.getTables(null, (schema != null) ? schema.getName() : null, "%", new String[] { type }); - else + } else { set = metaData.getTables(null, null, "%", new String[] { type }); + } while (set.next()) { - String tempSchema = set.getString("TABLE_SCHEM"); + String tempSchema = set.getString(TABLE_METADATA_TABLE_SCHEM); tempSchema = (tempSchema == null) ? "" : tempSchema.trim(); - String tableName = set.getString("TABLE_NAME"); + String tableName = set.getString(TABLE_METADATA_TABLE_NAME); tableName = (tableName == null) ? "" : tableName.trim(); if (tableName != null && tableName.length() > 0) { @@ -201,8 +221,8 @@ public class Database { ResultSet results = metaData.getTypeInfo(); try { while (results.next()) { - String name = results.getString("TYPE_NAME"); - int type = results.getInt("DATA_TYPE"); + String name = results.getString(TYPE_INFO_METADATA_TYPE_NAME); + int type = results.getInt(TYPE_INFO_METADATA_DATA_TYPE); list.add(new DataType(type, name)); } } finally { @@ -261,23 +281,23 @@ public class Database { int lowestKeySequence = Integer.MAX_VALUE; try { while (resultSet.next()) { - int keySequence = resultSet.getInt("KEY_SEQ"); + int keySequence = resultSet.getInt(FOREIGN_KEY_METADATA_KEY_SEQ); lowestKeySequence = Math.min(lowestKeySequence, keySequence); if (keySequence == lowestKeySequence || foreignKey == null) { foreignKey = new ForeignKeyImpl(); list.add(foreignKey); - foreignKey.setName(resultSet.getString("FK_NAME")); - foreignKey.setDeleteRule(resultSet.getShort("DELETE_RULE")); - foreignKey.setForeignEntitySchema(resultSet.getString("FKTABLE_SCHEM")); - foreignKey.setForeignEntityName(resultSet.getString("FKTABLE_NAME")); - foreignKey.setLocalEntitySchema(resultSet.getString("PKTABLE_SCHEM")); - foreignKey.setLocalEntityName(resultSet.getString("PKTABLE_NAME")); + foreignKey.setName(resultSet.getString(FOREIGN_KEY_METADATA_FK_NAME)); + foreignKey.setDeleteRule(resultSet.getShort(FOREIGN_KEY_METADATA_DELETE_RULE)); + foreignKey.setForeignEntitySchema(resultSet.getString(FOREIGN_KEY_METADATA_FKTABLE_SCHEM)); + foreignKey.setForeignEntityName(resultSet.getString(FOREIGN_KEY_METADATA_FKTABLE_NAME)); + foreignKey.setLocalEntitySchema(resultSet.getString(FOREIGN_KEY_METADATA_PKTABLE_SCHEM)); + foreignKey.setLocalEntityName(resultSet.getString(FOREIGN_KEY_METADATA_PKTABLE_NAME)); } foreignKey.addColumns( - resultSet.getString("PKCOLUMN_NAME"), - resultSet.getString("FKCOLUMN_NAME")); + resultSet.getString(FOREIGN_KEY_METADATA_PKCOLUMN_NAME), + resultSet.getString(FOREIGN_KEY_METADATA_FKCOLUMN_NAME)); } return (ForeignKey[]) list.toArray(new ForeignKey[list.size()]); } finally { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/DisplayableComparator.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/DisplayableComparator.java new file mode 100644 index 0000000..ab3f402 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/DisplayableComparator.java @@ -0,0 +1,43 @@ +package com.quantum.model; + +import java.util.Comparator; + + +/** + * This class is used to compare two displayable objects. + * + * @author BC Holmes + */ +public class DisplayableComparator implements Comparator { + + public int compare(Object arg0, Object arg1) { + if (arg0 == null && arg1 == null) { + return 0; + } else if (arg0 == null) { + return -1; + } else if (arg1 == null) { + return 1; + } else { + return compare((Displayable) arg0, (Displayable) arg1); + } + } + + /** + * @param displayable0 + * @param displayable1 + * @return + */ + private int compare(Displayable displayable0, Displayable displayable1) { + if (displayable0.getDisplayName() == null && displayable1.getDisplayName() == null) { + return 0; + } else if (displayable0.getDisplayName() == null) { + return -1; + } else if (displayable1.getDisplayName() == null) { + return 1; + } else { + return displayable0.getDisplayName().toLowerCase().compareTo( + displayable1.getDisplayName().toLowerCase()); + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityImpl.java index 8973ffd..f16a1e0 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/EntityImpl.java @@ -1,4 +1,4 @@ - package com.quantum.model; +package com.quantum.model; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -19,7 +19,27 @@ import com.quantum.adapters.DatabaseAdapter; * @author bcholmes */ abstract class EntityImpl implements Entity { - private String schema; + + // The JDBC-ODBC Driver is more happy if you look up metadata values + // using the column number than if you use the column name + + private static final int INDEX_METADATA_INDEX_NAME = 6; + private static final int INDEX_METADATA_COLUMN_NAME = 9; + private static final int INDEX_METADATA_ASC_OR_DESC = 10; + + private static final int PRIMARY_KEYS_METADATA_COLUMN_NAME = 4; + private static final int PRIMARY_KEYS_METADATA_KEY_SEQ = 5; + + private static final int COLUMN_METADATA_COLUMN_NAME = 4; + private static final int COLUMN_METATDATA_DATA_TYPE = 5; + private static final int COLUMN_METATDATA_TYPE_NAME = 6; + private static final int COLUMN_METADATA_COLUMN_SIZE = 7; + private static final int COLUMN_METADATA_DECIMAL_DIGITS = 9; + private static final int COLUMN_METADATA_REMARKS = 12; + private static final int COLUMN_METADATA_ORDINAL_POSITION = 17; + private static final int COLUMN_METADATA_IS_NULLABLE = 18; + + private String schema; private String name; private String type; private Bookmark bookmark; @@ -69,14 +89,17 @@ abstract class EntityImpl implements Entity { while (resultSet.next()) { ColumnImpl column = new ColumnImpl( this, - resultSet.getString("COLUMN_NAME"), - resultSet.getString("TYPE_NAME"), - resultSet.getInt("DATA_TYPE"), - resultSet.getInt("COLUMN_SIZE"), - resultSet.getInt("DECIMAL_DIGITS"), - "YES".equalsIgnoreCase(resultSet.getString("IS_NULLABLE")), - resultSet.getInt("ORDINAL_POSITION"), - getComments(resultSet.getString("REMARKS"),getQualifiedName(), resultSet.getString("COLUMN_NAME")) + resultSet.getString(COLUMN_METADATA_COLUMN_NAME), + resultSet.getString(COLUMN_METATDATA_TYPE_NAME), + resultSet.getInt(COLUMN_METATDATA_DATA_TYPE), + resultSet.getInt(COLUMN_METADATA_COLUMN_SIZE), + resultSet.getInt(COLUMN_METADATA_DECIMAL_DIGITS), + "YES".equalsIgnoreCase(resultSet.getString(COLUMN_METADATA_IS_NULLABLE)), + resultSet.getInt(COLUMN_METADATA_ORDINAL_POSITION), + getComments( + resultSet.getString(COLUMN_METADATA_REMARKS), + getQualifiedName(), + resultSet.getString(COLUMN_METADATA_COLUMN_NAME)) ); temp.put(column.getName(), column); } @@ -87,8 +110,8 @@ abstract class EntityImpl implements Entity { resultSet = metaData.getPrimaryKeys(null, getSchema(), getName()); try { while (resultSet.next()) { - String name = resultSet.getString("COLUMN_NAME"); - short keySequence = resultSet.getShort("KEY_SEQ"); + String name = resultSet.getString(PRIMARY_KEYS_METADATA_COLUMN_NAME); + short keySequence = resultSet.getShort(PRIMARY_KEYS_METADATA_KEY_SEQ); ColumnImpl column = (ColumnImpl) temp.get(name); if (column != null) { column.setPrimaryKeyOrder(keySequence); @@ -118,14 +141,24 @@ abstract class EntityImpl implements Entity { String comment = ""; try { Connection con = this.bookmark.getConnection(); - Statement stmt = con.createStatement(); DatabaseAdapter adapter = this.bookmark.getAdapter(); - if (adapter != null && stmt != null && adapter.getCommentsQuery(tableName, columnName) != null) { - - stmt.execute(adapter.getCommentsQuery(tableName, columnName)); - ResultSet set = stmt.getResultSet(); - if (set.next()) - comment = set.getString(1); + Statement stmt = con.createStatement(); + try { + if (adapter != null && stmt != null + && adapter.getCommentsQuery(tableName, columnName) != null) { + + stmt.execute(adapter.getCommentsQuery(tableName, columnName)); + ResultSet set = stmt.getResultSet(); + try { + if (set.next()) { + comment = set.getString(1); + } + } finally { + set.close(); + } + } + } finally { + stmt.close(); } } catch (NotConnectedException e) { } catch (SQLException e) { @@ -133,6 +166,7 @@ abstract class EntityImpl implements Entity { return comment; } + public Index[] getIndexes() { List indexList = new ArrayList(); @@ -143,14 +177,14 @@ abstract class EntityImpl implements Entity { ResultSet resultSet = metaData.getIndexInfo(null, getSchema(), getName(), false, false); while (resultSet.next()) { - String indexName = resultSet.getString("INDEX_NAME"); + String indexName = resultSet.getString(INDEX_METADATA_INDEX_NAME); IndexImpl index = (IndexImpl) temp.get(indexName); if (index == null) { index = new IndexImpl(this, indexName); temp.put(indexName, index); } - String columnName = resultSet.getString("COLUMN_NAME"); - String ascending = resultSet.getString("ASC_OR_DESC"); + String columnName = resultSet.getString(INDEX_METADATA_COLUMN_NAME); + String ascending = resultSet.getString(INDEX_METADATA_ASC_OR_DESC); index.addColumn(columnName, ascending == null ? null : (ascending.toUpperCase().startsWith("A") ? Boolean.TRUE : Boolean.FALSE)); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/JDBCDriver.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/JDBCDriver.java index 8f28a75..d768589 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/JDBCDriver.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/JDBCDriver.java @@ -2,32 +2,34 @@ package com.quantum.model; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.io.File; import java.sql.Driver; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; import com.quantum.util.JarUtil; +import com.quantum.util.StringArrayComparator; /** * @author BC */ -public class JDBCDriver { +public class JDBCDriver implements Comparable, Displayable { private String name; private String version; private String className; - private String jarFileName; + private List jarFileNames = Collections.synchronizedList(new ArrayList()); private String type; private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); /** * @param className * @param jarFileName */ - public JDBCDriver(String className, String jarFileName, String type) { - this(className, jarFileName, type, null, null); - } - /** - * - */ - public JDBCDriver() { + public JDBCDriver(String className, String[] jarFileNames, String type) { + this(className, jarFileNames, type, null, null); } /** * @param className @@ -35,12 +37,12 @@ public class JDBCDriver { * @param name * @param version */ - public JDBCDriver(String className, String jarFileName, String type, String name, String version) { + public JDBCDriver(String className, String[] jarFileNames, String type, String name, String version) { this.name = name; this.version = version; this.type = type; this.className = className; - this.jarFileName = jarFileName; + this.jarFileNames.addAll(Arrays.asList(jarFileNames)); } /** * @return Returns the className. @@ -61,17 +63,21 @@ public class JDBCDriver { /** * @return Returns the jarFileName. */ - public String getJarFileName() { - return this.jarFileName; + public String[] getJarFileNames() { + return (String[]) this.jarFileNames.toArray(new String[this.jarFileNames.size()]); } /** * @param jarFileName The jarFileName to set. */ - public void setJarFileName(String jarFileName) { - if (jarFileName != null && !jarFileName.equals(this.jarFileName)) { - String original = this.jarFileName; - this.jarFileName = jarFileName; - this.propertyChangeSupport.firePropertyChange("jarFileName", original, jarFileName); + public void setJarFileNames(String[] jarFileNames) { + StringArrayComparator comparator = new StringArrayComparator(); + if (comparator.compare( + (String[]) this.jarFileNames.toArray(new String[this.jarFileNames.size()]), + jarFileNames) != 0) { + String[] original = getJarFileNames(); + this.jarFileNames.clear(); + this.jarFileNames.addAll(Arrays.asList(jarFileNames)); + this.propertyChangeSupport.firePropertyChange("jarFileName", original, jarFileNames); } } /** @@ -115,23 +121,27 @@ public class JDBCDriver { } else if (getClass() != object.getClass()) { return false; } else { - JDBCDriver that = (JDBCDriver) object; - - if (this.className == null && that.className != null) { - return false; - } else if (this.className != null && !this.className.equals(that.className)) { - return false; - } else if (this.jarFileName == null && that.jarFileName != null) { - return false; - } else if (this.jarFileName != null && !this.jarFileName.equals(that.jarFileName)) { - return false; - } else if (this.type == null && that.type != null) { - return false; - } else if (this.type != null && !this.type.equals(that.type)) { - return false; - } else { - return true; - } + return equals((JDBCDriver) object); + } + } + /** + * @param that + * @return + */ + private boolean equals(JDBCDriver that) { + if (this.className == null && that.className != null) { + return false; + } else if (this.className != null && !this.className.equals(that.className)) { + return false; + } else if ((new StringArrayComparator()).compare( + this.getJarFileNames(), that.getJarFileNames()) != 0) { + return false; + } else if (this.type == null && that.type != null) { + return false; + } else if (this.type != null && !this.type.equals(that.type)) { + return false; + } else { + return true; } } public int hashCode() { @@ -139,8 +149,11 @@ public class JDBCDriver { if (this.className != null) { hashCode ^= this.className.hashCode(); } - if (this.jarFileName != null) { - hashCode ^= this.jarFileName.hashCode(); + for (Iterator i = this.jarFileNames.iterator(); i.hasNext();) { + Object jarFile = i.next(); + if (jarFile != null) { + hashCode ^= jarFile.hashCode(); + } } if (this.type != null) { hashCode ^= this.type.hashCode(); @@ -149,7 +162,7 @@ public class JDBCDriver { } public Driver getDriver() { - return JarUtil.loadDriver(getJarFileName(), getClassName()); + return JarUtil.loadDriver(getJarFileNames(), getClassName()); } /** * @param listener @@ -193,4 +206,28 @@ public class JDBCDriver { this.propertyChangeSupport.firePropertyChange("type", original, type); } } + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object object) { + return (new DisplayableComparator()).compare(this, object); + } + /* (non-Javadoc) + * @see com.quantum.model.Displayable#getDisplayName() + */ + public String getDisplayName() { + return getName(); + } + + public String getJarFilePath() { + StringBuffer buffer = new StringBuffer(); + for (Iterator i = this.jarFileNames.iterator(); i.hasNext();) { + String element = (String) i.next(); + buffer.append(element); + if (i.hasNext()) { + buffer.append(File.pathSeparator); + } + } + return buffer.toString(); + } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/TableImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/TableImpl.java index cddb0bc..87e5c85 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/TableImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/TableImpl.java @@ -3,7 +3,6 @@ package com.quantum.model; import java.sql.SQLException; import com.quantum.sql.MultiSQLServer; -import com.quantum.sql.SQLHelper; class TableImpl extends EntityImpl implements Table { @@ -14,7 +13,7 @@ class TableImpl extends EntityImpl implements Table { public Integer getSize() { Integer size = null; try { - size = new Integer(SQLHelper.getSize( + size = new Integer(MultiSQLServer.getInstance().getSize(getBookmark(), getBookmark().getConnection(), getQualifiedName(), getBookmark().getAdapter())); } catch (SQLException e) { @@ -25,6 +24,6 @@ class TableImpl extends EntityImpl implements Table { public void deleteAllRows() throws SQLException, ConnectionException { String sql = "DELETE FROM " + getQualifiedName(); - MultiSQLServer.getInstance().execute(getBookmark().getConnection(), sql); + MultiSQLServer.getInstance().execute(getBookmark(), getBookmark().getConnection(), sql); } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ViewImpl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ViewImpl.java index d63ca35..565c2a7 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ViewImpl.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/ViewImpl.java @@ -2,7 +2,7 @@ package com.quantum.model; import java.sql.SQLException; -import com.quantum.sql.SQLHelper; +import com.quantum.sql.MultiSQLServer; class ViewImpl extends EntityImpl implements View { @@ -13,7 +13,7 @@ class ViewImpl extends EntityImpl implements View { public Integer getSize() { Integer size = null; try { - size = new Integer(SQLHelper.getSize( + size = new Integer(MultiSQLServer.getInstance().getSize(getBookmark(), getBookmark().getConnection(), getQualifiedName(), getBookmark().getAdapter())); } catch (SQLException e) { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/xml/ModelToXMLConverter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/xml/ModelToXMLConverter.java index 5251fdc..075a1ad 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/xml/ModelToXMLConverter.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/model/xml/ModelToXMLConverter.java @@ -37,8 +37,17 @@ public class ModelToXMLConverter { driverNode.setAttribute("name", jdbcDriver.getName()); driverNode.setAttribute("version", jdbcDriver.getVersion()); driverNode.setAttribute("type", jdbcDriver.getType()); - driverNode.setAttribute("jarFileName", jdbcDriver.getJarFileName()); driverNode.setAttribute("className", jdbcDriver.getClassName()); + + String[] fileNames = jdbcDriver.getJarFileNames(); + for (int i = 0, length = fileNames == null ? 0 : fileNames.length; i < length; i++) { + if (fileNames[i] != null) { + Element fileName = document.createElement("jar"); + fileName.setAttribute("fileName", fileNames[i]); + driverNode.appendChild(fileName); + } + } + bookmarkRoot.appendChild(driverNode); } @@ -54,7 +63,10 @@ public class ModelToXMLConverter { MetaDataXMLInterface.createElementText(bookmark,"autoCommitPreference", b.getAutoCommitPreference()); //$NON-NLS-1$ MetaDataXMLInterface.createElementText(bookmark,"driver", b.getJDBCDriver().getClassName()); //$NON-NLS-1$ MetaDataXMLInterface.createElementText(bookmark,"type", b.getJDBCDriver().getType()); //$NON-NLS-1$ - MetaDataXMLInterface.createElementText(bookmark,"driverLocation", b.getJDBCDriver().getJarFileName()); //$NON-NLS-1$ + String[] fileNames = b.getJDBCDriver().getJarFileNames(); + for (int i = 0, length = fileNames == null ? 0 : fileNames.length; i < length; i++) { + MetaDataXMLInterface.createElementText(bookmark,"driverLocation", fileNames[i]); + } Element otherSchemas = (Element) bookmark.appendChild(document.createElement("Other_Schemas")); //$NON-NLS-1$ otherSchemas.setAttribute("schemaRule", b.useAllSchemas() diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/PHPMessages.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/PHPMessages.java new file mode 100644 index 0000000..3b2ce26 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/PHPMessages.java @@ -0,0 +1,41 @@ +package com.quantum.php; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class PHPMessages { + + private static final String BUNDLE_NAME = "com.quantum.php.PHPResources"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private PHPMessages() { + } + + public static String getString(Class resourceClass, String key) { + return getString( + createKey(resourceClass, key)); + } + + private static String createKey(Class resourceClass, String key) { + return resourceClass.getName() + (key.startsWith(".") ? key : "." + key); + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + + public static String getString(Class resourceClass, String key, Object[] arguments) { + return getString(createKey(resourceClass, key), arguments); + } + + public static String getString(String key, Object[] arguments) { + String string = getString(key); + return MessageFormat.format(string, arguments); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/PHPResources.properties b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/PHPResources.properties new file mode 100644 index 0000000..06eee1f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/PHPResources.properties @@ -0,0 +1,27 @@ +tableview.phpselect = PHP SELECT to Clipboard... +tableview.phpupdate = PHP UPDATE to Clipboard... +tableview.phpinsert = PHP INSERT to Clipboard... +tableview.phpdelete = PHP DELETE to Clipboard... +TableView.PHPSelectRow=PHP Select Row +TableView.PHPUpdateRow=PHP Update Row +TableView.PHPInsertRow=PHP Insert Row +TableView.PHPDeleteRow=PHP Delete Row + +PHPDeleteRowPage.ColumnName=Column Name +PHPDeleteRowPage.Value=Value +PHPDeleteRowPage.IncludeIn=Include in? +PHPDeleteRowPage.WhereClause=Where clause +PHPDeleteRowPage.UpdatingQuery=Updating query +PHPDeleteRowPage.WarningNoWhere=Warning: no \"where clause\" columns selected, all rows will be deleted +PHPInsertRowPage.ColumnName=Column Name +PHPInsertRowPage.Value=Value +PHPUpdateRowPage.ColumnName=Column Name +PHPUpdateRowPage.OldValue=Old Value +PHPUpdateRowPage.NewValue=New Value +PHPUpdateRowPage._13= +PHPUpdateRowPage.SetValue=Set Value +PHPSelectRowPage.ColumnName=Column Name +PHPSelectRowPage.VariableName=Variable Name +PHPSelectRowPage.NewValue=New Value +PHPSelectRowPage._13= +PHPSelectRowPage.SelectValue=Select Value \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLConnectionPreferencePage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/preferences/PHPSQLConnectionPreferencePage.java similarity index 98% rename from archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLConnectionPreferencePage.java rename to archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/preferences/PHPSQLConnectionPreferencePage.java index 99f7918..c9bc536 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLConnectionPreferencePage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/preferences/PHPSQLConnectionPreferencePage.java @@ -1,4 +1,4 @@ -package com.quantum.preferences.php; +package com.quantum.php.preferences; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.preference.StringFieldEditor; diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLTemplatesPreferencePage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/preferences/PHPSQLTemplatesPreferencePage.java similarity index 98% rename from archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLTemplatesPreferencePage.java rename to archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/preferences/PHPSQLTemplatesPreferencePage.java index 6854ee5..31b3d9e 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLTemplatesPreferencePage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/preferences/PHPSQLTemplatesPreferencePage.java @@ -1,4 +1,4 @@ -package com.quantum.preferences.php; +package com.quantum.php.preferences; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.preference.StringFieldEditor; diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPDeleteRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPDeleteRowPage.java new file mode 100644 index 0000000..8422670 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPDeleteRowPage.java @@ -0,0 +1,359 @@ +package com.quantum.php.wizards; + +import java.text.MessageFormat; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import com.quantum.QuantumPlugin; +import com.quantum.adapters.DatabaseAdapter; +import com.quantum.model.Bookmark; +import com.quantum.model.Column; +import com.quantum.model.Entity; +import com.quantum.php.PHPMessages; +import com.quantum.wizards.BaseSQLPage; +import com.quantum.wizards.SQLPage; + +public class PHPDeleteRowPage extends BaseSQLPage implements SQLPage { + String[] columnNames; + + Text[] values; + + Button[] whereValues; + + Text query; + + IPreferenceStore fStore; + + public PHPDeleteRowPage(String pageName) { + super(pageName); + } + + public void createControl(Composite parent) { + System.out.println("page create control"); //$NON-NLS-1$ + Composite container = new Composite(parent, SWT.V_SCROLL); + fStore = QuantumPlugin.getDefault().getPreferenceStore(); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + layout.numColumns = 3; + + Entity entity = this.results.getEntity(); + columnNames = this.results.getColumnNames(); + + values = new Text[columnNames.length]; + whereValues = new Button[columnNames.length]; + new Label(container, SWT.NULL).setText(PHPMessages + .getString("PHPDeleteRowPage.ColumnName")); //$NON-NLS-1$ + new Label(container, SWT.NULL).setText(PHPMessages + .getString("PHPDeleteRowPage.Value")); //$NON-NLS-1$ + new Label(container, SWT.NULL).setText(PHPMessages + .getString("PHPDeleteRowPage.IncludeIn")); //$NON-NLS-1$ + for (int i = 0; i < columnNames.length; i++) { + Label label = new Label(container, SWT.NULL); + label.setText(columnNames[i]); + values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); +// Object object = this.row == null ? null : this.row.get(i + 1); +// values[i].setText(object == null ? "" : '$'+columnNames[i]); //object.toString()); + values[i].setText('$'+columnNames[i]); //object.toString()); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = 150; + values[i].setLayoutData(gridData); + values[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + updateQuery(); + } + }); + + whereValues[i] = new Button(container, SWT.CHECK); + whereValues[i].setText(PHPMessages + .getString("PHPDeleteRowPage.WhereClause")); //$NON-NLS-1$ + // we check if it's a primary key to select it in the WHERE clause + Column column = getColumn(entity, columnNames[i]); + whereValues[i].setSelection(column == null ? false : column + .isPrimaryKey()); + whereValues[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + } + query = new Text(container, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP); + GridData gridData = new GridData(); + gridData.horizontalSpan = layout.numColumns; + gridData.verticalSpan = 3; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + query.setLayoutData(gridData); + + setControl(container); + updateQuery(); + + setPageComplete(true); + } + + public void updateQuery() { + System.out.println(PHPMessages.getString("PHPDeleteRowPage.UpdatingQuery")); //$NON-NLS-1$ + StringBuffer whereClause = new StringBuffer(); + Bookmark bookmark = this.results.getBookmark(); + Entity entity = this.results.getEntity(); + DatabaseAdapter adapter = bookmark.getAdapter(); + + int numSelected = 0; + for (int i = 0; i < columnNames.length; i++) { + if (whereValues[i].getSelection()) { + if (numSelected > 0) + whereClause.append(" AND "); //$NON-NLS-1$ + numSelected++; + whereClause.append("("); //$NON-NLS-1$ + whereClause.append(columnNames[i]); + whereClause.append(" = "); //$NON-NLS-1$ + appendColumn(whereClause, entity, columnNames[i], adapter, values[i] + .getText()); + whereClause.append(")"); //$NON-NLS-1$ + } + } + // String query = "DELETE FROM " + + // this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ + // if (numSelected > 0) { + // query += " WHERE " + whereClause.toString(); //$NON-NLS-1$ + // } + // if (numSelected > 0) { + // setMessage(""); //$NON-NLS-1$ + // } else { + // setMessage(PHPMessages.getString("PHPDeleteRowPage.WarningNoWhere")); + // //$NON-NLS-1$ + // } + String[] arguments = { this.results.getEntity().getQuotedTableName(), + whereClause.toString() }; + MessageFormat form = new MessageFormat(fStore + .getString("phpeclipse.sql.delete.template")); + + String query = form.format(arguments); + + if (numSelected > 0) { + setMessage(""); //$NON-NLS-1$ + } else { + setMessage(PHPMessages.getString("PHPDeleteRowPage.WarningNoWhere")); + } + + this.query.setText(query); + } + + protected String getQueryText() { + return query.getText(); + } + + /* + * (non-Javadoc) + * + * @see com.quantum.wizards.SQLPage#performFinish() + */ + public boolean performFinish() { + QuantumPlugin.getDefault().getSysClip().setContents( + new Object[] { query.getText() }, + new Transfer[] { TextTransfer.getInstance() }); + return true; + } +} +//import java.text.MessageFormat; +// +//import org.eclipse.jface.preference.IPreferenceStore; +//import org.eclipse.jface.wizard.WizardPage; +//import org.eclipse.swt.SWT; +//import org.eclipse.swt.dnd.TextTransfer; +//import org.eclipse.swt.dnd.Transfer; +//import org.eclipse.swt.events.ModifyEvent; +//import org.eclipse.swt.events.ModifyListener; +//import org.eclipse.swt.events.SelectionEvent; +//import org.eclipse.swt.events.SelectionListener; +//import org.eclipse.swt.layout.GridData; +//import org.eclipse.swt.layout.GridLayout; +//import org.eclipse.swt.widgets.Button; +//import org.eclipse.swt.widgets.Composite; +//import org.eclipse.swt.widgets.Label; +//import org.eclipse.swt.widgets.Text; +// +//import com.quantum.QuantumPlugin; +//import com.quantum.sql.TableRow; +//import com.quantum.wizards.BaseSQLPage; +//import com.quantum.wizards.SQLPage; +////import com.quantum.view.PHPSourceConsole; +////import com.quantum.view.tableview.TableAdapter; +// +//public class PHPDeleteRowPage extends BaseSQLPage implements SQLPage { +// TableRow row; +// String[] columnNames; +// Text[] values; +// Button[] whereValues; +// Label query; +// IPreferenceStore fStore; +// private final static boolean DEBUG = false; +// +// public PHPDeleteRowPage(String pageName) { +// super(pageName); +// } +// +//// public void init(TableRow row, TableAdapter adapter) { +//// this.row = row; +//// } +// +// protected String getQueryText() { +// return query.getText(); +// } +// +// public void createControl(Composite parent) { +// System.out.println("page create control"); +// fStore = QuantumPlugin.getDefault().getPreferenceStore(); +// Composite container = new Composite(parent, SWT.NULL); +// GridLayout layout = new GridLayout(); +// container.setLayout(layout); +// int layoutColumns = 3; +// layout.numColumns = layoutColumns; +// +// if (DEBUG) { +// if (row == null) { +// System.out.println("Row is null"); +// } +// if (row.getColumnNames() == null) { +// System.out.println("Columns are null"); +// } +// if (row.getTableData() == null) { +// System.out.println("Data is null"); +// } +// } +// columnNames = row.getColumnNames(); +// String[] data = row.getTableData(); +// if (DEBUG) { +// for (int i = 0; i < row.getColumnCount(); i++) { +// System.out.println("data = " + i + "=" + data[i]); +// System.out.println("column = " + i + "=" + columnNames[i]); +// } +// } +// values = new Text[row.getColumnCount()]; +// whereValues = new Button[row.getColumnCount()]; +// Label temp = new Label(container, SWT.NULL); +// temp.setText("Column Name"); +// temp = new Label(container, SWT.NULL); +// temp.setText("Value"); +// temp = new Label(container, SWT.NULL); +// temp.setText("Include in?"); +// for (int i = 0; i < row.getColumnCount(); i++) { +// Label label = new Label(container, SWT.NULL); +// label.setText(columnNames[i]); +// values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); +// GridData fullHorizontal = new GridData(); +// fullHorizontal.horizontalAlignment = GridData.FILL; +// values[i].setLayoutData(fullHorizontal); +// +// if (data[i] == null || data[i].equals("")) { +// values[i].setText('$' + columnNames[i]); +// } else { +// values[i].setText(data[i]); +// } +// +// values[i].addModifyListener(new ModifyListener() { +// public void modifyText(ModifyEvent e) { +// updateQuery(); +// } +// }); +// +// whereValues[i] = new Button(container, SWT.CHECK); +// whereValues[i].setText("Where clause"); +// whereValues[i].addSelectionListener(new SelectionListener() { +// public void widgetDefaultSelected(SelectionEvent e) { +// } +// public void widgetSelected(SelectionEvent e) { +// updateQuery(); +// } +// }); +// } +// query = new Label(container, SWT.WRAP); +// GridData gridData = new GridData(); +// gridData.horizontalSpan = layoutColumns; +// gridData.horizontalAlignment = GridData.FILL; +// gridData.verticalAlignment = GridData.FILL; +// gridData.grabExcessHorizontalSpace = true; +// gridData.grabExcessVerticalSpace = true; +// query.setLayoutData(gridData); +// +// setControl(container); +// updateQuery(); +// +// setPageComplete(true); +// } +// public void updateQuery() { +// if (DEBUG) { +// System.out.println("Updating delete query"); +// } +// StringBuffer whereClause = new StringBuffer(); +// int numSelected = 0; +// boolean first = false; +// for (int i = 0; i < columnNames.length; i++) { +// if (whereValues[i].getSelection()) { +// numSelected++; +// if (first) { +// whereClause.append(", "); +// } +// +// whereClause.append(columnNames[i]); +// whereClause.append(" = "); +// whereClause.append("'" + values[i].getText() + "'"); +// +// first = true; +// } +// } +// // if (whereClause.length() > 1) { +// // whereClause.deleteCharAt(whereClause.length() - 1); +// // whereClause.deleteCharAt(whereClause.length() - 1); +// // } +// +// String[] arguments = { row.getTable(), whereClause.toString()}; +// MessageFormat form = new +// MessageFormat(fStore.getString("phpeclipse.sql.delete.template")); +// +// String query = form.format(arguments); +// +// // String query = "$results = mysql_query(\"DELETE FROM " + row.getTable(); +// // if (numSelected > 0) { +// // query += " WHERE " + whereClause.toString() + "\");"; +// // } else { +// // query += "\");"; +// // } +// +// if (numSelected > 0) { +// setMessage(""); +// } else { +// setMessage("Warning: no \"where clause\" columns selected, all rows will be +// deleted"); +// } +// +// this.getControl().pack(); +// this.query.setText(query); +// } +// public boolean performFinish() { +//// PHPSourceConsole console = PHPSourceConsole.getInstance(); +//// console.clear(); +//// console.print(query.getText()); +// QuantumPlugin.getDefault().getSysClip().setContents( +// new Object[] { query.getText() }, +// new Transfer[] { TextTransfer.getInstance()}); +// return true; +// } +//} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPInsertRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPInsertRowPage.java new file mode 100644 index 0000000..13f8e2c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPInsertRowPage.java @@ -0,0 +1,290 @@ +package com.quantum.php.wizards; + +import java.text.MessageFormat; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import com.quantum.QuantumPlugin; +import com.quantum.adapters.DatabaseAdapter; +import com.quantum.model.Bookmark; +import com.quantum.model.Entity; +import com.quantum.php.PHPMessages; +import com.quantum.wizards.BaseSQLPage; +import com.quantum.wizards.SQLPage; + +public class PHPInsertRowPage extends BaseSQLPage implements SQLPage { + String[] columnNames; + Text[] values; + Label query; + int numColumns = 0; + private IPreferenceStore fStore; + + public PHPInsertRowPage(String pageName) { + super(pageName); + } + + public void createControl(Composite parent) { + System.out.println("page create control"); //$NON-NLS-1$ + fStore = QuantumPlugin.getDefault().getPreferenceStore(); + Composite container = new Composite(parent, SWT.V_SCROLL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + layout.numColumns = 2; + + columnNames = this.results.getColumnNames(); + values = new Text[columnNames.length]; + new Label(container, SWT.NULL).setText(PHPMessages.getString("PHPInsertRowPage.ColumnName")); //$NON-NLS-1$ + new Label(container, SWT.NULL).setText(PHPMessages.getString("PHPInsertRowPage.Value")); //$NON-NLS-1$ + for (int i = 0; i < columnNames.length; i++) { + Label label = new Label(container, SWT.NULL); + label.setText(columnNames[i]); + values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = 150; + values[i].setLayoutData(gridData); + + //values[i].setText(data[i]); + values[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + } + query = new Label(container, SWT.WRAP); + GridData gridData = new GridData(); + gridData.horizontalSpan = layout.numColumns; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + query.setLayoutData(gridData); + + setControl(container); + updateQuery(); + + setPageComplete(true); + } + public void updateQuery() { + System.out.println("Updating query"); //$NON-NLS-1$ + StringBuffer valuesClause = new StringBuffer(); + StringBuffer namesClause = new StringBuffer(); + Bookmark bookmark = this.results.getBookmark(); + Entity entity = this.results.getEntity(); + DatabaseAdapter adapter = bookmark.getAdapter(); + + numColumns = 0; + for (int i = 0; i < columnNames.length; i++) { + String name = columnNames[i]; + String value = values[i].getText(); + if (value.length() > 0) { + if (numColumns > 0) { + valuesClause.append(", "); //$NON-NLS-1$ + namesClause.append(", "); + } + appendColumn(valuesClause, entity, name, adapter, value); + namesClause.append(name); + numColumns++; + } + } + +// String query = "INSERT INTO " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ +// if (numColumns > 0) { +// query += " (" + namesClause + ")"; +// query += " VALUES " + "(" + valuesClause; //$NON-NLS-1$ +// query += " )"; //$NON-NLS-1$ +// } + String[] arguments = { this.results.getEntity().getQuotedTableName(), namesClause.toString(), valuesClause.toString()}; + MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template")); + + String query = form.format(arguments); + + // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " ("; + // query += fieldClause.toString() + ") "; + // query += " VALUES (" + valuesClause.toString(); + // query += ")\");"; + this.query.setText(query); + } + /* (non-Javadoc) + * @see com.quantum.wizards.BaseSQLPage#getQueryText() + */ + protected String getQueryText() { + return this.query.getText(); + } + /* (non-Javadoc) + * @see com.quantum.wizards.SQLPage#performFinish() + */ + public boolean performFinish() { + QuantumPlugin.getDefault().getSysClip().setContents( + new Object[] { query.getText() }, + new Transfer[] { TextTransfer.getInstance()}); + return true; + } +} + +//package com.quantum.php.wizards; +// +//import java.text.MessageFormat; +// +//import org.eclipse.jface.preference.IPreferenceStore; +//import org.eclipse.jface.wizard.WizardPage; +//import org.eclipse.swt.SWT; +//import org.eclipse.swt.dnd.TextTransfer; +//import org.eclipse.swt.dnd.Transfer; +//import org.eclipse.swt.events.ModifyEvent; +//import org.eclipse.swt.events.ModifyListener; +//import org.eclipse.swt.layout.GridData; +//import org.eclipse.swt.layout.GridLayout; +//import org.eclipse.swt.widgets.Composite; +//import org.eclipse.swt.widgets.Label; +//import org.eclipse.swt.widgets.Text; +// +//import com.quantum.QuantumPlugin; +//import com.quantum.sql.TableRow; +//import com.quantum.wizards.BaseSQLPage; +//import com.quantum.wizards.SQLPage; +////import com.quantum.view.PHPSourceConsole; +////import com.quantum.view.tableview.TableAdapter; +// +//public class PHPInsertRowPage extends BaseSQLPage implements SQLPage { +// TableRow row; +// String[] columnNames; +// Text[] values; +// Label query; +// private final static boolean DEBUG = false; +// private IPreferenceStore fStore; +// +// public PHPInsertRowPage(String pageName) { +// super(pageName); +// } +// +//// public void init(TableRow row, TableAdapter adapter) { +//// this.row = row; +//// } +// +// public void createControl(Composite parent) { +// if (DEBUG) { +// System.out.println("page create control"); +// } +// fStore = QuantumPlugin.getDefault().getPreferenceStore(); +// Composite container = new Composite(parent, SWT.NULL); +// GridLayout layout = new GridLayout(); +// container.setLayout(layout); +// int layoutColumns = 2; +// layout.numColumns = layoutColumns; +// +// if (DEBUG) { +// if (row == null) { +// System.out.println("Row is null"); +// } +// if (row.getColumnNames() == null) { +// System.out.println("Columns are null"); +// } +// if (row.getTableData() == null) { +// System.out.println("Data is null"); +// } +// } +// +// columnNames = row.getColumnNames(); +// String[] data = row.getTableData(); +// if (DEBUG) { +// for (int i = 0; i < row.getColumnCount(); i++) { +// System.out.println("data = " + i + "=" + data[i]); +// System.out.println("column = " + i + "=" + columnNames[i]); +// } +// } +// values = new Text[row.getColumnCount()]; +// Label temp = new Label(container, SWT.NULL); +// temp.setText("Column Name"); +// temp = new Label(container, SWT.NULL); +// temp.setText("Value"); +// for (int i = 0; i < row.getColumnCount(); i++) { +// Label label = new Label(container, SWT.NULL); +// label.setText(columnNames[i]); +// values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); +// GridData fullHorizontal = new GridData(); +// fullHorizontal.horizontalAlignment = GridData.FILL; +// values[i].setLayoutData(fullHorizontal); +// +// //values[i].setText(data[i]); +// values[i].addModifyListener(new ModifyListener() { +// public void modifyText(ModifyEvent e) { +// updateQuery(); +// } +// }); +// } +// query = new Label(container, SWT.WRAP); +// GridData gridData = new GridData(); +// gridData.horizontalSpan = layoutColumns; +// gridData.horizontalAlignment = GridData.FILL; +// gridData.verticalAlignment = GridData.FILL; +// gridData.grabExcessHorizontalSpace = true; +// gridData.grabExcessVerticalSpace = true; +// query.setLayoutData(gridData); +// +// setControl(container); +// updateQuery(); +// +// setPageComplete(true); +// } +// public void updateQuery() { +// if (DEBUG) { +// System.out.println("Updating insert query"); +// } +// StringBuffer fieldClause = new StringBuffer(); +// +// StringBuffer valuesClause = new StringBuffer(); +// String text; +// boolean first = false; +// for (int i = 0; i < columnNames.length; i++) { +// text = values[i].getText(); +// if (!text.equals("")) { +// if (first) { +// valuesClause.append(", "); +// fieldClause.append(", "); +// } +// valuesClause.append("'" + values[i].getText() + "'"); +// fieldClause.append(columnNames[i]); +// first = true; +// } +// } +// // if (valuesClause.length() > 1) { +// // valuesClause.deleteCharAt(valuesClause.length() - 1); +// // valuesClause.deleteCharAt(valuesClause.length() - 1); +// // } +// String[] arguments = { row.getTable(), fieldClause.toString(), valuesClause.toString()}; +// MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template")); +// +// String query = form.format(arguments); +// +// // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " ("; +// // query += fieldClause.toString() + ") "; +// // query += " VALUES (" + valuesClause.toString(); +// // query += ")\");"; +// this.query.setText(query); +// } +// public boolean performFinish() { +//// PHPSourceConsole console = PHPSourceConsole.getInstance(); +//// console.clear(); +//// console.print(query.getText()); +// QuantumPlugin.getDefault().getSysClip().setContents( +// new Object[] { query.getText() }, +// new Transfer[] { TextTransfer.getInstance()}); +// return true; +// } +// /* (non-Javadoc) +// * @see com.quantum.wizards.BaseSQLPage#getQueryText() +// */ +// protected String getQueryText() { +// return this.query.getText(); +// } +//} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPSelectRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPSelectRowPage.java new file mode 100644 index 0000000..3769350 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPSelectRowPage.java @@ -0,0 +1,210 @@ + +package com.quantum.php.wizards; + +import java.text.MessageFormat; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import com.quantum.QuantumPlugin; +import com.quantum.adapters.DatabaseAdapter; +import com.quantum.model.Bookmark; +import com.quantum.model.Column; +import com.quantum.model.Entity; +import com.quantum.php.PHPMessages; +import com.quantum.wizards.BaseSQLPage; +import com.quantum.wizards.SQLPage; + +public class PHPSelectRowPage extends BaseSQLPage implements SQLPage { + String[] columnNames; + + Text[] variableNames; + + // Text[] newValues; + Button[] primaryKeys; + + Button[] selectValues; + + Label query; + + IPreferenceStore fStore; + + public PHPSelectRowPage(String pageName) { + super(pageName); + } + + public void createControl(Composite parent) { + System.out.println("page create control"); //$NON-NLS-1$ + Composite container = new Composite(parent, SWT.V_SCROLL); + fStore = QuantumPlugin.getDefault().getPreferenceStore(); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + Entity entity = this.results.getEntity(); + + int layoutColumns = 4; + layout.numColumns = layoutColumns; + + columnNames = this.results.getColumnNames(); + variableNames = new Text[columnNames.length]; + // newValues = new Text[columnNames.length]; + primaryKeys = new Button[columnNames.length]; + selectValues = new Button[columnNames.length]; + Label temp = new Label(container, SWT.NULL); + temp.setText(PHPMessages.getString("PHPSelectRowPage.ColumnName")); //$NON-NLS-1$ + temp = new Label(container, SWT.NULL); + temp.setText(PHPMessages.getString("PHPSelectRowPage.VariableName")); //$NON-NLS-1$ + temp = new Label(container, SWT.NULL); + temp.setText(""); //$NON-NLS-1$ + // temp = new Label(container, SWT.NULL); + // temp.setText(PHPMessages.getString("PHPSelectRowPage.NewValue")); + // //$NON-NLS-1$ + temp = new Label(container, SWT.NULL); + temp.setText(PHPMessages.getString("PHPSelectRowPage._13")); //$NON-NLS-1$ + for (int i = 0; i < columnNames.length; i++) { + Label label = new Label(container, SWT.NULL); + label.setText(columnNames[i]); + variableNames[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData gridData = new GridData(); + gridData.widthHint = 100; + variableNames[i].setLayoutData(gridData); + Object data = this.row == null ? null : this.row.get(i + 1); + variableNames[i].setText(data == null ? "" : '$' + columnNames[i]);//data.toString()); + variableNames[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + primaryKeys[i] = new Button(container, SWT.CHECK); + primaryKeys[i].setText("Where"); //$NON-NLS-1$ + Column column = (entity == null) ? null : getColumn(entity, + columnNames[i]); + if (column != null && column.isPrimaryKey()) + primaryKeys[i].setSelection(true); + primaryKeys[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + // newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + // newValues[i].setText(data == null ? "" : '$'+data.toString()); + // gridData = new GridData(); + // gridData.widthHint = 100; + // newValues[i].setLayoutData(gridData); + // newValues[i].addModifyListener(new ModifyListener() { + // public void modifyText(ModifyEvent e) { + // updateQuery(); + // } + // }); + selectValues[i] = new Button(container, SWT.CHECK); + selectValues[i].setText(PHPMessages + .getString("PHPSelectRowPage.SelectValue")); //$NON-NLS-1$ + selectValues[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + } + query = new Label(container, SWT.WRAP | SWT.V_SCROLL); + GridData gridData = new GridData(); + gridData.horizontalSpan = layoutColumns; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + query.setLayoutData(gridData); + + setControl(container); + updateQuery(); + + setPageComplete(true); + } + + public void updateQuery() { + System.out.println("Selecting query"); //$NON-NLS-1$ + StringBuffer setClause = new StringBuffer(); + StringBuffer whereClause = new StringBuffer(); + Bookmark bookmark = this.results.getBookmark(); + Entity entity = this.results.getEntity(); + DatabaseAdapter adapter = bookmark.getAdapter(); + + int numValuesSet = 0; + int numValuesWhere = 0; + for (int i = 0; i < columnNames.length; i++) { + if (primaryKeys[i].getSelection()) { + String value = variableNames[i].getText(); + if (numValuesWhere > 0) + whereClause.append(" AND "); //$NON-NLS-1$ + whereClause.append("("); //$NON-NLS-1$ + whereClause.append(columnNames[i]); + whereClause.append(" = "); //$NON-NLS-1$ + appendColumn(whereClause, entity, columnNames[i], adapter, value); + whereClause.append(")"); //$NON-NLS-1$ + numValuesWhere++; + } + if (selectValues[i].getSelection()) { + // String value = newValues[i].getText(); + if (numValuesSet > 0) + setClause.append(", "); //$NON-NLS-1$ + setClause.append(columnNames[i]); + // setClause.append(" = "); //$NON-NLS-1$ + // appendColumn(setClause, entity, columnNames[i], adapter, value); + numValuesSet++; + } + } + // String query = "UPDATE " + this.results.getEntity().getQuotedTableName(); + // //$NON-NLS-1$ + // query += " SET " + setClause.toString(); //$NON-NLS-1$ + // query += " WHERE " + whereClause.toString(); //$NON-NLS-1$ + // + String[] arguments = { setClause.toString(), + this.results.getEntity().getQuotedTableName(), whereClause.toString() }; + MessageFormat form = new MessageFormat(fStore + .getString("phpeclipse.sql.select.template")); + + String query = form.format(arguments); + // String query = "$results = mysql_query(\"SELECT " + setClause.toString(); + // query += " FROM " + row.getTable(); + // query += " WHERE " + whereClause.toString() + "\");"; + this.query.setText(query); + + } + + /* + * (non-Javadoc) + * + * @see com.quantum.wizards.BaseSQLPage#getQueryText() + */ + protected String getQueryText() { + return query.getText(); + } + + /* + * (non-Javadoc) + * + * @see com.quantum.wizards.SQLPage#performFinish() + */ + public boolean performFinish() { + QuantumPlugin.getDefault().getSysClip().setContents( + new Object[] { query.getText() }, + new Transfer[] { TextTransfer.getInstance() }); + return true; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPUpdateRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPUpdateRowPage.java new file mode 100644 index 0000000..81be825 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/php/wizards/PHPUpdateRowPage.java @@ -0,0 +1,185 @@ +package com.quantum.php.wizards; + +import java.text.MessageFormat; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import com.quantum.QuantumPlugin; +import com.quantum.adapters.DatabaseAdapter; +import com.quantum.model.Bookmark; +import com.quantum.model.Column; +import com.quantum.model.Entity; +import com.quantum.php.PHPMessages; +import com.quantum.wizards.BaseSQLPage; +import com.quantum.wizards.SQLPage; + +public class PHPUpdateRowPage extends BaseSQLPage implements SQLPage { + String[] columnNames; + Text[] oldValues; + Text[] newValues; + Button[] primaryKeys; + Button[] setValues; + Label query; + IPreferenceStore fStore; + public PHPUpdateRowPage(String pageName) { + super(pageName); + } + + public void createControl(Composite parent) { + System.out.println("page create control"); //$NON-NLS-1$ + Composite container = new Composite(parent, SWT.V_SCROLL); + fStore = QuantumPlugin.getDefault().getPreferenceStore(); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + Entity entity = this.results.getEntity(); + + int layoutColumns = 5; + layout.numColumns = layoutColumns; + + columnNames = this.results.getColumnNames(); + oldValues = new Text[columnNames.length]; + newValues = new Text[columnNames.length]; + primaryKeys = new Button[columnNames.length]; + setValues = new Button[columnNames.length]; + Label temp = new Label(container, SWT.NULL); + temp.setText(PHPMessages.getString("PHPUpdateRowPage.ColumnName")); //$NON-NLS-1$ + temp = new Label(container, SWT.NULL); + temp.setText(PHPMessages.getString("PHPUpdateRowPage.OldValue")); //$NON-NLS-1$ + temp = new Label(container, SWT.NULL); + temp.setText(""); //$NON-NLS-1$ + temp = new Label(container, SWT.NULL); + temp.setText(PHPMessages.getString("PHPUpdateRowPage.NewValue")); //$NON-NLS-1$ + temp = new Label(container, SWT.NULL); + temp.setText(PHPMessages.getString("PHPUpdateRowPage._13")); //$NON-NLS-1$ + for (int i = 0; i < columnNames.length; i++) { + Label label = new Label(container, SWT.NULL); + label.setText(columnNames[i]); + oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData gridData = new GridData(); + gridData.widthHint = 100; + oldValues[i].setLayoutData(gridData); + Object data = this.row == null ? null : this.row.get(i+1); + oldValues[i].setText(data == null ? "" : '$'+columnNames[i]); + oldValues[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + primaryKeys[i] = new Button(container, SWT.CHECK); + primaryKeys[i].setText("Where"); //$NON-NLS-1$ + Column column = (entity == null) ? null : getColumn(entity, columnNames[i]); + if (column != null && column.isPrimaryKey()) + primaryKeys[i].setSelection(true); + primaryKeys[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + newValues[i].setText(data == null ? "" : '$'+columnNames[i]); + gridData = new GridData(); + gridData.widthHint = 100; + newValues[i].setLayoutData(gridData); + newValues[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + setValues[i] = new Button(container, SWT.CHECK); + setValues[i].setText(PHPMessages.getString("PHPUpdateRowPage.SetValue")); //$NON-NLS-1$ + setValues[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + } + query = new Label(container, SWT.WRAP | SWT.V_SCROLL); + GridData gridData = new GridData(); + gridData.horizontalSpan = layoutColumns; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + query.setLayoutData(gridData); + + setControl(container); + updateQuery(); + + setPageComplete(true); + } + public void updateQuery() { + System.out.println("Updating query"); //$NON-NLS-1$ + StringBuffer setClause = new StringBuffer(); + StringBuffer whereClause = new StringBuffer(); + Bookmark bookmark = this.results.getBookmark(); + Entity entity = this.results.getEntity(); + DatabaseAdapter adapter = bookmark.getAdapter(); + + int numValuesSet = 0; + int numValuesWhere = 0; + for (int i = 0; i < columnNames.length; i++) { + if (primaryKeys[i].getSelection()) { + String value = oldValues[i].getText(); + if (numValuesWhere > 0) whereClause.append(" AND "); //$NON-NLS-1$ + whereClause.append("("); //$NON-NLS-1$ + whereClause.append(columnNames[i]); + whereClause.append(" = "); //$NON-NLS-1$ + appendColumn(whereClause, entity, columnNames[i], adapter, value); + whereClause.append(")"); //$NON-NLS-1$ + numValuesWhere++; + } + if (setValues[i].getSelection()) { + String value = newValues[i].getText(); + if (numValuesSet > 0) setClause.append(", "); //$NON-NLS-1$ + setClause.append(columnNames[i]); + setClause.append(" = "); //$NON-NLS-1$ + appendColumn(setClause, entity, columnNames[i], adapter, value); + numValuesSet++; + } + } +// String query = "UPDATE " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ +// query += " SET " + setClause.toString(); //$NON-NLS-1$ +// query += " WHERE " + whereClause.toString(); //$NON-NLS-1$ +// + String[] arguments = { this.results.getEntity().getQuotedTableName(), setClause.toString(), whereClause.toString()}; + MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.update.template")); + + String query = form.format(arguments); + this.query.setText(query); + + } + + /* (non-Javadoc) + * @see com.quantum.wizards.BaseSQLPage#getQueryText() + */ + protected String getQueryText() { + return query.getText(); + } + + /* (non-Javadoc) + * @see com.quantum.wizards.SQLPage#performFinish() + */ + public boolean performFinish() { + QuantumPlugin.getDefault().getSysClip().setContents( + new Object[] { query.getText() }, + new Transfer[] { TextTransfer.getInstance()}); + return true; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/SQLEditorPreferences.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/SQLEditorPreferences.java index b1697ba..daf8164 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/SQLEditorPreferences.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/SQLEditorPreferences.java @@ -11,6 +11,7 @@ import org.eclipse.jface.preference.ColorFieldEditor; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@ -150,7 +151,8 @@ public class SQLEditorPreferences extends PreferencePage public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { - fontData = null; + FontData[] temp = JFaceResources.getTextFont().getFontData(); + fontData = temp == null || temp.length == 0 ? null : temp[0]; updateFontDisplay(); } }); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/properties/BookmarkPropertyPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/properties/BookmarkPropertyPage.java index b4d53ea..6559347 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/properties/BookmarkPropertyPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/properties/BookmarkPropertyPage.java @@ -1,8 +1,22 @@ package com.quantum.properties; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import com.quantum.IQuantumConstants; +import com.quantum.adapters.AdapterFactory; +import com.quantum.model.Bookmark; +import com.quantum.model.BookmarkHolder; +import com.quantum.model.JDBCDriver; +import com.quantum.wizards.BookmarkWizard; +import com.quantum.wizards.JDBCDriverSelectionWizardPage; + +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -15,15 +29,38 @@ import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.PropertyPage; -import com.quantum.IQuantumConstants; -import com.quantum.adapters.AdapterFactory; -import com.quantum.adapters.DatabaseAdapter; -import com.quantum.model.Bookmark; -import com.quantum.model.BookmarkCollection; -import com.quantum.model.BookmarkHolder; -import com.quantum.model.JDBCDriver; - public class BookmarkPropertyPage extends PropertyPage { + + class ChooseDriverWizard extends Wizard { + + private JDBCDriver selection; + private JDBCDriverSelectionWizardPage page; + private PropertyChangeListener listener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + if ("driver".equals(event.getPropertyName())) { + ChooseDriverWizard.this.selection = (JDBCDriver) event.getNewValue(); + } + } + }; + + public void addPages() { + this.page = new JDBCDriverSelectionWizardPage("page1"); + this.page.addPropertyChangeListener(this.listener); + addPage(this.page); + } + + public void dispose() { + this.page.removePropertyChangeListener(this.listener); + super.dispose(); + } + public boolean performFinish() { + BookmarkPropertyPage.this.driver = this.selection; + BookmarkPropertyPage.this.setDriverDetails(); + return true; + } + + } + private Text password; private Text userid; @@ -32,10 +69,12 @@ public class BookmarkPropertyPage extends PropertyPage { private Text jdbcURL; private Text driverName; private Text driverPath; + private Text driverClassName; + private Text driverVersion; + private Text type; - private Combo type; private Combo autoCommit; - private DatabaseAdapter[] adapters = AdapterFactory.getInstance().getDriverList(); + private JDBCDriver driver; protected Control createContents(Composite parent) { @@ -64,7 +103,7 @@ public class BookmarkPropertyPage extends PropertyPage { data.horizontalSpan = 2; tabFolder.setLayoutData(data); - createUserTab(tabFolder); + createConnectionTab(tabFolder); createDriverTab(tabFolder); createOptionsTab(tabFolder); @@ -86,46 +125,67 @@ public class BookmarkPropertyPage extends PropertyPage { GridLayout layout = new GridLayout(); layout.numColumns = 2; composite.setLayout(layout); - GridData data = new GridData(GridData.FILL); - data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = true; - composite.setLayoutData(data); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Label label = new Label(composite, SWT.NONE); label.setText("Driver Name:"); this.driverName = new Text(composite, SWT.BORDER); - data = new GridData(GridData.FILL); - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - this.driverName.setLayoutData(data); + this.driverName.setLayoutData(createFillHorizontalGridData()); + this.driverName.setEditable(false); label = new Label(composite, SWT.NONE); - label.setText("Driver Location:"); + label.setText("Driver Class Name:"); + + this.driverClassName = new Text(composite, SWT.BORDER); + this.driverClassName.setLayoutData(createFillHorizontalGridData()); + this.driverClassName.setEditable(false); + + label = new Label(composite, SWT.NONE); + label.setText("Driver Version:"); + + this.driverVersion = new Text(composite, SWT.BORDER); + this.driverVersion.setLayoutData(createFillHorizontalGridData()); + this.driverVersion.setEditable(false); + + label = new Label(composite, SWT.NONE); + label.setText("Driver Path:"); this.driverPath = new Text(composite, SWT.BORDER); - data = new GridData(GridData.FILL); - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - this.driverPath.setLayoutData(data); + this.driverPath.setLayoutData(createFillHorizontalGridData()); + this.driverPath.setEditable(false); label = new Label(composite, SWT.NULL); label.setText("Type:"); - this.type = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY); - String adapterNames[] = new String[adapters.length]; - for (int i = 0; i < adapters.length; i++) { - adapterNames[i] = adapters[i].getDisplayName(); - } - this.type.setItems(adapterNames); - - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - this.type.setLayoutData(data); + this.type = new Text(composite, SWT.BORDER); + this.type.setLayoutData(createFillHorizontalGridData()); + this.type.setEditable(false); driverTab.setControl(composite); + + Button button = new Button(composite, SWT.PUSH); + button.setText("Change"); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END); + data.horizontalSpan = 2; + button.setLayoutData(data); + button.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent event) { + WizardDialog dialog = + new WizardDialog(getShell(), new ChooseDriverWizard()); + dialog.open(); + } + public void widgetDefaultSelected(SelectionEvent event) { + } + }); + } + + private GridData createFillHorizontalGridData() { + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = 200; + return data; } - private void createUserTab(TabFolder tabFolder) { + private void createConnectionTab(TabFolder tabFolder) { TabItem userTab = new TabItem(tabFolder, SWT.NONE); userTab.setText("Connection"); @@ -218,7 +278,6 @@ public class BookmarkPropertyPage extends PropertyPage { this.autoCommit.setLayoutData(data); optionsTab.setControl(composite); - } @@ -235,12 +294,9 @@ public class BookmarkPropertyPage extends PropertyPage { } else { bookmark.setPassword(this.password.getText()); } - - int index = this.type.getSelectionIndex(); bookmark.setConnect(this.jdbcURL.getText()); - JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver( - this.driverName.getText(), this.driverPath.getText(), this.adapters[index].getType()); - bookmark.setJDBCDriver(jdbcDriver); + + bookmark.setJDBCDriver(this.driver); if (this.autoCommit.getSelectionIndex() >= 0) bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex())); return super.performOk(); @@ -257,19 +313,12 @@ public class BookmarkPropertyPage extends PropertyPage { String password = bookmark.getPassword(); this.password.setText(password == null ? "" : password); this.userid.setText(bookmark.getUsername()); + this.jdbcURL.setText(bookmark.getConnect()); - this.type.select(0); - boolean done = false; - for (int i = 0, - length = (adapters == null) ? 0 : adapters.length; - !done && i < length; - i++) { - if (bookmark.getJDBCDriver().getType() != null && - bookmark.getJDBCDriver().getType().equals(adapters[i].getType())) { - this.type.select(i); - done = true; - } - } + this.driver = bookmark.getJDBCDriver(); + + setDriverDetails(); + if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitTrue)) this.autoCommit.select(0); else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitFalse)) @@ -277,8 +326,18 @@ public class BookmarkPropertyPage extends PropertyPage { else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitSaved)) this.autoCommit.select(2); - this.driverName.setText(bookmark.getJDBCDriver().getClassName()); - this.jdbcURL.setText(bookmark.getConnect()); - this.driverPath.setText(bookmark.getJDBCDriver().getJarFileName()); } + + /** + * + */ + private void setDriverDetails() { + this.driverName.setText(this.driver.getName()); + this.driverClassName.setText(this.driver.getClassName()); + String path = this.driver.getJarFilePath(); + this.driverPath.setText(path == null ? "" : path); + String version = this.driver.getVersion(); + this.driverVersion.setText(version == null ? "" : version); + this.type.setText(AdapterFactory.getInstance().getAdapter(this.driver.getType()).getDisplayName()); + } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/MultiSQLServer.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/MultiSQLServer.java index 97c1cc1..f5eb590 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/MultiSQLServer.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/MultiSQLServer.java @@ -1,29 +1,21 @@ package com.quantum.sql; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.Reader; -import java.io.UnsupportedEncodingException; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.Driver; import java.sql.ResultSet; -import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; -import java.util.Vector; +import com.quantum.Messages; +import com.quantum.adapters.DatabaseAdapter; import com.quantum.model.Bookmark; import com.quantum.model.ConnectionException; import com.quantum.model.Entity; import com.quantum.model.JDBCDriver; import com.quantum.model.PasswordFinder; -import com.quantum.sql.metadata.MetaDataJDBCInterface; -import com.quantum.sql.metadata.ObjectMetaData; import com.quantum.view.LogProxy; -import com.quantum.view.bookmark.EntityNode; -import com.quantum.view.bookmark.TreeNode; /** @@ -31,11 +23,9 @@ import com.quantum.view.bookmark.TreeNode; * Use MultiSQLServer.getInstance() to get the object. */ public class MultiSQLServer implements ConnectionEstablisher { - private static final int STREAM = 1024 * 2; public static final String USERNAME = "user"; //$NON-NLS-1$ public static final String PASSWORD = "password"; //$NON-NLS-1$ private static MultiSQLServer instance = null; - boolean running = true; private MultiSQLServer() { } @@ -46,21 +36,23 @@ public class MultiSQLServer implements ConnectionEstablisher { return instance; } - public void commit(Connection con) { + public void commit(Connection con) throws SQLException { LogProxy log = LogProxy.getInstance(); try { con.commit(); } catch (SQLException e) { log.addText(LogProxy.ERROR, "Error commiting: " + e, e); //$NON-NLS-1$ + throw e; } } - public void rollback(Connection con) { + public void rollback(Connection con) throws SQLException { LogProxy log = LogProxy.getInstance(); try { con.rollback(); } catch (SQLException e) { log.addText(LogProxy.ERROR, "Error rolling back: " + e, e); //$NON-NLS-1$ + throw e; } } @@ -128,12 +120,11 @@ public class MultiSQLServer implements ConnectionEstablisher { try { JDBCDriver jdbcDriver = bookmark.getJDBCDriver(); Driver driver = jdbcDriver.getDriver(); - Connection connection = null; if (driver != null) { Properties props = new Properties(); props.put(USERNAME, bookmark.getUsername()); props.put(PASSWORD, password); - connection = + Connection connection = driver.connect(bookmark.getConnect(), props); if (connection == null) { throw new ConnectionException("Error: Driver returned a null connection: " + bookmark.toString()); //$NON-NLS-1$ @@ -144,252 +135,94 @@ public class MultiSQLServer implements ConnectionEstablisher { jdbcDriver.setVersion(metaData.getDriverVersion()); log.addText(LogProxy.RESULTS, "Connected to: " + bookmark.getName()); //$NON-NLS-1$ System.out.println("Connected"); //$NON-NLS-1$ + return connection; + } else { + throw new ConnectionException(Messages.getString( + ConnectionException.class, "couldNotInstaniateDriver", + new Object[] { jdbcDriver.getClassName(), bookmark.getName() })); } - return connection; } catch (SQLException e) { throw new ConnectionException(e); } } - public SQLResults execute(Connection con, String s) throws SQLException { - return execute(con, s, -1, -1); - } - public SQLResults execute(Connection con, String s, int startRow, int endRow) throws SQLException { - return execute(con, s, -1, -1, Integer.MAX_VALUE); + public SQLResults execute(Bookmark bookmark, Connection con, Entity entity, String s) + throws SQLException { + return execute(bookmark, con, entity, s, 200); } - public SQLResults execute(Connection con, String s, int startRow, int endRow, int maxLength) throws SQLException { - return execute(con, s, startRow, endRow, maxLength, ""); //$NON-NLS-1$ + public SQLResults execute(Bookmark bookmark, Connection con, String s) + throws SQLException { + return execute(bookmark, con, null, s, 200); } - public SQLResults execute( - Connection con, - String s, - int startRow, - int endRow, - int maxLength, - String encoding) - throws SQLException { + public SQLResultSetResults getMetaData(Entity entity, Connection connection) throws SQLException { + String query = "SELECT * FROM " + entity.getQuotedTableName() + " WHERE (1 = 0)"; //$NON-NLS-1$ //$NON-NLS-2$ + SQLResultSetResults results = null; + if (connection != null) { + Statement statement = connection.createStatement(); + try { + ResultSet set = statement.executeQuery(query); + try { + results = SQLMetaDataResults.create(entity.getBookmark(), set, query, entity); + } finally { + set.close(); + } + } finally { + statement.close(); + } + } + return results; + } + + public SQLResults execute(Bookmark bookmark, Connection con, String sql, + int numberOfRowsPerPage) throws SQLException { + return execute(bookmark, con, null, sql, numberOfRowsPerPage); + } - SQLResults results = new SQLResults(); + + public SQLResults execute( + Bookmark bookmark, + Connection con, + Entity entity, + String sql, + int numberOfRowsPerPage) + throws SQLException { long startTime = System.currentTimeMillis(); System.out.println("Executing"); //$NON-NLS-1$ LogProxy log = LogProxy.getInstance(); - log.addText(LogProxy.QUERY, "Executing Request [" + s + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - boolean metadata = false; - if (s.startsWith("METADATA")) { //$NON-NLS-1$ - metadata = true; - } - if (metadata) { - results.setQuery(s); - String table = s.substring(s.indexOf(':') + 1); - String query = "SELECT * FROM " + table + " WHERE (1 = 0)"; //$NON-NLS-1$ //$NON-NLS-2$ - s = query; - log.addText(LogProxy.QUERY, "Metadata Request [" + s + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - } else { - results.setQuery(s); - } - - Statement stmt = con.createStatement(); - boolean flag = stmt.execute(s); - results.setResultSet(flag); - if (metadata) { - genMetadataResultSet(results, stmt); - return results; - } - if (!flag) { - int updates = stmt.getUpdateCount(); - results.setUpdateCount(updates); - log.addText(LogProxy.RESULTS, "Success: " + updates + " records updated"); //$NON-NLS-1$ //$NON-NLS-2$ - - } else { - ResultSet set = stmt.getResultSet(); - ResultSetMetaData metaData = set.getMetaData(); - int columnCount = metaData.getColumnCount(); - Vector columnNames = new Vector(); - for (int i = 1; i <= columnCount; i++) { - columnNames.addElement(metaData.getColumnName(i)); - } - results.setColumnNames(columnNames); - Vector columnTypes = new Vector(); - for (int i = 1; i <= columnCount; i++) { - columnTypes.addElement(metaData.getColumnTypeName(i)); - } - results.setColumnTypes(columnTypes); - int columnSizes[] = new int[columnCount]; - for (int i = 1; i <= columnCount; i++) { - columnSizes[i - 1] = metaData.getColumnDisplaySize(i); - } - int rowCount = 1; - boolean exitEarly = false; - while (set.next()) { - boolean disable = startRow < 1 || endRow < 1; - boolean start = rowCount >= startRow; - boolean end = rowCount <= endRow; - if (disable || (start && end)) { - Vector row = new Vector(); - for (int i = 1; i <= columnCount; i++) { - String value; - if (columnSizes[i - 1] < STREAM - && columnSizes[i - 1] < maxLength) { - if (encoding.equals("")) { //$NON-NLS-1$ - value = set.getString(i); - } else { - try { - value = - new String(set.getBytes(i), encoding); - } catch (UnsupportedEncodingException e) { - log.addText(LogProxy.ERROR, "Error Unsupported encoding " + encoding.toString() + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$ - value = new String(set.getBytes(i)); - } - } - } else { - try { - if (encoding.equals("")) { //$NON-NLS-1$ - Reader reader = set.getCharacterStream(i); - StringBuffer buffer = new StringBuffer(); - if (reader != null) { - int retVal = reader.read(); - int count = 0; - while (retVal >= 0) { - buffer.append((char) retVal); - retVal = reader.read(); - count++; - if (count > maxLength) { - buffer.append("...>>>"); //$NON-NLS-1$ - break; - } - } - reader.close(); - } - value = buffer.toString(); - } else { - InputStream binaryStream = - set.getBinaryStream(i); - ByteArrayOutputStream baos = - new ByteArrayOutputStream(); - if (binaryStream != null) { - int retVal = binaryStream.read(); - int count = 0; - while (retVal >= 0) { - baos.write(retVal); - retVal = binaryStream.read(); - count++; - if (count > maxLength) { - break; - } - } - binaryStream.close(); - } - value = - new String( - baos.toByteArray(), - encoding); - } - } catch (Throwable e) { - // hack for mysql which doesn't implement - // character streams - value = set.getString(i); - } - } - if (set.wasNull()) { - row.addElement(""); //$NON-NLS-1$ - } else { - row.addElement(value); - } - } - results.addRow(row); - } - rowCount++; - if (!disable && (rowCount > endRow)) { - exitEarly = true; - break; + log.addText(LogProxy.QUERY, "Executing Request [" + sql + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + Statement statement = con.createStatement(); + try { + SQLResults results; + if (statement.execute(sql)) { + ResultSet set = statement.getResultSet(); + try { + results = SQLStandardResultSetResults.create(set, bookmark, sql, entity, numberOfRowsPerPage); + } finally { + set.close(); } - } - if (exitEarly) { - results.setHasMore(set.next()); } else { - results.setMaxSize(rowCount); - results.setHasMore(false); + int updates = statement.getUpdateCount(); + results = new SQLUpdateResults(updates); } - set.close(); - } - log.addText(LogProxy.RESULTS, "Success: result set displayed"); //$NON-NLS-1$ - stmt.close(); - results.setTime(System.currentTimeMillis() - startTime); - System.out.println("Executed"); //$NON-NLS-1$ - System.out.println(); - return results; - } - private void genMetadataResultSet(SQLResults results, Statement stmt) - throws SQLException { - ResultSet set = stmt.getResultSet(); - ResultSetMetaData metaData = set.getMetaData(); - int columnCount = metaData.getColumnCount(); - Vector columnNames = new Vector(); - columnNames.addElement("ColumnName"); //$NON-NLS-1$ - columnNames.addElement("Type"); //$NON-NLS-1$ - columnNames.addElement("Size"); //$NON-NLS-1$ - columnNames.addElement("Nullable"); //$NON-NLS-1$ - columnNames.addElement("AutoIncrement"); //$NON-NLS-1$ - results.setColumnNames(columnNames); - for (int i = 1; i <= columnCount; i++) { - Vector row = new Vector(); - row.addElement(metaData.getColumnName(i)); - row.addElement(metaData.getColumnTypeName(i)); - int textSize = metaData.getColumnDisplaySize(i); - int precision = metaData.getPrecision(i); - int scale = metaData.getScale(i); - if (scale == 0 && precision == 0) { - row.addElement(Integer.toString(precision)); - } else { - row.addElement(textSize + ", " + precision + ", " + scale); //$NON-NLS-1$ //$NON-NLS-2$ - } - int nullable = metaData.isNullable(i); - if (nullable == ResultSetMetaData.columnNoNulls) { - row.addElement("Not Null"); //$NON-NLS-1$ - } else if (nullable == ResultSetMetaData.columnNullable) { - row.addElement("Nullable"); //$NON-NLS-1$ - } else if ( - nullable == ResultSetMetaData.columnNullableUnknown) { - row.addElement("Nullable"); //$NON-NLS-1$ - } else { - row.addElement(""); //$NON-NLS-1$ + log.addText(LogProxy.RESULTS, "Success: result set displayed"); //$NON-NLS-1$ + if (results != null) { + results.setTime(System.currentTimeMillis() - startTime); } - row.addElement( - (metaData.isAutoIncrement(i) - ? Boolean.TRUE - : Boolean.FALSE) - .toString()); - results.addRow(row); - } - results.setHasMore(false); - set.close(); - } - - /** - * Returns an ObjectMetadata object got from the connection 'con' using the name and schema of the node. - * @param con - * @param node - * @return - * @throws SQLException - */ - public ObjectMetaData getObjectMetadata(Connection con, TreeNode node) throws SQLException { - ObjectMetaData metadata = new ObjectMetaData(); - if (!(node instanceof Entity)) return metadata; - - String schema = ((Entity)node).getSchema(); - String tableName = node.getName(); - - if (schema.length() == 0) schema = null; - metadata.setColumns(MetaDataJDBCInterface.getColumns(con, schema, tableName)); - if (node instanceof EntityNode && ((EntityNode) node).isTable()) { - metadata.setPrimaryKeys(MetaDataJDBCInterface.getPrimaryKeys(con, schema, tableName)); - metadata.setForeignKeys(MetaDataJDBCInterface.getForeignKeys(con, schema, tableName, true)); - metadata.setIndexInfo(MetaDataJDBCInterface.getIndexInfo(con, schema, tableName)); - metadata.setBestRowId(MetaDataJDBCInterface.getBestRowId(con, schema, tableName)); + return results; + } finally { + statement.close(); } - return metadata; } + public int getSize(Bookmark bookmark, Connection connection, String tableName, DatabaseAdapter adapter) throws SQLException { + SQLResultSetResults results = (SQLResultSetResults) execute( + bookmark, connection, adapter.getCountQuery(tableName)); + if (results.getRowCount() > 0 && results.getColumnCount() > 0) { + return Integer.parseInt(results.getElement(1, 1).toString()); + } else { + return -1; + } + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLHelper.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLHelper.java deleted file mode 100644 index 144a170..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLHelper.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.quantum.sql; - -import java.sql.Connection; -import java.sql.SQLException; - -import com.quantum.adapters.DatabaseAdapter; -import com.quantum.view.LogProxy; - -public class SQLHelper { - - public static int getSize(Connection connection, String tableName, DatabaseAdapter adapter) throws SQLException { - SQLResults results = MultiSQLServer.getInstance().execute( - connection, adapter.getCountQuery(tableName)); - if (results.getRowCount() > 0 && results.getColumnCount() > 0) { - return Integer.parseInt(results.getElement(1, 1).toString()); - } else { - return -1; - } - } - - public static SQLResults getResults(Connection connection, String query, int start, int end, int maxLength, String encoding) { - try { - return MultiSQLServer.getInstance().execute(connection, - query, start, end, maxLength, encoding); - } catch (SQLException e) { - LogProxy log = LogProxy.getInstance(); - log.addText( - LogProxy.ERROR, - "Error Executing: " + query + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$ - } - SQLResults results = new SQLResults(); - results.setIsError(true); - return results; - } - - /** - * True if the type is Real (numeric and with decimal part) according to java.sql.Types - * @param type - * @return - */ - public static boolean isReal(int type) { - return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT || - type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL ); - } - - /** - * True if the type is Numeric according to java.sql.Types - * @param type - * @return - */ - public static boolean isNumeric(int type) { - return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT || - type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL || type == java.sql.Types.BIGINT || - type == java.sql.Types.TINYINT || type == java.sql.Types.SMALLINT || type == java.sql.Types.INTEGER ); - } - /** - * True if the type is textual according to java.sql.Types - * @param type - * @return - */ - public static boolean isText(int type) { - return (type == java.sql.Types.CLOB || type == java.sql.Types.VARBINARY || type ==java.sql.Types.VARCHAR - || type == java.sql.Types.CHAR || type == java.sql.Types.LONGVARCHAR ); - } - - public static String getQualifiedName(String schema, String name) { - return (schema != null && schema.length() > 0) ? schema + "." + name : name; - } -} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLMetaDataResults.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLMetaDataResults.java new file mode 100644 index 0000000..61b3333 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLMetaDataResults.java @@ -0,0 +1,91 @@ +package com.quantum.sql; + +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + +import com.quantum.model.Bookmark; +import com.quantum.model.Entity; + + +/** + * @author BC + */ +public class SQLMetaDataResults extends SQLResultSetResults { + + /** + * @param query + */ + private SQLMetaDataResults(String query, Bookmark bookmark, Entity entity) { + super(query, bookmark, entity); + } + + static SQLResultSetResults create(Bookmark bookmark, ResultSet set, String query, Entity entity) throws SQLException { + + SQLMetaDataResults results = new SQLMetaDataResults(query, bookmark, entity); + results.parseResultSet(set); + + return results; + } + + /** + * @param set + * @param results + * @param metaData + * @param columnCount + * @throws SQLException + */ + protected void parseResultSet(ResultSet set) throws SQLException { + + List columns = new ArrayList(); + columns.add(new Column("ColumnName", "", 0)); //$NON-NLS-1$ + columns.add(new Column("Type", "", 0)); //$NON-NLS-1$ + columns.add(new Column("Size", "", 0)); //$NON-NLS-1$ + columns.add(new Column("Nullable", "", 0)); //$NON-NLS-1$ + columns.add(new Column("AutoIncrement", "", 0)); //$NON-NLS-1$ + setColumns((Column[]) columns.toArray(new Column[columns.size()])); + + ResultSetMetaData metaData = set.getMetaData(); + + List rowList = new ArrayList(); + for (int i = 1; i <= metaData.getColumnCount(); i++) { + Vector row = new Vector(); + row.addElement(metaData.getColumnName(i)); + row.addElement(metaData.getColumnTypeName(i)); + int textSize = metaData.getColumnDisplaySize(i); + int precision = metaData.getPrecision(i); + int scale = metaData.getScale(i); + if (scale == 0 && precision == 0) { + row.addElement(Integer.toString(precision)); + } else { + row.addElement(textSize + ", " + precision + ", " + scale); //$NON-NLS-1$ //$NON-NLS-2$ + } + int nullable = metaData.isNullable(i); + if (nullable == ResultSetMetaData.columnNoNulls) { + row.addElement("Not Null"); //$NON-NLS-1$ + } else if (nullable == ResultSetMetaData.columnNullable) { + row.addElement("Nullable"); //$NON-NLS-1$ + } else if ( + nullable == ResultSetMetaData.columnNullableUnknown) { + row.addElement("Nullable"); //$NON-NLS-1$ + } else { + row.addElement(""); //$NON-NLS-1$ + } + row.addElement( + (metaData.isAutoIncrement(i) + ? Boolean.TRUE + : Boolean.FALSE) + .toString()); + rowList.add(new Row(row)); + } + setRows((Row[]) rowList.toArray(new Row[rowList.size()])); + set.close(); + } + + public boolean isMetaData() { + return true; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResultSetCollection.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResultSetCollection.java new file mode 100644 index 0000000..09aa993 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResultSetCollection.java @@ -0,0 +1,56 @@ +package com.quantum.sql; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +/** + * @author BC + */ +public class SQLResultSetCollection { + + private static final SQLResultSetCollection instance = new SQLResultSetCollection(); + + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); + + private List results = Collections.synchronizedList(new ArrayList()); + + private SQLResultSetCollection() { + } + public static SQLResultSetCollection getInstance() { + return SQLResultSetCollection.instance; + } + + public void addPropertyChangeListener(PropertyChangeListener arg0) { + this.propertyChangeSupport.addPropertyChangeListener(arg0); + } + public void removePropertyChangeListener(PropertyChangeListener arg0) { + this.propertyChangeSupport.removePropertyChangeListener(arg0); + } + + public void addSQLResultSet(SQLResultSetResults resultSet) { + this.results.add(resultSet); + this.propertyChangeSupport.firePropertyChange("resultSets", null, resultSet); + } + + public void removeSQLResultSet(SQLResultSetResults resultSet) { + if (this.results.remove(resultSet)) { + this.propertyChangeSupport.firePropertyChange("resultSets", resultSet, null); + } + } + + public void removeAllSQLResultSet() { + if (this.results.size() > 0) { + this.results.clear(); + } + this.propertyChangeSupport.firePropertyChange("resultSets", null, null); + } + + public SQLResultSetResults[] getResultSets() { + return (SQLResultSetResults[]) this.results.toArray( + new SQLResultSetResults[this.results.size()]); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResultSetResults.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResultSetResults.java new file mode 100644 index 0000000..65716d0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResultSetResults.java @@ -0,0 +1,271 @@ +package com.quantum.sql; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import com.quantum.model.Bookmark; +import com.quantum.model.Entity; + +/** + * @author Tom Schneider + * @author BC Holmes + */ +public abstract class SQLResultSetResults extends SQLResults { + + + class ColumnArrayComparator implements Comparator { + + public int compare(Object arg0, Object arg1) { + return compare((Column[]) arg0, (Column[]) arg1); + } + public int compare(Column[] columns0, Column[] columns1) { + + if (columns0 == null && columns1 == null) { + return 0; + } else if (columns0 == null) { + return -1; + } else if (columns1 == null) { + return 1; + } else if (columns0.length < columns1.length) { + return -1; + } else if (columns0.length > columns1.length) { + return 1; + } else { + int result = 0; + for (int i = 0, length = columns1 == null ? 0 : columns1.length; + result == 0 && i < length; i++) { + result = compare(columns0[i], columns1[i]); + } + return result; + } + } + /** + * @param columns0 + * @param columns1 + * @param result + * @param i + * @return + */ + private int compare(Column column0, Column column1) { + + if (column0 == null && column1 == null) { + return 0; + } else if (column0 == null) { + return -1; + } else if (column1 == null) { + return 1; + } else if (column0.getName() == null) { + return -1; + } else if (column1.getName() == null) { + return 1; + } else if (column0.getName() != null && column1.getName() != null + && column0.getName().compareTo(column1.getName()) != 0) { + return column0.getName().compareTo(column1.getName()); + } else if (column0.getType() == null) { + return -1; + } else if (column1.getType() == null) { + return 1; + } else if (column0.getType() != null && column1.getType() != null + && column0.getType().compareTo(column1.getType()) != 0) { + return column0.getType().compareTo(column1.getType()); + } else { + return column0.getSize() - column1.getSize(); + } + } + } + + public class Row { + private final List elements; + + Row(List elements) { + this.elements = elements; + } + + public Object get(int columnNumber) { + return (columnNumber > this.elements.size() || columnNumber <= 0) + ? null + : this.elements.get(columnNumber - 1); + } + + public SQLResultSetResults getResultSet() { + return SQLResultSetResults.this; + } + } + + public class Column { + private final String name; + private final String type; + private final int size; + + Column(String name, String type, int size) { + this.name = name; + this.type = type; + this.size = size; + } + public String getName() { + return this.name; + } + public int getSize() { + return this.size; + } + public String getType() { + return this.type; + } + } + + private List rows = Collections.synchronizedList(new ArrayList()); + private List columns = Collections.synchronizedList(new ArrayList()); + private String query; + private Bookmark bookmark; + private final Entity entity; + private String encoding = ""; + + private FilterSort filterSort = null; + + /** + * @param entity + * @param query2 + */ + public SQLResultSetResults(String query, Bookmark bookmark, Entity entity) { + this.query = query; + this.bookmark = bookmark; + this.entity = entity; + } + public String getColumnName(int columnNumber) { + Column column = getColumn(columnNumber); + return column == null ? "" : column.getName(); + + } + /** + * @param columnNumber + * @return + */ + protected Column getColumn(int columnNumber) { + return columnNumber <= this.columns.size() + ? (Column) this.columns.get(columnNumber-1) + : null; + } + public Column[] getColumns() { + return (Column[]) this.columns.toArray(new Column[this.columns.size()]); + } + protected void setColumns(Column[] columns) { + Column[] original = getColumns(); + if (new ColumnArrayComparator().compare(original, columns) != 0) { + this.columns.clear(); + this.columns.addAll(Arrays.asList(columns)); + this.propertyChangeSupport.firePropertyChange("columns", original, columns); + } + } + public Object getElement(int column, int row) { + return ((Row) rows.get(row - 1)).get(column); + } + public int getColumnCount() { + if (columns.size() > 0) { + return columns.size(); + } + return 0; + } + public int getRowCount() { + return rows.size(); + } + public String[] getColumnNames() { + List names = new ArrayList(); + for (Iterator i = this.columns.iterator(); i.hasNext();) { + Column column = (Column) i.next(); + names.add(column.getName()); + } + return (String[]) names.toArray(new String[names.size()]); + } + /** + * Returns the resultSet. + * @return boolean + */ + public boolean isResultSet() { + return true; + } + public Row[] getRows() { + return (Row[]) rows.toArray(new Row[this.rows.size()]); + } + /** + * Returns the query. + * @return String + */ + public String getQuery() { + return this.query; + } + public String getFilteredQuery() { + if (this.filterSort == null) { + return this.query; + } else { + return this.query + this.filterSort.toString(); + } + } + public Bookmark getBookmark() { + return this.bookmark; + } + + public Entity getEntity() { + return this.entity; + } + /** + * Returns the resultSet. + * @return boolean + */ + public boolean isMetaData() { + return false; + } + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); + + public void addPropertyChangeListener(PropertyChangeListener listener) { + this.propertyChangeSupport.addPropertyChangeListener(listener); + } + public void removePropertyChangeListener(PropertyChangeListener listener) { + this.propertyChangeSupport.removePropertyChangeListener(listener); + } + protected abstract void parseResultSet(ResultSet set) throws SQLException; + + public void refresh(Connection connection) throws SQLException { + Statement statement = connection.createStatement(); + try { + ResultSet resultSet = statement.executeQuery(getFilteredQuery()); + try { + parseResultSet(resultSet); + } finally { + resultSet.close(); + } + } finally { + statement.close(); + } + } + + protected void setRows(Row[] rows) { + Row[] original = getRows(); + this.rows.clear(); + if (rows != null) { + this.rows.addAll(Arrays.asList(rows)); + } + this.propertyChangeSupport.firePropertyChange("rows", original, getRows()); + } + public String getEncoding() { + return this.encoding; + } + public void setEncoding(String encoding) { + this.encoding = encoding; + } + public FilterSort getFilterSort() { + return this.filterSort; + } + public void setFilterSort(FilterSort filterSort) { + this.filterSort = filterSort; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResults.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResults.java index 44b67ed..28325e7 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResults.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLResults.java @@ -1,145 +1,19 @@ package com.quantum.sql; -import java.util.ArrayList; -import java.util.Vector; -/** - * com.quantum project - * @author root - * -*/ -public class SQLResults { - private String query; - private String table; - private ArrayList rows = new ArrayList(); - private Vector columns; - private Vector columnTypes; - private int[] columnSizes; - private int updateCount = 0; - private boolean resultSet = false; - private boolean hasMore = false; - private boolean isError = false; - private int maxSize = -1; - private long time; - - public void setColumnNames(Vector columns) { - this.columns = columns; - } - public String getColumnName(int column) { - if (columns.size() < column) return ""; //$NON-NLS-1$ - return columns.elementAt(column - 1).toString(); - - } - public void setColumnTypes(Vector columnsTypes) { - this.columnTypes = columnsTypes; - } - public String getColumnType(int column) { - if (columnTypes.size() < column) return ""; //$NON-NLS-1$ - return columnTypes.elementAt(column - 1).toString(); - } - public void setColumnSizes(int[] columnSizes) { - this.columnSizes = columnSizes; - } - public int getColumnSize(int column) { - if (columnSizes.length < column) return 0; - return columnSizes[column - 1]; - } - public void addRow(Vector row) { - rows.add(row); - } - public Object getElement(int column, int row) { - return ((Vector) rows.get(row - 1)).elementAt(column - 1); - } - public int getColumnCount() { - if (columns.size() > 0) { - return columns.size(); - } - return 0; - } - public int getRowCount() { - return rows.size(); - } - /** - * Returns the query. - * @return String - */ - public String getQuery() { - return query; - } - - /** - * Sets the query. - * @param query The query to set - */ - public void setQuery(String query) { - this.query = query; - } - - /** - * Returns the resultSet. - * @return boolean - */ - public boolean isResultSet() { - return resultSet; - } - - /** - * Sets the resultSet. - * @param resultSet The resultSet to set - */ - public void setResultSet(boolean resultSet) { - this.resultSet = resultSet; - } - - public int getUpdateCount() { - return updateCount; - } - public void setUpdateCount(int updateCount) { - this.updateCount = updateCount; - } - - public String getTable() { - return table; - } - - public void setTable(String table) { - this.table = table; - } - - public boolean hasMore() { - return hasMore; - } - - public void setHasMore(boolean hasMore) { - this.hasMore = hasMore; - } - - public int getMaxSize() { - return maxSize; - } - - public void setMaxSize(int maxSize) { - this.maxSize = maxSize; - } - - public boolean isError() { - return isError; - } +/** + * @author BC + */ +public abstract class SQLResults { + public abstract boolean isResultSet(); - public void setIsError(boolean isError) { - this.isError = isError; - } - /** - * - */ - public Object[] getRows() { - return rows.toArray(); - } + private long time; public long getTime() { return this.time; } + public void setTime(long time) { this.time = time; } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLStandardResultSetResults.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLStandardResultSetResults.java new file mode 100644 index 0000000..7358b26 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLStandardResultSetResults.java @@ -0,0 +1,284 @@ +package com.quantum.sql; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.UnsupportedEncodingException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import com.quantum.model.Bookmark; +import com.quantum.model.Entity; + + +/** + * @author BC + */ +public class SQLStandardResultSetResults extends SQLResultSetResults implements Scrollable { + + /** + * Some columns -- especially BLOBS and CLOBS can be very wide. This variable + * sets the maximum width of the column. + */ + private static final int MAX_COLUMN_WIDTH = 1024 * 2; + + private boolean hasMore = false; + private int start = 1; + private int numberOfRowsPerPage; + private int totalNumberOfRows = -1; + + private boolean fullMode = false; + + /** + * @param bookmark + * @param query + * @param encoding + * @param numberOfRowsPerPage + */ + protected SQLStandardResultSetResults( + Bookmark bookmark, String query, Entity entity, + int numberOfRowsPerPage) { + super(query, bookmark, entity); + this.numberOfRowsPerPage = numberOfRowsPerPage; + } + + static SQLResultSetResults create( + ResultSet set, Bookmark bookmark, + String query, Entity entity, int numberOfRows) throws SQLException { + + SQLStandardResultSetResults results = new SQLStandardResultSetResults( + bookmark, query, entity, numberOfRows); + + results.parseResultSet(set); + + return results; + } + + /** + * @param set + * @param encoding + * @param numberOfRows + * @param results + * @param columnCount + * @throws SQLException + */ + protected void parseResultSet(ResultSet set) throws SQLException { + int rowCount = 1; + + ResultSetMetaData metaData = set.getMetaData(); + int columnCount = metaData.getColumnCount(); + List columns = new ArrayList(); + for (int i = 1; i <= columnCount; i++) { + columns.add(new Column( + metaData.getColumnName(i), + metaData.getColumnTypeName(i), + metaData.getColumnDisplaySize(i))); + } + setColumns((Column[]) columns.toArray(new Column[columns.size()])); + + boolean exitEarly = false; + int firstRow = (this.fullMode) ? 0 : this.start; + int lastRow = (this.fullMode) ? Integer.MAX_VALUE : this.start + this.numberOfRowsPerPage - 1; + List rowList = new ArrayList(); + while (set.next()) { + boolean disable = this.start < 1 || lastRow < 1; + if (disable || ((rowCount >= firstRow) && (rowCount <= lastRow))) { + List row = new ArrayList(); + for (int i = 1, length = columns.size(); i <= length; i++) { + String value = null; + if (getColumn(i).getSize() < MAX_COLUMN_WIDTH) { + value = getEncodedString(set, getEncoding(), i); + } else { + try { + if ("".equals(getEncoding())) { //$NON-NLS-1$ + value = getStringFromCharacterSteam(set, i); + } else { + value = getEncodedStringFromBinaryStream(set, getEncoding(), i); + } + } catch (IOException e) { + value = set.getString(i); + } catch (RuntimeException e) { + // hack for mysql which doesn't implement + // character streams + value = set.getString(i); + } + } + if (value == null) { + value = set.getString(i); + } + row.add(value == null || set.wasNull() ? "" : value); //$NON-NLS-1$ + } + rowList.add(new Row(row)); + } + rowCount++; + if (!disable && (rowCount > lastRow)) { + exitEarly = true; + break; + } + } + if (exitEarly) { + this.hasMore = set.next(); + } else { + this.totalNumberOfRows = Math.max(0, rowCount-1); + this.hasMore = false; + } + setRows((Row[]) rowList.toArray(new Row[rowList.size()])); + } + + + /** + * @param set + * @param encoding + * @param columnNumber + * @throws SQLException + * @throws IOException + * @throws UnsupportedEncodingException + */ + private String getEncodedStringFromBinaryStream(ResultSet set, String encoding, int columnNumber) + throws SQLException, IOException, UnsupportedEncodingException { + InputStream binaryStream = set.getBinaryStream(columnNumber); + if (binaryStream != null) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + for (int c = binaryStream.read(), count = 0; + c >= 0 && count <= MAX_COLUMN_WIDTH; + c = binaryStream.read(), count++) { + baos.write(c); + } + } finally { + binaryStream.close(); + } + return new String(baos.toByteArray(), encoding); + } else { + return null; + } + } + + + /** + * @param set + * @param columnNumber + * @throws SQLException + * @throws IOException + */ + private String getStringFromCharacterSteam(ResultSet set, int columnNumber) + throws SQLException, IOException { + Reader reader = set.getCharacterStream(columnNumber); + if (reader != null) { + StringBuffer buffer = new StringBuffer(); + int retVal = reader.read(); + int count = 0; + while (retVal >= 0) { + buffer.append((char) retVal); + retVal = reader.read(); + count++; + if (count > MAX_COLUMN_WIDTH) { + buffer.append("...>>>"); //$NON-NLS-1$ + break; + } + } + reader.close(); + return buffer.toString(); + } else { + return null; + } + } + + + /** + * @param set + * @param encoding + * @param index + * @return + * @throws SQLException + */ + private String getEncodedString(ResultSet set, String encoding, int index) + throws SQLException { + try { + return encoding == null || encoding.trim().length() == 0 + ? set.getString(index) + : new String(set.getBytes(index), encoding); + } catch (UnsupportedEncodingException e) { + return set.getString(index); + } + } + + public boolean hasMore() { + return this.hasMore; + } + + public int getTotalNumberOfRows() { + return this.totalNumberOfRows; + } + public void nextPage(Connection connection) throws SQLException { + if (hasNextPage()) { + this.start += this.numberOfRowsPerPage; + refresh(connection); + } + } + + /* (non-Javadoc) + * @see com.quantum.sql.Scrollable#previousPage(java.sql.Connection) + */ + public void previousPage(Connection connection) throws SQLException { + if (hasPreviousPage()) { + this.start = Math.max(1, this.start - this.numberOfRowsPerPage); + refresh(connection); + } + } + + /* (non-Javadoc) + * @see com.quantum.sql.Scrollable#hasNextPage() + */ + public boolean hasNextPage() { + return this.hasMore; + } + + /* (non-Javadoc) + * @see com.quantum.sql.Scrollable#hasPreviousPage() + */ + public boolean hasPreviousPage() { + return this.start > 1; + } + + public void setFullMode(boolean fullMode) { + this.fullMode = fullMode; + } + public boolean isFullMode() { + return this.fullMode; + } + + /* (non-Javadoc) + * @see com.quantum.sql.Scrollable#getStart() + */ + public int getStart() { + return getRowCount() == 0 ? 0 : (this.fullMode ? 1 : this.start); + } + + /* (non-Javadoc) + * @see com.quantum.sql.Scrollable#getEnd() + */ + public int getEnd() { + return this.fullMode + ? getRowCount() + : this.start + getRowCount() - 1; + } + + /* (non-Javadoc) + * @see com.quantum.sql.Scrollable#getLast() + */ + public int getLast() { + return this.totalNumberOfRows; + } + + + public void setFilterSort(FilterSort filterSort) { + super.setFilterSort(filterSort); + this.start = 1; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLUpdateResults.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLUpdateResults.java new file mode 100644 index 0000000..4ba3f52 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLUpdateResults.java @@ -0,0 +1,21 @@ +package com.quantum.sql; + + +/** + * @author BC + */ +public class SQLUpdateResults extends SQLResults { + private int updateCount = 0; + + public SQLUpdateResults(int updateCount) { + this.updateCount = updateCount; + } + + public int getUpdateCount() { + return this.updateCount; + } + + public boolean isResultSet() { + return false; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/Scrollable.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/Scrollable.java new file mode 100644 index 0000000..6068ca0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/Scrollable.java @@ -0,0 +1,20 @@ +package com.quantum.sql; + +import java.sql.Connection; +import java.sql.SQLException; + + +/** + * @author BC + */ +public interface Scrollable { + public void nextPage(Connection connection) throws SQLException; + public void previousPage(Connection connection) throws SQLException; + public boolean hasNextPage(); + public boolean hasPreviousPage(); + public void setFullMode(boolean fullMode); + public boolean isFullMode(); + public int getStart(); + public int getEnd(); + public int getLast(); +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQL.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQL.java new file mode 100644 index 0000000..99972eb --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQL.java @@ -0,0 +1,16 @@ +package com.quantum.sql.parser; + + +/** + * @author BC + */ +public interface SQL { + + /** + * The command describes the type of SQL statement that is represented. The command + * might be "SELECT" or "ALTER TABLE" or "GRANT" + * + * @return + */ + public String getCommand(); +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLParser.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLParser.java new file mode 100644 index 0000000..4bb97cb --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLParser.java @@ -0,0 +1,59 @@ +package com.quantum.sql.parser; + +import java.util.Vector; + + +public class SQLParser { + + /** + * Parses a query string into executable units. + * @param query + * @return a Vector of Strings, with the individual executable units. + */ + public static Vector parse(String query) { + Vector commands = new Vector(); + Vector groups = new Vector(); + try { + Vector tokens = SQLLexx.parse(query); + StringBuffer buffer = new StringBuffer(); + StringBuffer groupBuffer = new StringBuffer(); + for (int i = 0; i < tokens.size(); i++) { + Token t = (Token) tokens.elementAt(i); + if (t.getType() == Token.COMMENT) { + // ignore comments + } else if (t.getType() == Token.SEPARATOR) { + groupBuffer.append(t.getValue()); + String newCommand = buffer.toString().trim(); + if (!newCommand.equals("")) { //$NON-NLS-1$ + commands.addElement(newCommand); + } + buffer = new StringBuffer(); + } else if (t.getType() == Token.GROUP) { + // We don't append the group token because it may be misinterpreted + //groupBuffer.append(t.getValue()); + String newGroup = groupBuffer.toString().trim(); + if (!newGroup.equals("")) { //$NON-NLS-1$ + groups.addElement(newGroup); + //Groups have precedence over commands, so the preceding commands are erased + commands.clear(); + } + groupBuffer = new StringBuffer(); + } else { + // We append the tokens to the buffer until it's a separator or group. + buffer.append(t.getValue()); + groupBuffer.append(t.getValue()); + } + } + String newCommand = buffer.toString().trim(); + if (!newCommand.equals("")) { //$NON-NLS-1$ + commands.addElement(newCommand); + } + } catch (Throwable e) { + e.printStackTrace(); + } + Vector result = new Vector(); + result.addAll(groups); + result.addAll(commands); + return result; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLScript.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLScript.java new file mode 100644 index 0000000..a6b397a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/SQLScript.java @@ -0,0 +1,12 @@ +package com.quantum.sql.parser; + + +/** + * @author BC + */ +public class SQLScript { + + public SQL[] getSQLStatements() { + return null; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ui/dialog/SimpleSelectionDialog.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ui/dialog/SimpleSelectionDialog.java index ad76c71..6b569d7 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ui/dialog/SimpleSelectionDialog.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/ui/dialog/SimpleSelectionDialog.java @@ -119,9 +119,9 @@ public class SimpleSelectionDialog extends Dialog { style |= SWT.MULTI; } this.viewer = new TableViewer(composite, style); - GridData full = new GridData(GridData.FILL_HORIZONTAL); - full.widthHint = 200; - full.heightHint = 50; + GridData full = new GridData(GridData.FILL_BOTH); + full.widthHint = 300; + full.heightHint = 100; this.viewer.getControl().setLayoutData(full); this.viewer.setLabelProvider(new LabelProvider()); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/JarUtil.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/JarUtil.java index 2519891..528221e 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/JarUtil.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/JarUtil.java @@ -21,10 +21,10 @@ public class JarUtil { private static Hashtable classLoaderCache = new Hashtable(); - public static Driver loadDriver(String driverFile, String className) { + public static Driver loadDriver(String[] driverFiles, String className) { Driver result = null; try { - Class driverClass = loadDriverClass(driverFile, className); + Class driverClass = loadDriverClass(driverFiles, className); if (driverClass != null) { try { result = (Driver) driverClass.newInstance(); @@ -33,51 +33,100 @@ public class JarUtil { } } catch (InstantiationException e) { } catch (IllegalAccessException e) { + } catch (NoClassDefFoundError e) { + } catch (RuntimeException e) { } return result; } - public static Class loadDriverClass(String driverFile, String className) { + public static Class loadDriverClass(String[] driverFiles, String className) { Class result = null; - if (driverFile != null && className != null) { + if (driverFiles != null && driverFiles.length > 0 + && driverFiles[0].trim().length() > 0 && className != null) { try { - File file = new File(driverFile); - if (file.exists() && file.isFile()) { - URLClassLoader loader = getURLClassLoader(file); - Class driverClass = loader.loadClass(className); - result = Driver.class.isAssignableFrom(driverClass) ? driverClass : null; - } + File[] files = getFiles(driverFiles); + URLClassLoader loader = getURLClassLoader(files); + result = loadDriverClass(className, loader); } catch (MalformedURLException e) { } catch (ClassNotFoundException e) { + } catch (NoClassDefFoundError e) { + } catch (RuntimeException e) { + } + } else if (className != null) { + try { + result = loadDriverClass(className, JarUtil.class.getClassLoader()); + } catch (ClassNotFoundException e) { + } catch (NoClassDefFoundError e) { + } catch (RuntimeException e) { } } return result; } - public static String[] getAllDriverNames(String driverFile) { + /** + * @param driverFiles + * @return + */ + private static File[] getFiles(String[] driverFiles) { + List list = new ArrayList(); + + for (int i = 0, length = driverFiles == null ? 0 : driverFiles.length; i < length; i++) { + File file = new File(driverFiles[i]); + if (file.exists() && file.isFile()) { + list.add(file); + } + } + return (File[]) list.toArray(new File[list.size()]); + } + + /** + * @param className + * @param loader + * @return + * @throws ClassNotFoundException + */ + private static Class loadDriverClass(String className, ClassLoader loader) throws ClassNotFoundException { + Class driverClass = loader.loadClass(className); + return Driver.class.isAssignableFrom(driverClass) ? driverClass : null; + } + + public static String[] getAllDriverNames(String[] driverFile) { List list = new ArrayList(); try { - File file = new File(driverFile); - URLClassLoader loader = getURLClassLoader(file); - JarFile jar = new JarFile(file); - for (Enumeration e = jar.entries(); e.hasMoreElements(); ) { - JarEntry entry = (JarEntry) e.nextElement(); - String className = getClassNameFromFileName(entry.getName()); - if (className != null) { - try { - Class driverClass = loader.loadClass(className); - if (Driver.class.isAssignableFrom(driverClass)) { - list.add(className); - } - } catch (ClassNotFoundException ex) { - } - } + File[] files = getFiles(driverFile); + URLClassLoader loader = getURLClassLoader(files); + for (int i = 0, length = files == null ? 0 : files.length; i < length; i++) { + JarFile jar = new JarFile(files[i]); + addCandidateDriversToList(list, loader, jar); } } catch (IOException e) { } return (String[]) list.toArray(new String[list.size()]); } + /** + * @param list + * @param loader + * @param jar + */ + private static void addCandidateDriversToList(List list, URLClassLoader loader, JarFile jar) { + for (Enumeration e = jar.entries(); e.hasMoreElements(); ) { + JarEntry entry = (JarEntry) e.nextElement(); + String className = getClassNameFromFileName(entry.getName()); + if (className != null) { + try { + Class driverClass = loadDriverClass(className, loader); + if (driverClass != null) { + list.add(className); + } + } catch (NoClassDefFoundError ex) { + } catch (ClassNotFoundException ex) { + } catch (RuntimeException ex) { + } + } + } + } + private static String getClassNameFromFileName(String name) { String result = null; if (name.endsWith(".class")) { @@ -91,16 +140,36 @@ public class JarUtil { * @return * @throws MalformedURLException */ - private static URLClassLoader getURLClassLoader(File file) throws MalformedURLException { - String driverFile = file.getAbsolutePath(); + private static URLClassLoader getURLClassLoader(File[] files) throws MalformedURLException { + + String driverPath = getFilePath(files); URLClassLoader loader = - (URLClassLoader) classLoaderCache.get(driverFile); + (URLClassLoader) classLoaderCache.get(driverPath); if (loader == null) { - URL urls[] = new URL[1]; - urls[0] = file.toURL(); - loader = new URLClassLoader(urls); - classLoaderCache.put(driverFile, loader); + URL urls[] = new URL[files == null ? 0 : files.length]; + for (int i = 0, length = urls.length; i < length; i++) { + urls[i] = files[i].toURL(); + } + loader = urls.length > 0 ? new URLClassLoader(urls) : null; + if (loader != null) { + classLoaderCache.put(driverPath, loader); + } } return loader; } + + /** + * @param files + * @return + */ + private static String getFilePath(File[] files) { + StringBuffer buffer = new StringBuffer(); + for (int i = 0, length = files == null ? 0 : files.length; i < length; i++) { + buffer.append(files[i].getAbsolutePath()); + if (i < length-1) { + buffer.append(File.pathSeparator); + } + } + return buffer.toString(); + } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/StringArrayComparator.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/StringArrayComparator.java new file mode 100644 index 0000000..951285f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/StringArrayComparator.java @@ -0,0 +1,45 @@ +package com.quantum.util; + +import java.util.Comparator; + + +/** + * @author BC + */ +public class StringArrayComparator implements Comparator { + + public int compare(Object arg0, Object arg1) { + return compare((String[]) arg0, (String[]) arg1); + } + + public int compare(String[] arg0, String[] arg1) { + if (arg0 == null && arg1 == null) { + return 0; + } else if (arg0 == null) { + return -1; + } else if (arg1 == null) { + return 1; + } else if (arg0.length != arg1.length) { + return arg0.length - arg1.length; + } else { + int result = 0; + for (int i = 0, length = arg0 == null ? 0 : arg0.length; + result == 0 && i < length; i++) { + result = compare(arg0[i], arg1[i]); + } + return result; + } + } + + private int compare(String arg0, String arg1) { + if (arg0 == null && arg1 == null) { + return 0; + } else if (arg0 == null) { + return -1; + } else if (arg1 == null) { + return 1; + } else { + return arg0.compareTo(arg1); + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/TypesHelper.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/TypesHelper.java index feed61e..2b39182 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/TypesHelper.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/sql/TypesHelper.java @@ -87,4 +87,34 @@ public class TypesHelper { return name; } + /** + * True if the type is Real (numeric and with decimal part) according to java.sql.Types + * @param type + * @return + */ + public static boolean isReal(int type) { + return (type == DECIMAL || type == DOUBLE || type == FLOAT || + type == NUMERIC || type == REAL ); + } + + /** + * True if the type is Numeric according to java.sql.Types + * @param type + * @return + */ + public static boolean isNumeric(int type) { + return (type == DECIMAL || type == DOUBLE || type ==FLOAT || + type == NUMERIC || type == REAL || type == BIGINT || + type == TINYINT || type == SMALLINT || type == INTEGER ); + } + + /** + * True if the type is textual according to java.sql.Types + * @param type + * @return + */ + public static boolean isText(int type) { + return (type == CLOB || type == VARBINARY || type ==VARCHAR + || type == CHAR || type == LONGVARCHAR ); + } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/JDBCDriverTableViewer.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/JDBCDriverTableViewer.java index 8eb4bf1..63014c0 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/JDBCDriverTableViewer.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/JDBCDriverTableViewer.java @@ -60,7 +60,7 @@ public class JDBCDriverTableViewer implements PropertyChangeListener, ISelection result = ((JDBCDriver) element).getVersion(); break; case 4: - result = ((JDBCDriver) element).getJarFileName(); + result = ((JDBCDriver) element).getJarFilePath(); break; default: } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/ViewHelper.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/ViewHelper.java index e460e44..252c0a8 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/ViewHelper.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/ViewHelper.java @@ -12,6 +12,7 @@ import java.sql.SQLException; import com.quantum.Messages; import com.quantum.QuantumPlugin; +import com.quantum.model.Bookmark; import com.quantum.sql.MultiSQLServer; import com.quantum.sql.SQLResults; @@ -27,23 +28,22 @@ import org.eclipse.ui.IViewPart; */ public class ViewHelper { - public static SQLResults tryGetResults(IViewPart view, Connection con, String query) { - return tryGetResults(view.getSite().getShell(), con, query); + /** @deprecated */ + public static SQLResults tryGetResults(IViewPart view, Bookmark bookmark, Connection con, String query) { + return tryGetResults(view.getSite().getShell(), bookmark, con, query); } - public static SQLResults tryGetResults(Shell shell, Connection con, String query) { - SQLResults results = null; - MultiSQLServer server = MultiSQLServer.getInstance(); + /** @deprecated */ + public static SQLResults tryGetResults(Shell shell, Bookmark bookmark, Connection con, String query) { try { - results = server.execute(con, query); + MultiSQLServer server = MultiSQLServer.getInstance(); + return server.execute(bookmark, con, query); } catch (SQLException e) { LogProxy log = LogProxy.getInstance(); log.addText(LogProxy.ERROR, e.getLocalizedMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$ - results = new SQLResults(); - results.setIsError(true); MessageDialog.openConfirm(shell, "Database returned error", e.getLocalizedMessage()); //$NON-NLS-1$ + return null; } - return results; } public static FileOutputStream askSaveFile(String key, Shell shell) { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/TreeNode.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/TreeNode.java index 8b9825e..e3bf412 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/TreeNode.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/bookmark/TreeNode.java @@ -61,7 +61,7 @@ public abstract class TreeNode */ public int compareTo(Object object) { TreeNode that = (TreeNode) object; - return this.getLabelName().compareTo(that.getLabelName()); + return this.getLabelName().toLowerCase().compareTo(that.getLabelName().toLowerCase()); } public String toString() { diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/DeleteDriverAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/DeleteDriverAction.java new file mode 100644 index 0000000..324ff6d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/DeleteDriverAction.java @@ -0,0 +1,86 @@ +package com.quantum.view.driver; + +import java.util.List; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.model.Bookmark; +import com.quantum.model.BookmarkCollection; +import com.quantum.model.JDBCDriver; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.SelectionListenerAction; + +/** + * This action deletes JDBC Drivers from the JDBC Driver collection. + * + * @author BC Holmes + */ +public class DeleteDriverAction extends SelectionListenerAction { + + private final IViewPart viewPart; + + /** + * @param text + */ + protected DeleteDriverAction(IViewPart viewPart, ISelectionProvider selectionProvider) { + super(Messages.getString(DeleteDriverAction.class, "text")); + this.viewPart = viewPart; + selectionProvider.addSelectionChangedListener(this); + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.DELETE)); + } + + public void run() { + JDBCDriver driver = getJDBCDriver(); + + if (driver != null) { + Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks(); + boolean found = false; + for (int i = 0, length = bookmarks == null ? 0 : bookmarks.length; + driver != null && !found && i < length; i++) { + found |= driver.equals(bookmarks[i].getJDBCDriver()); + } + + if (found) { + MessageDialog.openWarning(getShell(), + Messages.getString(DeleteDriverAction.class, "failed"), + Messages.getString(DeleteDriverAction.class, "inUse")); + } else { + if (MessageDialog.openConfirm(getShell(), + Messages.getString(DeleteDriverAction.class, "confirm"), + Messages.getString(DeleteDriverAction.class, "confirmText", + new Object[] { driver.getName() }))) { + + if (!BookmarkCollection.getInstance().removeDriver(driver)) { + MessageDialog.openWarning(getShell(), + Messages.getString(DeleteDriverAction.class, "failed"), + Messages.getString(DeleteDriverAction.class, "cant")); + } + } + } + } + } + + /** + * @return + */ + private Shell getShell() { + return this.viewPart.getViewSite().getShell(); + } + + /** + * @return + */ + private JDBCDriver getJDBCDriver() { + List list = getSelectedNonResources(); + return list == null || list.size() == 0 ? null : (JDBCDriver) list.get(0); + } + + protected boolean updateSelection(IStructuredSelection selection) { + return selection != null && !selection.isEmpty(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/JDBCDriverView.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/JDBCDriverView.java new file mode 100644 index 0000000..c5210f0 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/JDBCDriverView.java @@ -0,0 +1,45 @@ +package com.quantum.view.driver; + + +import com.quantum.view.JDBCDriverTableViewer; + +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.part.ViewPart; + + +/** + * @author BC + */ +public class JDBCDriverView extends ViewPart { + + private JDBCDriverTableViewer viewer; + private JDBCDriverViewActionGroup actionGroup; + + public void createPartControl(Composite parent) { + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + parent.setLayout(layout); + this.viewer = new JDBCDriverTableViewer(parent); + this.viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); + + initActions(); + } + + public void initActions() { + + this.actionGroup = new JDBCDriverViewActionGroup(this, this.viewer); + + IActionBars actionBars = getViewSite().getActionBars(); + this.actionGroup.fillActionBars(actionBars); + } + + public void setFocus() { + } + public void dispose() { + this.viewer.dispose(); + super.dispose(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/JDBCDriverViewActionGroup.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/JDBCDriverViewActionGroup.java new file mode 100644 index 0000000..a9b4590 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/driver/JDBCDriverViewActionGroup.java @@ -0,0 +1,25 @@ +package com.quantum.view.driver; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.actions.SelectionListenerAction; + + +/** + * @author BC Holmes + */ +class JDBCDriverViewActionGroup extends ActionGroup { + + private SelectionListenerAction deleteAction; + + public JDBCDriverViewActionGroup(JDBCDriverView view, ISelectionProvider selectionProvider) { + this.deleteAction = new DeleteDriverAction(view, selectionProvider); + } + + public void fillActionBars(IActionBars actionBars) { + actionBars.setGlobalActionHandler( + IWorkbenchActionConstants.DELETE, this.deleteAction); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ChangeEncodingAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ChangeEncodingAction.java new file mode 100644 index 0000000..713f980 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ChangeEncodingAction.java @@ -0,0 +1,39 @@ +package com.quantum.view.tableview; + +import java.sql.SQLException; + +import com.quantum.Messages; +import com.quantum.sql.SQLResultSetResults; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IViewPart; + + +/** + * @author BC + */ +public class ChangeEncodingAction extends ResultSetAction { + + private final String encoding; + + /** + * @param view + * @param selectionProvider + */ + public ChangeEncodingAction(IViewPart view, ISelectionProvider selectionProvider, String encoding, String key) { + super(view, selectionProvider); + this.encoding = encoding; + setText(Messages.getString(getClass(), key)); + setToolTipText(Messages.getString(getClass(), key)); + } + + /* (non-Javadoc) + * @see com.quantum.view.tableview.ResultSetAction#executeResultSetAction(com.quantum.sql.SQLResultSetResults) + */ + protected void executeResultSetAction(SQLResultSetResults results) + throws SQLException { + results.setEncoding(this.encoding); + results.refresh(getConnection(results)); + } + +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CloseAllResultSetsAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CloseAllResultSetsAction.java new file mode 100644 index 0000000..af300bf --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CloseAllResultSetsAction.java @@ -0,0 +1,44 @@ +package com.quantum.view.tableview; + + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.sql.SQLResultSetCollection; +import com.quantum.util.versioning.VersioningHelper; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.SelectionListenerAction; + +/** + * @author root + * + */ +public class CloseAllResultSetsAction extends SelectionListenerAction { + private final ISelectionProvider selectionProvider; + /** + * @param text + */ + public CloseAllResultSetsAction(IViewPart view, ISelectionProvider selectionProvider) { + super("Close All"); + this.selectionProvider = selectionProvider; + this.selectionProvider.addSelectionChangedListener(this); + setEnabled(!this.selectionProvider.getSelection().isEmpty()); + + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.CLOSE_ALL)); + if (VersioningHelper.isEclipse30()) { + setDisabledImageDescriptor(ImageStore.getImageDescriptor(ImageStore.CLOSE_ALL_DISABLED)); + } + setText(Messages.getString(getClass(), "text")); + setToolTipText(Messages.getString(getClass(), "text")); + } + + public void run() { + SQLResultSetCollection.getInstance().removeAllSQLResultSet(); + } + + public boolean updateSelection(IStructuredSelection selection) { + return !selection.isEmpty(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CloseResultSetAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CloseResultSetAction.java new file mode 100644 index 0000000..facbea1 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CloseResultSetAction.java @@ -0,0 +1,54 @@ +package com.quantum.view.tableview; + + +import java.util.Iterator; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.sql.SQLResultSetCollection; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.util.versioning.VersioningHelper; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.SelectionListenerAction; + +/** + * @author root + * @author BC Holmes + */ +public class CloseResultSetAction extends SelectionListenerAction { + + private final ISelectionProvider selectionProvider; + + /** + * @param text + */ + public CloseResultSetAction(IViewPart view, ISelectionProvider selectionProvider) { + super(""); + this.selectionProvider = selectionProvider; + this.selectionProvider.addSelectionChangedListener(this); + setEnabled(!this.selectionProvider.getSelection().isEmpty()); + + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.CLOSE)); + if (VersioningHelper.isEclipse30()) { + setDisabledImageDescriptor(ImageStore.getImageDescriptor(ImageStore.CLOSE_DISABLED)); + } + setToolTipText(Messages.getString(getClass(), "text")); + } + + public void run() { + IStructuredSelection selection = + (IStructuredSelection) this.selectionProvider.getSelection(); + if (!selection.isEmpty()) { + for (Iterator i = selection.iterator(); i.hasNext(); ) { + SQLResultSetCollection.getInstance().removeSQLResultSet((SQLResultSetResults) i.next()); + } + } + } + + public boolean updateSelection(IStructuredSelection selection) { + return !selection.isEmpty(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CopyAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CopyAction.java new file mode 100644 index 0000000..3de9c5c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/CopyAction.java @@ -0,0 +1,54 @@ +/* + * Created on 28-jul-2003 + * + */ +package com.quantum.view.tableview; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.QuantumPlugin; + +import org.eclipse.jface.action.Action; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + + +public final class CopyAction extends Action { + + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + + private final TableView view; + + public CopyAction(TableView view) { + super(); + this.view = view; + setText(Messages.getString(getClass(), "text")); + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.COPY)); + } + + public void run() { + Table table = getTable(); + if (table != null) { + TableItem items[] = table.getSelection(); + StringBuffer text = new StringBuffer(); + for (int i = 0; i < items.length; i++) { + int columns = table.getColumnCount(); + for (int col = 0; col < columns; col++) { + text.append(items[i].getText(col)); + text.append('\t'); + } + text.append(LINE_SEPARATOR); + } + QuantumPlugin.getDefault().getSysClip().setContents( + new Object[] { text.toString()}, + new Transfer[] { TextTransfer.getInstance()}); + } + } + + private Table getTable() { + ResultSetViewer viewer = this.view.getSelectedResultSetViewer(); + return viewer == null ? null : viewer.getTable(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/FullModeAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/FullModeAction.java new file mode 100644 index 0000000..9c3c26c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/FullModeAction.java @@ -0,0 +1,41 @@ +package com.quantum.view.tableview; + +import java.sql.SQLException; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.sql.Scrollable; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewPart; + + +/** + * @author BC + */ +public class FullModeAction extends ResultSetAction { + + /** + * @param view + * @param selectionProvider + */ + public FullModeAction(IViewPart view, ISelectionProvider selectionProvider) { + super(view, selectionProvider); + setText(Messages.getString(getClass(), "text")); + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.FULLDATA)); + setToolTipText(Messages.getString(getClass(), "text")); + } + + protected void executeResultSetAction(SQLResultSetResults results) throws SQLException { + ((Scrollable) results).setFullMode(!((Scrollable) results).isFullMode()); + results.refresh(getConnection(results)); + } + + + protected boolean updateSelection(IStructuredSelection selection) { + return super.updateSelection(selection) + && (selection.getFirstElement() instanceof Scrollable); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/NextPageAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/NextPageAction.java new file mode 100644 index 0000000..75693d9 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/NextPageAction.java @@ -0,0 +1,81 @@ +package com.quantum.view.tableview; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.sql.SQLException; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.sql.Scrollable; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewPart; + + +/** + * @author BC + */ +public class NextPageAction extends ResultSetAction implements PropertyChangeListener { + + private SQLResultSetResults resultSet; + + public NextPageAction(IViewPart view, ISelectionProvider selectionProvider) { + super(view, selectionProvider); + setText(Messages.getString(getClass(), "text")); + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.NEXT)); + setToolTipText(Messages.getString(getClass(), "text")); + setEnabled(hasNextPage((IStructuredSelection) selectionProvider.getSelection())); + } + + protected void executeResultSetAction(SQLResultSetResults results) throws SQLException { + if (results instanceof Scrollable) { + ((Scrollable) results).nextPage(getConnection(results)); + } + } + protected boolean updateSelection(IStructuredSelection selection) { + setResultSet(getResultSet(selection)); + return hasNextPage(selection); + } + + /** + * @param srollable + */ + private void setResultSet(SQLResultSetResults results) { + if (this.resultSet != null) { + this.resultSet.removePropertyChangeListener(this); + } + + this.resultSet = results; + if (results != null) { + this.resultSet.addPropertyChangeListener(this); + } + } + + /** + * @param selection + */ + private SQLResultSetResults getResultSet(IStructuredSelection selection) { + return (selection != null && !selection.isEmpty() && + (selection.getFirstElement() instanceof SQLResultSetResults)) + ? (SQLResultSetResults) selection.getFirstElement() + : null; + } + + /** + * @param selection + * @return + */ + private boolean hasNextPage(IStructuredSelection selection) { + return !selection.isEmpty() && + (selection.getFirstElement() instanceof Scrollable) && + ((Scrollable) selection.getFirstElement()).hasNextPage(); + } + + public void propertyChange(PropertyChangeEvent event) { + if ("rows".equals(event.getPropertyName())) { + setEnabled(hasNextPage(getStructuredSelection())); + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/PreviousPageAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/PreviousPageAction.java new file mode 100644 index 0000000..25ebe0a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/PreviousPageAction.java @@ -0,0 +1,82 @@ +package com.quantum.view.tableview; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.sql.SQLException; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.sql.Scrollable; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewPart; + + +/** + * @author BC + */ +public class PreviousPageAction extends ResultSetAction implements PropertyChangeListener { + + private SQLResultSetResults resultSet; + + public PreviousPageAction(IViewPart view, ISelectionProvider selectionProvider) { + super(view, selectionProvider); + setText(Messages.getString(getClass(), "text")); + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.PREVIOUS)); + setToolTipText(Messages.getString(getClass(), "text")); + setEnabled(hasPreviousPage((IStructuredSelection) selectionProvider.getSelection())); + } + + protected void executeResultSetAction(SQLResultSetResults results) throws SQLException { + if (results instanceof Scrollable) { + ((Scrollable) results).previousPage(getConnection(results)); + } + } + protected boolean updateSelection(IStructuredSelection selection) { + setResultSet(getResultSet(selection)); + return hasPreviousPage(selection); + } + + /** + * @param srollable + */ + private void setResultSet(SQLResultSetResults results) { + if (this.resultSet != null) { + this.resultSet.removePropertyChangeListener(this); + } + + this.resultSet = results; + if (results != null) { + this.resultSet.addPropertyChangeListener(this); + } + } + + /** + * @param selection + */ + private SQLResultSetResults getResultSet(IStructuredSelection selection) { + return (selection != null && !selection.isEmpty() && + (selection.getFirstElement() instanceof SQLResultSetResults)) + ? (SQLResultSetResults) selection.getFirstElement() + : null; + } + + /** + * @param selection + * @return + */ + private boolean hasPreviousPage(IStructuredSelection selection) { + return !selection.isEmpty() && + (selection.getFirstElement() instanceof Scrollable) && + ((Scrollable) selection.getFirstElement()).hasPreviousPage(); + } + + public void propertyChange(PropertyChangeEvent event) { + if ("rows".equals(event.getPropertyName())) { + setEnabled(hasPreviousPage(getStructuredSelection())); + } + } + +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/RefreshTableAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/RefreshTableAction.java new file mode 100644 index 0000000..1a8e2d4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/RefreshTableAction.java @@ -0,0 +1,33 @@ +package com.quantum.view.tableview; + +import java.sql.SQLException; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.sql.SQLResultSetResults; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IViewPart; + +/** + * Implements the "Refresh Table" action for the TableView view + * + * @author root + */ +public class RefreshTableAction extends ResultSetAction { + + /** + * @param view + * @param selectionProvider + */ + public RefreshTableAction(IViewPart view, ISelectionProvider selectionProvider) { + super(view, selectionProvider); + setText(Messages.getString(getClass(), "text")); + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.REFRESH)); + setToolTipText(Messages.getString(getClass(), "text")); + } + + protected void executeResultSetAction(SQLResultSetResults results) throws SQLException { + results.refresh(getConnection(results)); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ResultSetAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ResultSetAction.java new file mode 100644 index 0000000..03a7f55 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ResultSetAction.java @@ -0,0 +1,72 @@ +package com.quantum.view.tableview; + +import java.sql.Connection; +import java.sql.SQLException; + +import com.quantum.sql.SQLResultSetResults; +import com.quantum.ui.dialog.ExceptionDisplayDialog; +import com.quantum.util.connection.ConnectionUtil; + +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.SelectionListenerAction; + +/** + * @author BC Holmes + */ +public abstract class ResultSetAction extends SelectionListenerAction { + private IViewPart view; + private ConnectionUtil connectionUtil = new ConnectionUtil(); + private final ISelectionProvider selectionProvider; + + /** + * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart) + */ + public ResultSetAction(IViewPart view, ISelectionProvider selectionProvider) { + super(""); + this.selectionProvider = selectionProvider; + this.view = view; + this.selectionProvider.addSelectionChangedListener(this); + } + + public void run() { + try { + IStructuredSelection selection = + (IStructuredSelection) this.selectionProvider.getSelection(); + if (!selection.isEmpty()) { + SQLResultSetResults results = (SQLResultSetResults) selection.getFirstElement(); + executeResultSetAction(results); + } + } catch (SQLException e) { + ExceptionDisplayDialog.openError(getShell(), null, null, e); + } catch (RuntimeException e) { + ExceptionDisplayDialog.openError(getShell(), null, null, e); + } + } + + protected boolean updateSelection(IStructuredSelection selection) { + return selection != null && !selection.isEmpty(); + } + /** + * @param results + * @throws SQLException + */ + protected abstract void executeResultSetAction(SQLResultSetResults results) throws SQLException; + + /** + * @param results + * @return + */ + protected Connection getConnection(SQLResultSetResults results) { + return this.connectionUtil.connect(results.getBookmark(), getShell()); + } + + /** + * @return + */ + private Shell getShell() { + return this.view.getSite().getShell(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ResultSetViewer.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ResultSetViewer.java new file mode 100644 index 0000000..fccbc9c --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/ResultSetViewer.java @@ -0,0 +1,246 @@ +package com.quantum.view.tableview; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.sql.Scrollable; + +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; + +/** + * @author BC + */ +class ResultSetViewer implements PropertyChangeListener { + + class LabelProviderImpl implements ITableLabelProvider { + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + public String getColumnText(Object element, int columnIndex) { + Object value = null; + if (element instanceof SQLResultSetResults.Row) { + value = ((SQLResultSetResults.Row) element).get(columnIndex+1); + } + return value == null ? "" : value.toString(); + } + public void addListener(ILabelProviderListener listener) { + } + public void dispose() { + } + public boolean isLabelProperty(Object element, String property) { + return false; + } + public void removeListener(ILabelProviderListener listener) { + } + } + + class ContentProviderImpl implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + if (inputElement instanceof SQLResultSetResults) { + return ((SQLResultSetResults) inputElement).getRows(); + } else { + return null; + } + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + } + + + private final SQLResultSetResults resultSet; + private TableViewer tableViewer; + private TabItem tabItem; + private final TableView tableView; + + public ResultSetViewer(TableView tableView, SQLResultSetResults resultSet) { + this.tableView = tableView; + this.resultSet = resultSet; + + createControl(); + + this.resultSet.addPropertyChangeListener(this); + } + + protected TabItem getTabItem() { + return this.tabItem; + } + + public Table getTable() { + return this.tableViewer.getTable(); + } + + protected void createControl() { + this.tabItem = new TabItem(this.tableView.tabs, SWT.NONE); + + int index = this.tableView.tabs.getItems().length; + Composite composite = new Composite(this.tableView.tabs, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginWidth = 5; + layout.marginHeight = 5; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + if (this.resultSet.getEntity() == null) { + this.tabItem.setImage(ImageStore.getImage(ImageStore.SCRIPT)); + this.tabItem.setText(this.resultSet.getBookmark().getName()); + this.tabItem.setToolTipText(this.resultSet.getQuery()); + } else if (this.resultSet.isMetaData()) { + this.tabItem.setImage(ImageStore.getImage(ImageStore.TABLE_DETAILS)); + this.tabItem.setText(this.resultSet.getBookmark().getName() + ":" + + this.resultSet.getEntity().getQualifiedName()); + tabItem.setToolTipText(this.resultSet.getEntity().getQualifiedName()); + } else { + this.tabItem.setImage(ImageStore.getImage(ImageStore.TABLE)); + this.tabItem.setText(this.resultSet.getBookmark().getName() + ":" + + this.resultSet.getEntity().getQualifiedName()); + this.tabItem.setToolTipText(this.resultSet.getEntity().getQualifiedName()); + } + + createTable(composite); + this.tabItem.setControl(composite); + initializePopUpMenu(); + + this.tableView.tabs.setSelection(index-1); + } + + + /** + * @param tabItem + * @param composite + */ + private void createTable(Composite composite) { + final Table table = new Table(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER); + table.setLayout(new GridLayout()); + table.setLayoutData(new GridData(GridData.FILL_BOTH)); + + addColumnsToTable(table); + this.tableViewer = new TableViewer(table); + this.tableViewer.setLabelProvider(new LabelProviderImpl()); + this.tableViewer.setContentProvider(new ContentProviderImpl()); + this.tableViewer.setInput(this.resultSet); + + packColumns(table); + } + + /** + * @param table + */ + private void packColumns(final Table table) { + for (int i = 0; i < table.getColumnCount(); i++) { + table.getColumn(i).pack(); + } + } + + /** + * @param table + * @return + */ + private int addColumnsToTable(final Table table) { + table.setHeaderVisible(true); + table.setLinesVisible(true); + int columnCount = this.resultSet.getColumnCount(); + for (int i = 0; i < columnCount; i++) { + TableColumn column = new TableColumn(table, SWT.NONE); + column.setText(this.resultSet.getColumnName(i+1).toString()); + } + return columnCount; + } + + public void propertyChange(PropertyChangeEvent event) { + if ("rows".equals(event.getPropertyName())) { + this.tableViewer.refresh(); + } else if ("columns".equals(event.getPropertyName())) { + Table table = this.tableViewer.getTable(); + TableColumn[] columns = table.getColumns(); + for (int i = 0, length = columns == null ? 0 : columns.length; i < length; i++) { + columns[i].dispose(); + } + addColumnsToTable(table); + this.tableViewer.setInput(this.resultSet); + packColumns(table); + table.layout(); + } + updateStatusLine(); + } + + public void dispose() { + this.resultSet.removePropertyChangeListener(this); + this.tabItem.dispose(); + } + + protected SQLResultSetResults getResultSet() { + return this.resultSet; + } + + private void initializePopUpMenu() { + MenuManager manager = new MenuManager(); + manager.setRemoveAllWhenShown(true); + manager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager menuManager) { + ResultSetViewer.this.tableView.actionGroup.fillContextMenu(menuManager); + } + }); + Menu contextMenu = manager.createContextMenu(this.tableViewer.getControl()); + this.tableViewer.getControl().setMenu(contextMenu); + // register the menu to the site so that we can allow + // actions to be plugged in + this.tableView.getSite().registerContextMenu(manager, this.tableView); + } + + /** + * + */ + protected void updateStatusLine() { + + if (this == this.tableView.getSelectedResultSetViewer()) { + IStatusLineManager statusLine = this.tableView.getViewSite().getActionBars().getStatusLineManager(); + if (this.resultSet != null && this.resultSet instanceof Scrollable) { + Scrollable scrollable = (Scrollable) this.resultSet; + int start = scrollable.getStart(); + int end = scrollable.getEnd(); + int last = scrollable.getLast(); + + statusLine.setMessage( + Messages.getString(getClass(), "position", + new String[] { + String.valueOf(start), + String.valueOf(end), + last < 0 + ? Messages.getString(getClass(), "unknown") + : String.valueOf(last)})); + } else { + statusLine.setMessage(""); + } + } + } + + protected ISelection getSelection() { + return this.tableViewer.getSelection(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/SelectAllAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/SelectAllAction.java new file mode 100644 index 0000000..b95208a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/SelectAllAction.java @@ -0,0 +1,33 @@ +/* + * Created on 28-jul-2003 + * + */ +package com.quantum.view.tableview; + +import com.quantum.Messages; + +import org.eclipse.jface.action.Action; +import org.eclipse.swt.widgets.Table; + + +public final class SelectAllAction extends Action { + + private final TableView view; + + public SelectAllAction(TableView view) { + super(); + this.view = view; + setText(Messages.getString(getClass(), "text")); + } + public void run() { + Table table = getTable(); + if (table != null) { + table.selectAll(); + } + } + + private Table getTable() { + ResultSetViewer viewer = this.view.getSelectedResultSetViewer(); + return viewer == null ? null : viewer.getTable(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableAdapter.java deleted file mode 100644 index e65c9d0..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableAdapter.java +++ /dev/null @@ -1,265 +0,0 @@ -package com.quantum.view.tableview; - -import java.sql.SQLException; -import java.util.Vector; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; - -import com.quantum.Messages; -import com.quantum.adapters.DatabaseAdapter; -import com.quantum.model.Bookmark; -import com.quantum.model.Entity; -import com.quantum.model.NotConnectedException; -import com.quantum.sql.FilterSort; -import com.quantum.sql.SQLHelper; -import com.quantum.sql.SQLResults; - -public class TableAdapter { - - public static final String DEFAULT = ""; //$NON-NLS-1$ - public static final String UTF_8 = "UTF-8"; //$NON-NLS-1$ - public static final String UTF_16 = "UTF-16"; //$NON-NLS-1$ - - private int pageSize = DefaultSizes.PAGE_SIZE; - private int maxColumnSize = DefaultSizes.MAX_COLUMN_SIZE; - private FilterSort extra = new FilterSort(); - private int offset = 1; - private int totalSize = -1; - private Vector rows = new Vector(); - private Vector columnNames = new Vector(); - private boolean hasMore = false; - - private Bookmark bookmark = null; - private Entity entity = null; - private String query; - - private String encoding = ""; //$NON-NLS-1$ - - private TableAdapter(Entity entity) { - this.entity = entity; - this.bookmark = entity.getBookmark(); - } - private TableAdapter(Bookmark bookmark) { - this.bookmark = bookmark; - } - public void fullMode() { - offset = 1; - pageSize = Integer.MAX_VALUE; - } - public void resetMode() { - offset = 1; - pageSize = DefaultSizes.PAGE_SIZE; - } - public static TableAdapter createFromQuery(Bookmark bookmark, SQLResults results) throws NotConnectedException { - TableAdapter retVal = new TableAdapter(bookmark); - retVal.setQuery(results.getQuery()); - retVal.setData(results); - return retVal; - } - public static TableAdapter createFromTable(Entity entity) { - TableAdapter retVal = new TableAdapter(entity); - return retVal; - } - private void loadSize() { - try { - if (entity != null) { - totalSize = SQLHelper.getSize( - bookmark.getConnection(), entity.getQualifiedName(), - bookmark.getAdapter()); - } - } catch (SQLException e) { - e.printStackTrace(); - } catch (NotConnectedException e) { - e.printStackTrace(); - } - } - public int getStartIndex() { - if (totalSize == 0) { - return 0; - } - return offset; - } - public int getEndIndex() { - return offset + rows.size() - 1; - } - public int getTotalSize() { - return totalSize; - } - public void nextPage() { - loadSize(); - offset = offset + pageSize; - if (totalSize >= 0 && offset > totalSize) { - offset = offset - pageSize; - } - } - public void previousPage() { - offset = offset - pageSize; - if (offset < 1) { - offset = 1; - } - } - public boolean hasNextPage() { - if (entity != null) { - if (offset + pageSize <= totalSize) { - return true; - } - return false; - } - return hasMore; - } - public boolean hasPreviousPage() { - if (offset > 1) { - return true; - } - return false; - } - - public String getQuery() { - if (entity != null) { - DatabaseAdapter adapter = bookmark.getAdapter(); - if (adapter == null) throw new RuntimeException(); - else return adapter.getTableQuery((entity).getQualifiedName()) + extra.toString(); - } - return query; - } - public void loadData() throws NotConnectedException { - loadSize(); - if (entity != null) { - if (offset > totalSize) { - offset = 1; - } - } - String query = getQuery(); - System.out.println(offset + Messages.getString("TableAdapter.to") + (offset + pageSize - 1)); //$NON-NLS-1$ - SQLResults results = SQLHelper.getResults(bookmark.getConnection(), query, offset, offset + pageSize - 1, maxColumnSize, encoding); - setData(results); - } - public void resetOffset() { - offset = 1; - } - public void setData(SQLResults results) throws NotConnectedException { - if (results.isError()) return; - int rowCount = results.getRowCount(); - int columnCount = results.getColumnCount(); - rows = new Vector(); - columnNames = new Vector(); - for (int col = 1; col <= columnCount; col++) { - columnNames.addElement(results.getColumnName(col)); - } - for (int row = 1; row <= rowCount; row++) { - String rowData[] = new String[columnCount]; - for (int col = 1; col <= columnCount; col++) { - rowData[col - 1] = results.getElement(col, row).toString(); - } - rows.addElement(rowData); - } - hasMore = results.hasMore(); - if (entity == null && results.getMaxSize() >= 0) { - if (offset > results.getMaxSize()) { - offset = 1; - loadData(); - } - } - } - public void loadTable(Table table) { - table.setHeaderVisible(true); - for (int i = 0; i < columnNames.size(); i++) { - TableColumn column = new TableColumn(table, SWT.NONE); - column.setText(columnNames.elementAt(i).toString()); - } - for (int i = 0; i < columnNames.size(); i++) { - table.getColumn(i).pack(); - } - for (int row = 0; row < rows.size(); row++) { - TableItem item = new TableItem(table, SWT.NONE); - String itemData[] = (String[]) rows.elementAt(row); - item.setText(itemData); - } - for (int i = 0; i < columnNames.size(); i++) { - table.getColumn(i).pack(); - } - } - -// public TableViewer addTableViewer(Table table) { -// TableViewer tableViewer = new TableViewer(table); -// tableViewer.setUseHashlookup(true); -// String[] colNams = new String[columnNames.size()]; -// for (int i = 0; i < columnNames.size(); i++) { -// colNams[i] = (String) columnNames.get(i); -// } -// tableViewer.setColumnProperties(colNams); -// -// // Create the cell editors -// CellEditor[] editors = new CellEditor[columnNames.size()]; -// for (int i = 0; i < columnNames.size(); i++) { -// TextCellEditor textEditor = new TextCellEditor(table); -// ((Text) textEditor.getControl()).setTextLimit(60); -// editors[i] = textEditor; -// } -// // Assign the cell editors to the viewer -// tableViewer.setCellEditors(editors); -// // Set the cell modifier for the viewer -// //tableViewer.setCellModifier(new MetaDataModifier(this)); -// // Set the default sorter for the viewer -// //tableViewer.setSorter(new ExampleTaskSorter(ExampleTaskSorter.DESCRIPTION)); -// -// return tableViewer; -// } - - public int getPageSize() { - return pageSize; - } - - public void setFilterSort(FilterSort extra) { - this.extra = extra; - } - public String getTable() { - return (entity != null) ? entity.getQualifiedName() : null; - } - - public void setQuery(String query) { - this.query = query; - } - public String getEncoding() { - return encoding; - } - - public void setEncoding(String encoding) { - this.encoding = encoding; - } - public String getStatusString() { - String status = getStartIndex() + Messages.getString("TableAdapter.to") + getEndIndex() + Messages.getString("TableAdapter.of") + //$NON-NLS-1$ //$NON-NLS-2$ - getTotalSize(); - if (!encoding.equals(DEFAULT)) { - status += " (" + encoding + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } - String filterText = extra.toString(); - if (!filterText.equals("")) { //$NON-NLS-1$ - status += " (" + filterText + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } - if (pageSize == Integer.MAX_VALUE) { - status += Messages.getString("TableAdapter.full"); //$NON-NLS-1$ - } - return status; - } - /** - * @return - */ - public Bookmark getBookmark() { - return this.bookmark; - } - /** - * @return - */ - public Entity getEntity() { - return entity; - } - -} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableView.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableView.java index c9b151a..9351717 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableView.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableView.java @@ -1,66 +1,60 @@ package com.quantum.view.tableview; -import java.util.Vector; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; -import com.quantum.Messages; import com.quantum.QuantumPlugin; -import com.quantum.extensions.ProcessServiceMembers; -import com.quantum.model.Bookmark; -import com.quantum.model.Entity; -import com.quantum.model.NotConnectedException; -import com.quantum.sql.SQLResults; -import com.quantum.ui.dialog.ExceptionDisplayDialog; -import com.quantum.view.LogProxy; +import com.quantum.sql.SQLResultSetCollection; +import com.quantum.sql.SQLResultSetResults; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.IActionBars; import org.eclipse.ui.part.ViewPart; /** * The Table View. Displays tables and Queries. */ -public class TableView extends ViewPart implements ISelectionListener { +public class TableView extends ViewPart implements ISelectionProvider, PropertyChangeListener { - private class DefaultEncodingAction extends Action { - private final TableAdapter ta; - private DefaultEncodingAction(TableAdapter ta) { - super(); - this.ta = ta; - } - public void run() { - ta.setEncoding(TableAdapter.DEFAULT); - } - } - private TabFolder tabs = null; - private Composite parent; - private Vector extensionVector; + protected TabFolder tabs = null; + + private Set listeners = Collections.synchronizedSet(new HashSet()); + + protected List resultSetViewers = Collections.synchronizedList(new ArrayList()); + protected TableViewActionGroup actionGroup; /** * Generic contructor */ public TableView() { + SQLResultSetCollection.getInstance().addPropertyChangeListener(this); } public void setFocus() { - setQualifiedTitle(); + } + + public void dispose() { + SQLResultSetCollection.getInstance().removePropertyChangeListener(this); + super.dispose(); } /** @@ -74,212 +68,157 @@ public class TableView extends ViewPart implements ISelectionListener { return (TableView) QuantumPlugin.getDefault().getView("com.quantum.view.tableview.TableView"); } - /** - * Close the current tab, disposing of it - */ - public void closeCurrent() { - if (tabs == null) return; - - if (tabs.getSelectionIndex() >= 0) { - try { - TabItem item = tabs.getItem(tabs.getSelectionIndex()); - item.dispose(); - } catch (Throwable e) { - LogProxy.getInstance().addText(LogProxy.ERROR, "Error Closing Current: " + e.toString()); //$NON-NLS-1$ - e.printStackTrace(); + public void createPartControl(Composite parent) { + this.tabs = new TabFolder(parent, SWT.NONE); + this.tabs.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + fireSelectionChangedEvent(); } - } - if (tabs.getItemCount() == 0) { - setTitle(Messages.getString("tableview.QuantumTableViewName")); //$NON-NLS-1$ + }); + + SQLResultSetResults[] resultSets = SQLResultSetCollection.getInstance().getResultSets(); + for (int i = 0, length = resultSets == null ? 0 : resultSets.length; i < length; i++) { + this.resultSetViewers.add(new ResultSetViewer(this, resultSets[i])); } + + initActions(); + } + + public void initActions() { + + this.actionGroup = new TableViewActionGroup(this); + + IActionBars actionBars = getViewSite().getActionBars(); + this.actionGroup.fillActionBars(actionBars); + } + + public void addSelectionChangedListener(ISelectionChangedListener listener) { + this.listeners.add(listener); } + protected void fireSelectionChangedEvent() { + ISelection selection = getSelection(); + for (Iterator i = this.listeners.iterator(); i.hasNext();) { + ISelectionChangedListener listener = (ISelectionChangedListener) i.next(); + listener.selectionChanged(new SelectionChangedEvent(this, selection)); + } + + ResultSetViewer results = getSelectedResultSetViewer(); + if (results != null) { + results.updateStatusLine(); + } else { + getViewSite().getActionBars().getStatusLineManager().setMessage(""); + } + } + + public ISelection getSelection() { + SQLResultSetResults selection = getSelectedResultSet(); + return selection == null + ? new StructuredSelection() + : new StructuredSelection(selection); + } + /** - * Reload table or query data into the selected tab + * @return */ - public void refreshCurrent() { -System.out.println("Refresh?"); - if (tabs.getSelectionIndex() >= 0) { -System.out.println("Refresh!"); - TabItem item = tabs.getItem(tabs.getSelectionIndex()); - TableAdapter adapter = (TableAdapter) item.getData(); - Bookmark bookmark = adapter.getBookmark(); - String table = adapter.getTable(); - if (table == null) { - loadTable(bookmark, item, null, null, true, true); - } else { - loadTable(bookmark, item, null, null, true, true); + protected SQLResultSetResults getSelectedResultSet() { + ResultSetViewer viewer = getSelectedResultSetViewer(); + return viewer == null ? null : viewer.getResultSet(); + } + + protected ResultSetViewer getSelectedResultSetViewer() { + ResultSetViewer selection = null; + int index = this.tabs.getSelectionIndex(); + if (index >= 0) { + TabItem item = this.tabs.getItem(index); + for (Iterator i = this.resultSetViewers.iterator(); + selection == null && i.hasNext();) { + ResultSetViewer viewer = (ResultSetViewer) i.next(); + if (item == viewer.getTabItem()) { + selection = viewer; + } } - String title = Messages.getString("tableview.QuantumTableViewName"); //$NON-NLS-1$ - if (bookmark != null) - title = bookmark.getName() + Messages.getString("tableview.ViewNameInitialDecoration") + title + Messages.getString("tableview.ViewNameFinalDecoration"); //$NON-NLS-1$ //$NON-NLS-2$ - setTitle(title); } + return selection; } - - public void loadQuery(Bookmark bookmark, SQLResults results) { - loadTable(bookmark, null, null, results, true, false); - } - public void loadTable(Entity entity) { - loadTable(entity.getBookmark(), null, entity, null, false, true); + + + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + this.listeners.remove(listener); } - public void loadTable(Bookmark bookmark, TabItem tabItem, Entity entity, SQLResults results, boolean query, boolean reload) { - try { - TableAdapter adapter; - // If no TabItem is given we have to create a new one, with the info of the table or view. - if (tabItem == null) { - tabItem = new TabItem(tabs, SWT.NONE); - // Data is stored in a TableAdapter object - if (query) { - adapter = TableAdapter.createFromQuery(bookmark, results); - } else { - adapter = TableAdapter.createFromTable(entity); - } - // That is stored in the tabItem, so it won't get lost - tabItem.setData(adapter); - // This does not really belong here, but it'll fail if done before the creation of the - // first TabItem, so it remains here till a better place found. - // We set a function to change the Title of the window depending on the selected tab. - tabs.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - setQualifiedTitle(); - } - }); - } else { - // If there is already a TabItem, we take its TableAdapter object - adapter = (TableAdapter) tabItem.getData(); - } - - // We create a Composite widget (main) to display our data, with a GridLayout - Composite main = new Composite(tabs, SWT.NONE); - GridLayout layout = new GridLayout(1, false); - layout.horizontalSpacing = 0; - layout.verticalSpacing = 0; - main.setLayout(layout); - - - // load widgets, the order of loading them determines the appearance in screen - ToolBar widgetToolBar = new ToolBar(main, SWT.HORIZONTAL); - // We fill up our Composite widget, the main table display, etc. - final Table table = new Table(main, SWT.FULL_SELECTION | SWT.MULTI); - final Label label = new Label(main, SWT.NULL); - TableViewToolBar toolBar = new TableViewToolBar(this, widgetToolBar, table, adapter, label); - - - // load table - if (reload) { - adapter.resetOffset(); - adapter.loadData(); - } - // Load the table data from the adapter into the widget - adapter.loadTable(table); - // Experimental, won't make it into 2.2 - // final TableViewer viewer = adapter.addTableViewer(table); - - String tableName = adapter.getTable(); - if (tableName != null) { - tabItem.setText(bookmark.getName() + ":" + tableName); - } else { - tabItem.setText(bookmark.getName() + ": SQL"); - tabItem.setToolTipText(bookmark.getName() + ":\n" + adapter.getQuery()); - } - - toolBar.getPrevious().setEnabled(adapter.hasPreviousPage()); - toolBar.getNext().setEnabled(adapter.hasNextPage()); - label.setText(adapter.getStatusString()); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - table.setLayoutData(gridData); - - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - label.setLayoutData(gridData); - - - toolBar.setColumns(this, adapter, table); - final TableAdapter ta = adapter; - final Action defaultEncodingAction = new DefaultEncodingAction(ta); - defaultEncodingAction.setText(Messages.getString("tableview.defaultEncoding")); //$NON-NLS-1$ - final Action UTF8EncodingAction = new Action() { - public void run() { - ta.setEncoding(TableAdapter.UTF_8); - } - }; - UTF8EncodingAction.setText(Messages.getString("tableview.UTF8Encoding")); //$NON-NLS-1$ - final Action UTF16EncodingAction = new Action() { - public void run() { - ta.setEncoding(TableAdapter.UTF_16); - } - }; - UTF16EncodingAction.setText(Messages.getString("tableview.UTF16Encoding")); //$NON-NLS-1$ - - IMenuListener menuListener = new TableViewMenuListener(this, table, UTF16EncodingAction, ta, defaultEncodingAction, UTF8EncodingAction, extensionVector); - - // final setup - MenuManager manager = new MenuManager(); - manager.setRemoveAllWhenShown(true); - Menu fTextContextMenu = manager.createContextMenu(table); - table.setMenu(fTextContextMenu); - table.setLinesVisible(true); - manager.addMenuListener(menuListener); - - tabItem.setControl(main); - tabs.setSelection(tabs.indexOf(tabItem)); - - setQualifiedTitle(); - } catch (NotConnectedException e) { - e.printStackTrace(); - handleException(e); - } catch (Exception e) { - e.printStackTrace(); - } + + public void setSelection(ISelection selection) { } - - protected void handleException(Exception e) { - ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e); - } + public void propertyChange(PropertyChangeEvent event) { + if ("resultSets".equals(event.getPropertyName())) { + SQLResultSetResults selection = getSelectedResultSet(); + + Collection additions = getAddedResultSets(); + for (Iterator i = additions.iterator(); i.hasNext();) { + SQLResultSetResults results = (SQLResultSetResults) i.next(); + this.resultSetViewers.add(new ResultSetViewer(this, results)); + } + + Collection deletions = getRemovedResultSets(); + for (Iterator i = deletions.iterator(); i.hasNext();) { + SQLResultSetResults results = (SQLResultSetResults) i.next(); + + ResultSetViewer viewer = findViewerFor(results); + this.resultSetViewers.remove(viewer); + viewer.dispose(); + } + + SQLResultSetResults newSelection = getSelectedResultSet(); + if (selection != null && newSelection == null) { + fireSelectionChangedEvent(); + } else if (selection == null && newSelection != null) { + fireSelectionChangedEvent(); + } else if (selection != null && !selection.equals(newSelection)) { + fireSelectionChangedEvent(); + } + } + } + /** * @return */ - /** - * Sets the title of the window to the text of the selected tab - */ - private void setQualifiedTitle() { - if (tabs.getSelectionIndex() < 0) return; - TabItem item = tabs.getItem(tabs.getSelectionIndex()); - String defTitle = Messages.getString("tableview.QuantumTableViewName"); //$NON-NLS-1$ - String title = item.getText(); - int ind = title.indexOf(Messages.getString("tableview.BookmarkSeparator")); //$NON-NLS-1$ - if (ind > 0) defTitle = title.substring(0,ind) - + Messages.getString("tableview.ViewNameInitialDecoration") //$NON-NLS-1$ - + defTitle - + Messages.getString("tableview.ViewNameFinalDecoration"); //$NON-NLS-1$ - setTitle(defTitle); + private Collection getRemovedResultSets() { + SQLResultSetResults[] results = SQLResultSetCollection.getInstance().getResultSets(); + Collection collection = (results == null) + ? new ArrayList() + : new ArrayList(Arrays.asList(results)); + Collection visible = getResultSets(); + visible.removeAll(collection); + return visible; } - public void createPartControl(Composite parent) { - this.parent = parent; - initActions(); - tabs = new TabFolder(parent, SWT.NONE); + private Collection getAddedResultSets() { + SQLResultSetResults[] results = SQLResultSetCollection.getInstance().getResultSets(); + Collection collection = (results == null) + ? new ArrayList() + : new ArrayList(Arrays.asList(results)); + collection.removeAll(getResultSets()); + return collection; } - public void initActions() { - extensionVector = new Vector(); - try { - ProcessServiceMembers.process(this, extensionVector); - } catch (WorkbenchException e) { - e.printStackTrace(); + private Collection getResultSets() { + List list = new ArrayList(); + for (Iterator i = this.resultSetViewers.iterator(); i.hasNext();) { + ResultSetViewer viewer = (ResultSetViewer) i.next(); + list.add(viewer.getResultSet()); } - + return list; } - - public void selectionChanged(IWorkbenchPart part, ISelection selection) { + + private ResultSetViewer findViewerFor(SQLResultSetResults results) { + ResultSetViewer viewer = null; + for (Iterator i = this.resultSetViewers.iterator(); viewer == null && i.hasNext();) { + ResultSetViewer temp = (ResultSetViewer) i.next(); + if (results != null && results.equals(temp.getResultSet())) { + viewer = temp; + } + } + return viewer; } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableViewActionGroup.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableViewActionGroup.java new file mode 100644 index 0000000..c99c134 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableViewActionGroup.java @@ -0,0 +1,417 @@ +package com.quantum.view.tableview; + +import java.util.Iterator; +import java.util.Vector; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.actions.SelectionListenerAction; + +import com.quantum.ImageStore; +import com.quantum.Messages; +import com.quantum.extensions.ExtensionAction; +import com.quantum.extensions.ProcessServiceMembers; +import com.quantum.php.wizards.PHPDeleteRowPage; +import com.quantum.php.wizards.PHPInsertRowPage; +import com.quantum.php.wizards.PHPSelectRowPage; +import com.quantum.php.wizards.PHPUpdateRowPage; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.sql.TableRow; +import com.quantum.util.StringMatrix; +import com.quantum.wizards.DeleteRowPage; +import com.quantum.wizards.InsertRowPage; +import com.quantum.wizards.SQLPage; +import com.quantum.wizards.SQLRowWizard; +import com.quantum.wizards.SortFilterPage; +import com.quantum.wizards.UpdateRowPage; + + +/** + * @author Julen Parra + * @author BC Holmes + */ +public class TableViewActionGroup extends ActionGroup { + + abstract class SQLWizardAction extends SelectionListenerAction { + + /** + * @param text + */ + protected SQLWizardAction(String text, ISelectionProvider selectionProvider) { + super(text); + selectionProvider.addSelectionChangedListener(this); + setEnabled(!selectionProvider.getSelection().isEmpty()); + } + + protected abstract SQLPage createSQLPage(); + + protected abstract String getTitle(); + + public void run() { + SQLPage page = createSQLPage(); + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(getTitle(), page, getSelectedSQLResults(), getSelectedRow()); + WizardDialog dialog = new WizardDialog( + tableView.getSite().getShell(), wizard); + dialog.open(); + } + + protected boolean updateSelection(IStructuredSelection selection) { + return selection != null && !selection.isEmpty(); + } + }; + + class SortFilterAction extends SQLWizardAction { + + public SortFilterAction(ISelectionProvider selectionProvider) { + super(Messages.getString(TableViewActionGroup.class, "filterSort"), + selectionProvider); + setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.FILTER)); + setToolTipText(Messages.getString(TableViewActionGroup.class, "filterSort")); + setEnabled(sortFilterApplies()); + } + + private boolean sortFilterApplies() { + SQLResultSetResults results = getSelectedSQLResults(); + return results != null && !results.isMetaData() && results.getEntity() != null; + } + + protected SQLPage createSQLPage() { + return new SortFilterPage("page1"); + } + + protected String getTitle() { + return Messages.getString(TableViewActionGroup.class, "filterSortTitle"); + } + + protected boolean updateSelection(IStructuredSelection selection) { + return sortFilterApplies(); + } + } + + class PHPInsertAction extends Action { + public PHPInsertAction() { + setText(Messages.getString("tableview.phpinsert")); + } + + public void run() { + PHPInsertRowPage page = new PHPInsertRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.PHPInsertRow"), + page, getSelectedSQLResults(), null); //$NON-NLS-1$ + WizardDialog dialog = + new WizardDialog( + tableView.getSite().getShell(), + wizard); + dialog.open(); + } + }; + + class PHPDeleteAction extends Action { + public PHPDeleteAction() { + setText(Messages.getString("tableview.phpdelete")); + } + + public void run() { + PHPDeleteRowPage page = new PHPDeleteRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.PHPDeleteRow"), + page, getSelectedSQLResults(), getSelectedRow()); //$NON-NLS-1$ + WizardDialog dialog = + new WizardDialog( + tableView.getSite().getShell(), + wizard); + dialog.open(); + } + }; + class PHPSelectAction extends Action { + public PHPSelectAction() { + setText(Messages.getString("tableview.phpselect")); + } + + public void run() { + PHPSelectRowPage page = new PHPSelectRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.PHPSelectRow"), + page, getSelectedSQLResults(), getSelectedRow()); //$NON-NLS-1$ + WizardDialog dialog = + new WizardDialog( + tableView.getSite().getShell(), + wizard); + dialog.open(); + } + }; + class PHPUpdateAction extends Action { + public PHPUpdateAction() { + setText(Messages.getString("tableview.phpupdate")); + } + + public void run() { + PHPUpdateRowPage page = new PHPUpdateRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.PHPUpdateRow"), + page, getSelectedSQLResults(), getSelectedRow()); //$NON-NLS-1$ + WizardDialog dialog = + new WizardDialog( + tableView.getSite().getShell(), + wizard); + dialog.open(); + } + }; + class InsertAction extends Action { + public InsertAction() { + setText(Messages.getString("tableview.insert")); + } + + public void run() { + InsertRowPage page = new InsertRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.InsertRow"), + page, getSelectedSQLResults(), null); //$NON-NLS-1$ + WizardDialog dialog = + new WizardDialog( + tableView.getSite().getShell(), + wizard); + dialog.open(); + } + }; + + class DeleteAction extends Action { + public DeleteAction() { + setText(Messages.getString("tableview.delete")); + } + + public void run() { + DeleteRowPage page = new DeleteRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.DeleteRow"), + page, getSelectedSQLResults(), getSelectedRow()); //$NON-NLS-1$ + WizardDialog dialog = + new WizardDialog( + tableView.getSite().getShell(), + wizard); + dialog.open(); + } + }; + + class UpdateAction extends Action { + public UpdateAction() { + setText(Messages.getString("tableview.update")); + } + + public void run() { + UpdateRowPage page = new UpdateRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.UpdateRow"), + page, getSelectedSQLResults(), getSelectedRow()); //$NON-NLS-1$ + WizardDialog dialog = + new WizardDialog( + tableView.getSite().getShell(), + wizard); + dialog.open(); + } + }; + + + private final TableView tableView; + private SelectionListenerAction closeAction; + private SelectionListenerAction closeAllAction; + private SelectionListenerAction nextAction; + private SelectionListenerAction previousAction; + private SelectionListenerAction refreshAction; + private SelectionListenerAction fullModeAction; + private SelectionListenerAction defaultEncodingAction; + private SelectionListenerAction utf8EncodingAction; + private SelectionListenerAction utf16EncodingAction; + + private CopyAction copyAction; + private SelectAllAction selectAllAction; + private InsertAction insertRowAction; + private DeleteAction deleteRowAction; + private UpdateAction updateRowAction; + + private PHPInsertAction phpInsertRowAction; + private PHPDeleteAction phpDeleteRowAction; + private PHPSelectAction phpSelectRowAction; + private PHPUpdateAction phpUpdateRowAction; + + private SortFilterAction sortFilterAction; + + private Vector extensionActions = new Vector(); + + public TableViewActionGroup(TableView tableView) { + this.tableView = tableView; + + this.closeAction = new CloseResultSetAction(this.tableView, this.tableView); + this.closeAllAction = new CloseAllResultSetsAction(this.tableView, this.tableView); + this.defaultEncodingAction = new ChangeEncodingAction(this.tableView, this.tableView, "", "default"); + this.utf8EncodingAction = new ChangeEncodingAction(this.tableView, this.tableView, "UTF-8", "utf8"); + this.utf16EncodingAction = new ChangeEncodingAction(this.tableView, this.tableView, "UTF-16", "utf16"); + this.nextAction = new NextPageAction(this.tableView, this.tableView); + this.previousAction = new PreviousPageAction(this.tableView, this.tableView); + this.refreshAction = new RefreshTableAction(this.tableView, this.tableView); + this.fullModeAction = new FullModeAction(this.tableView, this.tableView); + + this.copyAction = new CopyAction(this.tableView); + this.selectAllAction = new SelectAllAction(this.tableView); + + this.insertRowAction = new InsertAction(); + this.deleteRowAction = new DeleteAction(); + this.updateRowAction = new UpdateAction(); + + this.phpInsertRowAction = new PHPInsertAction(); + this.phpDeleteRowAction = new PHPDeleteAction(); + this.phpSelectRowAction = new PHPSelectAction(); + this.phpUpdateRowAction = new PHPUpdateAction(); + + this.sortFilterAction = new SortFilterAction(this.tableView); + + try { + ProcessServiceMembers.process(tableView, this.extensionActions); + } catch (WorkbenchException e) { + e.printStackTrace(); + } + } + + public void fillActionBars(IActionBars actionBars) { + IToolBarManager toolBar = actionBars.getToolBarManager(); + toolBar.add(this.previousAction); + toolBar.add(this.nextAction); + toolBar.add(this.fullModeAction); + toolBar.add(this.closeAction); + toolBar.add(this.closeAllAction); + toolBar.add(this.refreshAction); + toolBar.add(this.sortFilterAction); + + actionBars.setGlobalActionHandler( + IWorkbenchActionConstants.COPY, this.copyAction); + actionBars.setGlobalActionHandler( + IWorkbenchActionConstants.SELECT_ALL, this.selectAllAction); + } + + + public void fillContextMenu(IMenuManager menuManager) { + menuManager.add(this.defaultEncodingAction); + menuManager.add(this.utf8EncodingAction); + menuManager.add(this.utf16EncodingAction); + menuManager.add(new Separator()); + menuManager.add(this.copyAction); + menuManager.add(this.selectAllAction); + menuManager.add(new Separator()); + + SQLResultSetResults resultSet = getSelectedSQLResults(); + + if (resultSet != null && !resultSet.isMetaData() && resultSet.getEntity() != null) { + menuManager.add(this.insertRowAction); + menuManager.add(this.updateRowAction); + menuManager.add(this.deleteRowAction); + + menuManager.add(this.phpSelectRowAction); + menuManager.add(this.phpUpdateRowAction); + menuManager.add(this.phpDeleteRowAction); + menuManager.add(this.phpInsertRowAction); + + menuManager.add(new Separator()); + } + + createExtensionMenu(menuManager); + + createMarkerForActionsProvidedByOtherPlugins(menuManager); + } + + /** + * @return + */ + private SQLResultSetResults getSelectedSQLResults() { + return this.tableView.getSelectedResultSet(); + } + + protected SQLResultSetResults.Row getSelectedRow() { + IStructuredSelection selection = getTableRowSelection(); + + return selection == null || selection.isEmpty() + ? null + : (SQLResultSetResults.Row) selection.getFirstElement(); + } + /** + * @return + */ + private IStructuredSelection getTableRowSelection() { + ResultSetViewer viewer = this.tableView.getSelectedResultSetViewer(); + IStructuredSelection selection = viewer == null ? null : (IStructuredSelection) viewer.getSelection(); + return selection; + } + + /** + * @param menuManager + */ + private void createExtensionMenu(IMenuManager menuManager) { + MenuManager subMenuExtension = new MenuManager("Extensions"); + for (int i = 0; i < this.extensionActions.size(); i++) { + ExtensionAction extensionAction = (ExtensionAction) this.extensionActions.get(i); + extensionAction.addRowData(createTableRow()); + subMenuExtension.add(extensionAction); + } + if (this.extensionActions.size() > 0) { + menuManager.add(subMenuExtension); + } + } + + /** + * This method supports an earlier API for other plug-ins to add functionality to + * QuantumDB. + * + * @return + */ + private TableRow createTableRow() { + + SQLResultSetResults results = this.tableView.getSelectedResultSet(); + IStructuredSelection selection = getTableRowSelection(); + + if (results != null) { + StringMatrix data = new StringMatrix(); + data.addMatrixHeader(results.getColumnNames()); + if (selection != null && !selection.isEmpty()) { + int rowNumber = 0; + for (Iterator i = selection.iterator(); i.hasNext(); ) { + SQLResultSetResults.Row row = (SQLResultSetResults.Row) i.next(); + for (int j = 0, length = results.getColumnCount(); j < length; j++) { + Object object = row.get(j); + data.addAt(results.getColumnName(j+1), + object == null ? null : object.toString(), + rowNumber++); + } + } + } else { + // Create dummy values in case nothing selected + for (int i = 0, length = results.getColumnCount(); i < length; i++) { + data.addAt(results.getColumnName(i+1), "", 0); //$NON-NLS-1$ + } + } + + return new TableRow(results.getEntity(), results.getBookmark(), + results.getEntity() == null + ? null + : results.getEntity().getQualifiedName(), + data); + } else { + return null; + } + } + + private void createMarkerForActionsProvidedByOtherPlugins(IMenuManager menuManager) { + menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ + menuManager.add(new Separator()); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/AddDriverWizard.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/AddDriverWizard.java index e3cb426..6525e05 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/AddDriverWizard.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/AddDriverWizard.java @@ -1,5 +1,10 @@ package com.quantum.wizards; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + import com.quantum.ImageStore; import com.quantum.Messages; import com.quantum.QuantumPlugin; @@ -13,9 +18,13 @@ import com.quantum.view.widget.ComboViewer; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; @@ -31,20 +40,45 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; /** * @author BC Holmes + * @author Sirkware */ public class AddDriverWizard extends Wizard { + public class LabelProviderImpl extends LabelProvider { + + public Image getImage(Object element) { + return ImageStore.getImage(ImageStore.EXTERNAL_JAR); + } + } + + public class ContentProviderImpl implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + if (inputElement instanceof List) { + return ((List) inputElement).toArray(); + } else if (inputElement instanceof Object[]){ + return (Object[]) inputElement; + } else { + return null; + } + } + public void dispose() { + } + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + public class PageImpl extends WizardPage { private FileDialog fileDialog; - private Text driverFileName; private Text driverClassName; private ComboViewer type; + private TableViewer driverFiles; private DatabaseAdapter[] adapters = AdapterFactory.getInstance().getDriverList(); public PageImpl() { @@ -56,16 +90,12 @@ public class AddDriverWizard extends Wizard { setTitle(Messages.getString(getClass(), "title")); setDescription(Messages.getString(getClass(), "description")); - parent.setLayout(new GridLayout()); Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); composite.setLayout(layout); layout.numColumns = 3; - GridData fullHorizontal = new GridData( - GridData.FILL_HORIZONTAL | - GridData.VERTICAL_ALIGN_BEGINNING); - composite.setLayoutData(fullHorizontal); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); this.fileDialog = new FileDialog(composite.getShell(), SWT.OPEN); @@ -76,41 +106,76 @@ public class AddDriverWizard extends Wizard { Messages.getString("BookmarkWizard.AllFiles") }); Label label = new Label(composite, SWT.NULL); - label.setText(Messages.getString(getClass(), "fileName")); - this.driverFileName = new Text(composite, SWT.BORDER | SWT.SINGLE); - fullHorizontal = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); - this.driverFileName.setLayoutData(fullHorizontal); + label.setText(Messages.getString(AddDriverWizard.class, "jars")); + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + gridData.horizontalSpan = 3; + label.setLayoutData(gridData); - this.driverFileName.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent event) { - updateButtons(); - } - - }); - - Button button = new Button(composite, SWT.PUSH); - button.setText(Messages.getString(getClass(), "browse")); + Table table = new Table(composite, SWT.BORDER); + gridData = new GridData(GridData.FILL_BOTH); + gridData.horizontalSpan = 2; + table.setLayoutData(gridData); + this.driverFiles = new TableViewer(table); + this.driverFiles.setLabelProvider(new LabelProviderImpl()); + this.driverFiles.setContentProvider(new ContentProviderImpl()); + this.driverFiles.setInput(AddDriverWizard.this.driverFileNames); + + Composite buttonArea = new Composite(composite, SWT.NONE); + GridLayout gridLayout = new GridLayout(); + gridLayout.marginWidth = 0; + buttonArea.setLayout(gridLayout); + buttonArea.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + + Button addExternalJar = new Button(buttonArea, SWT.PUSH); + addExternalJar.setText(Messages.getString(AddDriverWizard.class, "addExternalJar")); + addExternalJar.setLayoutData( + new GridData(GridData.FILL_HORIZONTAL + | GridData.VERTICAL_ALIGN_BEGINNING)); - button.addSelectionListener(new SelectionAdapter() { + addExternalJar.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { PageImpl.this.fileDialog.setFilterPath(QuantumPlugin.getDefault() .getPreferenceStore().getString( "quantum.dialogs.bookmarkwizard.path")); String filename = PageImpl.this.fileDialog.open(); if (filename != null) { - PageImpl.this.driverFileName.setText(filename); + driverFileNames.add(filename); + PageImpl.this.driverFiles.refresh(); QuantumPlugin.getDefault().getPreferenceStore().setValue( "quantum.dialogs.bookmarkwizard.path", filename); - AddDriverWizard.this.setDriverFileName(filename); updateButtons(); } } }); - + + final Button removeJar = new Button(buttonArea, SWT.PUSH); + removeJar.setText(Messages.getString(AddDriverWizard.class, "removeJar")); + removeJar.setLayoutData( + new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.VERTICAL_ALIGN_BEGINNING)); + removeJar.setEnabled(false); + + this.driverFiles.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + removeJar.setEnabled(!event.getSelection().isEmpty()); + } + }); + + removeJar.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent event) { + IStructuredSelection selection = + (IStructuredSelection) PageImpl.this.driverFiles.getSelection(); + for (Iterator i = selection.iterator(); i.hasNext();) { + driverFileNames.remove(i.next()); + } + PageImpl.this.driverFiles.refresh(); + } + }); + label = new Label(composite, SWT.NULL); - label.setText(Messages.getString(getClass(), "driverClassName")); + label.setText(Messages.getString(AddDriverWizard.class, "driverClassName")); this.driverClassName = new Text(composite, SWT.BORDER | SWT.SINGLE); - fullHorizontal = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + GridData fullHorizontal = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); this.driverClassName.setLayoutData(fullHorizontal); this.driverClassName.addModifyListener(new ModifyListener() { @@ -118,16 +183,18 @@ public class AddDriverWizard extends Wizard { AddDriverWizard.this.setDriverClassName(((Text) event.getSource()).getText()); updateButtons(); } - }); - button = new Button(composite, SWT.PUSH); - button.setText(Messages.getString(getClass(), "browse")); + + + Button browse = new Button(composite, SWT.PUSH); + browse.setText(Messages.getString(AddDriverWizard.class, "browse")); + browse.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); - button.addSelectionListener(new SelectionAdapter() { + browse.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { SimpleSelectionDialog dialog = new SimpleSelectionDialog( getShell(), "Select a Driver", JarUtil.getAllDriverNames( - getDriverFile()), ImageStore.getImage(ImageStore.CLASS)); + getDriverFileNames()), ImageStore.getImage(ImageStore.CLASS)); if (dialog.open() == SimpleSelectionDialog.OK) { IStructuredSelection selection = dialog.getSelection(); if (!selection.isEmpty()) { @@ -137,23 +204,13 @@ public class AddDriverWizard extends Wizard { AddDriverWizard.this.setDriverClassName(className); updateButtons(); } - - } } }); - label = new Label(composite, SWT.NULL); + label = new Label(composite, SWT.NULL); label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$ this.type = new ComboViewer(composite); - this.type.setContentProvider(new IStructuredContentProvider() { - public void dispose() { - } - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - public Object[] getElements(Object inputElement) { - return PageImpl.this.adapters; - } - }); + this.type.setContentProvider(new ContentProviderImpl()); this.type.setLabelProvider(new ILabelProvider() { public Image getImage(Object element) { @@ -177,7 +234,7 @@ public class AddDriverWizard extends Wizard { } }); - type.setInput(this); + type.setInput(this.adapters); fullHorizontal = new GridData(); fullHorizontal.horizontalAlignment = GridData.FILL; type.getControl().setLayoutData(fullHorizontal); @@ -188,7 +245,9 @@ public class AddDriverWizard extends Wizard { setControl(composite); } protected void updateButtons() { - Class driver = JarUtil.loadDriverClass(getDriverFile(), getDriverClassName()); + Class driver = JarUtil.loadDriverClass( + getDriverFileNames(), + getDriverClassName()); setPageComplete(driver != null); String adapterType = AdapterFactory.getInstance().getAdapterType(getDriverClassName()); @@ -197,13 +256,6 @@ public class AddDriverWizard extends Wizard { AdapterFactory.getInstance().getAdapter(adapterType))); } } - protected String getDriverClassName() { - return this.driverClassName == null ? null : this.driverClassName.getText(); - } - protected String getDriverFile() { - return this.driverFileName == null ? null : this.driverFileName.getText(); - } - protected String getDriverType() { DatabaseAdapter driverInfo = (DatabaseAdapter) ((IStructuredSelection) this.type.getSelection()).getFirstElement(); @@ -213,8 +265,8 @@ public class AddDriverWizard extends Wizard { private PageImpl page; private String driverClassName; - private String driverFileName; private String driverType; + private List driverFileNames = Collections.synchronizedList(new ArrayList()); public void addPages() { @@ -230,7 +282,7 @@ public class AddDriverWizard extends Wizard { public boolean performFinish() { JDBCDriver driver = new JDBCDriver( getDriverClassName(), - getDriverFileName(), + getDriverFileNames(), this.page.getDriverType()); BookmarkCollection.getInstance().addDriver(driver); return true; @@ -261,16 +313,8 @@ public class AddDriverWizard extends Wizard { public void setDriverType(String driverType) { this.driverType = driverType; } - /** - * @return Returns the driverFileName. - */ - public String getDriverFileName() { - return this.driverFileName; - } - /** - * @param driverFileName The driverFileName to set. - */ - public void setDriverFileName(String driverFileName) { - this.driverFileName = driverFileName; + + public String[] getDriverFileNames() { + return (String[]) this.driverFileNames.toArray(new String[this.driverFileNames.size()]); } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BaseSQLPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BaseSQLPage.java index a7a84fe..3c75b99 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BaseSQLPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BaseSQLPage.java @@ -5,13 +5,13 @@ import java.sql.SQLException; import com.quantum.adapters.DatabaseAdapter; import com.quantum.model.Bookmark; import com.quantum.model.Column; -import com.quantum.model.ConnectionException; import com.quantum.model.Entity; import com.quantum.model.NotConnectedException; +import com.quantum.sql.MultiSQLServer; +import com.quantum.sql.SQLResultSetResults; import com.quantum.sql.SQLResults; -import com.quantum.sql.TableRow; -import com.quantum.view.ViewHelper; -import com.quantum.view.tableview.TableAdapter; +import com.quantum.ui.dialog.ExceptionDisplayDialog; +import com.quantum.util.connection.ConnectionUtil; import org.eclipse.jface.wizard.WizardPage; @@ -21,21 +21,22 @@ import org.eclipse.jface.wizard.WizardPage; */ public abstract class BaseSQLPage extends WizardPage implements SQLPage { - protected TableRow row; - protected TableAdapter adapter; + protected SQLResultSetResults.Row row; + protected SQLResultSetResults results; + private ConnectionUtil connectionUtil = new ConnectionUtil(); public BaseSQLPage(String pageName) { super(pageName); } public boolean performFinish() { try { - Bookmark bookmark = this.adapter.getBookmark(); + Bookmark bookmark = this.results.getBookmark(); bookmark.addQuery(getQueryText()); - SQLResults sqlResults = ViewHelper.tryGetResults(getShell(), - bookmark.getConnection(), getQueryText()); - return sqlResults.isError() ? false : true; - } catch (ConnectionException e) { - e.printStackTrace(); + SQLResults sqlResults = MultiSQLServer.getInstance().execute(bookmark, + this.connectionUtil.getConnection(bookmark, getShell()), getQueryText()); + return sqlResults == null ? false : true; + } catch (SQLException e) { + ExceptionDisplayDialog.openError(getShell(), null, null, e); return false; } } @@ -66,8 +67,8 @@ public abstract class BaseSQLPage extends WizardPage implements SQLPage { return null; } } - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - this.adapter = adapter; + public void init(SQLResultSetResults results, SQLResultSetResults.Row row) { + this.results = results; + this.row = row; } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BasicOnePartURLSetupControl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BasicOnePartURLSetupControl.java new file mode 100644 index 0000000..f3f6c99 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BasicOnePartURLSetupControl.java @@ -0,0 +1,57 @@ +package com.quantum.wizards; + +import com.quantum.Messages; +import com.quantum.model.JDBCDriver; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + + +/** + * @author BC + */ +public class BasicOnePartURLSetupControl extends URLSetupControl { + + private final String propertyName; + + public BasicOnePartURLSetupControl(Composite parent, JDBCDriver driver, String propertyName) { + super(parent, driver); + this.propertyName = propertyName; + } + + protected void createPart(Composite parent) { + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + parent.setLayout(layout); + + Label label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, this.propertyName)); + + Text databaseNameText = new Text(parent, SWT.BORDER | SWT.SINGLE); + databaseNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + databaseNameText.setText(getProperty(this.propertyName)); + label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "url")); + + final Text urlText = new Text(parent, SWT.BORDER | SWT.SINGLE); + urlText.setEditable(false); + urlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + urlText.setText(getConnectionURL()); + + databaseNameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + putProperty( + BasicOnePartURLSetupControl.this.propertyName, + ((Text) event.getSource()).getText()); + urlText.setText(getConnectionURL()); + } + }); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BasicThreePartURLSetupControl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BasicThreePartURLSetupControl.java new file mode 100644 index 0000000..7d2d12b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BasicThreePartURLSetupControl.java @@ -0,0 +1,80 @@ +package com.quantum.wizards; + +import com.quantum.Messages; +import com.quantum.model.JDBCDriver; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + + +/** + * @author BC + */ +public class BasicThreePartURLSetupControl extends URLSetupControl { + + public BasicThreePartURLSetupControl(Composite parent, JDBCDriver driver) { + super(parent, driver); + } + + protected void createPart(Composite parent) { + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + parent.setLayout(layout); + + Label label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "hostname")); + + Text hostNameText = new Text(parent, SWT.BORDER | SWT.SINGLE); + hostNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + hostNameText.setText(getProperty("hostname")); + + label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "port")); + + Text portText = new Text(parent, SWT.BORDER | SWT.SINGLE); + portText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + portText.setText(getProperty("port")); + + label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "dbname")); + + Text databaseNameText = new Text(parent, SWT.BORDER | SWT.SINGLE); + databaseNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + databaseNameText.setText(getProperty("dbname")); + label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "url")); + + final Text urlText = new Text(parent, SWT.BORDER | SWT.SINGLE); + urlText.setEditable(false); + urlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + urlText.setText(getConnectionURL()); + + hostNameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + putProperty("hostname", ((Text) event.getSource()).getText()); + urlText.setText(getConnectionURL()); + } + }); + + portText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + putProperty("port", ((Text) event.getSource()).getText()); + urlText.setText(getConnectionURL()); + } + }); + + databaseNameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + putProperty("dbname", ((Text) event.getSource()).getText()); + urlText.setText(getConnectionURL()); + } + }); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java index 25cbc3c..36a4077 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java @@ -1,10 +1,17 @@ package com.quantum.wizards; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import com.quantum.Messages; +import com.quantum.model.JDBCDriver; + import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -12,9 +19,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import com.quantum.Messages; -import com.quantum.model.JDBCDriver; - class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { @@ -25,6 +29,20 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { private String connectionURL; private boolean prompt; + private Label jdbcLabel; + private Text jdbcUrl; + private URLSetupControl urlSetupControl; + private Composite container; + + private PropertyChangeListener listener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + if ("connectionURL".equals(event.getPropertyName())) { + BookmarkConnectionWizardPage.this.setConnectionURL((String) event.getNewValue()); + BookmarkConnectionWizardPage.this.updateButtonState(); + } + } + }; + /** * Constructor for BookmarkPage. * @param pageName @@ -40,7 +58,7 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout); - layout.numColumns = 3; + layout.numColumns = 2; layout.verticalSpacing = 9; Label label = new Label(container, SWT.NULL); @@ -49,7 +67,6 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { GridData fullHorizontal = new GridData(GridData.FILL_HORIZONTAL); - fullHorizontal.horizontalSpan = 2; username.setLayoutData(fullHorizontal); username.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { @@ -64,7 +81,6 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { final Text password = new Text(container, SWT.BORDER | SWT.SINGLE); password.setEchoChar('*'); fullHorizontal = new GridData(GridData.FILL_HORIZONTAL); - fullHorizontal.horizontalSpan = 2; password.setLayoutData(fullHorizontal); password.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { @@ -77,23 +93,10 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { Button prompt = new Button(container, SWT.CHECK); prompt.setText(Messages.getString(getClass(), "prompt")); //$NON-NLS-1$ fullHorizontal = new GridData(GridData.FILL_HORIZONTAL); - fullHorizontal.horizontalSpan = 3; + fullHorizontal.horizontalSpan = 2; prompt.setLayoutData(fullHorizontal); - label = new Label(container, SWT.NULL); - label.setText(Messages.getString(getClass(), "url")); //$NON-NLS-1$ - - Text connect = new Text(container, SWT.BORDER | SWT.SINGLE); - fullHorizontal = new GridData(GridData.FILL_HORIZONTAL); - fullHorizontal.horizontalSpan = 2; - connect.setLayoutData(fullHorizontal); - connect.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent event) { - String connectionURL = ((Text) event.getSource()).getText(); - setConnectionURL(connectionURL); - updateButtonState(); - } - }); + createStandardJDBCWidgets(container); prompt.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Button prompt = ((Button) event.getSource()); @@ -103,10 +106,31 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { } }); + this.container = container; setControl(container); } /** + * @param container + */ + private void createStandardJDBCWidgets(Composite container) { + setConnectionURL(""); + + this.jdbcLabel = new Label(container, SWT.NULL); + this.jdbcLabel.setText(Messages.getString(getClass(), "url")); //$NON-NLS-1$ + + this.jdbcUrl = new Text(container, SWT.BORDER | SWT.SINGLE); + this.jdbcUrl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + this.jdbcUrl.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + setConnectionURL(((Text) event.getSource()).getText()); + updateButtonState(); + } + }); + + updateButtonState(); + } + /** * @return Returns the driver. */ public JDBCDriver getDriver() { @@ -116,7 +140,75 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage { * @param driver The driver to set. */ public void setDriver(JDBCDriver driver) { + String oldDriverClassName = this.driver == null ? null : this.driver.getClassName(); this.driver = driver; + + if (oldDriverClassName == null + || !oldDriverClassName.equals(this.driver.getClassName())) { + rebuildJDBCControls(this.driver); + } + } + /** + * + */ + private void rebuildJDBCControls(JDBCDriver driver) { + Point windowSize = getShell().getSize(); + Point oldSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); + + if (URLSetupControlFactory.hasControl(driver)) { + disposeOfCurrentJDBCControls(); + + this.urlSetupControl = URLSetupControlFactory.create(driver, this.container); + GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); + data.horizontalSpan = 2; + this.urlSetupControl.setLayoutData(data); + + this.urlSetupControl.addPropertyChangeListener(this.listener); + + setConnectionURL(this.urlSetupControl.getConnectionURL()); + updateButtonState(); + + resizeWindow(windowSize, oldSize); + this.container.layout(); + + } else if (this.jdbcLabel == null || this.jdbcUrl == null) { + + disposeOfCurrentJDBCControls(); + createStandardJDBCWidgets(this.container); + + resizeWindow(windowSize, oldSize); + + this.container.layout(); + } + this.container.setVisible(true); + this.container.redraw(); + } + + /** + * @param windowSize + * @param oldSize + */ + private void resizeWindow(Point windowSize, Point oldSize) { + Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); + if (newSize.y > windowSize.y) { + getShell().setSize( + new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y))); + } + } + private void disposeOfCurrentJDBCControls() { + if (this.jdbcUrl != null) { + this.jdbcUrl.dispose(); + this.jdbcUrl = null; + } + if (this.jdbcLabel != null) { + this.jdbcLabel.dispose(); + this.jdbcLabel = null; + } + if (this.urlSetupControl != null) { + this.urlSetupControl.removePropertyChangeListener(this.listener); + this.urlSetupControl.dispose(); + this.urlSetupControl = null; + } } /** * diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/DeleteRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/DeleteRowPage.java index e259f76..10d1fda 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/DeleteRowPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/DeleteRowPage.java @@ -30,45 +30,32 @@ public class DeleteRowPage extends BaseSQLPage implements SQLPage { public void createControl(Composite parent) { System.out.println("page create control"); //$NON-NLS-1$ - Composite container = new Composite(parent, SWT.NULL); + Composite container = new Composite(parent, SWT.V_SCROLL); GridLayout layout = new GridLayout(); container.setLayout(layout); layout.numColumns = 3; - if (row == null) { - System.out.println("Row is null"); //$NON-NLS-1$ - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); //$NON-NLS-1$ - } - if (row.getTableData() == null) { - System.out.println("Data is null"); //$NON-NLS-1$ - } - Entity entity = row.getEntity(); - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$ - } - values = new Text[row.getColumnCount()]; - whereValues = new Button[row.getColumnCount()]; + Entity entity = this.results.getEntity(); + columnNames = this.results.getColumnNames(); + + values = new Text[columnNames.length]; + whereValues = new Button[columnNames.length]; new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.ColumnName")); //$NON-NLS-1$ new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.Value")); //$NON-NLS-1$ new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.IncludeIn")); //$NON-NLS-1$ - for (int i = 0; i < row.getColumnCount(); i++) { + for (int i = 0; i < columnNames.length; i++) { Label label = new Label(container, SWT.NULL); label.setText(columnNames[i]); values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - GridData fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - values[i].setLayoutData(fullHorizontal); - values[i].setText(data[i]); - + Object object = this.row == null ? null : this.row.get(i+1); + values[i].setText(object == null ? "" : object.toString()); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = 150; + values[i].setLayoutData(gridData); values[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { + public void modifyText(ModifyEvent event) { updateQuery(); - } + } }); whereValues[i] = new Button(container, SWT.CHECK); @@ -102,8 +89,8 @@ public class DeleteRowPage extends BaseSQLPage implements SQLPage { public void updateQuery() { System.out.println(Messages.getString("DeleteRowPage.UpdatingQuery")); //$NON-NLS-1$ StringBuffer whereClause = new StringBuffer(); - Bookmark bookmark = row.getBookmark(); - Entity entity = row.getEntity(); + Bookmark bookmark = this.results.getBookmark(); + Entity entity = this.results.getEntity(); DatabaseAdapter adapter = bookmark.getAdapter(); int numSelected = 0; @@ -118,7 +105,7 @@ public class DeleteRowPage extends BaseSQLPage implements SQLPage { whereClause.append(")"); //$NON-NLS-1$ } } - String query = "DELETE FROM " + row.getTable(); //$NON-NLS-1$ + String query = "DELETE FROM " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ if (numSelected > 0) { query += " WHERE " + whereClause.toString(); //$NON-NLS-1$ } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InformixURLSetupControl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InformixURLSetupControl.java new file mode 100644 index 0000000..91e8f0b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InformixURLSetupControl.java @@ -0,0 +1,95 @@ +package com.quantum.wizards; + +import com.quantum.Messages; +import com.quantum.model.JDBCDriver; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + + +/** + * @author BC + */ +public class InformixURLSetupControl extends URLSetupControl { + + public InformixURLSetupControl(Composite parent, JDBCDriver driver) { + super(parent, driver); + } + + protected void createPart(Composite parent) { + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + parent.setLayout(layout); + + Label label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "hostname")); + + Text hostNameText = new Text(parent, SWT.BORDER | SWT.SINGLE); + hostNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + hostNameText.setText(getProperty("hostname")); + + label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "port")); + + Text portText = new Text(parent, SWT.BORDER | SWT.SINGLE); + portText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + portText.setText(getProperty("port")); + + label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "dbname")); + + Text databaseNameText = new Text(parent, SWT.BORDER | SWT.SINGLE); + databaseNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + databaseNameText.setText(getProperty("dbname")); + + label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(InformixURLSetupControl.class, "informixserver")); + + Text serverText = new Text(parent, SWT.BORDER | SWT.SINGLE); + serverText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + serverText.setText(getProperty("informixserver")); + + label = new Label(parent, SWT.NONE); + label.setText(Messages.getString(URLSetupControl.class, "url")); + + final Text urlText = new Text(parent, SWT.BORDER | SWT.SINGLE); + urlText.setEditable(false); + urlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + urlText.setText(getConnectionURL()); + + hostNameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + putProperty("hostname", ((Text) event.getSource()).getText()); + urlText.setText(getConnectionURL()); + } + }); + + portText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + putProperty("port", ((Text) event.getSource()).getText()); + urlText.setText(getConnectionURL()); + } + }); + + databaseNameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + putProperty("dbname", ((Text) event.getSource()).getText()); + urlText.setText(getConnectionURL()); + } + }); + + serverText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + putProperty("informixserver", ((Text) event.getSource()).getText()); + urlText.setText(getConnectionURL()); + } + }); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InsertRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InsertRowPage.java index 91c55d0..ecaf832 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InsertRowPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/InsertRowPage.java @@ -26,36 +26,22 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { public void createControl(Composite parent) { System.out.println("page create control"); //$NON-NLS-1$ - Composite container = new Composite(parent, SWT.NULL); + Composite container = new Composite(parent, SWT.V_SCROLL); GridLayout layout = new GridLayout(); container.setLayout(layout); layout.numColumns = 2; - if (row == null) { - System.out.println("Row is null"); //$NON-NLS-1$ - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); //$NON-NLS-1$ - } - if (row.getTableData() == null) { - System.out.println("Data is null"); //$NON-NLS-1$ - } - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$ - } - values = new Text[row.getColumnCount()]; + columnNames = this.results.getColumnNames(); + values = new Text[columnNames.length]; new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.ColumnName")); //$NON-NLS-1$ new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.Value")); //$NON-NLS-1$ - for (int i = 0; i < row.getColumnCount(); i++) { + for (int i = 0; i < columnNames.length; i++) { Label label = new Label(container, SWT.NULL); label.setText(columnNames[i]); values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - GridData fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - values[i].setLayoutData(fullHorizontal); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = 150; + values[i].setLayoutData(gridData); //values[i].setText(data[i]); values[i].addModifyListener(new ModifyListener() { @@ -82,8 +68,8 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { System.out.println("Updating query"); //$NON-NLS-1$ StringBuffer valuesClause = new StringBuffer(); StringBuffer namesClause = new StringBuffer(); - Bookmark bookmark = row.getBookmark(); - Entity entity = row.getEntity(); + Bookmark bookmark = this.results.getBookmark(); + Entity entity = this.results.getEntity(); DatabaseAdapter adapter = bookmark.getAdapter(); numColumns = 0; @@ -101,7 +87,7 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { } } - String query = "INSERT INTO " + row.getTable(); //$NON-NLS-1$ + String query = "INSERT INTO " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ if (numColumns > 0) { query += " (" + namesClause + ")"; query += " VALUES " + "(" + valuesClause; //$NON-NLS-1$ @@ -115,5 +101,4 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage { protected String getQueryText() { return this.query.getText(); } - } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/JDBCDriverSelectionWizardPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/JDBCDriverSelectionWizardPage.java index 7770614..9eb092f 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/JDBCDriverSelectionWizardPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/JDBCDriverSelectionWizardPage.java @@ -28,7 +28,7 @@ public class JDBCDriverSelectionWizardPage extends PropertyChangeWizardPage impl /** * @param pageName */ - protected JDBCDriverSelectionWizardPage(String pageName) { + public JDBCDriverSelectionWizardPage(String pageName) { super(pageName); setTitle(Messages.getString(getClass(), "title")); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPDeleteRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPDeleteRowPage.java deleted file mode 100644 index 6dc8db2..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPDeleteRowPage.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.quantum.wizards; - -import java.text.MessageFormat; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import com.quantum.QuantumPlugin; -import com.quantum.sql.TableRow; -//import com.quantum.view.PHPSourceConsole; -import com.quantum.view.tableview.TableAdapter; - -public class PHPDeleteRowPage extends WizardPage implements SQLPage { - TableRow row; - String[] columnNames; - Text[] values; - Button[] whereValues; - Label query; - IPreferenceStore fStore; - private final static boolean DEBUG = false; - - public PHPDeleteRowPage(String pageName) { - super(pageName); - } - - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - } - - public void createControl(Composite parent) { - System.out.println("page create control"); - fStore = QuantumPlugin.getDefault().getPreferenceStore(); - Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 3; - layout.numColumns = layoutColumns; - - if (DEBUG) { - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); - } - } - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - if (DEBUG) { - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); - } - } - values = new Text[row.getColumnCount()]; - whereValues = new Button[row.getColumnCount()]; - Label temp = new Label(container, SWT.NULL); - temp.setText("Column Name"); - temp = new Label(container, SWT.NULL); - temp.setText("Value"); - temp = new Label(container, SWT.NULL); - temp.setText("Include in?"); - for (int i = 0; i < row.getColumnCount(); i++) { - Label label = new Label(container, SWT.NULL); - label.setText(columnNames[i]); - values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - GridData fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - values[i].setLayoutData(fullHorizontal); - - if (data[i] == null || data[i].equals("")) { - values[i].setText('$' + columnNames[i]); - } else { - values[i].setText(data[i]); - } - - values[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - - whereValues[i] = new Button(container, SWT.CHECK); - whereValues[i].setText("Where clause"); - whereValues[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - } - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); - - setControl(container); - updateQuery(); - - setPageComplete(true); - } - public void updateQuery() { - if (DEBUG) { - System.out.println("Updating delete query"); - } - StringBuffer whereClause = new StringBuffer(); - int numSelected = 0; - boolean first = false; - for (int i = 0; i < columnNames.length; i++) { - if (whereValues[i].getSelection()) { - numSelected++; - if (first) { - whereClause.append(", "); - } - - whereClause.append(columnNames[i]); - whereClause.append(" = "); - whereClause.append("'" + values[i].getText() + "'"); - - first = true; - } - } - // if (whereClause.length() > 1) { - // whereClause.deleteCharAt(whereClause.length() - 1); - // whereClause.deleteCharAt(whereClause.length() - 1); - // } - - String[] arguments = { row.getTable(), whereClause.toString()}; - MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.delete.template")); - - String query = form.format(arguments); - - // String query = "$results = mysql_query(\"DELETE FROM " + row.getTable(); - // if (numSelected > 0) { - // query += " WHERE " + whereClause.toString() + "\");"; - // } else { - // query += "\");"; - // } - - if (numSelected > 0) { - setMessage(""); - } else { - setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted"); - } - - this.getControl().pack(); - this.query.setText(query); - } - public boolean performFinish() { -// PHPSourceConsole console = PHPSourceConsole.getInstance(); -// console.clear(); -// console.print(query.getText()); - QuantumPlugin.getDefault().getSysClip().setContents( - new Object[] { query.getText() }, - new Transfer[] { TextTransfer.getInstance()}); - return true; - } -} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPInsertRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPInsertRowPage.java deleted file mode 100644 index 3436157..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPInsertRowPage.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.quantum.wizards; - -import java.text.MessageFormat; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import com.quantum.QuantumPlugin; -import com.quantum.sql.TableRow; -//import com.quantum.view.PHPSourceConsole; -import com.quantum.view.tableview.TableAdapter; - -public class PHPInsertRowPage extends WizardPage implements SQLPage { - TableRow row; - String[] columnNames; - Text[] values; - Label query; - private final static boolean DEBUG = false; - private IPreferenceStore fStore; - - public PHPInsertRowPage(String pageName) { - super(pageName); - } - - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - } - - public void createControl(Composite parent) { - if (DEBUG) { - System.out.println("page create control"); - } - fStore = QuantumPlugin.getDefault().getPreferenceStore(); - Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 2; - layout.numColumns = layoutColumns; - - if (DEBUG) { - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); - } - } - - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - if (DEBUG) { - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); - } - } - values = new Text[row.getColumnCount()]; - Label temp = new Label(container, SWT.NULL); - temp.setText("Column Name"); - temp = new Label(container, SWT.NULL); - temp.setText("Value"); - for (int i = 0; i < row.getColumnCount(); i++) { - Label label = new Label(container, SWT.NULL); - label.setText(columnNames[i]); - values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - GridData fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - values[i].setLayoutData(fullHorizontal); - - //values[i].setText(data[i]); - values[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - } - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); - - setControl(container); - updateQuery(); - - setPageComplete(true); - } - public void updateQuery() { - if (DEBUG) { - System.out.println("Updating insert query"); - } - StringBuffer fieldClause = new StringBuffer(); - - StringBuffer valuesClause = new StringBuffer(); - String text; - boolean first = false; - for (int i = 0; i < columnNames.length; i++) { - text = values[i].getText(); - if (!text.equals("")) { - if (first) { - valuesClause.append(", "); - fieldClause.append(", "); - } - valuesClause.append("'" + values[i].getText() + "'"); - fieldClause.append(columnNames[i]); - first = true; - } - } - // if (valuesClause.length() > 1) { - // valuesClause.deleteCharAt(valuesClause.length() - 1); - // valuesClause.deleteCharAt(valuesClause.length() - 1); - // } - String[] arguments = { row.getTable(), fieldClause.toString(), valuesClause.toString()}; - MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template")); - - String query = form.format(arguments); - - // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " ("; - // query += fieldClause.toString() + ") "; - // query += " VALUES (" + valuesClause.toString(); - // query += ")\");"; - this.query.setText(query); - } - public boolean performFinish() { -// PHPSourceConsole console = PHPSourceConsole.getInstance(); -// console.clear(); -// console.print(query.getText()); - QuantumPlugin.getDefault().getSysClip().setContents( - new Object[] { query.getText() }, - new Transfer[] { TextTransfer.getInstance()}); - return true; - } -} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPSelectRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPSelectRowPage.java deleted file mode 100644 index 2f9e545..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPSelectRowPage.java +++ /dev/null @@ -1,207 +0,0 @@ -package com.quantum.wizards; - -import java.text.MessageFormat; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import com.quantum.QuantumPlugin; -import com.quantum.sql.TableRow; -//import com.quantum.view.PHPSourceConsole; -import com.quantum.view.tableview.TableAdapter; - -public class PHPSelectRowPage extends WizardPage implements SQLPage { - TableRow row; - String[] columnNames; - Text[] whereValues; - // Text[] newValues; - Button[] primaryKeys; - Button[] setValues; - Label query; - IPreferenceStore fStore; - private final static boolean DEBUG = false; - - public PHPSelectRowPage(String pageName) { - super(pageName); - } - - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - } - - public void createControl(Composite parent) { - if (DEBUG) { - System.out.println("page create control"); - } - Composite container = new Composite(parent, SWT.NULL); - fStore = QuantumPlugin.getDefault().getPreferenceStore(); - - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 4; - layout.numColumns = layoutColumns; - - if (DEBUG) { - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); - } - } - - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); - } - - whereValues = new Text[row.getColumnCount()]; - // newValues = new Text[row.getColumnCount()]; - primaryKeys = new Button[row.getColumnCount()]; - setValues = new Button[row.getColumnCount()]; - Label temp = new Label(container, SWT.NULL); - temp.setText("Column Name"); - temp = new Label(container, SWT.NULL); - temp.setText("Value"); - temp = new Label(container, SWT.NULL); - temp.setText("Where"); - // temp = new Label(container, SWT.NULL); - // temp.setText("New Value"); - temp = new Label(container, SWT.NULL); - temp.setText("Select"); - for (int i = 0; i < row.getColumnCount(); i++) { - Label label = new Label(container, SWT.NULL); - label.setText(columnNames[i]); - whereValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - if (data[i] == null || data[i].equals("")) { - whereValues[i].setText('$' + columnNames[i]); - } else { - whereValues[i].setText(data[i]); - } - - whereValues[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - - primaryKeys[i] = new Button(container, SWT.CHECK); - //primaryKeys[i].setText("Where Clause"); - primaryKeys[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - // newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - // newValues[i].setText(data[i]); - // newValues[i].addModifyListener(new ModifyListener() { - // public void modifyText(ModifyEvent e) { - // updateQuery(); - // } - // }); - setValues[i] = new Button(container, SWT.CHECK); - //setValues[i].setText("Select Value"); - setValues[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - } - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); - - setControl(container); - updateQuery(); - - setPageComplete(true); - } - - public void updateQuery() { - if (DEBUG) { - System.out.println("PHP SELECT"); - } - StringBuffer setClause = new StringBuffer(); - StringBuffer whereClause = new StringBuffer(); - String temp; - boolean firstClause = false; - for (int i = 0; i < columnNames.length; i++) { - if (primaryKeys[i].getSelection()) { - if (firstClause) { - whereClause.append(" AND "); - } - firstClause = true; - whereClause.append(columnNames[i]); - whereClause.append(" = "); - temp = whereValues[i].getText(); - // if (temp.charAt(0) == '$') { - // whereClause.append(temp); - // } else { - whereClause.append("'" + temp + "'"); - // } - - } - if (setValues[i].getSelection()) { - setClause.append(columnNames[i]); - // setClause.append(" = "); - // setClause.append(newValues[i].getText()); - setClause.append(", "); - } - } - // if (whereClause.length() > 1) { - // whereClause.deleteCharAt(whereClause.length() - 1); - // whereClause.deleteCharAt(whereClause.length() - 1); - // } - if (setClause.length() > 1) { - setClause.deleteCharAt(setClause.length() - 1); - setClause.deleteCharAt(setClause.length() - 1); - } - - String[] arguments = { setClause.toString(), row.getTable(), whereClause.toString()}; - MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.select.template")); - - String query = form.format(arguments); - // String query = "$results = mysql_query(\"SELECT " + setClause.toString(); - // query += " FROM " + row.getTable(); - // query += " WHERE " + whereClause.toString() + "\");"; - this.query.setText(query); - } - - public boolean performFinish() { -// PHPSourceConsole console = PHPSourceConsole.getInstance(); -// console.clear(); -// console.print(query.getText()); - QuantumPlugin.getDefault().getSysClip().setContents( - new Object[] { query.getText() }, - new Transfer[] { TextTransfer.getInstance()}); - return true; - } -} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPUpdateRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPUpdateRowPage.java deleted file mode 100644 index 0767336..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPUpdateRowPage.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.quantum.wizards; - -import java.text.MessageFormat; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import com.quantum.QuantumPlugin; -import com.quantum.sql.TableRow; -//import com.quantum.view.PHPSourceConsole; -import com.quantum.view.tableview.TableAdapter; - -public class PHPUpdateRowPage extends WizardPage implements SQLPage { - TableRow row; - String[] columnNames; - Text[] oldValues; - Text[] newValues; - Button[] primaryKeys; - Button[] setValues; - Label query; - IPreferenceStore fStore; - private final static boolean DEBUG = false; - - public PHPUpdateRowPage(String pageName) { - super(pageName); - } - - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - } - - public void createControl(Composite parent) { - if (DEBUG) { - System.out.println("page create control"); - } - fStore = QuantumPlugin.getDefault().getPreferenceStore(); - Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 5; - layout.numColumns = layoutColumns; - - if (DEBUG) { - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); - } - } - - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - - if (DEBUG) { - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); - } - } - - oldValues = new Text[row.getColumnCount()]; - newValues = new Text[row.getColumnCount()]; - primaryKeys = new Button[row.getColumnCount()]; - setValues = new Button[row.getColumnCount()]; - Label temp = new Label(container, SWT.NULL); - temp.setText("Column Name"); - temp = new Label(container, SWT.NULL); - temp.setText("Where Value"); - temp = new Label(container, SWT.NULL); - temp.setText("Where"); - temp = new Label(container, SWT.NULL); - temp.setText("Set Value"); - temp = new Label(container, SWT.NULL); - temp.setText("Set"); - for (int i = 0; i < row.getColumnCount(); i++) { - Label label = new Label(container, SWT.NULL); - label.setText(columnNames[i]); - oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - if (data[i] == null || data[i].equals("")) { - oldValues[i].setText('$' + columnNames[i]); - } else { - oldValues[i].setText(data[i]); - } - oldValues[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - primaryKeys[i] = new Button(container, SWT.CHECK); - // primaryKeys[i].setText("Where"); - primaryKeys[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - - if (data[i] == null || data[i].equals("")) { - newValues[i].setText('$' + columnNames[i]); - } else { - newValues[i].setText(data[i]); - } - newValues[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - setValues[i] = new Button(container, SWT.CHECK); - // setValues[i].setText("Set Value"); - setValues[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - } - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); - - setControl(container); - updateQuery(); - - setPageComplete(true); - } - - public void updateQuery() { - if (DEBUG) { - System.out.println("Updating update query"); - } - - StringBuffer setClause = new StringBuffer(); - StringBuffer whereClause = new StringBuffer(); - for (int i = 0; i < columnNames.length; i++) { - if (primaryKeys[i].getSelection()) { - whereClause.append(columnNames[i]); - whereClause.append(" = "); - whereClause.append("'" + oldValues[i].getText() + "'"); - whereClause.append(", "); - } - if (setValues[i].getSelection()) { - setClause.append(columnNames[i]); - setClause.append(" = "); - setClause.append("'" + newValues[i].getText() + "'"); - setClause.append(", "); - } - } - if (whereClause.length() > 1) { - whereClause.deleteCharAt(whereClause.length() - 1); - whereClause.deleteCharAt(whereClause.length() - 1); - } - if (setClause.length() > 1) { - setClause.deleteCharAt(setClause.length() - 1); - setClause.deleteCharAt(setClause.length() - 1); - } - String[] arguments = { row.getTable(), setClause.toString(), whereClause.toString()}; - MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.update.template")); - - String query = form.format(arguments); - // - // String query = "$results = mysql_query(\"UPDATE " + row.getTable(); - // query += " SET " + setClause.toString(); - // query += " WHERE " + whereClause.toString() + "\");"; - this.query.setText(query); - } - public boolean performFinish() { -// PHPSourceConsole console = PHPSourceConsole.getInstance(); -// console.clear(); -// console.print(query.getText()); - QuantumPlugin.getDefault().getSysClip().setContents( - new Object[] { query.getText() }, - new Transfer[] { TextTransfer.getInstance()}); - return true; - } -} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SQLPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SQLPage.java index 32b4322..69dc029 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SQLPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SQLPage.java @@ -1,11 +1,10 @@ package com.quantum.wizards; -import com.quantum.sql.TableRow; -import com.quantum.view.tableview.TableAdapter; +import com.quantum.sql.SQLResultSetResults; import org.eclipse.jface.wizard.IWizardPage; public interface SQLPage extends IWizardPage { - public void init(TableRow row, TableAdapter adapter); + public void init(SQLResultSetResults results, SQLResultSetResults.Row row); public boolean performFinish(); } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SQLRowWizard.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SQLRowWizard.java index bc37001..aa317c4 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SQLRowWizard.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SQLRowWizard.java @@ -1,19 +1,20 @@ package com.quantum.wizards; -import com.quantum.sql.TableRow; -import com.quantum.view.tableview.TableAdapter; +import com.quantum.sql.SQLResultSetResults; import org.eclipse.jface.wizard.Wizard; public class SQLRowWizard extends Wizard { - SQLPage page; - TableRow row; - TableAdapter adapter; - public void init(String title, SQLPage page, TableRow row, TableAdapter adapter) { + protected SQLPage page; + protected SQLResultSetResults.Row row; + private SQLResultSetResults results; + + public void init(String title, SQLPage page, + SQLResultSetResults results, SQLResultSetResults.Row row) { System.out.println("Init SQL row wizard"); //$NON-NLS-1$ this.row = row; - this.adapter = adapter; this.page = page; + this.results = results; setWindowTitle(title); } public boolean performFinish() { @@ -22,7 +23,7 @@ public class SQLRowWizard extends Wizard { } public void addPages() { System.out.println("QL row wizard adding pages"); //$NON-NLS-1$ - page.init(row, adapter); + page.init(this.results, this.row); addPage(page); } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SortFilterPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SortFilterPage.java index c23d03e..4447e10 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SortFilterPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/SortFilterPage.java @@ -1,9 +1,11 @@ package com.quantum.wizards; +import java.sql.SQLException; + import com.quantum.sql.FilterSort; -import com.quantum.sql.TableRow; -import com.quantum.view.tableview.TableAdapter; -import com.quantum.view.tableview.TableView; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.ui.dialog.ExceptionDisplayDialog; +import com.quantum.util.connection.ConnectionUtil; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -20,25 +22,27 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; public class SortFilterPage extends WizardPage implements SQLPage { - TableRow row; - TableAdapter adapter; Button[] filter; Combo[] operator; Text[] filterValues; Button[] stringFlags; Button[] sort; Combo[] ascDesc; + private SQLResultSetResults.Row row; + + private ConnectionUtil connectionUtil = new ConnectionUtil(); String columnNames[]; Label query; FilterSort filterSort = new FilterSort(); + private SQLResultSetResults results; public SortFilterPage(String pageName) { super(pageName); } - public void init(TableRow row, TableAdapter adapter) { + public void init(SQLResultSetResults results, SQLResultSetResults.Row row) { + this.results = results; this.row = row; - this.adapter = adapter; } public void createControl(Composite parent) { @@ -50,30 +54,16 @@ public class SortFilterPage extends WizardPage implements SQLPage { int layoutColumns = 6; layout.numColumns = layoutColumns; - if (row == null) { - System.out.println("Row is null"); //$NON-NLS-1$ - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); //$NON-NLS-1$ - } - if (row.getTableData() == null) { - System.out.println("Data is null"); //$NON-NLS-1$ - } + columnNames = this.results.getColumnNames(); - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$ - } - int size = row.getColumnCount(); + int size = this.results.getColumnCount(); filter = new Button[size]; operator = new Combo[size]; filterValues = new Text[size]; stringFlags = new Button[size]; sort = new Button[size]; ascDesc = new Combo[size]; - for (int i = 0; i < row.getColumnCount(); i++) { + for (int i = 0; i < size; i++) { filter[i] = new Button(container, SWT.CHECK); filter[i].setText(columnNames[i]); filter[i].addSelectionListener(new SelectionListener() { @@ -98,7 +88,8 @@ public class SortFilterPage extends WizardPage implements SQLPage { }); filterValues[i] = new Text(container, SWT.BORDER); - filterValues[i].setText(data[i]); + Object data = this.row == null ? null : this.row.get(i+1); + filterValues[i].setText(data == null ? "" : data.toString()); filterValues[i].addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { updateQuery(); @@ -173,8 +164,14 @@ public class SortFilterPage extends WizardPage implements SQLPage { } public boolean performFinish() { - adapter.setFilterSort(filterSort); - TableView.getInstance().refreshCurrent(); - return true; + this.results.setFilterSort(filterSort); + try { + this.results.refresh(this.connectionUtil.connect( + this.results.getBookmark(), getShell())); + return true; + } catch (SQLException e) { + ExceptionDisplayDialog.openError(getShell(), null, null, e); + return false; + } } } diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLBuilder.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLBuilder.java new file mode 100644 index 0000000..a22233a --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLBuilder.java @@ -0,0 +1,67 @@ +package com.quantum.wizards; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + + +/** + *

This class takes a URL pattern and creates a full URL. A URL pattern might look + * like this: jdbc:postgresql://{hostname}:{port}/{dbname}, and the + * properties should include "hostname", "port" and "dbname". + * + * @author BC Holmes + */ +public class URLBuilder { + + public static String createURL(String urlPattern, Map properties) { + StringBuffer buffer = new StringBuffer(); + boolean isVariable = false; + String variableName = null; + for (StringTokenizer tokenizer = new StringTokenizer(urlPattern, "{}", true); + tokenizer.hasMoreTokens(); ) { + String token = tokenizer.nextToken(); + + if ("{".equals(token) && !isVariable) { + isVariable = true; + } else if (isVariable && "}".equals(token) && variableName != null) { + if (!properties.containsKey(variableName)) { + buffer.append("{"); + buffer.append(variableName); + buffer.append("}"); + } else { + buffer.append(properties.get(variableName)); + } + isVariable = false; + } else if (isVariable) { + variableName = token; + } else { + buffer.append(token); + } + } + return buffer.toString(); + } + + public static String[] getVariableNames(String urlPattern) { + List list = new ArrayList(); + if (urlPattern != null) { + boolean isVariable = false; + String variableName = null; + for (StringTokenizer tokenizer = new StringTokenizer(urlPattern, "{}", true); + tokenizer.hasMoreTokens(); ) { + String token = tokenizer.nextToken(); + + if ("{".equals(token) && !isVariable) { + isVariable = true; + } else if (isVariable && "}".equals(token) && variableName != null) { + list.add(variableName); + isVariable = false; + } else if (isVariable) { + variableName = token; + } + } + } + return (String[]) list.toArray(new String[list.size()]); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLSetupControl.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLSetupControl.java new file mode 100644 index 0000000..b689441 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLSetupControl.java @@ -0,0 +1,112 @@ +package com.quantum.wizards; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import com.quantum.Messages; +import com.quantum.adapters.AdapterFactory; +import com.quantum.adapters.DatabaseAdapter; +import com.quantum.model.JDBCDriver; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + + +/** + * @author BC + */ +public abstract class URLSetupControl extends Composite { + + private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); + private String urlPattern; + private Map properties = Collections.synchronizedMap(new HashMap()); + private final JDBCDriver driver; + private String connectionURL; + + /** + * @param parent + * @param style + */ + public URLSetupControl(Composite parent, JDBCDriver driver) { + super(parent, SWT.NONE); + this.driver = driver; + GridLayout layout = new GridLayout(); + setLayout(layout); + this.urlPattern = AdapterFactory.getInstance().getURLPattern(driver.getClassName()); + + setPropertyDefaults(); + setConnectionURL(URLBuilder.createURL(this.urlPattern, getProperties())); + } + + /** + * + */ + protected void createPart() { + Group group = new Group(this, SWT.SHADOW_ETCHED_IN); + group.setText(Messages.getString(URLSetupControl.class, "text")); + group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); + + createPart(group); + } + + /** + * + */ + private void setPropertyDefaults() { + DatabaseAdapter adapter = + AdapterFactory.getInstance().getAdapter(getDriver().getType()); + Map properties = (adapter == null) ? new HashMap() : adapter.getDefaultConnectionParameters(); + for (Iterator i = properties.keySet().iterator(); i.hasNext();) { + String key = (String) i.next(); + putProperty(key, (String) properties.get(key)); + + } + } + + protected abstract void createPart(Composite parent); + + private Map getProperties() { + return this.properties; + } + + protected String getProperty(String name) { + String value = (String) this.properties.get(name); + return value == null ? "" : value; + } + + protected void putProperty(String name, String value) { + this.properties.put(name, value); + setConnectionURL(URLBuilder.createURL(this.urlPattern, getProperties())); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + this.propertyChangeSupport.addPropertyChangeListener(listener); + } + public void removePropertyChangeListener(PropertyChangeListener listener) { + this.propertyChangeSupport.removePropertyChangeListener(listener); + } + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); + } + + protected JDBCDriver getDriver() { + return this.driver; + } + public String getConnectionURL() { + return this.connectionURL == null ? "" : this.connectionURL; + } + public void setConnectionURL(String connectionURL) { + if (connectionURL != null && !connectionURL.equals(this.connectionURL)) { + String original = this.connectionURL; + this.connectionURL = connectionURL; + firePropertyChange("connectionURL", original, connectionURL); + } + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLSetupControlFactory.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLSetupControlFactory.java new file mode 100644 index 0000000..0b204d5 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/URLSetupControlFactory.java @@ -0,0 +1,80 @@ +package com.quantum.wizards; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.quantum.adapters.AdapterFactory; +import com.quantum.model.JDBCDriver; + +import org.eclipse.swt.widgets.Composite; + + +/** + * @author BC Holmes + */ +public class URLSetupControlFactory { + + public static boolean hasControl(JDBCDriver driver) { + return null != getControlClass(driver); + } + + public static URLSetupControl create(JDBCDriver driver, Composite composite) { + Class controlClass = getControlClass(driver); + + if (BasicThreePartURLSetupControl.class == controlClass) { + URLSetupControl control = new BasicThreePartURLSetupControl(composite, driver); + control.createPart(); + return control; + } else if (BasicOnePartURLSetupControl.class == controlClass) { + String[] properties = getProperties(driver); + URLSetupControl control = new BasicOnePartURLSetupControl(composite, driver, properties[0]); + control.createPart(); + return control; + } else if (InformixURLSetupControl.class == controlClass) { + URLSetupControl control = new InformixURLSetupControl(composite, driver); + control.createPart(); + return control; + } else { + return null; + } + } + + private static Class getControlClass(JDBCDriver driver) { + String[] parameters = getProperties(driver); + List parametersList = new ArrayList(); + if (parameters != null) { + parametersList.addAll(Arrays.asList(parameters)); + } + + if (parametersList.size() == 3 + && parametersList.contains("dbname") + && parametersList.contains("hostname") + && parametersList.contains("port")) { + return BasicThreePartURLSetupControl.class; + } else if (parametersList.size() == 4 + && parametersList.contains("dbname") + && parametersList.contains("hostname") + && parametersList.contains("informixserver") + && parametersList.contains("port")) { + return InformixURLSetupControl.class; + } else if (parametersList.size() == 1 + && (parametersList.contains("dbname") + || parametersList.contains("datasource"))) { + return BasicOnePartURLSetupControl.class; + } else { + return null; + } + } + + /** + * @param driver + * @return + */ + private static String[] getProperties(JDBCDriver driver) { + String driverClassName = driver.getClassName(); + String urlPattern = AdapterFactory.getInstance().getURLPattern(driverClassName); + String[] parameters = URLBuilder.getVariableNames(urlPattern); + return parameters; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/UpdateRowPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/UpdateRowPage.java index e1dd3c5..3753b7c 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/UpdateRowPage.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/UpdateRowPage.java @@ -15,6 +15,7 @@ import org.eclipse.swt.widgets.Text; import com.quantum.Messages; import com.quantum.adapters.DatabaseAdapter; import com.quantum.model.Bookmark; +import com.quantum.model.Column; import com.quantum.model.Entity; public class UpdateRowPage extends BaseSQLPage implements SQLPage { @@ -33,30 +34,16 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { Composite container = new Composite(parent, SWT.V_SCROLL); GridLayout layout = new GridLayout(); container.setLayout(layout); - Entity entity = row.getEntity(); + Entity entity = this.results.getEntity(); int layoutColumns = 5; layout.numColumns = layoutColumns; - if (row == null) { - System.out.println("Row is null"); //$NON-NLS-1$ - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); //$NON-NLS-1$ - } - if (row.getTableData() == null) { - System.out.println("Data is null"); //$NON-NLS-1$ - } - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$ - } - oldValues = new Text[row.getColumnCount()]; - newValues = new Text[row.getColumnCount()]; - primaryKeys = new Button[row.getColumnCount()]; - setValues = new Button[row.getColumnCount()]; + columnNames = this.results.getColumnNames(); + oldValues = new Text[columnNames.length]; + newValues = new Text[columnNames.length]; + primaryKeys = new Button[columnNames.length]; + setValues = new Button[columnNames.length]; Label temp = new Label(container, SWT.NULL); temp.setText(Messages.getString("UpdateRowPage.ColumnName")); //$NON-NLS-1$ temp = new Label(container, SWT.NULL); @@ -67,11 +54,15 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { temp.setText(Messages.getString("UpdateRowPage.NewValue")); //$NON-NLS-1$ temp = new Label(container, SWT.NULL); temp.setText(Messages.getString("UpdateRowPage._13")); //$NON-NLS-1$ - for (int i = 0; i < row.getColumnCount(); i++) { + for (int i = 0; i < columnNames.length; i++) { Label label = new Label(container, SWT.NULL); label.setText(columnNames[i]); oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - oldValues[i].setText(data[i]); + GridData gridData = new GridData(); + gridData.widthHint = 100; + oldValues[i].setLayoutData(gridData); + Object data = this.row == null ? null : this.row.get(i+1); + oldValues[i].setText(data == null ? "" : data.toString()); oldValues[i].addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { updateQuery(); @@ -79,7 +70,8 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { }); primaryKeys[i] = new Button(container, SWT.CHECK); primaryKeys[i].setText("Where"); //$NON-NLS-1$ - if (entity != null && getColumn(entity, columnNames[i]).isPrimaryKey()) + Column column = (entity == null) ? null : getColumn(entity, columnNames[i]); + if (column != null && column.isPrimaryKey()) primaryKeys[i].setSelection(true); primaryKeys[i].addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { @@ -89,7 +81,10 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { } }); newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - newValues[i].setText(data[i]); + newValues[i].setText(data == null ? "" : data.toString()); + gridData = new GridData(); + gridData.widthHint = 100; + newValues[i].setLayoutData(gridData); newValues[i].addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { updateQuery(); @@ -123,8 +118,8 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { System.out.println("Updating query"); //$NON-NLS-1$ StringBuffer setClause = new StringBuffer(); StringBuffer whereClause = new StringBuffer(); - Bookmark bookmark = row.getBookmark(); - Entity entity = row.getEntity(); + Bookmark bookmark = this.results.getBookmark(); + Entity entity = this.results.getEntity(); DatabaseAdapter adapter = bookmark.getAdapter(); int numValuesSet = 0; @@ -149,7 +144,7 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage { numValuesSet++; } } - String query = "UPDATE " + row.getTable(); //$NON-NLS-1$ + String query = "UPDATE " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$ query += " SET " + setClause.toString(); //$NON-NLS-1$ query += " WHERE " + whereClause.toString(); //$NON-NLS-1$ this.query.setText(query); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenSQLTableEditorAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenSQLTableEditorAction.java index 848a1ca..99fbfc5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenSQLTableEditorAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenSQLTableEditorAction.java @@ -45,240 +45,279 @@ import org.eclipse.ui.dialogs.ListSelectionDialog; import org.eclipse.ui.internal.dialogs.ListContentProvider; import com.quantum.QuantumPlugin; +import com.quantum.adapters.DatabaseAdapter; import com.quantum.model.Bookmark; import com.quantum.model.BookmarkCollection; import com.quantum.model.Entity; import com.quantum.model.EntityFactory; import com.quantum.model.NotConnectedException; +import com.quantum.sql.MultiSQLServer; +import com.quantum.sql.SQLResultSetCollection; +import com.quantum.sql.SQLResultSetResults; +import com.quantum.sql.SQLResults; +import com.quantum.ui.dialog.ExceptionDisplayDialog; import com.quantum.util.connection.ConnectionUtil; import com.quantum.view.tableview.TableView; -public class PHPOpenSQLTableEditorAction extends ActionDelegate - implements - IEditorActionDelegate { - - private IWorkbenchWindow fWindow; - private PHPEditor fEditor; - private IProject fProject; - - public void dispose() { - } - - public void init(IWorkbenchWindow window) { - this.fWindow = window; - } - - public void selectionChanged(IAction action, ISelection selection) { - if (!selection.isEmpty()) { - if (selection instanceof TextSelection) { - action.setEnabled(true); - } else if (fWindow.getActivePage() != null - && fWindow.getActivePage().getActivePart() != null) { - // - } - } - } - private IWorkbenchPage getActivePage() { - IWorkbenchWindow workbenchWindow = fEditor.getEditorSite() - .getWorkbenchWindow(); - IWorkbenchPage page = workbenchWindow.getActivePage(); - return page; - } - public IContainer getWorkingLocation(IFileEditorInput editorInput) { - if (editorInput == null || editorInput.getFile() == null) { - return null; - } - return editorInput.getFile().getParent(); - } - private IFile getIncludeFile(IProject project, - IFileEditorInput editorInput, String relativeFilename) { - // IContainer container = getWorkingLocation(editorInput); - // String fullPath = project.getLocation().toString(); - Path path = new Path(relativeFilename); - IFile file = project.getFile(path); - return file; - } - - public void run(IAction action) { - if (fEditor == null) { - IEditorPart targetEditor = fWindow.getActivePage() - .getActiveEditor(); - if (targetEditor != null && (targetEditor instanceof PHPEditor)) { - fEditor = (PHPEditor) targetEditor; - } - } - if (fEditor != null) { - // TableView view = TableView.getInstance(); - - // determine the current Project from a (file-based) Editor - IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile(); - fProject = f.getProject(); - - ITextSelection selection = (ITextSelection) fEditor - .getSelectionProvider().getSelection(); - IDocument doc = fEditor.getDocumentProvider().getDocument( - fEditor.getEditorInput()); - int pos = selection.getOffset(); - // System.out.println(selection.getText()); - String tableName = getSQLTableName(doc, pos); - - IViewPart viewPart = null; - String view = "com.quantum.view.tableview.TableView"; - try { - IWorkbenchPage page = QuantumPlugin.getDefault() - .getActivePage(); - viewPart = page.findView(view); - if (viewPart == null) { - viewPart = page.showView(view); - } - page.bringToTop(viewPart); - getTables((TableView) viewPart, fProject, tableName); - } catch (PartInitException e) { - e.printStackTrace(); - } - - } - } - - public void setActiveEditor(IAction action, IEditorPart targetEditor) { - if (targetEditor != null && (targetEditor instanceof PHPEditor)) { - fEditor = (PHPEditor) targetEditor; - } - } - - private String getSQLTableName(IDocument doc, int pos) { - Point word = null; - int start = -1; - int end = -1; - - try { - - int position = pos; - char character; - - while (position >= 0) { - character = doc.getChar(position); - if (Character.isWhitespace(character) || (character == '\"') - || (character == '\'') || (character == '\r') - || (character == '\n')) - break; - --position; - } - - start = position; - - position = pos; - int length = doc.getLength(); - - while (position < length) { - character = doc.getChar(position); - if (Character.isWhitespace(character) || (character == '\"') - || (character == '\'') || (character == '\r') - || (character == '\n')) - break; - ++position; - } - - start++; - end = position; - - if (end > start) - word = new Point(start, end - start); - - } catch (BadLocationException x) { - } - - if (word != null) { - try { - return doc.get(word.x, word.y); - } catch (BadLocationException e) { - } - } - return ""; - } - - public void getTables(TableView tableView, IProject project, - String tableName) { - // Get The Database bookmark from the Quantum SQL plugin: - BookmarkCollection sqlBookMarks = BookmarkCollection.getInstance(); - if (sqlBookMarks != null) { - String bookmarkString = Util.getMiscProjectsPreferenceValue( - project, IPreferenceConstants.PHP_BOOKMARK_DEFAULT); - if (bookmarkString != null && !bookmarkString.equals("")) { - Bookmark bookmark = sqlBookMarks.find(bookmarkString); - ArrayList sqlList = new ArrayList(); - if (bookmark != null && !bookmark.isConnected()) { - new ConnectionUtil().connect(bookmark, null); - } - if (bookmark != null && bookmark.isConnected()) { - try { - Connection connection = bookmark.getConnection(); - DatabaseMetaData metaData = connection.getMetaData(); - - if (metaData != null) { - String columnName; - String prefixWithoutDollar = tableName; - if (prefixWithoutDollar.charAt(0) == '$') { - prefixWithoutDollar = prefixWithoutDollar - .substring(1); - } - ResultSet set; - set = metaData.getTables(null, null, "%" - + prefixWithoutDollar+"%", null); - while (set.next()) { - tableName = set.getString("TABLE_NAME"); - tableName = (tableName == null) - ? "" - : tableName.trim(); - if (tableName != null && tableName.length() > 0) { - sqlList.add(tableName); - } - } - set.close(); - EntityFactory entityFactory = EntityFactory - .getInstance(); - if (sqlList.size() == 1) { - tableView.loadTable(entityFactory.create( - bookmark, null, - (String) sqlList.get(0), - Entity.TABLE_TYPE)); - } else if (sqlList.size() > 1) { - ListSelectionDialog listSelectionDialog = new ListSelectionDialog( - PHPeclipsePlugin.getDefault() - .getWorkbench() - .getActiveWorkbenchWindow() - .getShell(), sqlList, - new ListContentProvider(), - new LabelProvider(), - "Select the SQL to open."); - listSelectionDialog - .setTitle("Multiple tablenames found"); - if (listSelectionDialog.open() == Window.OK) { - Object[] locations = listSelectionDialog - .getResult(); - if (locations != null) { - for (int i = 0; i < locations.length; i++) { - tableView - .loadTable(entityFactory - .create( - bookmark, - null, - (String) locations[i], - Entity.TABLE_TYPE)); - } - - } - } - } - } - } catch (NotConnectedException e) { - // ignore this - not mission critical - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - } +public class PHPOpenSQLTableEditorAction extends ActionDelegate implements + IEditorActionDelegate { + + private IWorkbenchWindow fWindow; + + private PHPEditor fEditor; + + private IProject fProject; + + public void dispose() { + } + + public void init(IWorkbenchWindow window) { + this.fWindow = window; + } + + public void selectionChanged(IAction action, ISelection selection) { + if (!selection.isEmpty()) { + if (selection instanceof TextSelection) { + action.setEnabled(true); + } else if (fWindow.getActivePage() != null + && fWindow.getActivePage().getActivePart() != null) { + // + } + } + } + + private IWorkbenchPage getActivePage() { + fWindow = fEditor.getEditorSite() + .getWorkbenchWindow(); + IWorkbenchPage page = fWindow.getActivePage(); + return page; + } + + public IContainer getWorkingLocation(IFileEditorInput editorInput) { + if (editorInput == null || editorInput.getFile() == null) { + return null; + } + return editorInput.getFile().getParent(); + } + + private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, + String relativeFilename) { + // IContainer container = getWorkingLocation(editorInput); + // String fullPath = project.getLocation().toString(); + Path path = new Path(relativeFilename); + IFile file = project.getFile(path); + return file; + } + + public void run(IAction action) { + if (fEditor == null) { + IEditorPart targetEditor = fWindow.getActivePage().getActiveEditor(); + if (targetEditor != null && (targetEditor instanceof PHPEditor)) { + fEditor = (PHPEditor) targetEditor; + } + } + if (fEditor != null) { + // TableView view = TableView.getInstance(); + + // determine the current Project from a (file-based) Editor + fWindow = fEditor.getEditorSite().getWorkbenchWindow(); + IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile(); + fProject = f.getProject(); + + ITextSelection selection = (ITextSelection) fEditor + .getSelectionProvider().getSelection(); + IDocument doc = fEditor.getDocumentProvider().getDocument( + fEditor.getEditorInput()); + int pos = selection.getOffset(); + // System.out.println(selection.getText()); + String tableName = getSQLTableName(doc, pos); + + IViewPart viewPart = null; + String view = "com.quantum.view.tableview.TableView"; + try { + IWorkbenchPage page = QuantumPlugin.getDefault().getActivePage(); + viewPart = page.findView(view); + if (viewPart == null) { + viewPart = page.showView(view); + } + page.bringToTop(viewPart); + getTables((TableView) viewPart, fProject, tableName); + } catch (PartInitException e) { + e.printStackTrace(); + } + + } + } + + public void setActiveEditor(IAction action, IEditorPart targetEditor) { + if (targetEditor != null && (targetEditor instanceof PHPEditor)) { + fEditor = (PHPEditor) targetEditor; + } + } + + private String getSQLTableName(IDocument doc, int pos) { + Point word = null; + int start = -1; + int end = -1; + + try { + + int position = pos; + char character; + + while (position >= 0) { + character = doc.getChar(position); + if (Character.isWhitespace(character) || (character == '\"') + || (character == '\'') || (character == '\r') + || (character == '\n')) + break; + --position; + } + + start = position; + + position = pos; + int length = doc.getLength(); + + while (position < length) { + character = doc.getChar(position); + if (Character.isWhitespace(character) || (character == '\"') + || (character == '\'') || (character == '\r') + || (character == '\n')) + break; + ++position; + } + + start++; + end = position; + + if (end > start) + word = new Point(start, end - start); + + } catch (BadLocationException x) { + } + + if (word != null) { + try { + return doc.get(word.x, word.y); + } catch (BadLocationException e) { + } + } + return ""; + } + + public void getTables(TableView tableView, IProject project, String tableName) { + // Get The Database bookmark from the Quantum SQL plugin: + BookmarkCollection sqlBookMarks = BookmarkCollection.getInstance(); + if (sqlBookMarks != null) { + String bookmarkString = Util.getMiscProjectsPreferenceValue(project, + IPreferenceConstants.PHP_BOOKMARK_DEFAULT); + if (bookmarkString != null && !bookmarkString.equals("")) { + Bookmark bookmark = sqlBookMarks.find(bookmarkString); + ArrayList sqlList = new ArrayList(); + if (bookmark != null && !bookmark.isConnected()) { + new ConnectionUtil().connect(bookmark, null); + } + if (bookmark != null && bookmark.isConnected()) { + try { + Connection connection = bookmark.getConnection(); + DatabaseMetaData metaData = connection.getMetaData(); + ConnectionUtil connectionUtil = new ConnectionUtil(); + Entity entity; + DatabaseAdapter adapter; + + if (metaData != null) { + String columnName; + String prefixWithoutDollar = tableName; + if (prefixWithoutDollar.charAt(0) == '$') { + prefixWithoutDollar = prefixWithoutDollar.substring(1); + } + ResultSet set; + set = metaData.getTables(null, null, "%" + prefixWithoutDollar + + "%", null); + while (set.next()) { + tableName = set.getString("TABLE_NAME"); + tableName = (tableName == null) ? "" : tableName.trim(); + if (tableName != null && tableName.length() > 0) { + sqlList.add(tableName); + } + } + set.close(); + EntityFactory entityFactory = EntityFactory.getInstance(); + if (sqlList.size() == 1) { + adapter = bookmark.getAdapter(); + entity = entityFactory.create(bookmark, null, (String) sqlList + .get(0), Entity.TABLE_TYPE); + String query = adapter.getTableQuery(entity.getQualifiedName()); + + try { + SQLResults results = MultiSQLServer.getInstance().execute( + bookmark, connectionUtil.connect(bookmark, fWindow.getShell()), + entity, query); + + if (results != null && results.isResultSet()) { + SQLResultSetCollection.getInstance().addSQLResultSet( + (SQLResultSetResults) results); + } + } catch (SQLException e) { + ExceptionDisplayDialog.openError(fWindow.getShell(), null, null, e); + } + // tableView.loadTable(entityFactory.create( + // bookmark, null, + // (String) sqlList.get(0), + // Entity.TABLE_TYPE)); + } else if (sqlList.size() > 1) { + ListSelectionDialog listSelectionDialog = new ListSelectionDialog( + PHPeclipsePlugin.getDefault().getWorkbench() + .getActiveWorkbenchWindow().getShell(), sqlList, + new ListContentProvider(), new LabelProvider(), + "Select the SQL table to open."); + listSelectionDialog.setTitle("Multiple tablenames found"); + if (listSelectionDialog.open() == Window.OK) { + Object[] locations = listSelectionDialog.getResult(); + if (locations != null) { + for (int i = 0; i < locations.length; i++) { + adapter = bookmark.getAdapter(); + entity = entityFactory.create(bookmark, null, + (String) locations[i], Entity.TABLE_TYPE); + String query = adapter.getTableQuery(entity + .getQualifiedName()); + + try { + SQLResults results = MultiSQLServer.getInstance() + .execute(bookmark, + connectionUtil.connect(bookmark, fWindow.getShell()), + entity, query); + + if (results != null && results.isResultSet()) { + SQLResultSetCollection.getInstance().addSQLResultSet( + (SQLResultSetResults) results); + } + } catch (SQLException e) { + ExceptionDisplayDialog.openError(fWindow.getShell(), null, null, e); + } + + // tableView + // .loadTable(entityFactory + // .create( + // bookmark, + // null, + // (String) locations[i], + // Entity.TABLE_TYPE)); + } + + } + } + } + } + } catch (NotConnectedException e) { + // ignore this - not mission critical + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + } } \ No newline at end of file