1 package net.sourceforge.phpdt.sql.wizards;
3 import net.sourceforge.phpdt.sql.sql.TableRow;
4 import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
5 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
7 import org.eclipse.jface.wizard.WizardPage;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.ModifyEvent;
10 import org.eclipse.swt.events.ModifyListener;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.swt.widgets.Text;
17 public class PHPInsertRowPage extends WizardPage implements SQLPage {
22 public PHPInsertRowPage(String pageName) {
26 public void init(TableRow row, TableAdapter adapter) {
30 public void createControl(Composite parent) {
32 System.out.println("page create control");
34 Composite container = new Composite(parent, SWT.NULL);
35 GridLayout layout = new GridLayout();
36 container.setLayout(layout);
37 int layoutColumns = 2;
38 layout.numColumns = layoutColumns;
42 System.out.println("Row is null");
44 if (row.getColumnNames() == null) {
45 System.out.println("Columns are null");
47 if (row.getTableData() == null) {
48 System.out.println("Data is null");
51 columnNames = row.getColumnNames();
52 String[] data = row.getTableData();
54 for (int i = 0; i < row.getColumnCount(); i++) {
55 System.out.println("data = " + i + "=" + data[i]);
56 System.out.println("column = " + i + "=" + columnNames[i]);
59 values = new Text[row.getColumnCount()];
60 Label temp = new Label(container, SWT.NULL);
61 temp.setText("Column Name");
62 temp = new Label(container, SWT.NULL);
63 temp.setText("Value");
64 for (int i = 0; i < row.getColumnCount(); i++) {
65 Label label = new Label(container, SWT.NULL);
66 label.setText(columnNames[i]);
67 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
68 GridData fullHorizontal = new GridData();
69 fullHorizontal.horizontalAlignment = GridData.FILL;
70 values[i].setLayoutData(fullHorizontal);
72 //values[i].setText(data[i]);
73 values[i].addModifyListener(new ModifyListener() {
74 public void modifyText(ModifyEvent e) {
79 query = new Label(container, SWT.WRAP);
80 GridData gridData = new GridData();
81 gridData.horizontalSpan = layoutColumns;
82 gridData.horizontalAlignment = GridData.FILL;
83 gridData.verticalAlignment = GridData.FILL;
84 gridData.grabExcessHorizontalSpace = true;
85 gridData.grabExcessVerticalSpace = true;
86 query.setLayoutData(gridData);
88 setControl(container);
91 setPageComplete(true);
93 public void updateQuery() {
95 System.out.println("Updating insert query");
97 StringBuffer fieldClause = new StringBuffer();
99 StringBuffer valuesClause = new StringBuffer();
101 boolean first = false;
102 for (int i = 0; i < columnNames.length; i++) {
103 text = values[i].getText();
104 if (! text.equals("")) {
106 valuesClause.append(", ");
107 fieldClause.append(", ");
109 valuesClause.append("'"+values[i].getText()+"'");
110 fieldClause.append(columnNames[i]);
114 // if (valuesClause.length() > 1) {
115 // valuesClause.deleteCharAt(valuesClause.length() - 1);
116 // valuesClause.deleteCharAt(valuesClause.length() - 1);
118 String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
119 query += fieldClause.toString() + ") ";
120 query += " VALUES (" + valuesClause.toString();
122 this.query.setText(query);
124 public boolean performFinish() {
125 PHPSourceConsole console = PHPSourceConsole.getInstance();
127 console.print(query.getText());