Quantum version 2.4.1
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / UpdateRowPage.java
index e1dd3c5..3753b7c 100644 (file)
@@ -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);