introduced IConstant.DEBUG flag
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / wizards / DeleteRowPage.java
index 2f8e6e6..c16e981 100644 (file)
@@ -18,122 +18,131 @@ import net.sourceforge.phpdt.sql.sql.TableRow;
 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
 
 public class DeleteRowPage extends WizardPage implements SQLPage {
-       TableRow row;
-       String[] columnNames;
-       Text[] values;
-       Button[] whereValues;
-       Label query;
+  TableRow row;
+  String[] columnNames;
+  Text[] values;
+  Button[] whereValues;
+  Label query;
 
-       public DeleteRowPage(String pageName) {
-               super(pageName);
-       }
-       
-       public void init(TableRow row, TableAdapter adapter) {
-               this.row = row;
-       }
+  public DeleteRowPage(String pageName) {
+    super(pageName);
+  }
 
-       public void createControl(Composite parent) {
-               System.out.println("page create control");
-               Composite container = new Composite(parent, SWT.NULL);
-               GridLayout layout = new GridLayout();
-               container.setLayout(layout);
-               int layoutColumns = 3;
-               layout.numColumns = layoutColumns;
+  public void init(TableRow row, TableAdapter adapter) {
+    this.row = row;
+  }
 
-               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]);
-               }
-               values = new Text[row.getColumnCount()];
-               whereValues = new Button[row.getColumnCount()];
-               Label temp = new Label(container, SWT.NULL);
-               temp.setText("Column Name");
-               temp = new Label(container, SWT.NULL);
-               temp.setText("Value");
-               temp = new Label(container, SWT.NULL);
-               temp.setText("Include in?");
-               for (int i = 0; i < row.getColumnCount(); i++) {
-                       Label label = new Label(container, SWT.NULL);
-                       label.setText(columnNames[i]);
-                       values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
-                       GridData fullHorizontal = new GridData();
-                       fullHorizontal.horizontalAlignment = GridData.FILL;
-                       values[i].setLayoutData(fullHorizontal);
-                       values[i].setText(data[i]);
+  public void createControl(Composite parent) {
+    if (DEBUG) {
+      System.out.println("page create control");
+    }
+    Composite container = new Composite(parent, SWT.NULL);
+    GridLayout layout = new GridLayout();
+    container.setLayout(layout);
+    int layoutColumns = 3;
+    layout.numColumns = layoutColumns;
 
-                       values[i].addModifyListener(new ModifyListener() {
-                               public void modifyText(ModifyEvent e) {
-                                       updateQuery();
-                               }                               
-                       });
-                       
-                       whereValues[i] = new Button(container, SWT.CHECK);
-                       whereValues[i].setText("Where clause");
-                       whereValues[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);
+    if (DEBUG) {
+      if (row == null) {
+        System.out.println("Row is null");
+      }
 
-               setControl(container);
-        updateQuery();
-       
-               setPageComplete(true);
-       }
-       public void updateQuery() {
-               System.out.println("Updating query");
-               StringBuffer whereClause = new StringBuffer();
-               int numSelected = 0;
-               for (int i = 0; i < columnNames.length; i++) {
-                       if (whereValues[i].getSelection()) {
-                               numSelected++;
-                               whereClause.append(columnNames[i]);
-                               whereClause.append(" = ");
-                               whereClause.append(values[i].getText());
-                               whereClause.append(", ");
-                       }
-               }
-               if (whereClause.length() > 1) {
-                       whereClause.deleteCharAt(whereClause.length() - 1);
-                       whereClause.deleteCharAt(whereClause.length() - 1);
-               }
-               String query = "DELETE FROM " + row.getTable();
-               if (numSelected > 0) {
-                       query += " WHERE " + whereClause.toString();
-               }
-               if (numSelected > 0) {
-                       setMessage("");
-               } else {
-                       setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
-               }
-               this.getControl().pack();
-               this.query.setText(query);
-       }
-       public boolean performFinish() {
-          MultiSQLServer server = MultiSQLServer.getInstance();
-          server.execute(query.getText());
-          return true;
-       }
+      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]);
+      }
+    }
+    values = new Text[row.getColumnCount()];
+    whereValues = new Button[row.getColumnCount()];
+    Label temp = new Label(container, SWT.NULL);
+    temp.setText("Column Name");
+    temp = new Label(container, SWT.NULL);
+    temp.setText("Value");
+    temp = new Label(container, SWT.NULL);
+    temp.setText("Include in?");
+    for (int i = 0; i < row.getColumnCount(); i++) {
+      Label label = new Label(container, SWT.NULL);
+      label.setText(columnNames[i]);
+      values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+      GridData fullHorizontal = new GridData();
+      fullHorizontal.horizontalAlignment = GridData.FILL;
+      values[i].setLayoutData(fullHorizontal);
+      values[i].setText(data[i]);
+
+      values[i].addModifyListener(new ModifyListener() {
+        public void modifyText(ModifyEvent e) {
+          updateQuery();
+        }
+      });
+
+      whereValues[i] = new Button(container, SWT.CHECK);
+      whereValues[i].setText("Where clause");
+      whereValues[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 query");
+    }
+    StringBuffer whereClause = new StringBuffer();
+    int numSelected = 0;
+    for (int i = 0; i < columnNames.length; i++) {
+      if (whereValues[i].getSelection()) {
+        numSelected++;
+        whereClause.append(columnNames[i]);
+        whereClause.append(" = ");
+        whereClause.append(values[i].getText());
+        whereClause.append(", ");
+      }
+    }
+    if (whereClause.length() > 1) {
+      whereClause.deleteCharAt(whereClause.length() - 1);
+      whereClause.deleteCharAt(whereClause.length() - 1);
+    }
+    String query = "DELETE FROM " + row.getTable();
+    if (numSelected > 0) {
+      query += " WHERE " + whereClause.toString();
+    }
+    if (numSelected > 0) {
+      setMessage("");
+    } else {
+      setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
+    }
+    this.getControl().pack();
+    this.query.setText(query);
+  }
+  public boolean performFinish() {
+    MultiSQLServer server = MultiSQLServer.getInstance();
+    server.execute(query.getText());
+    return true;
+  }
 }
\ No newline at end of file