package com.quantum.wizards;
-import java.util.Arrays;
-
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.swt.widgets.Text;
import com.quantum.Messages;
-import com.quantum.adapters.DatabaseAdapter;
-import com.quantum.model.Bookmark;
-import com.quantum.model.Entity;
-import com.quantum.sql.SQLResultSetResults;
+import com.quantum.util.StringMatrix;
+import com.quantum.util.sql.SQLInstructionBuilder;
+/**
+ * @author BC Holmes
+ * @author Elvin E. Ebora
+ */
public class InsertRowPage extends BaseSQLPage implements SQLPage {
class InsertRowTableValues {
System.out.println("getValue called");
// Find the index of the column
- int colIndx = getColumnNamesAsList(colNames).indexOf(property);
+ int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property);
System.out.println("colIndx : " + colIndx);
Object rResult = null;
}
public void modify(Object element, String property, Object value) {
- int colIndx = getColumnNamesAsList(colNames).indexOf(property);
+ int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property);
TableItem item = (TableItem) element;
InsertRowTableValues insertVal = (InsertRowTableValues)item.getData();
String[] columnNames;
String[] colNames;
- Text[] values;
Label query;
InsertRowTableValues[] insertTable = null;
+ CommonWizardUI comUI;
TableViewer tableViewer = null;
int numColumns = 0;
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout());
container.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING));
+
+ comUI = new CommonWizardUI();
// init values to be displayed on the table
columnNames = this.results.getColumnNames();
createTable(container);
query = new Label(container, SWT.WRAP);
- GridData gridData = new GridData();
- gridData.horizontalSpan = 1;
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.FILL;
- query.setLayoutData(gridData);
+ query.setLayoutData(comUI.createGridData(1, GridData.FILL));
setControl(container);
updateQuery();
}
public void updateQuery() {
System.out.println("Updating query"); //$NON-NLS-1$
- StringBuffer valuesClause = new StringBuffer();
- StringBuffer namesClause = new StringBuffer();
- Bookmark bookmark = this.results.getBookmark();
- Entity entity = this.results.getEntity();
- DatabaseAdapter adapter = bookmark.getAdapter();
- numColumns = 0;
+ StringMatrix columns = new StringMatrix();
for (int i = 0; i < columnNames.length; i++) {
- String name = insertTable[i].getColNames();
- String value = insertTable[i].getValues();
- if (value != null && value.length() > 0) {
- if (numColumns > 0) {
- valuesClause.append(", "); //$NON-NLS-1$
- namesClause.append(", ");
- }
- appendColumn(valuesClause, entity, name, adapter, value);
- namesClause.append(name);
- numColumns++;
- }
+ columns.addHeader( insertTable[i].getColNames() );
+ columns.add( insertTable[i].getValues() , 0 );
}
-
- String query = "INSERT INTO " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$
- if (numColumns > 0) {
- query += " (" + namesClause + ")";
- query += " VALUES " + "(" + valuesClause; //$NON-NLS-1$
- query += " )"; //$NON-NLS-1$
- }
- this.query.setText(query);
+ this.query.setText(SQLInstructionBuilder.buildInsert(this.results.getEntity(), columns));
}
/* (non-Javadoc)
* @see com.quantum.wizards.BaseSQLPage#getQueryText()
private void createTable(Composite composite) {
System.out.println("Creating table...");
- int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
- Table table = new Table(composite, style);
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
- table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING));
-
+ Table table = comUI.createTablePage(composite);
colNames = new String[] { Messages.getString("InsertRowPage.ColumnName"), Messages.getString("InsertRowPage.Value") };
- createTableColumn(table, colNames[0], SWT.LEFT, 0, 200);
- createTableColumn(table, colNames[1], SWT.LEFT, 1, 500);
+ comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 200);
+ comUI.createTableColumn(table, colNames[1], SWT.LEFT, 1, 500);
this.tableViewer = new TableViewer(table);
this.tableViewer.setColumnProperties(colNames);