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.dnd.TextTransfer;
9 import org.eclipse.swt.dnd.Transfer;
10 import org.eclipse.swt.events.ModifyEvent;
11 import org.eclipse.swt.events.ModifyListener;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Label;
16 import org.eclipse.swt.widgets.Text;
18 import com.quantum.QuantumPlugin;
19 import com.quantum.sql.TableRow;
20 //import com.quantum.view.PHPSourceConsole;
21 import com.quantum.view.tableview.TableAdapter;
23 public class PHPInsertRowPage extends WizardPage implements SQLPage {
28 private final static boolean DEBUG = false;
29 private IPreferenceStore fStore;
31 public PHPInsertRowPage(String pageName) {
35 public void init(TableRow row, TableAdapter adapter) {
39 public void createControl(Composite parent) {
41 System.out.println("page create control");
43 fStore = QuantumPlugin.getDefault().getPreferenceStore();
44 Composite container = new Composite(parent, SWT.NULL);
45 GridLayout layout = new GridLayout();
46 container.setLayout(layout);
47 int layoutColumns = 2;
48 layout.numColumns = layoutColumns;
52 System.out.println("Row is null");
54 if (row.getColumnNames() == null) {
55 System.out.println("Columns are null");
57 if (row.getTableData() == null) {
58 System.out.println("Data is null");
62 columnNames = row.getColumnNames();
63 String[] data = row.getTableData();
65 for (int i = 0; i < row.getColumnCount(); i++) {
66 System.out.println("data = " + i + "=" + data[i]);
67 System.out.println("column = " + i + "=" + columnNames[i]);
70 values = new Text[row.getColumnCount()];
71 Label temp = new Label(container, SWT.NULL);
72 temp.setText("Column Name");
73 temp = new Label(container, SWT.NULL);
74 temp.setText("Value");
75 for (int i = 0; i < row.getColumnCount(); i++) {
76 Label label = new Label(container, SWT.NULL);
77 label.setText(columnNames[i]);
78 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
79 GridData fullHorizontal = new GridData();
80 fullHorizontal.horizontalAlignment = GridData.FILL;
81 values[i].setLayoutData(fullHorizontal);
83 //values[i].setText(data[i]);
84 values[i].addModifyListener(new ModifyListener() {
85 public void modifyText(ModifyEvent e) {
90 query = new Label(container, SWT.WRAP);
91 GridData gridData = new GridData();
92 gridData.horizontalSpan = layoutColumns;
93 gridData.horizontalAlignment = GridData.FILL;
94 gridData.verticalAlignment = GridData.FILL;
95 gridData.grabExcessHorizontalSpace = true;
96 gridData.grabExcessVerticalSpace = true;
97 query.setLayoutData(gridData);
99 setControl(container);
102 setPageComplete(true);
104 public void updateQuery() {
106 System.out.println("Updating insert query");
108 StringBuffer fieldClause = new StringBuffer();
110 StringBuffer valuesClause = new StringBuffer();
112 boolean first = false;
113 for (int i = 0; i < columnNames.length; i++) {
114 text = values[i].getText();
115 if (!text.equals("")) {
117 valuesClause.append(", ");
118 fieldClause.append(", ");
120 valuesClause.append("'" + values[i].getText() + "'");
121 fieldClause.append(columnNames[i]);
125 // if (valuesClause.length() > 1) {
126 // valuesClause.deleteCharAt(valuesClause.length() - 1);
127 // valuesClause.deleteCharAt(valuesClause.length() - 1);
129 String[] arguments = { row.getTable(), fieldClause.toString(), valuesClause.toString()};
130 MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template"));
132 String query = form.format(arguments);
134 // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
135 // query += fieldClause.toString() + ") ";
136 // query += " VALUES (" + valuesClause.toString();
138 this.query.setText(query);
140 public boolean performFinish() {
141 // PHPSourceConsole console = PHPSourceConsole.getInstance();
143 // console.print(query.getText());
144 QuantumPlugin.getDefault().getSysClip().setContents(
145 new Object[] { query.getText() },
146 new Transfer[] { TextTransfer.getInstance()});