1 package com.quantum.wizards;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.events.ModifyEvent;
5 import org.eclipse.swt.events.ModifyListener;
6 import org.eclipse.swt.layout.GridData;
7 import org.eclipse.swt.layout.GridLayout;
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Label;
10 import org.eclipse.swt.widgets.Text;
12 import com.quantum.Messages;
13 import com.quantum.adapters.DatabaseAdapter;
14 import com.quantum.model.Bookmark;
15 import com.quantum.model.Entity;
17 public class InsertRowPage extends BaseSQLPage implements SQLPage {
23 public InsertRowPage(String pageName) {
27 public void createControl(Composite parent) {
28 System.out.println("page create control"); //$NON-NLS-1$
29 Composite container = new Composite(parent, SWT.V_SCROLL);
30 GridLayout layout = new GridLayout();
31 container.setLayout(layout);
32 layout.numColumns = 2;
34 columnNames = this.results.getColumnNames();
35 values = new Text[columnNames.length];
36 new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.ColumnName")); //$NON-NLS-1$
37 new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.Value")); //$NON-NLS-1$
38 for (int i = 0; i < columnNames.length; i++) {
39 Label label = new Label(container, SWT.NULL);
40 label.setText(columnNames[i]);
41 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
42 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
43 gridData.widthHint = 150;
44 values[i].setLayoutData(gridData);
46 //values[i].setText(data[i]);
47 values[i].addModifyListener(new ModifyListener() {
48 public void modifyText(ModifyEvent e) {
53 query = new Label(container, SWT.WRAP);
54 GridData gridData = new GridData();
55 gridData.horizontalSpan = layout.numColumns;
56 gridData.horizontalAlignment = GridData.FILL;
57 gridData.verticalAlignment = GridData.FILL;
58 gridData.grabExcessHorizontalSpace = true;
59 gridData.grabExcessVerticalSpace = true;
60 query.setLayoutData(gridData);
62 setControl(container);
65 setPageComplete(true);
67 public void updateQuery() {
68 System.out.println("Updating query"); //$NON-NLS-1$
69 StringBuffer valuesClause = new StringBuffer();
70 StringBuffer namesClause = new StringBuffer();
71 Bookmark bookmark = this.results.getBookmark();
72 Entity entity = this.results.getEntity();
73 DatabaseAdapter adapter = bookmark.getAdapter();
76 for (int i = 0; i < columnNames.length; i++) {
77 String name = columnNames[i];
78 String value = values[i].getText();
79 if (value.length() > 0) {
81 valuesClause.append(", "); //$NON-NLS-1$
82 namesClause.append(", ");
84 appendColumn(valuesClause, entity, name, adapter, value);
85 namesClause.append(name);
90 String query = "INSERT INTO " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$
92 query += " (" + namesClause + ")";
93 query += " VALUES " + "(" + valuesClause; //$NON-NLS-1$
94 query += " )"; //$NON-NLS-1$
96 this.query.setText(query);
99 * @see com.quantum.wizards.BaseSQLPage#getQueryText()
101 protected String getQueryText() {
102 return this.query.getText();