1 package com.quantum.wizards;
3 import java.sql.SQLException;
5 import com.quantum.sql.FilterSort;
6 import com.quantum.sql.SQLResultSetResults;
7 import com.quantum.ui.dialog.ExceptionDisplayDialog;
8 import com.quantum.util.connection.ConnectionUtil;
10 import org.eclipse.jface.wizard.WizardPage;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.events.ModifyEvent;
13 import org.eclipse.swt.events.ModifyListener;
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.events.SelectionListener;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Combo;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Text;
24 public class SortFilterPage extends WizardPage implements SQLPage {
31 private SQLResultSetResults.Row row;
33 private ConnectionUtil connectionUtil = new ConnectionUtil();
37 FilterSort filterSort = new FilterSort();
38 private SQLResultSetResults results;
39 public SortFilterPage(String pageName) {
43 public void init(SQLResultSetResults results, SQLResultSetResults.Row row) {
44 this.results = results;
48 public void createControl(Composite parent) {
49 System.out.println("page create control"); //$NON-NLS-1$
51 Composite container = new Composite(parent, SWT.NULL);
52 GridLayout layout = new GridLayout();
53 container.setLayout(layout);
54 int layoutColumns = 6;
55 layout.numColumns = layoutColumns;
57 columnNames = this.results.getColumnNames();
59 int size = this.results.getColumnCount();
60 filter = new Button[size];
61 operator = new Combo[size];
62 filterValues = new Text[size];
63 stringFlags = new Button[size];
64 sort = new Button[size];
65 ascDesc = new Combo[size];
66 for (int i = 0; i < size; i++) {
67 filter[i] = new Button(container, SWT.CHECK);
68 filter[i].setText(columnNames[i]);
69 filter[i].addSelectionListener(new SelectionListener() {
70 public void widgetDefaultSelected(SelectionEvent e) {
72 public void widgetSelected(SelectionEvent e) {
77 operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
78 operator[i].add("="); //$NON-NLS-1$
79 operator[i].add("<>"); //$NON-NLS-1$
80 operator[i].add("<"); //$NON-NLS-1$
81 operator[i].add(">"); //$NON-NLS-1$
82 operator[i].addSelectionListener(new SelectionListener() {
83 public void widgetDefaultSelected(SelectionEvent e) {
85 public void widgetSelected(SelectionEvent e) {
90 filterValues[i] = new Text(container, SWT.BORDER);
91 Object data = this.row == null ? null : this.row.get(i+1);
92 filterValues[i].setText(data == null ? "" : data.toString());
93 filterValues[i].addModifyListener(new ModifyListener() {
94 public void modifyText(ModifyEvent e) {
99 stringFlags[i] = new Button(container, SWT.CHECK);
100 stringFlags[i].setText("String"); //$NON-NLS-1$
101 stringFlags[i].addSelectionListener(new SelectionListener() {
102 public void widgetDefaultSelected(SelectionEvent e) {
104 public void widgetSelected(SelectionEvent e) {
110 sort[i] = new Button(container, SWT.CHECK);
111 sort[i].setText(columnNames[i]);
112 sort[i].addSelectionListener(new SelectionListener() {
113 public void widgetDefaultSelected(SelectionEvent e) {
115 public void widgetSelected(SelectionEvent e) {
116 if (sort[index].getSelection()) {
117 filterSort.addSort(columnNames[index], ascDesc[index].getText());
119 filterSort.removeSort(columnNames[index]);
125 ascDesc[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
126 ascDesc[i].add(""); //$NON-NLS-1$
127 ascDesc[i].add("ASC"); //$NON-NLS-1$
128 ascDesc[i].add("DESC"); //$NON-NLS-1$
129 ascDesc[i].addSelectionListener(new SelectionListener() {
130 public void widgetDefaultSelected(SelectionEvent e) {
132 public void widgetSelected(SelectionEvent e) {
133 if (sort[index].getSelection()) {
134 filterSort.addSort(columnNames[index], ascDesc[index].getText());
136 filterSort.removeSort(columnNames[index]);
142 query = new Label(container, SWT.WRAP);
143 GridData gridData = new GridData();
144 gridData.horizontalSpan = layoutColumns;
145 gridData.horizontalAlignment = GridData.FILL;
146 gridData.verticalAlignment = GridData.FILL;
147 gridData.grabExcessHorizontalSpace = true;
148 gridData.grabExcessVerticalSpace = true;
149 query.setLayoutData(gridData);
151 setControl(container);
153 setPageComplete(true);
156 public void updateQuery() {
157 filterSort.clearFilters();
158 for (int i = 0; i < filter.length; i++) {
159 if (filter[i].getSelection()) {
160 filterSort.addFilter(filter[i].getText(), operator[i].getText(), filterValues[i].getText(), stringFlags[i].getSelection());
163 query.setText(filterSort.toString());
166 public boolean performFinish() {
167 this.results.setFilterSort(filterSort);
169 this.results.refresh(this.connectionUtil.connect(
170 this.results.getBookmark(), getShell()));
172 } catch (SQLException e) {
173 ExceptionDisplayDialog.openError(getShell(), null, null, e);