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) {
31 System.out.println("page create control");
32 Composite container = new Composite(parent, SWT.NULL);
33 GridLayout layout = new GridLayout();
34 container.setLayout(layout);
35 int layoutColumns = 2;
36 layout.numColumns = layoutColumns;
39 System.out.println("Row is null");
41 if (row.getColumnNames() == null) {
42 System.out.println("Columns are null");
44 if (row.getTableData() == null) {
45 System.out.println("Data is null");
47 columnNames = row.getColumnNames();
48 String[] data = row.getTableData();
49 for (int i = 0; i < row.getColumnCount(); i++) {
50 System.out.println("data = " + i + "=" + data[i]);
51 System.out.println("column = " + i + "=" + columnNames[i]);
53 values = new Text[row.getColumnCount()];
54 Label temp = new Label(container, SWT.NULL);
55 temp.setText("Column Name");
56 temp = new Label(container, SWT.NULL);
57 temp.setText("Value");
58 for (int i = 0; i < row.getColumnCount(); i++) {
59 Label label = new Label(container, SWT.NULL);
60 label.setText(columnNames[i]);
61 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
62 GridData fullHorizontal = new GridData();
63 fullHorizontal.horizontalAlignment = GridData.FILL;
64 values[i].setLayoutData(fullHorizontal);
66 //values[i].setText(data[i]);
67 values[i].addModifyListener(new ModifyListener() {
68 public void modifyText(ModifyEvent e) {
73 query = new Label(container, SWT.WRAP);
74 GridData gridData = new GridData();
75 gridData.horizontalSpan = layoutColumns;
76 gridData.horizontalAlignment = GridData.FILL;
77 gridData.verticalAlignment = GridData.FILL;
78 gridData.grabExcessHorizontalSpace = true;
79 gridData.grabExcessVerticalSpace = true;
80 query.setLayoutData(gridData);
82 setControl(container);
85 setPageComplete(true);
87 public void updateQuery() {
88 System.out.println("Updating query");
89 StringBuffer valuesClause = new StringBuffer();
90 for (int i = 0; i < columnNames.length; i++) {
91 valuesClause.append(values[i].getText());
92 valuesClause.append(", ");
94 if (valuesClause.length() > 1) {
95 valuesClause.deleteCharAt(valuesClause.length() - 1);
96 valuesClause.deleteCharAt(valuesClause.length() - 1);
98 String query = "INSERT INTO " + row.getTable();
99 query += " VALUES (" + valuesClause.toString();
101 this.query.setText(query);
103 public boolean performFinish() {
104 MultiSQLServer server = MultiSQLServer.getInstance();
105 server.execute(query.getText());