1 package com.quantum.wizards;
3 import org.eclipse.jface.viewers.CellEditor;
4 import org.eclipse.jface.viewers.ICellModifier;
5 import org.eclipse.jface.viewers.ILabelProviderListener;
6 import org.eclipse.jface.viewers.IStructuredContentProvider;
7 import org.eclipse.jface.viewers.ITableLabelProvider;
8 import org.eclipse.jface.viewers.TableViewer;
9 import org.eclipse.jface.viewers.TextCellEditor;
10 import org.eclipse.jface.viewers.Viewer;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.graphics.Image;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Table;
18 import org.eclipse.swt.widgets.TableItem;
20 import com.quantum.Messages;
21 import com.quantum.util.StringMatrix;
22 import com.quantum.util.sql.SQLInstructionBuilder;
26 * @author Elvin E. Ebora
28 public class InsertRowPage extends BaseSQLPage implements SQLPage {
30 class InsertRowTableValues {
31 private String colNames = null;
32 private String values = null;
34 public InsertRowTableValues() {
37 * @return Returns the colNames.
39 public String getColNames() {
43 * @param colNames The colNames to set.
45 public void setColNames(String colNames) {
46 this.colNames = colNames;
49 * @return Returns the values.
51 public String getValues() {
55 * @param values The values to set.
57 public void setValues(String values) {
62 class LabelProviderImpl implements ITableLabelProvider {
63 public Image getColumnImage(Object element, int columnIndex) {
66 public String getColumnText(Object element, int columnIndex) {
68 InsertRowTableValues insertRow = (InsertRowTableValues)element;
69 switch (columnIndex) {
71 sReturn = insertRow.getColNames();
74 sReturn = insertRow.getValues();
81 public void addListener(ILabelProviderListener listener) {}
82 public void dispose() {}
83 public boolean isLabelProperty(Object element, String property) {
86 public void removeListener(ILabelProviderListener listener) {}
89 class ContentProviderImpl implements IStructuredContentProvider {
90 public Object[] getElements(Object inputElement) {
94 public void dispose() {}
95 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
98 class CellModifierImpl implements ICellModifier {
100 public boolean canModify(Object element, String property) {
104 public Object getValue(Object element, String property) {
105 System.out.println("getValue called");
107 // Find the index of the column
108 int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property);
109 System.out.println("colIndx : " + colIndx);
111 Object rResult = null;
112 InsertRowTableValues insertVal = (InsertRowTableValues)element;
116 rResult = insertVal.getColNames();
119 rResult = insertVal.getValues();
129 public void modify(Object element, String property, Object value) {
130 int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property);
132 TableItem item = (TableItem) element;
133 InsertRowTableValues insertVal = (InsertRowTableValues)item.getData();
136 case 0: // field names
138 case 1: // field values
139 insertVal.setValues(value.toString());
149 String[] columnNames;
152 InsertRowTableValues[] insertTable = null;
153 CommonWizardUI comUI;
154 TableViewer tableViewer = null;
157 public InsertRowPage(String pageName) {
161 public void createControl(Composite parent) {
162 System.out.println("page create control"); //$NON-NLS-1$
163 Composite container = new Composite(parent, SWT.NULL);
164 container.setLayout(new GridLayout());
165 container.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING));
167 comUI = new CommonWizardUI();
169 // init values to be displayed on the table
170 columnNames = this.results.getColumnNames();
171 int nLen = columnNames.length;
172 insertTable = new InsertRowTableValues[nLen];
174 for (int nCtr=0; nCtr<nLen; nCtr++) {
175 insertTable[nCtr] = new InsertRowTableValues();
176 insertTable[nCtr].setColNames(columnNames[nCtr]);
177 insertTable[nCtr].setValues("");
180 createTable(container);
182 query = new Label(container, SWT.WRAP);
183 query.setLayoutData(comUI.createGridData(1, GridData.FILL));
185 setControl(container);
188 setPageComplete(true);
190 public void updateQuery() {
191 System.out.println("Updating query"); //$NON-NLS-1$
193 StringMatrix columns = new StringMatrix();
194 for (int i = 0; i < columnNames.length; i++) {
195 columns.addHeader( insertTable[i].getColNames() );
196 columns.add( insertTable[i].getValues() , 0 );
198 this.query.setText(SQLInstructionBuilder.buildInsert(this.results.getEntity(), columns));
201 * @see com.quantum.wizards.BaseSQLPage#getQueryText()
203 protected String getQueryText() {
204 return this.query.getText();
207 private void createTable(Composite composite) {
208 System.out.println("Creating table...");
209 Table table = comUI.createTablePage(composite);
210 colNames = new String[] { Messages.getString("InsertRowPage.ColumnName"), Messages.getString("InsertRowPage.Value") };
212 comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 200);
213 comUI.createTableColumn(table, colNames[1], SWT.LEFT, 1, 500);
214 this.tableViewer = new TableViewer(table);
215 this.tableViewer.setColumnProperties(colNames);
217 CellEditor[] editor = new CellEditor[colNames.length];
218 TextCellEditor txtEditorField = new TextCellEditor(table);
219 txtEditorField.getControl().setEnabled(false);
220 editor[0] = txtEditorField;
222 TextCellEditor txtEditorValues = new TextCellEditor(table);
223 editor[1] = txtEditorValues;
225 this.tableViewer.setCellEditors(editor);
226 this.tableViewer.setLabelProvider(new LabelProviderImpl());
227 this.tableViewer.setContentProvider(new ContentProviderImpl());
228 this.tableViewer.setCellModifier(new CellModifierImpl());
229 this.tableViewer.setInput(insertTable);
232 private void updateView() {
233 this.tableViewer.update(insertTable, null);