2 * Created on 28-jul-2003
5 package com.quantum.view.tableview;
7 import com.quantum.ImageStore;
8 import com.quantum.Messages;
9 import com.quantum.actions.CloseTableAction;
10 import com.quantum.actions.RefreshTableAction;
11 import com.quantum.model.NotConnectedException;
12 import com.quantum.sql.TableRow;
13 import com.quantum.util.StringMatrix;
14 import com.quantum.view.CopyAction;
15 import com.quantum.wizards.SQLRowWizard;
16 import com.quantum.wizards.SortFilterPage;
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.wizard.WizardDialog;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.SelectionEvent;
22 import org.eclipse.swt.events.SelectionListener;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.swt.widgets.Table;
25 import org.eclipse.swt.widgets.TableColumn;
26 import org.eclipse.swt.widgets.ToolBar;
27 import org.eclipse.swt.widgets.ToolItem;
33 public class TableViewToolBar {
35 private ToolBar toolBar;
36 private ToolItem previous;
37 private ToolItem next;
41 public TableViewToolBar(
43 final ToolBar toolBar,
45 final TableAdapter ta,
48 this.toolBar = toolBar;
50 final Action copyAction = new CopyAction(view, table);
51 final Action selectAllAction = new Action() {
56 ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
57 toolItem.setImage(ImageStore.getImage(ImageStore.COPY));
58 toolItem.setToolTipText(Messages.getString("tableview.copy")); //$NON-NLS-1$
59 toolItem.addSelectionListener(new SelectionListener() {
60 public void widgetDefaultSelected(SelectionEvent e) {
62 public void widgetSelected(SelectionEvent e) {
66 toolItem = new ToolItem(toolBar, SWT.PUSH);
67 toolItem.setImage(ImageStore.getImage(ImageStore.OPEN_TABLE)); //$NON-NLS-1$
68 toolItem.setToolTipText(Messages.getString("tableview.selectAll")); //$NON-NLS-1$
69 toolItem.addSelectionListener(new SelectionListener() {
70 public void widgetDefaultSelected(SelectionEvent e) {
72 public void widgetSelected(SelectionEvent e) {
73 selectAllAction.run();
77 filter = new ToolItem(toolBar, SWT.PUSH);
78 filter.setImage(ImageStore.getImage(ImageStore.FILTER));
79 filter.setToolTipText(Messages.getString("tableview.filterSort")); //$NON-NLS-1$
81 toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
83 final ToolItem fullMode = new ToolItem(toolBar, SWT.PUSH | SWT.CHECK);
85 previous = new ToolItem(toolBar, SWT.PUSH);
86 next = new ToolItem(toolBar, SWT.PUSH);
88 fullMode.setImage(ImageStore.getImage(ImageStore.FULLDATA));
89 fullMode.setToolTipText(Messages.getString("tableview.showAll")); //$NON-NLS-1$
90 fullMode.setSelection(false);
91 fullMode.addSelectionListener(new SelectionListener() {
92 public void widgetDefaultSelected(SelectionEvent e) {
94 public void widgetSelected(SelectionEvent event) {
96 if (ta.getPageSize() == Integer.MAX_VALUE) {
103 for (int i = table.getColumnCount() - 1; i >= 0; i--) {
104 table.getColumn(i).dispose();
107 label.setText(ta.getStatusString());
108 previous.setEnabled(ta.hasPreviousPage());
109 next.setEnabled(ta.hasNextPage());
110 } catch (NotConnectedException e) {
111 view.handleException(e);
115 previous.setImage(ImageStore.getImage(ImageStore.PREVIOUS));
116 previous.setToolTipText("Previous"); //$NON-NLS-1$
117 previous.addSelectionListener(new SelectionListener() {
118 public void widgetDefaultSelected(SelectionEvent e) {
120 public void widgetSelected(SelectionEvent event) {
125 for (int i = table.getColumnCount() - 1; i >= 0; i--) {
126 table.getColumn(i).dispose();
129 label.setText(ta.getStatusString());
130 previous.setEnabled(ta.hasPreviousPage());
131 next.setEnabled(ta.hasNextPage());
132 } catch (NotConnectedException e) {
133 view.handleException(e);
137 next.setImage(ImageStore.getImage(ImageStore.NEXT));
138 next.setToolTipText("Next"); //$NON-NLS-1$
139 next.addSelectionListener(new SelectionListener() {
140 public void widgetDefaultSelected(SelectionEvent e) {
142 public void widgetSelected(SelectionEvent event) {
147 for (int i = table.getColumnCount() - 1; i >= 0; i--) {
148 table.getColumn(i).dispose();
151 label.setText(ta.getStatusString());
152 previous.setEnabled(ta.hasPreviousPage());
153 next.setEnabled(ta.hasNextPage());
154 } catch (NotConnectedException e) {
155 view.handleException(e);
162 public void setColumns( final TableView view, final TableAdapter ta, Table table) {
164 // We create a matrix of TableColumn (columns in the Table widget) with
165 // the columns in the table object
166 TableColumn[] columns = table.getColumns();
167 String columnNames[] = new String[columns.length];
168 for (int i = 0; i < columns.length; i++) {
169 columnNames[i] = columns[i].getText();
171 // Copy in data the values of the data columns of the selected rows
172 StringMatrix data = new StringMatrix();
173 data.addMatrixHeader(columnNames);
174 // Create dummy values in case nothing selected
175 for (int i = 0; i < columns.length; i++) {
176 data.addAt(columnNames[i], "", 0); //$NON-NLS-1$
178 final TableRow emptyRow = new TableRow(ta.getEntity(), ta.getBookmark(), ta.getTable(), data);
180 filter.addSelectionListener(new SelectionListener() {
181 public void widgetDefaultSelected(SelectionEvent e) {
183 public void widgetSelected(SelectionEvent e) {
184 SortFilterPage page = new SortFilterPage(""); //$NON-NLS-1$
185 SQLRowWizard wizard = new SQLRowWizard();
186 wizard.init(Messages.getString("TableView.FilterAndSort"), page, emptyRow, ta); //$NON-NLS-1$
187 WizardDialog dialog = new WizardDialog(view.getSite().getShell(), wizard);
198 public ToolItem getNext() {
205 public ToolItem getPrevious() {