suppress "variable not initialized" error for break statements. In switch-case statem...
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / UpdateRowPage.java
index 031ed9f..c1afd51 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.CheckboxCellEditor;
 import org.eclipse.jface.viewers.ICellModifier;
@@ -12,32 +10,25 @@ 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.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Image;
 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.Table;
-import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.swt.widgets.Text;
 
 import com.quantum.ImageStore;
 import com.quantum.Messages;
-import com.quantum.adapters.DatabaseAdapter;
-import com.quantum.model.Bookmark;
 import com.quantum.model.Column;
 import com.quantum.model.Entity;
-import com.quantum.wizards.InsertRowPage.CellModifierImpl;
-import com.quantum.wizards.InsertRowPage.ContentProviderImpl;
-import com.quantum.wizards.InsertRowPage.InsertRowTableValues;
-import com.quantum.wizards.InsertRowPage.LabelProviderImpl;
+import com.quantum.util.StringMatrix;
+import com.quantum.util.sql.SQLInstructionBuilder;
 
+/**
+ * @author BC Holmes
+ * @author Elvin E. Ebora
+ */
 public class UpdateRowPage extends BaseSQLPage implements SQLPage {
     
     class UpdateRowTableValues {
@@ -170,7 +161,7 @@ public class UpdateRowPage 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;
@@ -200,7 +191,7 @@ public class UpdateRowPage 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;
                UpdateRowTableValues updateVal = (UpdateRowTableValues)item.getData();
@@ -230,12 +221,9 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage {
     
        String[] columnNames;
        String[] colNames;
-       Text[] oldValues;
-       Text[] newValues;
-       Button[] primaryKeys;
-       Button[] setValues;
        Label query;
        UpdateRowTableValues[] updateTable = null;
+       CommonWizardUI comUI;
        TableViewer tableViewer = null;
        static Image imgCheck = null;
        static Image imgUncheck = null;
@@ -257,6 +245,8 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage {
                
                Entity entity = this.results.getEntity();
                
+               comUI = new CommonWizardUI();
+               
                // init values to be displayed on the table
                columnNames = this.results.getColumnNames();
                int nLen = columnNames.length;
@@ -276,12 +266,8 @@ public class UpdateRowPage 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 = new Label(container, SWT.WRAP);                                         
+               query.setLayoutData(comUI.createGridData(1, GridData.FILL));
 
                setControl(container);
         updateQuery();
@@ -290,39 +276,23 @@ public class UpdateRowPage extends BaseSQLPage implements SQLPage {
        }
        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 nCtr = 0; nCtr < columnNames.length; nCtr++) {
-                       if (updateTable[nCtr].isBPrimary()) {
-                               String value = updateTable[nCtr].getSOldValue();
-                               if (numValuesWhere > 0) whereClause.append(" AND "); //$NON-NLS-1$
-                               whereClause.append("("); //$NON-NLS-1$
-                               whereClause.append(updateTable[nCtr].getSColNames());
-                               whereClause.append(" = "); //$NON-NLS-1$
-                appendColumn(whereClause, entity, updateTable[nCtr].getSColNames(), adapter, value);
-                               whereClause.append(")"); //$NON-NLS-1$
-                               numValuesWhere++;
-                       } 
-                       if (updateTable[nCtr].isBSetValue()) {
-                               String value = updateTable[nCtr].getSNewValue();
-                               if (numValuesSet > 0) setClause.append(", "); //$NON-NLS-1$
-                               setClause.append(updateTable[nCtr].getSColNames());
-                               setClause.append(" = "); //$NON-NLS-1$
-                appendColumn(setClause, entity, updateTable[nCtr].getSColNames(), adapter, value);
-                               numValuesSet++;
+               StringMatrix columns = new StringMatrix();
+               for (int i = 0; i < columnNames.length; i++) {
+                       if (updateTable[i].isBSetValue()) {
+                               columns.addHeader( updateTable[i].getSColNames() );
+                               columns.add( updateTable[i].getSNewValue(), 0 );
                        }
                }
-               
-               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);
+               StringMatrix key = new StringMatrix();
+               for (int i = 0; i < columnNames.length; i++) {
+                       if (updateTable[i].isBPrimary()) {
+                           key.addHeader( updateTable[i].getSColNames() );
+                           // It's an old value because it't the key.
+                           key.add( updateTable[i].getSOldValue() , 0 );
+                       }
+               }
+               this.query.setText(SQLInstructionBuilder.buildUpdate(this.results.getEntity(), columns, key));
        }
 
     /* (non-Javadoc)
@@ -337,21 +307,16 @@ public class UpdateRowPage 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));
-       
+        System.out.println("Creating table...");        
+        Table table = comUI.createTablePage(composite);
        colNames = new String[] { Messages.getString("UpdateRowPage.ColumnName"), Messages.getString("UpdateRowPage.OldValue"),
                        "Where", Messages.getString("UpdateRowPage.NewValue"), Messages.getString("UpdateRowPage.SetValue")     };
 
-               createTableColumn(table, colNames[0], SWT.LEFT, 0, 150);
-               createTableColumn(table, colNames[1], SWT.LEFT, 1, 300);
-               createTableColumn(table, colNames[2], SWT.CENTER, 2, 60);
-               createTableColumn(table, colNames[3], SWT.LEFT, 3, 300);
-               createTableColumn(table, colNames[4], SWT.CENTER, 4, 70);
+       comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 150);
+       comUI.createTableColumn(table, colNames[1], SWT.LEFT, 1, 300);
+       comUI.createTableColumn(table, colNames[2], SWT.CENTER, 2, 60);
+       comUI.createTableColumn(table, colNames[3], SWT.LEFT, 3, 300);
+       comUI.createTableColumn(table, colNames[4], SWT.CENTER, 4, 70);
                this.tableViewer = new TableViewer(table);
                this.tableViewer.setColumnProperties(colNames);