package net.sourceforge.phpdt.sql.wizards; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import net.sourceforge.phpdt.sql.sql.FilterSort; import net.sourceforge.phpdt.sql.sql.TableRow; import net.sourceforge.phpdt.sql.view.TableView; import net.sourceforge.phpdt.sql.view.tableview.TableAdapter; public class SortFilterPage extends WizardPage implements SQLPage { TableRow row; TableAdapter adapter; Button[] filter; Combo[] operator; Text[] filterValues; Button[] stringFlags; Button[] sort; String columnNames[]; Label query; FilterSort filterSort = new FilterSort(); public SortFilterPage(String pageName) { super(pageName); } public void init(TableRow row, TableAdapter adapter) { this.row = row; this.adapter = adapter; } public void createControl(Composite parent) { System.out.println("page create control"); //$NON-NLS-1$ Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout); int layoutColumns = 5; layout.numColumns = layoutColumns; if (row == null) { System.out.println("Row is null"); //$NON-NLS-1$ } if (row.getColumnNames() == null) { System.out.println("Columns are null"); //$NON-NLS-1$ } if (row.getTableData() == null) { System.out.println("Data is null"); //$NON-NLS-1$ } columnNames = row.getColumnNames(); String[] data = row.getTableData(); for (int i = 0; i < row.getColumnCount(); i++) { System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$ } int size = row.getColumnCount(); filter = new Button[size]; operator = new Combo[size]; filterValues = new Text[size]; stringFlags = new Button[size]; sort = new Button[size]; for (int i = 0; i < row.getColumnCount(); i++) { filter[i] = new Button(container, SWT.CHECK); filter[i].setText(columnNames[i]); filter[i].addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { updateQuery(); } }); operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY); operator[i].add("="); //$NON-NLS-1$ operator[i].add("<>"); //$NON-NLS-1$ operator[i].add("<"); //$NON-NLS-1$ operator[i].add(">"); //$NON-NLS-1$ operator[i].addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { updateQuery(); } }); filterValues[i] = new Text(container, SWT.BORDER); filterValues[i].setText(data[i]); filterValues[i].addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { updateQuery(); } }); stringFlags[i] = new Button(container, SWT.CHECK); stringFlags[i].setText("String"); //$NON-NLS-1$ stringFlags[i].addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { updateQuery(); } }); final int index = i; sort[i] = new Button(container, SWT.CHECK); sort[i].setText(columnNames[i]); sort[i].addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { if (sort[index].getSelection()) { filterSort.addSort(columnNames[index]); } else { filterSort.removeSort(columnNames[index]); } updateQuery(); } }); } query = new Label(container, SWT.WRAP); GridData gridData = new GridData(); gridData.horizontalSpan = layoutColumns; gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; query.setLayoutData(gridData); setControl(container); setPageComplete(true); } public void updateQuery() { filterSort.clearFilters(); for (int i = 0; i < filter.length; i++) { if (filter[i].getSelection()) { filterSort.addFilter(filter[i].getText(), operator[i].getText(), filterValues[i].getText(), stringFlags[i].getSelection()); } } query.setText(filterSort.toString()); } public boolean performFinish() { adapter.setFilterSort(filterSort); TableView.getInstance().refreshCurrent(); return true; } }