Simplified parsing for double quoted strings
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / InsertRowPage.java
index f25054d..7cb600d 100644 (file)
@@ -1,7 +1,5 @@
 package com.quantum.wizards;
 
-import java.util.Arrays;
-
 import org.eclipse.jface.viewers.CellEditor;
 import org.eclipse.jface.viewers.ICellModifier;
 import org.eclipse.jface.viewers.ILabelProviderListener;
@@ -11,24 +9,22 @@ import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TextCellEditor;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
 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.Label;
 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.sql.SQLResultSetResults;
+import com.quantum.util.StringMatrix;
+import com.quantum.util.sql.SQLInstructionBuilder;
 
+/**
+ * @author BC Holmes
+ * @author Elvin E. Ebora
+ */
 public class InsertRowPage extends BaseSQLPage implements SQLPage {
     
     class InsertRowTableValues {
@@ -109,7 +105,7 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage {
                System.out.println("getValue called");
        
                // Find the index of the column
-               int colIndx = getColumnNamesAsList(colNames).indexOf(property);
+               int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property);
                System.out.println("colIndx : " + colIndx);             
                 
                Object rResult = null;
@@ -131,7 +127,7 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage {
        }
        
        public void modify(Object element, String property, Object value) {
-               int colIndx = getColumnNamesAsList(colNames).indexOf(property);
+               int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property);
                
                TableItem item = (TableItem) element;
                InsertRowTableValues insertVal = (InsertRowTableValues)item.getData();
@@ -152,9 +148,9 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage {
     
        String[] columnNames;
        String[] colNames;
-       Text[] values;
        Label query;
        InsertRowTableValues[] insertTable = null;
+       CommonWizardUI comUI;
        TableViewer tableViewer = null; 
        int numColumns = 0;
        
@@ -167,6 +163,8 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage {
                Composite container = new Composite(parent, SWT.NULL);
                container.setLayout(new GridLayout());
                container.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING));
+               
+               comUI = new CommonWizardUI();
 
                // init values to be displayed on the table
                columnNames = this.results.getColumnNames();
@@ -182,11 +180,7 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage {
                createTable(container);                         
                
                query = new Label(container, SWT.WRAP);
-               GridData gridData = new GridData();
-               gridData.horizontalSpan = 1;            
-               gridData.horizontalAlignment = GridData.FILL;
-               gridData.verticalAlignment = GridData.FILL;             
-               query.setLayoutData(gridData);
+               query.setLayoutData(comUI.createGridData(1, GridData.FILL));
 
                setControl(container);
         updateQuery();
@@ -195,34 +189,13 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage {
        }
        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;
+               StringMatrix columns = new StringMatrix();
                for (int i = 0; i < columnNames.length; i++) {
-                   String name = insertTable[i].getColNames();
-                   String value = insertTable[i].getValues();
-                       if (value != null && value.length() > 0) {
-                               if (numColumns > 0) {
-                                       valuesClause.append(", "); //$NON-NLS-1$
-                                       namesClause.append(", ");
-                               }
-                appendColumn(valuesClause, entity, name, adapter, value);
-                               namesClause.append(name);       
-                               numColumns++;
-                       }
+                   columns.addHeader( insertTable[i].getColNames() );
+                   columns.add( insertTable[i].getValues() , 0 );
                }
-               
-               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$
-               }
-               this.query.setText(query);
+               this.query.setText(SQLInstructionBuilder.buildInsert(this.results.getEntity(), columns));
        }
     /* (non-Javadoc)
      * @see com.quantum.wizards.BaseSQLPage#getQueryText()
@@ -233,16 +206,11 @@ public class InsertRowPage extends BaseSQLPage implements SQLPage {
     
     private void createTable(Composite composite) {
         System.out.println("Creating table...");
-        int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
-               Table table = new Table(composite, style);
-       table.setHeaderVisible(true);
-       table.setLinesVisible(true);
-       table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING));
-       
+        Table table = comUI.createTablePage(composite);
        colNames = new String[] { Messages.getString("InsertRowPage.ColumnName"), Messages.getString("InsertRowPage.Value") };
 
-               createTableColumn(table, colNames[0], SWT.LEFT, 0, 200);
-               createTableColumn(table, colNames[1], SWT.LEFT, 1, 500);
+       comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 200);
+       comUI.createTableColumn(table, colNames[1], SWT.LEFT, 1, 500);
                this.tableViewer = new TableViewer(table);
                this.tableViewer.setColumnProperties(colNames);