1 package net.sourceforge.phpdt.sql.wizards;
3 import org.eclipse.jface.wizard.WizardPage;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.events.ModifyEvent;
6 import org.eclipse.swt.events.ModifyListener;
7 import org.eclipse.swt.layout.GridData;
8 import org.eclipse.swt.layout.GridLayout;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Label;
11 import org.eclipse.swt.widgets.Text;
13 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
14 import net.sourceforge.phpdt.sql.sql.TableRow;
15 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
17 public class InsertRowPage extends WizardPage implements SQLPage {
22 public InsertRowPage(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 query");
97 StringBuffer valuesClause = new StringBuffer();
98 for (int i = 0; i < columnNames.length; i++) {
99 valuesClause.append(values[i].getText());
100 valuesClause.append(", ");
102 if (valuesClause.length() > 1) {
103 valuesClause.deleteCharAt(valuesClause.length() - 1);
104 valuesClause.deleteCharAt(valuesClause.length() - 1);
106 String query = "INSERT INTO " + row.getTable();
107 query += " VALUES (" + valuesClause.toString();
109 this.query.setText(query);
111 public boolean performFinish() {
112 MultiSQLServer server = MultiSQLServer.getInstance();
113 server.execute(query.getText());