Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGP...
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / wizards / PHPUpdateRowPage.java
index 9ebab2b..951d4f6 100644 (file)
@@ -22,164 +22,173 @@ import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
 import net.sourceforge.phpdt.sql.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;
-
-       public PHPUpdateRowPage(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 = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
-               Composite container = new Composite(parent, SWT.NULL);
-               GridLayout layout = new GridLayout();
-               container.setLayout(layout);
-               int layoutColumns = 5;
-               layout.numColumns = layoutColumns;
-
-               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]);
-               }
-               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() {
-               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 =
-                       { setClause.toString(), row.getTable(), 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;
-       }
+  TableRow row;
+  String[] columnNames;
+  Text[] oldValues;
+  Text[] newValues;
+  Button[] primaryKeys;
+  Button[] setValues;
+  Label query;
+  IPreferenceStore fStore;
+
+  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 = PHPEclipseSQLPlugin.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