1 package net.sourceforge.phpdt.sql.wizards;
3 import org.eclipse.jface.wizard.WizardPage;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.events.ModifyEvent;
6 import org.eclipse.swt.events.ModifyListener;
7 import org.eclipse.swt.events.SelectionEvent;
8 import org.eclipse.swt.events.SelectionListener;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Combo;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.swt.widgets.Text;
17 import net.sourceforge.phpdt.sql.sql.FilterSort;
18 import net.sourceforge.phpdt.sql.sql.TableRow;
19 import net.sourceforge.phpdt.sql.view.TableView;
20 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
22 public class SortFilterPage extends WizardPage implements SQLPage {
33 FilterSort filterSort = new FilterSort();
34 public SortFilterPage(String pageName) {
38 public void init(TableRow row, TableAdapter adapter) {
40 this.adapter = adapter;
43 public void createControl(Composite parent) {
44 System.out.println("page create control");
46 Composite container = new Composite(parent, SWT.NULL);
47 GridLayout layout = new GridLayout();
48 container.setLayout(layout);
49 int layoutColumns = 5;
50 layout.numColumns = layoutColumns;
53 System.out.println("Row is null");
55 if (row.getColumnNames() == null) {
56 System.out.println("Columns are null");
58 if (row.getTableData() == null) {
59 System.out.println("Data is null");
62 columnNames = row.getColumnNames();
63 String[] data = row.getTableData();
64 for (int i = 0; i < row.getColumnCount(); i++) {
65 System.out.println("data = " + i + "=" + data[i]);
66 System.out.println("column = " + i + "=" + columnNames[i]);
68 int size = row.getColumnCount();
69 filter = new Button[size];
70 operator = new Combo[size];
71 filterValues = new Text[size];
72 stringFlags = new Button[size];
73 sort = new Button[size];
74 for (int i = 0; i < row.getColumnCount(); i++) {
75 filter[i] = new Button(container, SWT.CHECK);
76 filter[i].setText(columnNames[i]);
77 filter[i].addSelectionListener(new SelectionListener() {
78 public void widgetDefaultSelected(SelectionEvent e) {
80 public void widgetSelected(SelectionEvent e) {
85 operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
87 operator[i].add("<>");
90 operator[i].addSelectionListener(new SelectionListener() {
91 public void widgetDefaultSelected(SelectionEvent e) {
93 public void widgetSelected(SelectionEvent e) {
98 filterValues[i] = new Text(container, SWT.BORDER);
99 filterValues[i].setText(data[i]);
100 filterValues[i].addModifyListener(new ModifyListener() {
101 public void modifyText(ModifyEvent e) {
106 stringFlags[i] = new Button(container, SWT.CHECK);
107 stringFlags[i].setText("String");
108 stringFlags[i].addSelectionListener(new SelectionListener() {
109 public void widgetDefaultSelected(SelectionEvent e) {
111 public void widgetSelected(SelectionEvent e) {
117 sort[i] = new Button(container, SWT.CHECK);
118 sort[i].setText(columnNames[i]);
119 sort[i].addSelectionListener(new SelectionListener() {
120 public void widgetDefaultSelected(SelectionEvent e) {
122 public void widgetSelected(SelectionEvent e) {
123 if (sort[index].getSelection()) {
124 filterSort.addSort(columnNames[index]);
126 filterSort.removeSort(columnNames[index]);
132 query = new Label(container, SWT.WRAP);
133 GridData gridData = new GridData();
134 gridData.horizontalSpan = layoutColumns;
135 gridData.horizontalAlignment = GridData.FILL;
136 gridData.verticalAlignment = GridData.FILL;
137 gridData.grabExcessHorizontalSpace = true;
138 gridData.grabExcessVerticalSpace = true;
139 query.setLayoutData(gridData);
141 setControl(container);
143 setPageComplete(true);
146 public void updateQuery() {
147 filterSort.clearFilters();
148 for (int i = 0; i < filter.length; i++) {
149 if (filter[i].getSelection()) {
150 filterSort.addFilter(filter[i].getText(), operator[i].getText(), filterValues[i].getText(), stringFlags[i].getSelection());
153 query.setText(filterSort.toString());
156 public boolean performFinish() {
157 adapter.setFilterSort(filterSort);
158 TableView.getInstance().refreshCurrent();