1 package net.sourceforge.phpdt.sql.wizards;
3 import java.text.MessageFormat;
5 import org.eclipse.jface.preference.IPreferenceStore;
6 import org.eclipse.jface.wizard.WizardPage;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.events.ModifyEvent;
9 import org.eclipse.swt.events.ModifyListener;
10 import org.eclipse.swt.layout.GridData;
11 import org.eclipse.swt.layout.GridLayout;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.Text;
16 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
17 import net.sourceforge.phpdt.sql.sql.TableRow;
18 import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
19 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
21 public class PHPInsertRowPage extends WizardPage implements SQLPage {
26 private IPreferenceStore fStore;
28 public PHPInsertRowPage(String pageName) {
32 public void init(TableRow row, TableAdapter adapter) {
36 public void createControl(Composite parent) {
37 System.out.println("page create control");
38 fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
39 Composite container = new Composite(parent, SWT.NULL);
40 GridLayout layout = new GridLayout();
41 container.setLayout(layout);
42 int layoutColumns = 2;
43 layout.numColumns = layoutColumns;
46 System.out.println("Row is null");
48 if (row.getColumnNames() == null) {
49 System.out.println("Columns are null");
51 if (row.getTableData() == null) {
52 System.out.println("Data is null");
54 columnNames = row.getColumnNames();
55 String[] data = row.getTableData();
56 for (int i = 0; i < row.getColumnCount(); i++) {
57 System.out.println("data = " + i + "=" + data[i]);
58 System.out.println("column = " + i + "=" + columnNames[i]);
60 values = new Text[row.getColumnCount()];
61 Label temp = new Label(container, SWT.NULL);
62 temp.setText("Column Name");
63 temp = new Label(container, SWT.NULL);
64 temp.setText("Value");
65 for (int i = 0; i < row.getColumnCount(); i++) {
66 Label label = new Label(container, SWT.NULL);
67 label.setText(columnNames[i]);
68 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
69 GridData fullHorizontal = new GridData();
70 fullHorizontal.horizontalAlignment = GridData.FILL;
71 values[i].setLayoutData(fullHorizontal);
73 //values[i].setText(data[i]);
74 values[i].addModifyListener(new ModifyListener() {
75 public void modifyText(ModifyEvent e) {
80 query = new Label(container, SWT.WRAP);
81 GridData gridData = new GridData();
82 gridData.horizontalSpan = layoutColumns;
83 gridData.horizontalAlignment = GridData.FILL;
84 gridData.verticalAlignment = GridData.FILL;
85 gridData.grabExcessHorizontalSpace = true;
86 gridData.grabExcessVerticalSpace = true;
87 query.setLayoutData(gridData);
89 setControl(container);
92 setPageComplete(true);
94 public void updateQuery() {
95 System.out.println("Updating insert query");
96 StringBuffer fieldClause = new StringBuffer();
98 StringBuffer valuesClause = new StringBuffer();
100 boolean first = false;
101 for (int i = 0; i < columnNames.length; i++) {
102 text = values[i].getText();
103 if (!text.equals("")) {
105 valuesClause.append(", ");
106 fieldClause.append(", ");
108 valuesClause.append("'" + values[i].getText() + "'");
109 fieldClause.append(columnNames[i]);
113 // if (valuesClause.length() > 1) {
114 // valuesClause.deleteCharAt(valuesClause.length() - 1);
115 // valuesClause.deleteCharAt(valuesClause.length() - 1);
118 { row.getTable(), fieldClause.toString(), valuesClause.toString()};
121 fStore.getString("phpeclipse.sql.insert.template"));
123 String query = form.format(arguments);
125 // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
126 // query += fieldClause.toString() + ") ";
127 // query += " VALUES (" + valuesClause.toString();
129 this.query.setText(query);
131 public boolean performFinish() {
132 PHPSourceConsole console = PHPSourceConsole.getInstance();
134 console.print(query.getText());