1 package com.quantum.wizards;
3 import org.eclipse.jface.viewers.CellEditor;
4 import org.eclipse.jface.viewers.CheckboxCellEditor;
5 import org.eclipse.jface.viewers.ICellModifier;
6 import org.eclipse.jface.viewers.ILabelProviderListener;
7 import org.eclipse.jface.viewers.IStructuredContentProvider;
8 import org.eclipse.jface.viewers.ITableLabelProvider;
9 import org.eclipse.jface.viewers.TableViewer;
10 import org.eclipse.jface.viewers.TextCellEditor;
11 import org.eclipse.jface.viewers.Viewer;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.graphics.Image;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Table;
19 import org.eclipse.swt.widgets.TableItem;
21 import com.quantum.ImageStore;
22 import com.quantum.Messages;
23 import com.quantum.model.Column;
24 import com.quantum.model.Entity;
25 import com.quantum.util.StringMatrix;
26 import com.quantum.util.sql.SQLInstructionBuilder;
30 * @author Elvin E. Ebora
32 public class DeleteRowPage extends BaseSQLPage implements SQLPage {
34 class DeleteRowPageValues {
35 private String sColNames = null;
36 private String sValues = null;
37 private boolean bPrimary = false;
39 public DeleteRowPageValues() {
42 * @return Returns the bPrimary.
44 public boolean isBPrimary() {
48 * @param primary The bPrimary to set.
50 public void setBPrimary(boolean primary) {
54 * @return Returns the sColNames.
56 public String getSColNames() {
60 * @param colNames The sColNames to set.
62 public void setSColNames(String colNames) {
66 * @return Returns the sValues.
68 public String getSValues() {
72 * @param values The sValues to set.
74 public void setSValues(String values) {
79 class LabelProviderImpl implements ITableLabelProvider {
80 public Image getColumnImage(Object element, int columnIndex) {
81 if (columnIndex == 2) {
82 return ((DeleteRowPageValues)element).isBPrimary() ? imgCheck : imgUncheck;
87 public String getColumnText(Object element, int columnIndex) {
89 DeleteRowPageValues deleteRow = (DeleteRowPageValues)element;
90 switch (columnIndex) {
91 case 0: // column names
92 sReturn = deleteRow.getSColNames();
95 sReturn = deleteRow.getSValues();
97 case 2: // set checkbox
104 public void addListener(ILabelProviderListener listener) {}
105 public void dispose() {}
106 public boolean isLabelProperty(Object element, String property) {
109 public void removeListener(ILabelProviderListener listener) {}
112 class ContentProviderImpl implements IStructuredContentProvider {
113 public Object[] getElements(Object inputElement) {
117 public void dispose() {}
118 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
121 class CellModifierImpl implements ICellModifier {
123 public boolean canModify(Object element, String property) {
127 public Object getValue(Object element, String property) {
128 System.out.println("getValue called");
130 // Find the index of the column
131 int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property);
132 System.out.println("colIndx : " + colIndx);
134 Object rResult = null;
135 DeleteRowPageValues deleteVal = (DeleteRowPageValues)element;
138 case 0: // column names
139 rResult = deleteVal.getSColNames();
142 rResult = deleteVal.getSValues();
145 rResult = new Boolean(deleteVal.isBPrimary());
154 public void modify(Object element, String property, Object value) {
155 int colIndx = comUI.getColumnNamesAsList(colNames).indexOf(property);
157 TableItem item = (TableItem) element;
158 DeleteRowPageValues deleteVal = (DeleteRowPageValues)item.getData();
161 case 0: // column names
164 deleteVal.setSValues(value.toString());
167 deleteVal.setBPrimary(((Boolean)value).booleanValue());
178 String[] columnNames;
181 DeleteRowPageValues[] deleteTable = null;
182 CommonWizardUI comUI;
183 TableViewer tableViewer = null;
184 static Image imgCheck = null;
185 static Image imgUncheck = null;
188 imgCheck = ImageStore.getImage(ImageStore.CHECKED);
189 imgUncheck = ImageStore.getImage(ImageStore.UNCHECKED);
192 public DeleteRowPage(String pageName) {
196 public void createControl(Composite parent) {
197 System.out.println("page create control"); //$NON-NLS-1$
198 Composite container = new Composite(parent, SWT.NULL);
199 container.setLayout(new GridLayout());
200 container.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_BEGINNING));
202 Entity entity = this.results.getEntity();
204 comUI = new CommonWizardUI();
206 // init values to be displayed on the table
207 columnNames = this.results.getColumnNames();
208 int nLen = columnNames.length;
209 deleteTable = new DeleteRowPageValues[nLen];
211 for(int nCtr=0; nCtr<nLen; nCtr++) {
212 deleteTable[nCtr] = new DeleteRowPageValues();
213 deleteTable[nCtr].setSColNames(columnNames[nCtr]);
214 Object data = this.row == null ? null : this.row.get(nCtr+1);
215 deleteTable[nCtr].setSValues(data == null ? "" : data.toString());
216 Column column = (entity == null) ? null : getColumn(entity, columnNames[nCtr]);
217 if (column != null && column.isPrimaryKey()) {
218 deleteTable[nCtr].setBPrimary(true);
222 createTable(container);
224 query = new Label(container, SWT.WRAP);
225 query.setLayoutData(comUI.createGridData(1, GridData.FILL));
227 setControl(container);
230 setPageComplete(true);
232 public void updateQuery() {
233 System.out.println(Messages.getString("DeleteRowPage.UpdatingQuery")); //$NON-NLS-1$
234 StringMatrix key = new StringMatrix();
235 for (int i = 0; i < columnNames.length; i++) {
236 if (deleteTable[i].isBPrimary()) {
237 key.addHeader( deleteTable[i].getSColNames() );
238 key.add( deleteTable[i].getSValues() , 0 );
241 this.query.setText(SQLInstructionBuilder.buildDelete(this.results.getEntity(), key));
244 protected String getQueryText() {
245 return query.getText();
248 private void updateView() {
249 this.tableViewer.update(deleteTable, null);
252 private void createTable(Composite composite) {
253 System.out.println("Creating table...");
254 Table table = comUI.createTablePage(composite);
255 colNames = new String[] { Messages.getString("DeleteRowPage.ColumnName"), Messages.getString("DeleteRowPage.Value"), "Where" };
257 comUI.createTableColumn(table, colNames[0], SWT.LEFT, 0, 150);
258 comUI.createTableColumn(table, colNames[1], SWT.LEFT, 1, 300);
259 comUI.createTableColumn(table, colNames[2], SWT.CENTER, 2, 60);
260 this.tableViewer = new TableViewer(table);
261 this.tableViewer.setColumnProperties(colNames);
263 CellEditor[] editor = new CellEditor[colNames.length];
264 TextCellEditor txtEditorField = new TextCellEditor(table);
265 txtEditorField.getControl().setEnabled(false);
266 editor[0] = txtEditorField;
268 TextCellEditor txtEditorFieldValue = new TextCellEditor(table);
269 editor[1] = txtEditorFieldValue;
271 editor[2] = new CheckboxCellEditor(table, SWT.NULL);
273 this.tableViewer.setCellEditors(editor);
274 this.tableViewer.setLabelProvider(new LabelProviderImpl());
275 this.tableViewer.setContentProvider(new ContentProviderImpl());
276 this.tableViewer.setCellModifier(new CellModifierImpl());
277 this.tableViewer.setInput(deleteTable);