*** empty log message ***
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / UpdateRowPage.java
index b057d59..3753b7c 100644 (file)
@@ -1,11 +1,5 @@
 package com.quantum.wizards;
 
-import com.quantum.Messages;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DatabaseAdapter;
-import com.quantum.model.Bookmark;
-import com.quantum.model.Entity;
-
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
@@ -18,6 +12,12 @@ 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.adapters.DatabaseAdapter;
+import com.quantum.model.Bookmark;
+import com.quantum.model.Column;
+import com.quantum.model.Entity;
+
 public class UpdateRowPage extends BaseSQLPage implements SQLPage {
        String[] columnNames;
        Text[] oldValues;
@@ -34,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);
@@ -68,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();
@@ -80,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 && entity.getColumn(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) {
@@ -90,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();
@@ -124,9 +118,9 @@ 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();
-               DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+               Bookmark bookmark = this.results.getBookmark();
+               Entity entity = this.results.getEntity();
+               DatabaseAdapter adapter = bookmark.getAdapter();
                
                int numValuesSet = 0;
                int numValuesWhere = 0;
@@ -150,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);