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.NULL);
30 GridLayout layout = new GridLayout();
31 container.setLayout(layout);
32 layout.numColumns = 2;
35 System.out.println("Row is null"); //$NON-NLS-1$
37 if (row.getColumnNames() == null) {
38 System.out.println("Columns are null"); //$NON-NLS-1$
40 if (row.getTableData() == null) {
41 System.out.println("Data is null"); //$NON-NLS-1$
43 columnNames = row.getColumnNames();
44 String[] data = row.getTableData();
45 for (int i = 0; i < row.getColumnCount(); i++) {
46 System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$
47 System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$
49 values = new Text[row.getColumnCount()];
50 new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.ColumnName")); //$NON-NLS-1$
51 new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.Value")); //$NON-NLS-1$
52 for (int i = 0; i < row.getColumnCount(); i++) {
53 Label label = new Label(container, SWT.NULL);
54 label.setText(columnNames[i]);
55 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
56 GridData fullHorizontal = new GridData();
57 fullHorizontal.horizontalAlignment = GridData.FILL;
58 values[i].setLayoutData(fullHorizontal);
60 //values[i].setText(data[i]);
61 values[i].addModifyListener(new ModifyListener() {
62 public void modifyText(ModifyEvent e) {
67 query = new Label(container, SWT.WRAP);
68 GridData gridData = new GridData();
69 gridData.horizontalSpan = layout.numColumns;
70 gridData.horizontalAlignment = GridData.FILL;
71 gridData.verticalAlignment = GridData.FILL;
72 gridData.grabExcessHorizontalSpace = true;
73 gridData.grabExcessVerticalSpace = true;
74 query.setLayoutData(gridData);
76 setControl(container);
79 setPageComplete(true);
81 public void updateQuery() {
82 System.out.println("Updating query"); //$NON-NLS-1$
83 StringBuffer valuesClause = new StringBuffer();
84 StringBuffer namesClause = new StringBuffer();
85 Bookmark bookmark = row.getBookmark();
86 Entity entity = row.getEntity();
87 DatabaseAdapter adapter = bookmark.getAdapter();
90 for (int i = 0; i < columnNames.length; i++) {
91 String name = columnNames[i];
92 String value = values[i].getText();
93 if (value.length() > 0) {
95 valuesClause.append(", "); //$NON-NLS-1$
96 namesClause.append(", ");
98 appendColumn(valuesClause, entity, name, adapter, value);
99 namesClause.append(name);
104 String query = "INSERT INTO " + row.getTable(); //$NON-NLS-1$
105 if (numColumns > 0) {
106 query += " (" + namesClause + ")";
107 query += " VALUES " + "(" + valuesClause; //$NON-NLS-1$
108 query += " )"; //$NON-NLS-1$
110 this.query.setText(query);
113 * @see com.quantum.wizards.BaseSQLPage#getQueryText()
115 protected String getQueryText() {
116 return this.query.getText();