2 * Created on 28-jul-2003
5 package com.quantum.view.tableview;
7 import com.quantum.Messages;
8 import com.quantum.QuantumPlugin;
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 RefreshTableAction refreshTableAction;
37 private CloseTableAction closeTableAction;
38 private ToolItem previous;
39 private ToolItem next;
43 public TableViewToolBar(
45 final ToolBar toolBar,
47 final TableAdapter ta,
50 this.toolBar = toolBar;
52 refreshTableAction = new RefreshTableAction();
53 refreshTableAction.setText(Messages.getString("tableview.refresh")); //$NON-NLS-1$
54 refreshTableAction.setImageDescriptor(
55 QuantumPlugin.getImageDescriptor("refresh.gif")); //$NON-NLS-1$
56 refreshTableAction.init(view);
57 closeTableAction = new CloseTableAction();
58 closeTableAction.setText(Messages.getString("tableview.close")); //$NON-NLS-1$
59 closeTableAction.setImageDescriptor(
60 QuantumPlugin.getImageDescriptor("close.gif")); //$NON-NLS-1$
61 closeTableAction.init(view);
63 ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
64 toolItem.setImage(QuantumPlugin.getImage("refresh.gif")); //$NON-NLS-1$
65 toolItem.setToolTipText(Messages.getString("tableview.refresh")); //$NON-NLS-1$
66 toolItem.addSelectionListener(new SelectionListener() {
67 public void widgetDefaultSelected(SelectionEvent e) {
69 public void widgetSelected(SelectionEvent e) {
70 refreshTableAction.run();
74 final Action copyAction = new CopyAction(view, table);
75 final Action selectAllAction = new Action() {
80 toolItem = new ToolItem(toolBar, SWT.PUSH);
81 toolItem.setImage(QuantumPlugin.getImage("copy.gif")); //$NON-NLS-1$
82 toolItem.setToolTipText(Messages.getString("tableview.copy")); //$NON-NLS-1$
83 toolItem.addSelectionListener(new SelectionListener() {
84 public void widgetDefaultSelected(SelectionEvent e) {
86 public void widgetSelected(SelectionEvent e) {
90 toolItem = new ToolItem(toolBar, SWT.PUSH);
91 toolItem.setImage(QuantumPlugin.getImage("table.gif")); //$NON-NLS-1$
92 toolItem.setToolTipText(Messages.getString("tableview.selectAll")); //$NON-NLS-1$
93 toolItem.addSelectionListener(new SelectionListener() {
94 public void widgetDefaultSelected(SelectionEvent e) {
96 public void widgetSelected(SelectionEvent e) {
97 selectAllAction.run();
101 filter = new ToolItem(toolBar, SWT.PUSH);
102 filter.setImage(QuantumPlugin.getImage("filter.gif")); //$NON-NLS-1$
103 filter.setToolTipText(Messages.getString("tableview.filterSort")); //$NON-NLS-1$
105 toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
107 final ToolItem fullMode = new ToolItem(toolBar, SWT.PUSH | SWT.CHECK);
109 previous = new ToolItem(toolBar, SWT.PUSH);
110 next = new ToolItem(toolBar, SWT.PUSH);
112 fullMode.setImage(QuantumPlugin.getImage("fulldata.gif")); //$NON-NLS-1$
113 fullMode.setToolTipText(Messages.getString("tableview.showAll")); //$NON-NLS-1$
114 fullMode.setSelection(false);
115 fullMode.addSelectionListener(new SelectionListener() {
116 public void widgetDefaultSelected(SelectionEvent e) {
118 public void widgetSelected(SelectionEvent event) {
120 if (ta.getPageSize() == Integer.MAX_VALUE) {
127 for (int i = table.getColumnCount() - 1; i >= 0; i--) {
128 table.getColumn(i).dispose();
131 label.setText(ta.getStatusString());
132 previous.setEnabled(ta.hasPreviousPage());
133 next.setEnabled(ta.hasNextPage());
134 } catch (NotConnectedException e) {
135 view.handleException(e);
139 previous.setImage(QuantumPlugin.getImage("previous.gif")); //$NON-NLS-1$
140 previous.setToolTipText("Previous"); //$NON-NLS-1$
141 previous.addSelectionListener(new SelectionListener() {
142 public void widgetDefaultSelected(SelectionEvent e) {
144 public void widgetSelected(SelectionEvent event) {
149 for (int i = table.getColumnCount() - 1; i >= 0; i--) {
150 table.getColumn(i).dispose();
153 label.setText(ta.getStatusString());
154 previous.setEnabled(ta.hasPreviousPage());
155 next.setEnabled(ta.hasNextPage());
156 } catch (NotConnectedException e) {
157 view.handleException(e);
161 next.setImage(QuantumPlugin.getImage("next.gif")); //$NON-NLS-1$
162 next.setToolTipText("Next"); //$NON-NLS-1$
163 next.addSelectionListener(new SelectionListener() {
164 public void widgetDefaultSelected(SelectionEvent e) {
166 public void widgetSelected(SelectionEvent event) {
171 for (int i = table.getColumnCount() - 1; i >= 0; i--) {
172 table.getColumn(i).dispose();
175 label.setText(ta.getStatusString());
176 previous.setEnabled(ta.hasPreviousPage());
177 next.setEnabled(ta.hasNextPage());
178 } catch (NotConnectedException e) {
179 view.handleException(e);
184 toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
186 toolItem = new ToolItem(toolBar, SWT.PUSH);
187 toolItem.setImage(QuantumPlugin.getImage("close.gif")); //$NON-NLS-1$
188 toolItem.setToolTipText(Messages.getString("tableview.close")); //$NON-NLS-1$
189 toolItem.addSelectionListener(new SelectionListener() {
190 public void widgetDefaultSelected(SelectionEvent e) {
192 public void widgetSelected(SelectionEvent e) {
193 closeTableAction.run();
199 public void setColumns( final TableView view, final TableAdapter ta, Table table) {
201 // We create a matrix of TableColumn (columns in the Table widget) with
202 // the columns in the table object
203 TableColumn[] columns = table.getColumns();
204 String columnNames[] = new String[columns.length];
205 for (int i = 0; i < columns.length; i++) {
206 columnNames[i] = columns[i].getText();
208 // Copy in data the values of the data columns of the selected rows
209 StringMatrix data = new StringMatrix();
210 data.addMatrixHeader(columnNames);
211 // Create dummy values in case nothing selected
212 for (int i = 0; i < columns.length; i++) {
213 data.addAt(columnNames[i], "", 0); //$NON-NLS-1$
215 final TableRow emptyRow = new TableRow(ta.getEntity(), ta.getBookmark(), ta.getTable(), data);
217 filter.addSelectionListener(new SelectionListener() {
218 public void widgetDefaultSelected(SelectionEvent e) {
220 public void widgetSelected(SelectionEvent e) {
221 SortFilterPage page = new SortFilterPage(""); //$NON-NLS-1$
222 SQLRowWizard wizard = new SQLRowWizard();
223 wizard.init(Messages.getString("TableView.FilterAndSort"), page, emptyRow, ta); //$NON-NLS-1$
224 WizardDialog dialog = new WizardDialog(view.getSite().getShell(), wizard);
235 public ToolItem getNext() {
242 public ToolItem getPrevious() {