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) {
45 System.out.println("page create control");
47 Composite container = new Composite(parent, SWT.NULL);
48 GridLayout layout = new GridLayout();
49 container.setLayout(layout);
50 int layoutColumns = 5;
51 layout.numColumns = layoutColumns;
55 System.out.println("Row is null");
57 if (row.getColumnNames() == null) {
58 System.out.println("Columns are null");
60 if (row.getTableData() == null) {
61 System.out.println("Data is null");
65 columnNames = row.getColumnNames();
66 String[] data = row.getTableData();
68 for (int i = 0; i < row.getColumnCount(); i++) {
69 System.out.println("data = " + i + "=" + data[i]);
70 System.out.println("column = " + i + "=" + columnNames[i]);
73 int size = row.getColumnCount();
74 filter = new Button[size];
75 operator = new Combo[size];
76 filterValues = new Text[size];
77 stringFlags = new Button[size];
78 sort = new Button[size];
79 for (int i = 0; i < row.getColumnCount(); i++) {
80 filter[i] = new Button(container, SWT.CHECK);
81 filter[i].setText(columnNames[i]);
82 filter[i].addSelectionListener(new SelectionListener() {
83 public void widgetDefaultSelected(SelectionEvent e) {
85 public void widgetSelected(SelectionEvent e) {
90 operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
92 operator[i].add("<>");
95 operator[i].addSelectionListener(new SelectionListener() {
96 public void widgetDefaultSelected(SelectionEvent e) {
98 public void widgetSelected(SelectionEvent e) {
103 filterValues[i] = new Text(container, SWT.BORDER);
104 filterValues[i].setText(data[i]);
105 filterValues[i].addModifyListener(new ModifyListener() {
106 public void modifyText(ModifyEvent e) {
111 stringFlags[i] = new Button(container, SWT.CHECK);
112 stringFlags[i].setText("String");
113 stringFlags[i].addSelectionListener(new SelectionListener() {
114 public void widgetDefaultSelected(SelectionEvent e) {
116 public void widgetSelected(SelectionEvent e) {
122 sort[i] = new Button(container, SWT.CHECK);
123 sort[i].setText(columnNames[i]);
124 sort[i].addSelectionListener(new SelectionListener() {
125 public void widgetDefaultSelected(SelectionEvent e) {
127 public void widgetSelected(SelectionEvent e) {
128 if (sort[index].getSelection()) {
129 filterSort.addSort(columnNames[index]);
131 filterSort.removeSort(columnNames[index]);
137 query = new Label(container, SWT.WRAP);
138 GridData gridData = new GridData();
139 gridData.horizontalSpan = layoutColumns;
140 gridData.horizontalAlignment = GridData.FILL;
141 gridData.verticalAlignment = GridData.FILL;
142 gridData.grabExcessHorizontalSpace = true;
143 gridData.grabExcessVerticalSpace = true;
144 query.setLayoutData(gridData);
146 setControl(container);
148 setPageComplete(true);
151 public void updateQuery() {
152 filterSort.clearFilters();
153 for (int i = 0; i < filter.length; i++) {
154 if (filter[i].getSelection()) {
155 filterSort.addFilter(
157 operator[i].getText(),
158 filterValues[i].getText(),
159 stringFlags[i].getSelection());
162 query.setText(filterSort.toString());
165 public boolean performFinish() {
166 adapter.setFilterSort(filterSort);
167 TableView.getInstance().refreshCurrent();