1 package com.quantum.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 com.quantum.QuantumPlugin;
17 import com.quantum.sql.TableRow;
18 import com.quantum.view.PHPSourceConsole;
19 import com.quantum.view.tableview.TableAdapter;
21 public class PHPInsertRowPage extends WizardPage implements SQLPage {
26 private final static boolean DEBUG = false;
27 private IPreferenceStore fStore;
29 public PHPInsertRowPage(String pageName) {
33 public void init(TableRow row, TableAdapter adapter) {
37 public void createControl(Composite parent) {
39 System.out.println("page create control");
41 fStore = QuantumPlugin.getDefault().getPreferenceStore();
42 Composite container = new Composite(parent, SWT.NULL);
43 GridLayout layout = new GridLayout();
44 container.setLayout(layout);
45 int layoutColumns = 2;
46 layout.numColumns = layoutColumns;
50 System.out.println("Row is null");
52 if (row.getColumnNames() == null) {
53 System.out.println("Columns are null");
55 if (row.getTableData() == null) {
56 System.out.println("Data is null");
60 columnNames = row.getColumnNames();
61 String[] data = row.getTableData();
63 for (int i = 0; i < row.getColumnCount(); i++) {
64 System.out.println("data = " + i + "=" + data[i]);
65 System.out.println("column = " + i + "=" + columnNames[i]);
68 values = new Text[row.getColumnCount()];
69 Label temp = new Label(container, SWT.NULL);
70 temp.setText("Column Name");
71 temp = new Label(container, SWT.NULL);
72 temp.setText("Value");
73 for (int i = 0; i < row.getColumnCount(); i++) {
74 Label label = new Label(container, SWT.NULL);
75 label.setText(columnNames[i]);
76 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
77 GridData fullHorizontal = new GridData();
78 fullHorizontal.horizontalAlignment = GridData.FILL;
79 values[i].setLayoutData(fullHorizontal);
81 //values[i].setText(data[i]);
82 values[i].addModifyListener(new ModifyListener() {
83 public void modifyText(ModifyEvent e) {
88 query = new Label(container, SWT.WRAP);
89 GridData gridData = new GridData();
90 gridData.horizontalSpan = layoutColumns;
91 gridData.horizontalAlignment = GridData.FILL;
92 gridData.verticalAlignment = GridData.FILL;
93 gridData.grabExcessHorizontalSpace = true;
94 gridData.grabExcessVerticalSpace = true;
95 query.setLayoutData(gridData);
97 setControl(container);
100 setPageComplete(true);
102 public void updateQuery() {
104 System.out.println("Updating insert query");
106 StringBuffer fieldClause = new StringBuffer();
108 StringBuffer valuesClause = new StringBuffer();
110 boolean first = false;
111 for (int i = 0; i < columnNames.length; i++) {
112 text = values[i].getText();
113 if (!text.equals("")) {
115 valuesClause.append(", ");
116 fieldClause.append(", ");
118 valuesClause.append("'" + values[i].getText() + "'");
119 fieldClause.append(columnNames[i]);
123 // if (valuesClause.length() > 1) {
124 // valuesClause.deleteCharAt(valuesClause.length() - 1);
125 // valuesClause.deleteCharAt(valuesClause.length() - 1);
127 String[] arguments = { row.getTable(), fieldClause.toString(), valuesClause.toString()};
128 MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template"));
130 String query = form.format(arguments);
132 // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
133 // query += fieldClause.toString() + ") ";
134 // query += " VALUES (" + valuesClause.toString();
136 this.query.setText(query);
138 public boolean performFinish() {
139 PHPSourceConsole console = PHPSourceConsole.getInstance();
141 console.print(query.getText());