1 package com.quantum.wizards;
3 import com.quantum.sql.FilterSort;
4 import com.quantum.sql.TableRow;
5 import com.quantum.view.tableview.TableAdapter;
6 import com.quantum.view.tableview.TableView;
8 import org.eclipse.jface.wizard.WizardPage;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.ModifyEvent;
11 import org.eclipse.swt.events.ModifyListener;
12 import org.eclipse.swt.events.SelectionEvent;
13 import org.eclipse.swt.events.SelectionListener;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Combo;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Text;
22 public class SortFilterPage extends WizardPage implements SQLPage {
34 FilterSort filterSort = new FilterSort();
35 public SortFilterPage(String pageName) {
39 public void init(TableRow row, TableAdapter adapter) {
41 this.adapter = adapter;
44 public void createControl(Composite parent) {
45 System.out.println("page create control"); //$NON-NLS-1$
47 Composite container = new Composite(parent, SWT.NULL);
48 GridLayout layout = new GridLayout();
49 container.setLayout(layout);
50 int layoutColumns = 6;
51 layout.numColumns = layoutColumns;
54 System.out.println("Row is null"); //$NON-NLS-1$
56 if (row.getColumnNames() == null) {
57 System.out.println("Columns are null"); //$NON-NLS-1$
59 if (row.getTableData() == null) {
60 System.out.println("Data is null"); //$NON-NLS-1$
63 columnNames = row.getColumnNames();
64 String[] data = row.getTableData();
65 for (int i = 0; i < row.getColumnCount(); i++) {
66 System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$
67 System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$
69 int size = row.getColumnCount();
70 filter = new Button[size];
71 operator = new Combo[size];
72 filterValues = new Text[size];
73 stringFlags = new Button[size];
74 sort = new Button[size];
75 ascDesc = new Combo[size];
76 for (int i = 0; i < row.getColumnCount(); i++) {
77 filter[i] = new Button(container, SWT.CHECK);
78 filter[i].setText(columnNames[i]);
79 filter[i].addSelectionListener(new SelectionListener() {
80 public void widgetDefaultSelected(SelectionEvent e) {
82 public void widgetSelected(SelectionEvent e) {
87 operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
88 operator[i].add("="); //$NON-NLS-1$
89 operator[i].add("<>"); //$NON-NLS-1$
90 operator[i].add("<"); //$NON-NLS-1$
91 operator[i].add(">"); //$NON-NLS-1$
92 operator[i].addSelectionListener(new SelectionListener() {
93 public void widgetDefaultSelected(SelectionEvent e) {
95 public void widgetSelected(SelectionEvent e) {
100 filterValues[i] = new Text(container, SWT.BORDER);
101 filterValues[i].setText(data[i]);
102 filterValues[i].addModifyListener(new ModifyListener() {
103 public void modifyText(ModifyEvent e) {
108 stringFlags[i] = new Button(container, SWT.CHECK);
109 stringFlags[i].setText("String"); //$NON-NLS-1$
110 stringFlags[i].addSelectionListener(new SelectionListener() {
111 public void widgetDefaultSelected(SelectionEvent e) {
113 public void widgetSelected(SelectionEvent e) {
119 sort[i] = new Button(container, SWT.CHECK);
120 sort[i].setText(columnNames[i]);
121 sort[i].addSelectionListener(new SelectionListener() {
122 public void widgetDefaultSelected(SelectionEvent e) {
124 public void widgetSelected(SelectionEvent e) {
125 if (sort[index].getSelection()) {
126 filterSort.addSort(columnNames[index], ascDesc[index].getText());
128 filterSort.removeSort(columnNames[index]);
134 ascDesc[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
135 ascDesc[i].add(""); //$NON-NLS-1$
136 ascDesc[i].add("ASC"); //$NON-NLS-1$
137 ascDesc[i].add("DESC"); //$NON-NLS-1$
138 ascDesc[i].addSelectionListener(new SelectionListener() {
139 public void widgetDefaultSelected(SelectionEvent e) {
141 public void widgetSelected(SelectionEvent e) {
142 if (sort[index].getSelection()) {
143 filterSort.addSort(columnNames[index], ascDesc[index].getText());
145 filterSort.removeSort(columnNames[index]);
151 query = new Label(container, SWT.WRAP);
152 GridData gridData = new GridData();
153 gridData.horizontalSpan = layoutColumns;
154 gridData.horizontalAlignment = GridData.FILL;
155 gridData.verticalAlignment = GridData.FILL;
156 gridData.grabExcessHorizontalSpace = true;
157 gridData.grabExcessVerticalSpace = true;
158 query.setLayoutData(gridData);
160 setControl(container);
162 setPageComplete(true);
165 public void updateQuery() {
166 filterSort.clearFilters();
167 for (int i = 0; i < filter.length; i++) {
168 if (filter[i].getSelection()) {
169 filterSort.addFilter(filter[i].getText(), operator[i].getText(), filterValues[i].getText(), stringFlags[i].getSelection());
172 query.setText(filterSort.toString());
175 public boolean performFinish() {
176 adapter.setFilterSort(filterSort);
177 TableView.getInstance().refreshCurrent();