Added the PHP wizards again
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / wizards / InsertRowPage.java
index fde6b50..5f8f6c2 100644 (file)
@@ -22,101 +22,116 @@ import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
 
 public class InsertRowPage extends WizardPage implements SQLPage {
-       TableRow row;
-       String[] columnNames;
-       Text[] values;
-       Label query;
-       public InsertRowPage(String pageName) {
-               super(pageName);
-       }
+  TableRow row;
+  String[] columnNames;
+  Text[] values;
+  Label query;
+  public InsertRowPage(String pageName) {
+    super(pageName);
+  }
 
-       public void init(TableRow row, TableAdapter adapter) {
-               this.row = row;
-       }
+  public void init(TableRow row, TableAdapter adapter) {
+    this.row = row;
+  }
 
-       public void createControl(Composite parent) {
-               System.out.println("page create control"); //$NON-NLS-1$
-               Composite container = new Composite(parent, SWT.NULL);
-               GridLayout layout = new GridLayout();
-               container.setLayout(layout);
-               layout.numColumns = 2;
+  public void createControl(Composite parent) {
+    if (DEBUG) {
+      System.out.println("page create control"); //$NON-NLS-1$
+    }
 
-               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$
-               }
-               values = new Text[row.getColumnCount()];
-               new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.ColumnName")); //$NON-NLS-1$
-               new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.Value")); //$NON-NLS-1$
-               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);
+    Composite container = new Composite(parent, SWT.NULL);
+    GridLayout layout = new GridLayout();
+    container.setLayout(layout);
+    layout.numColumns = 2;
 
-                       //values[i].setText(data[i]);
-                       values[i].addModifyListener(new ModifyListener() {
-                               public void modifyText(ModifyEvent e) {
-                                       updateQuery();
-                               }                               
-                       });
-               }
-               query = new Label(container, SWT.WRAP);
-               GridData gridData = new GridData();
-               gridData.horizontalSpan = layout.numColumns;
-               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"); //$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$
+      }
+    }
 
-               setControl(container);
-        updateQuery();
-       
-               setPageComplete(true);
-       }
-       public void updateQuery() {
-               System.out.println("Updating query"); //$NON-NLS-1$
-               StringBuffer valuesClause = new StringBuffer();
-               BookmarkNode bookmark = row.getBookmarkNode();
-               TreeNode node = bookmark.find(row.getTable());
-               ObjectMetaData metadata = null;
-               if (node != null) metadata = node.getMetaData(); 
-               DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
-               
-               int numValues = 0;
-               for (int i = 0; i < columnNames.length; i++) {
-                       String value = values[i].getText();
-                       if (numValues > 0) valuesClause.append(", "); //$NON-NLS-1$
-                       if (adapter != null && metadata != null && value != "") //$NON-NLS-1$
-                               valuesClause.append(adapter.quote(value, metadata.getColumnType(columnNames[i])));
-                       else
-                               valuesClause.append(value);     
-                       numValues++;
-               }
-               String query = "INSERT INTO " + row.getTable(); //$NON-NLS-1$
-               query += " VALUES (" + valuesClause; //$NON-NLS-1$
-               query += " )"; //$NON-NLS-1$
-               this.query.setText(query);
-       }
-       public boolean performFinish() {
-          MultiSQLServer server = MultiSQLServer.getInstance();
-          BookmarkView bookmarkView = BookmarkView.getInstance(); 
-          BookmarkNode bookmark = bookmarkView.getCurrentBookmark();
-          server.execute(bookmark.getConnection(), query.getText());
-          return true;
-       }
+    columnNames = row.getColumnNames();
+    String[] data = row.getTableData();
+
+    if (DEBUG) {
+      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$
+      }
+    }
+
+    values = new Text[row.getColumnCount()];
+    new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.ColumnName")); //$NON-NLS-1$
+    new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.Value")); //$NON-NLS-1$
+    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();
+        }
+      });
+    }
+    query = new Label(container, SWT.WRAP);
+    GridData gridData = new GridData();
+    gridData.horizontalSpan = layout.numColumns;
+    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"); //$NON-NLS-1$
+    }
+
+    StringBuffer valuesClause = new StringBuffer();
+    BookmarkNode bookmark = row.getBookmarkNode();
+    TreeNode node = bookmark.find(row.getTable());
+    ObjectMetaData metadata = null;
+    if (node != null)
+      metadata = node.getMetaData();
+    DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+
+    int numValues = 0;
+    for (int i = 0; i < columnNames.length; i++) {
+      String value = values[i].getText();
+      if (numValues > 0)
+        valuesClause.append(", "); //$NON-NLS-1$
+      if (adapter != null && metadata != null && value != "") //$NON-NLS-1$
+        valuesClause.append(adapter.quote(value, metadata.getColumnType(columnNames[i])));
+      else
+        valuesClause.append(value);
+      numValues++;
+    }
+    String query = "INSERT INTO " + row.getTable(); //$NON-NLS-1$
+    query += " VALUES (" + valuesClause; //$NON-NLS-1$
+    query += " )"; //$NON-NLS-1$
+    this.query.setText(query);
+  }
+  public boolean performFinish() {
+    MultiSQLServer server = MultiSQLServer.getInstance();
+    BookmarkView bookmarkView = BookmarkView.getInstance();
+    BookmarkNode bookmark = bookmarkView.getCurrentBookmark();
+    server.execute(bookmark.getConnection(), query.getText());
+    return true;
+  }
 }
\ No newline at end of file