From d3e3673f9469ec85ffb75472c805e913dbf41934 Mon Sep 17 00:00:00 2001 From: khartlage Date: Fri, 4 Jun 2004 19:23:36 +0000 Subject: [PATCH 1/1] 3.x RC1 compatibility --- .../.classpath | 2 - .../plugin-3.0.xml | 300 -------------------- .../plugin.xml | 32 ++- .../schema/data.exsd | 6 +- .../schema/metadata.exsd | 6 +- .../src/com/quantum/QuantumPlugin.java | 28 ++- .../src/com/quantum/QuantumResources.properties | 4 + .../php/PHPSQLConnectionPreferencePage.java | 108 +++++++ .../php/PHPSQLTemplatesPreferencePage.java | 94 ++++++ .../src/com/quantum/util/xml/XMLHelper.java | 27 +- .../src/com/quantum/view/PHPSourceConsole.java | 157 ++++++++++ .../view/tableview/TableViewMenuListener.java | 279 ++++++++++-------- .../src/com/quantum/wizards/PHPDeleteRowPage.java | 174 +++++++++++ .../src/com/quantum/wizards/PHPInsertRowPage.java | 144 ++++++++++ .../src/com/quantum/wizards/PHPSelectRowPage.java | 202 +++++++++++++ .../src/com/quantum/wizards/PHPUpdateRowPage.java | 195 +++++++++++++ 16 files changed, 1312 insertions(+), 446 deletions(-) delete mode 100644 archive/net.sourceforge.phpeclipse.quantum.sql/plugin-3.0.xml create mode 100644 archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLConnectionPreferencePage.java create mode 100644 archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLTemplatesPreferencePage.java create mode 100644 archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/PHPSourceConsole.java create mode 100644 archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPDeleteRowPage.java create mode 100644 archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPInsertRowPage.java create mode 100644 archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPSelectRowPage.java create mode 100644 archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPUpdateRowPage.java diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/.classpath b/archive/net.sourceforge.phpeclipse.quantum.sql/.classpath index 5074f04..065ac06 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/.classpath +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/.classpath @@ -1,9 +1,7 @@ - - diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin-3.0.xml b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin-3.0.xml deleted file mode 100644 index 213fbe7..0000000 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin-3.0.xml +++ /dev/null @@ -1,300 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - A wizard that exports the list of database bookmarks to a Quantum bookmark file. - - - - - A wizard that exports the database structure to a Torque-compatible XML file. - - - - - - - - - - - diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml index 4558693..9d27d0d 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/plugin.xml @@ -8,10 +8,19 @@ class="com.quantum.QuantumPlugin"> - + + + + + @@ -22,7 +31,6 @@ - @@ -146,6 +154,12 @@ class="com.quantum.view.SQLQueryView" id="com.quantum.view.sqlqueryview"> + + @@ -203,6 +217,18 @@ class="com.quantum.preferences.CustomCopyPreferences3" id="com.quantum.preferences.customcopy3"> + + + + - + - + This extension point allow other plug-ins to act on data information extracted by Quantum. @@ -97,7 +97,7 @@ For each registered extension, Quantum will add a menu entry in the context menu - + diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/schema/metadata.exsd b/archive/net.sourceforge.phpeclipse.quantum.sql/schema/metadata.exsd index 25ea75f..eca31de 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/schema/metadata.exsd +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/schema/metadata.exsd @@ -1,15 +1,15 @@ - + - + This extension point allow other plug-ins to act on metadata information extracted by Quantum. For each registered extension, Quantum will add a menu entry in the context menu of the Bookmarks View. - + 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 154604a..140a149 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 @@ -46,7 +46,7 @@ import org.xml.sax.SAXException; * Main class of the quantum plugin, sets defaults, saves and recovers state. */ public class QuantumPlugin extends AbstractUIPlugin { - + public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.quantum.sql"; private static QuantumPlugin plugin; private Clipboard sysClip; @@ -129,7 +129,7 @@ public class QuantumPlugin extends AbstractUIPlugin { */ public void shutdown() throws CoreException { super.shutdown(); - sysClip.dispose(); +// sysClip.dispose(); } /** @@ -208,6 +208,30 @@ public class QuantumPlugin extends AbstractUIPlugin { 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$ + + getPreferenceStore().setDefault( + "phpeclipse.sql.select.template", + "$results = mysql_query(\"SELECT {0} FROM {1} WHERE {2} \");"); + + getPreferenceStore().setDefault( + "phpeclipse.sql.insert.template", + "$results = mysql_query(\"INSERT INTO {0} ({1}) VALUES {2} \");"); + + getPreferenceStore().setDefault("phpeclipse.sql.update.template", "$results = mysql_query(\"UPDATE {0} SET {1} WHERE {2} \");"); + + getPreferenceStore().setDefault("phpeclipse.sql.delete.template", "$results = mysql_query(\"DELETE FROM {0} WHERE {1} \");"); + + getPreferenceStore().setDefault("phpeclipse.sql.username.connect", "root"); + + getPreferenceStore().setDefault("phpeclipse.sql.connect.connect", "jdbc:mysql://localhost/mysql"); + + getPreferenceStore().setDefault("phpeclipse.sql.driver.connect", "com.mysql.jdbc.Driver"); + + getPreferenceStore().setDefault("phpeclipse.sql.type.connect", "MySQL"); + + getPreferenceStore().setDefault( + "phpeclipse.sql.filename.connect", + "C:\\wampp2\\mysql\\lib\\mysql-connector.jar"); } // Returns the active page public IWorkbenchPage getActivePage() 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 d0a7e30..06a897b 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 @@ -30,6 +30,10 @@ tableview.close = Close Table tableview.update = Update... tableview.insert = Insert... tableview.delete = Delete... +tableview.phpselect = PHP Select... +tableview.phpupdate = PHP Update... +tableview.phpinsert = PHP Insert... +tableview.phpdelete = PHP Delete... tableview.filterSort = Sort or Filter Table... tableview.showAll = Toggle Show All Table Rows tableview.defaultEncoding = Set Default Encoding 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/preferences/php/PHPSQLConnectionPreferencePage.java new file mode 100644 index 0000000..99f7918 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLConnectionPreferencePage.java @@ -0,0 +1,108 @@ +package com.quantum.preferences.php; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.preference.StringFieldEditor; +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.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +import com.quantum.QuantumPlugin; + +public class PHPSQLConnectionPreferencePage + extends PreferencePage + implements IWorkbenchPreferencePage { + + StringFieldEditor fUserNameSFE; + StringFieldEditor fConnectSFE; + StringFieldEditor fDriverSFE; + StringFieldEditor fTypeSFE; + StringFieldEditor fDriverFileFFE; + + public PHPSQLConnectionPreferencePage() { + super(); + setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore()); + } + public void init(IWorkbench workbench) { + setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore()); + } + protected void performDefaults() { + fUserNameSFE.loadDefault(); + fConnectSFE.loadDefault(); + fDriverSFE.loadDefault(); + fTypeSFE.loadDefault(); + fDriverFileFFE.loadDefault(); + super.performDefaults(); + } + + public boolean performOk() { + fUserNameSFE.store(); + fConnectSFE.store(); + fDriverSFE.store(); + fTypeSFE.store(); + fDriverFileFFE.store(); + return super.performOk(); + } + + protected Control createContents(Composite parent) { + initializeDialogUnits(parent); + // final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + Composite composite = new Composite(parent, SWT.LEFT); + GridLayout layout = new GridLayout(); + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + // layout.numColumns = 1; + + fUserNameSFE = + new StringFieldEditor( + "phpeclipse.sql.username.connect", + "Default User name:", + composite); + fUserNameSFE.setPreferencePage(this); + fUserNameSFE.setPreferenceStore(getPreferenceStore()); + fUserNameSFE.load(); + + fConnectSFE = + new StringFieldEditor( + "phpeclipse.sql.connect.connect", + "Connect:", + composite); + fConnectSFE.setPreferencePage(this); + fConnectSFE.setPreferenceStore(getPreferenceStore()); + fConnectSFE.load(); + + fDriverSFE = + new StringFieldEditor( + "phpeclipse.sql.driver.connect", + "Driver:", + composite); + fDriverSFE.setPreferencePage(this); + fDriverSFE.setPreferenceStore(getPreferenceStore()); + fDriverSFE.load(); + + fTypeSFE = + new StringFieldEditor("phpeclipse.sql.type.connect", "Type:", composite); + fTypeSFE.setPreferencePage(this); + fTypeSFE.setPreferenceStore(getPreferenceStore()); + fTypeSFE.load(); + + // fDriverFileFFE = + // new FileFieldEditor( + // "phpeclipse.sql.filename.connect", + // "Driver filename:", + // composite); + fDriverFileFFE = + new StringFieldEditor( + "phpeclipse.sql.filename.connect", + "Driver filename:", + composite); + fDriverFileFFE.setPreferencePage(this); + fDriverFileFFE.setPreferenceStore(getPreferenceStore()); + fDriverFileFFE.load(); + + return composite; + } +} 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/preferences/php/PHPSQLTemplatesPreferencePage.java new file mode 100644 index 0000000..6854ee5 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/preferences/php/PHPSQLTemplatesPreferencePage.java @@ -0,0 +1,94 @@ +package com.quantum.preferences.php; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.preference.StringFieldEditor; +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.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +import com.quantum.QuantumPlugin; + +public class PHPSQLTemplatesPreferencePage + extends PreferencePage + implements IWorkbenchPreferencePage { + + StringFieldEditor fPHPSelectSFE; + StringFieldEditor fPHPInsertSFE; + StringFieldEditor fPHPUpdateSFE; + StringFieldEditor fPHPDeleteSFE; + + public PHPSQLTemplatesPreferencePage() { + super(); + setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore()); + // setDescription("PHP SQL templates"); //$NON-NLS-1$ + } + + public void init(IWorkbench workbench) { + setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore()); + } + + protected void performDefaults() { + fPHPSelectSFE.loadDefault(); + fPHPInsertSFE.loadDefault(); + fPHPUpdateSFE.loadDefault(); + fPHPDeleteSFE.loadDefault(); + super.performDefaults(); + } + + public boolean performOk() { + fPHPSelectSFE.store(); + fPHPInsertSFE.store(); + fPHPUpdateSFE.store(); + fPHPDeleteSFE.store(); + return super.performOk(); + } + + protected Control createContents(Composite parent) { + initializeDialogUnits(parent); + // final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + Composite composite = new Composite(parent, SWT.LEFT); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + composite.setLayout(new GridLayout()); + + fPHPSelectSFE = + new StringFieldEditor( + "phpeclipse.sql.select.template", + "SELECT template:", + composite); + fPHPSelectSFE.setPreferencePage(this); + fPHPSelectSFE.setPreferenceStore(getPreferenceStore()); + fPHPSelectSFE.load(); + + fPHPInsertSFE = + new StringFieldEditor( + "phpeclipse.sql.insert.template", + "INSERT template:", + composite); + fPHPInsertSFE.setPreferencePage(this); + fPHPInsertSFE.setPreferenceStore(getPreferenceStore()); + fPHPInsertSFE.load(); + + fPHPUpdateSFE = + new StringFieldEditor( + "phpeclipse.sql.update.template", + "UPDATE template:", + composite); + fPHPUpdateSFE.setPreferencePage(this); + fPHPUpdateSFE.setPreferenceStore(getPreferenceStore()); + fPHPUpdateSFE.load(); + + fPHPDeleteSFE = + new StringFieldEditor( + "phpeclipse.sql.delete.template", + "DELETE template:", + composite); + fPHPDeleteSFE.setPreferencePage(this); + fPHPDeleteSFE.setPreferenceStore(getPreferenceStore()); + fPHPDeleteSFE.load(); + return composite; + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/xml/XMLHelper.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/xml/XMLHelper.java index bf16296..9fdeeef 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/xml/XMLHelper.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/util/xml/XMLHelper.java @@ -10,9 +10,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; -import org.apache.xml.serialize.DOMSerializer; -import org.apache.xml.serialize.OutputFormat; -import org.apache.xml.serialize.XMLSerializer; +import org.apache.xalan.serialize.DOMSerializer; +import org.apache.xalan.serialize.SerializerToXML; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -28,21 +27,27 @@ public class XMLHelper { public static DOMSerializer createDOMSerializer(Writer writer) throws IOException { - XMLSerializer serializer = new XMLSerializer(writer, createOutputFormat()); +// XMLSerializer serializer = new XMLSerializer(writer, createOutputFormat()); +// return serializer.asDOMSerializer(); + SerializerToXML serializer = new SerializerToXML(); + serializer.setWriter(writer); return serializer.asDOMSerializer(); } public static DOMSerializer createDOMSerializer(OutputStream stream) throws IOException { - XMLSerializer serializer = new XMLSerializer(stream, createOutputFormat()); +// XMLSerializer serializer = new XMLSerializer(stream, createOutputFormat()); +// return serializer.asDOMSerializer(); + SerializerToXML serializer = new SerializerToXML(); + serializer.setOutputStream(stream); return serializer.asDOMSerializer(); } - private static OutputFormat createOutputFormat() { - OutputFormat format = new OutputFormat(); - format.setIndenting(true); - format.setLineWidth(80); - return format; - } +// private static OutputFormat createOutputFormat() { +// OutputFormat format = new OutputFormat(); +// format.setIndenting(true); +// format.setLineWidth(80); +// return format; +// } public static Document createEmptyDocument() throws ParserConfigurationException { DocumentBuilder builder = createDocumentBuilder(); diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/PHPSourceConsole.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/PHPSourceConsole.java new file mode 100644 index 0000000..42c2956 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/PHPSourceConsole.java @@ -0,0 +1,157 @@ +package com.quantum.view; + +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; + +import com.quantum.Messages; +import com.quantum.QuantumPlugin; + +/** + * The PHPSourceConsole is used to display the output from the PHP SQL wizards + * @see ViewPart + */ +public class PHPSourceConsole extends ViewPart { + + public static final String CONSOLE_ID = + "net.sourceforge.phpdt.sql.view.phpsourceconsoleview"; + + TextViewer viewer = null; + private Document document = null; + + /** + * The constructor. + */ + public PHPSourceConsole() { + } + + /** + * Insert the method's description here. + * @see ViewPart#createPartControl + */ + public void createPartControl(Composite parent) { + viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); + GridData viewerData = new GridData(GridData.FILL_BOTH); + viewer.getControl().setLayoutData(viewerData); + viewer.setEditable(false); + + StyledText widget = viewer.getTextWidget(); + widget.setFont( + JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT)); + Action cutAction = new Action() { + public void run() { + viewer.getTextWidget().cut(); + } + }; + Action copyAction = new Action() { + public void run() { + viewer.getTextWidget().copy(); + } + }; + Action pasteAction = new Action() { + public void run() { + viewer.getTextWidget().paste(); + } + }; + + IActionBars bars = this.getViewSite().getActionBars(); + bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction); + bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction); + bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction); + } + + /** + * Insert the method's description here. + * @see ViewPart#setFocus + */ + public void setFocus() { + } + + /** + * Set the text for the viewer + */ + private void setOutputText(String text) { + document = new Document(text); + viewer.setDocument(document); + } + + private void appendOutputText(String text) { + try { + if (document == null) { + document = new Document(text); + viewer.setDocument(document); + } + document.replace(document.getLength(), 0, text); + } catch (BadLocationException e) { + } + // viewer.setDocument(document); + } + + public static PHPSourceConsole getInstance() { + IWorkbenchPage page = + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + PHPSourceConsole console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID); + // if (PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) { + + try { + page.showView(PHPSourceConsole.CONSOLE_ID); + if (console == null) { + console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID); + } + } catch (PartInitException e) { + QuantumPlugin.getDefault().getLog().log( + new Status( + IStatus.ERROR, + QuantumPlugin.PLUGIN_ID, + 0, + Messages.getString("sqlconsole.viewopeningproblem"), + e)); + } + + // } + return console; + } + + /** + * Prints out the string represented by the string buffer + */ + public synchronized void print(String output) { + appendOutputText(output); + } + + /** + * Prints out the string represented by the string buffer + */ + public synchronized void println(String output) { + appendOutputText(output+'\n'); + } + + public synchronized void clear() { + setOutputText(""); + } +} diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableViewMenuListener.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableViewMenuListener.java index 09da28f..319001a 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableViewMenuListener.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/tableview/TableViewMenuListener.java @@ -3,18 +3,7 @@ * */ package com.quantum.view.tableview; - import java.util.Vector; - -import com.quantum.Messages; -import com.quantum.extensions.ExtensionAction; -import com.quantum.sql.TableRow; -import com.quantum.util.StringMatrix; -import com.quantum.wizards.DeleteRowPage; -import com.quantum.wizards.InsertRowPage; -import com.quantum.wizards.SQLRowWizard; -import com.quantum.wizards.UpdateRowPage; - import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; @@ -23,116 +12,162 @@ import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; - - +import com.quantum.Messages; +import com.quantum.extensions.ExtensionAction; +import com.quantum.sql.TableRow; +import com.quantum.util.StringMatrix; +import com.quantum.wizards.DeleteRowPage; +import com.quantum.wizards.InsertRowPage; +import com.quantum.wizards.PHPDeleteRowPage; +import com.quantum.wizards.PHPInsertRowPage; +import com.quantum.wizards.PHPSelectRowPage; +import com.quantum.wizards.PHPUpdateRowPage; +import com.quantum.wizards.SQLRowWizard; +import com.quantum.wizards.UpdateRowPage; public final class TableViewMenuListener implements IMenuListener { - private final TableView tableView; - private final Table table; - private final Action UTF16EncodingAction; - private final TableAdapter ta; - private final Action defaultEncodingAction; - private final Action UTF8EncodingAction; - private final Vector extensionVector; - - public TableViewMenuListener( - TableView view, - Table table, - Action UTF16EncodingAction, - TableAdapter ta, - Action defaultEncodingAction, - Action UTF8EncodingAction, - Vector extensionVector ) { - - super(); - this.tableView = view; - this.table = table; - this.UTF16EncodingAction = UTF16EncodingAction; - this.ta = ta; - this.defaultEncodingAction = defaultEncodingAction; - this.UTF8EncodingAction = UTF8EncodingAction; - this.extensionVector = extensionVector; - } - public void menuAboutToShow(IMenuManager mgr) { - if (ta.getTable() != null) { - TableItem[] selection = table.getSelection(); - TableColumn[] columns = table.getColumns(); - // Copy in columnNames the names of the columns of the selected rows - String columnNames[] = new String[columns.length]; - for (int i = 0; i < columns.length; i++) { - columnNames[i] = columns[i].getText(); - } - // Copy in data the values of the data columns of the selected rows - StringMatrix data = new StringMatrix(); - data.addMatrixHeader(columnNames); - if (selection != null && selection.length > 0) { - for (int iRow = 0; iRow < selection.length; iRow++) { - TableItem sel = selection[iRow]; - for (int i = 0; i < columns.length; i++) { - data.addAt(columnNames[i], sel.getText(i), iRow ); - } - } - } else { - // Create dummy values in case nothing selected - for (int i = 0; i < columns.length; i++) { - data.addAt(columnNames[i], "", 0); //$NON-NLS-1$ - } - } - final TableRow row = - new TableRow(ta.getEntity(), ta.getBookmark(), ta.getTable(), data); - Action updateAction = new Action() { - public void run() { - UpdateRowPage page = new UpdateRowPage(""); //$NON-NLS-1$ - SQLRowWizard wizard = new SQLRowWizard(); - wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$ - WizardDialog dialog = - new WizardDialog( - tableView.getSite().getShell(), - wizard); - dialog.open(); - } - }; - updateAction.setText(Messages.getString("tableview.update")); //$NON-NLS-1$ - Action insertAction = new Action() { - public void run() { - InsertRowPage page = new InsertRowPage(""); //$NON-NLS-1$ - SQLRowWizard wizard = new SQLRowWizard(); - wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$ - WizardDialog dialog = - new WizardDialog( - tableView.getSite().getShell(), - wizard); - dialog.open(); - } - }; - insertAction.setText(Messages.getString("tableview.insert")); //$NON-NLS-1$ - Action deleteAction = new Action() { - public void run() { - DeleteRowPage page = new DeleteRowPage(""); //$NON-NLS-1$ - SQLRowWizard wizard = new SQLRowWizard(); - wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$ - WizardDialog dialog = - new WizardDialog( - tableView.getSite().getShell(), - wizard); - dialog.open(); - } - }; - deleteAction.setText(Messages.getString("tableview.delete")); //$NON-NLS-1$ - mgr.add(insertAction); - mgr.add(updateAction); - mgr.add(deleteAction); - - MenuManager subMenuExtension = new MenuManager("Extensions"); - for (int i = 0; i < extensionVector.size(); i++) { - ExtensionAction extensionAction = (ExtensionAction) extensionVector.get(i); - extensionAction.addRowData(row); - subMenuExtension.add(extensionAction); - } - if (extensionVector.size() > 0) mgr.add(subMenuExtension); - - } - mgr.add(defaultEncodingAction); - mgr.add(UTF8EncodingAction); - mgr.add(UTF16EncodingAction); - } + private final TableView tableView; + private final Table table; + private final Action UTF16EncodingAction; + private final TableAdapter ta; + private final Action defaultEncodingAction; + private final Action UTF8EncodingAction; + private final Vector extensionVector; + public TableViewMenuListener(TableView view, Table table, + Action UTF16EncodingAction, TableAdapter ta, + Action defaultEncodingAction, Action UTF8EncodingAction, + Vector extensionVector) { + super(); + this.tableView = view; + this.table = table; + this.UTF16EncodingAction = UTF16EncodingAction; + this.ta = ta; + this.defaultEncodingAction = defaultEncodingAction; + this.UTF8EncodingAction = UTF8EncodingAction; + this.extensionVector = extensionVector; + } + public void menuAboutToShow(IMenuManager mgr) { + if (ta.getTable() != null) { + TableItem[] selection = table.getSelection(); + TableColumn[] columns = table.getColumns(); + // Copy in columnNames the names of the columns of the selected rows + String columnNames[] = new String[columns.length]; + for (int i = 0; i < columns.length; i++) { + columnNames[i] = columns[i].getText(); + } + // Copy in data the values of the data columns of the selected rows + StringMatrix data = new StringMatrix(); + data.addMatrixHeader(columnNames); + if (selection != null && selection.length > 0) { + for (int iRow = 0; iRow < selection.length; iRow++) { + TableItem sel = selection[iRow]; + for (int i = 0; i < columns.length; i++) { + data.addAt(columnNames[i], sel.getText(i), iRow); + } + } + } else { + // Create dummy values in case nothing selected + for (int i = 0; i < columns.length; i++) { + data.addAt(columnNames[i], "", 0); //$NON-NLS-1$ + } + } + final TableRow row = new TableRow(ta.getEntity(), ta.getBookmark(), ta + .getTable(), data); + Action phpSelectAction = new Action() { + public void run() { + PHPSelectRowPage page = new PHPSelectRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$ + WizardDialog dialog = new WizardDialog(tableView.getSite().getShell() + .getShell(), wizard); + dialog.open(); + } + }; + phpSelectAction.setText(Messages.getString("tableview.phpselect")); //$NON-NLS-1$ + Action phpUpdateAction = new Action() { + public void run() { + PHPUpdateRowPage page = new PHPUpdateRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$ + WizardDialog dialog = new WizardDialog( + tableView.getSite().getShell(), wizard); + dialog.open(); + } + }; + phpUpdateAction.setText(Messages.getString("tableview.phpupdate")); //$NON-NLS-1$ + Action phpInsertAction = new Action() { + public void run() { + PHPInsertRowPage page = new PHPInsertRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$ + WizardDialog dialog = new WizardDialog( + tableView.getSite().getShell(), wizard); + dialog.open(); + } + }; + phpInsertAction.setText(Messages.getString("tableview.phpinsert")); //$NON-NLS-1$ + Action phpDeleteAction = new Action() { + public void run() { + PHPDeleteRowPage page = new PHPDeleteRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$ + WizardDialog dialog = new WizardDialog( + tableView.getSite().getShell(), wizard); + dialog.open(); + } + }; + phpDeleteAction.setText(Messages.getString("tableview.phpdelete")); //$NON-NLS-1$ + Action updateAction = new Action() { + public void run() { + UpdateRowPage page = new UpdateRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$ + WizardDialog dialog = new WizardDialog( + tableView.getSite().getShell(), wizard); + dialog.open(); + } + }; + updateAction.setText(Messages.getString("tableview.update")); //$NON-NLS-1$ + Action insertAction = new Action() { + public void run() { + InsertRowPage page = new InsertRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$ + WizardDialog dialog = new WizardDialog( + tableView.getSite().getShell(), wizard); + dialog.open(); + } + }; + insertAction.setText(Messages.getString("tableview.insert")); //$NON-NLS-1$ + Action deleteAction = new Action() { + public void run() { + DeleteRowPage page = new DeleteRowPage(""); //$NON-NLS-1$ + SQLRowWizard wizard = new SQLRowWizard(); + wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$ + WizardDialog dialog = new WizardDialog( + tableView.getSite().getShell(), wizard); + dialog.open(); + } + }; + deleteAction.setText(Messages.getString("tableview.delete")); //$NON-NLS-1$ + mgr.add(phpSelectAction); + mgr.add(phpInsertAction); + mgr.add(phpUpdateAction); + mgr.add(phpDeleteAction); + mgr.add(insertAction); + mgr.add(updateAction); + mgr.add(deleteAction); + MenuManager subMenuExtension = new MenuManager("Extensions"); + for (int i = 0; i < extensionVector.size(); i++) { + ExtensionAction extensionAction = (ExtensionAction) extensionVector + .get(i); + extensionAction.addRowData(row); + subMenuExtension.add(extensionAction); + } + if (extensionVector.size() > 0) + mgr.add(subMenuExtension); + } + mgr.add(defaultEncodingAction); + mgr.add(UTF8EncodingAction); + mgr.add(UTF16EncodingAction); + } } \ No newline at end of file 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 new file mode 100644 index 0000000..8b48541 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPDeleteRowPage.java @@ -0,0 +1,174 @@ +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.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()); + 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 new file mode 100644 index 0000000..4e850b7 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPInsertRowPage.java @@ -0,0 +1,144 @@ +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.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()); + 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 new file mode 100644 index 0000000..05cb2d4 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPSelectRowPage.java @@ -0,0 +1,202 @@ +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.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()); + 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 new file mode 100644 index 0000000..26b2ea9 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/PHPUpdateRowPage.java @@ -0,0 +1,195 @@ +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.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()); + return true; + } +} \ No newline at end of file -- 1.7.1