1 package com.quantum.wizards;
3 import com.quantum.Messages;
4 import com.quantum.adapters.AdapterFactory;
5 import com.quantum.adapters.DatabaseAdapter;
6 import com.quantum.model.Bookmark;
7 import com.quantum.model.Entity;
9 import org.eclipse.swt.SWT;
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 public class InsertRowPage extends BaseSQLPage implements SQLPage {
24 public InsertRowPage(String pageName) {
28 public void createControl(Composite parent) {
29 System.out.println("page create control"); //$NON-NLS-1$
30 Composite container = new Composite(parent, SWT.NULL);
31 GridLayout layout = new GridLayout();
32 container.setLayout(layout);
33 layout.numColumns = 2;
36 System.out.println("Row is null"); //$NON-NLS-1$
38 if (row.getColumnNames() == null) {
39 System.out.println("Columns are null"); //$NON-NLS-1$
41 if (row.getTableData() == null) {
42 System.out.println("Data is null"); //$NON-NLS-1$
44 columnNames = row.getColumnNames();
45 String[] data = row.getTableData();
46 for (int i = 0; i < row.getColumnCount(); i++) {
47 System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$
48 System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$
50 values = new Text[row.getColumnCount()];
51 new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.ColumnName")); //$NON-NLS-1$
52 new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.Value")); //$NON-NLS-1$
53 for (int i = 0; i < row.getColumnCount(); i++) {
54 Label label = new Label(container, SWT.NULL);
55 label.setText(columnNames[i]);
56 values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
57 GridData fullHorizontal = new GridData();
58 fullHorizontal.horizontalAlignment = GridData.FILL;
59 values[i].setLayoutData(fullHorizontal);
61 //values[i].setText(data[i]);
62 values[i].addModifyListener(new ModifyListener() {
63 public void modifyText(ModifyEvent e) {
68 query = new Label(container, SWT.WRAP);
69 GridData gridData = new GridData();
70 gridData.horizontalSpan = layout.numColumns;
71 gridData.horizontalAlignment = GridData.FILL;
72 gridData.verticalAlignment = GridData.FILL;
73 gridData.grabExcessHorizontalSpace = true;
74 gridData.grabExcessVerticalSpace = true;
75 query.setLayoutData(gridData);
77 setControl(container);
80 setPageComplete(true);
82 public void updateQuery() {
83 System.out.println("Updating query"); //$NON-NLS-1$
84 StringBuffer valuesClause = new StringBuffer();
85 StringBuffer namesClause = new StringBuffer();
86 Bookmark bookmark = row.getBookmark();
87 Entity entity = row.getEntity();
88 DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
91 for (int i = 0; i < columnNames.length; i++) {
92 String name = columnNames[i];
93 String value = values[i].getText();
94 if (value.length() > 0) {
96 valuesClause.append(", "); //$NON-NLS-1$
97 namesClause.append(", ");
99 appendColumn(valuesClause, entity, name, adapter, value);
100 namesClause.append(name);
105 String query = "INSERT INTO " + row.getTable(); //$NON-NLS-1$
106 if (numColumns > 0) {
107 query += " (" + namesClause + ")";
108 query += " VALUES " + "(" + valuesClause; //$NON-NLS-1$
109 query += " )"; //$NON-NLS-1$
111 this.query.setText(query);
114 * @see com.quantum.wizards.BaseSQLPage#getQueryText()
116 protected String getQueryText() {
117 return this.query.getText();